akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  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*(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<int> a(n);
  rep(i,n){
    cin >> a[i];
  }

  const int inf=1e+5; 
  vector<ll> num(inf,0);
  num[0]=3;
  mint res(1);
  rep(i,n){
    res*=(mint)num[a[i]];
    num[a[i]]--;
    num[a[i]+1]++;
  }

  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var ansl = new int[4] { 0, 0, 0, 0 };
        for (var i = 0; n > i; i++)
        {
            var l = Console.ReadLine();
            if (l == "AC") ansl[0]++;
            if (l == "WA") ansl[1]++;
            if (l == "TLE") ansl[2]++;
            if (l == "RE") ansl[3]++;
        }

        for (var i = 0; 4 > i; i++)
        {
            if (i == 0) Console.Write("AC");
            if (i == 1) Console.Write("WA");
            if (i == 2) Console.Write("TLE");
            if (i == 3) Console.Write("RE");
            Console.WriteLine($" x {ansl[i]}");
        }
    }
}

Measured memory_bytes: 30568
//
// Created by yamunaku on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

struct edge{
    int to;
    ll c;
};

int main(){
    CFS;
    int n, m;
    ll l;
    cin >> n >> m >> l;
    vector<vector<edge>> e(n);
    int u, v;
    ll c;
    rep(i, m){
        cin >> u >> v >> c;
        if(c > l) continue;
        u--, v--;
        e[u].push_back({v, c});
        e[v].push_back({u, c});
    }
    vector<vector<ll>> ans(n, vector<ll>(n, -1));
    rep(i, n){
        priority_queue<pair<pair<ll, ll>, int>> q;
        q.push({{0, 0}, i});
        int count = 0;
        while(!q.empty()){
            auto now = q.top();
            q.pop();
            if(ans[i][now.second] != -1) continue;
            count++;
            ans[i][now.second] = -now.first.first;
            for(auto nx:e[now.second]){
                if(ans[i][nx.to] != -1) continue;
                if(-now.first.second + nx.c > l){
                    q.push({{now.first.first - 1, -nx.c}, nx.to});
                }else{
                    q.push({{now.first.first, now.first.second-nx.c}, nx.to});
                }
            }
            if(count==n) break;
        }
    }
    int q;
    cin >> q;
    rep(i, q){
        cin >> u >> v;
        cout << ans[u - 1][v - 1] << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long res = 0;
  for (int i = 0; i < k; i++) {
    res += a[i];
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int Q = sc.nextInt();

            Node[] nodes = new Node[N];
            for (int i = 0; i < N; i++) {
                nodes[i] = new Node();
            }

            for (int i = 0; i < N - 1; i++) {
                int a = sc.nextInt();
                int b = sc.nextInt();

                nodes[a - 1].children.add(nodes[b - 1]);
            }

            for (int i = 0; i < Q; i++) {
                int p = sc.nextInt();
                long x = sc.nextLong();

                nodes[p - 1].counter += x;
            }

            addCounter(nodes[0]);

            StringBuffer ans = new StringBuffer();
            ans.append(nodes[0].counter);
            for (int i = 1; i < N; i++) {
                ans.append(" ").append(nodes[i].counter);
            }
            System.out.println(ans.toString());
        }
    }

    public static void addCounter(Node node) {
        for (Node child : node.children) {
            child.counter += node.counter;
            addCounter(child);
        }
    }

    public static class Node {

        public long counter = 0;

        public List<Node> children = new ArrayList<>();

    }

}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n,m,x;
  cin>>n>>m>>x;
  vector<ll> c(n);
  auto a = vec<ll>(n,m);
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[i][j];
  }
  ll ans = INF;
  for(int b=0;b<(1<<n);++b){
    bitset<32> mask(b);
    vector<ll> tmp(m);
    ll res = 0;
    rep(i,n)if(mask[i]){
      res += c[i];
      rep(j,m){
        tmp[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(i,m)if(tmp[i]<x)ok=false;
    if(ok)chmin(ans,res);
  }
  if(ans==INF)cout<<-1<<endl;
  else cout<<(ans)<<endl;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

void solve(long long Q, long long H, long long S, long long D, long long N){
	ll one=min({Q*4,2*H,S});
	ll two=min(2*one,D);
	ll ans=(N/2)*two + (N&1)*one;
	printf("%lld\n",ans);
}

int main(){	
	ios_base::sync_with_stdio(false); cin.tie(0);
	long long S;
	long long D;
	long long H;
	long long Q;
	long long N;
	scanf("%lld",&Q);
	scanf("%lld",&H);
	scanf("%lld",&S);
	scanf("%lld",&D);
	scanf("%lld",&N);
	solve(Q, H, S, D, N);
	return 0;
}



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

int N;
int Ns, Nl;
int num[4];
int S[4], L[4];
int result;

int main() {
    while (true) {
        result = 0;
        cin >> N;
        
        if (!N) break;            
        
        if (N != 6174) {
            num[0] = N / 1000;
            N %= 1000;
            num[1] = N / 100;
            N %= 100;
            num[2] = N / 10;
            N %= 10;
            num[3] = N;
            
            while (true) {
                Ns = 0; Nl = 0;
                int judge = 0;
                for (int i = 0; i < 4; i++) {
                    if (num[0] == num[i]) judge++;
                }

                if (judge == 4) {
                    cout << "NA" << endl;
                    break;
                }

                sort(num, num + 4);
                for (int i = 0; i < 4; i++) {
                    S[i] = num[i];
                }

                Ns += S[0] * 1000;
                Ns += S[1] * 100;
                Ns += S[2] * 10;
                Ns += S[3];

                sort(num, num + 4, greater<int>());
                for (int i = 0; i < 4; i++) {
                    L[i] = num[i];
                }

                Nl += L[0] * 1000;
                Nl += L[1] * 100;
                Nl += L[2] * 10;
                Nl += L[3];

                N = Nl - Ns;

                num[0] = N / 1000;
                N %= 1000;
                num[1] = N / 100;
                N %= 100;
                num[2] = N / 10;
                N %= 10;
                num[3] = N;

                result++;

                if(num[0] == 6 && num[1] == 1 && num[2] == 7 && num[3] == 4) {
                    cout << result << endl;
                    break;
                }
            }
        }
        else cout << 0 << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1180
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for i in range(M)]

ans = [[0,0]]*(M)

prefectures = [[] for i in range(0,N+1,1)]
for i in range(M):
    prefectures[PY[i][0]].append([PY[i][1],i])
for i in range(N+1):
    prefectures[i].sort()
for i in range(N+1):
    for j in range(len(prefectures[i])):
        ans[prefectures[i][j][1]]=[i,j+1]

for i in range(M):
    ans[i][0] = str(ans[i][0]).zfill(6)
    ans[i][1] = str(ans[i][1]).zfill(6)
    print("".join(ans[i]))



Measured memory_bytes: 135344
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define MOD 1000000007
typedef long long ll;
using namespace std;
int main()
{
	ll N, K, i, j, x = 0, c, r = 0; 
  	cin >> N >> K;
  	vector<ll> A(N);
  	for (i = 0; i < N; i++){
    	cin >> A[i];
    }
  	for (i = 40; i >= 0; i--) {
    	c = 0;
      	for (j = 0; j < N; j++) {
        	c += (A[j] >> i) & 1;
        }
        if (2 * c <= N && (x | (1L << i)) <= K) {
           	x |= 1L << i;
        }
    }
  	for (i = 0; i < N; i++) {
    	r += x ^ A[i];
    }
  	cout << r << endl;
}

Measured memory_bytes: 1024
import itertools

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(M)]

# 距離表の初期化
INF = 10 ** 12
dist = [[INF] * N for _ in range(N)]
for i in range(N):
	dist[i][i] = 0

# グラフを読み込みつつ距離表の更新
for a, b, c in ABC:
	a, b = a - 1, b - 1
	dist[a][b] = c
	dist[b][a] = c

# ワーシャル–フロイド法の前処理
for k in range(N):
	for i in range(N):
		for j in range(N):
			dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

#print(dist)

# 全探索(*^_^*)つ[rCr]
min_dist = INF
for p in itertools.permutations(r):
	d = 0
	for n in range(1, R):
		d += dist[p[n] - 1][p[n - 1] - 1]
	if d < min_dist:
		min_dist = d
		#print(d, p)
print(min_dist)


Measured memory_bytes: 48856
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,m,x[100010],y[100010];
vector<int> vec1,vec2;
int c1,c2;
signed main(){
	cin>>n>>m;
	rep(i,n){
		cin>>x[i];
		if(i)c1+=(x[i]-x[i-1])*i*(n-i);
		c1%=moder;
	}
	rep(i,m){
		cin>>y[i];
		if(i)c2+=(y[i]-y[i-1])*i*(m-i);
		c2%=moder;
	}
	cout<<c1*c2%moder<<endl;
	return 0;
}

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

int		main(void)
{
	int A, B, K;

	cin >> A >> B >> K;
	int cnt = 0;
	for (int i = min(A, B); i > 0; i--)
	{
		if (A % i == 0 && B % i ==0)
			cnt++;
		if (cnt == K)
		{
			cout << i << endl;
			return (0);
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 20;
int main()
{
    int n,l,r;
    scanf("%d%d%d",&n,&l,&r);
    int ans = 0; 
    for (int i = 1; i <=n; i++){
        int t = i;
        int tmps = 0;
        while (t){
           tmps += t % 10;
           t /= 10; 
        }
        if (tmps >= l && tmps <= r) {
            ans += i;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
stdin.ReadLine().Split(" ")
|> Array.map int
|> fun x ->
    if x |> Array.exists (fun x -> x % 3 = 0) then "Possible"
    else if x |> Array.reduce (+) |> (fun x -> x % 3 = 0) then "Possible"
    else "Impossible"
|> printfn "%s"


Measured memory_bytes: 29612
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    queue<char> ans;

    int a = tx - sx;
    int b = ty - sy;
    int c = a+1;
    int d = b+1;

    rep(i,a){
        ans.push('R');
    }
    rep(i,b){
        ans.push('U');
    }
    rep(i,a){
        ans.push('L');
    }
    rep(i,b){
        ans.push('D');
    }
    ans.push('D');
    rep(i,c){
        ans.push('R');
    }
    rep(i,d){
        ans.push('U');
    }
    ans.push('L');
    ans.push('U');
    rep(i,c){
        ans.push('L');
    }
    rep(i,d){
        ans.push('D');
    }
    ans.push('R');

    while(!ans.empty()){
        cout << ans.front();
        ans.pop();
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
i=0
j=0
k=0
answer = 0
left = 0
right = N
for j in range(N):
    while i<N and a[i] < b[j]:
        left += 1
        i += 1
    while k<N and c[k] <= b[j]:
        right -= 1
        k += 1
    answer += left*right
print(answer)



Measured memory_bytes: 22720
#include<stdio.h>
#include<string.h>
int c[20000001];
char ch[20],a[20];

int C(char x)
{
	
	if(x=='A') return 1;
	if(x=='C') return 2;
	if(x=='G') return 3;
	return 4;
}

int search(int k, int x, int y, int t)
{
	if(k==strlen(a))
	{
		if(!t) c[x] = 1;
		return c[x];
	}
	return search(k+1,x+C(a[k])*y,y*4,t);
}

int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s %s",ch,a);
		if(ch[0]=='i') 
		{
			search(0,0,1,0);
		}
		else
		{
			if(search(0,0,1,1))
			{
				printf("yes\n");
			}
			else printf("no\n");
		}
	}
	return 0;
}
	


Measured memory_bytes: 7096
#include <stdio.h>

int main(void){
	int N;
	int num[36];
	int num_b[36];
	int num_s[36];
	int key_i;
	
	char num_name[36];
	char num_name_b[36];
	char num_name_s[36];
	char key_c;

	int i,j,k,l = 0;
	
	int mini;
	
	char judge[5];
	char judge_bc[5];
	char judge_sc[5];
	int judge_b = 0;
	int judge_s = 0;
	
	//Input Cards
	scanf("%d",&N);
	
	for(i = 0;i < N;i++){
		scanf("%c",&num_name[i]);
		if(num_name[i] != '\n'&&num_name[i] != ' '){
			scanf("%d",&num[i]);
		}else{
			i--;
		}
	}
	
	//Copy Cards
	for(i = 0;i < N;i++){
		num_b[i] = num[i];
		num_s[i] = num[i];
		num_name_b[i] = num_name[i];
		num_name_s[i] = num_name[i];
	}
	
	//BubbleSort
	for(i = 0;i < N;i++){
		for(j = N-1;j > i;j--){
			if(num_b[j] < num_b[j-1]){
				key_i = num_b[j];
				key_c = num_name_b[j];
				num_b[j] = num_b[j-1];
				num_name_b[j] = num_name_b[j-1];
				num_b[j-1] = key_i;
				num_name_b[j-1] = key_c;
			}
		}
	}
	
	//Selection Sort
	for(i = 0;i < N;i++){
		mini = i;
		for(j = i;j < N;j++){
			if(num_s[j] < num_s[mini]){
				mini = j;
			}
		}
		key_i = num_s[i];
		key_c = num_name_s[i];
		num_s[i] = num_s[mini];
		num_name_s[i] = num_name_s[mini];
		num_s[mini] = key_i;
		num_name_s[mini] = key_c;
	}
	
	//Judge Stable or Not Stable
	for(i = 1;i < 10;i++){
		k = 0;
		for(j = 0;(j < N&&k < 4);j++){
			if(num[j] == i){
				judge[k] = num_name[j];
				k++;
			}
		}

		l = 0;
		
		if(judge_b == 0){
			for(j = 0;(j < N&&l < k);j++){
				if(num_b[j] == i){
					judge_bc[l] = num_name_b[j];
					l++;
				}
			}
			
			for(j = 0;j < k;j++){
				if(judge_bc[j] != judge[j])judge_b = 1;
			}
		}
		
		
		l = 0;
		
		if(judge_s == 0){
			
			for(j = 0;(j < N&&l < k);j++){
				if(num_s[j] == i){
					judge_sc[l] = num_name_s[j];
					l++;
				}
			}
			
			for(j = 0;j < k;j++){
				if(judge_sc[j] != judge[j])judge_s = 1;
			}
		}
	}
	
	
	//Display
	for(i = 0;i < N;i++){
		if(i == N -1){
			printf("%c%d",num_name_b[i],num_b[i]);
		}else{
			printf("%c%d ",num_name_b[i],num_b[i]);
		}
	}
	
	printf("\n");	
	
	if(judge_b == 0){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
	
	
	for(i = 0;i < N;i++){
		if(i == N -1){
			printf("%c%d",num_name_s[i],num_s[i]);
		}else{
			printf("%c%d ",num_name_s[i],num_s[i]);
		}
	}
	
	printf("\n");
	
	if(judge_s == 0){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
	
	return 0;
}

Measured memory_bytes: 612
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			
			//3個ずつ比較
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			
			//照準ソート
			Arrays.sort(temp);
			
			//ソート前とソート後で真ん中の値を比較
			if(array[i+1] == temp[1]) count++;
			
		}

		System.out.print(count);

		scanner.close();
	}

}

Measured memory_bytes: 25172
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getString()

	ans := "No"
	if (n[0] == n[1] && n[0] == n[2]) || (n[1] == n[2] && n[1] == n[3]) {
		ans = "Yes"
	}

	fmt.Println(ans)
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#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 EPS 1e-10
#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 first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#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> > // only sort first param
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 power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right



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

    ll N , K;
    cin >> N >> K;
    
    vector<ld> p;
    
    rep(i, N){
        ld inp;
        cin >> inp;
        inp += 1.0;
        inp /= 2.0;
        
        p.pb(inp);
    }
    
    ld ans = 0.0;
    
    ld s = 0.0;
    rep(i, K){
        s += p[i];
    }
    
    ans = s;
    
    for(ll i = K ; i < N; i ++){
        s += p[i];
        s -= p[i - K];
        
        ans = max(s, ans);
    }

    cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> a(n),b(n);
    rep (i,0,n)
    {
        cin>>a[i]>>b[i];
    }
    sort(all(a));
    sort(all(b));
    if (n%2==0)
    {
        ld val1=(a[n/2]+a[n/2-1])/((ld)2);
        ld val2=(b[n/2]+b[n/2-1])/((ld)2);
        val1*=2;
        val2*=2;
        ll ans=val2-val1+1;
        cout<<ans<<"\n";
    }
    else
    {
        ll val1=a[n/2],val2=b[n/2];
        cout<<val2-val1+1<<"\n";
    }
    
}


Measured memory_bytes: 6368
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arr = new long[n];
		long total = 0;
		long sub = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			total += a;
			arr[i] = a;
			if (i % 2 == 1) {
				sub += a;
			}
		}
		StringBuilder sb = new StringBuilder();
		long prev = total - 2 * sub;
		sb.append(prev);
		for (int i = 0; i < n - 1; i++) {
			prev = (arr[i] - prev / 2) * 2;
			sb.append(" ").append(prev);
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 59620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#define MAX_N 1000000000
typedef long long ll;
using namespace std;
int main(){
  ll N,temp,ans;
  cin>>N;
  for(temp=0; temp*temp<=N;temp++){
    ans=temp*temp;
  }
  cout<<ans<<endl;
  return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ld>v(n);
  rep(i,0,n)cin>>v[i];
  sort(ALL(v));
  rep(i,1,n){
    v[0]=(v[0]+v[i])/2;
  }
  cout<<setprecision(10)<<fixed<<v[0]<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define N 200010
using namespace std;
int n,k,a[N];
bool check(int x)
{
	int cnt = 0;
	for(int i=1;i<=n;i++) cnt+=(a[i]+x-1)/x-1;
//	cout<<x<<" "<<cnt<<" ##"<<endl;
	return cnt<=k;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin >> a[i];
	
	if(k==0)
	{
		int mx=0;
		for(int i=1;i<=n;i++) mx = max(mx, a[i]);
		cout << mx << endl;
		return 0;
	}
	
	int l=0,r=1e9;
	while(l<r-1)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else           l=mid;
	}
	cout << r << endl;
	
	return 0;
}

Measured memory_bytes: 4384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    int m, f, r;
    map<int, char> mp;
    mp[29] = 'F';
    mp[49] = 'D';
    mp[64] = 'C';
    mp[79] = 'B';
    mp[100] = 'A';
 
    int v[5] = {29, 49, 64, 79, 100};

    while (1) {

        cin >> m >> f >> r;

        if (m + f + r == -3) {
            return 0;
        }
        char rank;
        if (m == -1 || f == -1) {
            rank =  'F';
        }
        else {
            int point = m + f;
            
            for (auto criterion : v) {
                if (point <= criterion) {
                    if (criterion == 49) {
                        if (r >= 50) {
                            rank = 'C';
                            break;
                        }
                    }
                    rank =  mp[criterion];
                    break;
                }
            }
        }
        cout << rank << '\n';
    }

}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;

vector<int> v;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<int> v(n);
    for(int&i:v)cin>>i;
    int ans=v[0];
    for(int i=1; i<n; i++){
        ans=__gcd(v[i],ans);
    }
    cout<<ans;
    
    
    
    
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		int X = sc.nextInt();
		int Y = sc.nextInt();

		if(Y%2 == 1) {
			System.out.println("No");
			System.exit(0);
		}

		if(X*2<=Y && Y<= X*4) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35868
s=input()
s=s.replace("dream","D")
s=s.replace("erase","E")
s=s.replace("Der","M")
s=s.replace("Er","M")
s=s.replace("D","M")
s=s.replace("E","M")
s=s.replace("M","")
if s:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3188
import heapq as hq
s=[]
hq.heapify(s) #sをpriority-q化　O(n log(n))
# a=hq.heappop(s)  #最小値を取り出す O(log(n))
# hq.heappush(s,123) #123をs(priority-q)に追加 O(log(n))
n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    hq.heappush(s,(-a,False))
    hq.heappush(s,(-b,True))
ans=1
x,y=hq.heappop(s)
h+=x
while y and h>0:
    x,y=hq.heappop(s)
    h+=x
    ans+=1
if h>0:
    ans+=(h-x-1)//-x
print(ans)

Measured memory_bytes: 23812
#include<stdio.h>
#include<math.h>
int main()
{
	int n,m,t,a,x,y,a0=0,x0=0,y0=0,s,k=0;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d",&a,&x,&y);
		s=fabs(x-x0)+fabs(y-y0);
		x0=x,y0=y;
		if(!(s<=a-a0&&(a-a0-s)%2==0))
		{
			k=1;
		}
		a0=a;
	}
	if(k)puts("No");
	else puts("Yes");
}

Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt=0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            x=500*a+100*b+50*c
            if x==X:
                cnt+=1
            else:
                cnt=cnt
print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long a[100];
int main(){
	long long m;
	int n;
	scanf("%d",&n);
	a[0]=2;
	a[1]=1;
	m=a[1];
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
		m = a[i];
	}
	printf("%lld\n",m);
	return 0;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N = in();
    cout << N*(N-1)/2 << "\n";
}

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

int main() {
    int N,M;
    cin >> N;
    M = N / 1000;
    if (N % 1000 == 0) {
    cout << 1000 * M - N << endl;
    return 0;
    }
    cout << 1000 * (M + 1) - N << endl;
}

Measured memory_bytes: 3636
N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [False] * (K+1)
for i in range(1,K+1):
    for a in A:
        if i-a < 0: break
        if not dp[i-a]:
            dp[i] = True
print('First' if dp[-1] else 'Second')

Measured memory_bytes: 43884
N, K = map(int, input().split())
S = [0 for _ in range(N)]
for i in range(K):
  d = int(input())
  a = list(map(int,input().split()))
  for j in range(N):
    if (j+1) in a:
      S[j] = 1
print(S.count(0))

Measured memory_bytes: 67820
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod_exp(ll x, ll e) {
  ll ans = 1;
  while (e > 0) {
    if (e & 1) ans = mult(ans, x);
    x = mult(x, x);
    e >>= 1;
  }
  return ans;
}

ll inv(ll x) {
  return mod_exp(x, MOD-2);
}

ll fact[N], inv_fact[N];

ll ncr(ll n, ll k) {
  return mult(fact[n], mult(inv_fact[n-k], inv_fact[k]));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    fact[0] = 1;
    inv_fact[0] = 1;
    for (ll i = 1; i < M+5; i++) {
      fact[i] = mult(fact[i-1], i);
      inv_fact[i] = inv(fact[i]);
    }

    ll no = 0;
    for (ll i = 1; i <= N; i++) {
      ll curr = ncr(N, i);
      curr = mult(curr, mod_exp(MOD-1, i+1));
      curr = mult(curr, mod_exp(mult(fact[M-i], inv_fact[M-N]), 2));
      curr = mult(curr, mult(fact[M], inv_fact[M-i]));
      no = add(no, curr);
    }
    ll all = mod_exp(mult(fact[M], inv_fact[M-N]), 2);
    cout << sub(all, no) << endl;
}

Measured memory_bytes: 10964
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int n;

    cin >> n;

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

    bool flag = true;
    while (flag) {
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 != 0) flag = false;
        }
        if (flag) {
            count++;
            for (int i = 0; i < n; i++) {
                a[i] /= 2;
            }
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int64_t modPow(int a,int b,int d){
  bitset<40> bit(b);
  string s = bit.to_string();
  int64_t ret = 1;
  for(int i=0;i<s.length();++i){
    ret*=ret;
    if(s[i]-'0') ret*=a;
    ret%=d;
  }
  return ret;
}

int main() {
    string S;
    cin >> S;
    int64_t N = S.size();
    vector<int64_t> A(N + 1);
    int64_t now = 0, ans = 0;
    map<int64_t, int64_t> P;
    P[0]++;
    for (int i = 0; i < N; i++){
        A.at(i + 1) = (now + (S.at(N - i - 1) - '0') * modPow(10, i, 2019)) % 2019;
        now = A.at(i + 1);
        P[A.at(i + 1)]++;
    }

    for (auto x : P){
        int64_t a = x.first, b = x.second;
        ans += b * (b - 1) / 2;
    }
    cout << ans << endl;


}

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

int main() {
  int N;
  int M;
  int a;
  int b;
  int count=0;
  cin >>N>>M;
  
  long H[N+1];
  int ans[N+1];
  ans[0]=0;
  H[0]=0;
    for (int i=1;i<N+1;i++){
     cin >> H[i]; 
      ans[i]=0;
    }
  
  for(int i=0;i<M;i++){
    cin >> a>> b;
    if(H[a] >= H[b]){
      ans[b]=ans[b]+1;
    }
    if(H[a] <= H[b]){
     ans[a]=ans[a]+1; 
    }
    
  }
  for(int i=1;i<N+1;i++){
   if(ans[i]==0){
     count=count+1;
   }
    
  }
  cout << count << endl;
  
  
 return 0;
}


Measured memory_bytes: 4804
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        const int Mod = 1000000007;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s1 = Console.ReadLine();
            var s2 = Console.ReadLine();
            
            if (n == 1) {
               Console.WriteLine(3);
               return; 
            }
            
            var total = 6L;
            var start = 2;
            var counter = 0;
            var tate = false;
            if (s1[0] == s2[0]) {
                tate = true;
                start = 1;
                total = 3;
            }
            for (var i = start; i < n; i++) {
                if (tate) {
                    total *= 2;
                    if (s1[i] != s2[i])
                    {
                       tate = false;
                       i++; 
                    }
                } else {
                    if (s1[i] == s2[i]) {
                        tate = true;
                    } else {
                        total *= 3;
                        i++;
                    }
                }

                total %= Mod;
            }
            
            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <climits>
using namespace std;
typedef long long ll;

int main(int argc, const char* argv[])
{
    int N, K;
    cin >> N >> K;
    
    int h[N];
    for(int i = 0; i < N; i++)
        cin >> h[i];
    
    ll dp[N];
    dp[0] = 0;
    for(int i = 1; i < N; i++)
    {
        ll m = LLONG_MAX;
        for(int k = 1; k <= K; k++)
        {
            if(k <= i)
            {
                ll tmp = dp[i-k] + (h[i] - h[i-k] > 0 ? h[i] - h[i-k] : h[i-k] - h[i]);
                if(tmp < m)
                    m = tmp;
            }
        }
        
        dp[i] = m;
    }
    
    cout << dp[N-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%lld", &x)
#define pr(x) printf("%d", (x))
#define pr64(x) printf("%lld", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define fill(a,v,n) memset((a),(v),sizeof(a[0])*(n))
#define copy(a,b,n) memcpy((a),(b),sizeof(a[0])*(n))
#define ALL(x) (x.begin(),x.end())
#define prf(x) printf("%.20f", x)
#define for_each_edge(u) for(int i = point[u];i;i=G[i].n)
typedef unsigned int uint;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(int &a, int b){a = (a+b)%MOD;}
void _sub(int &a, int b){a = (a+MOD-b)%MOD;}
void _mul(int &a, int b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pw(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll pwM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(int n){
	cnt = 0;
	fill(point,0,n+1);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n, m, k,q;
char s[N];
int main(){
//	freopen("1", "r", stdin);
	scanf("%s",s+1);
	n = strlen(s+1);
	int num = 0;
	rep(i,1,n)num += s[i]-'0';
	if(s[n]=='1'){
		puts("-1");
		return 0;
	}
	if(s[1]=='0'){
		puts("-1");
		return 0;
	}
	rep(i,1,n-1)if(s[i] != s[n-i]){
		puts("-1");
		return 0;
	}
	if(num == n-1){
		rep(i,1,n-1)
			pr(i),sp,pr(i+1),ln;
		return 0;
	}
	if(num == 2){
		rep(i,2,n)
			pr(1),sp,pr(i),ln;
		return 0;
	}
	int la = 0;
	m = 0;
	rep(i,(n+1)/2,n){
		if(s[i] == '1'){
			rep(j,la+1,i-1){
				pr(j),sp,pr(i),ln;
				m++;
			}
			if(la){
				pr(la),sp,pr(i),ln;
				m++;
			}
			la = i;
		}
	}
	rep(i,la+1,n){
		pr(la),sp,pr(i),ln;
		m++;
	}
	assert(m==n-1);
//	puts("-1");
	return 0;
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
	    printf("Case #%d: ", ca);
	}
*/
	return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {

    public static void main(String[] args) {
        long MOD = 1000000007;
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long total = 0;
        for (long i = k; i <= n + 1; i++) {
            total += (n - i + 1 + n) * i / 2 - (0 + i - 1) * i / 2 + 1;
            total %= MOD;
        }
        System.out.println(total);
    }

}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }

int main() {
  unordered_set<ll> s;
  int N;
  cin >> N;
  
  for(int i=0; i<N; ++i) {
    ll A;
    cin >> A;
    if(s.find(A) == s.end()) {
      s.insert(A);  
    } else {
      cout << "NO" << endl;
      return 0;
    }
    
  }
  
  cout << "YES" << endl;
  
  return 0;
}

Measured memory_bytes: 8520
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,q;
ll s[200005],t[200005],x[200005];
set<pair<ll,int> >S;
vector<pair<ll,pair<ll,ll> > > vec;
ll ans[200005];
int main(){
	scanf("%d%d",&n,&q);
	repn(i,n){
		scanf("%lld%lld%lld",&s[i],&t[i],&x[i]);
		ll L = s[i]-x[i];
		ll R = t[i]-1-x[i];
		vec.pb(mp(x[i],mp(L,R)));
	}
	repn(i,q){
		ll d;
		scanf("%lld",&d);
		S.insert(mp(d,i));
		ans[i] = -1;
	}
	SORT(vec);
	rep(i,vec.size()){
		ll L = vec[i].sc.fi;
		ll R = vec[i].sc.sc;
		if(S.empty()) continue;
		auto it = S.lower_bound(mp(L,-1));
		while(S.size() && it != S.end() && (*it).fi <= R){
			ans[(*it).sc] = vec[i].fi;
			S.erase(it++);
		}
	}
	repn(i,q) printf("%lld\n",ans[i])
	;}

Measured memory_bytes: 26476
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	key, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := make(map[int]int)
	B := make(map[int]int)
	for i := 0; i < N; i++ {
		if i%2 == 0 {
			A[sc.nextInt()]++
		} else {
			B[sc.nextInt()]++
		}
	}
	valA := []Val{}
	for key, count := range A {
		valA = append(valA, Val{key, count})
	}
	sort.Sort(ByNum(valA))
	valB := []Val{}
	for key, count := range B {
		valB = append(valB, Val{key, count})
	}
	sort.Sort(ByNum(valB))
	aMin := valA[len(valA)-1]
	bMin := valB[len(valB)-1]
	if aMin.key != bMin.key {
		fmt.Fprintln(wtr, N-valA[len(valA)-1].num-valB[len(valB)-1].num)
	} else {
		var aMin2, bMin2 int
		if len(valA) != 1 {
			aMin2 = valA[len(valA)-2].num
		} else {
			aMin2 = 0
		}
		if len(valB) != 1 {
			bMin2 = valB[len(valB)-2].num
		} else {
			bMin2 = 0
		}
		mi := min(N-aMin.num-bMin2, N-bMin.num-aMin2)
		fmt.Fprintln(wtr, mi)
	}

	wtr.Flush()
}


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

//桁数を求める
int GetDigit(ll num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
int f(ll a, ll b){
    return max(GetDigit(a), GetDigit(b));
}


int main(){
ll n;
cin >> n;
int ans = 10;
ll a;
for (ll a = 1; a <= sqrt(n); a++)
{
    ll b = n/a;
    if(a*b==n){
        ans = min(ans,f(a,b));
    }
}




cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
long long a[200005];

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%lld",&a[i]);
    std::sort(a+1,a+1+n);
    long long ans = a[n];
    int need = n-2, p = n-1;
    while(need!=0){
        ans += a[p];
        need--;
        if(need==0) break;
        ans += a[p];
        need--;
        p--;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int sum_cnt = 0;
    rep(i,101)
    {
        int cnt = 0;
        bool prev_zero = true;

        rep(j,n)
        {
            if(h[j] <= 0)
            {
                prev_zero = true;
            }
            else
            {
                if(prev_zero) ++cnt;
                prev_zero = false;
                h[j] -= 1;               
            }
        }

        sum_cnt += cnt;

        if(cnt == 0)
            break;
    }

    cout << sum_cnt << endl;
    return 0;
}

Measured memory_bytes: 256