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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N;
    cin >> N;

    map<int, int> vals;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        vals[a]++;
    }

    int ans = 0;
    while (vals.size()) {
        int big = vals.rbegin()->first;
        int ct = vals.rbegin()->second;
        vals.erase(big);

        int match = 1 << (32 - __builtin_clz(big));
        match -= big;

        if (match == big) {
            ans += ct / 2;
        } else {
            if (ct < vals[match]) {
                ans += ct;
                vals[match] -= ct;
            } else {
                ans += vals[match];
                vals.erase(match);
            }
        }
    }
    cout << ans << endl;

    return 0;
}



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

using namespace std;

int main()
{
//    freopen("int.txt","r",stdin);

    int a,c,b;
    while(cin>>a>>b)
    {
        cout<<a/b<<" "<<a%b;
        double s;
        s=(double)a/b;
        printf(" %.5lf\n",s);
    }
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {

    int n;
    cin >> n;

    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;

    return 0;

}


Measured memory_bytes: 3644
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;

using namespace std ;

double coins( double probability[] , int N ){
    double dp[N+1][N+1] ;
    memset( dp, 0, sizeof(dp) ) ;
    dp[0][0] = 1 ;
    for( int i = 1 ; i <= N ; i++ )
        dp[i][0] = dp[i-1][0] * ( 1 - probability[i-1] ) ;
    for( int i = 1 ; i <= N ; i++ ){
        for( int j = 1 ; j <= N ; j++ ){
            dp[j][i] = probability[j-1] * dp[j-1][i-1] + ( 1 - probability[j-1] ) * dp[j-1][i] ;
        }
    }
    double ans = 0 ;
    for( int i = N / 2 + 1 ; i <= N ; i++ ){
        ans += dp[N][i] ;
    }
    return ans ;
}
    
int main(){
    FAST();
    int N ; cin >> N ;
    double arr[N] ;
    for( int i = 0 ; i < N ; i++ )
        cin >> arr[i] ;
    cout << fixed <<setprecision(10) << coins(arr , N ) << endl ;
    return 0 ;
}





Measured memory_bytes: 70656
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1e5+4;
int n,m;
int tot;
struct Node {
	int a,b;
	friend bool operator <(const Node &x,const Node &y) {
		return x.b<y.b;
	}
}p[N];
bool cmp(Node c,Node d) {
	return c.a<d.a;
}
priority_queue<Node> q;
inline int read() {
	int x=0;char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}
int main() {
	n=read(),m=read();
	for (register int i=1;i<=n;++i) {
		int a=read(),b=read();
		if (a<=m) p[++tot].a=a,p[tot].b=b;
	}
	sort(p+1,p+tot+1,cmp);
	int cur=0,sum=0;
	for (register int i=1;i<=m;++i) {
		while (p[cur+1].a<=i&&cur<tot) {
			++cur;
			q.push(p[cur]);
		}
		if (!q.empty()) {
			sum+=q.top().b;
			q.pop();
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 2168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        if (n > 999){
            System.out.println("ABD");
        }else{
            System.out.println("ABC");
        }
    }
}


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

int main() {
  int N;
  scanf("%d", &N);
  int v = N % 10;
  if (v == 2 || v == 4 || v == 5 || v == 7 || v == 9)
    printf("hon\n");
  else if (v == 3)
    printf("bon\n");
  else printf("pon\n");
}


Measured memory_bytes: 3768
open System
open System.Collections.Generic
open System.Linq
open System

let Puts = Console.WriteLine : 'a -> unit
let Reads () = Console.ReadLine().Split()
let ReadDouble () = Reads() |> (fun x -> x.[0], x.[1])
let ReadTriple () = Reads() |> (fun x -> x.[0], x.[1], x.[2])
let ReadQuadruple () = Reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])

let FuncDouble f1 f2 (t1, t2) = (f1 t1, f2 t2)
let FuncTriple f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let FuncQuadruple f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)

let ReadIntTriple () = ReadTriple () |> FuncTriple int int int
let ReadIntDouble () = ReadDouble () |> FuncDouble int int

let ensmallen l = l % 1000000007L

let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)


let sayYESNO b = if b then Puts "YES" else Puts "NO"

// main code

let a, b, c = ReadIntTriple()

[1..100] |> Seq.map (fun i -> i * a % b) |> Seq.exists (fun i -> i = c) |> sayYESNO


