akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;
	cin>>n;
	vll l(n);
	rep(i, n){cin>>l[i];}
	sort(all(l));
	ll ans = 0;
	rep(i, n-2){
		for(int j = i+1;j < n-1;j++){
			auto iter = lower_bound(all(l), l[i]+l[j]);
			//auto ite2 = lower_bound(all(l), max(l[i],l[j]));
			//ans += (iter-l.begin()) - (l.end()-ite2) - 1;
			ans += (iter-l.begin()) - (j+1);
			//if()
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
e = gets.split.map(&:to_i)
n.times{ |i|
  puts e.join(" ")
  break if (i == (n-1))
  i.downto(0){ |j|
    e[j],e[j+1] = e[j+1],e[j] if (e[j] > e[j+1])
  }
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

//---------------------------------------------------------------

int main(){
  int N;
  cin>>N;
  vector<ll>a(N);
  rep(i,N){
    cin>>a.at(i);
  }
  ll ans = 0;
  sort(a.begin(),a.end());
  ll count = 1;
  if(N == 1){
    if(a.at(0)==1)ans = 0;
    else ans = 1;
  }else{
  rep(i,N-1){
    if(a.at(i)!=a.at(i+1)){
      if(a.at(i)<count){
        ans+=count-a.at(i);
      }else if(a.at(i)>count){
        ans += count;
      };
      count = 1;
    }else{
      count++;
    }
  }
  if(a.at(N-1)<count){
    ans+=count-a.at(N-1);
  }else if(a.at(N-1)>count){
    ans += count;
  };
  }



cout<<ans<<endl;




}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

def saiki(n,temp,start,ans):
    if n==len(S):
        if start==n:
            ans+=temp
            return ans
        else:
            return ans
    
    ans=saiki(n+1,temp+int(S[start:n+1]),n+1,ans)
    ans=saiki(n+1,temp,start,ans)
    
    return ans


S=input()


print(saiki(0,0,0,0))



Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

void printData(vector<int> A, int N) {
   for(int i = 0; i < N; i++) {
      cout << A[i];
      if(i != N - 1) {
         cout << " ";
      } else {
         cout << endl;
      }
   }
}

int bubbleSort(vector<int> A, int N) {
   int swapNum = 0;
   int flag = 1;
   while(flag) {
      flag = 0;
      for(int j = N - 1; j >= 1; j--) {
         if(A[j] < A[j - 1]) {
            swap(A[j], A[j - 1]);
            swapNum ++;
            flag = 1;
         }
      }
   }
   printData(A, N);

   return swapNum;
}

int main () {
   int N;
   cin >> N;

   vector<int> A;

   for(int i = 0; i < N; i++) {
      int r;
      cin >> r;
      A.push_back(r);
   }

   cout << bubbleSort(A, N) << endl;
}


Measured memory_bytes: 3168
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	string S;
	cin >> S;

	int first = (S[0] - '0') * 10 + (S[1] - '0');
	int second = (S[2] - '0') * 10 + (S[3] - '0');

	if ((first > 12 || first <= 0) && (second > 12 || second <= 0))
	{
		cout << "NA";
	}
	else if ((first <= 12 && first > 0) && (second <= 12 && second > 0))
	{
		cout << "AMBIGUOUS";
	}
	else if (first <= 12 && first > 0)
	{
		cout << "MMYY";
	}
	else if (second <= 12 && second > 0)
	{
		cout << "YYMM";
	}

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    
    parents = [-1] * N
    stack = [0]
    while stack:
        v = stack.pop()
        for e in G[v]:
            if e == 0 or parents[e] >= 0:
                continue
            parents[e] = v
            stack.append(e)
    
    ans = N
    for i in range(1,N):
        if parents[i] > i:
            ans += (parents[i] - i) * (i + 1)
        else:
            ans += (i - parents[i]) * (N - i)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 46676
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        System.out.println((double)((N+1)/2)/(double)N);
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        ll ans = 0;
        rep(i, 0, 101) {
                if (A <= i and i <= B and C <= i and i <= D) ++ans;
        }
        cout << max(0LL, ans-1) << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if (s.at(0)=='7'||s.at(1)=='7'||s.at(2)=='7') {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 1000000007
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
    
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> vn(n);
	REP(i,n){
		cin>>vn.at(i);
	}
	int ans=0;
	REP(l,n+1){
		REP(r,n+1){
			if(l+r>k) break;
			if(l+r>n) break;
			vector<int> a;
			REP(i,l){
				a.push_back(vn.at(i));
			}
			REP(i,r){
				a.push_back(vn.at(n-1-i));
			}
			int res=k-l-r;
			sort(ALL(a));
			REP(i,res){
				if(i>=SZ(a)) break;
				if(a.at(i)>0) break;
				a.at(i)=0;
			}
			int sum=0;
			REP(i,SZ(a)){
				sum+=a.at(i);
			}
			ans=max(ans,sum);
		}
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
#define LANCER_SHARK { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
using namespace std;


//int a[200007], b[200007];
int main(){
	LANCER_SHARK;
	ll a, b;
	cin >> a >> b;
	cout <<(a - 1)*(b - 1);
	cout <<  endl;
	return 0;
}


Measured memory_bytes: 3612
import scala.io.Source.stdin
import scala.math.{max,min}

object Main extends App {

  val p = (
    (
      for (i <- (0 until 19) ++ (17 to 0 by -1)) yield (i+3)*(i+2)*(i+1)/6 - max(2*(i-9)*(i-8)*(i-7)/3,0)
    ) ++
    (for (i <- 37 to 51) yield 0)
  )

  stdin.getLines.foreach { x => println(p(x.toInt)) }
}

Measured memory_bytes: 44176
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

result = 0
g = -10
for i in a:
    result += b[i-1]
    if g+1 == i:
        result += c[i-2]
    g = i
print(result)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=2e5+10,XJQ=998244353;
ll n,q,s[N];
ll lazy[N*4],t[N*4];
void Downdata(ll x,ll l,ll m,ll r){
	if(!lazy[x])return;
	ll val=lazy[x];
	lazy[x*2]=lazy[x*2+1]=lazy[x];
	t[x*2]=(s[m]-s[l-1]+XJQ)%XJQ*val%XJQ;
	t[x*2+1]=(s[r]-s[m]+XJQ)%XJQ*val%XJQ;
	lazy[x]=0;return;
}
void Change(ll x,ll L,ll R,ll l,ll r,ll val){
	if(L==l&&R==r){
		lazy[x]=val;
		t[x]=(s[R]-s[L-1]+XJQ)%XJQ*val%XJQ;
		return;
	}
	ll mid=(L+R)>>1;
	Downdata(x,L,mid,R);
	if(r<=mid)Change(x*2,L,mid,l,r,val);
	else if(l>mid)Change(x*2+1,mid+1,R,l,r,val);
	else Change(x*2,L,mid,l,mid,val),Change(x*2+1,mid+1,R,mid+1,r,val);
	t[x]=(t[x*2]+t[x*2+1])%XJQ;
}
int main()
{
	scanf("%lld%lld",&n,&q);
	s[1]=1;
	for(ll i=2;i<=n;i++)
		s[i]=s[i-1]*10%XJQ;
	for(ll i=1;i<=n;i++){
		s[i]=(s[i]+s[i-1])%XJQ;
		Change(1,1,n,i,i,1);
	}
	while(q--){
		ll l,r,d;
		scanf("%lld%lld%lld",&l,&r,&d);
		l=n-l+1;r=n-r+1;swap(l,r);
		Change(1,1,n,l,r,d);
		printf("%lld\n",t[1]);
	}
	return 0;
}

Measured memory_bytes: 12084
#include <iostream>
using namespace std;
int main() {
  long long n, a, b;

  cin >> n >> a >> b;
  if((b-a) % 2 == 0) cout << (b-a)/2 << endl;
  else {
    long long ans = min(a-1, n-b) + 1 + ((b-a-1)/2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3608
#include<map>
#include<set>
#include<cmath>
#include<climits>
#include<vector>
#include<queue>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#define mod 1000000007
#define MAX 1000000
using namespace std;
#define LL long long int
vector<LL> sieve()
{
    vector<LL> div(MAX+1,0); 
    for (LL i = 1; i<= MAX; i++)
    { 
        for (LL j = 1; j * i <= MAX; j++) 
        {
            div[i * j]++; 
        }
    } 
    return div;
}
int main() 
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<LL> f=sieve();
    LL N;
    cin >> N;
    LL count=0;
    for(LL i=1;i<N;i++)
    {
        count+=f[(N-i)];
    }
    cout<<   count  <<  endl;
}


Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

ll beki(ll x, ll n, const ll &p) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

ll F[700010];
ll Finv[700010];

void init_combination() {
    const int MAX = 700000;
    F[0] = 1;
    for (int i = 1; i <= MAX; i++) {
        F[i] = F[i - 1] * i % mod;
    }
    Finv[MAX] = beki(F[MAX], mod - 2, mod);
    for (ll i = MAX - 1; i >= 0; i--) {
        Finv[i] = Finv[i + 1] * (i + 1) % mod;
    }
    return;
}

void solve() {
    init_combination();
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for(int i = max(1, n - k); i <= n; i++) {
        ans += F[n] * Finv[i] % mod
                * Finv[n - i] % mod
                * F[n - 1]    % mod
                * Finv[i - 1] % mod
                * Finv[n - i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 11264
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int IN[1100];
int OUT[1100];
int UF[1100];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int oo[1100];
int ii[1100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b*2+1;i++)UF[i]=-1;
	for(int i=0;i<a;i++){
		int p,q,r,s;scanf("%d%d%d%d",&p,&q,&r,&s);
		int fr=-r;
		int to=-s;
		if(r==0)fr=p;
		if(s==0)to=q;
		to*=-1;
		IN[fr+b]++;
		OUT[to+b]++;
		UNION(fr+b,to+b);
	}
	for(int i=0;i<2*b;i++){
		if(IN[i]>OUT[i]&&i-b<0){printf("NO\n");return 0;}
		if(IN[i]<OUT[i]&&i-b>0){printf("NO\n");return 0;}
	}
	for(int i=1;i<=b;i++){
		if(IN[i+b]>OUT[i+b]){
			oo[FIND(i+b)]++;
		}
		if(IN[-i+b]<OUT[-i+b]){
			ii[FIND(-i+b)]++;
		}
	}
	for(int i=1;i<=b;i++){
		if(IN[i+b]+OUT[i+b]&&(oo[FIND(i+b)]==0||ii[FIND(i+b)]==0)){printf("NO\n");return 0;}
		if(IN[-i+b]+OUT[-i+b]&&(oo[FIND(-i+b)]==0||ii[FIND(-i+b)]==0)){printf("NO\n");return 0;}
		
	}
	printf("YES\n");
}

Measured memory_bytes: 256
LI = lambda: list(map(int, input().split()))

S = input()
T = input()


def main():
    sn = len(S)
    tn = len(T)
    ans = sn
    for i in range(sn - tn + 1):
        x = 0
        for j in range(tn):
            if S[i + j] != T[j]:
                x += 1
        ans = min(ans, x)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9056
#include <stdio.h>

int main(){

  int A[1000];
  int N, i, j, k, v;

  scanf("%d", &N);

  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }

  for(i = 1; i < N; i++){
    for(k = 0; k < N - 1; k++){
      printf("%d ", A[k]);
    }

    printf("%d\n", A[N - 1]);
    
    v = A[i];
    j = i - 1;


    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    
  }
  
  for(k = 0; k < N - 1; k++){
      printf("%d ", A[k]);
    }

  printf("%d\n", A[N - 1]);
  

  return 0;
}



Measured memory_bytes: 2084
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 2e9
#define ll long long
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) v.begin(), v.end()

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; char op; cin >> a >> op >> b;
    if (op=='+') cout << a + b << endl;
    else cout << a - b << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)
#define FOR(i,a,b) for(int i = a;i<b;i++)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll gcd(ll a, ll b) {//最大公約数
	if (a < b)swap(a, b);
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	if (a < b)swap(a, b);
	return (a / gcd(a, b))*b;
}

int main() {

	int a[3];
	int cnt = 0;
	rep(i, 3)cin >> a[i];
	sort(a, a + 3);
	bool odd = true, even = true;
	rep(i, 3) {
		if (a[i] % 2 == 0)odd = false;
		else even = false;
	}
	if (!odd && !even) {
		cnt++;
		if (a[0] % 2 == 1 && a[1] % 2 == 1 && a[2] % 2 == 0) {
			a[0]++; a[1]++;
		}
		else if (a[0] % 2 == 0 && a[1] % 2 == 1 && a[2] % 2 == 1) {
			a[1]++; a[2]++;
		}
		else if (a[0] % 2 == 1 && a[1] % 2 == 0 && a[2] % 2 == 1) {
			a[0]++; a[2]++;
		}
		else if (a[0] % 2 == 0 && a[1] % 2 == 0 && a[2] % 2 == 1) {
			a[0]++; a[1]++;
		}
		else if (a[0] % 2 == 1 && a[1] % 2 == 0 && a[2] % 2 == 0) {
			a[1]++; a[2]++;
		}
		else if (a[0] % 2 == 0 && a[1] % 2 == 1 && a[2] % 2 == 0) {
			a[0]++; a[2]++;
		}
	}
	cnt += (a[2] - a[1]) / 2;
	cnt += (a[2] - a[0]) / 2;

	pr(cnt);

	//system("pause");
	return 0;
}



Measured memory_bytes: 256
old = []
new = []
ans = []
t = True

while True:
    try:
        n = input()
    except:
        break

    n = n.split(',')[0]
    if not n:
        t = False
    if t:
        old.append(n)
    else:
        new.append(n)

for o in set(old):
    if o in new:
        s = old.count(o) + new.count(o)
        ans.append([int(o), int(s)])
ans.sort()
for a in ans:
    print('%d %d' % (a[0], a[1]))

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    map<ll, ll> m;
    rep (i, M) {
        ll a, b;
        cin >> a >> b;
        m[a]++;
        m[b]++;
    }

    bool flag = true;
    for (auto it : m) {
        if (it.second%2 != 0) {
            flag = false;
        }
    }

    if (flag) {
        YES;
    } else {
        NO;
    }
    return 0;
}

Measured memory_bytes: 5632
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    K = int(input())
    s = input()
    if len(s) <= K:
        print(s)
    else:
        print(s[:K] + '...')
if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
# a = gets.to_i
# b = gets.to_i
s = gets.chomp
t = gets.chomp
# s,t = gets.split.map(&:to_s)
# r= gets.split.map(&:to_i)

# s = gets.chomp.chars.uniq
# puts gets.chomp.chars.uniq.size != 1 ? "Yes" : "No"
# r = a-b
ans=0
3.times{|i| ans+=1 if s[i]==t[i]}
p ans

Measured memory_bytes: 1788
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll n; cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n){
		cin >> b[i] >> a[i];
	}

	ll ans = 0;
	ll tmp = 0;
	rrep(i, n){
		ll c = (b[i] + tmp) / a[i];
		if(c * a[i] < b[i] + tmp) c++;
		ll d = c * a[i] - b[i] - tmp;
		tmp += d;
		ans += d;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4844
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,c,Q,k,dp[100000];
map<ll,ll> mp[100000];
vector<ll> v[100000];
void dfs(ll p,ll q){
    for(auto x:v[q]){
        if(p!=x){
            dp[x]+=dp[q]+mp[q][x];
            dfs(q,x);
        }
    }
    return ;
}
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b>>c;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
        mp[a][b]=c;
        mp[b][a]=c;
    }
    cin>>Q>>k;
    dfs(-1,k-1);
    while(Q--){
        cin>>a>>b;
        a--,b--;
        cout<<dp[a]+dp[b]<<endl;
    }
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=6010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, sum;
int A[2][MAXN];
bool mark[MAXN];
string ans, S, T;

string Solve(string T){
	string res;
	int a=0, b=0;
	for (int i=T.size()-1; ~i; i--){
		if (T[i]=='a') A[0][a++]=i;
		if (T[i]=='b') A[1][b++]=i;
		mark[i]=0;
	}
	if (T[0]=='a'){
		int last=-1;
		for (int i=a-1; ~i; i--) if (last<A[0][i]){
			res+="ab";
			last=A[1][i];
		}
		return res;
	}
	for (int i=0; 2*i<T.size(); i++){
		mark[A[0][i]]=mark[A[1][i]]=1;
		string s;
		for (int j=0; j<T.size(); j++) if (mark[j]) s+=T[j];
		res=max(res, s);
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>S;
	for (int i=2*n-1; ~i; i--){
		if (S[i]=='a') sum++;
		else sum--;
		T=S[i]+T;
		if (sum==0){
			T=Solve(T);
			ans=max(ans, T+ans);
			T="";
		}
	}
	cout<<ans<<"\n";
	
	return 0;
}
/*
5
aaabababbb

*/

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
int main()
{ 
  char s[100];
  int count=0;
  cin>>s;
  for(int i=0;i<strlen(s);i++)
  {
    if(s[i]!=s[strlen(s)-1-i])
      count++;
  }
  cout<<count/2<<endl;
}
  


Measured memory_bytes: 256
def Substring():
    
    str1 = str(input())
    
    str2 = str(input())

    count_list = []

    for i in range(len(str1) - len(str2) + 1):
        
        count = len(str2)
        
        for j in range(len(str2)):
                        
            if str1[i + j] == str2[j]:
                
                count = count - 1

        count_list.append(count)
        
    print(min(count_list))
        
if __name__ == '__main__':
    Substring()



Measured memory_bytes: 9044
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

int n,a,b;

cin >> n;

if(n==1){
   cout << "Hello World" << endl;
}else{
   cin >> a >> b;
   cout << a+b << endl;
}




   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>

using namespace std;
using ll = long long int;

int main(){
  int h, w, n;
  cin >> n >> h >> w;
  int count = 0;
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < n; j++)
    {
      int x = n - i;
      int y = n - j;
      if(x >= h && y >= w)
      {
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 100005
typedef long long ll;
using namespace std;
int n;
struct edge{
	int to,next;
}e[N<<1];
int head[N],cnt;
void add(int u,int v){
	e[++cnt]=(edge){v,head[u]};
	head[u]=cnt;
}
int son[N];
int path[N],len;
bool dfs(int x,int fa){
	bool p=x==n;
	for(int i=head[x];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa)continue;
		p|=dfs(v,x);
	}
	son[fa]+=son[x]+1;
	if(p){
		path[++len]=x;
		return true;
	}
	return false;
}
int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	dfs(1,0);
	int ans=son[path[len]]-son[path[len-1]];
	for(int i=len-1;i>len/2;--i)
		ans+=son[path[i]]-son[path[i-1]];
	printf("%s\n",ans*2>n?"Fennec":"Snuke");
	return 0;
}

Measured memory_bytes: 7552
# coding: utf-8
N = int(input())
if N % 2 != 0:
    print(0)
    exit()
else:
    ans = 0
    i = 1
    ans += N // 10
    N //= 10
    while N > 0 :
        ans += N // 5
        N //= 5
    print(ans)

Measured memory_bytes: 3060
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
	D, G = NMI()
	problems = [NLI() for _ in range(D)]
	n = D
	ans = 10**10
	for case in range(2 ** n):
		res = 0
		point = 0
		maxbit = 0
		for i in range(n):
			if (case >> i) & 1:
				res += problems[i][0]
				point += problems[i][1] + problems[i][0] * (i+1) * 100
			else:
				maxbit = max(maxbit, i)
				pass

		if point >= G:
			ans = min(ans, res)
			continue

		for i in range(problems[maxbit][0]):
			point += (maxbit+1) * 100
			res += 1
			if point >= G:
				ans = min(ans, res)
				break

	print(ans)


if __name__ == "__main__":
	main()

Measured memory_bytes: 3316
from math import atan, pi
E = 10**-10

def cross(a0,a1,b0,b1):
    return a0*b1-a1*b0

while(1):
    a = [0 for i in range(2)]
    b = [0 for i in range(2)]
    c = [0 for i in range(2)]
    d = [0 for i in range(2)]
    try:
        a[0],a[1],b[0],b[1],c[0],c[1],d[0],d[1] = [float(i) for i in input().split(",")]
        A = cross((d[1]-a[1]),(d[0]-a[0]),(b[1]-a[1]),(b[0]-a[0]))
        B = cross((c[1]-d[1]),(c[0]-d[0]),(a[1]-d[1]),(a[0]-d[0]))
        C = cross((b[1]-c[1]),(b[0]-c[0]),(d[1]-c[1]),(d[0]-c[0]))
        D = cross((a[1]-b[1]),(a[0]-b[0]),(c[1]-b[1]),(c[0]-b[0]))
        if A*B*C*D < 0:
            print("NO")
        else:
            print("YES")
    except EOFError:
        break


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

int main(void){
    int n;
    cin >> n;
    int a[n];
    double sum;
    for(int i = 0;i < n;i++)cin >> a[i];
    sort(a,a+n);
    sum = a[0];
    for(int i = 1;i < n;i++){
        sum += a[i];
        sum /= 2;
    }
    cout << sum << endl;
}

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

using namespace std;

#define ll long long

int bin_pow(int a, int pow) {
    if (pow == 0) return 1;
    if (pow == 1) return a;
    if (pow % 2 == 0) {
        int tmp = bin_pow(a, pow / 2);
        return tmp * tmp;
    }
    return a * bin_pow(a, pow - 1);
}

int fact(int x) {
    int ans = 1;

    for (int i = 1; i <= x; i++) ans *= i;
    return ans;
}

int count(vector<int> a) {
    int ans = 0;
    unordered_set<int> was;
    for (int i = 0; i < a.size(); i++) {
        int count = a[i] - 1;
        for (int j = 1; j < a[i]; j++) {
            count -= was.count(j);
        }
        ans += count * fact(a.size() - i - 1);
        was.insert(a[i]);
    }

    return ans;
}

ll m = 1000000007;

bool isPrime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    cin.tie();
    ios_base::sync_with_stdio(false);
    int a;
    cin >> a;

    while (!isPrime(a++));

    cout << a - 1;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
total = 0
for i in range(1, len(a)):
    total += abs(a[i] - a[i - 1])
for i in range(1, len(a) - 1):
    print(total - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]))

Measured memory_bytes: 14048
import sys
from collections import Counter
n = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
q = int(sys.stdin.readline().rstrip())
count_dic = Counter(A)
SUM = sum(A)
for i in range(q):
  b, c = map(int, input().split())
  SUM += count_dic[b]*(c - b)
  count_dic[c] += count_dic[b]
  count_dic[b] = 0
  print(SUM)

Measured memory_bytes: 94376
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a, a+n);

	int ptr, res;
	while (ptr < n) {
		int cc = a[ptr], f = 0;
		while (ptr < n&&a[ptr] == cc) {
			f++;
			ptr++;
		}
		res += f % 2;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
p = [0 for i in range(M)]
S = ["" for i in range(M)]
ACc = [False for i in range(N)]
firstans = [0 for i in range(N)]
errors = 0
answers = 0

for i in range(M):
    p[i], S[i] = input().split(" ")
    p[i] = int(p[i])

for i in range(M):
    if S[i] == "AC":
        ACc[p[i]-1] = True
        if firstans[p[i]-1] == 0:
            firstans[p[i]-1] = i


for i in range(M):
    if S[i] == "WA" and (ACc[p[i]-1]) and i <= firstans[p[i]-1]:
        errors +=1 
    

for i in range(N):
    if ACc[i]:
        answers +=1


print(answers, errors)

Measured memory_bytes: 18068
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 300010;
const long long MOD = 998244353;
long long fact[MAX] = { 0 };
long long inv[MAX] = { 0 };

long long modpow(long long x, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1)res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

long long C(long long n, long long k) {
	return fact[n] * inv[n - k] % MOD * inv[k] % MOD;
}

int main() {
	long long N, A, B, K;
	long long ans = 0;

	cin >> N >> A >> B >> K;

	fact[0] = 1;
	fact[1] = 1;
	inv[0] = 1;
	inv[1] = 1;
	for (int i = 2; i <= N; i++) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = modpow(fact[i], MOD - 2, MOD);
	}

	for (long long r = 0; r <= N; r++) {
		long long X = K - (A * r);
		long long b = X / B;

		if (X < 0)break;
		if (X % B != 0)continue;
		if (b >= N + 1)continue;

		ans += C(N, r) * C(N, b) % MOD;
	}

	cout << ans % MOD << endl;

	return 0;
}

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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  int n,x=0;
  int ans=0;
  string s;
  cin>>n>>s;
  rep(i,n){
    if(s[i]=='I'){
      x++;
    }
    else{x--;}
    ans=max(ans,x);
  }
  cout<<ans<<endl;
}


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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}



