akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;

int n;
bool a;
vector<int> ms;
vector<int> ms2;
vector<int> msp;

void msk()
{
    for (int i = 2; i < 300000; i++)
    {
        if (i % 7 == 1 || i % 7 == 6)
        {
            ms.push_back(i);
        }
    }

    for (int i = 0; i < ms.size(); i++)
    {
        a = true;
        for (int j = 0; ms.at(j) <= sqrt(ms.at(i)); j++)
        {
            if (ms.at(i) % ms.at(j) == 0)
            {
                a = false;
                break;
            }
        }
        if (a)
            ms2.push_back(ms.at(i));
    }

    for (int i = 0; i < ms2.size(); i++)
    {
        msp.push_back(ms2.at(i));
    }
}

int main()
{
    msk();
    while (1)
    {
        scanf("%d", &n);
        if (n == 1)
            return 0;

        printf("%d:", n);
        for (int i = 0; i < ms2.size(); i++)
        {
            if (n % ms2.at(i) == 0)
            {
                printf(" %d", ms2.at(i));
            }
        }
        printf("\n");
    }
}


Measured memory_bytes: 3052
print([51,0,0,0,4,5,0,0,15,0,0,0,0,1,0,0,14,1,0,0,0,0,0,0,5,0,2,0,0,0,0,1][-int(input())])
#メモ

# 1->1 000
# 6->2 example0
# 8->5 001
# 15->1 002
# 16->14 003
# 19->1 004
# 24->15 005
# 27->5 example1
# 28->4 006
# 32->51 007

# %14
# 0->4
# 1->1
# 2->14
# 4->51
# 5->1
# 6->2
# 8->5
# 10->15
# 13->5

Measured memory_bytes: 2940
s = input()
if((len(s) >= 1)and(len(s) <= 100)):
  ls1 = []
  ls2 = []
  count = 0
  for char in s:
    ls1.append(char)
  ls2 = ls1.copy()
  ls1.reverse()
  for i in range(int(len(ls2)/2)):
    if (ls1[i] != ls2[i]):
      count += 1
  print(count)

Measured memory_bytes: 3064
N, M = list(map(int, input().split()))

numlist = [-1] * N
exist = True
for m in range(M):
    s, c = list(map(int, input().split()))
    if numlist[s - 1] == -1:
        numlist[s - 1] = c
    else:
        if numlist[s - 1] != c:
            exist = False
            break

if numlist[0] == 0 and len(numlist) > 1:
    exist = False
elif numlist[0] == -1 and len(numlist) > 1:
    numlist[0] = 1
elif numlist[0] == -1 and len(numlist) == 1:
    numlist[0] = 0
if exist:
    ans = [0 if i == -1 else i for i in numlist]
    print(''.join([str(i) for i in ans]))
else:
    print(-1)


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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

const int N = 1e5 + 4;

int n, t, a[N], m[N];
map<int, int> cnt;

void solve() {
    cin >> n >> t;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        m[i] = (i ? min(a[i], m[i - 1]) : a[i]);
    }
    for (int i = 1; i < n; ++i) {
        if (a[i] > m[i - 1]) {
            cnt[a[i] - m[i - 1]]++;
        }
    }
    cout << cnt.rbegin()->second << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 9096
n, m = list(map(int, input().split()))
student_positions = []
checkpoints = []

for i in range(n):
  student_positions.append(list(map(int, input().split())))

for i in range(m):
  checkpoints.append(list(map(int, input().split())))

for i in range(n):
  max = 0
  for j in range(1, m):
    if abs(student_positions[i][0] - checkpoints[j][0]) + abs(student_positions[i][1] - checkpoints[j][1]) < abs(student_positions[i][0] - checkpoints[max][0]) + abs(student_positions[i][1] - checkpoints[max][1]):
      max = j

  print(max + 1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int k;
    cin>>s>>k;
    vector<string> ans;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=k;j++){
            ans.push_back(s.substr(i,j));
        }
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    //for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
    cout<<ans[k-1]<<endl;
    return 0;
}


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

