akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

//#define TEST

int l; // number of stones
string s;

int Judge(int i) {
	if (s[i] == 'W' || s[i] == 'B') return -1;
	int left_index = i - 1;
	while (left_index >= 0 && s[left_index] == 'W') {
		--left_index;
	}
	bool left = (left_index < 0) ? false : ((s[left_index] == '.') ? false : true);
#ifdef TEST
	cout << "i = " << i << endl;
	cout << left << " " << left_index << endl;
#endif
	int right_index = i + 1;
	while (right_index < l && s[right_index] == 'W') {
		++right_index;
	}
	bool right = (right_index >= l) ? false : ((s[right_index] == '.') ? false : true);
#ifdef TEST
	cout << right << " " << right_index << endl;
#endif
	if (left && right) return -1;
	int score = 0;
	if (i > 0 && s[i - 1] == 'B') {
		int idx = i - 1;
		while (idx >= 0 && s[idx] == 'B') {
			--idx;
		}
		if (idx >= 0 && s[idx] == 'W') {
			score = max(score, i - idx - 1);
		}
	}
	if (i < l - 1 && s[i + 1] == 'B') {
		int idx = i + 1;
		while (idx < l && s[idx] == 'B') {
			++idx;
		}
		if (idx < l && s[idx] == 'W') {
			score = max(score, idx - i - 1);
		}
	}
#ifdef TEST
	cout << score << endl;
#endif
	return score;
}


