akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3000000;
const int K = 100000;
const int mod = 1e9 + 7;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    while(t--){
        int n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << endl;
    }
}


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

int dp[3001][3001];
int lcs(string s1,string s2,int n,int m){
    //cout<<"as ";
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
}

int main() {

	for(int i=0;i<=3000;i++)
    dp[i][0]=0;
    for(int i=0;i<=3000;i++)
    dp[0][i]=0;
	string s1,s2;
	int n,m,sum=1,c=0;
	cin>>s1>>s2;
	n=s1.size();
	m=s2.size();
	lcs(s1,s2,n,m);
	int index = dp[n][m]; 
  char lc[index+1]; 
   lc[index] = '\0'; // Set the terminating character 
   int i = n, j = m; 
   while (i > 0 && j > 0) 
   { 
       if (s1[i-1] == s2[j-1]) 
      { 
          lc[index-1] =s1[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
     else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
    cout<<lc;
	return 0;
}


Measured memory_bytes: 35456
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
TA=10**5+1
for i in range(n):
    if TA>abs(a-t+h[i]*0.006):
        ans=i+1
        TA=abs(a-t+h[i]*0.006)

print(ans)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

struct Dsu {
	int dsu[55];
	Dsu() { rep(i, 0, 55) dsu[i] = -1; }
	int find(int x) {
		return dsu[x] < 0 ? x : dsu[x] = find(dsu[x]);
	}
	void merge(int u, int v) {
		u = find(u), v = find(v);
		if (u == v) return;
		if (-dsu[u] < -dsu[v]) swap(u, v);
		dsu[u] += dsu[v];
		dsu[v] = u;
	}
} dsu;

int a[2505], b[2505];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	rep(i, 0, m) read(a[i], b[i]);
	int ans = 0;
	rep(i, 0, m) {
		dsu = Dsu();
		rep(j, 0, m) if (j != i) dsu.merge(a[j], b[j]);
		if (dsu.dsu[dsu.find(1)] != -n) ans++;
	}
	die(ans);
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl A(n+1);
    vl B(n);
    rep(i,n+1)cin>>A[i];
    rep(i,n)cin>>B[i];
    ll res=0;
    rep(i,n+1)res+=A[i];
    rep(i,n){
        ll a=A[i];
        A[i]=max(0,a-B[i]);
        B[i]=max(0,B[i]-a);
        a=A[i+1];
        A[i+1]=max(0,a-B[i]);
    }
    rep(i,n+1)res-=A[i];
    cout<<res<<endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Main me = new Main();
		System.out.println(me.fact(Integer.parseInt(in.readLine())));
	}
	private long fact(long n){
		if(n==0)
			return 1;
		else
			return n*fact(n-1);
	}
}

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

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

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

    sort(h.begin(), h.end(), greater<int>()); 

    long long ss; 
    if (k < n)
        ss = accumulate(h.begin() + k, h.end(), 0LL); 
    else 
        ss = 0;        
    cout << ss << "\n"; 


    return 0; 
}