int main(void){
  long long n, a[10010], cnt=0;
  scanf("%d",&n);
  for (long long i = 0; i < n; i++) {
    scanf("%d",&a[i]);
    while (a[i]%2==0) {
      a[i] = a[i] / 2;
      cnt++;
    }
  }

  printf("%lld", cnt);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	char a;
	cin>>a;
	if (a>='a' && a<='z')cout<<'a'<<endl;
	else cout<<'A'<<endl;
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
typedef long long ll;
int dp[2][1000001];
ll util(vector<int> adj[], int n, int u, int parent, int flag){
    if(dp[flag][u] != -1) return dp[flag][u]%MOD;
    int white = 1;
    for(int i=0;i<adj[u].size();i++){
        int v = adj[u][i];
        if(v != parent) white = (white*(util(adj, n, v, u, 0)%MOD))%MOD;
    }
    int res = white;
    if(flag == 0){
        int black = 1;
        for(int i=0;i<adj[u].size();i++){
            int v = adj[u][i];
            if(v != parent) black = (black*(util(adj, n, v, u, 1)%MOD))%MOD;
        }
        res = (res%MOD + black%MOD)%MOD;
    }
    dp[flag][u] = res;
    return res;
}
int main(){
	int n;
	cin>>n;
    vector<int> adj[n];
    for(int i=0;i<n-1;i++){
        int xi, yi;
        cin>>xi>>yi;
        adj[xi-1].push_back(yi-1);
        adj[yi-1].push_back(xi-1);
    }
    memset(dp, -1, sizeof(dp));
    int ans = util(adj, n, 0, -1, 0);
    cout<<ans;
	return 0;
}

Measured memory_bytes: 21888
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int M,N,K;
  int a,b,c,d;
  cin>>M>>N>>K;
  vector< vector<char> >f(M+1,vector<char>(N+1,0));
  vector< vector<int> >J(M+1,vector<int>(N+1,0));
  vector< vector<int> >O(M+1,vector<int>(N+1,0));
  vector< vector<int> >I(M+1,vector<int>(N+1,0));

  for(int i=1;i<=M;i++){
    for(int j=1;j<=N;j++){
      cin>>f[i][j];
    }
  }

  for(int i=1;i<=M;i++){
    J[i][1] = (f[i][1]=='J');
    O[i][1] = (f[i][1]=='O');
    I[i][1] = (f[i][1]=='I');
    for(int j=2;j<=N;j++){
      J[i][j] = J[i][j-1] + (f[i][j]=='J');
      O[i][j] = O[i][j-1] + (f[i][j]=='O');
      I[i][j] = I[i][j-1] + (f[i][j]=='I');
    }
  }
  for(int i=2;i<=M;i++){
    for(int j=1;j<=N;j++){
      J[i][j]+=J[i-1][j];
      O[i][j]+=O[i-1][j];
      I[i][j]+=I[i-1][j];
    }
  }

  for(int i=0;i<K;i++){
    cin>>a>>b>>c>>d;
    cout<<J[c][d]-J[c][b-1]-J[a-1][d]+J[a-1][b-1]<<" "
	<<O[c][d]-O[c][b-1]-O[a-1][d]+O[a-1][b-1]<<" "
	<<I[c][d]-I[c][b-1]-I[a-1][d]+I[a-1][b-1]<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ara[200005], freq[200005];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    scanf("%lld", &ara[i]), freq[ ara[i] ]++;
    ll sum= 0;
    for(int i=1; i<=n; i++)
    if(freq[i]>1)sum+= (freq[i]*(freq[i]-1))/2ll;
    for(int i=0; i<n; i++)
    {
        ll res= sum;
        if(freq[ ara[i] ]>1)
        {
            res-= (freq[ ara[i] ]*(freq[ ara[i] ]-1))/2ll;
            res+= ((freq[ ara[i] ]-1)*(freq[ ara[i] ]-2))/2ll;
        }
        printf("%lld\n", res);
    }
    return 0;
}


Measured memory_bytes: 4736
#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;}

vector<int>zalgorithm(string s){
    vector<int>a(s.size());
    a[0]=s.size();
    int i=1,j=0;
    while(i<s.size()){
        while(i+j<s.size()&&s[j]==s[i+j])j++;
        a[i]=j;
        if(j==0){i++;continue;}
        int k=1;
        while(i+k<s.size()&&k+a[k]<j)a[i+k]=a[k],k++;
        i+=k;j-=k;
    }
    return a;
}

string S;
int L;

map<int,int>calc(int a,int b){
    if(a+b>=L){
        map<int,int>ret;
        ret[L]++;
        return ret;
    }

    auto m=calc(a+b,a);
    map<int,int>ret;

    for(auto p:m){
        if(p.fi>a+b){
            ret[a+b]+=p.se;
            ret[p.fi-a-b]+=p.se;
        }
        else{
            ret[p.fi]+=p.se;
        }
    }
    return ret;
}

vint solve(){
    vint z=zalgorithm(S);

    int b=0;
    for(int i=S.size()-1;i>0;i--){
        if(z[i]==S.size()-i)b=S.size()-i;
    }

    int a=S.size()-b;

    auto m=calc(a,b);
    vint ret(26);
    for(auto p:m){
        rep(i,p.fi)ret[S[i]-'a']+=p.se;
    }
    return ret;
}

signed main(){
    cin>>S;
    S=S.substr(0,S.size()/2);
    int l,r;
    cin>>l>>r;
    l--;

    L=r;
    vint y=solve();

    L=l;
    vint x=solve();
    rep(i,26){
        if(i)cout<<" ";
        cout<<y[i]-x[i];
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 1216
#include <cstdio>
using namespace std;
int w, n, a[31], f, s, t;
int main() {
  for (int i = 0; i < 31; i++) {
    a[i] = i;
  }
  scanf("%d%d", &w, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d,%d", &f, &s);
    t = a[f];
    a[f] = a[s];
    a[s] = t;
  }
  for (int i = 1; i <= w; i++) {
    printf("%d\n", a[i]);
  }
}


Measured memory_bytes: 2576
#include <bits/stdc++.h>
#define  ren(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) ren(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    int n;
    cin>>n;
    cout<<n*800-(n/15)*200<<endl;

    return 0;
}


Measured memory_bytes: 256
require 'matrix'
cs = 3.times.map{gets.chomp.split.map(&:to_i)}
d1 = [[0,0],[1,1],[2,2]].map{|i,j| cs[i][j]}.inject(:+)
d2 = [[0,2],[1,1],[2,0]].map{|i,j| cs[i][j]}.inject(:+)
d3 = [[0,1],[1,2],[2,0]].map{|i,j| cs[i][j]}.inject(:+)
d4 = [[0,2],[1,0],[2,1]].map{|i,j| cs[i][j]}.inject(:+)
if [d1,d2,d3,d4].uniq.size == 1
	puts "Yes"
else
	puts "No"
end

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct ANT
{
  int st;
  int en;
  int go;
};

struct CRASH
{
    int no0;
    int no1;
    int t;
};


int main(){
    int n,l,t;
    cin>>n>>l>>t;
    vector<ANT> ant(n);
    vector<int> enpos(n);
    int x,w;
    int cnt=0;
    rep(i,n){
        cin>>x>>w;
        int go=w==1? go=1 : go=-1;
        int st=x;
        int en=(x+t*go);
        while(en<0){
            en+=l;
            cnt--;
        }
        while(en>l){
            en-=l;
            cnt++;
        }
        ant[i]={st,en,go};
        enpos[i]=en;
    }
    sort(enpos.begin(),enpos.end());
    cnt=(cnt%n+n)%n;
    rotate(enpos.begin(),enpos.begin()+cnt,enpos.end());
    rep(i,n) cout<<enpos[i]<<endl;
    /*
    vector<CRASH> cr;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(ant[i].go*ant[j].go>0) continue;
            int tim;
            if(ant[i].go>0){
                tim=(ant[j].st-ant[i].st)/2;
                if(tim<0) tim+=l/2;
            }
            else{
                tim=(ant[i].st-ant[j].st)/2;
                if(tim<0) tim+=l/2;
            }
            while(tim<=t){
                CRASH c={i,j,tim};
                cr.push_back(c);
                tim+=l;
            }
        }
    }
    sort(cr.begin(),cr.end(),[](CRASH a, CRASH b){return a.t<b.t;});
    vector<int> box(n);
    rep(i,n){
        cout<<ant[box[i]].en<<endl;
    }
    */
    return 0;
}


Measured memory_bytes: 4780
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

//?????° <S,o,+>
/*
????????????????????????
a o (b + c) = a o b + a o c
*/
using Value = long long int;
const Value INI = 0;
class starry_sky_tree {
public:
	int sz;
	vector<Value>data, lazy;
	starry_sky_tree(const int sz_) :sz(sz_), data(2 * sz_,INI), lazy(2 * sz_,INI) {

	}
	Value multiply(int a,int b,Value l,Value r) {
		return (b - a)*r + l ;
	}
	Value add(Value l,Value r) {
		return l + r;
	}
	void update(int l, int r, int node, int a, int b, Value val) {
		if (b <= l || r <= a)return;
		else if (l <= a&&b <= r) {
			lazy[node]=add(lazy[node],val); 
			return; 
		}
		int left = node * 2, right = left + 1;
		update(l, r, left, a, (a + b) / 2, val);
		update(l, r, right, (a + b) / 2,b, val);
		data[node] = add(
			multiply(a,(a+b)/2,data[left], lazy[left]), 
			multiply((a+b)/2, b, data[right] , lazy[right]));
	}
	void update(int l, int r, Value val) {
		update(l, r, 1, 0, sz, val);
	}
	Value query(int l, int r, int node, int a, int b) {
		if (b <= l || r <= a)return INI;
		else if (l <= a&&b <= r)return multiply(a,b,data[node],lazy[node]);
		Value vl = query(l, r, node * 2 + 0, a, (a + b) / 2);
		Value vr = query(l, r, node * 2 + 1, (a + b) / 2, b);
		return multiply(max(l,a),min(r,b),add(vl, vr),lazy[node]);
	}
	Value query(int l, int r) {
		return query(l, r, 1, 0, sz);
	}
};

int main() {
	int N, Q; cin >> N >> Q;
	starry_sky_tree tree(1 << 18);
	while (Q--) {
		int a; cin >> a;
		if (a) {
			int s, t; cin >> s >> t;
			s--; t--;
			Value ans = tree.query(s, t + 1);
			cout << ans << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			s--; t--;
			tree.update(s, t + 1, x);
		}
	}
	return 0;
}

Measured memory_bytes: 11036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
const ll mod = 1e9+7;

int main() {
    ll n, m;
    cin >> n >> m;
    if(abs(n-m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i = 2; i <= n; ++i) {
        ans*=i%mod;
        ans%=mod;
    }

    for(ll i = 2; i <= m; ++i) {
        ans*=i%mod;
        ans%=mod;
    }
    if(abs(n-m)==0) ans*=2;
    ans%=mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef unsigned long long ULL;
 
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define f first
#define s second
#define FILL(a, b) memset(a, b, sizeof(a))
 
const int MAX = 400*1000+5;
const int INF = 1000*1000*1000 + 7;
const LL LINF = 1LL*INF*INF;
const int MOD = INF;
const double PI = acos(-1.);
const int MAXN = 3*100007;
 
mt19937 rnd(time(0));

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	VI a(n), b(n);
	LL sum = 0;
	FOR(i, 0, n)
	{
		cin >> a[i] >> b[i];
		sum += a[i];
	}
	LL tianka = 0;
	FOR(i, 0, n)
	{
		if (a[i] > b[i])
		{
			tianka = max(tianka, sum - b[i]);
		}	
	}
	cout << tianka;

	return 0;	
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[][] ans = new int[n][2];

            for (int i = 0; i < n; i++) {
                int cnt = 0;
                int tmp = i + 1;
                while (tmp >= 1) {
                    if (tmp % 2 == 0) {
                        cnt++;
                        tmp /= 2;
                    } else {
                        break;
                    }
                }
                ans[i][0] = i + 1;
                ans[i][1] = cnt;
            }

            Arrays.sort(ans, (x, y) -> Integer.compare(x[1], y[1]));
            // 出力
            out.println(ans[n - 1][0]);

        }

    }
}



Measured memory_bytes: 28628
/*input
5
3 5 7
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <functional>
#include <cmath>
#include <cstring>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <cstdlib>
#include <list>
#include <cassert>
#include <ctime>
#include <fstream>
#include <sstream>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define N 100005
// const int INF = 1e18;

int n;
int a[N];
int odd, even;
bool all1 = true;

void done(int x, int y) {
	int t = (x + y) % 2;
	if (t == 0) cout << "Second" << endl;
	else cout << "First" << endl;
	exit(0);
}

void prep() {
	odd = 0; even = 0; all1 = true;
	for (int i = 1; i <= n; i++) {
		if (a[i] > 1) all1 = false;
		if (a[i] % 2 == 0) even++;
		else odd++;
	}
}

void process(int x) {
	odd = 0; even = 0; all1 = true;
	int gcd = -1;
	for (int i = 1; i <= n; i++) {
		if (a[i] == 1) {
			if ((n - 1) % 2 == 1) done(1, x);
			else done(2, x);
		}
		else if (a[i] % 2 == 1) a[i]--;
		if (gcd == -1) gcd = a[i];
		else gcd = __gcd(a[i], gcd);
	}
	for (int i = 1; i <= n; i++) {
		a[i] /= gcd; if (a[i] > 1) all1 = false;
		if (a[i] % 2 == 0) even++;
		else odd++;
	}
}

void check(int x) {
	if (all1) done(2, x);
	if (even == 0) done(1, x);
	if (even % 2) done(1, x);
	if (odd >= 2) done(2, x);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	prep();
	int turn = 1;
	while (1) {
		turn++;
		check(turn);
		process(turn);
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll s[9];
int main(){
  ll n;
  cin >>n;
  ll a[n];
  for(ll i=0;i<n;i++) {
    cin >>a[i];
    if(1<=a[i]&&399>=a[i]) s[0]++;
    else if(400<=a[i]&&799>=a[i]) s[1]++;
    else if(800<=a[i]&&1199>=a[i]) s[2]++;
    else if(1200<=a[i]&&1599>=a[i]) s[3]++;
    else if(1600<=a[i]&&1999>=a[i]) s[4]++;
    else if(2000<=a[i]&&2399>=a[i]) s[5]++;
    else if(2400<=a[i]&&2799>=a[i]) s[6]++;
    else if(2800<=a[i]&&3199>=a[i]) s[7]++;
    else if(3200<=a[i]) s[8]++;
  }
  ll ans=0;
  for(ll i=0;i<8;i++) if(s[i]!=0) ans++;
  if(s[8]==0) cout<<ans<<" "<<ans<<endl;
  else {
    if(ans==0) cout <<1<<" "<<s[8]<<endl;
    else cout <<ans<<" "<<ans+s[8]<<endl;
  }
}


Measured memory_bytes: 256
#c
n,m =map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
result = []
for i in ab:
    if h[i[0]-1] > h[i[1]-1]:
        result.append(i[1])
    elif h[i[1]-1] > h[i[0]-1]:
        result.append(i[0])
    else:
        result.append(i[0])
        result.append(i[1])
result = list(set(result))
print(n - len(result))

Measured memory_bytes: 39968
# include <iostream>
# include <cstdio>

using namespace std ;

int cnt[1000005] , tmp ;

long long n ;

int get( int x )
{
	int now = 0 ;
	for ( int i = 1 ;  ; i++ )
	{
		now += i ;
		if ( now > x ) return i - 1 ;
	}
}

int main()
{
	scanf("%lld" , &n) ;
	for ( int i = 2 ; 1ll * i * i <= n ; i++ )
	{
		if ( n % i == 0 )
		{
			tmp ++ ;
			int now = 0 ;
			while ( n % i == 0 ) 
			{
				now ++ ;
				n /= i ;
			}
			cnt[tmp] = now ;
		}
	}
	if ( n > 1 ) cnt[++ tmp] = 1 ;
	long long res = 0 ;
	for ( int i = 1 ; i <= tmp ; i++ )
	{
		// printf("fact:%d %d\n" , cnt[i] , get( cnt[i] )) ;
		res = res + get( cnt[i] ) ;
	}
	printf("%lld\n" , res) ;
	return 0 ;
}

Measured memory_bytes: 3828
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    26
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
#define INF         1000000005

typedef long long LL;
// }}}

int n;
string s;
pair<LL, LL> sum[15][15];

// [l, r)
pair<LL, LL> solve(int l, int r){
    if(sum[l][r] != pair<LL, LL>{-1, -1}){
        return sum[l][r];
    }
    pair<LL, LL> ret = {stoll(s.substr(l, r-l)), 1};
    for(int i=1;i<r-l;i++){
        auto a = solve(l+i, r);
        ret.first += stoll(s.substr(l, i))*a.second + a.first;
        ret.second += a.second;
    }
    //cout << l << " " << r << " " << ret << endl;
    return sum[l][r] = ret;
}

int main() {
    cin >> s;
    n = s.size();
    for(int i=0;i<n;i++){
        for(int j=0;j<n+1;j++){
            sum[i][j] = {-1, -1};
        }
    }
    printf("%lld\n", solve(0, n).first);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

//?§??????°??????????????°?????¶????????????????????°
int n,m,h,k;

//???????§???????????§????1day???????????°
int s,t,p;

typedef pair<int,int> P;
typedef pair<P,int> PP;
struct edge{
	int to,cost,time,corp;
	
	edge(int to_,int cost_,int time_,int corp_){
		to=to_; cost=cost_; time=time_; corp=corp_;
	}
	
};
vector<edge> G[100];

const int BIT=1<<8;

// i????????????????????????????????????
int pass_corps[BIT];

// pass_cost[bit] bit?????¨?????????????????????????????????
int pass_cost[BIT];

//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
int corps_cost[BIT];

const int INF=1e8;

int solve(int use){
	
	// d[time][pos]
	int d[25][BIT];
	for(int i=0;i<25;i++){
		for(int j=0;j<BIT;j++) d[i][j]=INF;
	}
	
	d[0][s]=corps_cost[use];
	priority_queue<PP,vector<PP>,greater<PP> > q;
	
	// cost,time,pos
	q.push(PP(P(corps_cost[use],0),s));
	while(!q.empty()){
		
		PP pp=q.top(); q.pop();
		
		int cost=pp.first.first,time=pp.first.second,pos=pp.second;
		
		//printf("cost %d, time %d, pos %d\n",cost,time,pos);
		
		if(pos==t) return cost;
		
		if(d[time][pos]<cost) continue;
		
		for(int i=0;i<G[pos].size();i++){
			edge e=G[pos][i];
			int to=e.to,ncost=cost+e.cost,nt=time+e.time,ncorp=e.corp;
			
			//printf("to %d, ncost %d, nt %d ncorp %d\n",to,ncost,nt,ncorp);
			
			if(nt>h) continue;
			
			if(use&(1<<ncorp)) ncost=cost;
			if(ncost<d[nt][to]){
				d[nt][to]=ncost;
				q.push(PP(P(ncost,nt),to));
			}
			
		}
		
	}
	
	return INF;
	
}

int main(){
	
	while(scanf("%d %d %d %d",&n,&m,&h,&k),n){
		
		for(int i=0;i<100;i++) G[i].clear();
		for(int i=0;i<BIT;i++){
			pass_corps[i]=0;
			pass_cost[i]=corps_cost[i]=INF;
		}
		for(int i=0;i<m;i++){
			int a,b,c,h,r;
			scanf("%d %d %d %d %d",&a,&b,&c,&h,&r);
			a--; b--; r--;
			
			G[a].push_back(edge(b,c,h,r));
			G[b].push_back(edge(a,c,h,r));
		}
		
		scanf("%d %d %d",&s,&t,&p);
		s--; t--;
		
		for(int i=0;i<p;i++){
			int l,d,corp;
			scanf("%d %d",&l,&d);
			
			int corps=0;
			for(int j=0;j<l;j++){
				scanf("%d",&corp);
				corp--;
				corps|=(1<<corp);
			}
			
			pass_corps[i]=corps;
			pass_cost[corps]=d;
		}
				
		//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
		corps_cost[0]=0;
		for(int i=0;i<(1<<k);i++){
			if(corps_cost[i]==INF) continue;
			for(int j=0;j<p;j++){
				corps_cost[i|pass_corps[j]]=min(corps_cost[i|pass_corps[j]],corps_cost[i]+pass_cost[pass_corps[j]]);
			}
		}
		
		int res=INF;
		for(int use=0;use<(1<<k);use++){
			if(corps_cost[use]==INF) continue;
			res=min(res,solve(use));
		}
		if(res==INF) res=-1;
		cout<<res<<endl;	
	}
}

Measured memory_bytes: 3344
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/14/20 20:57:13
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  map<int,int> ps;
  for (int k = 2; k <= n; k++) {
    int kk = k;
    int t = sqrt(kk);
    for (int m = 2; m <= t and kk > 1; m++) {
      int cnt = 0;
      while (kk > 1 and kk%m==0) {
        kk/=m;
        cnt++;
      }
      if (cnt)
        ps[m] += cnt;
    }
    if (kk > 1)
      ps[kk]++;
  }
  int cs[5] = {};
  for (auto [m, c] : ps) {
    if (c >= 74)
      cs[4]++;
    if (c >= 24)
      cs[3]++;
    if (c >= 14)
      cs[2]++;
    if (c >= 4)
      cs[1]++;
    if (c >= 2)
      cs[0]++;
  }
  ll ans = 0;
  // 75
  ans += cs[4];
  // 3*25
  ans += (cs[0] and cs[3] ? (cs[0]-cs[3])*cs[3] : 0) + (cs[3]>=2 ? cs[3]*(cs[3]-1) : 0);
  // 5*15
  ans += (cs[1] and cs[2] ? (cs[1]-cs[2])*cs[2] : 0) + (cs[2]>=2 ? cs[2]*(cs[2]-1) : 0);
  // 3*5*5
  ans += (cs[0] and cs[1]>=2 ? (cs[0]-cs[1])*(cs[1]*(cs[1]-1)/2) : 0) +
      (cs[1]>=3 ? cs[1]*(cs[1]-1)*(cs[1]-2)/2 : 0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define ll long long 
vector<int> ve[100005];
vector<pair<int,int> > enem;
int vis[100005],cnt=1,ans[100005],sub_gr_si[100005],degree[100005];

void find_conn(int x) {
	vis[x] = cnt;
	sub_gr_si[cnt]+=1;
	for(int i=0;i<ve[x].size();i++)
		if(!vis[ve[x][i]])
			find_conn(ve[x][i]);
}

int main() {
	int i,j,k,l,n,m,n1,n2;
	cin>>n>>m>>k;
	for(i=0;i<m;i++) {
		cin>>n1>>n2;
		degree[n1]++;
		degree[n2]++;
		ve[n1].pb(n2);
		ve[n2].pb(n1);
	}
	for(i=0;i<k;i++) {
		cin>>n1>>n2;
		enem.pb(mp(n1,n2));
	}
	for(i=1;i<=n;i++)
		if(!vis[i]) {
			find_conn(i);
			cnt+=1;
		}
	for(i=1;i<=n;i++) {
		ans[i] = sub_gr_si[vis[i]]-1;
		ans[i] -= degree[i];
	}
	for(i=0;i<k;i++)
		if(vis[enem[i].f] == vis[enem[i].s]) {
			ans[enem[i].f]-=1;
			ans[enem[i].s]-=1;
		}
	for(i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define F           first
#define S           second
#define ld          long double
#define rep(i,a,b)  for(ll i=a;i<b;i++)

const int N = 55, M = 110;
ll n, t, a[N], dp[N][N][M];

ll recur(ll l, ll r, ll k)
{
    if(k<=0) return 0;
    if(l==r) return a[l];
    ll &ans=dp[l][r][k];
    if(ans != -1) return ans;
    ll op1 = recur(l+1, r, k-1) + a[l];
    ll op2 = recur(l, r-1, k-1) + a[r];
    ll op3 = recur(l+1, r, k-2);
    ll op4 = recur(l, r-1, k-2);
    ll op5 = 0;
    ans = max(op1, op2);
    ans = max(ans, op3);
    ans = max(ans, op4);
    ans = max(ans, op5);
    return ans;
    
}
 
void solve()
{
    cin>>n>>t;
    memset(dp, -1, sizeof dp);
    rep(i, 1, n+1) cin>>a[i];
    ll ans=recur(1, n, t);
    cout<<ans<<endl;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}

Measured memory_bytes: 2816
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

public class Program{
    public static void Main(){
        TextReader reader;
        string filename = "";
        if(filename.Count()==0) reader = Console.In;
        else reader = new StreamReader(filename);
        var input = reader.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];
        var Products_Weights = new int[N];
        var Products_Values = new int[N];
        var dp = new int[N+1, M+1];
        // dp[i, j]: i???????????§??????????????\???????????????j???????????¨???????????§?????????
        for(int i=0; i<N+1; i++) dp[i, 0] = 0;
        for(int j=0; j<M+1; j++) dp[0, j] = 0;
        //???????????????????????????
        for(int i=0; i<N; i++){
            var info = reader.ReadLine().Split().Select(int.Parse).ToArray();
            Products_Values[i] = info[0];
            Products_Weights[i] = info[1];
        }

        //?????????????????????dp??????????????????????????????
        /*
        dp[i, j] = i????????????????????\?????????, i????????????????????\??????
        ??? dp[i-1, j], dp[i-1, j-Weights[i]]+Values[i]
        */
        for(int i=1; i<dp.GetLength(0); i++){
            for(int j=1; j<dp.GetLength(1); j++){
                //?????§??????M????¶?????????????????????????
                //????????§???j???????????§??????j?????§??\?????????????????§i???????????????????????????j????????§????????¨??????????????\???????????¨?????§?????????
                if(j>=Products_Weights[i-1]){
                    dp[i, j] = Math.Max(dp[i-1, j], dp[i-1, j-Products_Weights[i-1]]+Products_Values[i-1]);
                }else{
                    dp[i, j] = dp[i-1, j];
                }
            }
        }
        Console.WriteLine(dp[N, M]);
    }
}