signed main() {
	cin >> l >> s;
	int ans = 0;
	for (int i = 0; i < l; ++i)
		ans = max(ans, Judge(i));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3200
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

A,B,C,D = (int(i) for i in input().split())

hogeb = B // D
hogec = B // C
hogebc = B // lcm(D,C)

hoge = B-(hogeb + hogec -hogebc)

ononb = (A-1) // D
ononc = (A-1) // C
ononbc = (A-1) // lcm(D,C)

onon = A-1-(ononb + ononc - ononbc)

print(hoge-onon)


Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


const MOD: i64 = 1000000000 + 7;

use std::iter::Enumerate;

fn solve(mut a: Vec<i64>) ->  i64 {
    let n = a.len();
    a.sort();
    if n == 1 {
        if a[0] == 0 {
            return 1;
        } else {
            return 0;
        }
    }

    let rem = n as i64 % 2;
    let not_rem = (rem + 1) % 2;
    for (exp, i) in a.iter().enumerate() {
        let exp = 2 * ((exp as i64 + rem) / 2) + not_rem;
        if exp != *i {
            return 0;
        }
    }

    let mut res = 1;
    for _ in 0..n/2 {
        res *= 2;
        res %= MOD;
    }
    res
}


fn main() {
    input!(
        n: usize,
        a: [i64; n],
        );
    println!("{}", solve(a));
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	int n,m;
	cin>>n>>m;
	int s[m],c[m];
	for(int i = 0; i < m; i++){
		cin>>s[i]>>c[i];
	}
	if(n == 1){
		int w = 10;
		for(int i = 0; i < m; i++){
			if(w != c[i] && w == 10){
				w = c[i];
			}
			else if(w != c[i] && w != 10){
				cout<<"-1"<<endl;
				return 0;
			}
		}
		if(w == 10) w = 0;
		cout<<w<<endl;
		return 0;
	}
	int ans[n];
	for(int i = 0; i < n; i++) ans[i] = 10;
	for(int i = 0; i < m; i++){
		if(s[i] == 1 && c[i] == 0){
			cout<<"-1"<<endl;
			return 0;
		}
		else if(ans[s[i]-1] == 10){
			ans[s[i]-1] = c[i];
		}
		else if(ans[s[i]-1] != c[i]){
			//cout<<"ans[s[i]-1] = "<<ans[s[i]-1]<<endl;
			//cout<<"s[i] = "<<s[i]<<endl;
			//cout<<"c[i] = "<<c[i]<<endl;
			cout<<"-1"<<endl;
			return 0;
		}
	}
	
	if(ans[0] == 10 && n != 1) ans[0] = 1;
	else if(ans[0] == 10 && n == 1) ans[0] = 0;
	for(int i = 1; i < n; i++){
		if(ans[i] == 10) ans[i] = 0;
	}
	for(int i = 0; i < n; i++){
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int unused __attribute__((unused));
  int i, N, *A, kijun;
  long long sum = 0;
  unused = scanf("%d", &N);
  A = malloc(sizeof(int)*N);
  for(i=0; i<N; i++) unused = scanf("%d", &A[i]);

  if(N > 1){
    kijun = A[0];
    for(i=1; i<N; i++){
      if(A[i] < kijun){
        sum += kijun-A[i];
      }else{
        kijun = A[i];
      }
    }
  }
  printf("%lld", sum);
  free(A);
  return 0;
}

Measured memory_bytes: 2244
#include<cstdio>
#include<cmath>
int main(){
  double x1,y1,x2,y2;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  printf("%.7f\n",sqrt(pow(x2-x1,2)+pow(y2-y1,2)));
}


Measured memory_bytes: 2752
/*
g++ -std=c++11 -o2 -Wall ABC095D.cpp -o ./out/ABC095D.out
./out/ABC095D.out
*/

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i=0; i<n; ++i)
#define FOR(i, a, b) for(int i=a; i<b; ++i)
#define FORR(i, a, b) for(int i=b-1; i>=a; --i)

typedef long long ll;

ll x[110000], v[110000], s[110000], a1[110000], a2[110000], b1[110000], b2[110000];
ll ans;

int main(){
//    freopen("./input/input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll c;
    cin>>n>>c;
  	REP(i, n){
  		cin>>x[i+1]>>v[i+1];
  		s[i+1]=s[i]+v[i+1];
  		a1[i+1]=max(a1[i], s[i+1]-x[i+1]);
  		a2[i+1]=max(a2[i], s[i+1]-x[i+1]*2);
  	}
  	FORR(i, 1, n+1){
  		b1[n-i+1]=max(b1[n-i], s[n]-s[i-1]-(c-x[i]));
  		b2[n-i+1]=max(b2[n-i], s[n]-s[i-1]-(c-x[i])*2);
  	}
  	REP(i, n+1) ans=max(ans, max(a1[i]+b2[n-i], a2[i]+b1[n-i]));
  	cout<<ans<<'\n';
  	return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
int main(){
		int a,b,c,count;
		cin >> a >> b >> c;
		for (int i = a; i < b+1; ++i)
		{
			if(c%i==0){
				count++;
			}
			/* code */
		}
		cout << count << endl;
}


Measured memory_bytes: 3120
#111
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=Counter(v[0::2]).most_common()
R=Counter(v[1::2]).most_common()


if L[0][0]!=R[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[1][1]-L[0][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[0][1]-L[1][1]
elif len(R)==1 and len(L)==1:
    ans=n//2
print(ans)    


Measured memory_bytes: 20700
#include <cstdio>
#include <algorithm>
int main() {
	int n;
	scanf("%d", &n);
	
	int s[2*n];
	
	for(int i = 0; i < 2 * n; i++) {
		scanf("%d", &s[i]);
	}
	
	std::sort(s, s + 2 * n);
	
	int sum = 0;
	
	for(int i = 0; i < 2 * n; i += 2) {
		sum += s[i];
	}
	
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  int max = -1;
  int min = 1001;
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    if (a < min)
      min = a;
    if (a > max)
      max = a;
  }
  std::cout << max - min << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair 
#define inf 100000001
using namespace std;

int X[4]={0,1,0,-1};
int Y[4]={-1,0,1,0};

int M(char c){
  if(c=='^')return 0;
  if(c=='>')return 1;
  if(c=='v')return 2;
  if(c=='<')return 3;
}

int main()
{
  int a,b,muki,gi,gj,h,w;
  char map[52][52];
  bool tap[52][52]={},table[52][52][4]={};
  for(int i=0;i<52;i++){
    for(int j=0;j<52;j++){
      map[i][j]='#';
      tap[i][j]=false;
      for(int k=0;k<4;k++)table[i][j][k]=false;
    }
  }
  cin>>h>>w;
  h++;w++;
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      cin>>map[i][j];
      if(map[i][j]=='G'){
        gi=i;
	gj=j;
	map[i][j]='.';
      }
      else if(map[i][j]!='.' && map[i][j]!= '#'){
	a=i;
	b=j;
	muki=M(map[i][j]);
	map[i][j]='.';
      }
    }
  }
  int ans=0;
  table[a][b][muki]=true;
  tap[a][b]=true;
  while(1){
    if(map[a+Y[(muki+1)%4]][b+X[(muki+1)%4]]!='#'){
      muki=(muki+1)%4;
      a+=Y[muki];b+=X[muki];
    }
    else if(map[a+Y[muki]][b+X[muki]]!='#'){
      a+=Y[muki];b+=X[muki];
    }
    else if(map[a+Y[(muki+3)%4]][b+X[(muki+3)%4]]!='#'){
      muki=(muki+3)%4;
      a+=Y[muki];b+=X[muki];
    }
    else if(map[a+Y[(muki+2)%4]][b+X[(muki+2)%4]]!='#'){
      muki=(muki+2)%4;
      a+=Y[muki];b+=X[muki];
    }
    tap[a][b]=true;
    if(table[a][b][muki]){
      ans=-1;
      break;
    }
    if(a==gi && b==gj)break;
    table[a][b][muki]=true;
  }
  if(ans!=-1){
    for(int i=1;i<52;i++){
      for(int j=1;j<52;j++)if(tap[i][j])ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  ll N, A, B; cin >> N >> A >> B;
  ll X[N]; rep(i,N) cin >> X[i];

  ll ans = 0;
  rep(i,N-1){
    ans += min((X[i+1]-X[i])*A,B);
  }
  cout << ans << endl;

 

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin >> n;

    long long int arr[n];
    unsigned long long int c = 1;

    int zero = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i]==0){
            zero++;
        }
    }
    if(zero > 0){
        cout << 0 <<endl;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        unsigned long long int d;
        d = c;
        c *= arr[i];
         if( d > c){
            cout << -1 <<endl;
            return 0;
        }
    }
    if (c > 1000000000000000000)
    {
        cout << -1 << endl;
        return 0;
    }
    else
    {
        printf("%lld\n", c);
    }
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>n>>l;
    int sum=0;
    if(l>0) sum = ((l+1)+(l+n-1))*(n-1)/2;
    else if(l<1-n) sum = ((l)+(l+n-2))*(n-1)/2;
    else sum = ((l)+(l+n-1))*n/2;
    cout << sum <<endl;
}


Measured memory_bytes: 764
#include<stdio.h>

int f(int d){
	int i;
	int s=0;
	for(i=d;i<600;i+=d){
		s+=i*i*d;
	}
	return s;
}
int main(void){
	int d;
	

	while(scanf("%d",&d)!=EOF){
		printf("%d\n",f(d));
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
int main()
{
    int i,j,l,flag=0;
    char s[500],t[500],a,b;
    scanf("%s%s",s,t);
    l=strlen(s);
    if(!strcmp(s,t)) {
        printf("Yes\n");
        flag=1;
    }
    else {
        for(i=1;i<l;i++){
            a=s[0];
            for(j=0;j<l;j++){
                if(j==l-1){
                    b =s[0];
                    s[0]=a;
                    a=b;
                }
                else {
                    b=s[j+1];
                    s[j+1]=a;
                    a=b;
                }
            }
            if(!strcmp(s,t)) {
                printf("Yes\n");
                flag=1;
                break;
            }
        }
    }
    if(flag==0) printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N;
    cin >> N;

    int sum = 0;

    REP(i, N + 1) {
        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        }
        sum += i;
    }
    cout << sum;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3640
n = int(input())
INFTY = 10**5
WHITE = 0
GRAY = 1
BLACK = 2

A = [[ int(row) if row != "-1" else INFTY for row in input().split()] for i in range(n)]

def prim(A, st):
    colors = [WHITE] * n
    colors[st] = BLACK
    T = [st]
    total_weights = 0
    
    while len(T) < n:
    
        current_min = INFTY
        next_add = st
        for node_inT in T:
            for v in range(n):
                if colors[v] == WHITE and A[node_inT][v] < current_min:
                    current_min = A[node_inT][v]
                    next_add = v

        total_weights += current_min
        T.append(next_add)
        colors[next_add] = BLACK
    
    return total_weights

MST = [0] * n
for i in range(n):
    MST[i] = prim(A, i)

print(min(MST))


Measured memory_bytes: 5716
#include<cstdio>
int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A+B>=C)
		printf("Yes\n");
	else printf("No\n");
}/*
由于最后的结果是三个值相加 当所有数全为正数时 只需把每一个蛋糕的
三个值相加 计算出贡献 贪心地取最大就可以了
而数中有负数 则枚举一下每个值的正负性 再计算贡献

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 1005
int N,M,ans;
int x[MAXN],y[MAXN],z[MAXN],r[MAXN];
bool cmp(int p,int q)
{
	return p>q;
}
void Solve(int m,int n,int k)
{
	memset(r,0,sizeof(r));
	int res=0;
	for(int i=1;i<=N;i++)
	{
		if(m*x[i]>0) r[i]+=x[i];
			else r[i]-=x[i];
		if(n*y[i]>0) r[i]+=y[i];
			else r[i]-=y[i];
		if(k*z[i]>0) r[i]+=z[i];
			else r[i]-=z[i];
	}
	sort(r+1,r+N+1,cmp);
	for(int i=1;i<=M;i++)
		res+=r[i];
	if(res>ans) ans=res;
}
int main()
{
	scanf("%d %d",&N,&M);
	for(int i=1;i<=N;i++)
		scanf("%d %d %d",&x[i],&y[i],&z[i]);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=2;j++)
			for(int k=1;k<=2;k++)
				Solve(i,j,k);
	printf("%d\n",ans);
}*/

Measured memory_bytes: 128
#include <stdio.h>

int gcd(int a, int b)
{
	if (!b){
		return (a);
	}
	return (gcd(b, a % b));
}

int main(void)
{
	int a, b;
	
	while (scanf("%d%d", &a, &b) != EOF){
		if (a < b){
			a ^= b;
			b ^= a;
			a ^= b;
		}
		
		printf("%d\n", gcd(a, b));
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int h,w,k;
   cin >> h >> w >> k;
   char c[h][w];
   rep(i,h){
      rep(j,w){
         cin >> c[i][j];
      }
   }
   int ans=0;
   rep(maskR,1<<h){
      rep(maskC,1<<w){
         int black=0;
         rep(i,h){
            rep(j,w){
               if(((maskR>>i) & 1)==0 && ((maskC>>j) & 1)==0 
            && c[i][j]=='#'){
               black++;
            }
            }
         }
         if(black==k){
            ans++;
         }
      }
   }

   cout << ans << endl;
   return 0;  
}

Measured memory_bytes: 3600
import java.util.HashSet;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.IntStream;

public class Main {
    
    private static class Target {
        private final int h;
        private final int w;
        
        private Target(int h, int w) {
            this.h = h;
            this.w = w;
        }
        
        @Override
        public boolean equals(Object o) {
            if (o instanceof Target) {
                Target t = (Target) o;
                return h == t.h && w == t.w;
            }
            return false;
        }
        
        @Override
        public int hashCode() {
            return Objects.hash(h, w);
        }
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int H = sc.nextInt();
        final int W = sc.nextInt();
        final int M = sc.nextInt();
        
        int[] hCount = new int[H];
        int[] wCount = new int[W];
        
        Set<Target> targets = new HashSet<>();
        for (int i = 0; i < M; i++) {
            int h = sc.nextInt() - 1;
            int w = sc.nextInt() - 1;
            hCount[h]++;
            wCount[w]++;
            targets.add(new Target(h, w));
        }
        
        int hMaxCount = IntStream.of(hCount).max().getAsInt();
        int wMaxCount = IntStream.of(wCount).max().getAsInt();
        Set<Integer> maxHs = new HashSet<>();
        Set<Integer> maxWs = new HashSet<>();
        for (int h = 0; h < H; h++) {
            if (hCount[h] == hMaxCount) {
                maxHs.add(h);
            }
        }
        for (int w = 0; w < W; w++) {
            if (wCount[w] == wMaxCount) {
                maxWs.add(w);
            }
        }
        
        boolean exists = maxHs.stream().flatMap(h -> maxWs.stream().map(w -> new Target(h, w)))
                .filter(Predicate.not(targets::contains))
                .findAny().isPresent();
        
        System.out.println(exists ? hMaxCount + wMaxCount : hMaxCount + wMaxCount - 1);
    }
}


Measured memory_bytes: 114988
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        if (2 * n >= m) {
            System.out.println(m/2);
            return;
        }

        m -= 2 * n;
        long div = m/4;
        System.out.println(n + div);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 1e9+7;
 
string to_string(char &c) {string x(1, c); return x;}
string to_string(const char s[]) {return (string)s;}
string to_string(string &s) {return s;}
string to_string(vb &v) {string res; for (const bool &x : v) res += to_string(x) + ' '; return res;}
template <class C> string to_string(C &v) {string res; for (auto &x : v) res += to_string(x) + ' '; return res;}
template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int k, n;
    cin >> k >> n;
    vi a(n);
    cin >> a;
    int sm = accumulate(a.begin(), a.end(), 0LL);
    if (k <= sm) print("Yes");
    else print("No");
}

Measured memory_bytes: 1024
n = gets.chomp.to_i
arr = gets.chomp.split()
q = gets.chomp.to_i

ans = arr.inject do |result, item|
  result = result.to_i + item.to_i
end

ans = ans.to_i if ans.kind_of?(String)

nums = Hash.new(0)
arr.each do |i|
  nums[i.to_s] += 1
end

q.times do
  bef, af = gets.chomp.split()
  apper_times = nums[bef]
  ans += (af.to_i - bef.to_i) * apper_times
  nums[bef] -= apper_times
  nums[af] += apper_times
  puts ans
end


Measured memory_bytes: 33548
#!/usr/bin/env python3
#A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = str(n)
if int(s[-1]) in [2, 4, 5, 7, 9]:
    print('hon')
elif int(s[-1]) in [0, 1, 6, 8]:
    print('pon')
elif int(s[-1]) == 3:
    print('bon')
    

Measured memory_bytes: 65496
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    string s,t;
    cin >> n >> s >> t;
    int id = 0;
    while(id < n){
        if(s.substr(id,n - id) == t.substr(0, n - id)){
            break;
        }else id++;
    }
    int ans =  n*2 - s.substr(id,n - id).size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    int x=0,y=0;
    for(int i=0;i<b;i++){
        x += a*pow(10,i);
    }
    for(int i=0;i<a;i++){
        y += b*pow(10,i);
    }

    if(a<b){
        cout << x << endl;
    }else{
        cout << y << endl; 
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define pp pair<ll,ll>
#define mp make_pair
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define pb push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FREV(i,a,b) for(i=a;i>=b;i--)
#define FORI(a) for(auto it=a.begin();it!=a.end();it++)
#define READ(a,i,n) FOR(i,0,n) { sll(a[i]);}
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
#define sll(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define INF 1e18
#define MOD 1000000007

using namespace std;
int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d;
   cin>>a>>b>>c>>d;
   ll a1,a2,a3,a4;
  a1=a*c;
  a2=a*d;
  a3=b*c;
  a4=b*d;
  cout<<max(max(a1,a2),max(a3,a4))<<"\n";
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

#define INF 1e9

int min(int a, int b){ return a < b ? a : b; }

int main(void){
  while(true){
    int N, M, L, K, A, H;
    cin >> N >> M >> L >> K >> A >> H;
    if(N == 0 && M == 0 && L == 0 && K == 0 && A == 0 && H == 0){ break; } 

    // ??????????¨?????????????????????±???????????????
    int cool_;
    vector<bool> cool(N, false);
    cool[A] = cool[H] = true;
    for(int i = 0; i < L; i++){
      cin >> cool_;
      cool[cool_] = true;
    }

    // ???????????±???????????????
    int x, y, t;
    vector<vector<int> > adjmatrix(N, vector<int>(N, INF));
    for(int i = 0; i < K; i++){
      cin >> x >> y >> t;
      adjmatrix[x][y] = adjmatrix[y][x] = t;
    }
    for(int i = 0; i < N; i++){ adjmatrix[i][i] = 0; }

    // ???????????£?????????????????????????????°????????????????????????????????´??\????????????
    for(int k = 0; k < N; k++)
      for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
          adjmatrix[i][j] = min(adjmatrix[i][j], adjmatrix[i][k] + adjmatrix[k][j]);

    // ?????´????¨?????????????????????£??\???????????????
    vector<vector<int> > cooladj(N, vector<int>(N, INF));
    for(int i = 0; i < N; i++){
      // ????????????????????´????¨???????????????£???????????????
      if(!cool[i]){ continue; }
      for(int j = 0; j < N; j++){
        // ?????????????????´????¨???????????????£?????? or ?????????????????????????????£???????????????
        if((i == j) || (!cool[j]) || (adjmatrix[i][j] > M)){ continue; }
        cooladj[i][j] = adjmatrix[i][j];
      }
    }

    // ???????????£???
    for(int k = 0; k < N; k++)
      for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
          cooladj[i][j] = min(cooladj[i][j], cooladj[i][k] + cooladj[k][j]);

    // ???????????????
    if(cooladj[A][H] == INF){ cout << "Help!" << endl; }
    else if(cooladj[A][H] <= M){ cout << cooladj[A][H] << endl; }
    else{ cout << cooladj[A][H] + (cooladj[A][H] - M) << endl; }    
  }

  return 0;
}

Measured memory_bytes: 1304
int w,h,X,Y,C,t,b,d[9][9],q[9][9],a[]={-1,0,1,0};

Z(x,y){
	int i=0,s=1;
	if(q[y][x])return 0;
	q[y][x]=1;
	if(d[y][x])return y==Y&&x==X;
	for(;i<4;i++)s+=Z(x+a[i],y+a[(i+1)%4]);
	return s;
}
B(int x,int y,int c){
	int i=0;
	if(!(c||x-X||y-Y))return 1;
	memset(q,0,324);
	if(d[y][x]||Z(x,y) != c+(x-X||y-Y))return 0;
	if(b++> 120000)return 2;
	for(d[y][x]=1;i<4;i++)if(t=B(x+a[i],y+a[(i+1)%4],c-1))return t;
	return d[y][x]=0;
}
main(i,j){
	for(;C=b=j=0,memset(d,-1,324),scanf("%d%d\n",&w,&h),h;puts(C<4||B(X,Y,C)-1?"No":"Yes"))
		for(;j++<h;)for(i=0;i++<w;)scanf("%d",&t),(d[j][i]=t)||(++C,X=i,Y=j);
	exit(0);
}

Measured memory_bytes: 384
/**
     *      ABC 71 C
     *      author  : kyomukyomupurin
     *      created : 2018-09-06 09:05:31
    **/
     
    #include <bits/stdc++.h>
    using namespace std;
     
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        
        int N; cin >> N;
        int A[N] = {};
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        sort(A, A + N, greater<int>());
     
        int point1 = -1; int point2 = -1;
        long long len1, len2;
        for (int i = 0; i < N - 1; ++i) {
            if (A[i] == A[i + 1]){
                point1 = i; len1 = A[i]; break;
            }
        }
        if (point1 < 0){
            cout << 0 << endl;
            return 0;
        }
        for (int i = point1 + 2; i < N - 1; ++i) {
            if (A[i] == A[i + 1]){
                point2 = i; len2 = A[i]; break;
            }
        }
        if (point2 < 0){
            cout << 0 << endl;
            return 0;
        }    
        long long answer = len1 * len2;
        cout << answer << endl;
     
        return 0;
    }

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

#ifdef LOCAL  //デバッグ出力
#define dout cout
#define debug() if (true)
#else
#define dout \
  if (false) cout
#define debug() if (false)
#endif

using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22) {
    cout << "bust";
  } else {
    cout << "win";
  }

  return 0;
}

