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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

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

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

int main(void){
    ll N,M; cin >> N >> M;
    ll dist[N][N]; REP(i,N)REP(j,N) dist[i][j] = LL_INF; REP(i,N) dist[i][i] = 0;
    REP(i,M){
        ll s,t,d; cin >> s >> t >> d;
        dist[s][t] = d;
    }
    REP(k,N)REP(i,N)REP(j,N) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    ll dist2[N][N]; REP(i,N)REP(j,N) dist2[i][j] = dist[i][j];
    REP(k,N)REP(i,N)REP(j,N) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);

    bool flag = false;
    REP(i,N)REP(j,N){
        if(dist[i][j] != dist2[i][j]){
            flag = true;
        }
    }

    if(flag){
        cout << "NEGATIVE CYCLE" << en;
        return 0;
    }

    REP(i,N){
        REP(j,N-1){
            if(dist[i][j] > 1e15) cout << "INF" << " ";
            else cout << dist[i][j] << " ";
        }
        if(dist[i][N-1] > 1e15) cout << "INF";
        else cout << dist[i][N-1];
        cout << en;
    }
    return 0;
}


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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> cant(10);
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    cant[d] = 1;
  }
  vector<int> v;
  while (n > 0) {
    v.push_back(n % 10);
    n /= 10;
  }
  int smallest = -1;
  for (int i = 0; i < 10; ++i) {
    if (!cant[i]) {
      smallest = i;
      break;
    }
  }
  assert(smallest != -1);
  int dig = (int) v.size();
  for (int i = dig - 1; i >= 0; --i) {
    if (cant[v[i]]) {
      int j = i, need = 1;
      while (j < dig && need) {
        for (int c = v[j] + 1; c <= 9; ++c) {
          if (!cant[c]) {
            v[j] = c;
            need = 0;
            break;
          }
        }
        if (need) {
          ++j;
        } else {
          break;
        }
      }
      if (j == dig && need) {
        int largest = smallest;
        if (largest == 0) {
          for (int k = smallest + 1; k < 10; ++k) {
            if (!cant[k]) {
              largest = k;
              break;
            }
          }
        }
        assert(largest != 0);
        v.push_back(largest);
      }
      for (int k = 0; k < j; ++k) {
        v[k] = smallest;
      }
      break;
    }
  }
  for (int i = (int) v.size() - 1; i >= 0; --i) {
    cout << v[i];
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
s=input()
k=int(input())
one_cnt=0
if s[0]=="1":
    one_cnt+=1
    for i in range(1,len(s)):
        if s[i]=="1" and s[i-1]=="1":
            one_cnt+=1
        else:
            next=s[i]
            break
    if  k<=one_cnt:
        print(1)
    else:
        print(next)
else:
    print(s[0])

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

using namespace std;

#define rep(i,n) for(long i=1;i<=n;i++)

const long inf=20000000000;

int main(){
  long a,b,q;
   cin >> a >> b >>q;
 
  vector<long> s(a+2),t(b+2);
   s[0]=-1*inf;
   t[0]=-1*inf; 
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
   s[a+1]=inf;
   t[b+1]=inf;
  
   
  rep(i,q) {
    long res=inf;
    long x; 
    cin >> x;
 
  long shrine=upper_bound(s.begin(),s.end(),x)-s.begin();
  long temple=upper_bound(t.begin(),t.end(),x)-t.begin();
  
    res=min(res,min(abs(t[temple]-x),abs(s[shrine]-x))+abs(t[temple]-s[shrine]));
    res=min(res,min(abs(t[temple-1]-x),abs(s[shrine]-x))+abs(t[temple-1]-s[shrine]));
    res=min(res,min(abs(t[temple]-x),abs(s[shrine-1]-x))+abs(t[temple]-s[shrine-1]));
    res=min(res,min(abs(t[temple-1]-x),abs(s[shrine-1]-x))+abs(t[temple-1]-s[shrine-1]));
  
  cout << res << endl;
  }
    
}
  


Measured memory_bytes: 2944
N=int(input())
A1=list(map(int, input().split()))
A2=list(map(int, input().split()))
A=[A1,A2]
import numpy as np
dp= np.ndarray([2,N])
dp[0][0]=A[0][0]

for i in range(N-1):
  dp[0][i+1]=dp[0][i]+A[0][i+1]

dp[1][0]=dp[0][0]+A[1][0]

for j in range(N-1):
  dp[1][j+1]=max(dp[1][j], dp[0][j+1])+A[1][j+1]

print(int(dp[1][N-1]))


Measured memory_bytes: 12516
#include<iostream>
using namespace std;
int main(){
string s,t;
int a,b;
string u;
cin>>s>>t;
cin>>a>>b;
cin>>u;
if(u==s){
cout<<a-1<<" "<<b<<endl;
}
if(u==t){
cout<<a<<" "<<b-1<<endl;
}

return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n,i,j;
    cin>>n;
    ll s = 0;
    vector<ll> a(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    sort(all(a));
    ll sub = s;
    for(i=0;i<n;i++)
    {
        if(a[i]%10) {sub = a[i];break;}
    }
    if(s%10) cout<<s;
    else cout<<s-sub;
}


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

using namespace std;

// 文字列一つ受け取る場合
// string s;
// 整数(max 2^31-1 or 10^9)一つ受け取る場合
// int x;
int k;
int n;
set<int> a;



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

    for(int i = 0;i<n;i++){
        int j;
        cin >>j;
        a.insert(j);
    }
   int maxDiff = 0;
   int prevA = k;
   for(auto itr = a.begin();itr!=a.end();++itr){
       int value = *itr;
       maxDiff = max(maxDiff, value - prevA);
       prevA = value;
   }
   int begin = *a.begin();
   int end = *--a.end();
   maxDiff = max(maxDiff,begin+(k-end));
   cout << k - maxDiff;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b, n, ans;
	cin >> a >> b;
	n = b - a;
	ans = n * (n + 1) / 2 - b;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
LL d[414][414];
LL c[414];
LL f(int l,int r){
	if(d[l][r]!=0)return d[l][r];
	LL mn=1LL*mod*mod;
	FOR(i,l,r){
		LL t=f(l,i)+f(i+1,r)+c[r+1]-c[l];
		mn=min(mn,t);
	}
	d[l][r]=mn;
	return mn;
}

int main(){
	int n;
	cin>>n;
	vector<LL> a(n);
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,n+2){
		c[i]=0;
	}
	FOR(i,1,n+2){
		c[i]=c[i-1]+a[i-1];
	}
	FOR(i,0,414)FOR(j,0,414)d[i][j]=0;
	FOR(i,0,n){
		d[i][i]=a[i];
	}
	cout<<f(0,n-1)-c[n]<<endl;

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  map<string,int> S;
  rep(i,n){
    string s;
    cin>>s;
    S[s]++;
  }
  int best=0;
  for(auto s:S) best=max(best,s.second);
  for(auto s:S) if(s.second==best)
    cout<<s.first<<endl;
  return 0;
}

Measured memory_bytes: 25216
#include<iostream>;
#include<math.h>;
using namespace std;
 
double calcHour(int s);
double calcMin(int s);
double calcS(int s);
 
 
int main(int argc, const char * argv[]) {
  int s;
  cin >> s;
  cout << calcHour(s) << ":" << calcMin(s) << ":" << calcS(s) << endl;
  return 0;
}
 
double calcHour(int s) {
  return floor(s/3600);
}
 
double calcMin(int s) {
  return floor((s % 3600) / 60);
}
 
double calcS(int s) {
  return s % 60;
}

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

int main() {
    int N;
    cin >> N;
    bool can = false;
    for (int i=0; i<=25; i++) {
        for (int j=0; j<=25; j++){
            int total;
            total = 4*i + 7*j;
            if (total == N) can = true;
        }    
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

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

		String[] AB = sn.nextLine().split(" ");
		int A = Integer.parseInt(AB[0]);
		int B = Integer.parseInt(AB[1]);
		
		int x = ((B - A) / 2);
		
		int A1 = A - x;
		int A2 = A + x;
		int B1 = B - x;
		int B2 = B + x;

		if (A1 == B1) {
			System.out.println(A1);
			return;
		}
		if (A1 == B2) {
			System.out.println(A1);
			return;
		}
		if (A2 == B1) {
			System.out.println(A2);
			return;
		}
		if (A2 == B2) {
			System.out.println(A2);
			return;
		}

		System.out.println("IMPOSSIBLE");
	}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3

import sys

n, y = map(int, input().split())

for j in range(n + 1):
    for i in range(j + 1):
        if i * 10000 + (j - i) * 5000 + (n - j) * 1000 == y:
            print("%d %d %d" % (i, j - i, n - j))
            sys.exit(0)

print("-1 -1 -1")


Measured memory_bytes: 2940
//#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
#include <functional>
//#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

const int MOD = 1e9 + 7;
const int INF = 1e9 * 1e9 + 10;

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}



signed main()
{
	fast();
	long long d, t, s;
	cin >> d >> t >> s;
	if (d <= t * s)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3648
import sys

N=int(input())
if N==0:
    print(0)
    sys.exit()

walist=[0]*50
walist[0]=1
walist[1]=-2
for i in range(1,25):
    walist[2*i]=walist[2*i-2]+2**(2*i)
    walist[2*i+1]=walist[2*i-1]-2**(2*i+1)


    


def near(k):
    if k>=0:
        for i in range(16):
            if 2**i<=k<=walist[2*i]:
                return 2*i
            if 2**(2*i)>=k:
                return 2*i
    else:
        for i in range(16):
            if walist[(2*i)+1]<=k<=-2**((2*i)+1):
                return 2*i+1
            if -2**((2*i)+1)<=k:
                return 2*i+1


ANSSTR=[0]*50

while True:
    k=near(N)
    ANSSTR[k]=1
    N=N-(-2)**k
    if N==0:
        break

for i in range(49,-1,-1):
    if ANSSTR[i]==1:
        break

for j in range(i,-1,-1):
    print(ANSSTR[j],end="")


    


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#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,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template<class T> void printvec(vector<T> v){
    for (T t : v) cout << t << " ";
    cout << endl;
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
     vi v(3);
     REP(i,3) cin >> v[i];
     sort(ALL(v));
     
     cout << v[0]+v[1] <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);

  for( j = 2; j <= n; j++){
    key = A[j];
    i = j - 1;
    while(i > 0 && A[i] > key){
      A[i+1] = A[i];
      i -= 1;
    }
    A[i+1] = key;
    trace(A, n);
  }

  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
typedef pair<char,int> P;

vector<P> A,B,C,ans;
int a,b,c;

vector<P> input(){
  char ch;
  int num;
  vector<P> res;
  while(1){
    cin>>ch;
    if(ch=='$')break;
    cin>>num;
    res.push_back(P(ch,num));
  }
  return res;
}

int main(){
  A=input();a=A.size();
  B=input();b=B.size();
  C=input();c=C.size();  
  for(int i=0;i+b-1<a;i++){
    bool flg=true;
    for(int j=0;j<b;j++){
      if(A[i+j].first!=B[j].first)flg=false;
      if(j==0||j+1==b){
        if(A[i+j].second<B[j].second)flg=false;
      }else{
        if(A[i+j].second!=B[j].second)flg=false;
      }
    }
    if(flg){
      for(int k=0;k<i;k++)ans.push_back(A[k]);
      if(b>1){
        A[i].second-=B[0].second;
        if(A[i].second>0)ans.push_back(A[i]);
      }
      for(int k=0;k<c;k++)ans.push_back(C[k]);
      A[i+b-1].second-=B[b-1].second;
      if(A[i+b-1].second>0)ans.push_back(A[i+b-1]);
      for(int k=i+b;k<a;k++)ans.push_back(A[k]);
      break;
    }
  }
  if(ans.empty())ans=A;

  for(int i=0;i<(int)ans.size();i++){
    if(i+1<(int)ans.size() && ans[i].first==ans[i+1].first){
      ans[i+1].second+=ans[i].second;
    }else{
      cout<<ans[i].first<<' '<<ans[i].second<<' ';
    }
  }
  cout<<'$'<<endl;

  return 0;
}

Measured memory_bytes: 1240
array = []
while True:
    value = input().split()
    value = [int(x) for x in value]
    if value[0] == 0 and value[1] == 0:
        break
    else:
        array.append(value)

for i in range(0, len(array)):
    for j in range(0, array[i][0]):
        for k in range(0, array[i][1]):
            print("#", end="")
        print("")
    print("")

Measured memory_bytes: 9068
#include<cstdio>
#include<cstring>
int main()
{
    int n,t,tem=0;
    long long int ans=0;
    scanf("%d%d",&n,&t);
    for(int i = 1; i <= n; i++)
    {
        long long int ot;
        scanf("%lld",&ot);
        if(tem > ot)
            ans += (ot + t) > tem ? (ot + t - tem) : 0;
        else
            ans += t;
        tem = (ot+t) > tem ? (ot+t) : tem;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define INFLL 1e17
#define PI 2*acos(0.0)
#define show(x) cout<< #x <<" is "<< x <<"\n"
using namespace std;

#define FS first
#define SC second
#define PB(t) push_back(t)
#define LEN(t) ((int)t.size())
#define ALL(t) t.begin(),t.end()
#define MP(x, y) make_pair((x), (y))
#define Fill(a,c) memset(&a, c, sizeof(a))
#define POPCOUNT __builtin_popcount

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

int main() {
    #ifdef LJ
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    for (int p, q, r; cin >> p >> q >> r;) {
        VI nums = {p, q, r};
        sort(ALL(nums));
        cout << nums[0] + nums[1] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Deque<Integer> numbers = new ArrayDeque<>();
		String str;
		int a = 0;
		int b = 0;

		while(scan.hasNext()) {
			str = scan.next();
			switch(str) {
				case "+":
					a = numbers.pop();
					b = numbers.pop();
					numbers.push(a + b);
					break;
				case "-":
					b = numbers.pop();
					a = numbers.pop();
					numbers.push(a - b);
					break;
				case "*":
					a = numbers.pop();
					b = numbers.pop();
					numbers.push(a * b);
					break;
				default:
					numbers.push(Integer.parseInt(str));
			}

		}

		System.out.println(numbers.peek());

	}
}



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

int main()
{
    /* ------- 宣言と入力 ------- */

    long long int H;

    cin >> H;

    /* ------- 計算 ------- */

    int jou;

    for (int i = 0; i < 100; i++)
    {
        if (H < pow(2, i + 1))
        {
            jou = i;
            break;
        }
    }

    long long int ans=0;

    for (int i = 0; i <= jou; i++)
    {
        ans += pow(2, i);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y=list(map(int,input().split()))

if A+B <= 2*C:
    print(A*X + B*Y)
    exit()
else:
    cnt = 0
    if X >= Y:
        cnt += 2*C*Y
        X -= Y
        if A >= 2*C:
            cnt += 2*X*C
        else:
            cnt += X*A
    else:
        cnt += 2*C*X
        Y -= X
        if B >= 2*C:
            cnt += 2*Y*C
        else:
            cnt += Y*B
print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
   long long int a,b,k;
   scanf("%lld %lld %lld",&a,&b,&k);
   if(a > k){
      a = a-k;
   }else{
      k = k-a;
      a = 0;
      if(k > b){
         b = 0;
      }else{
         b = b-k;
      }
   }
   printf("%lld %lld\n", a, b);

   return 0;
}



Measured memory_bytes: 1708
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 998244353

ll d[100100];

long long modpow(long long a, long long b){ 
  long long r = 1LL;
  while(b){
    if(b & 1LL)r *= a;
    if(r >= MOD)r %= MOD;
    a *= a;
    if(a >= MOD)a %= MOD;
    b >>= 1LL;
  }
  return r % MOD;
}

int main(){
  ll n;
  cin>>n;
  ll a1;
  cin>>a1;
  if(a1!=0){
    cout << 0 << endl;
    return 0;
  }
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  clr(d,0);
  rep(i,0,n-1){
    ll a;
    cin>>a;
    if(a==0){
      cout << 0 << endl;
      return 0;
    }
    d[a]++;
  }
  if(d[1]==0){
    cout << 0 << endl;
    return 0;
  }
  ll c = 0;
  rep(i,1,100050){
    if(d[i]!=0&&d[i+1]==0)c++;
  }
  if(c>1){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  rep(i,1,100050){
    if(d[i+1]==0)break;
    ans *= modpow(d[i],d[i+1]);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int w,h,x,y,r;

  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

  if(x-r<0||y-r<0||x+r>w||y+r>h)printf("No\n");
  else printf("Yes\n");

  return 0;
}

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

#define FOR(i,n) for(int i=0;i<n;i++)
#define PRINT(a) cout<<a<<"\n"
#define QUO(x,y) (x-x%y)/y	//x÷yの商
 
int main(){

	int a,b,c;
	cin>>a>>b>>c;

	if(b-a==c-b)PRINT("YES");
	else PRINT("NO");
	
	

	return 0;
}

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

using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, L;
int a[N], pre[N][35];

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

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

    cin >> L;
    for(int i = 1; i <= n; ++i) {
        int l = i, r = n;
        while(r > l)    {
            int m = (l + r + 2) / 2;
            if(a[m] - L > a[i])
                 r = m - 1;
            else l = m;
        }
        pre[i][0] = l;
    }
    for(int i = 1 ; i < 17 ; ++i)
        for(int j = 1 ; j + (1 << i) - 1 <= n ; ++j)
            pre[j][i] = pre[pre[j][i - 1]][i - 1];
    int q;
    cin >> q;
    while(q --) {
        int ha, hb;
        cin >> ha >> hb;
        if(ha > hb) swap(ha, hb);

        int res = 0;
        for(int i = 16 ; i >= 0; --i)   {
            if(!pre[ha][i])
                continue;
            if(pre[ha][i] < hb) {
                ha = pre[ha][i];
                res += (1 << i);
            }
        }
        if(ha < hb) ++res;
        cout << res << '\n';
    }
}


Measured memory_bytes: 14976
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<iostream>
using namespace std;
#include<string>
#include<sstream>
#include<algorithm>
#include<functional>
#include<set>
#include<math.h>
#include<map>
#include<vector>
#include<list>
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define fi first
#define se second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	vector<int>a(1e+5);
	int n,neq=0;
	LL ans = 0;
	LL MIN = INF;
	cin >> n;
	forn(i, 1, n+1)cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		if (a[i] < 0)neq++;
		ans += abs(a[i]);
		MIN = MMIN(MIN, abs(a[i]));
	}
	if(neq%2!=0)cout << ans-2*MIN << '\n';
	else cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N; 
	vector<int>P(N);
	for (int n = 0;n<N;++n) {
		cin >> P[n];
	}
	int ans = 0;
	for (int n = 1;n<N-1;++n) {
		if (P[n-1]<P[n] && P[n]<P[n+1]) {
			ans++;
		}
		if (P[n - 1] > P[n] && P[n] > P[n + 1]) {
			ans++;
		}
	}

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

Measured memory_bytes: 3592
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define N 200000

int main(){	
	char a[3];
    cin>>a[0]>>a[1]>>a[2];

    int five = 0,seven = 0;
    for(int i=0;i<3;++i){
        if(a[i] == '5')++five;
        else if(a[i] == '7')++seven;
    }
    if(five==2 && seven==1)cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 02.09.2017 15:17:17       
**/
#include <bits/stdc++.h>

using namespace std;

int a[1234567];

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


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

	int64 K, A, B;
	cin >> K >> A >> B;
	if (K >= A-1 && B-A >= 2) {
		cout << A+ (B-A)*((K-(A-1))/2) + (K-(A-1))%2 << endl;
	} else {
		cout << K+1 << endl;
	}
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int a, b, c;cin >> a >> b >> c;
    if(a%2 == 1 || b%2 == 1 || c%2 == 1){
        cout << 0 << endl;
        return 0;
    }

    if(a == b && b == c && c == a){
        cout << -1 << endl;
        return 0;
    }

    int count = 0;
    while(a%2 == 0 && b%2 == 0 && c%2 == 0){
        count++;
        int na = b/2 + c/2;
        int nb = c/2 + a/2;
        int nc = a/2 + b/2;
        a = na;
        b = nb;
        c = nc;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long
const int INF=1000000007;
int x,a,b;
int main(){
cin>>x>>a>>b;
  cout<<(x-a)%b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node
{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
} Node;

void insert(int k);
void inorder(Node *x);
void preorder(Node *k);

Node *root, *NIL;

void insert(int k)
{
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;

    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL){
    root=z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node *x)
{
  if(x == NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

void preorder(Node *x)
{
  if(x == NIL) return;
  printf(" %d", x->key);
  preorder(x->left);
  preorder(x->right);
}
  
int main()
{
  int i, o, k;
  char s[50];

  scanf("%d", &o);

  for(i=0; i<o; i++){
    scanf("%s", s);

    if(strcmp(s, "insert") == 0){
      scanf("%d", &k);
      insert(k);
    }
    else if(strcmp(s,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else
      continue;
  }
  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    c -= a+b;
    bool ans = true;
    if(c < 0) ans = false;
    else{
        long double dd = ld(c*c)/4;
        if(dd <= a*b) ans = false;
        //outset(20);
        //cout << dd << endl;
        //cout << a*b << endl;
        
    }
    
    ans ? cyes : cno;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,a;
cin>>h>>a;
if(a>=1&&a<=pow(10,4)&&h>=1&&h<=pow(10,4))
{
int n=0;
while(h>0){
    h -= a;
    n++;
}
cout<<n<<endl;}



return 0;}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
vector<int> prime(0, 0);

void eratos(int n){
  vector<bool> N(n+10,true);
  N[0] = false;
  N[1] = false;
  for(int i=2; i<=n; i++){
    if (N[i])
      prime.push_back(i);
    int j=2;
    while (i*j <= n)
      N[i*j++] = false;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  eratos(1001000);//nまでの素数を抽出
  
  ll N; cin >> N;
  ll cnt = 0;
  ll end = prime.size();
  for(ll i=0; i<end; i++){
    ll tmp=0;
    while (N % prime[i] == 0){
      N /= prime[i];
      tmp++;
    }
    ll j = 1;
    while (tmp - j >= 0){
      tmp -= j;
      j++;
      cnt++;
    }
    if (N < prime[i])
      break;
    if (i == end -1)
      cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3948
n, k = map(int, input().split())
a = list(map(int, input().split()))

s = []
order = [-1] * (n+1)

c = 1
l = 0

i = 1

while order[i] == -1:
    order[i] = len(s)
    s.append(i)
    i = a[i-1]

c = len(s) - order[i]
l = order[i]

if k < l:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l+k])



Measured memory_bytes: 32388
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int m;
	cin >> m;
	cout << 24 + 24 - m << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 810;
char s[N][N];
int x,y;
int f[N][N];
PII q[N*N];
int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
bool in[N][N];
int main(){
	int H,W,K;
	cin>>H>>W>>K;
	for(int i =1 ;i<=H;i++) scanf("%s",s[i]+1);
	for(int i =1;i<=H;i++) for(int j  = 1;j<=W;j++) if(s[i][j]=='S'){
		x = i,y = j;
	}
	for(int i =0;i<N;i++) for(int j =0;j<N;j++) f[i][j]=1e9;
	f[x][y] = 0;
	int head = 0,tail = 0;
	q[0] = mp(x,y);
	int ans = 1e9;
	while(head<=tail){
		PII tmp = q[head++];
		//cout<<tmp.X<<' '<<tmp.Y<<endl;
		if(tmp.X==1 || tmp.X == H || tmp.Y ==1 || tmp.Y == W) ans = 1;
		int tmp2 = min(min(H-tmp.X,tmp.X-1),min(W-tmp.Y,tmp.Y-1));
		ans = min(ans,1+(tmp2+K-1)/K);
		for(int i =0;i<4;i++){
			x = tmp.X+dx[i];
			y = tmp.Y+dy[i];
			if(x>0 && x<=H && y>=0 && y<=W && f[tmp.X][tmp.Y]+1<=f[x][y] && s[x][y]=='.'){
				f[x][y] = f[tmp.X][tmp.Y]+1;
				if(f[x][y]<=K)
				if(!in[x][y]) {
					in[x][y] = 1;
					q[++tail] = mp(x,y);
				}
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
} 

Measured memory_bytes: 9216
#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,M,temp;
  cin >> N >> M;
  vector<int>vec(N,0);
  REP(i,2*M){
    cin >> temp;
    vec.at(temp-1)++;
  }
  REP(i,N)cout << vec.at(i) << endl;;
}



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

int main() {
    int K;
    cin >> K;
    if(K<10){
        cout << K << endl;
        return 0;
    }
    vector<ll> A(9);
    for(int i=1; i<10; i++){
        A.at(i-1) = i; 
    }
    int i = 8; // 0-indexed
    int it1 = 0; // 1桁目が始まるindex
    int it2 = 8; // 1桁目が終わるindex
    int j = it1;
    while(i<=K){
        while(j<=it2){
            if(A.at(j)%10==0) {
                A.push_back(A.at(j)*10 + 0);
                A.push_back(A.at(j)*10 + 1);
                i += 2;
            } else if(A.at(j)%10==9) {
                A.push_back(A.at(j)*10 + 8);
                A.push_back(A.at(j)*10 + 9);
                i += 2;
            } else {
                for(int b = -1; b <= 1; b++){
                    A.push_back(A.at(j)*10 + A.at(j)%10 + b);
                    i++;
                }            
            }
            j++;
        }
        it1 = it2+1;
        it2 = i;
    }
    //rep(i,K) cout << A.at(i) << endl;
    cout << A.at(K-1) << endl;
    return 0;
}


Measured memory_bytes: 2676
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#define maxn 100005
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int ans=max(a+b,a-b);
    printf("%d\n",max(ans,a*b));
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n = int(input())

tree= [[] for i in range(n+1)]
color=[-1 for i in range(n+1)]
que=[]
for i in range(n-1):
    u,v,w=map(int,input().split(' '))
    tree[u].append([v,w])
    tree[v].append([u,w])

que.append(1)
color[1]=0


while(len(que)!=0): 
    node = que.pop()
    for next_node,w in tree[node]:
        if color[next_node]==-1:
            # print((color[node]+cost[node][next_node])%2)
            color[next_node]=(color[node]+w)%2
            que.append(next_node)
            # print(color)
for i in range(1,len(color)):
    print(color[i])


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

int main() {
    int a, b;
    cin >> a >> b;
  if ( (a + b) % 2 == 0 ) {
    cout << (a + b) / 2 << endl;
  }
  else {
    cout << (a + b + 1 ) / 2 <<endl;
  }
}

Measured memory_bytes: 256
w,h,n = map(int, input().split())
xya = [list(map(int, input().split())) for i in range(n)]
lx = 0
rx = w
ly = 0
ry = h
for x,y,a in xya:
  if a == 1:
    lx = max(lx,x)
  elif a == 2:
    rx = min(rx,x)
  elif a == 3:
    ly = max(ly,y)
  else:
    ry = min(ry,y)
ans = max(0,rx-lx) * max(0,ry-ly)
print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
import math
import itertools
def distance(N, ar):
    table = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if i != j:
                dx = ar[i][0] - ar[j][0]
                dy = ar[i][1] - ar[j][1]
                table[i][j] = math.sqrt(dx * dx + dy * dy)
    return table    

def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [[0, 0],[1, 0],[0, 1]])
    2.2761423749
    >>> print_ans(2, [[-879, 981], [-866, 890]])
    91.9238815543
    >>> print_ans(8, [[-406, 10],[512, 859],[494, 362],[-955, -475],[128, 553],[-986, -885],[763, 77],[449, 310]])
    7641.9817824387
    """
    fac = math.factorial(N)
    perm_list = list(itertools.permutations(range(N) ) )
    table = distance(N, ar)
    dist = 0
    for perm in perm_list:
        for i in range(len(perm) -1):
            dist += table[perm[i]][perm[i+1]]
    print(dist/fac)


if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, ar)


Measured memory_bytes: 8052
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

min_cost = min(a) + min(b)

for i in range(M):
  x = list(map(int,input().split()))
  cost = a[x[0] - 1] + b[x[1] - 1] - x[2]

  if min_cost > cost:
    min_cost = cost

print(min_cost)

Measured memory_bytes: 18608
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextInt();
		long w = sc.nextInt();
		long s = sc.nextInt();
		long t = sc.nextInt();
		if (h * w % 2 == 1 && (s * w + t) % 2 == 1) {
		    System.out.println("No");
		} else {
		    System.out.println("Yes");
		}
	}
}



Measured memory_bytes: 26272
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;
typedef  long double ld;
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; i++)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll> 
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define vd vector<double>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
const long long INF = 1ll << 32;
bool isPrime(int n) 
{ 
    // Corner case 
    if (n <= 1)  return false; 
  
    // Check from 2 to n-1 
    for (int i=2; i<n; i++) 
        if (n%i == 0) 
            return false; 
  
    return true; 
} 
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    fast;
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<0<<endl;
    else
        cout<<1000-n%1000<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
const int BASE = 10;
const int BB = BASE*BASE;
int N, T;

int main() {
  scanf("%d", &N);
  int T = 1;
  int ret = 0;
  while ((BASE*T - 1) <= N) {
    ret += (BASE - 1) * T;
    T *= BB;
  }
  if (T <= N) {
    ret += N - T + 1;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main()
{
	int N, R;
	int IR = 0;

	std::cin >> N >> R;

	if (N >= 10)
	{
		IR = R;
	}
	else
	{
		IR = R + 100 * (10 - N);
	}

	std::cout << IR;

	return 0;
}

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

int main(){
    int K;
    string S;
    cin >> K >> S;
  
  	if(K >= (int)S.size()){
      cout << S << endl;
    } else {
      cout << S.substr(0,K) << "..." << endl;
    }
}

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

#define pb push_back
#define mx 200005
#define MOD 1000000007
#define optimize                                                               \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#define inf 0x3f3f3f3f
#define READ freopen("in.txt", "r", stdin);
#define WRITE freopen("out.txt", "w", stdout);

int main(int argc, char *argv[]) {
  string S, T;
  cin >> S >> T;

  int correct = 0;
  for (int i = 0; i < 3; ++i) {
    if (S[i] == T[i]) {
      correct++;
    }
  }

  cout << correct << "\n";

  return 0;
}


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

const int N_MAX = 200005;
const int M_MAX = 200005;
const int MOD = 998244353;

long long int col[N_MAX];
long long int blo[N_MAX];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    long long int ans = 0;
    blo[0] = 1;
    blo[1] = n-1;
    int copn = n;
    for(int i = 2; i <= k; i++){
        blo[i] = blo[i-1] * (n-i);
        blo[i] %= MOD;
        blo[i] *= modinv(i, MOD); //あやしい
        blo[i] %= MOD;
    }
    col[1] = m;
    if (n - 1 <= k){
        ans += col[1] * blo[n-1];
        ans %= MOD;
    }
    for(int i = 2; i <= n; i++){
        col[i] = col[i-1] * (m-1);
        col[i] %= MOD;
        if (n-i <= k){
            ans += col[i] * blo[n-i];
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}




int main(){

    ll N;
    cin >> N;
    string s;
    cin >> s;
    vector<ll> numW(N,0);
    FOR(i,0,N){
      numW[i] = s[i]=='W';
      if(i) numW[i] += numW[i-1]; //index i までにWが何個あるか
    }

    ll ans = min(numW[N-1],N-numW[N-1]);
    FOR(i,0,N){//0~iまで赤,i+1~N-1まで白
      ll a,b,c,d;
      a = i+1 - numW[i];
      b = numW[i];
      d = numW[N-1] - numW[i];
      c = N - i - 1 - d;
      ans = min(ans , max(b,c) ); 
    }
    cout << ans << endl;
}




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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            if (vals[1] == 100) vals[1]++;
            var result = Math.Pow(100, vals[0]) * vals[1];
            Console.WriteLine((int)result);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main(void){
  int N, K, Q;
  cin >> N >> K >> Q;
  int A[Q];
  int i;
  for(i=0; i<Q; i++)
    cin >> A[i];

  int win_n[N+1] = {0};
  for(i=0; i<Q; i++)
    win_n[A[i]]++;

  for(i=1; i<=N; i++){
    if( (Q - win_n[i]) < K)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  
  return 0;
}


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

int main(){
  int n;cin >> n;
  vector<int> h(n);for(int i=0;i<n;i++)cin >> h[i];
  int j=0,maxi = 0;
  for(int i=0;i<n-1;i++){
    if(h[i] < h[i+1]){
      maxi = max(maxi,j);
      j = 0;
    } else {
      j += 1;
    }
  }
  if(h[n-2] >= h[n-1])maxi = max(maxi,j);
  cout << maxi << endl;
  return 0;
}

Measured memory_bytes: 640
n,m =map(int,input().split())
a=[0]*n
b=[0]*n
c=[0]*m
d=[0]*m
for i in range(n):
    a[i],b[i]=map(int,input().split())
for i in range(m):
    c[i],d[i]=map(int,input().split())

for i in range(n):
    for j in range(m):
        if j==0:
            ind=0
            dis=abs(a[i]-c[j])+abs(b[i]-d[j])
        else:
            if abs(a[i]-c[j])+abs(b[i]-d[j])<dis:
                ind=j
                dis = abs(a[i] - c[j]) + abs(b[i] - d[j])
    print(ind+1)

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    int N, K, ans = 1001001001, tmp;
    cin >> N >> K;
    vector<int>H(N);

    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    sort(H.begin(), H.end());

    for (int i = 0; i <= N- K; i++) {
        ans = min(ans, H[i + K - 1] - H[i]);
    }

    cout << ans;

    return 0;

}



Measured memory_bytes: 640
import sys
input = sys.stdin.readline
S = str(input())
N = 3
goal = 7
for i in range(2**N):
    result = int(S[0])
    for j in range(N):
        if i & 2**(N-j-1):
            result += int(S[j+1])
        else:
            result -= int(S[j+1])
    if result != goal:
        continue
    print(S[0], end="")
    for j in range(N):
        if i & 2**(N-j-1):
            print('+', end="")
        else:
            print('-', end="")
        print(S[j+1], end="")
    print("=7")
    break
    

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

int main(){

  ll N=0;
  cin>>N;

  ll ans=N;


  for(long long i=1;i<N;i++){

    if( i>sqrt(N) )break;

    if(N%i!=0)continue;
    
	ans=min(ans,i+N/i-2);
    
  }

  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

pi a[3];

double AB, BC, CA;
double angA, angB, angC;

bool trial(double v){
	if(AB - v / tan(angA/2) - v / tan(angB/2) >= 2 * v) return 1;
	if(BC - v / tan(angB/2) - v / tan(angC/2) >= 2 * v) return 1;
	if(CA - v / tan(angC/2) - v / tan(angA/2) >= 2 * v) return 1;
	return 0;
}

int main(){
	for(int i=0; i<3; i++){
		cin >> a[i].first >> a[i].second;
	}
	AB = hypot(a[1].first - a[0].first, a[1].second - a[0].second);
	BC = hypot(a[2].first - a[1].first, a[2].second - a[1].second);
	CA = hypot(a[0].first - a[2].first, a[0].second - a[2].second);
	angA = acos((AB * AB + CA * CA - BC * BC) / (2 * AB * CA));
	angB = acos((BC * BC + AB * AB - CA * CA) / (2 * BC * AB));
	angC = acos((CA * CA + BC * BC - AB * AB) / (2 * CA * BC));
	double s = 0, e = 1000;
	for(int i=0; i<100; i++){
		double m = (s+e)/2;
		if(trial(m)) s = m;
		else e = m;
	}
	printf("%.15f\n", s);
}


Measured memory_bytes: 512