prob_desc_description stringlengths 63 3.8k | prob_desc_output_spec stringlengths 17 1.47k ⌀ | lang_cluster stringclasses 2 values | src_uid stringlengths 32 32 | code_uid stringlengths 32 32 | lang stringclasses 7 values | prob_desc_output_to stringclasses 3 values | prob_desc_memory_limit stringclasses 19 values | file_name stringclasses 111 values | tags listlengths 0 11 | prob_desc_created_at stringlengths 10 10 | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_notes stringlengths 4 3k ⌀ | exec_outcome stringclasses 1 value | difficulty int64 -1 3.5k ⌀ | prob_desc_input_from stringclasses 3 values | prob_desc_time_limit stringclasses 27 values | prob_desc_input_spec stringlengths 28 2.42k ⌀ | prob_desc_sample_outputs stringlengths 2 796 | source_code stringlengths 42 65.5k | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? | Print a single integer — the total number of calories that Jury wastes. | C | db9065d975878227a749083f0036a169 | ae54dfe6ef155a443c7e7a9d9e8fccd2 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1400686200 | ["1 2 3 4\n123214", "1 5 3 2\n11221"] | null | PASSED | 800 | standard input | 1 second | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | ["13", "13"] | #include<stdio.h>
int main()
{
int a1,a2,a3,a4,i,n,sum;
char str[100000];
while(scanf("%d %d %d %d",&a1,&a2,&a3,&a4)==4)
{
sum = 0;
scanf("%s",str);
for(i=0;str[i];i++)
{
n=str[i]-'0';
switch(n)
{
case 1: sum = sum+a1;
break;
case 2: sum = sum+a2;
break;
case 3: sum = sum+a3;
break;
case 4: sum = sum+a4;
break;
}
}
printf("%d\n",sum);
}
} | |
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? | Print a single integer — the total number of calories that Jury wastes. | C | db9065d975878227a749083f0036a169 | 92ae6a6507d6e2babb15d8151348d5c6 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1400686200 | ["1 2 3 4\n123214", "1 5 3 2\n11221"] | null | PASSED | 800 | standard input | 1 second | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | ["13", "13"] | #include<stdio.h>
main()
{
long int a[5],b,c,d,i,l,sum=0,p;
char s[100000];
for(i=0;i<4;i++){
scanf("%ld",&a[i]);
}
scanf("%s",&s);
l=strlen(s);
for(i=0;s[i]!='\0';i++){
sum=sum+a[s[i]-49];
}
printf("%ld ",sum);
}
| |
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? | Print a single integer — the total number of calories that Jury wastes. | C | db9065d975878227a749083f0036a169 | fcfc70714f46d680e60f73daca28194a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1400686200 | ["1 2 3 4\n123214", "1 5 3 2\n11221"] | null | PASSED | 800 | standard input | 1 second | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | ["13", "13"] | #include<stdio.h>
#include<string.h>
int main()
{
int a,b,c,d,i,t,sum=0;
scanf("%d %d %d %d",&a, &b, &c,&d);
char s[100000];
scanf("%s", &s);
t=strlen(s);
for(i=0;i<t;i++){
if(s[i]=='1')
sum=sum+a;
else if(s[i]=='2')
sum=sum+b;
else if(s[i]=='3')
sum=sum+c;
else
sum=sum+d;
}
printf("%d",sum);
return 0;
}
| |
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? | Print a single integer — the total number of calories that Jury wastes. | C | db9065d975878227a749083f0036a169 | 481209039c837015f797ab78ed3fef64 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1400686200 | ["1 2 3 4\n123214", "1 5 3 2\n11221"] | null | PASSED | 800 | standard input | 1 second | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | ["13", "13"] | #include<stdio.h>
#include<string.h>
int main()
{
long long a[5],ans=0;
char s[100001];
scanf("%lld%lld%lld%lld",&a[0],&a[1],&a[2],&a[3]);
scanf("%s",&s);
int len=strlen(s);
for(int i=0; i<len; i++)
{
ans=ans+a[s[i]-'1'];
}
printf("%lld\n",ans);
}
| |
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? | Print a single integer — the total number of calories that Jury wastes. | C | db9065d975878227a749083f0036a169 | eb238b8ed6671d7b167a95c8441f9657 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1400686200 | ["1 2 3 4\n123214", "1 5 3 2\n11221"] | null | PASSED | 800 | standard input | 1 second | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | ["13", "13"] | #include <stdio.h>
int main()
{
int a1,a2,i,a3,n,a4;
int s=0,t=0,u=0,v=0;
scanf("%d%d%d%d", &a1,&a2,&a3,&a4);
char a[100000];
scanf("%s",a);
for(i = 0; a[i] != '\0'; ++i);
n=i;
for(i=0;i<n;i++){
if(a[i]=='1'){
s=s+a1;
}
else if(a[i]=='2'){
t=t+a2;
}
else if(a[i]=='3'){
u=u+a3;
}
else if(a[i]=='4'){
v=v+a4;
}
}
printf("%d", s+t+u+v);
return 0;
}
| |
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares? | Print a single integer — the total number of calories that Jury wastes. | C | db9065d975878227a749083f0036a169 | ec135eb3c317d5c5b642b75c2267504b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1400686200 | ["1 2 3 4\n123214", "1 5 3 2\n11221"] | null | PASSED | 800 | standard input | 1 second | The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip. | ["13", "13"] | #include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
char str[100000];
int sum=0;
scanf("%s",str);
int l=strlen(str);
for(int i=0;i<l;i++)
{
char rem=str[i];
if(rem=='1')
sum=sum+a;
else if(rem=='2')
sum=sum+b;
else if(rem=='3')
sum=sum+c;
else
sum=sum+d;
}
printf("%d",sum);
return 0;
}
| |
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. | For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days. | C | d256f8cf105b08624eee21dd76a6ad3d | 9ba16c9b3c3d23898d853231b6baa6c3 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures"
] | 1456683000 | ["5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3", "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2"] | NoteConsider the first sample.We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. | PASSED | 1,700 | standard input | 4 seconds | The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: 1 di ai (1 ≤ di ≤ n, 1 ≤ ai ≤ 10 000), representing an update of ai orders on day di, or 2 pi (1 ≤ pi ≤ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. | ["3\n6\n4", "7\n1"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAXN 200010
int menor[MAXN], maior[MAXN];
int ft_e[MAXN], ft_a[MAXN];
int freq(int *ft, int ind) {
int ret = 0;
for (; ind > 0; ind -= ind & (-ind))
ret += ft[ind];
return ret;
}
int update (int *ft, int ind, int val, int n) {
for (;ind <= n; ind += (ind & (-ind)))
ft[ind] += val;
return 0;
}
int main () {
int n, k, a, b, q;
int i;
scanf("%d %d %d %d %d", &n, &k, &a, &b, &q);
for (i = 0; i < q; i++) {
int info;
scanf("%d", &info);
if (info == 1) {
int d, o;
int upd = 0;
scanf("%d %d", &d, &o);
if (menor[d] + o > b) {
upd = b - menor[d];
menor[d] = b;
} else {
menor[d] += o;
upd = o;
}
update(ft_e, d, upd, n);
upd = 0;
if (maior[d] + o > a) {
upd = a - maior[d];
maior[d] = a;
} else {
maior[d] += o;
upd = o;
}
update(ft_a, d, upd, n);
}
if (info == 2) {
int p;
int res = 0;
scanf ("%d", &p);
res += freq(ft_e, p - 1);
// printf("#%d\n", res);
res += (freq(ft_a, n) - freq(ft_a, p + k - 1));
printf("%d\n", res);
}
}
return 0;
} | |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 81fd0e750cc8ea89eafdcbcd6a002ba5 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include <stdio.h>
#include <string.h>
int main()
{
int i;
int k;
int length;
char s[100005];
char t[100005];
scanf("%s", s);
length = strlen(s);
if ( length%2 )
{
printf("No\n");
return 0;
}
k = 0;
for ( i = 0; i < length; i++ )
{
if ( k == 0 || s[i] != t[k-1] )
{
t[k] = s[i];
k++;
}
else
{
k--;
}
}
if ( k <= 0 )
printf("Yes\n");
else
printf("No\n");
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 919c1d09cb00b380da333f21bd88e169 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
char a[1000000];
typedef struct node
{
char data;
struct node * next;
}node;
node* head=NULL;
void push(char k)
{
node* temp=malloc(sizeof(node));
temp->data=k;
temp->next=head;
head=temp;
}
void pop()
{
node* temp=head->next;
head->next=NULL;
free(head);
head=temp;
}
int top()
{
if(head==NULL) return -1;
return (head->data);
}
int main()
{
scanf("%s",a);
push(a[0]);
int i,l=strlen(a);
for(i=1;i<l;i++)
{
if(top()==a[i]) pop();
else push(a[i]);
}
if(head==NULL) printf("YES\n");
else printf("NO\n");
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 4c73d22d31aae947522acaf30e5fca18 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | //
// Created by shreyanshu on 7/6/18.
//
#include <stdio.h>
#include <stdlib.h>
unsigned int top=-1;
void popElement(char *stack) {
stack[top]=' ';
top--;
}
void pushElement(char *stack,char c) {
top++;
stack[top]=c;
}
int main() {
unsigned int i;
char *a=(char *)malloc(sizeof(char)*100000);
char *stack=(char *)malloc(sizeof(char)*100000);
scanf("%s",a);
while (a[i]!='\0') {
if( top!=-1 && stack[top] == a[i] )
popElement(stack);
else
pushElement(stack,a[i]);
i++;
}
if( top == -1 )
printf("Yes\n");
else
printf("No\n");
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 3c22b7ae6836b0341c611c20c232c82c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<string.h>
int main() {
int i,j,k,l,n,m,ptr;
char c[100005],d[100005];
scanf(" %s",c);
n = strlen(c);
ptr = -1;
for(i=0;i<n;i++) {
if(ptr >= 0)
if(d[ptr] == c[i])
ptr--;
else {
ptr++;
d[ptr] = c[i];
}
else {
ptr++;
d[ptr] = c[i];
}
}
if(ptr == -1)
printf("Yes\n");
else
printf("No\n");
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 448bbe9df2deb8c832fa26dfbf75b7c6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<string.h>
int main()
{
char a[1000000];
scanf("%s",a);
if(strlen(a)%2!=0)
{
puts("No");
return 0;
}
char stack[1000000];
int ptr = 0,i=0;
stack[ptr] = a[0];
ptr++;
for(i=1;i<strlen(a);i++)
{
if(stack[ptr-1] == a[i])
{
ptr -= 1;
continue;
}
else
{
stack[ptr] = a[i];
ptr++;
}
}
if(ptr == 0)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 77940c409bc85317d634c509198dd493 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<stdlib.h>
typedef struct stack
{
int capa;
int a[100001];
int top;
}stack;
stack* stack1;
void create(int capacity)
{
stack1=(stack*)malloc(sizeof(stack));
stack1->top=-1;
stack1->capa=capacity;
}
void push(int value)
{
if(stack1->top==100001)
{
return ;
}
else
{
stack1->top=(stack1->top)+1;
stack1->a[(stack1->top)]=value;
}
}
void pop()
{
if(stack1->top==-1)
{
return ;
}
else
{
stack1->top=stack1->top-1;
}
}
int main()
{
char s[100002];
int i;
create(100002);
scanf("%s",s);
if(s[0]=='+')
{
push(1);
}
else
{
push(-1);
}
for(i=1;s[i]!='\0';i++)
{
if(stack1->a[stack1->top]==1)
{
if(s[i]=='+')
{
pop();
}
else
{
push(-1);
}
}
else
{
if(s[i]=='+')
{
push(1);
}
else
{
pop();
}
}
}
if(stack1->top==-1)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 270a4ea17e700ebec165dbfdbc77ade7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<string.h>
int main()
{
int countC=0, countAC=0;
int up=0;
char A[100001];
scanf("%s", A);
int n = strlen(A);
// printf("%d", n);
int i;
for(i=0; i<n; i++){
if((i%2 && A[i] =='+') || (i%2 == 0 && A[i] == '-')){
countC++;
}
else
countC--;
}
if(countC)
printf("No\n");
else
printf("Yes\n");
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | dd9cd0ec989e9200d6a77196890b677f | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<string.h>
int main()
{
char a[1000003], b[1000003];
int i, j=0, n;
scanf("%s", a);
for(i=0;a[i];i++){
if(a[i]!=b[j]){
j++;
b[j]=a[i];
}
else{
--j;
}
//printf("J:%d\n", j);
}
if(j==0){
printf("Yes");
}
else{
printf("No");
}
return 0;
}
| |
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view): Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.To understand the problem better please read the notes to the test samples. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | C | 89b4a7b4a6160ce784c588409b6ce935 | 8f1acaf012787f1e1b486275301c962f | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"implementation",
"greedy"
] | 1379172600 | ["-++-", "+-", "++", "-"] | NoteThe first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled: In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher: In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself: | PASSED | 1,600 | standard input | 1 second | The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | ["Yes", "No", "Yes", "No"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[100001];
scanf(" %s",a);
int knot=0;
int i;
int len =strlen(a);
if(len%2==1)
{
printf("No\n");
return 0;
}
for(i=1;i<len;i+=2)
{
if(a[i]=='+' &&a[i-1]=='-')
{
knot++;
}
if(a[i]=='-'&& a[i-1]=='+')
{
knot--;
}
}
if(!knot)
printf("Yes\n");
else
printf("No\n");
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | a1015787d82678171282083bbe664887 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
main()
{freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int p,i,j,k,temp,a[4]={0};
scanf("%d",&p);
a[p]++;
for(i=0;i<3;i++)
{
scanf("%d %d",&j,&k);
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
for(i=1;i<4;i++)
if(a[i]==1)
printf("%d",i);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 574e8351199637a68bc7b453eb7aa96e | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int s[4]={0},a,b,t,n,i;
scanf("%d",&n);
s[n]=1;
for(i=0;i<3;i++)
{
scanf("%d %d",&a,&b);
if(s[a]==1)
{
s[b]=1;
s[a]=0;
}
else if(s[b]==1)
{
s[a]=1;
s[b]=0;
}
else continue;
}
for(i=1;i<=3;i++)
if(s[i]==1)
{
printf("%d",i);
break;
}
return(0);
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | e750d0270d98e2f4df0ef75f562da994 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int n,a,b,i;
FILE *in = fopen("input.txt","r");
FILE *out = fopen("output.txt","w");
fscanf(in,"%d",&n);
for(i=0;i<3;i++)
{
fscanf(in,"%d %d",&a,&b);
if(n==a) {n=b;continue;}
if(n==b) {n=a;continue;}
}
fprintf(out,"%d",n);
return(0);
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 35bffb547f55d3a894993133ae3d683c | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int a,a1,a2,b1,b2,c1,c2;
FILE *fin = fopen("input.txt","r");
FILE *fout = fopen("output.txt","w");
fscanf(fin,"%d",&a);
fscanf(fin,"%d %d",&a1,&a2);
fscanf(fin,"%d %d",&b1,&b2);
fscanf(fin,"%d %d",&c1,&c2);
if(a==a1)
a=a2;
else if(a==a2)
a=a1;
if(a==b1)
a=b2;
else if(a==b2)
a=b1;
if(a==c1)
a=c2;
else if(a==c2)
a=c1;
fprintf(fout,"%d\n",a);
return 0;
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 555bf37fb528de645018b06cbd83c37d | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int a,a1,a2,b1,b2,c1,c2;
FILE *fin = fopen("input.txt","r");
FILE *fout = fopen("output.txt","w");
fscanf(fin,"%d",&a);
fscanf(fin,"%d %d",&a1,&a2);
fscanf(fin,"%d %d",&b1,&b2);
fscanf(fin,"%d %d",&c1,&c2);
if(a==a1)
{a=a2;}
else if(a==a2)
{a=a1;}
if(a==b1)
{a=b2;}
else if(a==b2)
{a=b1;}
if(a==c1)
{a=c2;}
else if(a==c2)
{a=c1;}
fprintf(fout,"%d\n",a);
return 0;
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 59428d1ebf499acf4c5555e53c7b5751 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int s[3]={0};
int n,a,b,i,t;
FILE *in=fopen("input.txt","r");
FILE *out=fopen("output.txt","w");
fscanf(in,"%d",&n);
s[n-1]=1;
for(i=0;i<3;i++)
{
fscanf(in,"%d%d",&a,&b);
t=s[a-1];
s[a-1]=s[b-1];
s[b-1]=t;
}
for(i=0;i<3;i++)
{
if(s[i]==1)
{ fprintf(out,"%d",i+1);
break;}
}
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | d069327efab48309f2a60aab60d2c939 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, i, a, b;
scanf("%d", &n);
for(i=0; i<3; i++)
{
scanf("%d %d", &a, &b);
if(a==n)
n=b;
else if(b==n)
n=a;
}
printf("%d", n);
return 0;
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | b0f128a2ed6a90afa9071f54760a0167 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int curr,i,pos1,pos2;
scanf("%d",&curr);
for(i=0;i<3;i++){scanf("%d %d",&pos1,&pos2);if(pos1==curr)curr=pos2;else if(pos2==curr)curr=pos1;}
printf("%d",curr);
return 0;
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | b176bb98759535f2a0a78f577c3c25eb | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int t,a,b,i;
scanf("%d", &t);
for(i=0;i<3;i++)
{
scanf("%d%d", &a, &b);
if(a==t)
t=b;
else if(b==t)
t=a;
}
printf("%d", t);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | b16e95aefb82b4a3b17322bcbf906b27 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, z[3];
z[0] = 0;
z[1] = 0;
z[2] = 0;
int a, b;
int i, aux;
scanf("%d", &n);
z[n-1] = 1;
for(i = 0; i < 3; ++i)
{
scanf("%d %d", &a, &b);
a--;
b--;
aux = z[a];
z[a] = z[b];
z[b] = aux;
}
for(i = 0; i < 3; ++i)
{
if(z[i] == 1)
{
printf("%d", i+1);
break;
}
}
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 685ec6cca834f934c6806c5fc70c5808 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int x;
int main(void) {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while(scanf("%d", &x) != EOF) {
int cup1=0, cup2=0, cup3=0;
switch(x) {
case 1:
cup1 = 5;
break;
case 2:
cup2 = 5;
break;
case 3:
cup3 = 5;
break;
}
int i, y, z, t;
for(i=0; i<3; i++) {
scanf("%d%d", &y, &z);
if(y==1 & z==2){
t = cup1;
cup1 = cup2;
cup2 = t;
}
else if(y==1 & z==3){
t = cup1;
cup1 = cup3;
cup3 = t;
}
else if(y==2 & z==1){
t = cup2;
cup2 = cup1;
cup1 = t;
}
else if(y==2 & z==3){
t = cup2;
cup2 = cup3;
cup3 = t;
}
else if(y==3 & z==1){
t = cup3;
cup3 = cup1;
cup1 = t;
}
else if(y==3 & z==2){
t = cup3;
cup3 = cup2;
cup2 = t;
}
}
if(cup1 == 5)
printf("1\n");
else if(cup2 == 5)
printf("2\n");
else
printf("3\n");
}
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | e6359495dda62276e1927eb53a00e48e | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int main()
{
int n, i;
int a[3] = {0};
FILE *fp1, *fp2;
fp1 = fopen("input.txt", "r");
fp2 = fopen("output.txt", "w");
fscanf(fp1, "%d", &n);
a[n - 1]++;
for (i = 0; i < 3; i++) {
int x, y, tmp;
fscanf(fp1, "%d %d", &x, &y);
tmp = a[x - 1];
a[x - 1] = a[y - 1];
a[y - 1] = tmp;
}
for (i = 0; i < 3; i++) {
if (a[i] == 1) {
fprintf(fp2, "%d\n", i + 1);
}
}
fclose(fp1);
fclose(fp2);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | db425f7aa13850893e3ada30edb8da98 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int arr[4]={0},i,a,b,orig;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&orig);
arr[orig]=1;
for(i=0;i<3;i++)
{
scanf("%d %d",&a,&b);
if(arr[a]==1 && arr[b]==0)
{
arr[b]=1;
arr[a]=0;
}
else if(arr[a]==0 && arr[b]==1)
{
arr[a]=1;
arr[b]=0;
}
}
for(i=1;i<4;i++)
if(arr[i]!=0)
printf("%d",i);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 8f4e6aac68ddbb56fdf1ef74dfac0491 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
int main () {
FILE *fin = fopen ("input.txt", "r");
FILE *fout = fopen ("output.txt", "w");
int fst, cup[4], a, b;
cup[1] = cup[2] = cup[3] = 0;
fscanf (fin, "%d", &fst );
cup[fst] = 1;
fscanf (fin, "%d %d", &a, &b );
cup[a] ^= cup[b]; cup[b] ^= cup[a]; cup[a] ^= cup[b];
fscanf (fin, "%d %d", &a, &b );
cup[a] ^= cup[b]; cup[b] ^= cup[a]; cup[a] ^= cup[b];
fscanf (fin, "%d %d", &a, &b );
cup[a] ^= cup[b]; cup[b] ^= cup[a]; cup[a] ^= cup[b];
for( fst = 1; fst < 4; fst++ ){
if( cup[fst] ) { fprintf (fout, "%d\n", fst ); break; }
}
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | c74310e9bda5583e70c15db4a46b2e9c | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
main()
{
int n,i,x,y,z;
FILE * f = NULL;
f = fopen("input.txt","r");
fscanf(f,"%d",&n);
x = n;
for (i=0;i<3;i++)
{
fscanf(f,"%d%d",&y,&z);
if (x==y) x = z;
else if (x==z) x = y;
}
fclose(f);
f = fopen("output.txt","w");
fprintf(f,"%d",x);
fclose(f);
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 573abf6b5efb21f2d9700c99bc34bbb2 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int m ,n, i, s[3] , p [3] ;
int main()
{
freopen ("input.txt","r",stdin);
freopen ("output.txt","w",stdout);
scanf("%d", &n) ;
for ( i = 0 ; i < 3 ; i++)
{
scanf("%d %d", &s[i] , &p[i] ) ;
}
for ( i = 0 ; i < 3 ; i++)
{
if ( n == s[i] )
{
n = p[i] ;
}
else if ( n == p[i] )
{
n = s[i] ;
}
}
printf("%d" , n ) ;
return 0 ;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 90f48b8d061f1550f17aaad0676b8d2e | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
FILE *fin , * fout ;
int pos , a ,b , i ;
fin = fopen("input.txt","r");
fout = fopen("output.txt","w");
fscanf(fin,"%d",&pos);
for ( i = 0 ; i < 3 ; i++)
{
fscanf(fin,"%d %d",&a,&b);
if ( pos == a )
{
pos = b ;
continue;
}
if ( pos == b )
{
pos = a ;
continue;
}
}
fprintf(fout,"%d\n",pos);
fclose(fin);
fclose(fout);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | c3301c715f4a707c5bb3a95615ea3008 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int main()
{
FILE *in, *out;
int cups[3] = {1,2,3};
int pos, i, j, k, aux;
in = fopen("input.txt","rt");
out = fopen("output.txt","wt");
fscanf(in,"%d\n",&pos);
for(k=0;k<3;k++)
{
fscanf(in,"%d %d",&i,&j);
aux = cups[i-1];
cups[i-1] = cups[j-1];
cups[j-1] = aux;
}
fclose(in);
for(k=0;k<3;k++) if(cups[k]==pos) fprintf(out,"%d\n",k+1);
fclose(out);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | d6185c2b814f2a86150fa377df6266c3 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,a,b,i,temp;
scanf("%d",&n);
for(i=0;i<3;i++){
scanf("%d %d",&a,&b);
if(a==n){
n=b;
}
else if(b==n){
n=a;
}
}
printf("%d",n);
//main();
return 0;
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 2dec5b91f73204ba04b93d5afe231d91 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int main(int argc, char *argv[])
{
int m, i, j;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d", &m);
scanf("%d %d", &i, &j);
if(i == m)
m = j;
else if(j == m)
m = i;
scanf("%d %d", &i, &j);
if(i == m)
m = j;
else if(j == m)
m = i;
scanf("%d %d", &i, &j);
if(i == m)
m = j;
else if(j == m)
m = i;
printf("%d\n", m);
fclose(stdin);
fclose(stdout);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 87481ad2c004e43a225ca0ac4f188caa | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <limits.h>
int main(void)
{
int n, t, x, y;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d", &t);
for (n=0; n<3; n++) {
scanf("%d%d", &x, &y);
if (x == t)
t = y;
else if (y == t)
t = x;
}
printf("%d", t);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 4a56958cdac848d10aa0b847f70deb43 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
#define NO_OF_SHUFFLES 3
int main()
{
int ball_shell, shell_1, shell_2, i;
FILE *input = fopen("input.txt", "r");
FILE *output = fopen("output.txt", "w");
fscanf(input, "%d", &ball_shell);
for(i = 1; i <= NO_OF_SHUFFLES; i++)
{
fscanf(input,"%d %d",&shell_1, &shell_2);
if(ball_shell == shell_1)
{
ball_shell = shell_2;
}
else if(ball_shell == shell_2)
{
ball_shell = shell_1;
}
}
fprintf(output,"%d\n",ball_shell);
fclose(input);
fclose(output);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 7d301a4d97fb4a7c17e2c233b5e34a7e | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include"stdio.h"
#include"math.h"
int main()
{
int i,p=3,a,b;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&i);
while(p--)
{
scanf("%d%d",&a,&b);
if(i==a)
i=b;
else if(i==b)
i=a;
}
printf("%d\n",i);
return 0;
} | |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 43e318b088cb2791d530d24396375d00 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int ball_in,cup1,cup2,temp,i;
FILE *fp;
fp=fopen("input.txt","r");
ball_in=fgetc(fp);
temp=fgetc(fp);
for(i=0;i<3;i++)
{
cup1=fgetc(fp);
printf("%d",cup1);
temp=fgetc(fp);
printf("%d",cup1);
cup2=fgetc(fp);
printf("%d",cup1);
temp=fgetc(fp);
printf("%d",cup1);
if(cup1==ball_in)
ball_in=cup2;
else if(cup2==ball_in)
ball_in=cup1;
}
fclose(fp);
fp=fopen("output.txt","w");
fprintf(fp,"%c",ball_in);
fclose(fp);
//scanf("%*d");
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | b78198b9f25016dc56e537791c23edb7 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include<stdio.h>
int main()
{
int cup, a, b, i;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d", &cup);
for(i=0; i<3; i++){
scanf("%d%d", &a, &b);
if(a==cup){
cup=b;
}
else if(b==cup){
cup=a;
}
}
printf("%d\n", cup);
return 0;
}
| |
Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too? | In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles. | C | 88e6651e1b0481d711e89c8071be1edf | 3b616e1e7b255af71ff0a433c08b7548 | GNU C | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287471600 | ["1\n1 2\n2 1\n2 1", "1\n2 1\n3 1\n1 3"] | null | PASSED | 1,000 | input.txt | 2 seconds | The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3. | ["2", "2"] | #include <stdio.h>
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
short pos,shuff[3][2],i;
scanf("%hi",&pos);
for(i=0;i<3;i++)
{
scanf("%hi %hi",&shuff[i][0],&shuff[i][1]);
if(pos==shuff[i][0])
pos=shuff[i][1];
else if(pos==shuff[i][1])
pos=shuff[i][0];
}
printf("%hi\n",pos);
return 0;
}
| |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.Strictly speaking, it makes a photo of all points with coordinates $$$(x, y)$$$, such that $$$x_1 \leq x \leq x_2$$$ and $$$y_1 \leq y \leq y_2$$$, where $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.After taking the photo, Pavel wrote down coordinates of $$$n$$$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. | Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. | C | cda1179c51fc69d2c64ee4707b97cbb3 | 8af117fdbbd44d4b3d3a17779b293cb6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"sortings",
"brute force",
"math"
] | 1532938500 | ["4\n4 1 3 2 3 2 1 3", "3\n5 8 5 5 7 5"] | NoteIn the first sample stars in Pavel's records can be $$$(1, 3)$$$, $$$(1, 3)$$$, $$$(2, 3)$$$, $$$(2, 4)$$$. In this case, the minimal area of the rectangle, which contains all these points is $$$1$$$ (rectangle with corners at $$$(1, 3)$$$ and $$$(2, 4)$$$). | PASSED | 1,500 | standard input | 1 second | The first line of the input contains an only integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$), the number of points in Pavel's records. The second line contains $$$2 \cdot n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_{2 \cdot n}$$$ ($$$1 \leq a_i \leq 10^9$$$), coordinates, written by Pavel in some order. | ["1", "0"] | #include <stdio.h>
#define ll long long
int cmp(const void *a, const void *b) {
int c = *(int *)a;
int d = *(int *)b;
if(c < d)
return -1;
else if (c == d)
return 0;
else
return 1;
}
int main() {
int n;
scanf("%d", &n);
int array[2*n];
for (int i = 0; i < 2*n; i++)
scanf("%d", &array[i]);
qsort(array, 2*n, sizeof(int), cmp);
ll min = (ll)(array[n-1] - array[0])*(array[2*n-1] - array[n]);
for (int i = 1; i < n; i++) {
ll tmpSum = (ll)(array[i+n-1] - array[i])*(array[2*n-1] - array[0]);
if (min > tmpSum)
min = tmpSum;
}
printf("%lld", min);
} | |
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.Strictly speaking, it makes a photo of all points with coordinates $$$(x, y)$$$, such that $$$x_1 \leq x \leq x_2$$$ and $$$y_1 \leq y \leq y_2$$$, where $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.After taking the photo, Pavel wrote down coordinates of $$$n$$$ of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle. | Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records. | C | cda1179c51fc69d2c64ee4707b97cbb3 | 20236909c090fd5871e4a5efa33bff20 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"sortings",
"brute force",
"math"
] | 1532938500 | ["4\n4 1 3 2 3 2 1 3", "3\n5 8 5 5 7 5"] | NoteIn the first sample stars in Pavel's records can be $$$(1, 3)$$$, $$$(1, 3)$$$, $$$(2, 3)$$$, $$$(2, 4)$$$. In this case, the minimal area of the rectangle, which contains all these points is $$$1$$$ (rectangle with corners at $$$(1, 3)$$$ and $$$(2, 4)$$$). | PASSED | 1,500 | standard input | 1 second | The first line of the input contains an only integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$), the number of points in Pavel's records. The second line contains $$$2 \cdot n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_{2 \cdot n}$$$ ($$$1 \leq a_i \leq 10^9$$$), coordinates, written by Pavel in some order. | ["1", "0"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int compare(const void *a, const void *b)
{
return (*(int *)a - *(int *)b);
}
int main()
{
int n;
scanf("%d", &n);
int *arr = calloc((2 * n), sizeof(int));
for (int i = 0; i < 2 * n; ++i){
scanf(" %d", &arr[i]);
}
qsort(arr, 2 * n, sizeof(int), compare);
long long w = arr[n-1] - arr[0];
long long h = arr[(2 * n)-1] - arr[n];
const long long area1 = w * h;
h = INT_MAX;
w = arr[(2 * n) - 1] - arr[0];
int tmp = 0;
for (int i = 1; i < n; ++i){
tmp = arr[i + n - 1] - arr[i];
if (tmp < h) {
h = tmp;
}
}
const long long area2 = w * h;
printf("%I64d\n", (area1 > area2) ? area2 : area1);
}
| |
Tavas is a cheerleader in the new sports competition named "Pashmaks". This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner).Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0.As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner.Tavas isn't really familiar with programming, so he asked you to help him. | In the first and the only line of output, print a sequence of numbers of possible winners in increasing order. | C | e54f8aff8ede309bd591cb9fbd565d1f | 8806e3f65d46f4b9d64b230a6f886a6b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"geometry",
"math"
] | 1429029300 | ["3\n1 3\n2 2\n3 1", "3\n1 2\n1 1\n2 1"] | null | PASSED | 2,600 | standard input | 1 second | The first line of input contains a single integer n (1 ≤ n ≤ 2 × 105). The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≤ si, ri ≤ 104). | ["1 2 3", "1 3"] | #include<stdio.h>
#define MAXN 200000
int N;
typedef struct{
int index;
int x, y;
} comp_t;
comp_t comp[MAXN];
int good[MAXN];
int good_num;
int db[MAXN];
int comp_cmp(const void *A, const void *B)
{
comp_t *a = (comp_t *)A; comp_t *b = (comp_t *)B;
if(b->x != a->x) return b->x - a->x;
return b->y - a->y;
}
int index_cmp(const void *A, const void *B)
{
comp_t *a = (comp_t *)A; comp_t *b = (comp_t *)B;
return a->index - b->index;
}
int main()
{
int i, j;
long long x0, x1, x2, y0, y1, y2;
scanf("%d\n", &N);
for(i=0; i<N; i++){
scanf("%d %d\n", &comp[i].x, &comp[i].y);
comp[i].index = i+1;
}
for(i=0; i<N; i++) db[i] = -1;
qsort(comp, N, sizeof(comp_t), comp_cmp);
good[0] = 0;
good_num = 1;
for(i=1; i<N; i++){
//printf("Processing (%d, %d)\n", comp[i].x, comp[i].y);
if(comp[i].x == comp[good[good_num-1]].x){
if(comp[i].y == comp[good[good_num-1]].y) db[i] = good[good_num-1];
continue;
}
while(good_num > 1){
x0 = comp[good[good_num-2]].x;
x1 = comp[good[good_num-1]].x;
x2 = comp[i].x;
y0 = comp[good[good_num-2]].y;
y1 = comp[good[good_num-1]].y;
y2 = comp[i].y;
if(x0*y2*(x1-x2)*(y1-y0) >= x2*y0*(y2-y1)*(x0-x1)) break;
good_num--;
}
if(comp[i].y > comp[good[good_num-1]].y){
good[good_num] = i;
good_num++;
}
/*
for(j=0; j<good_num; j++){
printf("(%d, %d) ", comp[good[j]].x, comp[good[j]].y);
}
printf("\n");
*/
}
for(i=0; i<N; i++) comp[i].x = 0;
for(i=0; i<good_num; i++)
comp[good[i]].x = 1;
for(i=0; i<N; i++)
if(db[i]>=0 && comp[db[i]].x)
comp[i].x = 1;
qsort(comp, N, sizeof(comp_t), index_cmp);
for(i=0; i<N; i++)
if(comp[i].x)
printf("%d ", comp[i].index);
printf("\n");
}
| |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | d86becaa9e003a2e2c72fa10b3a4d71a | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include <stdio.h>
int n, i, k, b[101], flag=0;
char a[101];
FILE *f, *g;
int main()
{
f=fopen("input.txt", "r");
g=fopen("output.txt", "w");
fscanf(f, "%d", &n);
fscanf(f, "%s", &a);
k=0;
for(i=0; i<n; i++)
if(a[i]=='1'){b[k]=i; k++;}
n=b[1]-b[0];
for(i=1; i<k-1; i++)
if(b[i+1]-b[i]!=n){flag=1; break;}
if(flag==1) fprintf(g, "NO");
else fprintf(g, "YES");
fclose(f);
fclose(g);
return 0;
} | |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | 74838b833c4038fdcbc16aa0d1222a83 | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include <stdio.h>
FILE *f, *g;
int n, j = 0;
char q[101];
int c[98];
int main()
{
f = fopen("input.txt", "r");
g = fopen("output.txt", "w");
fscanf(f, "%d", &n);
fscanf(f, "%s", q);
/*gasesc primul '1'. Numar cati de '0' sunt dupa primul 1 si pana la urmatorul 1. Numarul il atribui primului element din sirul c.
incrementez i si repe t procesul. Cand ajung la urmatorul 1 incrementez j.*/
for (int i = 0; i < n; i++)
{
if (q[i] == '1')
{
while (q[i + 1] == '0')
{
c[j]++;
i++;
}
j++;
}
}
for (int i = 0; i < j - 2; i++)
{
if (c[i] != c[i + 1])
{
fprintf(g, "NO");
fclose(f);
fclose(g);
return 0;
}
}
fprintf(g, "YES");
fclose(f);
fclose(g);
return 0;
} | |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | 3130f374df9228573ba10829ac86a2e1 | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include <stdio.h>
int n, i, sum = 0, ist, idr, diff, diffc;
char q[101];
FILE *f, *g;
int main()
{
f = fopen("input.txt", "r");
g = fopen("output.txt", "w");
fscanf(f, "%d", &n);
fscanf(f, "%s", q);
ist = 0;
while (q[ist] == '0') ist++;
idr = ist + 1;
while (q[idr] == '0') idr++;
diff = idr - ist;
// printf("%d %d %d\n", ist, idr, diff);
while (idr < n )
{
ist = idr;
idr = ist + 1;
while (q[idr] == '0' && idr < n) idr++;
if (idr < n) { diffc = idr - ist;
// printf("%d %d %d\n", ist, idr, diffc);
if (diffc != diff) {fprintf(g, "NO");
fclose(f); fclose(g);
return 0;}
}
}
fprintf(g, "YES");
fclose(f); fclose(g);
return 0;
} | |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | 87aa31084baf42985b31efeaa3147766 | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include <stdio.h>
int main()
{ freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int a,i,k=0,d;
int ara[150];
char s[150];
scanf("%d",&a);
scanf("%s",&s);
for(i=0;i<a;i++)
{
if(s[i]=='1'){
ara[k]=i;
k++;
}
}
for(i=0;i<k-1;i++){
if(i==0){
d=ara[i+1]-ara[i];
}
else if(d!=ara[i+1]-ara[i]){
printf("NO");
return 0;
}
}
printf("YES");
}
| |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | d478884362da306c127ff7994d3c93bb | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include<stdio.h>
int main(){
int n = 0,start = 0,interval[105] = {0};
int interval_th = 0,no = 0;
char signal[105];
int count = 0;
FILE *fp = fopen("input.txt","r");
FILE *output = fopen("output.txt","w");
while(!feof(fp)){
fscanf(fp,"%d\n%s",&n,signal);
}
//printf("%s\n",signal);
for(int i = 0;i<n;i++){
//printf("%d = ",i);
if(start==0&&signal[i]=='1'){
//printf("a\n");
start = 1;
continue;
}
if(start==1&&signal[i]=='0'){
//printf("b\n");
count++;
}
if(start==1&&signal[i]=='1'){
//printf("c\n");
interval[interval_th] = count;
interval_th++;
start = 1;
count = 0;
continue;
}
}
for(int i = 0;i<interval_th;i++){
if(interval[i]!=interval[0]){
fprintf(output,"NO\n");
no = 1;
break;
}
}
if(no == 0){
fprintf(output,"YES\n");
}
return 0;
} | |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | 81c0e0985c546e3d8d0915462cfffd8f | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include<ctype.h>
#include<limits.h>
#include<math.h>
#include<stdbool.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
char signal[n + 1];
scanf("%s", signal);
int distance[n], index = 0;
for(int i = 0; i < n; i++)
if(signal[i] == '1')
distance[index++] = i;
bool found = true;
int d = distance[1] - distance[0];
for(int i = 1; i < index - 1; i++)
if((distance[i + 1] - distance[i]) != d)
found = false;
if(found)
printf("YES");
else
printf("NO");
return 0;
}
| |
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | C | 4fc1ca3517168842cc85d74ba0066598 | 96c2a304c46f11f5112d0f0013ec5e61 | GNU C11 | output.txt | 64 megabytes | train_001.jsonl | [
"implementation"
] | 1287482400 | ["8\n00111000", "7\n1001011", "7\n1010100"] | null | PASSED | 1,300 | input.txt | 2 seconds | The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s. | ["YES", "NO", "YES"] | #include<stdio.h>
#include<stdlib.h>
int judge(char *);
int judge(char *s)
{
int i,k=0;
int a[100]={0};
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='1')
{
a[k++]=i;
}
}
for(i=2;i<k;i++)
{
if(a[i]-a[i-1]!=a[i-1]-a[i-2])
{
return 0;
}
}
return 1;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
char s[101];
int n;
scanf("%d%s",&n,s);
printf((judge(s)==1)?"YES\n":"NO\n");
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | a23bcf1c37f53935cc0bb29faccc45e6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
int main()
{
int n,cnt,i;
signed long long int x,a;
char c;
scanf("%d %I64d",&n,&x);
for(i=1,cnt=0;i<=n;i++){
getchar();
scanf("%c %I64d",&c,&a);
if(c=='+'){
x=x+a;
}
if(c=='-'){
if(a<=x){
x=x-a;
}
else{
x=x;
cnt=cnt+1;
}
}
}
printf("%I64d %d",x,cnt);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 82cad59be962b59349b02bd71da08f26 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main ()
{
long long int n,x,d,dst;
char ch;
scanf("%lld %lld",&n,&x);dst=0;
while(n--)
{
getchar();
scanf("%c %lld",&ch,&d);
if(ch=='+')
x+=d;
else
{
if(x>=d)
x-=d;
else dst++;
}
}
printf("%lld %lld\n",x,dst);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 204bf9cd095279d8f9088f2a841bbf0b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | //distressed 失望
//就是一个简单的统计处理!
#include<stdio.h>
int main() {
int n,x;
scanf("%d%d",&n,&x);
int distress=0;
int i;
long long ice_cream=x;
for(i=0;i<n;i++){
char sign[2];
int number;
scanf("%s%d",sign,&number);
if(sign[0]=='+'){
ice_cream+=number;
}else{
if(number>ice_cream){
distress++;
}else{
ice_cream-=number;
}
}
}
printf("%lld %d\n",ice_cream,distress);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | adb37ca3b16092abe1dd0bb584d9ccbf | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
#include<string.h>
int main()
{
long long int n,x,sad,answer;
scanf("%lld %lld\n", &n, &x);
answer = x;
sad = 0;
int cur;
char type;
for (int i = 0; i < n; ++i)
{
scanf("%c %d\n", &type, &cur);
if (type == '+')
{
answer += cur;
}
else if (answer >= cur)
{
answer -= cur;
}
else
{
++sad;
}
}
printf("%lld %lld\n",answer,sad);
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 0213c8d7e72cd03de9a1a0d4553a44ad | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
int n,i,d,count=0;
long long int x;
scanf("%d %I64d",&n ,&x);
char ch;
for(i=0;i<n;i++)
{
scanf(" %c %d", &ch, &d);
if( ch=='+')
{
x=x+d;
}
if( ch=='-')
{
if(x>=d)
{
x=x-d;
}
else count++;
}
}
printf("%I64d %d", x,count);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 295d779d2826fe636ddeed0554b37bab | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int i,n,x;
long long int num=0,count=0;
char ch,sp;
scanf("%lld%lld",&n,&x);
for(i=0;i<n;i++)
{
scanf("%c%c%lld",&ch,&sp,&num);
if(sp=='+')
x=x+num;
if(sp=='-')
{
x=x-num;
if(x<0)
{
count++;
x=x+num;
}
}
}
printf("%lld %lld",x,count);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | e8c65d543974ca0c57ee7d4a712d402a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
char c;
long long n,x,t,i,count=0;
scanf("%I64d %I64d",&n,&t);
for(i=1;i<=n;i++)
{
getchar();
scanf("%c %I64d",&c,&x);
if(c=='+')
t=t+x;
else
{
if(x<=t)
{
t=t-x;
}
else
count++;
}
}
printf("%I64d %I64d",t,count);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | b12b9f6380b36bdc04301d15d11798ec | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long n,x,i,a,count=0;
char c;
scanf("%I64d %I64d",&n,&x);
getchar();
for(i=0;i<n;i++)
{
scanf("%c %I64d",&c,&a);
getchar();
if(c=='+')
x+=a;
else
{
if(x>=a)
x-=a;
else
count++;
}
}
printf("%I64d %I64d",x,count);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 73c97379b3c1eeb35f84140b3a6a6273 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
#include<math.h>
int main()
{
long long x,n,a,b,count=0,i;
char ch;
scanf("%I64d %I64d",&n,&x);
for(i=0;i<n;i++)
{
scanf(" %c %I64d",&ch,&a);
if(ch=='+') x=x+a;
else if(ch=='-' && a<=x) x=x-a;
else if(ch=='-' && a>x) count++;
}
printf("%I64d %I64d\n",x,count);
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 9f84f4cb0e3912a6f859bfeb41058ec2 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
char c[2];
long long int inikay,sum,i,xtra,pack,child,temp;
scanf("%lld %lld",&inikay,&pack);
sum=pack;
child=0;
for(i=0;i<inikay;i++)
{
scanf("%s %lld",c,&xtra);
if(c[0]=='+')
sum+=xtra;
if(c[0]=='-')
{temp=sum;
if(xtra>temp)
{child++;
}
else
sum-=xtra;
}
}
printf("%lld %lld\n",sum,child);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 60cbde4248f3367fad9703dfdfabec71 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
#include<memory.h>
#include<string.h>
int jia(const char* a,const char*b,char* c);
int jian(const char* a,const char*b,char* c);
char y[1000],sum[1000];
int jia(const char* a,const char*b,char* c)
{
int i,j,k,max,o;
short d,m[1000],n[1000],l[1000];
memset(l,0,1000);
memset(m,0,1000);
memset(n,0,1000);
j=strlen(a);
k=strlen(b);
for (i=0;i<j;i++)
m[j-1-i]=a[i]-'0';
for (i=0;i<k;i++)
n[k-1-i]=b[i]-'0';
if (j>k)
max=j;
else
max=k;
for (i=0;i<max;i++)
{
o=m[i]+n[i]+l[i];
l[i+1]=l[i+1]+o/10;
l[i]=o%10;
}
if (l[max]>0)
max++;
for (i=0;i<max;i++)
c[i]=l[max-1-i]+'0';
}
int jian(const char* a,const char*b,char* c)
{
int i,j,k,max,o;
short d,m[1000],n[1000],l[1000];
memset(l,0,1000);
memset(m,0,1000);
memset(n,0,1000);
j=strlen(a);
k=strlen(b);
for (i=0;i<j;i++)
m[j-1-i]=a[i]-'0';
for (i=0;i<k;i++)
n[k-1-i]=b[i]-'0';
for (i=0;i<j;i++)
{
o=m[i]-n[i]+l[i];
if (o<0)
{
l[i+1]=l[i+1]-1;
l[i]=10+o;
}
else
{
l[i+1]=l[i+1]+o/10;
l[i]=o%10;
}
}
while (l[j-1]==0 && j>1)
j--;
memset(c,'\0',1000);
for (i=0;i<j;i++)
c[i]=l[j-1-i]+'0';
}
int main(){
int n,p,sum1,i,l;
char s[2];
scanf("%d %s",&n,&y);
strcpy(sum,y);
sum1=0;
for (i=0;i<n;i++)
{
scanf("%s",&s);
if (s[0]=='+')
{
scanf("%s",&y);
jia(sum,y,sum);
}
else if (s[0]=='-')
{
scanf("%s",&y);
if (strlen(sum)>strlen(y))
p=-1;
else if (strlen(sum)<strlen(y))
p=1;
else
p=strcmp(y,sum);
if (p>0)
sum1++;
else
jian(sum,y,sum);
}
}
printf("%s %d",sum,sum1);
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 84d20d5bc3fdc461a6e10f6a52320d10 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
main()
{
long long int numchoc , chng , t=0 , initial , line , distress=0 ;
char sign ;
scanf("%I64d %I64d",&line,&numchoc);
while(t<line)
{
scanf(" %c",&sign);
scanf("%I64d",&chng);
if(sign=='+')
{
numchoc+=chng ;
}
else
{
if(chng>numchoc)
{
distress++ ;
}
else
{
numchoc-=chng ;
}
}
t++ ;
}
printf("%I64d %I64d\n",numchoc , distress);
return 0 ;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | cc88ae8a03a076f77222b9ca32429360 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int i,j,x,n,d=0;
char c[2];
scanf("%lld %lld",&n,&x);
for(i=0;i<n;i++)
{scanf("%s",&c);
scanf("%lld",&j);
if(c[0]=='+')
x=x+j;
else {
if(x-j>=0)
x=x-j;
else d++;
}
}
printf("%lld %lld",x,d);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | debb3ab15cbfc3d8d6ed8d3e1b6b1a03 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
#include <stdlib.h>
int main() {
long long n, x, nk = 0, d;
char c;
scanf("%I64d%I64d", &n, &x, &c);
while(n--) {
scanf(" %c%I64d", &c, &d);
if(c == '+') {
x += d;
} else {
if(x >= d) {
x -= d;
} else {
nk++;
}
}
}
printf("%I64d %I64d\n", x, nk);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 49e83e841f59bcd04a5647efbea6e1ee | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
int main()
{
//freopen("inp.txt", "r", stdin);
int n;
long long int x;
scanf("%d %lli", &n, &x);
int i;
int distress = 0;
for(i = 0; i < n; i++)
{
char symbol;
//char temp;
long long int d;
//scanf("%c", &temp);
scanf("\n%c %lli", &symbol, &d);
//printf("%c\n", symbol);
if(symbol == '+')
x += d;
if(symbol == '-')
{
if(x >= d)
x -= d;
else
distress++;
}
}
printf("%lli %d\n", x, distress);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 22643899a068db0e2de4e13a029be4fc | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
long long b;
char s[5];
main(){
int n,a=0,x;
scanf("%d%I64d",&n,&b);
while(n--){
scanf("%s%d",s,&x);
if(s[0]=='+')
b+=x;
else if(b>=x)
b-=x;
else a++;
}
printf("%I64d %d\n",b,a);
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 9e0ba1824bd8a3d9f979e6144a330274 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | long long n,x,a,i,l=0;
sign;
main(n)
{
scanf("%d%I64d",&n,&x);
for(i=0;i<n;i++)
{
scanf("%s%I64d",&sign,&a);
if(sign=='+')x+=a;
if(sign=='-'){if(a>x)l++;
if(a<=x)x-=a;}}
printf("%I64d %I64d",x,l);
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 696ddbe333f4d6a172253cc83091fc65 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
int main()
{
long long int n, x, dem, bal, count, i, j, neu;
char id;
while(scanf("%lld %lld", &n, &x)!=EOF)
{
bal = x;
for(i=0, count = 0; i<n; i++)
{
scanf("\n%c %lld", &id, &neu);
if(id=='+') bal+=neu;
else
{
if(neu>bal)
{
count++;
}
else
{
bal-=neu;
}
}
}
printf("%lld %lld\n", bal, count);
}
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 4f2522b82cd01bc66d14e65b68a1b734 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
int i,n,x;scanf("%d%d",&n,&x);char ch[10];int t;int c=0;long long int m=x;//printf("x=%d\n",x);int m=x;
for(i=1;i<=n;i++)
{
scanf("%s",ch);scanf("%d",&t);//printf("x=%d\n",m);
if(ch[0]=='+')
{
m=m+t;//printf("x=%d\n",m);
}
else
{
if((m-t)>=0)
m=m-t;
else
c++;
// printf("x=%d\n",m);
}
}
printf("%I64d %d\n",m,c);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 2dfbc19a06f479f811fda191bedbdd42 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
int main()
{
char s[10000000];
long long int sum=0,i,n,x=0,c=0,len,j=0,b=0;
scanf("%lld%lld",&n,&sum);
for(i=1;i<=n;i++){
scanf("%s%lld",s,&x);
if(s[0]=='+'){
sum+=x;
}
else{
if(sum<x){
c++;
}
else{
sum-=x;
}
}
}
printf("%lld %lld",sum,c);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | f4b1c0f248a7642b1fe7597f3f0a04bc | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long n,sum,count=0,x,i;
char ch;
scanf("%I64d%I64d ",&n,&sum);
for(i=1;i<=n;i++)
{
scanf("%c%I64d",&ch,&x);
getchar();
if(ch=='+')
sum+=x;
else
{
if(x<=sum)
sum-=x;
else
count++;
}
}
printf("%I64d %I64d",sum,count);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 14e89989babcde7dd2bdc62d533e7186 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
#include <stdint.h>
char buffer[2];
uint64_t d=0,K=0,s=0;
int main() {
scanf("%d%d", &d, &K);
while (scanf("%s", buffer) > 0) {
scanf("%d", &d);
K = *buffer=='+' ? K+d : K<d ? s++,K : K-d;
}
printf("%I64d %d\n", K, s);
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 29a2a603a6344ccbc2c0eb98c7cd1875 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
#define sf scanf
#define pf printf
#define ll long long
#define sfl2(a,b) sf("%lld %lld",&a,&b)
int main()
{
int t,tc=1;
ll n,m;
sfl2(n,m);
char ch;
ll sum=0,cnt=0,x;
sum+=m;
for(int i=1;i<=n;i++)
{
sf(" %c %lld",&ch,&x);
if(ch=='+')
{
sum+=x;
}
else
{
if(sum>=x)
{
sum-=x;
}
else
{
cnt++;
}
}
}
pf("%lld %lld\n",sum,cnt);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 993e4c1460f8c4507edd46247df48497 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
#include<string.h>
struct ice
{
char c[2];
long int y;
};
int main()
{
long long int n,x,i;
scanf("%I64d%I64d ",&n,&x);
struct ice a[n];
for(i=0; i<n; i++)
{
scanf("%s%I64d",a[i].c,&a[i].y);
}
long long int count1=x,count2=0;
for(i=0; i<n; i++)
{
if(a[i].c[0]=='+')
count1+=a[i].y;
else if((a[i].c[0]=='-')&&(count1<a[i].y))
{
count2++;
// printf("%d %d\n",count1,count2);
}
else if((a[i].c[0]=='-')&&(count1>=a[i].y))
{
count1-=a[i].y;
// printf("%d %d\n",count1,count2);
}
}
printf("%I64d %I64d",count1,count2);
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 5e759d062c6a9ebea6d7b312c14189ed | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
#include<string.h>
int main()
{
long long int i,n,a,b,sum,count;
char str[2];
while(scanf("%I64d %I64d",&a,&b)==2){
sum=b;count=0;
for(i=1;i<=a;i++){
scanf("%s %I64d",str,&n);
if(strcmp(str,"+")==0)
sum=sum+n;
else{
if(sum-n>=0)
sum=sum-n;
else
count++;
}
}
printf("%I64d %I64d\n",sum,count);
}
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 79b68bbdb5f0b94503d921297c6e4346 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int count,k=0,n,x,i,j;
char c;
scanf("%lld%lld",&n,&x);
count=x;
for(i=0;i<n;i++)
{
getchar();
scanf("%c%lld",&c,&j);
// printf("%c ",c);
// printf("%ld ",j);
if(c=='+')
count+=j;
if(c=='-')
if(count>=j)
count-=j;
else
k++;
}
printf("%lld %lld",count,k);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 8ccdfa9ad048166fdf25853441c5bbb7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int n,x,d,i,sum,count=0;
char ch;
scanf("%I64d%I64d%*c",&n,&x);
sum=x;
for(i=0;i<n;i++){
scanf("%c%I64d%*c",&ch,&d);
if(ch=='+'){
sum+=d;
}
else{
if(sum<d){
count++;
continue;
}
sum-=d;
}
}
printf("%I64d %I64d",sum,count);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | cf51775623fbf623d1b3df734b1e5e27 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main()
{
// 1. read input
int n;
int64_t x;
int d = 0;
scanf("%d %I64d", &n, &x);
for(int i = 0 ; i < n ; i++)
{
char c;
int64_t v;
scanf(" %c %I64d", &c, &v);
if(c == '+')
{
x += v;
}
else if(c == '-')
{
if(v > x)
{
d++;
}
else
{
x -= v;
}
}
}
printf("%I64d %d\n", x, d);
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | e18f79c8c596f4f74dafde7a11ed88b2 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int n,m,count=0,j,i,b;
char c,a;
scanf("%lld%lld",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%c%c%lld",&c,&a,&b);
if(a=='+')
{
m=b+m;
}
if(a=='-')
{
j=m;
m=m-b;
if(m<0)
{
m=j;
count++;
}
}
}
printf("%lld %lld",m,count);
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 396d0f5a1dcab6869a0bd633f1b7da68 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
int n,i,j,distress=0;
long long int d,x;
scanf("%d %I64d",&n,&x);
char c[100];
for (i=0;i<=n;i++)
{
gets(c);
c[1]='0';
d=atoi(c);
if (d>0) x=x+d;
else if (d<0 && d*(-1)<=x) x=x+d;
else if (d<0 && d*(-1)>x) distress+=1;
}
printf("%I64d %d",x,distress);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 0a5d35231e407f5ff29ec7c4e0bd53e4 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int n,x,sum;
char a[3];
scanf("%lld%lld",&n,&x);
long long int i,d[n],count=0;
sum=x;
for(i=0;i<n;i++)
{
scanf("%s%lld",a,&d[i]);
if(a[0]=='-')
{
if(sum>=d[i])
sum-=d[i];
else
count++;
}
if(a[0]=='+')
sum+=d[i];
}
printf("%lld %lld",sum,count);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 24eb2922047b3bf1e259ccf4f8098ebe | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
long long int i,n,x,sum=0,cnt=0,a[10001];
char c[10000];
main()
{
scanf("%I64d %I64d",&n,&x);
getchar();
sum=x;
for(i=0;i<n;i++)
{
scanf("%c %I64d",&c[i],&a[i]);
getchar();
}
for(i=0;i<n;i++)
{
if(c[i]== '+')
{
sum=sum+a[i];
}
else if(c[i]== '-')
{
if(sum < a[i])
{
cnt++;
}
else
{
sum=sum-a[i];
}
}
//printf("%ld %ld\n",sum,cnt);
}
printf("%I64d %I64d\n",sum,cnt);
return 0;
}
| |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | d9b1bd5b68a012703a6c2abeb55825de | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include<stdio.h>
int main()
{
long long int n,x,d,stock,count=0;
char sign,dummy;
scanf("%lld %lld",&n,&x);
stock=x;
while(n--)
{
scanf(" %c",&sign);
scanf("%lld",&d);
if(sign=='+')
stock+=d;
else
{
if(stock-d>=0)
stock-=d;
else
count++;
}
}
printf("%lld %lld\n",stock,count);
return 0;
} | |
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | C | 0a9ee8cbfa9888caef39b024563b7dcd | 0f8c1e7e1cf491365570f82d6f7cda70 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation"
] | 1466699700 | ["5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98"] | NoteConsider the first sample. Initially Kay and Gerda have 7 packs of ice cream. Carrier brings 5 more, so now they have 12 packs. A kid asks for 10 packs and receives them. There are only 2 packs remaining. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. Carrier bring 40 packs, now Kay and Gerda have 42 packs. Kid asks for 20 packs and receives them. There are 22 packs remaining. | PASSED | 800 | standard input | 2 seconds | The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place. | ["22 1", "3 2"] | #include <stdio.h>
int main()
{
int n;
long long x;
scanf("%d %I64d\n", &n, &x);
char direction;
int temp, distressed = 0;
for (int i = 0; i < n; ++i)
{
scanf("%c %d\n", &direction, &temp);
if (direction == '+')
{
x += temp;
}
else
{
if (x >= temp)
{
x -= temp;
}
else
{
distressed++;
}
}
}
printf("%I64d %d", x,distressed);
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 9298d50208dc7b195bb35de3f7a938d6 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include <stdio.h>
#include <stdlib.h>
int comp(const void*,const void*);
int main()
{
int n,max1,max2,min1,min2,i;
scanf("%d",&n);
int num[n];
for(i=0;i<n;i++)
scanf("%d",&num[i]);
qsort((void*)num,n,sizeof(int),comp);
max1=num[n-1],max2=num[n-2],min1=num[0],min2=num[1];
if(max1==max2&&min1==min2)
printf("%d",max1-min1);
else if(max1!=max2&&min1==min2)
printf("%d",max2-min1);
else if(max1==max2&&min1!=min2)
printf("%d",max1-min2);
else if(max1!=max2&&min1!=min2)
if(max1-max2>min2-min1)
printf("%d",max2-min1);
else
printf("%d",max1-min2);
return 0;
}
int comp(const void *a,const void *b)
{
return *((int*)a)-*((int*)b);
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | f88e37603f014b5458c63e9aa3c41cc6 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include<stdio.h>
int main()
{ int n,i,q,j,a[100001],max=0,max1=0,min=100001,min1=100001;
scanf("%d",&n);
for(i=0; i<n; i++) scanf("%d",&a[i]);
if(n==2) printf("0"); else {
for(i=0; i<n; i++) {if(a[i]<min) {min1=min; min=a[i];} else {if(a[i]<min1) min1=a[i];};
if(a[i]>=max) {max1=max; max=a[i];} else {if(a[i]>=max1) max1=a[i];
} }
if(max1-min<max-min1) printf("%d",max1-min); else printf("%d",max-min1);
}}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 1f3b46a521b7fe00a731924fcc08e0d2 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include<stdio.h>
void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
void sort(int a[],int l,int x)
{
if(l>=x)
return;
int c=l,pivot=a[x];
for(int i=l;i<=x;i++)
{
if(a[i]<=pivot)
{
swap(&a[c],&a[i]);
c++;
}
}
sort(a,l,c-2);
sort(a,c,x);
}
int calmin(int a,int b,int c)
{
if(a<b)
{
if(a<c)
return a;
else
return c;
}
else
{
if(b<c)
return b;
else
return c;
}
}
int main()
{
int n;
scanf("%d",&n);
int ar[n],a,b,c,max=0,nmax=0,min=100000,nmin=100000;
if(n==2)
{
scanf("%d%d",&a,&b);
printf("%d",0);
}
else if(n==3)
{
scanf("%d%d%d",&a,&b,&c);
if(a>b)
max=a-b;
else
max=b-a;
if(b>c)
min=b-c;
else
min=c-b;
if(c>a)
nmin=c-a;
else
nmin=a-c;
printf("%d",calmin(min,nmin,max));
}
else
{
for(int i=0;i<n;i++)
{
scanf("%d",&ar[i]);
if(ar[i]>=max)
{
nmax=max;
max=ar[i];
}
else if(ar[i]>nmax)
nmax=ar[i];
if(ar[i]<=min)
{
nmin=min;
min=ar[i];
}
else if(nmin>ar[i])
nmin=ar[i];
}
//printf("%d %d %d %d",min,nmin,nmax,max);
printf("%d",calmin(max-min,max-nmin,nmax-min));
}
//printf("%d %d %d %d",min,nmin,nmax,max);
/*sort(ar,0,n-1);
int a=100000,b=100000,c=100000;
a=ar[n-1]-ar[0];
b=ar[n-1]-ar[1];
c=ar[n-2]-ar[0];
printf("%d",min(a,b,c));*/
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | a3208c8ec1ea3100c1d8fd66a51ca91a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include <stdio.h>
int main()
{
int i;
long int n,a1=0,b=0,w,q,temp;
scanf("%ld",&n);
long int a[n];
for(i=0;i<n;i++)
{
scanf("\n%ld",&a[i]);
}
int min1=a[0],max2=0,max1=a[0],min2=1000001;
for(i=0;i<n;i++)
{
if(a[i]<min1){ min1=a[i];a1=i;}
if(a[i]>max1) {max1=a[i];b=i;}
}
if(n==2)
printf("0");
else
{
for(i=0;i<n;i++)
{
if(i!=a1&&i!=b)
{
if(a[i]<min2) min2=a[i];
if(a[i]>max2) max2=a[i];
}
}
w=max1-max2;
q=min2-min1;
if(w>q)printf(" %d",max2-min1);
else printf(" %d",max1-min2);
}
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 197867171352ab8b0af29cd7b34a92bd | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include <stdio.h>
int n;
int a[100100];
void merge(int *a, int l, int mid, int r) {
int n1 = mid - l + 1;
int n2 = r - mid;
int L[n1], R[n2];
for (int i = 0; i < n1; i++) L[i] = a[l + i];
for (int i = 0; i < n2; i++) R[i] = a[mid + 1 + i];
int i = 0, j = 0, k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
a[k] = L[i++];
}
else a[k] = R[j++];
k++;
}
while (i < n1) {
a[k] = L[i];
k++; i++;
}
while (j < n2) {
a[k] = R[j];
k++; j++;
}
}
void ms(int *a, int l, int r) {
if (l < r) {
int m = l + (r - l) / 2;
ms(a, l, m);
ms(a, m + 1, r);
merge(a, l, m, r);
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
ms(a, 0, n - 1);
int ans = (a[n - 1] - a[1] > a[n - 2] - a[0] ? a[n - 2] - a[0] : a[n - 1] - a[1]);
printf("%d\n", ans);
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 366fa584aee60a2cced044b06bf150af | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include<stdio.h>
int main()
{
long long int n,i,a,x=0,y=10000000000000000,z=0,m,k;
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld",&a);
if(a>=x){
z=x;
x=a;
}
if(a<x&&a>z){
z=a;
}
if(a<=y){
m=y;
y=a;
}
if(a>y&&a<m){
m=a;
}
}
if(z-y<x-m){
k=z-y;
}
else{
k=x-m;
}
printf("%lld\n",k);
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | adaf3fffa62b5d69bb7bcfebdf03043a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include<stdio.h>
int main(){
int n,max1,max2=0,min1,min2=100005,num,index=0;
scanf("%d",&n);
scanf("%d",&max1);
min1=max1;
for(int i=1;i<n;i++){
scanf("%d",&num);
if(num>=max1){
max2=max1;
max1=num;
} else if(num>max2&&num!=max1){max2=num;}
if(num<=min1){
min2=min1;
min1=num;
} else if(num<min2&&num!=min1){min2=num;}
}
if(max1-max2>min2-min1){printf("%d",max2-min1);}
else{printf("%d",max1-min2);}
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | dcf0220300717ea400f808f376f5d965 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include <stdio.h>
int sec_max(int a[], int n, int p)
{ int max;
if(p==0)
{ max=a[1];}
else{
max=a[0];}
for(int i=0;(i<n); i++)
{
if(i==p){
continue;
}
if(max<a[i])
max=a[i];
}
return max;
}
int sec_min(int a[], int n, int p)
{ int min;
if(p==0)
{ min=a[1];}
else{
min=a[0];}
for(int i=0;(i<n); i++)
{
if(i==p){
continue;
}
if(min>a[i])
min=a[i];
}
return min;
}
int main()
{
int n; scanf("%d", &n); int a[n]; int i;
for(i=0; i<n; i++)
scanf("%d", &a[i]);
if(n==2){
printf("0"); return 0;
}
int min=a[0],max=a[0],s=0,t=0;
for(i=1; i<n; i++)
{
if(min>a[i])
{ min=a[i];s=i;}
if(max<a[i])
{ max=a[i];t=i;}
}
int smax=sec_max(a,n,t);
int smin=sec_min(a,n,s);
if((max-smin)<(smax-min))
printf("%d\n", (max-smin));
else
printf("%d\n", (smax-min));
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 471d0a72a871bed4c40db932ebc6213d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include <stdio.h>
int main()
{
int min1 = 100001, min2 = 100001, max1 = 0, max2 = 0;
int n, m;
scanf("%d", &n);
while (n--) {
scanf("%d", &m);
if (m < min1) {
min2 = min1;
min1 = m;
}
else {
if (m < min2)
min2 = m;
}
if (m > max1) {
max2 = max1;
max1 = m;
}
else {
if (m > max2)
max2 = m;
}
}
printf("%d", max2 - min1 < max1 - min2? max2 - min1:max1-min2);
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 93be770b0a54b839d0307a710da8efe6 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include<stdio.h>
int main()
{
int min1=0,max1=0,max2=0,n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int min2=1000000;
for(int i=0;i<n;i++)
{
if(a[i]>a[max1])
{
max1=i;
}
if(a[i]<a[min1])
{
min1=i;
}
}
for(int i=0;i<n;i++)
{
if(a[i]>max2 && a[i]<=a[max1] && i!=max1)
{
max2=a[i];
}
if(a[i]<min2 && a[i]>=a[min1] && i!=min1)
{
min2=a[i];
}
}
if((a[max1]-min2)<(max2-a[min1]))
{
printf("%d\n",a[max1]-min2);
}
else printf("%d\n",max2-a[min1]);
return 0;
}
| |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 88ab76633f9e8bf029196ace16a26a7b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int minimum(int a, int b) {
if (a < b) {
return a;
}
return b;
}
int main(void) {
int n, i, *a, max, min, new_max, new_min;
scanf("%d",&n);
a = (int*)malloc(sizeof(int)*n);
assert(a);
for (i = 0; i < n && scanf("%d",&a[i]); i++);
max = 0;
new_max = 1;
if (a[new_max] > a[max]) {
i = max;
max = new_max;
new_max = i;
}
for (i = 2; i < n; i++) {
if (a[i] > a[max]) {
new_max = max;
max = i;
} else if (a[i] > a[new_max]) {
new_max = i;
}
}
min = 0;
new_min = 1;
if (a[new_min] < a[min]) {
i = min;
min = new_min;
new_min = i;
}
for (i = 2; i < n; i++) {
if (a[i] < a[min]) {
new_min = min;
min = i;
} else if (a[i] < a[new_min]) {
new_min = i;
}
}
printf("%d",minimum(a[new_max]-a[min],a[max]-a[new_min]));
free(a);
return 0;
} | |
You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability. | Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$. | C | 2eb7234904b28b4793b7c482a2370092 | 2bc2e7c0f81e7ccec831a2139be2e110 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["4\n1 3 3 7", "2\n1 100000"] | NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly. | PASSED | 900 | standard input | 1 second | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$. | ["2", "0"] | #include<stdio.h>
int main(void)
{
int i,n,x,y,min,min1=100000,max=-1,max1=-1,result;
scanf("%d",&n);
int array[n];
for(i=0;i<n;i++)
{
scanf("%d",&array[i]);
if(!i)
min=array[i];
else if(min>array[i])
{
if(min1>min)
min1=min;
min=array[i];
}
else if(min1>array[i])
min1=array[i];
if(max<array[i])
{
if(max1<max)
max1=max;
max=array[i];
}
else if(max1<array[i])
max1=array[i];
}
x=max-min1;
y=max1-min;
result=x<y?x:y;
printf("%d\n",result);
return 0;
}
| |
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it). | For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea. | C | 471f80e349e70339eedd20d45b16e253 | cf98f30a1ee53d446901fdfa3ce33974 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1517582100 | ["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"] | NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1. | ["1 2 \n1 0 2"] | #include <stdio.h>
int main()
{
int n,t,i,j,l,r,time;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&n);
scanf("%d %d",&l,&r);
time=l;
printf("%d\n",time);
for(j=1;j<n;j++)
{
scanf("%d %d",&l,&r);
if(l>time)
{
time=l;
printf("%d\n",time);
}
else if(time<r)
{
time++;
printf("%d\n",time);
}
else printf("0\n");
}
}
return 0;
}
| |
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it). | For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea. | C | 471f80e349e70339eedd20d45b16e253 | 930edd42b0c2152001baf8c2de891ee2 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1517582100 | ["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"] | NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | PASSED | 1,200 | standard input | 1 second | The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1. | ["1 2 \n1 0 2"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
int main()
{
int test_cases,n,j,k;
int L,r,seconds;
scanf("%d",&test_cases);
for(k=0;k<test_cases;k++)
{
scanf("%d",&n);
seconds=0;
for(j=0;j<n;j++)
{
scanf("%d %d",&L,&r);
if(seconds>r)
printf("%d ",0);
else
{
if(seconds<L)
seconds=L;
printf("%d ",seconds);
seconds++;
}
}
printf("\n");
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.