int main()
{
int N;cin>>N;
vector<long>A(N);
for(int i=0;i<N;i++)
{cin>>A[i];}

vector<long>lgcd(N);
vector<long>rgcd(N);

lgcd[0]=A[0];
for(int i=1;i<N;i++)
{lgcd[i]=gcd(A[i],lgcd[i-1]);}

rgcd[N-1]=A[N-1];
for(int i=N-2;i>=0;i--)
{rgcd[i]=gcd(A[i],rgcd[i+1]);}

vector<long>answers(N);
answers[0]=rgcd[1];
answers[N-1]=lgcd[N-2];
for(int i=1;i<N-1;i++)
{answers[i]=gcd(lgcd[i-1],rgcd[i+1]);}

sort(answers.begin(),answers.end());
cout<<answers[N-1]<<endl;

}



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

using namespace std;
using ll = long long;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int x;
	cin >> x;

	if (x <= 599) cout << 8;
	else if (x <= 799) cout << 7;
	else if (x <= 999) cout << 6;
	else if (x <= 1199) cout << 5;
	else if (x <= 1399) cout << 4;
	else if (x <= 1599) cout << 3;
	else if (x <= 1799) cout << 2;
	else cout << 1;
}

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

char l[12][32];

int main()
{
    
    int n,m,atari,d;
    while(cin>>n>>m>>atari>>d)
    {
        memset(l,'0',sizeof(l));
        for(int j=1;j<d+1;j++)for(int i=1;i<n;i++)cin >> l[i][j];

        int x = m;
        for(int j=1;j<d+1;j++)
        {
            if(l[x-1][j] == '1'){x--; continue;}
            if(l[x][j] == '1'){x++; continue;}
        }
        if(x == atari){cout << 0<<endl; continue;}
        int na = 1;
        for(int s=1;s<d+1;s++)
        {
            for(int t=1;t<n;t++)
            {
                if(l[t-1][s]=='0'&&l[t][s]=='0'&&l[t+1][s]=='0')
                {
                l[t][s] = '1';
                x = m;
                for(int j=1;j<d+1;j++)
                {
                    if(l[x-1][j] == '1'){x--; continue;}
                    if(l[x][j] == '1'){x++; continue;}
                }
                if(x == atari){cout <<s <<" "<< t <<endl; na = 0; break;}
                if(na==0) {break;}
                l[t][s] = '0';
                }
            }
            if(na==0) {break;}
        }
        if(na) cout << 1<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;

    return 0;

}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a[4];
char s[100001];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(register int i=1;i<=len;i++)
		a[s[i]-'a'+1]++;
	sort(a+1,a+4);
	if(a[3]-a[1]<=1)  printf("YES");
	else  printf("NO");
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1, v2 = [], []
for i in range(n):
    if i%2:
        v1.append(v[i])
    else:
        v2.append(v[i])
vv1 = Counter(v1).most_common()
vv2 = Counter(v2).most_common()
if vv1[0] != vv2[0]:
    print(n - vv1[0][1] - vv2[0][1])
else:
    if len(vv1) == len(vv2) == 1:
        print(n - max(vv1[0][1], vv2[0][1]))
    elif len(vv1) == 1 and len(vv2) == 2:
        print(n - vv1[0][1] - vv2[1][1])
    elif len(vv1) == 2 and len(vv2) == 1:
        print(n - vv1[1][1] - vv2[0][1])
    else:
        print(n - max(vv1[1][1] + vv2[0][1], vv1[0][1] + vv2[1][1]))

Measured memory_bytes: 21084
import java.util.Scanner;
public class Main
{
    public static String removeCharAt(String s,int pos)
    {
        System.out.println("executed");
        return s.substring(0,pos)+s.substring(pos+1);
    }
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n;
    n = sc.nextInt();
    String s = sc.next(); 
    char temparr[]=s.toCharArray();
    int count=0;
    //System.out.println(temparr.length);
    for(int i=0;i<temparr.length-1;i++)
    {
        if(temparr[i]!='1')
        {
            for(int j=i+1;j<temparr.length;j++)
            {
                if(temparr[i]==temparr[j])
                {
                    temparr[j]='1';
                    //s=removeCharAt(s,j);
                
                    count++;
                }
                else 
                    break;
                //System.out.println(s);
            }
        }
    }
    System.out.println(s.length()-count);
      
  }
}