Measured memory_bytes: 13596
#include<bits/stdc++.h>
#define LL long long
#define endl '\n'
using namespace std;
const LL MOD = 1e9+7;
const LL INF = 1e9+7;


int main(){

	int n;
	cin>>n;
	set<int> a;
	while(n--){
		int x;
		cin>>x;
		a.insert(x);
	}
	cout<<a.size()<<endl;
	return 0;
	
}


Measured memory_bytes: 256
N,Q = gets.split.map(&:to_i)
STX = N.times.map{
	s,t,x = gets.split.map(&:to_i)
	next s-x,t-x,x
}
D = Q.times.map{ gets.to_i }

min,xts = [],STX.map{|s,t,x|
	next x,
		D.bsearch_index{|d| t<=d }||Q,
		D.bsearch_index{|d| s<=d }||Q
}.sort_by{|_,_,s| s }

puts Q.times.map{|d|
	while ! xts.empty? && xts[0][2] <= d
		x,t  = xts.shift
		i = min.bsearch_index{|xm,| x<xm }||min.size
		j = min.bsearch_index{|_,tm| t<tm }||min.size
		min[i...j] = i<=j ? [[x,t]] : []
	end
	min.shift(min.index{|_,tm| d<tm }||min.size)
	next min.empty? ? -1 : min[0][0]
}