Measured memory_bytes: 13396
def solve():
    N = int(input())
    t = [0] * (N+1)
    x = [0] * (N+1)
    y = [0] * (N+1)
    t[0] = 0
    x[0] = 0
    y[0] = 0
    for i in range(1, N+1):
        t[i], x[i], y[i] = map(int, input().split())

    for i in range(1,N+1):
        # 空間的に可能かどうか。奇数秒後はx+yが奇数に、偶数秒後はx+yが偶数にならないといけない。
        if (t[i]%2==0 and (x[i]+y[i])%2==1) or (t[i]%2==1 and (x[i]+y[i])%2==0):
            print('No')
            exit()
        #　時間的に可能かどうか。
        if (t[i] - t[i-1]) < abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]):
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 11636
import java.util.*;

class PL implements Comparable<PL>{
    long x,y;
    PL(long x,long y){
        this.x=x;this.y=y;
    }
    @Override
    public int compareTo(PL o){
        return Long.compare(x,o.x);
    }
    @Override
    public String toString(){
        return "("+x+","+y+")";
    }
}

class Main {
    Main(int n,long[]k){
        int m=k.length;
        Queue<PL> q=new PriorityQueue<PL>(Collections.reverseOrder());
        long f=k[0];
        long[]a=new long[n];
        long c=1;
        for(int i=m-2;i>=0;--i){
            long nc=0;
            while(q.size()>0&&q.peek().x>k[i]){
                PL t=q.poll();
                long x=t.x,y=t.y;
                long qq=x/k[i],r=x%k[i];
                nc+=y*qq;
                if(r>f)
                    q.add(new PL(r,y));
                else if(r>=1)
                    a[(int)(r-1)]+=y;
            }
            long qq=k[i+1]/k[i],r=k[i+1]%k[i];
            nc+=c*qq;
            if(r>f)
                q.add(new PL(r,c));
            else if(r>=1)
                a[(int)(r-1)]+=c;
            c=nc;
        }
        a[(int)(f-1)]+=c;
        while(q.size()>0){
            PL t=q.poll();
            long x=t.x,y=t.y;
            if(x>=1)
                a[(int)(x-1)]+=y;
        }
        for(int i=n-2;i>=0;--i)a[i]+=a[i+1];
        for(long aa:a)System.out.println(aa);
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=Integer.parseInt(scan.next());
        int q=Integer.parseInt(scan.next());
        int p=1;
        long[] k=new long[q+1];
        k[0]=n;
        for(int i=0;i<q;++i){
            long u=Long.parseLong(scan.next());
            while(p>0&&k[p-1]>=u)p--;
            k[p++]=u;
        }
        new Main(n,Arrays.copyOf(k,p));
    }
}


Measured memory_bytes: 65612
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


ll cnt[31][100005];
map<ll,vector<pair<ll,ll> > > ch;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N , C; cin >> N >> C;


    rep(i,N){
        ll s,t,c; cin >> s >> t >> c;
        ch[c].pb(mp(s,t));
    }
    rep(i,31) ch[i].pb(mp(-1,-1));
    
    rep(i,31){
        rep(j,ch[i].size()-1){
            ll s = ch[i][j].first;
            ll t = ch[i][j].second;
            cnt[i][s]++;
            cnt[i][t+1]--;
        }
        ll now = 0;
        rep(j,100005){
            now += cnt[i][j];
            cnt[i][j] = min((ll)1,now);
        }
    }
    ll ans = 0;
    rep(i,100005){
        ll ret = 0;
        rep(j,31){
            ret += cnt[j][i];
        }
        ans = max(ans,ret);
    }
    
    cout << ans << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 26880
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,=pin()
    ans=[]
    t=0
    
    max_digit=len("1000000000000001")
    ans=[]
    for i in range(max_digit):
        a=(N-1)%26+1
        if a==0:break
        ans.append(a)
        if a==N :
            break
        N=(N-a)//26

    ans.reverse()
#    print(ans)
    A=""
    for a in ans:
        A+=chr(ord("a")-1+a) 
    print(A)   
#%%submit!
resolve()


Measured memory_bytes: 80328
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;



