akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>
// #include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif



int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    
    long long int n, X, M; std::cin >> n >> X >> M;
    std::vector<long long int> Sum(M, 0);
    std::vector<int> Pos(M, -1);
    int idx = 0; long long int S = 0;
    for(; idx < n; ++idx){
        if(Pos[X] != -1) break;
        Sum[X] = S;
        Pos[X] = idx;
        S += X;
        X = (X * X) % M;
    }
    long long int remain = n - idx;
    const int loop = idx - Pos[X];

    const long long int DS = S - Sum[X];


    const long long int K = remain / loop;
    long long int d = remain % loop;
    long long int res = S + DS * K;
    while(d--){
        res += X;
        X = (X * X) % M;
    }
    std::cout << res << '\n';




    

    return 0;
}

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

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

    int n; cin >> n;
    bool color[8] = {false};
    int wizard = 0;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (a < 400) color[0] = true;
        else if (a < 800) color[1] = true;
        else if (a < 1200) color[2] = true;
        else if (a < 1600) color[3] = true;
        else if (a < 2000) color[4] = true;
        else if (a < 2400) color[5] = true;
        else if (a < 2800) color[6] = true;
        else if (a < 3200) color[7] = true;
        else wizard++;
    }

    int colors = 0;
    for (int i = 0; i < 8; ++i) {
        if (color[i] == true) colors++;
    }

    if (colors == 0) {
        cout << "1 " << wizard << endl;
    } else {
        cout << colors << " " << colors + wizard << endl;
    }

    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input.trim();
  input = input.split(" ");
console.log(String.fromCharCode(input[0].charCodeAt()-32)+""+String.fromCharCode(input[1].charCodeAt()-32)+""+String.fromCharCode(input[2].charCodeAt()-32))
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000

typedef struct{
  int top;
  int S[MAX];
}Stack;


void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

int isEmpty(Stack *st)
{
  return st->top == 0;
}

int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの開始位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\')                                  // '\' を発見
      push(i, &st1);
    else if (!isEmpty(&st1) && c == '/') {          // '/' を発見
      int j = pop(&st1);
      sum += i - j;
      int a = i - j;
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {
        pop(&st2_j);
        a += pop(&st2_a);
      }
      push(j, &st2_j);
      push(a, &st2_a);
    }
  }

  // 水たまりの水量を出力
  printf("%d\n", sum);
  printf("%d", st2_a.top);
  for (int i = 1; i <= st2_a.top; i++)
    printf(" %d", st2_a.S[i]);
  printf("\n");

  return 0;
}




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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;

    vector<set<int>> al(26);

    for(int i = 0; i < n; i++){
      int p = int(s[i]-'a');
      al[p].insert(i);
    }


    for(int k = 0; k < q; k++){
      int qt; cin >> qt;
      if(qt == 1){
        int iq; cin >> iq;
        iq--;
        char cq; cin >> cq;
        
        int p = int(cq-'a');       
        int op = int(s[iq]-'a');
        al[op].erase(iq);
        al[p].insert(iq);
        s[iq] = cq;

      } else {
        int l, r; cin >> l >> r;
        l--; 

        int cnt = 0;
        for(int i = 0; i < 26; i++){
          auto itr = al[i].lower_bound(l);
          if(itr != al[i].end() && *itr < r) cnt++;
        }
        printf("%d\n", cnt);
      }

    }


    return 0;
}


Measured memory_bytes: 24220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#define ll long long
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<char>>sym(n);
	vector<vector<int>>vis(n);
	vector<vector<int>>dist(n);
	for (int i = 0;i < n;i++)
	{
		sym[i].resize(m);
		vis[i].resize(m);
		dist[i].resize(m);
		for (int j = 0;j < m;j++)
		{
			cin >> sym[i][j];
		}
	}
	int max = 0;
	int count = 0;
	for (int i = 0;i < n;i++)
	{
		for (int j = 0;j < m;j++)
		{
			count = 0;
			if (sym[i][j] == '.')
			{
				for (int k = 0;k < n;k++)
				{
					for (int l = 0;l < m;l++)
					{
						vis[k][l] = 0;
						dist[k][l] = 0;
					}
				}
				queue<pair<int, int>> q;
				vis[i][j] = 1;
				q.push(make_pair(i, j));
				while (!q.empty())
				{
					pair<int, int> x = q.front();
					q.pop();
					if (count < dist[(x.first)][x.second])
						count = dist[(x.first)][x.second];
					if (x.first < n-1 && sym[(x.first)+1][x.second]=='.' && vis[(x.first) + 1][x.second]==0)
					{
						vis[(x.first) + 1][x.second] = 1;
						q.push(make_pair(x.first + 1, x.second));
						dist[(x.first) + 1][x.second] = dist[(x.first)][x.second] + 1;
					}
					if (x.first >0 && sym[(x.first) -1][x.second] == '.' && vis[(x.first) - 1][x.second] == 0)
					{
						vis[(x.first) - 1][x.second] = 1;
						q.push(make_pair(x.first - 1, x.second));
						dist[(x.first) - 1][x.second] = dist[(x.first)][x.second] + 1;
					}
					if (x.second < m-1 && sym[(x.first)][x.second+1] == '.' && vis[(x.first)][x.second+1] == 0)
					{
						vis[(x.first)][x.second+1] = 1;
						q.push(make_pair(x.first, x.second+1));
						dist[(x.first)][x.second+1] = dist[(x.first)][x.second] + 1;
					}
					if (x.second >0 && sym[(x.first)][x.second-1] == '.' && vis[(x.first)][x.second-1] == 0)
					{
						vis[(x.first)][x.second-1] = 1;
						q.push(make_pair(x.first, x.second-1));
						dist[(x.first)][x.second-1] = dist[(x.first)][x.second] + 1;
					}
				}
				if (max < count)
					max = count;

			}
		}
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int n, num=0;
    double cnt=0;
    cin >> n;
    rep(i, n){
        num += 1;
        if(num%2 == 1) cnt++;
    }
    cout << cnt / n << endl;
}

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