Measured memory_bytes: 1024
function Main(input){
    input = input.split("\n");
    var arr = input[1].split(" ").map(Number);
    arr = arr.sort(function(a,b){return a-b});
    var n = (arr[0]+arr[1])/2;
  //  console.log(arr);
    arr.shift();
    arr.shift();
 //   console.log(arr,n);
    while(arr.length!=0){
        arr.splice(nibu(arr,n),0,n);
     //   console.log(arr);
        n = (arr[0]+arr[1])/2;
        arr.shift();
        arr.shift();
    }
    console.log(n)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function nibu(a,searchValue){
	var index = -1;

//調べる左端を表す添字(index)
var left = 0;

//調べる右端を表す添字(index)
var right = a.length-1;

//左端と右端にデータがある間は処理を繰り返す
while(left <= right){

    //左右の真ん中を表す添字(index)
    middle =Math.floor((left +right)/2);

    //真ん中の値と探す値を比較する
    if(a[middle]==searchValue){
        //一致した場合、変数に入れて処理終了
        index = middle;
        break;
    }else if(a[middle]<searchValue){
        //探す値より小さい場合、左側にはもっと小さい値しかないので左端の値を真ん中の値の右に移動する
        left = middle +1;
    }else{
        //探す値より大きい場合、右側にはもっと大きい値しかないので右端の値を真ん中の値の左に移動する
        right = middle -1;
    }
}
if(index!=-1) return index;
else return left;
}

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

int main() {
  int n;long long y;
  cin >> n >> y;
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n-i;j++){
      if(10000*i+5000*j+1000*(n-i-j) == y){
        cout << i << " " << j << " " << n-i-j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


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

using namespace std;

priority_queue < int, vector <int>, greater <int> > pq1, pq2;

const int Nmax = 1e5 + 5;

struct coins
{
    int gold, silver, dif;
};
coins v[Nmax];

int gold_coins, silver_coins, bronze_coins, i, x, y, z;
long long sum_bronze, sum_gold, dp[Nmax];

bool cmp (coins A, coins B)
{
    if (A.dif < B.dif) return true;
    if (A.dif == B.dif)
    {
        if (A.gold < B.gold) return true;
        if (A.gold == B.gold) return (A.silver > B.silver);
    }
    return false;
}

int main ()
{
  //  freopen("in", "r", stdin);
   // freopen("out", "w", stdout);
    scanf("%d %d %d\n", &gold_coins, &silver_coins, &bronze_coins);

    int N = gold_coins + silver_coins + bronze_coins;

    for (i = 1; i <= N; ++i)
    {
        scanf("%d %d %d\n", &x, &y, &z);

        v[i].gold = x - z, v[i].silver = y - z, v[i].dif = x - y;

        sum_bronze += z;
    }

    sort(v + 1, v + N + 1, cmp);

    //dp[i] = numarul maxim de silver pana in i
    dp[0] = 0;

    for (i = 1; i <= silver_coins; ++i)
        pq1.push(v[i].silver), dp[i] = dp[i - 1] + v[i].silver;

    for (i = N; i >= N - gold_coins + 1; --i)
        pq2.push(v[i].gold), sum_gold += v[i].gold;

    int Left = silver_coins + 1, Right = N - gold_coins;
    long long ans = -LLONG_MAX;

    for (i = Left; i <= N; ++i)
        if (pq1.top() < v[i].silver)
        {
            dp[i] = dp[i - 1] - pq1.top() + v[i].silver;
            pq1.pop();
            pq1.push(v[i].silver);
        }
        else dp[i] = dp[i - 1];

    ans = max(ans, dp[Right] + sum_gold);

    for (i = Right; i > silver_coins; --i)
    {
        if (pq2.top() < v[i].gold)
        {
            sum_gold -= pq2.top();
            pq2.pop();
            sum_gold += v[i].gold;
            pq2.push(v[i].gold);
        }
        ans = max(ans, dp[i - 1] +  sum_gold);
    }

    printf("%lld\n", ans + sum_bronze);

    return 0;
}


Measured memory_bytes: 2748
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int T,D,ta,tb,da,db;
  double mn;
  cin>>T>>D>>ta>>tb>>da>>db;
  mn=100;
  for(int i=0;i<=D;i+=da){
    for(int j=0;j<=D;j+=db){
      if(i+j>D)break;
      double C=1.0*(ta*i+tb*j)/(i+j);
      if(T-C>=0&&mn>T-C)mn=T-C;
      else if(C-T>0&&mn>C-T)mn=C-T;
    }
  }
  printf("%.10f\n",mn);
  return 0;
}

Measured memory_bytes: 1196
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,avx2,tune=native")
//#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define orz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);    
#define inp freopen("input.txt","r",stdin);freopen("out.txt","w",stdout); 
ll mod=1e9+7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    
}
const int N=2e5+5;

 
int main() {
	io();
	int n,k,i;
	cin>>n>>k;
	int cnt=0;
	for(i=0;i<n;i++){
		int x;
		cin>>x;
		if(x>=k)
			cnt++;
	}
	cout<<cnt;
}

Measured memory_bytes: 384
use proconio::input;

fn main() {
  input! {
    a: isize,
    b: isize,
    c: isize,
    mut k: isize,
  }
  // 1 が a, 0 が b, -1 がc
  let ka = a.min(k);
  k -= ka;
  let kb = b.min(k);
  k -= kb;
  let kc = c.min(k);
  println!("{}", ka - kc);
}


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

int main() {
    for (int i = 0; i < 3000; ++i) {
        int x, y; cin >> x >> y;
        
        if (x == 0 && y == 0) break;
        
        if (x > y) swap(x, y);
        
        cout << x << " " << y << endl;
    }
    return 0;
}


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

const ll INF = ll(1e18)+1;

int main(void){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll l = -INF,r = INF;
    //二分探索
    while(l+1<r){
        ll x = (l+r)/2;
        bool ok = [&]{
            ll tot = 0;
            rep(i,n){
                if (a[i]<0){
                    int l = -1,r = n;
                    while(l+1<r){
                        int c = (l+r)/2;
                        if(a[c]*a[i] < x) r=c; else l=c;
                    }
                    tot += n-r;
                }else{
                    int l = -1,r = n;
                    while(l+1<r){
                        int c = (l+r)/2;
                        if(a[c]*a[i] < x) l=c; else r=c;
                    }
                    tot += r;
                }
                if (a[i]*a[i] < x) tot --;
            }
            tot /= 2;
            return tot < k;
        }();
        if(ok) l=x;else r=x;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string A,B,C;

  cin >> A >> B >> C ;

  int x=0;//状態変数、0:A,1:B,2:C
  int a=0,b=0,c=0,ans=-1;

  while(1){
    switch(x){
      case 0 : if(a==A.size()){ans=0; break;}
               else {x=(int)(A.at(a)-'a'); a++; break;}

      case 1 : if(b==B.size()){ans=1; break;}
               else {x=(int)(B.at(b)-'a'); b++; break;}

      case 2 : if(c==C.size()){ans=2; break;}
              else {x=(int)(C.at(c)-'a'); c++; break;}
    }

    if(ans!=-1) break;    
  
  }

  if(ans==0) cout << 'A' << endl;

  else if(ans==1) cout << 'B' << endl;

  else if(ans==2) cout << 'C' << endl;
  
  return 0;
}

Measured memory_bytes: 256
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = (0..n1).to_a
  r = (0..n2).to_a
  0.upto(n1-1).each {|i| l[i] = a[left+i]}
  0.upto(n2-1).each {|i| r[i] = a[mid+i]}
  l[n1] = Float::INFINITY
  r[n2] = Float::INFINITY
  i = 0
  j = 0
  left.upto(right - 1).each {|k|
    if l[i] <= r[j]
      a[k] = l[i]
      i += 1
    else
      a[k] = r[j]
      j += 1
    end
  }
  i + j
end

def merge_sort(a, left, right)
  count = 0
  if left + 1 < right
    mid = (left + right) / 2
    count += merge_sort(a, left, mid)
    count += merge_sort(a, mid, right)
    count += merge(a, left, mid, right)
  end
  count
end

n = gets.to_i
s = gets.split.map(&:to_i)

count = merge_sort(s, 0, s.size)
puts s.join(" ")
puts count

Measured memory_bytes: 59636
/** AtCoder Beginner Contest 136, by Abreto<m@abreto.net> */
#include <bits/stdc++.h>

using namespace std;

namespace abreto {

const int maxn = 512;

int N, K;
int A[maxn];
int S;

bool check(int g)
{
    vector<int> rs;
    int sumr = 0;
    for (int i = 0; i < N; i++) {
        int r = A[i] % g;
        sumr += r;
        rs.push_back(r);
    }
    if (sumr % g) return false;
    int sumk = sumr / g;
    sort(rs.begin(), rs.end());
    int totOps = 0;
    for (int i = 0; i < N - sumk; i++)
        totOps += rs[i];
    return (totOps <= K);
}

void main(void)
{
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S += A[i];
    }
    int ans = 1;
    for (int i = 1; i*i <= S; i++) {
        if (0 == S % i) {
            if (check(S / i)) ans = max(ans, S / i);
            if (check(i)) ans = max(ans, i);
        }
    }
    cout << ans << '\n';
}

}

int main(void)
{
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    abreto::main();
    return 0;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    sxr = 0
    for i in a:
        sxr = sxr^i
    ans = []
    for i in a:
        ans.append(str(i^sxr))
    print(" ".join(ans))

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 109084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 5100000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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



int n, m;
vector<PII> ans;
Vl g[100005];
ll h[100005];


int main() {

	cin >> n >> m;
	rep(i, n - 1 + m) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		h[y]++;
	}

	queue <int> q;

	rrep(i, n)if (h[i] == 0)q.push(i);

	int s = q.front();
	ans.push_back(dmp(s, 0));

	while (!q.empty()) {
		int tmp = q.front(); q.pop();

		rep(i, g[tmp].size()) {
			h[g[tmp][i]]--;
			if (h[g[tmp][i]] == 0) {
				ans.pb(dmp(g[tmp][i], tmp));
				q.push(g[tmp][i]);
			}
		}
	}

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

	rep(i, ans.size()) {
		cout << ans[i].se << endl;
	}

	return 0;
}


Measured memory_bytes: 7924
#include <iostream>
#include <string>
using namespace std;
 
#define MAX 200000
 
long long combination(long long );
 
int main() {
	long long N;
	long long i;
	long long s;
	long long a[MAX];
	long long ser[MAX + 1] = { 0 };
	long long sum = 0;
	long long ans;
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> a[i];
		ser[a[i]]++;
	}
	for (i = 0; i <= N; i++) {
		if (ser[i] >= 2) {
			sum += combination(ser[i]);
		}
	}
	for (i = 0; i < N; i++) {
		if (ser[a[i]] >= 2 )ans = sum - combination(ser[a[i]]);
        else ans = sum;
		if (ser[a[i]] - 1 >= 2)ans += combination(ser[a[i]] - 1);
		cout << ans << endl;
	}
	return 0;
}
 
