akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}

using minHeap = priority_queue< int, vector< int >, greater< int > >;

int add(int x , int y){
    return (x%mod + y%mod)%mod;
}

int sub(int x , int y){
    return (x%mod - y%mod + mod)%mod;
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n,k;
    scn2(n,k);

    int a[n+1];

    for(int i=1; i<=n; i++)scn(a[i]);

    int dp[k+3];
    dp[0] = 1;

    for(int i=1; i<=k; i++) dp[i] = 0;

    for(int i=1; i<=n; i++){

        if(a[i] == 0)continue;

        vector<int>csum(k+3,0);
        csum[0] = 1;
        for(int j=1; j<=k; j++) csum[j] = add(csum[j-1] , dp[j]);

        for(int j=1; j<=k; j++){

            int take = min(j,a[i]);
            int lo = j-take-1;
            int now = sub(csum[j-1],(lo>=0?csum[lo]:0));

            dp[j] = add(dp[j],now);
            //cout<<dp[j]<<" ";
        }
       // cout<<endl;
    }
    cout<<dp[k];

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
vector<ll> divs;
void getdivs(ll x){
	for(int i=1;i*i<x;i++){
		if(x%i==0){
			divs.pb(i);
			divs.pb(x/i);
		}
	}
	sort(divs.begin(),divs.end());
}
int main(){
	int n,k;
	cin>>n>>k;
	vector<ll> a;
	ll sum = 0;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
		sum += x;
	}
	getdivs(sum);
	reverse(divs.begin(),divs.end());
	for(int i=0;i<divs.size();i++){
		ll res = 0;
		ll cur = divs[i];
		vector<ll> kais;
		ll su=0;
		for(int j=0;j<n;j++){
			kais.pb(a[j]%cur);
			su+=a[j]%cur;
		}
		sort(kais.begin(),kais.end());
		ll cnt = su/cur;
		for(int j=0;j<n-cnt;j++){
			res += kais[j];
		}
		if(res<=k){
			cout<<cur<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    int s, w; cin >> s >> w;
    if(s <= w)cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

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

typedef long long ll;

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

      int n, t; cin >> n >> t;
      int ans = 100000;
      while (n--) {
            int x, y; cin >> x >> y;
            if (y <= t) {
                  ans = min(ans, x);
            }
      }
      if (ans == 100000) cout << "TLE";
      else cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  Iswap(&a,&b);
  Iswap(&a,&c);
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 1732
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	int D;
	scanf("%d",&D);
	std::vector<int> c(26);
	for(int i=0;i<26;i++)scanf("%d",&c[i]);
	std::vector<vector<int>> s(D,vector<int>(26));
	for(int i = 0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	int S = 0;
	std::vector<int>last(26);
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			S-=c[j]*(i-last[j]);
		}
		int who = 1;
		int mx = 0;
		for(int j=0;j<26;j++){
			if(mx < s[i][j] +c[j]*(i-last[j])){
				mx = s[i][j] +c[j]*(i-last[j]);
				who = j+1;
			}
		}
		printf("%d\n",who );
	}
	
}

Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long l,r;
  cin >> l >> r;
  if(r-l>=2019){
    cout << 0 << endl;
  }
  else{
    long long ans=2019;
    for(long long i=l;i<r;i++){
      for(long long j=i+1;j<=r;j++){
        long long t=(i%2019)*(j%2019)%2019;
        ans=min(ans,t);
      }
    }
    cout << ans << endl;
  }
}

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


int main(){

    string S;
    int K;
    cin >> S;
    cin >> K;


    // Sの始めの1の個数を数え、1の次にあるものを求める
    int num = 0, ans;

    for( int i = 0; i < S.size(); i ++ ){
        if( S[i] == '1' ) num++;
        else{
            ans = S[i] - '0';
            break;
        }
    }

    if( K <= num ) cout << 1 << endl;
    else cout << ans << endl;

    return 0;

}

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