int main()
{
    idfc;
    ll a;
    cin>>a;
    char w,x,y,z;
    cin>>w>>x>>y>>z;
    int ww,xx,zz;
    ww=w-48;
    xx=y-48;
    zz=z-48;
    ll b=(ww*100)+(xx*10)+zz;

    ll ans=a*b;
    ans/=100;
    cout<<ans;

    return 0;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    string s;
    cin >> s;

    ll m = 1e15;
    for(ll i=0; i<sz(s)-2; i++)
    {
        ll cur = 100*((ll)(s[i]-48));
        cur+=10*((ll)(s[i+1]-48));
        cur+=((ll)(s[i+2]-48));
        
        m = min(m, abs(753-cur));
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>    
    
int main(void) {    
    int k;    
    int s;    
    scanf("%d", &k);    
    scanf("%d", &s);    
    int ans = 0;    
    for(int x = 0; x <= k; x++) {    
        for(int y = 0; y <= k; y++) {       
            int z = s-x-y;   
            if(z <= k && z >= 0)
                ans++;
        }                                   
    }    
    printf("%d", ans);    
}    

Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        boolean flag = false;
        for(int i=0; i<N; i++){
            String s = sc.next();
            
            if(s.equals("Y")){
                flag = true;
                break;
            }
        }
        
        if(flag){
            System.out.println("Four");
        }else{
            System.out.println("Three");
        }
    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());

        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(scanner.next());
        }

        scanner.close();

        int ans = Integer.MAX_VALUE;
        for (int i = -100; i <= 100; i++) {
            int cost = 0;
            for (int x : A) {
                cost += (x - i) * (x - i);
            }
            ans = Math.min(ans, cost);
        }
        System.out.println(ans);
    }
}


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

int main() {
	int K, S;
	cin >> K >> S;

	long long ans = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			int z = S - x - y;
			if (z >= 0 && z <= K) ans++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int a, b; cin >> a >> b;
  if(a + b == 15) cout << "+" << endl;
  else if(a * b == 15) cout << "*" << endl;
  else cout << "x" << endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        long aa = a;
        long bb = b;
        int[][] c =  new int [2][45];
        int index = 0;
        while (index <= 44) {
            c[0][index] = (int) (a % 2);
            c[1][index] = (int) (b % 2);
            a /= 2;
            b /= 2;
            index++;
        }
        //奇数の数
        int d[] = new int[45];

        if (c[0][0] == 0 && c[1][0] == 0) {
            if ((bb - aa) % 4 == 0) {
                d[0] = 0;
            } else {
                d[0] = 1;
            }
        } else if (c[0][0] == 1 && c[1][0] == 1) {
            if ((bb - aa) % 4 == 0) {
                d[0] = 1;
            } else {
                d[0] = 0;
            }
        } else {
            if ((bb - aa) % 4 == 1) {
                d[0] = 1;
            } else {
                d[0] = 0;
            }
        }

        for (int i = 1 ; i < 45 ; i++) {
            int abit = c[0][i];
            int bbit = c[1][i];
            if (abit == 0 && bbit == 0) {
                d[i] = 0;
            } else if (abit == 1 && bbit == 1) {
                if (c[0][0] == c[1][0]) {
                    d[i] = 1;
                } else {
                    d[i] = 0;
                }
            } else if (abit == 1 && bbit == 0){
                if (c[0][0] == 0) {
                    d[i] = 0;
                } else {
                    d[i] = 1;
                }
            } else {
                if (c[1][0] == 0) {
                    d[i] = 1;
                } else {
                    d[i] = 0;
                }
            }

        }
        long ans = 0;
        long e = 1;
        for (int i = 0 ; i < 45 ; i++) {
            ans += e * d[i];
            e *= 2;
        }


        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    double ret = 0;
    for (int i = 0; i < n; ++i) {
        ret += 1.0 / a[i];
    }
    cout << fixed << setprecision(10) << 1.0 / ret << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] count = new int[26];
        String x=null;
        String str = "abcdefghijklmnopqrstuvwxyz";
        String[] str2 = str.split("");
        	while(sc.hasNext()){
            	x = sc.nextLine();
            	x = x.toLowerCase();
        		String[] c = x.split("");
        		
        		for(int i=0;i<c.length;i++){
            		for(int j=0;j<str2.length;j++){
                    	if(str2[j].equals(c[i])){
                    		count[j]++;
                		}
           			}
        		}
        	}    
        for(int i=0;i<str2.length;i++){
                System.out.println(str2[i]+" : "+count[i]);
        }
    }
}


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

struct union_find {
    vector<int> parent;

    union_find(int n) {
        parent = vector<int>(n,-1);
    }