Measured memory_bytes: 26560
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
int x[100000],y[100000];
signed main(){
	int a,b,ans=0;
	cin>>a>>b;
	f(i,a){
		cin>>x[i]>>y[i];
	}
	sort(x,x+a);
	sort(y,y+a);
	auto Itr=upper_bound(y,y+a,x[a-1])-y;
	for(int i=a-1;i>=Itr;i--){
		ans++;
		b-=y[i];
		if(b<=0){
			cout<<ans<<endl;
			return 0;
		}
	}
	cout<<ans+(b-1)/x[a-1]+1<<endl;
}


Measured memory_bytes: 1024
mod = 10**9 + 7
n = 10**6

fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
  rfact[i-1] = r = r * i % mod

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % mod

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % mod

N,M = map(int, input().split())
a = perm(M,N)
b = 0
for i in range(N+1):
    if i % 2:
        b -= comb(N,i) * perm(M-i,N-i) % mod
    else:
        b += comb(N,i) * perm(M-i,N-i) % mod
b %= mod
ans = a * b % mod
print(ans)

Measured memory_bytes: 95164
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(final InputReader in, final PrintWriter out) {
        String abcd = in.next();
        for (int i = 0; i < (1 << 3); i++) {
            int tmp = Integer.parseInt(String.valueOf(abcd.charAt(0)));
            StringBuilder sb = new StringBuilder(String.valueOf(abcd.charAt(0)));
            for (int j = 0; j < 3; j++) {
                if (1 == ((i >> j) & 1)) {
                    tmp += Integer.parseInt(String.valueOf(abcd.charAt(j + 1)));
                    sb.append("+");
                } else {
                    tmp -= Integer.parseInt(String.valueOf(abcd.charAt(j + 1)));
                    sb.append("-");
                }
                sb.append(abcd.charAt(j + 1));
            }

            if (tmp == 7) {
                out.println(sb + "=7");
                return;
            }
        }
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 22740
function main()
  
  (A,B,C,D) = map(x -> parse(BigInt,x), split(readline()))
  
  div_AC = div(A-1,C)
  div_AD = div(A-1,D)
  div_BC = div(B,C)
  div_BD = div(B,D)
  
  lcm_CD = lcm(C,D)
  
  div_Al = div(A-1,lcm_CD)
  div_Bl = div(B,lcm_CD)
  
  A -= (div_AC + div_AD - div_Al)
  B -= (div_BC + div_BD - div_Bl)

  println(B - A + 1)
  
end

main()

Measured memory_bytes: 111676
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

//-----end of template-----//

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(0, a + b - n) << endl;
}

Measured memory_bytes: 256
//                          **********  YATIN KWATRA  ********** 

//AC bakshi Rabha

#include <bits/stdc++.h>
#define ll                      long long 
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795
// #define node                    Node

using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

ll mo = 1000000000000000000;
void solve()
{ 
        ll n,m;
        cin >> n;

        cin >> m;
        n--;

        ll ans = m;

        ll ok = 0;


        while(n--)
        {
          cin >> m;

          if(m == 0) ok = 1;

           if((ans != -1) and (ans<=(mo/m))) ans *= m;
            else ans = -1;

         // cout << ans << endl;
        }

        if(ok) cout << 0 << endl;
        else  cout << ans << endl;
    
       
}
int main() {
    
    FIO
    INPUT();
    
    int t;
    t = 1;
 //   cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 3648