Measured memory_bytes: 256
n,m = list(map(int,input().split()))

p = [0]*(m)
y = [0]*(m)

for i in range(0,m):
    p[i],y[i] = list(map(int,input().split()))

b = [[p[i],y[i]] for i in range(0,m)]

a = sorted(b)
num = {}
count = 1
num[a[0][1]] = 1

for i in range(1,m):
    if a[i-1][0] == a[i][0]:
        count += 1
    else:
        count = 1    
    num[a[i][1]] = count

for i in range(0,m):
    z1 = 6 - len(str(b[i][0]))
    z2 = 6 - len(str(num[b[i][1]]))
    print("0"*z1 + str(b[i][0]) + "0"*z2 + str(num[b[i][1]]))

Measured memory_bytes: 34080
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int mini = 1e12;
	for(int i = 1; i <= 100; i++){
		int val = 0;
		for(int j = 0; j < n; j++){
			val += (a[j]-i)*(a[j]-i);
		}
		mini = min(val,mini);
	}
	cout << mini << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
   ll k;
   ll n;
   cin>>k>>n;
   ll a[n];
   for(int x=0;x<n;x++)
   {
       cin>>a[x];
   }
   sort(a,a+n);
   ll an=min(a[n-1]-a[0],k-a[0]-(k-a[n-1]));
   for(int x=0;x<n-1;x++)
   {
       an=min(k-(a[x+1]-a[x]),an);
   }
   cout<<an;
}
int main()
{
  ll t=1;
 // cin>>t;
  while(t--)
  {
    solve();
  }
}