    int root(int a) {
        if (parent[a] < 0) return a;
        return parent[a] = root(parent[a]);
    }

    int size(int a) {
        return -parent[root(a)];
    }

    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return false;
        if (size(a) < size(b)) swap(a,b);
        parent[a] += parent[b];
        parent[b] = a;
        return true;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    vector<ll> ans(m);
    ans[m-1] = (ll)n * (n-1) / 2;
    union_find uni(n);
    for (int i = m-1; i >= 1; i--) {
        ans[i-1] = ans[i];
        if (uni.root(a[i]) != uni.root(b[i])) {
            ans [i-1] -= (ll)uni.size(a[i]) * uni.size(b[i]);
            uni.connect(a[i],b[i]);
        }
    }
    rep(i,m) cout << ans[i] << endl;
}

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

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

  sort(a, a + N);
  string ans;
  // 種類数が2以上離れていたら矛盾する
  if (a[N-1] - a[0] >= 2) {
    ans = "No";
  } else {
    if (a[N-1] - a[0] == 0) {
      if (a[0] == N - 1 || 2 * a[0] <= N) {
        ans = "Yes";
      } else {
        ans = "No";
      }
    } else {
      int x = 0, y;
      for (int i = 0; i < N; i++) {
        if (a[i] == a[N-1] - 1) x++;
      }
      y = N - x;
      if (x < a[N-1] && 2 * (a[N-1] - x) <= y) {
        ans = "Yes";
      } else {
        ans = "No";
      }
    }
  }

  // 解答
  cout << ans << endl;
  return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

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

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// 最小閉路探索
// （１）ある始点と仮定して、DFSをして経路長さを求める
// （２）始点に向かう辺の中で、閉路が最も小さくなるものを探す
// （３）現時点で見つかっている最小経路よりも小さくなるなら更新
int main() {
    int N, M;
    cin >> N >> M;
    
    vector<int> G[1005];
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
    }
 
    // 最小閉路の探索
    vector<int> res(N + 1, -1);
    REP(s, N) {
        vector<int> dist(N, -1);
        vector<int> prev(N, -1);
        queue<int> que;
        que.push(s);
        dist[s] = 0;
        while (!que.empty()) {
            auto v = que.front(); que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[v] + 1;
                    prev[nv] = v;
                    que.push(nv);
                }
            }
        }

        // 始点に向かう最短経辺
        pair<int, int> best(N + 1, -1);
        REP(t, N) {
            if (t == s || dist[t] == -1) continue;
            for (auto nt : G[t]) {
                if (nt == s) best = min(best, make_pair(dist[t] + 1, t));
            }
        }

        if(best.first == N + 1) continue;

        vector<int> tmp({s});
        int cur = best.second;
        while (cur != s) {
            tmp.push_back(cur);
            cur = prev[cur];
        }
        if (res.size() > tmp.size()) res = tmp;
    }
 
    if (res.size() == N + 1) cout << -1 << endl;
    else {
        cout << res.size() << endl;
        for (auto v : res) cout << v + 1 << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

bool check(vector<int> ret)
{
	bool flag = true;
	REP(i,1,ret.size()+1)
	{
		if(i != ret[i-1]) 
		{
			flag = false;
			break;
		}
	}
	return flag;
}

int main()
{
	map<int,int> m;

	int t = 1;
	while(true)
	{
		if((t*(t+1))/2 > 100*10000) break;
		else
		{
			m[(t*(t+1))/2]++;
			t++;
		}
	}


	int n;
	while(cin >> n && n)
	{
		int ret = 0;
		vector<int> v;
		v.resize(n);

		rep(i,n)
		{
			cin >> v[i];
			ret += v[i];
		}

		if(m[ret] != 1) cout << -1 << endl;
		else
		{
			bool flag = true;

			rep(i,10000)
			{
				if(check(v)) 
				{
					cout << i << endl;
					flag = false;
					break;
				}

				rep(i,v.size()) v[i] -= 1;
				v.push_back((int)v.size());
				v.erase(remove(v.begin(),v.end(),0),v.end());
			}

			if(flag) cout << -1 << endl;
		}
	}
}

Measured memory_bytes: 1288
program string_rotation
  implicit none
  character(200) :: s, t
  integer :: n, i
  read(*,*) s
  read(*,*) t
  n = len_trim(s)
  s(n+1:2*n) = s(1:n)
  do i = 1, n
    if (s(i:i+n-1) == t(1:n)) then
      write(*,'(a)') "Yes"
      stop
    end if
  end do
  write(*,'(a)') "No"
end program string_rotation

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N+1);
	vector<int> B(N+1);
	vector<int> C(N);
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
	}
	for (int i = 1; i <= N; i++)
	{
		cin >> B[i];
	}
	for (int i = 1; i <= N-1; i++)
	{
		cin >> C[i];
	}
	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		ans += B[A[i]];
		if (i != N  && (A[i+1]==A[i]+1))
		{
			ans += C[A[i]];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(a,b):
    # implement process
    s = str(min(a,b))
    n = max(a,b)
    return s * n

def main():
    # input
    a,b = map(int, input().split())
    
    # process
    ans = str( solve(a,b) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
7 7
"""
_EXPECTED = """\
7777777
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9152
#include<iostream>
#define PI 3.141592653589
using namespace std;
 
int main(){
    int n;
    cin >>n;
    int a[100];
    for ( int i = 0; i < n; i++ ){
        cin>>a[i];
    }
 
     
    for ( int i = 0; i < n; i++ ){
        if (i!=0){cout << " ";}
        cout << a[n-i-1];
    }
    cout << endl;
     
    return 0;
}

Measured memory_bytes: 3088
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    from collections import deque


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

    aa = list(map(int, input().split()))
    aa.sort(reverse=True)
    aa = deque(aa)

    if n == 1:
        a = aa.popleft()
        for _ in range(m):
            a = a // 2
        print(a)
        exit()

    top = aa.popleft()

    deque_list = [aa, deque()]
    top_list = [deque_list[0].popleft(), top//2]


    for _ in range(m-1):
        max_num = max(top_list)
        max_index = top_list.index(max_num)
        try:
            deque_list[max_index+1].append(max_num//2)
        except IndexError:
            deque_list.append(deque())
            top_list.append(max_num//2)
        if top_list[max_index+1] == -1:
            top_list[max_index+1] = deque_list[max_index+1].popleft()
        try:
            top_list[max_index] = deque_list[max_index].popleft()
        except IndexError:
            top_list[max_index] = -1

    ans = 0
    for num in top_list:
        ans += max(0, num)
    for one_deque in deque_list:
        ans += sum(one_deque)
    print(ans)


Measured memory_bytes: 14636
using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int sunuke = int.Parse(inp[0]);
        int sweets = int.Parse(inp[1]);
        bool[] sunukes = new bool[sunuke];
        for (int idx = 0; idx < sweets; idx++)
        {
            var inp2 = Console.ReadLine().Split(' ');
            var inp3 = Console.ReadLine().Split(' ');

            for(int idx2 = 0; idx2 < int.Parse(inp2[0]); idx2++)
            {
                sunukes[int.Parse(inp3[idx2]) -1] = true;
            }
        }

        int count = 0;
        for(int idx = 0; idx < sunukes.Length; idx++)
        {
            if (!sunukes[idx]) count++;
        }

        Console.WriteLine(count.ToString());
    }
}

Measured memory_bytes: 27600
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int to_n(char c);

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

	int to_num;
	int min = 1000000;
	for (int i = 0; i < s.length() - 2; i++) {
		to_num = to_n(s[i]) * 100 + to_n(s[i + 1]) * 10 + to_n(s[i + 2]);
		if (abs(to_num - 753) < min) {
			min = abs(to_num - 753);
		}
	}
	cout << min << endl;

	return 0;
}

int to_n(char c)
{
	return c - '0';
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<llP> vec(n);
  rep(i, n) {
    ll x, l;
    cin >> x >> l;
    vec[i] = make_pair(x-l, x+l);
  }

  auto comp = [&](llP a, llP b) {
    return a.second < b.second;
  };
  sort(ALL(vec), comp);

  ll d = -INF64;

  int ans = 0;
  rep(i, n) {
    if(vec[i].first < d) continue;
    d = vec[i].second;
    ++ans;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4840
import java.util.Scanner;

class Main {
	// ???????????????????????§???????????????????????°????????????????????°
	private static int count;
	//????????????????´?????????§???+1????????????????????°
	private static int max = -1;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		//??\????????????????????????????´????????????????????´?????????°???????????????????????????????????§???+ 1????±???????
		int n = scanner.nextInt();
		int[] numList = new int[n];
		for (int i = 0; i < n; i++) {
			numList[i] = scanner.nextInt();
			if (max < numList[i]) {
				max = numList[i] + 1;
			}
		}
		scanner.close();
		// ?????????????????????????????? ?????°???????±???????(numList)????????????????°????????´???????(0)?????????????????§???????´???????(n)?????????
		mergeSort(numList, 0, n);
		System.out.print(numList[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + numList[i]);
		}
		System.out.println();
		System.out.println(count);
	}

	// ???????????????(mid)???????????????L??¨R????????????????´?????????? L??¨R????????????????´???°???????????¨?????????
	// L??¨R??????????´?????????????????°????????????????numList???????´???????????????£??????????´?+1?????§????????§??????????????????????????????????´?????????§???
	// +1(max)????????????????????????????´?????????????
	static void merge(int[] numList, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];

		for (int i = 0; i < n1; i++) {
			L[i] = numList[left + i];
		}

		for (int i = 0; i < n2; i++) {
			R[i] = numList[mid + i];
		}

		L[n1] = max;
		R[n2] = max;
		int i = 0;
		int j = 0;
		// L??¨R??????????????????????°????????????????numList???????´??????????
		// ?°?????????????????????????????????????????¬??????????????????????????????????????´????????????????????????°?????????+1?????????
		for (int k = left; k < right; k++) {
			count++;
			if (L[i] <= R[j]) {
				numList[k] = L[i];
				i = i + 1;
			} else {
				numList[k] = R[j];
				j = j + 1;
			}
		}
	}

	// ????¨????merge???????????????????±??????????????°?????´???????(left)??¨?????§????´???????(right)?????????-1??????????????§??°????????????
	static void mergeSort(int[] numList, int left, int right) {
		if ((left + 1) < right) {
			int mid = (left + right) / 2;

			mergeSort(numList, left, mid);
			// System.out.println("???");
			mergeSort(numList, mid, right);
			// System.out.println("???");
			merge(numList, left, mid, right);
		}
	}
}

Measured memory_bytes: 169840
s = input()
t = input()

slist = []
tlist = []

for i in s:
    slist.append(i)
for i in t:
    tlist.append(i)
    
sortedslist = sorted(slist)
sortedtlist = sorted(tlist)

#print(sortedslist, sortedtlist)

sample ='abcdefghijklmnopqrstuvwxyz'

def checktoend(sa, ta):
    n = min(len(sa), len(ta))
    end = 0
    for i in range(n):
        for x in sample:
            if sa[i]==x and ta[-(i+1)]==x:
                break
            elif sa[i]==x and ta[-(i+1)]!=x:
                print('Yes')
                end = 1#end
                break
            elif sa[i]!=x and ta[-(i+1)]==x:
                print('No')
                end = 1
                break
        if end == 1:
            break
    else:
        if len(sa)<len(ta):
            print('Yes')
        else:
            print('No')

checktoend(sortedslist, sortedtlist)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

ll dp[2][402][402];

int main() {
    ll N, Ma, Mb; cin >> N >> Ma >> Mb;
    vector<ll> a(N), b(N), c(N); REP(i, N) cin >> a[i] >> b[i] >> c[i];
    
    fill((ll *)dp, (ll *)dp + 2 * 402 * 402, inf);
    dp[0][0][0] = 0;
    REP(i, N) REP(j, 401) REP(k, 401) {
        if (j >= a[i] and k >= b[i]) {
            dp[(i+1)%2][j][k] = min(dp[i%2][j][k], dp[i%2][j-a[i]][k-b[i]]+c[i]);
        } else {
            dp[(i+1)%2][j][k] = dp[i%2][j][k];
        }
    }
    
    ll ans = inf;
    FOR(j, 1, 401) FOR(k, 1, 401) if (Ma * k == Mb * j) ans = min(ans, dp[N%2][j][k]);
    cout << (ans == inf ? -1 : ans) << endl;
    
    return 0;
}

Measured memory_bytes: 2816
// https://atcoder.jp/contests/caddi2018/tasks/caddi2018_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n;
    // 全てが偶数だったら負ける
    bool ans = false;
    REP(i, n) {
        cin >> t;
        if (t % 2 != 0) {
            ans = true;
        }
    }
    if (ans) {
        cout << "first\n";
    } else {
        cout << "second\n";
    }
    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

string alice = "Alice", borys = "Borys";

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int tmp = abs(A-B)-1;
    cout << ((tmp%2) ? alice : borys) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
const int maxn=500005;
struct node
{
    int l,r,sum;
} tree[maxn*4];
struct ques
{
    int l,r,index;
}ask[maxn];
int a[maxn];
int ans[maxn];
void build(int i,int left,int right)
{
    tree[i].l=left,tree[i].r=right;
    tree[i].sum=0;
    if(left==right)
        return;
    int mid=left+right>>1;
    build(i<<1,left,mid);
    build(i<<1|1,mid+1,right);
}
map<int,int> has;
void update(int i,int pos ,int w)
{
    if(tree[i].l==pos&&tree[i].r==pos)
    {
        tree[i].sum+=w;
        return ;
    }
    int mid=(tree[i].l+tree[i].r)>>1;
    if(pos<=mid)
        update(i<<1,pos ,w);
    else
        update(i<<1|1,pos ,w);
    tree[i].sum=tree[i<<1].sum+tree[i<<1|1].sum;
}
int query(int i,int left,int right)
{
    if(tree[i].l==left&&tree[i].r==right)
    {
        return tree[i].sum;
    }
    int mid=(tree[i].l+tree[i].r)>>1;
    if(right<=mid)
        return query(i<<1,left,right);
    else if(left>mid)
        return query(i<<1|1,left,right);
    else
        return query(i<<1,left,mid)+query(i<<1|1,mid+1,right);
}
bool cmp(ques a,ques b)
{
    return a.r<b.r;
}
int main()
{
    int n;int m;
    scanf("%d",&n); scanf("%d",&m);
    build(1,1,n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    
   
    for(int i=1;i<=m;i++)
    {
        ask[i].index=i;
        scanf("%d%d",&ask[i].l,&ask[i].r);
    }
    sort(ask+1,ask+1+m,cmp);
    int cur=1;
    for(int i=1;i<=m;i++)
    {
        for(int j=cur;j<=ask[i].r;j++)
        {
            if(has.find(a[j])!=has.end())
            {
                int p=has[a[j]];
                update(1,p ,-1);
            }
            update(1,j, 1);
            has[a[j]]=j;
        }
        cur=ask[i].r+1;
        ans[ask[i].index]=query(1,ask[i].l,ask[i].r);
    }
    for(int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
} 

Measured memory_bytes: 49344
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stdio.h>
#include <numeric>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	int n;
	cin >> n;
	vector<int> mas(n);
	map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> mas[i];
		++mp[mas[i]];
	}
	if (mp.size() == 3){
		int xr = 0;
		for (auto p : mp) {
			if (p.second != n / 3) {
				xr = 1; break;
			}
			xr = xr ^ p.first;
		}
		if (xr) cout << "No\n";
		else cout << "Yes\n";
	}
	else if (mp.size() == 2) {
		bool b = true;
		for (auto p : mp) {
			if (p.second != 2 * n / 3 && (p.second != n / 3 || p.first != 0)) {
				b = false; break;
			}
		}
		if (!b) cout << "No\n";
		else cout << "Yes\n";
	}
	else if (mp.size() == 1 && mp.begin()->first == 0) {
		cout << "Yes\n";
	} else cout << "No\n";
	
	return 0;
}


Measured memory_bytes: 4224
#include<stdio.h>
#include<string.h>



void change(char *str){
  int len=strlen(str);
  int i;
  for(i=0;i<len;i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]-=32;
    }
  }
}