vector<pair<long long int,long long int> > w[100005];
bool vis[100005];
int color[100005];


void bfs(long long int s)
{
    vis[s]=true;
    queue<long long int>q;
    q.push(s);
    while(!q.empty())
    {
        long long int x=q.front();
        q.pop();
        for(int k=0;k<w[x].size();k++)
        {
            long long int j=w[x][k].first;
            if(vis[j]==false)
            {
                vis[j]=true;
                q.push(j);
               if(w[x][k].second%2==0)
               {
                   color[j]=color[x];
               }
               else{
                color[j]=color[x]^1;
               }
            }
        }

    }
}

main()
{
    long long int n,i,j;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        long long int x,y,d;
        cin>>x>>y>>d;
         w[x].push_back({y,d});
         w[y].push_back({x,d});
    }

    color[1]=1;
    bfs(1);
    for(i=1;i<=n;i++)
    {
        cout<<color[i]<<endl;
    }
}



Measured memory_bytes: 11500
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
    ll n;
    cin>>n;
    if(n==0)return 0;
    V<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(all(a));
    int ans=INT_MAX;
    for(int i=0;i<n-1;i++){
       chmin(ans,a[i+1]-a[i]);
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3152
import itertools

n, k = map(int,input().split())
ans = 0
li = list(range(n+1))

for i in range(k,n+2):
    a = int(1/2*i*(i-1))
    b = n*i-(int(1/2*i*(i-1)))
    ans += b - a + 1

print(ans%(10**9+7))

Measured memory_bytes: 66700
#include <iostream>

using namespace std;

int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		cout<<"Yes"<<endl;
	else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
 
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
 
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int X, A;
	cin>>X>>A;
	cout<<(X>=A)*10<<'\n';
	return 0;
}

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

typedef long long ll;
typedef long double ld;
const ll M=1e9+7;
const ll MAXN=1e6+7;
const ld pi=acos(-1);

#define gi(n) ll n=read()
#define endl '\n'
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define per(i,a,b) for(ll i=b-1; i>=a; --i)

typedef vector<ll> V;
typedef vector<V> VV;
typedef set<ll> S;
typedef pair<ll,ll> pl;
typedef vector<pl> Vp;

#define all(v) v.begin(),v.end()
#define pb push_back
#define fs first
#define sc second

inline ll read(){
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll mul(ll a,ll b,ll P){return b?(mul(a*2%P,b>>1,P)+(b&1?a:0))%P:0;}
ll pow1(ll p,ll d, ll P){return d?mul(pow1(mul(p,p,P),d>>1,P),(d&1?p%P:1),P):1;}

V prime;
bool is_composite[MAXN];
void sieve (ll n){
	std::fill (is_composite, is_composite + n, false);
	rep(i,2,n){
		if(!is_composite[i]) prime.pb(i);
		for(ll j = 0; j < prime.size() && i*prime[j] < n; ++j){
			is_composite[i*prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
}
ll modInverse(ll a, ll m){
	ll m0=m,y=0,x=1;
	if(m==1) return 0;
	while(a>1){
		ll q=a/m,t=m;
		m=a%m;
		a=t; 
		t=y;

		y = x-q*y; 
		x = t;
	}
	if(x<0) x += m0;
	return x; 
}

void doit(){
	map<string,ll> m;
	gi(n);
	string s;
	rep(i,0,n) cin>>s, m[s]++;
	string arr[4]={"AC","WA","TLE","RE"};
	rep(i,0,4) cout<<arr[i]<<" x "<<(m[arr[i]]?m[arr[i]]:0)<<endl;
}
int main(){
	//for(gi(t);t--;cout<<endl)
		doit();
	return 0;
}

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

const int N = 1000 * 100 + 10;
int a[N], b[N], n, par[N * 2], sz[N * 2];

int get_par(int root) {
	return par[root] == root? root: par[root] = get_par(par[root]);
}

void Union(int v, int u) {
	v = get_par(v), u = get_par(u);
	if (v == u)
		return;
	if (sz[u] > sz[v])
		swap(v, u);
	sz[v] += sz[u];
	par[u] = v;
}

int main() { 
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], a[n] ^= a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i], b[n] ^= b[i];
	map<int, int> cnt;
	for (int i = 0; i <= n; i++)
		cnt[a[i]]++;
	for (int i = 0; i < n; i++) {
		cnt[b[i]]--;
		if (cnt[b[i]] < 0)
			return cout << "-1\n", 0;
	}
	vector<int> vec;
	for (int i = 0; i < n; i++)
		if (a[i] != b[i])
			vec.push_back(a[i]), vec.push_back(b[i]), ans++;
	vec.push_back(a[n]), vec.push_back(b[n]);
	sort(vec.begin(), vec.end());
	vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
	int s = (int)(vec.size());
	for (int i = 0; i < s; i++)
		par[i] = i, sz[i] = 1;
	for (int i = 0; i <= n; i++) 
		if (a[i] != b[i]) {
			a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
			b[i] = lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin();
			Union(a[i], b[i]);
		}
	for (int i = 0; i < s; i++)
		if (get_par(i) == i)
			ans++;
	cout << ans - 1 << '\n';
	return 0;
}


Measured memory_bytes: 10464
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int []h=new int[n];
		int i,ans=0,lim=0;
		for(i=0;i<n;i++) {
			h[i]=sc.nextInt();
			if(lim<=h[i]) {
				lim=h[i];
				ans++;
			}
		}
		System.out.println(ans);
		

	}

}