long long combination(long long a) {
	long long nu;
	nu = a * (a - 1) / 2;
	return nu;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int main() {
    string S;
    cin >> S;
    cout << S[0] << S[1] << S[2] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> cnt(3, vector<int>(n + 1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cnt[j][i + 1] = cnt[j][i];
        }
        if (s[i] == 'R') cnt[0][i + 1]++;
        if (s[i] == 'G') cnt[1][i + 1]++;
        if (s[i] == 'B') cnt[2][i + 1]++;
    }
    ll ans = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;
            int len = j - i;
            if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
                if (j + len >= n) {
                    ans += cnt[2][n] - cnt[2][j];
                }
                else {
                    ans += cnt[2][n] - cnt[2][j] - (s[j + len] == 'B' ? 1 : 0);
                }
            }
            else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
                if (j + len >= n) {
                    ans += cnt[1][n] - cnt[1][j];
                }
                else {
                    ans += cnt[1][n] - cnt[1][j] - (s[j + len] == 'G' ? 1 : 0);
                }
            }
            else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
                if (j + len >= n) {
                    ans += cnt[0][n] - cnt[0][j];
                }
                else {
                    ans += cnt[0][n] - cnt[0][j] - (s[j + len] == 'R' ? 1 : 0);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
const ll mod = 1000000007;

int n;
int a[200010];
int b[200010];
vector<int> ans;
signed main() {
    cin >> n;
    for (int i=1;i<=n;i++) {
        cin >> a[i];
    }

    for (int i=n;i>=1;i--) {
        for (int j=1;j*i<=n;j++) {
            b[i] ^= b[i*j];
        }
        b[i] ^= a[i];
        if (b[i] == 1) ans.push_back(i);
    }

    cout << ans.size() << endl;
    for (auto &it :ans) cout << it << " " << endl;
}

// logのテイラー展開
// 倍数のみの処理
//XOR(bit) 最適解の構成

Measured memory_bytes: 5108
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
void solve(){

}

int main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;

     return 0;

}
///Alhamdulillah



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    void run() {
        Scanner scan = new Scanner(System.in);
        int start = scan.nextInt();
        int end = scan.nextInt();
        int ans = 0;
        for (int i = start; i <= end; i++) {
            String num = String.valueOf(i);
            if (num.charAt(0) == num.charAt(4) && num.charAt(1) == num.charAt(3))
                ans++;
        }
        System.out.println(ans);
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int in(){
    int a,b;
    cin>>a>>b;
    return a*60+b;
}

int N;

int A[55],B[55],C[55],D[55],E[55],F[55];

int sum[24*60+114];

int atmpt(int s,int t){
    memset(sum,0,sizeof(sum));
    vpint lis;

    rep(i,N){
        if(s<A[i]||B[i]<s)continue;
        if(t<C[i]||D[i]<t)continue;
        sum[E[i]]++;
        sum[F[i]+1]--;
    }

    rep(i,24*60)sum[i+1]+=sum[i];
    return *max_element(sum,sum+24*60);

}

signed main(){
    cin>>N;

    vint lis;
    rep(i,N){
        A[i]=in();B[i]=in();C[i]=in();D[i]=in();E[i]=in();F[i]=in();
        lis.pb(A[i]);lis.pb(C[i]);
    }
    sort(all(lis));
    lis.erase(unique(all(lis)),lis.end());


    int ans=0;
    rep(i,lis.size()){
        for(int j=i+1;j<lis.size();j++){
            chmax(ans,atmpt(lis[i],lis[j]));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3132
H, W = map(int, input().split())
C = [[0 for _ in range(10)] for _ in range(10)]
for i in range(10):
    for j, c in enumerate(input().split()):
        C[i][j] = int(c)
for k in range(10):
    for i in range(10):
        for j in range(10):
            if C[i][j] > C[i][k] + C[k][j]:
                C[i][j] = C[i][k] + C[k][j]

ans = 0
for i in range(H):
    for A in input().split():
        A = int(A)
        if A >= 0:
            ans += C[A][1]
# print(C)
print(ans)


Measured memory_bytes: 3064
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import product
def main():
    n, m, x = map(int, input().split())
    books = []
    for _ in range(n):
        book = tuple(map(int, input().split()))
        books.append(book)
    pro = product((1, 0),repeat=n)
    costs = []

    for proe in pro:
        cost = 0
        algo = [0] * m
        for i1, proee in enumerate(proe):
            if proee:
                cost += books[i1][0]
                for al in range(1, m + 1):
                    algo[al-1] += books[i1][al]
        if all([i >= x for i in algo]):
            costs.append(cost)
    if not costs:
        print(-1)
    else:
        print(min(costs))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9152
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


//1=2
//2=4
//3=6+1=7
//4=8+3=11
//5=10+6=16
//6=12+10=22

int n;
vector<ll> a;
int main(){
	a.PB(0);
	a.PB(0);
	a.PB(0);
	a.PB(1);
	a.PB(3);
	rep(i,10000) a.PB(a[a.size()-1]+a.size()-2);
	//rep(i,30) cout<<a[i]<<endl;
	while(cin>>n){
		ll res=2*n;
		res+=a[n];
		//cout<<a[n]<<endl<<endl;
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
ll arr[200005];
int ball[200005];
int main(){
	int n;
	cin>>n;
	for(int i=0; i<n; i++){
		int a;
		cin>>a;
		ball[i] = a;
		arr[a]++;
	}
	ll total = 0;
	for(int i=1; i<=n; i++){
		total+=arr[i]*(arr[i]-1)/2;
	}
	for(int j=0; j<n; j++){
		int i = arr[ball[j]];
		cout<<total-(i-1)<<'\n';
	}
}

Measured memory_bytes: 5912
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [a, b, k]: number[] = tmp[0].split(" ").map(int => parseInt(int));
    return `${Math.max(a - k, 0)} ${k - a >= 0 ? Math.max(b - (k - a), 0) : b}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
A, B, C, D = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def f(num, c, d):
    return num - (num // c + num // d - num // int(c * d / gcd(c, d)))

print (f(B, C, D) - f(A - 1, C, D))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct E
{
    long long x,y;
}a[N];
 
bool cmp1(E e1,E e2)
{
    return e1.y>e2.y;
}
 
bool cmp2(E e1,E e2)
{
    return e1.x>e2.x;
}
 
int main()
{
    int n,s,i;
	cin>>n>>s;
    for(i=0;i<n;i++)
	{
        cin>>a[i].x>>a[i].y;
    }
    sort(a,a+n,cmp2);
    long long max_x=a[0].x;
    sort(a,a+n,cmp1);
    int len_t=n;
    for(i=0;i<n;i++)
	{
        if(a[i].y<max_x)
		{
            len_t=i;
            break;
        }
    }
    long long sum=0;
    int res=0;
    for(i=0;i<len_t;i++)
	{
        sum+=a[i].y;
        res++;
        if(sum>=s)
		{
            cout<<res<<endl;
            return 0;
        }
    }
    s-=sum;
    res+=ceil(s*1.0/max_x);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int r = nextInt();

    int ans = 0;

    if(n>=10){
      ans = r;
    }
    else{
      ans = r + 1000 - 100*n;
    }

    System.out.println(ans);

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 21460
s = int(input())
A = [s]
counter = 1
while(True):
  counter += 1
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1
  # print(s, A)
  if s in A:
    break
  A.append(s)
print(counter)


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

int n;
int payback()
{
    return 800 * n - (n / 15) * 200;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> n;

    cout << payback() << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()[::-1]
MOD = 10**9 + 7
n = len(s)

data = [0 for i in range(n+2)] #10**iを13で割ったあまり
data[0] = 1
for i in range(1,n+2):
    data[i] = (data[i-1]*10)%13


dp = [[0 for i in range(13)] for j in range(10**5+100)]

if s[0] ==  '?':
    for i in range(10):
        dp[0][i] = 1
else:
    i = int(s[0])
    dp[0][i] = 1


for i in range(1,n):
    for j in range(13):
        if s[i] == '?':
            for k in range(10):
                dp[i][(k*data[i] + j)%13] += dp[i-1][j]
        else:
            num = int(s[i])
            dp[i][(num*data[i]+j)%13] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %=MOD

print(dp[n-1][5])

Measured memory_bytes: 67708
MAX = 3000
leap = (4...MAX).step(4).to_a - (100...MAX).step(100).to_a + (400...MAX).step(400).to_a
while gets
  a, b = $_.split.map(&:to_i)
  break if a == 0 && b == 0
  puts if $<.lineno > 1

  ret = [*a..b] & leap
  puts (ret.empty? ? "NA" : ret)
end

Measured memory_bytes: 6252
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  int N;
  cin >> N;
  vector<vector<int>> A(2,vector<int>(N));
  REP(i, 2){
    REP(j, N){
      cin >> A.at(i).at(j);
    }
  }

  int MAX = 0;
  REP(i,N){
    int cnt = 0;
    REP(j,N){
      if(j<=i){
        cnt+=A.at(0).at(j);
      }
      if(j>=i){
        cnt+=A.at(1).at(j);
      }
    }
    MAX = max(MAX,cnt);
  }

  cout << MAX << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <queue>
using namespace std;

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

inline int enc(int y,int x){
    return 52*y+x;
}

inline int enc2(int ty, int tx, int ky, int kx){
    return enc(ty,tx)*52*52 + enc(ky,kx);
}

int main(){
    int w,h,tx,ty,kx,ky;
    static int board[52][52];
    static int dist[52*52*52*52];
    while(scanf("%d%d",&w,&h),w){
        scanf("%d%d%d%d",&tx,&ty,&kx,&ky);
        for(int i=0; i<52; i++)
            for(int j=0; j<52; j++)
                board[i][j] = 1;
        for(int i=1; i<=h; i++)
            for(int j=1; j<=w;j++)
                scanf("%d",board[i]+j);
        for(int i=0; i<52*52*52*52; i++)
            dist[i] = 1<<10;

        queue< pair<int,int> > Q;
        dist[enc2(ty,tx,ky,kx)] = 0;
        for(int k=0; k<4; k++){
            int nty = ty + dy[k],
                ntx = tx + dx[k],
                nky = ky - dy[k],
                nkx = kx - dx[k];
            if(board[nty][ntx]) nty = ty, ntx = tx;
            if(board[nky][nkx]) nky = ky, nkx = kx;
            int p = enc2(nty,ntx,nky,nkx);
            if(1 < dist[p]){
                dist[p] = 1;
                Q.push( make_pair(p,2) );
            }
        }
        while(!Q.empty()){
            ty = (Q.front().first/(52*52))/52;
            tx = (Q.front().first/(52*52))%52;
            ky = (Q.front().first%(52*52))/52;
            kx = (Q.front().first%(52*52))%52;
            int d = Q.front().second;
            if(d > 100) break;
            Q.pop();
            for(int k=0; k<4; k++){
               int nty = ty + dy[k],
                   ntx = tx + dx[k],
                   nky = ky - dy[k],
                   nkx = kx - dx[k];
               if(board[nty][ntx]) nty = ty, ntx = tx;
               if(board[nky][nkx]) nky = ky, nkx = kx;
               int p = enc2(nty,ntx,nky,nkx);
               if(d < dist[p]){
                   dist[p] = d;
                   Q.push( make_pair(p,d+1) );
               }
           }
        }
        int ans = 1<<20;
        for(int i=1; i<=h; i++)
            for(int j=1; j<=w; j++)
                ans = min(ans,dist[enc2(i,j,i,j)]);
        if(ans > 100)
            printf("NA\n");
        else
            printf("%d\n",ans);
    }
}

Measured memory_bytes: 29000
def comb(n, r):
    if r<0 or r>n:
        return 0
    r=min(r, n-r)
    return g1[n]*g2[r]*g2[n-r]%MOD

MOD=10**9+7
MAXN=2000+10
g1=[1, 1]
g2=[1, 1]
inverse=[0, 1]

for i in range(2, MAXN+1):
    g1.append((g1[-1]*i)%MOD)
    inverse.append(-inverse[MOD%i]*(MOD//i)%MOD)
    g2.append((g2[-1]*inverse[-1])%MOD)

def f(n, k):
    if n<k:
        return 0
    if n==0 and k==0:
        return 1
    if k<1:
        return 0
    return f2(n-k, k)

def f2(n, k):
    return comb(n+k-1, k-1)

N, K=map(int, input().split())
for i in range(1, K+1):
    b=f(K, i)
    r=f(N-K, i-1)+2*f(N-K, i)+f(N-K, i+1)
    print((b*r)%MOD)

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

int main() {
	int n;
	long long a;
	cin>>n;
	set <long long> myset;
	for(int i=0;i<n;i++){
		cin>>a;
		myset.insert(a);
	}
	if(myset.size()==n) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 9600
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	std::size_t N;
	std::cin >> N;
	std::multiset<int> set;
	std::size_t minus_count = 0;
	for (int i : boost::irange<std::size_t>(0, N))
	{
		int a;
		std::cin >> a;
		if (a < 0)
		{
			++minus_count;
		}
		set.emplace(a);
	}
	std::vector<std::pair<int, int>> action;
	if (minus_count == N)
	{
		while (set.size() != 1)
		{
			auto a = *set.rbegin();
			auto b = *std::next(set.rbegin());
			set.erase(std::prev(set.end(), 2), set.end());
			action.emplace_back(a, b);
			set.emplace(a - b);
		}
	}
	else if (minus_count == 0)
	{
		while (set.size() != 2)
		{
			auto a = *set.begin();
			auto b = *std::next(set.begin());
			set.erase(set.begin(), std::next(set.begin(), 2));
			action.emplace_back(a, b);
			set.emplace(a - b);
		}
		auto a = *set.begin();
		auto b = *std::next(set.begin());
		set.erase(set.begin(), std::next(set.begin(), 2));
		action.emplace_back(b, a);
		set.emplace(b - a);
	}
	else
	{
		while (minus_count != 1)
		{
			auto ite = set.lower_bound(0);
			auto a = *set.begin();
			auto b = *ite;
			set.erase(ite);
			set.erase(set.begin());
			action.emplace_back(b, a);
			set.emplace(b - a);
			--minus_count;
		}
		while (set.size() != 2)
		{
			auto a = *set.begin();
			auto b = *std::next(set.begin());
			set.erase(set.begin(), std::next(set.begin(), 2));
			action.emplace_back(a, b);
			set.emplace(a - b);
		}
		auto a = *set.begin();
		auto b = *std::next(set.begin());
		set.erase(set.begin(), std::next(set.begin(), 2));
		action.emplace_back(b, a);
		set.emplace(b - a);
	}
	std::cout << *set.begin() << std::endl;
	for (auto&& p : action)
	{
		std::cout << p.first << " " << p.second << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    map<int, int> mp;

    int k;
    rep(i, n-1) {
        cin >> k;
        mp[k]++;
    }

    rep(i, n) {
        cout << mp[i+1] << endl;
    }

    return 0;
}


Measured memory_bytes: 13028
h , w = map(int, input().split())
c=[[] for i in range(10)]
for i in range(10):
	c[i] = list(map(int,input().split()))

mp=[[0]*10 for i in range(10)]

for i in range(10):
	for j in range(10):
		for k in range(10):
			c[j][k]=min(c[j][k],c[j][i]+c[i][k])

a=[[] for i in range(h)]

for i in range(h):
	a[i] = list(map(int,input().split()))
ans=0
for i in range(h):
	for j in range(w):
		if a[i][j]!=-1:
			ans+=c[a[i][j]][1]
print(ans)


Measured memory_bytes: 9604
from collections import Counter
n = int(input())
c = list(input())
cc = Counter(c)
ans = 0
i = 0
while(cc["R"] and i < n):
    if c[i] == "W":
        ans += 1
        cc["R"] -= 1
    if c[i] == "R":
        cc["R"] -= 1
    i += 1
print(ans)

Measured memory_bytes: 11020
#include<bits/stdc++.h>
using namespace std;
string s;
const int mod=998244353;
int n,pre[2222][2],dp[4444][4444],res;
void add(int &a,int b)
{
	a+=b;
	if (a>=mod) a-=mod;
}
int main()
{
	cin>>s;
	n=s.size();
	for (int i=1;i<=n;i++)
	{
		if (s[i-1]=='0')
		{
			pre[i][0]=pre[i-1][0]+2;
			pre[i][1]=pre[i-1][1];
		}
		else if (s[i-1]=='1')
		{
			pre[i][0]=pre[i-1][0]+1;
			pre[i][1]=pre[i-1][1]+1;
		}
		else
		{
			pre[i][0]=pre[i-1][0];
			pre[i][1]=pre[i-1][1]+2;
		}
	}
	dp[0][0]=1;
	for (int i=0;i<2*n;i++)
	{
		for (int j=0;j<=i;j++)
		{
			if (!dp[i][j]) continue;
			if (pre[min(n,i+1)][1]>j)
			{
				add(dp[i+1][j+1],dp[i][j]);
			}
			if (pre[min(n,i+1)][0]>i-j)
			{
				add(dp[i+1][j],dp[i][j]);
			}
		}
	}
	for (int i=0;i<=2*n;i++) add(res,dp[2*n][i]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 68352
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner input=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int a=input.nextInt();
		int b=input.nextInt();
		int ans=-1, i=0;
		for(i=0;i<10*(b+1);i++) {
			if((int)(0.08*i)==a&&(int)(0.1*i)==b) {
				ans=i;
				break;
			}
		}
		pw.print(ans);
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 23252
using System;

namespace C___Coloring_Colorfully
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int N = S.Length;

            string str01 = Make01(false,N);
            string str10 = Make01(true,N);

            Console.WriteLine(Math.Min(diffCount(S,str01,N),diffCount(S,str10,N)));
        }

        // 0と1を交互に繰り返す文字列を生成
        static string Make01(bool isStart1,int count)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            for(int i = 0 ; i < count ; i++)
            {
                sb.Append(isStart1?"1":"0");
                isStart1 = !isStart1;
            }
            return sb.ToString();
        }

        // 文字列を比較し、違う文字の数を返す
        static int diffCount(string str1,string str2,int count)
        {
            int _diffCount = 0;
            for(int i = 0 ; i < count ; i++)
            {
                if(str1[i] != str2[i]) _diffCount++;
            }

            return _diffCount;
        }
    }
}


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

using namespace std;

const int MAX_N = 100000;

int v[MAX_N];

int main() {
  int n;
  long long st, dr;
  bool ok = true;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i)
    scanf("%d", &v[i]);
  st = dr = 2;
  for(int i = n - 1; i >= 0; --i) {
    if(st % v[i] == 0)
      dr = (dr / v[i] + 1) * v[i] - 1;
    else if((st / v[i] + 1) * v[i] <= dr) {
      st = (st / v[i] + 1) * v[i];
      dr = (dr / v[i] + 1) * v[i] - 1;
    } else
      ok = false;
  }

  if(!ok)
    printf("-1");
  else
    printf("%lld %lld", st, dr);
  return 0;
}


Measured memory_bytes: 640