int main(){
  char t[10000];
  char key[10000];
  char eofstr[]={"END_OF_TEXT"};
  int ans=0;

  scanf("%s",key);
  change(key);

  while(1){
    scanf("%s",t);
    if(strcmp(t,eofstr)==0){
      break;
    }
    change(t);
    if(strcmp(t,key)==0){
      ans++;
    }
  }

  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
using namespace std;
#define M 1000000007
int main()
{
	long long a[200000], i,n, j, s=0, su=0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		s=(s+a[i])%M;
	}
	for (i = 0; i < n; i++)
	{
		s -= a[i];
		s+=M;
		s%=M;
		su += (a[i] * s)%M;
		su %= M;
	}
	cout << su;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e3 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
 
}

void solve()
{
	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000;
}	

 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3636
n,k=map(int,input().split())
INF=10**18
a=list(map(int,input().split()))
ans=INF
for i in range(2**(n-1)):
  cst=0
  cnt=0
  b=a[0]
  for j in range(n-1):
    if (i>>j) & 1:
      cst+=max(b+1-a[j+1],0)
      b=max(a[j+1],b+1)
      cnt+=1
    elif a[j+1]>b:
      cst+=a[j+1]-b
      b=a[j+1]
  if cnt==k-1:
    ans=min(ans,cst)