Measured memory_bytes: 51960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

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

int main() {
    int a; cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

#define MOD 1000000007

ll d[1100][1100];
ll dd[1100][1100];

ll h,w;

int main(){
  cin>>h>>w;
  vector<string> vs;
  rep(y,0,h){
    string s;
    cin>>s;
    vs.pb(s);
  }
  queue<ll> qy;
  queue<ll> qx;
  queue<ll> qc;
  clr(dd,0);
  rep(y,0,h){
    rep(x,0,w){
      if(vs[y][x]=='#'){
        d[y][x] = 1;
        qy.push(y);
        qx.push(x);
        qc.push(0);
      }
      else{
        d[y][x] = 0;
      }
    }
  }
  ll mx = 0;
  ll dy[4] = {-1,0,0,1};
  ll dx[4] = {0,-1,1,0};
  while(!qy.empty()){
    ll y1 = qy.front();qy.pop();
    ll x1 = qx.front();qx.pop();
    ll c1 = qc.front();qc.pop();
    dd[y1][x1] = c1;
    mx = max(mx,c1);
    rep(i,0,4){
      ll y2 = y1 + dy[i];
      ll x2 = x1 + dx[i];
      if(y2<0)continue;
      if(y2>=h)continue;
      if(x2<0)continue;
      if(x2>=w)continue;
      if(d[y2][x2]==1)continue;
      d[y2][x2] = 1;
      qy.push(y2);
      qx.push(x2);
      qc.push(c1+1);
    }
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 44336
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
long long sum(int l,int r,vector<int>v)
{
  long long s=0;
  for(int i=l;i<=r;i++)
  {
    s+=(long long)v[i];
  }
  return s;
}
int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  for(auto &e:v)
    cin>>e;
  vector<vector<long long> >dp(n,vector<long long>(n,0));
  for(int l=n-1;l>=0;l--)
  {
    for(int r=l;r<n;r++)
    {
      dp[l][r]=1e18L +5;
      if(l==r)
        dp[l][r]=0;
      else
      { long long s=sum(l,r,v);
        for(int i=l;i<r;i++)
        dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+s);
      }
     }
   }
   cout<<dp[0][n-1];                  
  return 0; 
}

Measured memory_bytes: 4872
N = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        s = l[i]+l[j]
        start = j+1
        end = N
        while start != end:
            center = (start + end)//2
            if s <= l[center]:
                end = center
            else:
                start = center + 1
        ans += end-j-1
print(ans)


Measured memory_bytes: 73216
#a_1+a_2+...+a_N = M   Find greatest common divisor of a
N,M=map(int,input().split())

Q=M//N #Quotient
R=M%N  #Reminder
'''
if Q>R :
    k=int((Q-R)//(1+N))
    k-=1
    Q -= k
    R += k*N
    '''
memo=0
while R%Q != 0:
    k= int((Q-R%Q)//(N+R//Q+1))   #max k:k*(N+R//Q)<Q-k
    #print(R,Q,R%Q,R//Q,k)
    while (R+k*N)//(Q-k) > memo:
        k -= 1
        #print(k,memo,(R+k*N)//(Q-k))
    if k > 0:
        Q -= k
        R += k*N
        memo=R//Q
    else:
        Q -= 1
        R += N
        memo=R//Q

print(Q)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i< n ;i++){
    cin >> a[i];
  }
  int m,l,o,p,ans;
  if(a[1] > a[0]){
    m = a[1];
    l = a[0];
  }else{
    m = a[0];
    l = a[1];
  }
  while(1){
      o = m % l;
      if(o == 0){
        p = l;
        break;
      }
      m = l;
      l = o;
    }
  for(i = 2;i < n; i++){
    if(a[i] > p){
      m = a[i];
      l = p;
    }else{
      m = p;
      l = a[i];
    }
    while(1){
      o = m % l;
      if(o == 0){
        p = l;
        break;
      }
      m = l;
      l = o;
    }
  }
  cout << p << endl;
  
}