Measured memory_bytes: 1792
import random

D = int(input())
C = [*map(int, input().split())]
S = [[*map(int, input().split())] for _ in range(D)]

O = [[0]*26 for _ in range(D)]
A = [[0]*26 for _ in range(D)]

def last(d,t):
    for i in range(d,-1,-1):
        if O[i][t] > 0: return i
    return 0

T = []
t = 0
for d in range(D):
    t = int(random.uniform(1,27))
    T.append(t)

print(*T,sep='\n')

# score = 0
# t = 0
# for d in range(D):
#     t = T[d] - 1
#     O[d][t] = 1
#     dw = 0
#     for i in range(26):
#         dw += C[i]*((d+1) - last(d,i))
#     A[d][t] = S[d][t] - dw
#     score += A[d][t]
#     # print(score)

# for _ in range(10000000):



#         score = 0
#         t = 0
#         for d in range(D):
#             t = T[d] - 1
#             O[d][t] = 1
#             dw = 0
#             for i in range(26):
#                 dw += C[i]*((d+1) - last(d,i))
#             A[d][t] = S[d][t] - dw
#             score += A[d][t]


Measured memory_bytes: 9824
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String T = sc.next();
		String P = sc.next();
		
		for(int i = 0; i < T.length() - P.length() + 1; i++) {
			if(T.substring(i, i + P.length()).equals(P)) {
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 26408
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    n, m = map(int, input().split())
    # https://atcoder.jp/contests/abc156/submissions/11621672
    def modpow(a, b, mod=10 ** 9 + 7):
        ret = 1
        while b > 0:
            if b % 2 == 1:
                ret = ret * a % mod
            a = a * a % mod
            b //= 2
        return ret


    def modcomb(n, c, mod=10 ** 9 + 7):
        if n<c:
            return 0
        if c > n - c:
            c = n - c
        u, d = 1, 1
        for i in range(c):
            u = u * (n - i) % mod
            d = d * (i + 1) % mod
        return u * modpow(d, mod - 2) % mod


    """mod = 10 ** 9 + 7
    n, a, b = map(int, input().split())
    ans = (modpow(2, n) - 1) % mod
    ans = (ans-modcomb(n, a)) % mod
    ans = (ans-modcomb(n, b)) % mod
    print(ans)"""

    # combどうしの積をとると余りがずれるので避ける！　普通のcombを計算して最後にmodをとって。

    import math

    # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f
    def make_prime_list_2(num):
        if num < 2:
            return []

        # 0のものは素数じゃないとする
        prime_list = [i for i in range(num + 1)]
        prime_list[1] = 0  # 1は素数ではない
        num_sqrt = math.sqrt(num)

        for prime in prime_list:
            if prime == 0:
                continue
            if prime > num_sqrt:
                break

            for non_prime in range(2 * prime, num, prime):
                prime_list[non_prime] = 0

        return [prime for prime in prime_list if prime != 0]

    def prime_factorization_2(num):
        """numの素因数分解
        素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""

        if num == 1:
            return False
        else:
            num_sqrt = math.floor(math.sqrt(num))
            prime_list = make_prime_list_2(num_sqrt)

            dict_counter = {}  # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
            # cf. https://atcoder.jp/contests/arc034/submissions/12251452

            for prime in prime_list:
                while num % prime == 0:
                    if prime in dict_counter:
                        dict_counter[prime] += 1
                    else:
                        dict_counter[prime] = 1
                    num //= prime
            if num != 1:
                if num in dict_counter:
                    dict_counter[num] += 1
                else:
                    dict_counter[num] = 1

            return dict_counter

    ans = 1
    if not prime_factorization_2(m):
        print(1)
    else:
        d = prime_factorization_2(m)
        mod = 10 ** 9 + 7

        for k, v in d.items():
            ans = ans * modcomb(v + n - 1, n - 1)
        print(ans % mod)


resolve()

Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long  int a , b , c , d ;
	cin >> a >> b >> c >> d ;
	long long int x  = 0, y = 0 ;
	long long int  u = 0 , v = 0;
	if(a>0&&b>0&&c>0&&d>0){
	x =  max(a,b);
	y = max(c,d);
	cout <<  x*y ;
}
	else{
		x = a*c;
		u  = a*d;
		y = b*c;
		v = b*d;
		x =  max(x,u);	
		y = max(y,v);
		if(x>y){
			cout << x ;
		}
		else{
			cout <<  y ;
		}
	}
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;

int main() {
  stack<int> s;
  int n;
  while (cin >> n) {
    if (n == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(n);
    }
  }
  return 0;
}



Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0533

int main() {
	int a[10], b[10];
	for (int i = 0; i < 10; i++) cin >> a[i];
	for (int i = 0; i < 10; i++) cin >> b[i];
	sort(a, a + 10);
	sort(b, b + 10);
	cout << (a[7] + a[8] + a[9]);
	cout << " ";
	cout << (b[7] + b[8] + b[9]) << endl;
	return 0;
}

Measured memory_bytes: 1180
n=int(input())
uvw=[list(map(int,input().split())) for _ in range(n-1)]
uvw=[[u-1,v-1,w] for u,v,w in uvw]

z=[[] for _ in range(n)]
for u,v,w in uvw:
    z[u].append([u,v,w%2==0])
    z[v].append([v,u,w%2==0])
from collections import deque
que=deque([])
res=[-1 for _ in range(n)]
res[0]=0
for t in z[0]:
    que.append(t)

visited=[False for _ in range(n)]
visited[0]=True

while que:
    u,v,w=que.pop()
    if w:
        if res[u]>=0 and res[v]<0:
            res[v]=res[u]
        elif res[v]>=0 and res[u]<0:
            res[u]=res[v]
    else:
        if res[u]==0:
            res[v]=1
        elif res[u]==1:
            res[v]=0
        elif res[v]==0:
            res[u]=1
        elif res[v]==1:
            res[u]=1
    if visited[v]==False:
        visited[v]=True
        for t in z[v]:
            que.append(t)
for t in res:
    print(t)

Measured memory_bytes: 118744
#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;

    string es = "";
    for (int i=1; i<=s.size(); ++i) {
        if (i%2 == 1) es.push_back(s[i-1]);
    }

    cout << es << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long n,t,c,arr[1000004],i,d,ans[1000004]; 
int main()
{
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&arr[i]);
    }
    for(i=1;i<n;i++)
    {
        if(i==1)
        {
            ans[i]=abs(arr[i]-arr[0]);
        }
        else if(i==2)
        {
            ans[i]=min(ans[i-1]+abs(arr[i]-arr[i-1]),abs(arr[i]-arr[i-2]));
        }
        else
        {
            ans[i]=min(ans[i-1]+abs(arr[i]-arr[i-1]),ans[i-2]+abs(arr[i]-arr[i-2]));
        }
    }
    printf("%lld\n",ans[n-1]);
}

Measured memory_bytes: 5356
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0

int main()
{
#if DEBUG_Switch
	freopen("C:\\code\\input.txt", "r", stdin);
#endif
	//freopen("C:\\code\\output.txt","w",stdout);
	int n;
	cin >> n;
	n %= 1000;
	int ans = 1000 - n;
	ans %= 1000;
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 3624
#include<stdio.h>

int main(){
		int n,i,a[101],ans=0,c=1;
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		for(i=0;i<n-1;i++){
				if(a[i]==a[i+1])c++;
				else {
						ans+=c/2;
						c=1;
				}
		}
		ans+=c/2;
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,m; cin>>n>>m;
  
  vector<pair<int,int>> st(n);
  vector<int> point(n);
  
  vector<pair<int,int>> ch(m);
  
  rep(i,n) {
    ll a,b; cin>>a>>b;
    pair<ll, ll> p;
    p = make_pair(a, b);
    st[i] = p;
  }
   
  rep(i,m) {
    ll c,d; cin>>c>>d;
    pair<ll, ll> p;
    p = make_pair(c, d);
    ch[i] = p;
  }
  
  rep(i,n) {
    pair<ll, ll> stp = st[i];
    ll mandiss = 10000000000;
    int dissnum = 100;
    rep(j,m) {
      pair<ll, ll> chp = ch[j];
      ll dis = abs(stp.first - chp.first) + abs(stp.second - chp.second);
      if (dis<mandiss) {
        mandiss = dis;
        dissnum = j+1;
      }
    }
    point[i] = dissnum;
  }
  
  rep(i,n) {
    cout<<point[i]<<endl;
  }
}

Measured memory_bytes: 3612
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

char s[105], t[105];
bool cmp(char a, char b){
	return a > b;
}
int main()
{
	cin >> s >> t;
	sort(s, s + strlen(s));
	sort(t, t + strlen(t), cmp);
	int res = strcmp(s, t);
	if(res < 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

//highlight color RGB = [70,70,70]
#define asll unsigned long long
#define ll long long
#define ld long double
#define imt int
#define pii pair<int,int>
#define st first
#define nd second
#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES "<<x<<endl;
#define psbk(x) push_back(x);
#define For(x,a,b) for(int x=(a);x<(b);x++)
#define FOR(x,n) for(int x=0;x<(n);x++)
#define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml
#define m_p make_pair
asll M=1e9+7;
int n,m,tc;
int p,q,r;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	srand(time(0));
	int a;
	cin>>a;
	cout<<!a<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;

int main()
{
    set<int> sequence;
    
    for( int i = 0 ; i < 3 ; i++){
        int value;
        cin >> value;
        sequence.insert(value);
    }

    int length = sequence.size();
    
    if( length == 2)    cout << "Yes" << endl;
    else                cout << "No" << endl;
   
    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int A, B, C;
	int Biscuit = 0;
	cin >> A >> B >> C;

	double Q = C + 0.5;
	double W = Q / A;

	for (int i = 0; i < W-1; i++) {	
		Biscuit += B;
	}

	cout << Biscuit << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
ans = []
flg = 0
for i in range(N) :
    for j in range(len(A)-1,-1,-1) :
        k = j+1
        if k == A[j] :
            ans.append(k)
            A = A[:j]+A[j+1:]
            break
    else :
        print(-1)
        flg = 1
        break
if not flg :
    print(*ans[::-1],sep="\n")
  
    


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
 
public class Main {
	static ArrayList<Integer>[] g;
	static int n;
	static int[] deg;
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		g = new ArrayList[n];
		deg = new int[n];
		for (int i = 0; i < n; ++i) {
			g[i] = new ArrayList<>();
		}
		for (int i = 1; i < n; ++i) {
			int a = sc.nextInt() - 1;
			g[a].add(i);
			g[i].add(a);
		}
		dfs(0, -1);
		System.out.println(deg[0]);
	}
 
	static void dfs(int cur, int par) {
		if(cur!=0&&g[cur].size()==1){
			deg[cur]=0;
			return;
		}else if(g[cur].size()==0){
			deg[cur]=0;
			return;
		}
		ArrayList<Integer> v = new ArrayList<>();
		for (int dst : g[cur]) {
			if (dst == par)
				continue;
			dfs(dst, cur);
			v.add(deg[dst]);
		}
		Collections.sort(v, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				return -Integer.compare(o1, o2);
			}
		});
		int max = 0;
		for (int i = 0; i < v.size(); ++i) {
			max = Math.max(max, i + v.get(i));
		}
		deg[cur] = max + 1;
	}
 
}

Measured memory_bytes: 96616
s=input()
n=len(s)
mod=10**9+7
dp=[13*[0]for _ in range(n)]
if s[0]=="?":dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
else:dp[0][int(s[0])]=1
for i in range(1,n):
  if s[i]!="?":
    k=int(s[i])
    for j in range(13):
      dp[i][(j*10+k)%13]+=dp[i-1][j]
  else:
    for j in range(13):
      for k in range(10):
        dp[i][(j*10+k)%13]+=dp[i-1][j]
  for j in range(13):dp[i][j]%=mod
print(dp[-1][5])

Measured memory_bytes: 61788
n, m = map(int, input().split())
lis = []
for i in range(m):
    s = list(map(int, input().split()))
    lis.append(s)
p = list(map(int, input().split()))
#print(lis)
ans = 0
for i in range(2**n):
    flg = [False] * n
    for j in range(n):
        if ((i >> j) & 1):
            flg[j] = True
    #print(flg)
    cnt = 0
    for j in range(m):
        val = 0
        for k in range(lis[j][0]):
            if flg[lis[j][k+1]-1] == True:
                val += 1
        if val % 2 == p[j]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,n = 0;
    cin >> a >> b >> c;
    for(int i = a; i <= b; i++){
        if(c % i == 0){
            n++;
        }
    }
    cout << n << endl;

}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
    int A,B;
    cin >> A >> B;

    if ((A+B)%2 == 0){
        cout << (A+B)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using std::cout;
using std::cin;
using std::endl;


int main(void) {
int number;
int count = 1;
cin >> number;
while (number != 0) {
cout << "Case " << count << ": " << number << endl; 
cin >> number;
count ++;
}
return 0;
}

Measured memory_bytes: 3024