print(ans)

Measured memory_bytes: 74124
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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(){
  long n;
  cin >> n;
  string s;
  while(n > 0){
    long r = n % 26;
    if(r == 0) {
      s.push_back('z');
      n -=26;
    }
    else {
      s.push_back('a' + r-1);
      n -= r;
    }
    n /= 26;
  }
  reverse(all(s));
  cout << s << endl;
}

Measured memory_bytes: 3628
# -*- coding:utf-8 -*-

def solve():
    s = input()

    for i in range(len(s)):
        if s[i] == "A":
            a_i = i
            break
    
    for i in range(len(s)-1, -1, -1):
        if s[i] == "Z":
            z_i = i
            break

    print(len(s[a_i:z_i+1]))

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3512
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

int main(){
  ll n;
  cin>>n;
  vector<ll>a(n,0);
  vector<ll>b(n,0);
  vector<ll>x(n,0);
  vector<ll>xx;
  ll asum=0;
  ll bsum=0;
  ll xsum=0;
  ll xxsum=0;
  ll ans=0;
  for(int i=0;i<n;i++){
		cin>>a[i];
    asum+=a[i];
	}
  for(int i=0;i<n;i++){
		cin>>b[i];
    bsum+=b[i];
    x[i]=a[i]-b[i];
	}
  xsum=asum-bsum;
  if(asum<bsum){
    cout<<-1<<endl;
    return 0;
  }
  sort(x.begin(),x.end());
  for(int i=0;i<n;i++){
		if(x[i]<0){
      xxsum+=x[i];
      ans++;
    }
    if(x[i]>0)xx.push_back(x[i]);
	}
  reverse(xx.begin(),xx.end());
  for(int i=0;i<n&&xxsum<0;i++){
		xxsum+=xx[i];
    ans++;
	}
  cout<<ans<<endl;
}


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