Measured memory_bytes: 640
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let m: usize = sc.read();

    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a: usize = sc.read::<usize>() - 1;
        let b: usize = sc.read::<usize>() - 1;
        let c: i64 = sc.read();
        graph[a].push((b, -c));
    }

    let inf = std::i64::MAX;
    let mut dist = vec![inf; n];
    dist[0] = 0;
    for _ in 0..n {
        for v in 0..n {
            for e in &graph[v] {
                let (to, cost) = *e;
                if dist[v] == inf || dist[to] <= dist[v] + cost {
                    continue;
                }
                dist[to] = dist[v] + cost;
            }
        }
    }

    let mut negative = vec![false; n];
    for _ in 0..n {
        for v in 0..n {
            for e in &graph[v] {
                let (to, cost) = *e;
                if dist[v] == inf {
                    continue;
                }
                if dist[to] > dist[v] + cost {
                    dist[to] = dist[v] + cost;
                    negative[to] = true;
                }
                if negative[v] {
                    negative[to] = true;
                }
            }
        }
    }

    if negative[n - 1] {
        println!("inf");
    } else {
        println!("{}", -dist[n - 1]);
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 10050000000000000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 18
#define KOK 32000
using namespace std;

int n,tot;
int tut[N],f[N];
ll ans;
char s[N];
vector<int> pos[26],rpos[26];
vector<ii> v;

void up(int x) {

	for(int i=x;i<=n;i+=(i&-i)) f[i]++;

}

int get(int x) {

	int res=0;

	for(int i=x;i>=1;i-=(i&-i)) res+=f[i];

	return res;

}

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%s",s+1);

	n=strlen(s+1);

	int odd=0;

	for(int i=1;i<=n;i++) {

		pos[s[i]-'a'].pb(i);

		odd-=1-sz(pos[s[i]-'a'])%2;
		odd+=sz(pos[s[i]-'a'])%2;

	}

	if(odd>1) {

		printf("-1");

		return 0;

	}

	for(int i=0;i<26;i++) {

		for(int j=0;j<sz(pos[i])/2;j++) {

			v.pb({pos[i][j],i});

		}

	}

	sort(all(v));

	for(int i=0;i<sz(v);i++) {

		rpos[v[i].nd].pb(++tot);

	}

	if(n%2) {

		for(int i=0;i<26;i++) {

			if(sz(pos[i])&1) {

				rpos[i].pb(++tot);

			}

		}

	}

	for(int i=sz(v)-1;i>=0;i--) {

		rpos[v[i].nd].pb(++tot);

	}

	for(int i=0;i<26;i++) {

		for(int j=0;j<sz(pos[i]);j++) {

			tut[rpos[i][j]]=pos[i][j];

		}

	}

	for(int i=1;i<=n;i++) {

		int apos=i-1-get(tut[i]);

		ans+=abs(tut[i]+apos-i);		

		up(tut[i]);

	}

	printf("%lld",ans);

}