Measured memory_bytes: 21716
import scala.io.StdIn.{readLine,readInt}

object Main {
  def cut(c:Array[Int],n:Int,k:Int) = {
    c.slice(k,2*n) ++ c.slice(0,k)
  }

  def rif(c:Array[Int],n:Int) = {
    val a = c.slice(0,n)
    val b = c.slice(n,n+n)
    (0 until 2*n).map{ i=> if(i%2==0) a(i/2) else b((i-1)/2) }.toArray
  }

  def main(args:Array[String]) = {
    val n = readInt
    val m = readInt
    var a = (0 until 2*n).map { i => i+1 }.toArray
    for(i<-0 until m) {
      val k = readInt
      if(k==0) a = rif(a,n)
      else a = cut(a,n,k)
    }
    println(a.mkString("\n"))
  }

}

Measured memory_bytes: 53144
import java.io.*;
import java.util.*;

public class Main {
    private static boolean elapsed = false;

    private void solve(Scanner sc, PrintWriter out) {
        int a = sc.nextInt();   
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a + b == c || a + c == b || b + c == a) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

Measured memory_bytes: 10324
#include <iostream>
typedef unsigned long long ULL;
using namespace std;
inline ULL round(ULL t)
{
    cout << t << endl;
    return ((ULL)((double)t / 1000 + 0.5))*1000;
}
int main()
{
    int t;
    ULL res = 100000;
    cin >> t;
    while(t--)
    {
        res *= 1.05;
        if(res % 1000 !=0)
            res += 1000 - res % 1000;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

typedef pair<int, int> P;

signed main() {
	int n, k;
	cin >> n >> k;
	
	P a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}

	sort(a, a + n);
	int count = 0;
	for (int i = 0; i < n; i++) {
		count += a[i].second;
		if (count >= k) {
			cout << a[i].first << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1792
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define ll long long
#define ull unsigned long long
//#define int long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
                                                                    
typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 1e5 + 1;
int n , m;
int a[N];
string s;

main(){
	vector < char > ans;
	cin >> s;
	for(int i = 0 ; i < sz(s) ; i++){
		if(s[i] != 'B')
			ans.pb(s[i]);
		else if(sz(ans) != 0)
			ans.pop_back();
	}		
	for(auto to : ans)cout << to;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
int main() { 
    ll N; cin >> N;
    ll bn = pow(10, 15);
    for(int i=0; i<5; i++) {
        ll c; cin >> c;
        bn = min(bn, c);
    }
    cout << setprecision(16) << ceil(double(N)/bn)+4 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char str[310][610];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%s",str[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			str[i][j+n]=str[i][j];
	int ans=0;
	for(int s=0;s<n;s++){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(str[i][j+s]!=str[j][i+s])
					goto done;
		ans+=n;
		done:;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> vec[3];
ll n, c, d[35][35], f[550][550], a, res1 = 1000000000, k[3][35];
int main(void){
    // Your code here!
    cin >> n >> c;
    for (ll i = 1; i <= c; i++) {
        for (ll j = 1; j <= c; j++) {
            cin >> d[i][j];
        }
    }
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= n; j++) {
            cin >> a;
            vec[(i + j) % 3].push_back(a);
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 0; j != vec[1].size(); j++) {
            k[1][i] += d[vec[1][j]][i];
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 0; j != vec[2].size(); j++) {
            k[2][i] += d[vec[2][j]][i];
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 0; j != vec[0].size(); j++) {
            k[0][i] += d[vec[0][j]][i];
        }
    }
    for (ll i = 1; i <= c; i++) {
        for (ll j = 1; j <= c; j++) {
            for (ll l = 1; l <= c; l++) {
                if (i == j || j == l || l == i) continue;
                res1 = min(res1, k[0][i] + k[1][j] + k[2][l]);
            }
        }
    }
    cout << res1 << endl;
}


Measured memory_bytes: 2608
#include<cstdio>
using namespace std;
long long gcd(long long x,long long y)
{
    long long ans=0;
    while(y!=0)
   {
     ans=x%y;
     x=y;
     y=ans;
   }
    return x;
}
int main()
{
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	a--;
	long long cnt1=b/c;
	long long cnt2=a/c;
	long long cnt3=b/d;
	long long cnt4=a/d;
	long long cnt5=b/(c/gcd(c,d)*d);
	long long cnt6=a/(c/gcd(c,d)*d);
	long long ans=b-a-((cnt1-cnt2)+(cnt3-cnt4)-(cnt5-cnt6));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=3e5+5;

int n,a[N];

bool check(int l,int r) {
	if (l==r) return a[l]==l;
	if (!((r-l+1)&1)) return 0;
	for(int i=l+1;i<=r-1;i+=2) if (a[i]!=i) return 0;
	for(int i=l;i<=r;i+=2) if (a[i]==i) return 0;
	int lst=0;
	for(int i=l;i<=r;i+=2)
		if (a[i]<i) {
			if (a[i]<lst) return 0;
			lst=a[i];
		}
	lst=0;
	for(int i=l;i<=r;i+=2)
		if (a[i]>i) {
			if (a[i]<lst) return 0;
			lst=a[i];
		}
	return 1;
}

int main() {
	n=read();
	fo(i,1,n) a[i]=read();
	int lst=0,mx=0;
	fo(i,1,n) {
		mx=max(mx,a[i]);
		if (mx==i) {
			if (!check(lst+1,i)) {puts("No");return 0;}
			lst=i;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1280
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
char board[10][10];
int main(){
	rep(i,8){
		rep(j,8){
			cin>>board[i][j];
		}
	}
	char tmp[10][10];
	rep(i,8)rep(j,8)tmp[i][j]=board[i][j];
	cout <<90<<endl;
	for(int i =0;i < 8;i++){
		for(int j =0;j <8;j++){
			tmp[i][j]=board[7-j][i];
		}
	}
	rep(i,8){
		rep(j,8){
			cout<<tmp[i][j];
		}
		cout <<endl;
	}
	cout <<180<<endl;
	rep(i,8)rep(j,8)board[i][j]=tmp[i][j];
	for(int i =0;i < 8;i++){
		for(int j =0;j <8;j++){
			tmp[i][j]=board[7-j][i];
		}
	}
	rep(i,8){
		rep(j,8){
			cout<<tmp[i][j];
		}
		cout <<endl;
	}
	cout <<270<<endl;
	rep(i,8)rep(j,8)board[i][j]=tmp[i][j];
	for(int i =0;i < 8;i++){
		for(int j =0;j <8;j++){
			tmp[i][j]=board[7-j][i];
		}
	}
	rep(i,8){
		rep(j,8){
			cout<<tmp[i][j];
		}
		cout <<endl;
	}
	return 0;
}

Measured memory_bytes: 1144
//abc153D
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  long long h, c=1, c2=0, i;
  scanf("%lld", &h);

  while(h > 1){
    h/=2;
    c2+=c;
    c*=2;
  }
  printf("%lld", c + c2);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll n;
vector<vector<ll> >G(100010);
vector<vector<ll> >dp(100010,vector<ll>(2,-1));
ll dfs(ll i,ll p,ll c){
    if(dp[i][c]!=-1)return dp[i][c];
    ll res=1;
    for(auto e:G[i]){
        if(e==p)continue;
        ll a=dfs(e,i,0);
        ll b=dfs(e,i,1);
        if(c)res=res%inf*a%inf;
        else res=res%inf*(a+b)%inf;
    }
    dp[i][c]=res;
    return res;
}
int main(){
    cin>>n;
    rep(i,n-1){
        ll x,y;cin>>x>>y;
        x--;y--;
        G[x].pb(y);
        G[y].pb(x);
    }
    cout<<(dfs(0,-1,0)+dfs(0,-1,1))%inf<<endl;
}

Measured memory_bytes: 19584
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
constexpr long long mod = 998244353;
typedef pair<int, int> P;
typedef vector<int> vec;
typedef vector<vec> mat;

int kj[100005], kji[100005];
int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

void setkj(int n) {
	kj[0] = 1;
	rep(i, n)kj[i + 1] = kj[i] * (i + 1) % mod;
	rep(i, n + 1)kji[i] = modpow(kj[i], mod - 2);
}
int comb(int r, int c) {
	if (c<0 || r<c)return 0;
	return kj[r] * kji[c] % mod*kji[r - c] % mod;
}
int GJ(mat &A) {
	int N = A.size(), M = A[0].size();
	int rnk = 0;
	rep(i, M) {
		int pivot = -1;
		for (int j = rnk; j < N; j++) {
			if (A[j][i]) {
				pivot = j; break;
			}
		}
		if (pivot == -1)continue;
		swap(A[pivot], A[rnk]);

		rep(j, N) {
			if (j != rnk&&A[j][i]) {
				rep(k, M) {
					A[j][k] ^= A[rnk][k];
				}
			}
		}
		rnk++;
	}

	int res = 0;
	rep(i, N) {
		rep(j, M) {
			if (A[i][j]) {
				res++; break;
			}
		}
	}
	return res;
}

signed main() {
	setkj(305);
	int n, m; cin >> n >> m;
	mat A(n);
	rep(i, n) {
		A[i].resize(m);
		rep(j, m)cin >> A[i][j];
	}
	int r = GJ(A);

	/*
	rep(i, n) {
		rep(j, m)cout << A[i][j]; cout << endl;
	}
	cout << r << endl;
	*/

	int ans = modpow(2, n - r)*modpow(2, m - r) % mod;
	int d = 0;
	for (int i = 1; i <= r; i += 2) {
		d += modpow(3, r - i)*comb(r, i) % mod;
		d %= mod;
	}
	cout << d*ans%mod << endl;
}

Measured memory_bytes: 1024
n,k = map(int,input().split())
d = set(list(map(int,input().split())))

def solve(n):
  digits = str(n)
  for digit in digits:
    if int(digit) in d:
      return False
  return True

while True:
  if solve(n):
    print(n)
    break
  else:
    n += 1
  

Measured memory_bytes: 73408
n=int(input())
a=[int(i) for i in input().split()]
d=[0]*(10**5+1)
for i in a:
    d[i]+=1
ans=sum(a)
q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    ans=ans-b*d[b]+c*d[b]
    d[b],d[c]=0,d[b]+d[c]
    print(ans)

Measured memory_bytes: 20492
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;
const int MAX = 2*123500;

/** Problem1173 : The Balance of the World **/
int main()
{
	string s; int t;
	
	while (1) {
		getline(cin, s);
		if (s==".") break;
		
		stack<int> stak;
		bool flg=true;
		for (int i=0; i<s.length(); i++) {
			switch (s[i]) {
				case '[' :
					stak.push(1);
					break;
					
				case ']' :
					if (!stak.size()) {flg=false; break;}
					t = stak.top(); stak.pop();
					if (t!=1)
						flg=false;
					break;
					
				case '(' :
					stak.push(0);
					break;
					
				case ')' :
					if (!stak.size()) {flg=false; break;}
					t = stak.top(); stak.pop();
					if (t!=0)
						flg=false;
					break;
			}
		}
		cout << (flg&&!stak.size()?"yes":"no") << endl;
	}
	return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

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

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int dx = x2-x1;
	int dy = y2-y1;
	swap(dx,dy);
	dx *= -1;
	int x3 = x2 + dx;
	int y3 = y2 + dy;
	swap(dx,dy);
	dx *= -1;
	int x4 = x3 + dx;
	int y4 = y3 + dy;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}


Measured memory_bytes: 256
/*
   Author : tarang
*/
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
int a[106];
int main(){
   int x ;
   cin >> x ;
   if(x){
   	cout << 0 << endl;
   }
   else cout << 1 ;
}



Measured memory_bytes: 3616
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   static final int SIZE = 100;
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int[] counter = new int[SIZE];
      int a;
      int max = 0;
      
      while(sc.hasNext()){
         a = Integer.parseInt(sc.nextLine());
         counter[a - 1] ++;
         if(counter[a - 1] > max){
            max = counter[a - 1];
         }
      }
      
      for(int i = 0; i < SIZE; i ++){
         if(counter[i] == max){
            System.out.println(i+1);
         }
      }
   }//main
}//class


Measured memory_bytes: 26020
import java.util.Scanner;

public class Main {

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

		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long k = sc.nextInt();
		long res = 0;

		if(k <= a) {
			res = k;
		} else if (k <= a + b) {
			res = a;
		} else {
			res = a - (k - (a + b));
		}

		System.out.printf("%d", res);
	}
}


Measured memory_bytes: 35752
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int n,m;
	cin >>n;
	vector<pair<int,int> > a(n);
	for(int i=0;i<n;i++){
		cin >>m;
		a[i] = make_pair(m,i);
	}
	sort(a.begin(),a.end());
	int ans=0;
	for(int j=0;j<n;j=j+2){
		if(a[j].second%2){
			ans+=1;
		}
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

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

int count(char *S, int *odd_black, int *even_black)
{
    int len = 0;
    *odd_black = 0;
    *even_black = 0;
    while(S[len] != '\0'){
        if(S[len] == '0'){
            if(len%2 == 1) (*odd_black)++;
            else (*even_black)++; 
        }
        len++;
    }
    return len;
}

int main()
{
    const int max_len = 100000+1;
    char S[max_len];
    scanf("%s", S);
    int odd_black, even_black;
    int len = count(S, &odd_black, &even_black);
    int odd_white = len/2 - odd_black;
    int even_white = (len+1)/2 - even_black;
    int m = min(odd_white+even_black, odd_black+even_white);
    printf("%d\n", m);
    //printf("%d %d %d %d %d\n", len, odd_black, even_black, odd_white, even_white);
    return 0;
}


Measured memory_bytes: 256
def main():
    M, D = map(int, input().split())
    ans = 0
    for m in range(1, M+1):
        for d in range(1, D+1):
            d1 = d % 10
            d10 = d // 10
            if d1 >= 2 and d10 >= 2 and d1 * d10 == m:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define mkp make_pair
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
int arr[mxn];
int n, m, k, q;
string s, t;

void solve() {
    string pon = "0168";
    cin >> s;
    char ch = s.back();
    if (pon.find(ch) != string::npos) {
        cout << "pon" << endl;
    } else if(ch == '3') {
        cout << "bon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3588
def sosu(x):
    for i in range(2, int(x**0.5)+1):
        if x % i == 0:
            return False
    else:
        return True


def main():
    x = int(input())
    i = 0
    while True:
        ans = sosu(x)
        if ans == True:
            print(x)
            return
        x += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def c():
    from collections import deque
    n = int(input())
    A = [int(ai) for ai in input().split()]
    A = deque(sorted(A, reverse=True))
    xy = []
    for i in range(1, n):
        # print(A)
        if A[0] == A[1]:
            tmp = A.popleft(); A.popleft()
            xy.append(tmp)
        else:
            A.popleft()

        if len(xy) == 2:
            print(xy[0] * xy[1])
            break
    if len(xy) < 2:
        print(0)

c()

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

int main(){
    int n,j=0;
    int k=0;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%2==0){
            int b[j] ;
            b[j] = a[i];
            j++;
            if((a[i]%3)==0 || (a[i])%5==0){
                k++;
            }else{}
        }
    }
        if(j==k){
            cout << "APPROVED";
        }
        else{
            cout << "DENIED";
        }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
  long a, b, k;
  std::cin >> a >> b >> k;
  if(a+b < k){
    a = 0; b = 0;
  }
  else if(a < k){
     b -= k-a; a = 0;
  }
  else
    a -= k;
  std::cout << a << " " << b << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



// define eps
double EPS = 1e-10;

struct Point2D { 
	double x, y;
	Point2D (double a=0, double b=0) : x(a), y(b) {}
};
typedef Point2D Vector2D;

// Point2D's and Vector2D's operator
Point2D operator + (Point2D a, Point2D b) { return Point2D(a.x + b.x, a.y + b.y); }
Point2D operator - (Point2D a, Point2D b) { return Point2D(a.x - b.x, a.y - b.y); }
Point2D operator * (Point2D a, double d) { return Point2D(a.x * d, a.y * d); }
Point2D operator / (Point2D a, double d) { return Point2D(a.x / d, a.y / d); }

bool operator < (const Point2D& a, const Point2D& b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
bool operator > (const Point2D& a, const Point2D& b) { return b.x != a.x ? b.x < a.x : b.y < a.y; }
bool operator == (const Point2D& a, const Point2D& b) { return fabs(a.x-b.x)<EPS && fabs(a.y-b.y)<EPS; }

double norm(Point2D a) { return a.x*a.x + a.y*a.y; }
double dot2D(const Vector2D& a, const Vector2D& b) { return a.x * b.x + a.y * b.y; }
double cross2D(const Vector2D& a, const Vector2D& b) { return a.x*b.y - a.y*b.x; }

// 点の進行方向	a -> b -> c
int ccw(Point2D a, Point2D b, Point2D c) {
	b = b - a; c = c - a;
	if (cross2D(b, c) > 0) return +1;	// counter clockwise
	if (cross2D(b, c) < 0) return -1;	// clockwise
	if (dot2D(b, c) < 0) return +2;		// c--a--b on line
	if (norm(b) < norm(c)) return -2;	// a--b--c on line
	return 0;	// 
}

vector<Point2D> convexHull(vector<Point2D> ps) {
	int n = (int)ps.size(), k = 0;
	sort(ps.begin(), ps.end());
	vector<Point2D> ch(2*n);	
	for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
		while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
	for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])	// upper-hull
		while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
	ch.resize(k-1);
	return ch;
}


int main() {
	int n;
	
	while (cin>>n) {
		if (n==0) break;
	
		vector<Point2D> ps(n);
	
		for_(i, 0, n) {
			D x, y;
			scanf("%lf,%lf", &x, &y);
			ps[i].x = x; ps[i].y = y;
		}
	
		vector<Point2D> ch = convexHull(ps);
		int k = (int)ch.sz;
	
		cout << n - k << endl;
	}
	
	return 0;
}

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

int main(void) {
    string s, t, u;
    int a, b;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (s == u) {
        --a;
    } else {
        --b;
    }

    cout << a << " " << b << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Integer[] d = new Integer[N];
        int count = 0;

        for (int i = 0; i < N; i++) {
            d[i] = Integer.parseInt(sc.next());
        }

        Arrays.sort(d, Collections.reverseOrder());

        for (int i = 0; i < N; i++) {
            if (i < N - 1) {
                if (d[i] > d[i + 1]) {
                    count++;
                }
            }

            if (i == N - 1) {
                count++;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(count);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 35816
fn main() {
    proconio::input! {
        n: usize,
        s: String,
    }
    let cnt = |c| { s.chars().filter(|&x|{ x == c }).count() };
    let (r,g,b) = (cnt('R'),cnt('G'),cnt('B'));
    let dup = {
        let s = s.as_bytes();
        let mut count = 0;
        for i in 0..n {
            for j in i+1..n {
                let k = 2*j - i;
                if k >= n { continue; }
                if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] { count += 1; }
            }
        }
        count
    };
    println!("{}", r*g*b - dup);
}

Measured memory_bytes: 2160
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
C = [list(map(int, input().split())) for _ in range(M)]


for a in A:
    distance = 10**9
    point = 0
    for i, c in enumerate(C):
        if abs(a[0] - c[0]) + abs(a[1] - c[1]) < distance:
            distance = abs(a[0] - c[0]) + abs(a[1] - c[1])
            point = i
    print(point + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<vector>
#define maxx 1000000
#define ll long long
#define boostUP ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n) for(ll i=0;i<n;i++)
#define fcr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(arr) sizeof(arr)/sizeof(arr[0])

using namespace std;

int main(){
	int n; cin >> n;
	
	if( n <= 1000)
		n = 1000 - n;
	else{
		int rem = n  % 1000;
		if(rem == 0)
			n = 0;
		else if(rem <= 1000)
			n = 1000 - rem;
	}
	cout << n << endl;
}



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

#define MOD 1000000007;

int dp[1001][1001];


int solve(vector<vector<char>>&v,int x1,int y1,int x2,int y2)
{
    if(dp[x1][y1]!=-1)
        return dp[x1][y1];
    if(x1==x2&&y1+1==y2)
        return dp[x1][y1]=1;
    if(y1==y2&&x1+1==x2)
        return dp[x1][y1]=1;

    int op1=0,op2=0;
    if(y1+1<=y2&&v[x1][y1+1]!='#')
    {
        op1=solve(v,x1,y1+1,x2,y2)%MOD;
        dp[x1][y1+1]=op1%MOD;
    }
    if(x1+1<=x2&&v[x1+1][y1]!='#')
    {
        op2=solve(v,x1+1,y1,x2,y2)%MOD;
        dp[x1+1][y1]=op2%MOD;
    }
    
    return dp[x1][y1]=(op1+op2)%MOD;
}

int main()
{
    int r,c;
    cin>>r>>c;
    vector<vector<char>> v;
    memset(dp,-1,sizeof dp);
    for(int i=0; i<r; i++)
    {
        vector<char> vi(c);
        for(int j=0; j<c; j++)
            cin>>vi[j];
        v.push_back(vi);
    }
    cout<<solve(v,0,0,r-1,c-1);
    return 0;
}

Measured memory_bytes: 8640
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for a in range(K + 1):  # a回まで行う
    for i in range(a + 1):
        get = a - i
        rel = i
        if rel >= get:
            continue
        for j in range(get + 1):  # 右からj個とる
            point = 0
            right = j
            left = get - right
            if right + left > N:
                continue
            l = V[:left]
            r = V[N - right:]
            al = r + l
            al.sort()
            point = sum(al[rel:])
            ans = max(ans, point)
print(ans)


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

struct subset{
    int par,rank;
};

int find(subset subsets[],int i){
    if(subsets[i].par!=i){
        subsets[i].par=find(subsets,subsets[i].par);
    }
    return subsets[i].par;
}

void Union(subset subsets[],int x,int y){
    int xroot=find(subsets,x);
    int yroot=find(subsets,y);
    if(subsets[xroot].rank>subsets[yroot].rank){
        subsets[yroot].par=xroot;
    }else if(subsets[yroot].rank>subsets[xroot].rank){
        subsets[xroot].par=yroot;
    }else{
        subsets[xroot].par=yroot;
        subsets[yroot].rank++;
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    subset subsets[n];
    for(int i=0;i<n;i++){
        subsets[i].par=i;
        subsets[i].rank=0;
    }
    while(m--){
        int a,b;
        cin>>a>>b;
        a--,b--;
        int xroot=find(subsets,a);
        int yroot=find(subsets,b);
        if(xroot!=yroot){
            Union(subsets,xroot,yroot);
        }
    }
    int ans=0;
    set<int>sub;
    map<int,int>mp;
    for(int i=0;i<n;i++){
        int xroot=find(subsets,i);
        mp[xroot]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ans=max(ans,it->second);
    }
    cout<<ans<<endl;

}

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

struct SegmentTree{
    int leaves;
    vector<long long int> data;

    void init(int n){
        leaves = 1;
        while(leaves < n) leaves *= 2;// nearest power of 2 (leaf nodes)
        data.assign(2 * leaves, 0);// (0,) 1, ..., 2 * leaves - 1
    }

    // update i-th leaf (0-indexed) to x
    void update(int i, long long int x){
        i += leaves;
        data[i] = x;
        while(i >= 2){
            i /= 2;// move upward (to the parent node)
            data[i] = max(data[i*2], data[i*2 + 1]);// compare the children
        }
    }

    // maximum [a,b)
    long long int query(int a, int b, int k, int l, int r){// k-th node of the tree = [l,r)
        if(b <= l || r <= a) return 0;// no overlap
        if(a <= l && r <= b) return data[k];// completely inside
        // otherwise: recursive
        long long int vl = query(a, b, k*2    , l      , (l+r)/2);// left  child
        long long int vr = query(a, b, k*2 + 1, (l+r)/2, r      );// right child
        return max(vl, vr);
    }
};

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

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

    SegmentTree seg; 
    seg.init(n+1);

    for(int i=0; i<n; i++){
        seg.update(h[i], a[i] + seg.query(0, h[i], 1, 0, seg.leaves));
    }

    cout << seg.query(0, n+1, 1, 0, seg.leaves) << endl;
    return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    if (S[0] == S[1] and S[0] != S[2] and S[2] == S[3]){
        cout << "Yes" << endl;
    }
    else if (S[0] == S[2] and S[0] != S[1] and S[1] == S[3]){
        cout << "Yes" << endl;
    }
    else if (S[0] == S[3] and S[0] != S[1] and S[1] == S[2]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

#define sd(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define N 60
#define INF 100000000000000000ll
ll a[N];

int main()
{
	int n=50,i,j;
	ll k;
	sl(k);

	for(i=0;i<n;i++)
		a[i]=n-1+k/n;
	k%=n;
	while(k--)
	{
		ll minn=INF;
		int mini;
		for(i=0;i<n;i++)
			if(a[i]<minn)
			{
				minn=a[i];
				mini=i;
			}
		a[mini]+=n;
		for(i=0;i<n;i++)
			if(i!=mini)
				a[i]--;
	}
	printf("%d\n",n);
	for(i=0;i<n;i++)
		printf("%lld ",a[i]);
	printf("\n");
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	n-=k;
	if(k == 1){printf("0\n");}
	else{printf("%d\n",n);}
	return 0;
};

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,n,i,j;
	char a[105][105];
	for(i=0;i<105;i++)
	for(j=0;j<105;j++)a[i][j]='.';
	cin>>m>>n;
	for(i=1;i<=m;i++)
	for(j=1;j<=n;j++)cin>>a[i][j];
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(a[i][j]=='#')
			{
				cout<<"#";
				continue;
			}
			register int tmp=0;
			if(a[i-1][j-1]=='#')tmp++;
			if(a[i-1][j]=='#')tmp++;
			if(a[i-1][j+1]=='#')tmp++;
			if(a[i][j-1]=='#')tmp++;
			if(a[i][j+1]=='#')tmp++;
			if(a[i+1][j-1]=='#')tmp++;
			if(a[i+1][j]=='#')tmp++;
			if(a[i+1][j+1]=='#')tmp++;
			cout<<tmp;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, raw_input().split(' '))
d = {}

for i in range(m):
	a, b = map(int, raw_input().split(' '))
	if d.has_key(a):
		d[a] += 1
	else:
		d[a] = 1
	if d.has_key(b):
		d[b] += 1
	else:
		d[b] = 1

for i in range(1, n + 1):
	if d.has_key(i):
		print d[i]
	else:
		print 0

Measured memory_bytes: 2568
#include<iostream>
using namespace std;
int main(){
    int n;
    int ans;
    cin>>n;
    if(n<105)
	ans=0;
    else if(n<135)
	ans=1;
    else if(n<165)
	ans=2;
    else if(n<189)
	ans=3;
    else if(n<195)
	ans=4;
    else
	ans=5;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>

main(){
    int n;
    long long a[200000];
    int i,j;
    int l,r;
    long long   xor;
    long long   sum;
    long long kosu=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);

    r=0;
    for(l=0;l<n;l++){
        if(!l)
            sum=xor=0;
        else{
            sum-=a[l-1]+a[r];
            xor=sum;
        }
        for(;r<n;r++){
            sum+=a[r];
            xor^=a[r];
            if(sum!=xor){
                break;
            }
        }
        kosu+=r-l;

    }
    printf("%lld\n",kosu);
    return 0;
}

Measured memory_bytes: 1792
H,W=map(int,input().split())
h,w=map(int,input().split())

HW=[]

for i in range(H):
  sublist=[]
  for j in range(W):
    sublist.append(0)
  HW.append(sublist)


# 行
for i in range(h):
  for j in range(W):
    HW[i][j]=1


# 列
for i in range(w):
  for j in range(H):
    if HW[j][i]==1: continue
    HW[j][i]=1

cnt=0

for i in range(H):
  for j in range(W):
    if HW[i][j]==0:
      cnt+=1

print(cnt)

Measured memory_bytes: 9224