int main(){
  string s;
  cin >> s;
  string A;
  long long ans = 0;
  for(int i = 0; i < (1 << (s.size() - 1)); i++){
    bitset<11> p(i);
    A = s[0];
    for(int j = 0; j < (s.size() - 1); j++){
      if(p[j]){
        ans += stoll(A);
        A = s[j + 1];
      }
      else{
        A += s[j + 1];
      }
    }
    ans += stoll(A);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool isPrime(long long n);
signed main(){
    long long n,sum=0;
    cin>>n;
    long long a[n+4];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(isPrime(a[i])){
            sum=sum+1;
        }
    }
    cout<<sum<<'\n';
    return(0);
}
bool isPrime(long long n){
    if(n==2) return(true);
    if(n<=1 || n%2==0) return(false);
    for(long long i=3;i*i<=n;i+=2){
        if(n%i==0) return(false);
    }
    return(true);
}


Measured memory_bytes: 3160
let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)

let () = Scanf.scanf "%d %d\n" @@ fun n x ->
  let xs = Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun x -> x in
  Printf.printf "%d\n" @@ Array.fold_right (fun x' -> gcd @@ abs @@ x' - x) xs 0


Measured memory_bytes: 5248
import math
import itertools
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
d=[0]*n

def distance(x1,x2,y1,y2):
    return math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))
    
total= 0;
l=0
for i in range(n):
    d[i]=i
for b in itertools.permutations(d):
    l+=1
    #print(b)
    for i in range(n-1):
        total += distance(a[b[i+1]][0],a[b[i]][0],a[b[i+1]][1],a[b[i]][1])
    #    print(a[b[i+1]],a[b[i]])
     #   print(se)
print(total/l)

Measured memory_bytes: 40812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, s.length()) {
        ++mp[s[i]];
    }
    int min_num = 1e8;
    char min_char;
    for ( auto tmp_mp : mp ) {
        if ( tmp_mp.second < min_num ) {
            min_num = tmp_mp.second;
            min_char = tmp_mp.first;
        }
    }
    if ( s.length() == 2 && mp.size() == 1 ) {
        cout << "NO" << endl;
        return 0;
    }
    if ( s.length() >= 3 && mp.size() < 3 ) {
        cout << "NO" << endl;
        return 0;
    }
    for ( auto tmp_mp : mp ) {
        if ( tmp_mp.second - min_num >= 2 ) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512