Measured memory_bytes: 5364
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Union_Find_Tree{
	public:
	vi Par,Rank,Size;
	Union_Find_Tree(int n){
		Par=Rank=vi(n);
		Size=vi(n,1);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	int Find_Size(int x){
		return Size[Find_Par(x)];
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		if(Rank[x]<Rank[y]){
			Par[x]=y;
			Size[y]+=Size[x];
		}
		else{
			Par[y]=x;
			Size[x]+=Size[y];
			if(Rank[x]==Rank[y]) Rank[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){
		return Find_Par(x)==Find_Par(y);
	}
};

int n,m;
vd x,y;

double L(int i,int j){
	double A=fabs(x[i]-x[j]),B=fabs(y[i]-y[j]);
	return sqrt(A*A+B*B);
}

int main(){
	cin>>n>>m;
	x=y=vd(n);
	vector<pair<double,P> > a(m);
	double res=0;
	for(int i=0;i<n;i++) cin>>x[i]>>y[i];
	for(int i=0;i<m;i++){
		int v,u;
		cin>>v>>u;
		v--;u--;
		double l=L(v,u);
		res+=l;
		a[i]={-l,{v,u}};
	}
	sort(a.begin(),a.end());
	Union_Find_Tree uft(n);
	for(int i=0;i<m;i++){
		P p=a[i].second;
		int v=p.first,u=p.second;
		if(!uft.Same(v,u)){
			uft.Unite(v,u);
			res+=a[i].first;
		}
	}
	cout<<syosu(5)<<res<<endl;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    while(sc.hasNext()) {
      final int n = sc.nextInt();

      if(n == 0) break;

      final Field field = new Field();

      for(int i = 0; i < n; i++) {
        field.setGem(sc.nextInt(), sc.nextInt());
      }

      final int m = sc.nextInt();

      int x = 10;
      int y = 10;

      int gems = 0;

      for(int i = 0; i < m; i++) {
        final String d = sc.next();
        final int l = sc.nextInt();

        if(d.equals("N")) {
          gems += field.takeGems_y(y, y + l, x);
          y += l;
        }
        else if(d.equals("E")) {
          gems += field.takeGems_x(x, x + l, y);
          x += l;
        }
        else if(d.equals("S")) {
          gems += field.takeGems_y(y, y - l, x);
          y -= l;
        }
        else if(d.equals("W")) {
          gems += field.takeGems_x(x, x - l, y);
          x -= l;
        }
      }

      if(gems == n) System.out.println("Yes");
      else System.out.println("No");
    }
  }

  private final Scanner sc = new Scanner(System.in);
}

class Field {
  public Field() {
    this.map = new boolean[21][21];
    for(int i = 0; i <= 20; i++) {
      for(int j = 0; j <= 20; j++) {
        map[i][j] = false;
      }
    }
  }

  public void setGem(int x, int y) {
    map[x][y] = true;
  }

  public int takeGems_x(int x1, int x2, int y) {
    int gems = 0;

    final int from = Math.min(x1, x2);
    final int to = Math.max(x1, x2);

    for(int i = from; i <= to; i++) {
      if(map[i][y]) {
        gems++;
        map[i][y] = false;
      }
    }

    return gems;
  }

  public int takeGems_y(int y1, int y2, int x) {
    int gems = 0;

    final int from = Math.min(y1, y2);
    final int to = Math.max(y1, y2);

    for(int i = from; i <= to; i++) {
      if(map[x][i]) {
        gems++;
        map[x][i] = false;
      }
    }

    return gems;
  }

  private boolean[][] map;
}

Measured memory_bytes: 12000
#include <iostream>
#include <stdio.h>
#include<string>
#include <cstdio>
#include <math.h>
#include <vector>
using namespace std;
int main(void){
    vector<std::string> day = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  	char s[6];
    scanf("%s", s);
   	for(int i = 0; i < day.size(); i++) {
    	if(s == day[i]){
            printf("%d",7-i);
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

using namespace std;
#define int long long

struct box {
    int w, s, v;

    bool operator<(const box &b) const {
        return w + s < b.w + b.s;
    }
};

istream &operator>>(istream &in, box &b) {
    in >> b.w >> b.s >> b.v;
    return in;
}

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

    int n;
    cin >> n;
    vector<box> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    int dp[200010];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    for (auto &b:a) {
        for (int i = b.s; i >= 0; --i) {
            if (~dp[i])dp[i + b.w] = max(dp[i + b.w], dp[i] + b.v);
        }
    }
    cout << *max_element(dp, dp + 200010) << endl;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()
#define x first
#define y second

const int inf = 2e9 + 100;
const int maxn = 2e5 + 100;

int a[maxn], ans[maxn], d[maxn];
vector<int> g[maxn];
int n;

void dfs(int v, int p = -1) {
    int j = upper_bound(d + 1, d + n, a[v]) - d;
    int f = 0;
    int was = 0;
    int id = -1;
    if (d[j - 1] < a[v] && a[v] < d[j]) {
        f = 1;
        was = d[j];
        id = j;
        d[j] = a[v];
        ans[v] = j;
    }
    ans[v] = max(ans[v], (p != -1 ? ans[p] : 1));
    for (auto u : g[v]) {
        if (u == p) {
            continue;
        }
        dfs(u, v);
    }
    if (f) {
        d[id] = was;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        d[i] = inf;
    }
    d[0] = -inf;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 33480