int main() {
  char a, b;
  cin >> a >> b;

  if(a == 'H') {
    if(b == 'H') {
      cout << 'H' << endl;
    } else {
      cout << 'D' << endl;
    }
  } else {
    if(b == 'H') {
      cout << 'D' << endl;
    } else {
      cout << 'H' << endl;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(list(input()))

s[0].sort()
ans = ""
for a in s[0]:
    bre = True
    for i in range(1, n):
        if not a in s[i]:
            bre = False
    if bre:
        ans += a
        for i in range(1, n):
            s[i].remove(a)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define RREP(i, a, b) for(int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9+7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ld PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;

int main(){
	int h,w,d; cin >> h >> w >> d;
	int a[300][300]; map<int, P> mp;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> a[i][j];
			mp[a[i][j]] = {i + 1, j + 1};
		}
	}
	
	map<int, int> mp2;
	vector<int> vec[d];
	for(int i = 1; i <= d; i++){
		int c = 0;
		vec[i % d].push_back(0);
		for(int j = i; j <= h * w; j += d){
			mp2[j] = c++;
			if(j + d > h * w) break;
			
			P st = mp[j];
			P t = mp[j + d];
			int cost = abs(st.first - t.first) + abs(st.second - t.second);
		
			vec[i % d].push_back(cost);
		}
	}
	
	for(int i = 0; i < d; i++){
		for(int j = 0; j < vec[i].size() - 1; j++){
			vec[i][j + 1] += vec[i][j];
		}
	}
	
	int q; cin >> q;
	for(int i = 0; i < q; i++){
		int l, r; cin >> l >> r;

		
		cout << vec[l % d][mp2[r]] - vec[l % d][mp2[l]] << endl;
	}
	return 0;
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    int n;
    cin>>n;
    cout<<"ABC"<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>


using namespace std;

int main(void)
{
	string searchString;
	int ans = 0;
	int N;
	
	cin >> N;
	cin >> searchString;

	// 回数分ループ
	for (int i = 0; i < N; i++)
	{
		string inputString;
		cin >> inputString;
		// 始まりの点を定めるループ
		for (int j = 0; j < inputString.size(); j++)
		{
			bool flagOk = false;

			// 間隔を定めるループ
			for (int k = 1; k < inputString.size(); k++)
			{
				string checkString = "";
				// 繰り返せる数分文字列を連結
				for (int l = j; l < inputString.size(); l += k)
				{
					checkString += inputString[l];

					if (checkString == searchString)
					{
						ans++;
						flagOk = true;
						break;
					}
				}
				if (flagOk == true)
				{
					break;
				}
			}
			if (flagOk == true)
			{
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
int a[200000],b[200000],z[200000];
int main(void)
{
	int i,j,n,m,x,f;
	f=0;
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++){
		z[i]=0;
	}
	for(i=1;i<=m;i++) scanf("%d %d",&a[i],&b[i]);
	for(i=1;i<=m;i++){
		if(a[i]==1){
			if(z[b[i]]==2) f=1;
			z[b[i]]=2;
		}
		if(b[i]==n){
			if(z[a[i]]==2) f=1;
			z[a[i]]=2;
		}
	}
	if(f==1) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class MainClass
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int count = 0;
        for (int i = 1; i < n-1; i++)
        {
            if (a[i-1]<a[i]&&a[i]<a[i+1])
            {
                count++;
            }
            else if (a[i + 1] < a[i] && a[i] < a[i - 1])
            {
                count++;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13268
#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++)
#define ANS(ans) cout << ans << endl
#define FLG(flg) if(flg) cout << "Yes" << endl; else cout << "No" << endl;
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define COUT(s) cout << s << endl;
#define AN vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];
#define IN  int n;  cin >> n;
#define VI  vector<int> 
#define SS stringstream ss;
#define SOLVE cout << solve() << endl;

int main() {
    long long n; cin >> n;
    long long ans = 0;
    long long i ,j;
    i = pow(n,0.5);
    while(true) {
        if(n % i ==0) {
            j = n / i;
            break;
        }
        else {
            i--;
        }
    }
    cout << i + j - 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if (a < b && b < c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 26136
///
// File:  0005.cpp
// Author: ymiyamoto
//
// Created on Wed Nov  8 22:03:57 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

uint64_t gcd(uint64_t a, uint64_t b)
{
  if (a < b) return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a - b);
}

uint64_t lcm(uint64_t a, uint64_t b, uint64_t g)
{
  return a * b / g;
}

int32_t main()
{
  while (true) {
    uint64_t a, b;
    cin >> a >> b;
    if (cin.eof()) break;
    uint64_t g = gcd(a, b);
    cout << g << " " << lcm(a, b, g) << endl;
  }

  return 0;
}

Measured memory_bytes: 3056
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
static const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  cin>>s>>sb; V(int)c[26],cb[26]; bool see[26]={};
  n=s.size();
  rep(i,n)c[s[i]-'a'].eb(i);
  rep(i,n)cb[sb[i]-'a'].eb(i);
  ok=1;
  rep(i,n){
    if(see[s[i]-'a'])continue;
    m=c[s[i]-'a'].size();
    if(m!=cb[sb[i]-'a'].size()){ok=0; break;}
    rep(j,m){
      if(c[s[i]-'a'][j]!=cb[sb[i]-'a'][j]){ok=0; break;}
    }
    if(!ok)break;
    see[s[i]-'a']=1;
  }
  pri1((ok?"Yes":"No"));
}

Measured memory_bytes: 2836
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long n,i,j,k,x,y,z,w;
    cin>>n;
    for (i=1;i<=n;i++)
    {
    	cin>>arr[i];
    	arr[i]-=i;
	}
	sort (arr+1,arr+n+1);
	if (n%2==1)
	{
		y=0;
		x=arr[n/2+1];
		for (i=1;i<=n;i++)
		{
			y=y+abs(x-arr[i]);
		}
		cout<<y<<endl;
	}
	else
	{
		z=0;w=0;
		x=(arr[n/2]+arr[n/2+1])/2;
		y=x+1;
		for (i=1;i<=n;i++)
		{
			z=z+abs(x-arr[i]);
		}
		for (i=1;i<=n;i++)
		{
			w=w+abs(y-arr[i]);
		}
		cout<<min(z,w)<<endl;		
	}
}

Measured memory_bytes: 4480
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    //input
    int n = sc.nextInt();

    //output
    int[] array = new int[n];
    for(int x = 1; x*x <= n; x++){
      for(int y = 1; y*y <= n; y++){
        for(int z = 1; z*z <= n; z++){
          int value = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
          if( value <= n ){
            array[value-1]++;
          }
        }
      }
    }

    for(int i = 0; i < array.length; i++){
      System.out.println(array[i]);
    }

  }

}


Measured memory_bytes: 29868
n, m, k = [int(w) for w in input().split()]

cond = False

for i in range(n + 1):
    for j in range(m + 1):
        b = i * (m - j) + j * (n - i)
        if b == k:
            cond = True
            break
    if cond:
        break

print("Yes" if cond else "No")


Measured memory_bytes: 9044
#include<iostream>
#include<cstdio>
using namespace std;
int main ()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<b)
  printf("a < b\n");
  else if(a>b) printf("a > b\n");
  else if(a == b) printf("a == b\n");
  return 0 ;
}


Measured memory_bytes: 3104
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) cin >> P[i];
    vector<int> A;
    for(int i = 0; i < N; i++){
        if(P[i] != i+1) A.push_back(i);
    }
    if(A.size()==2 or A.size()==0) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
main()
{
    int d,n;
    while(~scanf("%d%d",&d,&n))
    {
        if(d==0)
        {
            n<100 ? printf("%d\n",n) : puts("101");
        }
        else if(d==1)
        {
            n<100 ? printf("%d\n",n*100) : puts("10100");
        }
        else
        {
            n<100 ? printf("%d\n",n*10000) : puts("1010000");
        }
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    
    vector<double> v(N), w(N);
    for (int i=0; i<N; ++i) {
        cin >> v[i];
        w[i] = v[i];
    }
    sort(w.begin(), w.end());
    
    int p, q;
    for (int i=0; i<N; ++i) {
        p = lower_bound(w.begin(), w.end(), v[i]) - w.begin();
        q = upper_bound(w.begin(), w.end(), v[i]) - w.begin();
        cout << p*3+(q-p-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 4452
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>

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

using namespace std;

typedef long long ll;

int n;
vector<int> w;

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

    int sum = 0;
    int tmp = 0;
    cin >> n;
    REP(i, n) {
        cin >> tmp;
        w.emplace_back(tmp);
        sum += tmp;
    }
    
    int sum2pre = 0;
    int sum2 = 0;
    int result = 0;
    REP(i, n) {
        sum2pre = sum2;
        sum2 += w[i];
        if (sum / 2 <= sum2) {
            result = abs(((sum - sum2) - sum2));
            if (result < abs(((sum - sum2pre) - sum2pre))) {
                cout << result << endl;
            } else {
                cout << abs(((sum - sum2pre) - sum2pre)) << endl;
            }
            break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define debug(a) cerr<<#a <<' '<< a <<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

void sieve (LL n,vector<LL> &p){
    vector<char> isprime(n+1,1);
    int cnt=0;
    isprime[0]=isprime[1]=0;
    for(LL i=2; i<=n; i++){
        if(isprime[i]){
            p.push_back(i);
            for(LL j=i*i; j<=n; j+=i) isprime[j]=0;
        }
    }
}
VLL primes;

pair<long long ,long long> remove_cube(long long k){
    LL div=1,a=1,b=1;
    vector<pair<long long ,int>> ret;
    for(int i=0; ;++i){
        if(primes[i]*primes[i]*primes[i]>k){
            break;
        }
        if(k%primes[i]==0){
            ret.push_back(make_pair(primes[i],0));
            LL kk=k;
            while(kk%primes[i]==0){
                kk/=primes[i];
                div*=primes[i];
                (ret.end()-1)->second++;
            }
        }
    }
    REP(i,ret.size()){
        LL p=ret[i].FI,pow=ret[i].SE;
        REP(j,pow%3) a*=p;
        REP(j,(3-pow%3)%3) b*=p;
    }
    if(div!=k){
        LL rest=(LL)round(sqrt(k/div));
        if(rest*rest==k/div){
            a*=rest*rest;
            b*=rest;
        }else{
            a*=k/div;
            if((double)b*k/div*k/div>1e10)b=-1;
            else b*=k/div*k/div;
        }
    }
    //cout << a <<' '<<b<<endl;
    return make_pair(a,b);
}

pair<long long ,long long> pairvec(pair<long long ,long long> a){
    return make_pair(a.SE,a.FI);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<pair<long long ,long long >,int> cnt,vis;
    sieve(110000ll,primes);
    int n;
    pair<long long ,long long> s[100010]={};
    cin >> n;
    REP(i,n){
        LL tmp; cin >> tmp;
        s[i]=remove_cube(tmp);
        cnt[s[i]]++;
    }
    LL ans=0;
    REP(i,n){
        if(vis[s[i]]==1) continue;
        if(s[i]==make_pair(1ll,1ll)) {
            ans++;
        }
        else{
            ans+=max(cnt[s[i]],cnt[pairvec(s[i])]);
        }
        vis[s[i]]=1;
        vis[pairvec(s[i])]=1;
    }
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 26900
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var min = long.MaxValue;

        for(int i=0; i<s.Length-2; i++) {
            var ss = long.Parse(s.Substring(i, 3));
            min = Math.Min(min, Math.Abs(ss - 753L));
        }

        return min;
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <queue>
#define MAX_N 8
#define MAX_M 8
#define MAX_C 6
#define INF 1000000
using namespace std;

int N, M, C, ans = 1, nd, flag = 0;
int field[MAX_N][MAX_M], d[MAX_N][MAX_M], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

class Graphs
{
public:
	int g[MAX_N][MAX_M];
	int sum;
	int node;
	int intialize(int x[MAX_N][MAX_M]);
	int ingrh(int x[MAX_N][MAX_M]);
	void outgrh();
	int outNode();
};

int Graphs::intialize(int x[MAX_N][MAX_M])
{
	node = 0;
	sum = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			g[i][j] = field[i][j];
			if (g[i][j] == 7) sum++;
		}
	}
	if (ans < sum) ans = sum;

	return node;
}

int Graphs::ingrh(int x[MAX_N][MAX_M])
{
	sum = 0;
	node++;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			g[i][j] = x[i][j];
			if (g[i][j] == 7) {
				sum++;
			}
		}
	}
	if (ans < sum) ans = sum;

	return node;
}

void Graphs::outgrh()
{
	for (int i = 0; i < N; i++) 
		for (int j = 0; j < M; j++)  field[i][j] = g[i][j];
}

typedef Graphs G;
typedef pair<int, int> P;

G grh;
queue<G> que;

void initINF(){
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			d[i][j] = INF;
		}
	}
	d[0][0] = 0; 
}

void bfs(int color) {
	queue<P> qg;
	qg.push(P(0, 0));
	initINF();
	while(qg.size()) {
		P p = qg.front();
		qg.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx && nx < N && 0 <= ny && ny < M && (field[nx][ny] == 7 || field[nx][ny] == color) && d[nx][ny] == INF) {
				if (field[nx][ny] == color) flag = 1;
				qg.push(P(nx, ny));
				d[nx][ny] = 0;
				field[nx][ny] = 7;
			}
		}
	}
}

int Graphs::outNode() { return node; }

void solve()
{
	int color;
	color = field[0][0];
	field[0][0] = 7;
	bfs(color);	
	grh.intialize(field);
	nd = grh.outNode();
	que.push(grh);
	for (int i = 0; nd < 4; i++) {
		for (int j = 0; j < MAX_C+1; j++) {
			grh = que.front();
			grh.outgrh();
			flag = 0;
			bfs(j);
			if (flag == 1) {
				grh.ingrh(field);
				que.push(grh);
			}
		}
		que.pop();
		if (que.size()) {
			grh = que.front();
			nd = grh.outNode();
		}else break;
	}
	while (que.size()) {
		grh = que.front();
		que.pop();
		grh.outgrh();
		bfs(C);
		grh.ingrh(field);
	}
}

int main(void)
{
	while (cin >> N >> M >> C) {
		if (N == 0) break;
		ans = 1;
		for (int i = 0; i < N; i++) 
			for (int j = 0; j < M; j++) cin >> field[i][j];
		solve();
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

double calculateProbabilityOfGettingMoreHeads(vector<double>& probabilites) {
	int probabilitiesSize = probabilites.size();
	const int N = 2 * probabilitiesSize + 1;
	vector<vector<double>> dp(2, vector<double>(N,0.0));

	dp[0][probabilitiesSize] = dp[0][probabilitiesSize + 1] = probabilites[0];
	for (int i = probabilitiesSize + 2; i < N; ++i)
		dp[0][i] = 1;

	for(int i = 1; i < probabilitiesSize; ++i)
		for (int j = -1 * (probabilitiesSize - 1); j < probabilitiesSize; ++j) {
			dp[i & 1][j + probabilitiesSize] = probabilites[i] * dp[!(i & 1)][j + 1 + probabilitiesSize];
			dp[i & 1][j + probabilitiesSize] += (1 - probabilites[i]) * dp[!(i & 1)][j - 1 + probabilitiesSize];
		}

	return dp[(probabilitiesSize - 1) & 1][probabilitiesSize];
}

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

	vector<double> probabilites(n);
	for (auto& probability : probabilites)
		cin >> probability;

	cout << fixed << setprecision(10) << calculateProbabilityOfGettingMoreHeads(probabilites) << endl;

	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i+100*j+50*k==x){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#define r(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#include <fstream>
#define f first
#define endl "\n"
#define s second
#define pb push_back
#define ms(a,b) memset(a,b,sizeof(a))
#define fori(a,b) for(__typeof(a) i=a,ENDI=b;i<ENDI;i++)
#define forj(a,b) for(__typeof(a) j=a,ENDJ=b;j<ENDJ;j++)
typedef long long ll;
using namespace std;
char _;
int AC,TLE,WA,RE;
int main(){	
	int n;
	r(n);
	while(n--){
		string k;
		cin >> k;
		if(k=="AC")
			AC++;
		else if(k=="WA")WA++;
		else if(k=="TLE")TLE++;
		else RE++;
	}

	cout << "AC x " << AC << endl;
	cout << "WA x " << WA << endl;
	cout << "TLE x " << TLE << endl;
	cout << "RE x " << RE << endl;

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
  
int t[(1<<18)];
  
void Set(int a,int b,int x,int k=0,int l=0,int r=(1<<17)){
  if(b<=l || r<=a)return;
  if(a<=l && r<=b){
    t[k]=max(t[k],x);
    return;
  }
  int m=(l+r)/2;
  Set(a,b,x,k*2+1,l,m);
  Set(a,b,x,k*2+2,m,r);
}
  
int Get(int i){
  i+=(1<<17)-1;
  int res=t[i];
  while(i){
    i=(i-1)/2;
    res=max(res,t[i]);
  }
  return res;
}
           
int n,q;
int value[100005];
  
int main(){
  value[0]=2147483647;
    
  scanf("%d %d",&n,&q);
  for(int i=1;i<=q;i++){
    int type;
    scanf("%d",&type);
    if(type==0){
      int l,r;
      scanf("%d %d %d",&l,&r,&value[i]);
      r++;
      Set(l,r,i);
    }else{
      int target;
      scanf("%d",&target);
      int ans=Get(target);
      printf("%d\n",value[ans]);
    }
  }
  return 0;
}

Measured memory_bytes: 4416
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
#include<stdio.h>
using namespace std;

typedef struct{
	int x,y;
}p;
char a[1005][1005];
p acm[11];
p s,g;
int b[1005][1005];
int H,W,N;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int bfs(p s,p g)
{
	queue<p> q;
	p n;
	memset(b,-1,sizeof(b));
	q.push(s);
	b[s.x][s.y]=0;
	while(!q.empty())
	{
		p h;
		h=q.front();
		q.pop();
		if(h.x==g.x&&h.y==g.y)
		{
			break;
		}
		for(int i=0;i<4;i++)
		{
			n.x=h.x+dx[i];
			n.y=h.y+dy[i];
			if(n.x>=0&&n.x<H&&n.y>=0&&n.y<W&&a[n.x][n.y]!='X'&&b[n.x][n.y]==-1)
			{
				q.push(n);
				b[n.x][n.y]=b[h.x][h.y]+1;
			}
		}
	}
	return b[g.x][g.y];
}
int main()
{
	int i,j,t,step=0;
	scanf("%d%d%d",&H,&W,&N);
	for(i=0;i<H;i++)
	{
		scanf("%s",a[i]);
	}
	for(i=0;i<H;i++)
	for(j=0;j<W;j++)
	{
		if(a[i][j]>='1'&&a[i][j]<='9')
		{
			t=a[i][j]-'0';
		    acm[t].x=i;
		    acm[t].y=j;
		}
		else if(a[i][j]=='S')
		{
			s.x=i;
			s.y=j;
			a[i][j]='.';
		}
	}
		for(i=1;i<=N;i++)
		{
			g.x=acm[i].x;
			g.y=acm[i].y;
			step+=bfs(s,g);
			s.x=g.x;
			s.y=g.y;
			a[g.x][g.y]='.';
		}
	
	printf("%d\n",step);
	return 0;
 } 


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int r, g, b; cin >> r >> g >> b;
    int sum = r * 100 + g * 10 + b;
    if(sum % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N;
    cin >> N;
    auto h = make_vec<int>(N);
    REP(i, N) { cin >> h.at(i); }

    int ans = 0;
    REP(i, N - 1) {
        if (h[i + 1] < h[i]) {
            ans += h[i] - h[i + 1];
        }
    }
    ans += h[N - 1];

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


Measured memory_bytes: 384
n = int(input())
lst1 = [list(map(int,input().split())) for i in range(n-1)]
ans = []
for i in range(n-1):
    res = 0
    for j in range(i,n-1):
        if res < lst1[j][1]:
            res = lst1[j][1]
        elif res%lst1[j][2]==0:
            pass
        else:
            res = res+ lst1[j][2] -res%lst1[j][2] #駅を経つまでの時間を加算
        res += lst1[j][0]
        
    ans.append(res)

ans.append(0)

for i in ans:
    print(i)

Measured memory_bytes: 40560
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n, Alice=0, Bob=0;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(all(a), greater<int>());
	rep(i,n){
		if(i%2 == 0) Alice+=a[i];
		else Bob+=a[i];
	}
	cout << Alice-Bob << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    string s;
    cin >> s;
    int ans = 700;
    for(int i = 0; i < s.size(); i++){
       if(s[i]=='o')  ans += 100;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c=parseMap(split(readline()))
    if a==b==c
        println("Yes")
    else
        println("No")
    end
end
main()

Measured memory_bytes: 112308
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

const int MAX_N = 1e4 + 10, MAX_D = 100;
string K;
int D, N;
// dp[i][j][k] := i文字目まで見た時の和がj(modD)になる。0がそれより小さい、1がギリギリの数
mint dp[MAX_N][MAX_D][2];

int mod(int a){
    while(a < 0) a += D;
    return a % D;
}

int main(){
    cin >> K >> D;
    N = K.size();
    dp[0][0][1] = 1;


    rep(i, N) rep(j,D){
        rep(k, 10) dp[i+1][j][0] += dp[i][mod(j-k)][0];
        rep(k,K[i] - '0') dp[i+1][j][0] +=dp[i][mod(j-k)][1];        

        dp[i+1][j][1] += dp[i][mod(j-(K[i] - '0'))][1];
    }
    //rep(i, N + 1) rep(j, D) cout << dp[i][j][0] << " " << dp[i][j][1] << endl;

    cout << dp[N][0][0] + dp[N][0][1] - 1 << endl;

}

Measured memory_bytes: 8192
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a = int(input())
print(3 * (a ** 2))

Measured memory_bytes: 6736
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
from numba import jit

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	if n%1000 == 0:
		print(0)
	else:
		print(1000-n%1000)




if __name__ == '__main__':
    main()


"""
	n, m = LI()
	dist = np.full((n,n), INF)
	bridges = []
	for i in range(n):
		dist[i, i] = 0
	for i in range(m):
		a, b, c = LI()
		dist[a-1][b-1] = c
		dist[b-1][a-1] = c
		bridges.append((a,b,c))
	for i in range(n):
		for j in range(n):
			for k in range(n):
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
	for a, b, c in 

"""

Measured memory_bytes: 91764
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

ll solve() {
  ll N, A, B; cin >> N >> A >> B;
  if (A > B) return 0;
  if (A == B) return 1;
  if (N == 1) return 0;
  if (N == 2) return 1;
  return (B*(N-1) + A) - (A*(N-1) + B) + 1;
}

int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  cout << solve() << endl;

  return 0;
}



Measured memory_bytes: 256
class Node
  attr_accessor :self, :parent
  def initialize(i)
    @self, @parent = i, i
  end
end

class UnionFindTree
  attr_accessor :nodes

  #
  def initialize(n)
    @nodes = (1..n).map{|i| Node.new(i) }
  end

  # 1番上の親を返す.
  def root(x)
    return x if x == @nodes[x-1].parent
    return @nodes[x-1].parent = root(@nodes[x-1].parent)
  end

  # 判定する
  #   2つの木が同じ親に属していればtrue
  def check(a, b)
    return true if root(a) == root(b)
    return false
  end

  # まとめる
  def union(a, b)
    return if check(a, b)
    #$ans -= 1
    @nodes[root(b)-1].parent = root(a)
  end

  #
  def parent_size
    size = 0
    @nodes.each do | node |
      size += 1 if node.self == node.parent
    end
    return size
  end
end

n, m = gets.rstrip.split.map(&:to_i)
tree = UnionFindTree.new(n)
#p tree

#$ans = n
m.times do
  x, y, _ = gets.rstrip.split.map(&:to_i)
  tree.union(x, y)
end
#p $ans
p tree.parent_size

Measured memory_bytes: 11900
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;	cin >> n >> m;
  int left=1;
  int right=n;
  
  for(int i=0;i<m;i++){
    int L,R;	cin >> L >> R;
    if(left<L)	left=L;
    if(R<right)	right=R;
  }
  cout << max(right-left+1,0);
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>

using  ll = long long;
using ull = unsigned long long;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
constexpr ll kINF = 1152921504606846976;//2^60
constexpr double kEPS = 1e-6;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define rep(i,n) REP(i,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep(i,n) RREP(i,n)
#define mp make_pair
#define fi first
#define sc second

using P = pair<ll,ll>;

ll n;
ll deg[1000];
ll p[1000],d[1000];
vector<P> G[1000];
ll used[1000];

ll dfs(int i) {
  ll ret = 0;
  for (auto e : G[i]) {
    if (used[e.second] || deg[e.second] == 1) continue;
    used[e.second] = true;

    ret = max(ret, e.first + dfs(e.second));
  }
  return ret;
}

void solve() {
  ll sum = 0;
  rep (i,n) {
    if (i == 0) continue;
    if (deg[i] == 1 || deg[p[i]] == 1) {
      sum += d[i];
    } else {
      sum += 3 * d[i];
    }
  }
  ll ans = sum;
  rep (i,n) {
    if (deg[i] <= 1) continue;
    rep (j,n) used[j] = false;
    used[i] = true;
    ll r = dfs(i);
    ans = min(ans, sum - r);
  }
  cout << ans << endl;
}

int main(void) {
  while(true) {
    cin >> n;
    if (n==0) break;
    rep (i,n) {
      G[i].clear();
      deg[i] = 0;
    }
    rep (i,n) {
      if (i == 0) continue;
      cin >> p[i];
    }
    rep (i,n) {
      if (i == 0) continue;
      cin >> d[i];
    }
    rep (i,n) {
      if (i == 0)continue;
      p[i]--;
      G[i].push_back(P(d[i],p[i]));
      G[p[i]].push_back(P(d[i],i));
      deg[p[i]]++;deg[i]++;
    }

    solve();
  }
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,p,q,x,c1,c2,c3,d,e,f;
    ll n,m,z;
    vector<ll>v;
    cin>>n>>m>>z;
    if(z<=m) cout<<"delicious"<<endl;
    else if(z>n+m) cout<<"dangerous"<<endl;
    else if(z>m && z<=(n+m)) cout<<"safe"<<endl;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INF 999999999

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	int A, B;
	cin >> A >> B;
	if(A <= 8 && B <= 8){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
bool comp(pair<ll,ll> v1 ,pair<ll,ll> v2 )
{
 
}
bool vis[10] ;
 
int solve()
{
 	ll n ;
 	cin >> n ;
 	string s ,t ;
 	cin >> s >> t ;
 	int i = 0 , j = 0 ;
 	while(i < n && j < n)
 		cout << s[i++] << t[j++];
}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
 
	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

Measured memory_bytes: 256
N = input()
N = int(N)
S = list(input() for i in range(N))#N個縦に入力

C0 = 0
C1 = 0
C2 = 0
C3 = 0

for i in range(len(S)):
    if S[i] == 'AC':
        C0 += 1
    elif S[i] == 'WA':
        C1 += 1
    elif S[i] == 'TLE':
        C2 += 1
    elif S[i] == 'RE':
        C3 += 1

print('AC'+' '+'x'+ ' '+ str(C0))
print('WA'+' '+'x'+ ' '+ str(C1))
print('TLE'+' '+'x'+ ' '+ str(C2))
print('RE'+' '+'x'+ ' '+ str(C3))


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

using namespace std;

static const int INF = 1e9 + 7;

using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ull = unsigned long long;



void hawawa()
{
  long long n;
  cin >> n;
  for (long long i = 1; i <= 3500; i++) {
    for (long long j = i; j <= 3500; j++) {
      if ((4 * i * j - n * i - n * j) == 0) continue;
      if ((n * i * j) % (4 * i * j - n * i - n * j) == 0) {
        long long w = (n * i * j) / (4 * i * j - n * i - n * j);
        if (w < 0) continue;
        cout << i << " " << j << " " << w << "\n";
        return;
      }

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

Measured memory_bytes: 384
#include <stdio.h>

int search(int c,int d,int e);

int a[10];

int main(void){
    int N,i,k,b;
    scanf("%d",&N);
    for(k=0;k<N;k++){
      for(i=0;i<10;i++){
        scanf(" %d",&a[i]);
      };  
      b=search(0,0,0);
      if(b==1){
          printf("YES\n");
      }else{
          printf("NO\n");
      };
    };
    
}

int search(int c,int d,int e){
    int f=0;
    if(c<10){c++;
        if(a[c-1]>d&&f!=1){
            f=search(c,a[c-1],e);
        }if(a[c-1]>e&&f!=1){
            f=search(c,d,a[c-1]);
        }if(f==1){
            return(1);
        }else{
            return(0);
        };
    }else{
        return(1);
    };
}


Measured memory_bytes: 2040
#include<stdio.h>
int main()
{
	int a[100000],b,c,d,n,i;
	b=c=d=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%4==0)//能被4整除 
		b++;
		else if(a[i]%2!=0)//都不能 
		c++;
		else if(a[i]%4!=0&&a[i]%2==0)
		d++;
	}
	if(d==0)
	c--;
	if(c>b)
	printf("No\n");
	else printf("Yes\n");
	
 } 

Measured memory_bytes: 512
import java.util.*;
class Main{
    Main(){
	Scanner sc =new Scanner(System.in);
	int a ,b;
	for(int i=0;i<7;i++){
	    a=sc.nextInt();
	    b=sc.nextInt();
	    System.out.println(a-b);
	}
    }
    public static void main (String[]arg){
	new Main();
    }
}

Measured memory_bytes: 17236