akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    string t; cin >> t;
    for (int i = 0; i < (int)t.size(); i++) {
        if (t[i] == '?') t[i] = 'D';
        /*if (i == 0 && t[i] == '?') {
            t[i] = 'D';
            continue;
        }
        if (t[i] == '?') {
            if (t[i - 1] == 'P') t[i] = 'D';
            else t[i] = 'P';
        }
        */
    }
    cout << t << endl;
}

Measured memory_bytes: 3748
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if (a-b)%2 == 0:
        print((a+b)//2)
    else:
        print("IMPOSSIBLE")
    return

#B
def B():
    n = I()
    p = LI()
    k = [p[i] for i in range(n)]
    k.sort()
    s = 0
    for i in range(n):
        s += (p[i] != k[i])
    if s < 3:
        print("YES")
    else:
        print("NO")
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


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

int main(){
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int wakeup_time = 0;

    if(M1 >= M2){
        H2 -= 1;
        wakeup_time += (M2 + 60) - M1;
    }else{
        wakeup_time += M2 - M1;
    }
    wakeup_time += (H2 - H1) * 60;

    if(wakeup_time >= K){
        cout << wakeup_time - K << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main(){

  int N,X,m,min = 1000000,cnt=0;

  cin >> N >> X;

  for(int i = 0; i < N; i++){
    cin >> m;
    X -= m;
    if(m < min){
      min = m;
    }
  }

  cnt = N + X / min;

  cout << cnt << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	ll i,j,n,m;
	string s; ll l=0;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
	l=1;
	if(l)printf("Yes\n");
	else printf("No\n"); 


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };
pair<int,int>p[200010];
signed main() {
	int n;
	cin>>n;
	rep(i,n){
		cin>>p[i].second>>p[i].first;
	}
	sort(p,p+n);
	int sum=0;
	rep(i,n){
		sum+=p[i].second;
		if(p[i].first<sum){cout<<"No"<<endl;return 0;}
	}
	cout<<"Yes"<<endl;	
}





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

int main(){
    string s;
    cin>>s;
    ll cnt = 0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='o')cnt++;
    }
    ll tmp = 0;
    if(15-s.length()>0){
        tmp = 15-s.length();
    }
    cnt+=tmp;
    if(cnt>=8){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

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

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

int* Vari() {
	int* a = new int;
	cin >> *a;
	return a;
}

void coutStr(string str) {
	cout << str << endl;
}
void coutInt(int i) {
	cout << i << endl;
}

void Main()
{
	int* n = Vari();
	bool ans = true;
	rep(i, *n) {
		int temp;
		cin >> temp;
		if (temp % 2 == 0 && !(temp % 3 == 0 || temp % 5 == 0)) {
			ans = false;
		}

	}

	if (ans) {
		coutStr("APPROVED");
	}
	else {
		coutStr("DENIED");
	}
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 256
H,W = input().split()
H,W = int(H),int(W)
nodes = [list(input()) for i in range(H)]


if H == 1 and W == 1 and nodes[0][0] == ".":
    print("No")
    quit()
if H == 1 and W == 1 and nodes[0][0] == "#":
    print("Yes")
    quit()


for i in range(H):
    for j in range(W):
        if nodes[i][j] == "#":
            flag = False
            if i - 1 >= 0:
                if nodes[i-1][j] == "#":
                    flag = True
            if i + 1 < H:
                if nodes[i+1][j] == "#":
                    flag = True
            if j - 1 >= 0:
                if nodes[i][j-1] == "#":
                    flag = True
            if j + 1 < W:
                if nodes[i][j+1] == "#":
                    flag = True

            if flag == False:
                print("No")
                quit()

print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

vector<ll> add(ll k){
    vector<ll>res;
    for(ll i=1;i*i<=k;i++){
        if(k%i==0){
            res.pb(i);res.pb(k/i);
        }
    }
    return res;
}

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    vector<ll>v,vv;
    v=add(a[0]);vv=add(a[1]);
    for(auto x:vv)v.pb(x);
    ll ans=0;
    for(auto x:v){
        ll count=0;
        rep(i,0,n-1){
            if(a[i]%x!=0){
                count++;
            }
        }
        if(count<=1)Max(ans,x);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
A = [int(s) for s in input().split(' ')]
B = [int(s2) for s2 in input().split(' ')]
C = [int(s3) for s3 in input().split(' ')]

satis = 0

for i in range(N-1):
    if A[i]+1 == A[i+1]:
        satis += C[A[i]-1]

satis += sum(B)

print(satis)

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
//#define int long long

signed main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
}

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

typedef long long LL;

int main(int argc, char** argv)
{
	int n;
	scanf("%d", &n);
	priority_queue<LL, vector<LL>, greater<LL> > q;
	q.push(9LL); q.push(5LL);
	q.push(3LL); q.push(7LL);
	q.push(2LL); q.push(4LL); q.push(6LL); q.push(8LL);
	q.push(1LL);
	while(true)
	{
		LL x = q.top(); q.pop();
		if(--n == 0)
		{
			printf("%lld\n", x);
			return 0;
		}
		int r = x % 10LL;
		LL t = x * 10LL + r;
		q.push(t);
		if(r > 0) q.push(t - 1);
		if(r < 9) q.push(t + 1);
	}
	return 0;
}

Measured memory_bytes: 2420
N = gets.to_i
A = gets.split(" ").map(&:to_i)
def insertionSort(a, n)
  for i in (0..(n-1))
    v = a[i]
    j =	i - 1
    while j >= 0 && a[j] > v
      a[j+1] = a[j]
      j	-= 1
    end
    a[j+1] = v
    puts a.join(" ")
  end
end

insertionSort(A, N)



Measured memory_bytes: 8916
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

VI cnt(100001, 0);

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int v = 0;
  REP(i, N)
  {
    int A;
    cin >> A;
    if (cnt[A] == 0) v++;
    cnt[A]++;
  }
  int check = 0;
  REPx(x, cnt) if (x > 1) check += x-1;
  if (check % 2) cout << v-1 << endl;
  else cout << v << endl;

  return 0;
}


Measured memory_bytes: 640
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()

Ws=[]
for i in range(N):
    a,b=LI()
    Ws.append((a,b))
Ws.sort()

cur = 0
HQ=[]
res = 0

for rest in range(1,M+1):
    while cur < N and Ws[cur][0] <= rest:
        heapq.heappush(HQ, -Ws[cur][1])
        cur += 1

    if HQ:
        nagated_gain = heapq.heappop(HQ)
        # print("debug: {} {}".format(rest, -nagated_gain))
        res -= nagated_gain

print(res)


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

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
#define PI 3.14159265358979323846
const long long mod = 1000000007;

int main(){
    //    random_device rnd;
    //    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    DOUBLECHANGE(10);
    int N;
    cin >> N;
    vector<pair<int,int>> pos (N,make_pair(0,0));
    for(int i = 0;i < N;i++){
        cin >> pos[i].first >> pos[i].second;
    }

    double ans = 0;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
//            cout << i << " and " << j << endl;
            ans += (N-1)*2 * sqrt(pow(abs(pos[i].first-pos[j].first),2)+pow(abs(pos[i].second-pos[j].second),2));
//            cout << "ans = " << (N-1)*2 * sqrt(pow(abs(pos[i].first-pos[j].first),2)+pow(abs(pos[i].second-pos[j].second),2)) << endl;
        }
    }
//    cout << "total = " << ans << endl;
    cout << ans/(N*(N-1))/2 << endl;
}


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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s;
	int n; cin >> n >> s;
	if(n%2){
		cout << "No\n";
		return 0;
	}
	for (int i = 0; i < n/2; ++i){
		if(s[i] != s[i+n/2]){
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  sort(an.begin(),an.end());
  double ans = an[0];
  for(int i=1; i<n; ++i){
    ans = (ans + an[i]) /2;
  }
  printf("%.10f\n",ans);
}

Measured memory_bytes: 3756
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    ll N;
    cin >> N;
    
    ll a = 1, b;
    for (ll i = sqrt(N); i >= 1; i--) {
        if (N % i == 0) {
            a = i;
            break;
        }
    }
    b = N / a;
    
    ll ans = a + b - 2;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll>> pqls;
priority_queue <P,vector<P>,greater<P>> pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,d,e,f,g,h,w;
 
ll x[800005],y[800005],z[900005];
char s[500005];

int main(){
    cin>>n;
	m=n;
	vector <ll> d;
	while(n!=0){
		if(n%2==0){
			a = n/2;
			a *= -1;
			b=0;
		}else{
			b=1;
			n--;
			a = n/2;
			a *= -1;
		}		
		d.pb(b);
		n = a;
	}
	if(m==0){
		p(0);
		return 0;
	}
	for(i=d.size()-1;i>=0;i--){
		cout<<d[i];
	}
	el;
	return 0;
}

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

int main()
{
	long int n;cin>>n;
	long int a[n];
	long int a1=1;
	long int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		sum++;
		a1=a[a1-1];
		if(a1==2) break;
	}
	if(a1==2) cout<<sum<<endl;
	else cout<<-1<<endl; 
} 

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

void solve()
{
	string N;
	cin >> N;
	string N_reverse = N;
	reverse(N_reverse.begin(), N_reverse.end());
	if (N == N_reverse)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,cnt,i;
	char s[100001];
	scanf("%d",&n);
	scanf("%s",s);
	cnt=0;
	i=0;
	while(i<=n-1){
		if(s[i]=='O'&&s[i+1]=='X'||s[i]=='X'&&s[i+1]=='O'){
			cnt++;
			i++;
		}
		i++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int ans = 0;
    int N,K;
    cin>>N>>K;

    for(int i = 0;i < N;i++) {
        int a;
        cin>>a;
        if(a >= K)
            ans++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    ll sum = 0LL;
    vll a(n); for(auto& e : a) cin >> e, sum += e;

    ll res = inf;
    ll cur = 0LL;
    rep(i, n - 1){
        cur += a[i];
        sum -= a[i];
        chmin(res, abs(sum - cur));
    }

    cout << res << endl;

    return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;
    cin>>N;
    vector<int> v(N);
    cin>>v;
    for(auto &it:v)it--;
    int cnt=0;
    REP(i,N-1){
        if(v[i]==i){
            swap(v[i],v[i+1]);
            cnt++;
        }
    }
    {
        int i=N-2;
        if(v[i+1]==i+1){
            swap(v[i],v[i+1]);
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int count = 1;
        
        String tmp = String.valueOf(str.charAt(0));
        for (int i = 1; i < str.length(); i++) {
            String chr = String.valueOf(str.charAt(i));
            if (tmp.equals(chr)) {
                if (i == str.length() - 1) {
                    break;
                }
                tmp = chr + String.valueOf(str.charAt(i + 1));
                count++;
                i++;
            } else {
                tmp = chr;
                count++;
            }
        }
        
        System.out.println(count);
    }
}


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

# define C continue;
# define R return;

# define D double
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()

# define pii pair < int , int >
# define vpii vector < pii >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(-1,1);
const D tpie = 2*pie;

void solve( int test_case )
{

    int n,k;
    cin>>n>>k;

    string s;
    cin>>s;

    s[k-1] = char((int)s[k-1]  + 32);
    cout<<s;
}

int main()
{
    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

struct Demand
{
    public int a;
    public int b;

    public Demand(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
}

class Program
{
    static void Main(string[] args)
    {
        var nmstr = Console.ReadLine().Split(' ');
        var n = int.Parse(nmstr[0]);
        var m = int.Parse(nmstr[1]);

        var demand = new Demand[m];
        for (int i = 0; i < m; i++)
        {
            var abstr = Console.ReadLine().Split(' ');
            var a = int.Parse(abstr[0]);
            var b = int.Parse(abstr[1]);
            demand[i] = new Demand(a, b);
        }
        demand = demand.OrderBy(a => a.a).ThenBy(a => a.b).ToArray();

        var ans = 1;
        var minb = demand[0].b;
        for (int i = 1; i < m; i++)
        {
            if (demand[i].a != demand[i - 1].a)
            {
                if (demand[i].a >= minb)
                {
                    ans++;
                    minb = demand[i].b;
                }
            }

            minb = Math.Min(minb, demand[i].b);
        }
        
        Console.WriteLine("{0}", ans);
    }
}


Measured memory_bytes: 22728
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
    ll h,w,a=0;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << "1" << endl;
        return 0;
    }
    if(h%2 == 0){
        h = (h/2)*w;
        a = h;
    }else{
        h = h/2+1;
        rep(i,w){
           if(i%2 == 0){
               a += h;
           }else{
               a += (h-1);
           } 
        }  
    }
    cout << a << endl;
    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int md = (int) 1e9 + 7;

inline void add(int& a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline void sub(int& a, int b) {
  a -= b;
  if (a < 0) {
    a += md;
  }
}

inline int mul(int a, int b) {
  return (int) ((ll) a * b % md);
}

inline int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  return power(a, md - 2);
}

vector<int> fact(1, 1);
vector<int> inv_fact(1, 1);

int C(int n, int k) {
  if (k < 0 || k > n) {
    return 0;
  }
  while ((int) fact.size() < n + 1) {
    fact.push_back(mul(fact.back(), (int) fact.size()));
    inv_fact.push_back(inv(fact.back()));
  }
  return mul(fact[n], mul(inv_fact[k], inv_fact[n - k]));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  while ((int) fact.size() < m + 1) {
    fact.push_back(mul(fact.back(), (int) fact.size()));
    inv_fact.push_back(inv(fact.back()));
  }
  int ans = mul(C(m, n), fact[n]);
  int s = 0;
  for (int i = 0; i <= n; i++) {
    if (i % 2 == 0) {
      add(s, mul(C(n, i), mul(C(m - i, n - i), fact[n - i])));
    } else {
      sub(s, mul(C(n, i), mul(C(m - i, n - i), fact[n - i])));
    }
  }
  ans = mul(ans, s);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7380
import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
 u=q.get()
 for v in M[u]:
  v=int(v)-1
  if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])


Measured memory_bytes: 7008
#!/usr/bin/perl

use Data::Dumper;

my ($n,$h) = map {$_ - 0} split(/\s+/o,<STDIN>);


my $max_a = -1;
my $min_a = 1000000010;
my $max_b = -1;
my $min_b = 1000000010;

my @ab = ();
for(my $i=0;$i<$n;$i++){
  my ($aa,$bb) = map {$_ - 0} split(/\s+/o,<STDIN>);
  push(@ab,+[$aa,$bb,$i]);
}

my @ab_a = sort { $b->[0] <=> $a->[0] } @ab;
my @ab_b = sort { $b->[1] <=> $a->[1] } @ab;

my @upper_b = sort { $b->[1] <=> $a->[1] } grep { $_->[1] > $ab_a[0]->[0] } @ab;

my $dmg = 0;
my $count = 0;
for(my $i=0;$i<=$#upper_b;$i++){
  $dmg += $upper_b[$i]->[1];
  $count ++;
  if( $dmg>=$h ){
    print "$count\n";
    exit(0);
  }
}


my $a_count ;
my $chk = ( $h - $dmg ) % $ab_a[0]->[0];
if( $chk == 0 ){
  $a_count = int(( $h - $dmg ) / $ab_a[0]->[0]);
} else {
  $a_count = 1+int(( $h - $dmg ) / $ab_a[0]->[0]);
}

my $res = $count + $a_count;

print "$res\n";

exit(0);


Measured memory_bytes: 31856
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	sum := totalEachDigit(n)

	if n%sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func totalEachDigit(num int) int {
	total := 0
	for num > 0 {
		total += num % 10
		num /= 10
	}
	return total
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

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

    bool flag = true;
    for (int i = 0; i < static_cast<int>(s.size()); i++) {
        if (!(((i + 1) % 2 != 0 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D'))
                || ((i + 1) % 2 == 0 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')))) {
            flag = false;
        }
    }

    cout << (flag ? "Yes" : "No") << endl;
}


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

using namespace std;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for (int i = 0; i < M; ++i) {
    cin >> A[i];
  }
  int pos = lower_bound(A.begin(), A.end(), X) - A.begin();
  cout << min(M - pos, pos) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

int gcd(int x,int y){
    if(x % y == 0){
        return y;
    }
    return gcd(y, x % y);
}

int main(){
    using namespace std;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int MAX_A = 1000000;
    vector<int> lp(MAX_A + 1,0);//最小の素因数をいれる(2以上をみていけばいい)
    vector<int> pr;//MAX_A以下の素数の集合
    vector<int> count(MAX_A + 1,0);
    for(int i = 2; i <= MAX_A; i++){//線形時間で処理してくれる
        if(lp[i] == 0){
            lp[i] = i;
            pr.push_back(i);
        }
        for(int j = 0; j < pr.size()&& pr[j] <= lp[i]&& i * pr[j] <= MAX_A; j++){
            lp[i * pr[j]] = pr[j];//i * pr[j] == C(const)としてありえるi, jの組は高々一通りになるので、これは線形時間で処理される
        }
    }
    int N;
    cin >> N;
    vector<int> A(N);
    int GCD = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        GCD = gcd(GCD, A[i]);
    }
    if(GCD != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    for(int i = 0; i < N; i++){
        while(A[i]>1){
            int div = lp[A[i]];
            if(count[div]){
                cout << "setwise coprime" << endl;
                return 0;
            }
            count[div]++;
            while(A[i] % div == 0){
                A[i] /= div;
            }
        }
    }
    cout << "pairwise coprime" << endl;
}


Measured memory_bytes: 15488
#include<stdio.h>
#include<string.h>
#define MAX 10

void solve(char *line, int N){
  int i, j, minj, tmp;
  int C[N];
  int B = 0;
  for (i = 0; i < N; i++ ) C[i] = 0;

  for ( i = 0; i < strlen(line); i++ ){
    int p = i%N;
    if ( line[i] == 'M' ){
      C[p]++;
    } else if ( line[i] == 'S' ){
      C[p]++;
      B += C[p];
      C[p] = 0;
    } else if ( line[i] == 'L' ){
      C[p] += B + 1;
      B = 0;
    }
  }

  // selection sort;
  for ( i = 0; i < N; i++ ){
    minj = i;
    for ( j = i; j < N; j++ )
      if ( C[j] < C[minj] ) minj = j;
    tmp = C[i];
    C[i] = C[minj];
    C[minj] = tmp;
  }

  for ( i = 0; i < N; i++ ) printf("%d ", C[i]);
  printf("%d\n", B);
}

int main(){
  int N;
  char line[101];
  while(1){
    scanf("%d", &N);
    if ( N == 0 ) break;
    scanf("%s", line);
    solve(line, N);
  }
  return 0;
}



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

ll pow(ll x,ll y){
  if(y==0){
    return 1;
  }else if(y==1){
    return x%MOD;
  }else if(y%2==0){
    return pow(x,y/2)*pow(x,y/2)%MOD;
  }else{
    return pow(x,y-1)*x%MOD;
  }
}

int main(){
  int x;cin >> x;
  cout << 1-x << endl;
}

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

int main() {
  int n,ans = 0;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data.at(i);
  }
  for(int i = 0;i < n-2;i++){
    if((data.at(i) < data.at(i+1) && data.at(i+1) < data.at(i+2)) || (data.at(i) > data.at(i+1) && data.at(i+1) > data.at(i+2))){
      ans ++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int res = 1;
    int max = 0;
    for (int i = 1; i <= n; i++) {
        int tmp = i;
        int count = 0;
        while (tmp % 2 == 0) {
            tmp /= 2;
            count++;
        }
        if (count > max) {
            max = count;
            res = i;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, B[100001], V[100001];

int simulate(int b, int n){
	if(V[b] == 0) V[b] = 1;
	else return -1;
	if(b != 2) return simulate(B[b], n + 1);
	else return n; 
}

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &B[i]);
	printf("%d\n", simulate(1, 0));
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int a2 = 0;
		int a4 = 0;
		int e = 0;
		for(int i = 0 ; i < n ; i++) {
			if(a[i] % 4 == 0) a4++;
			else if(a[i] % 2 == 0) a2++;
			else e++;
		}
		if(a2 == 0 && e <= a4 + 1 || a2 != 0 && e <= a4) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 51216
from sys import stdin
input = stdin.readline

class DisjointSet(object):
    def __init__(self, n):
        self.p = list(range(n))
        self.rank = [0]*n

    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)

    def unite(self, x, y):
        self.link(self.find_set(x), self.find_set(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
    
    def find_set(self, x):
        if x != self.p[x]:
            self.p[x] = self.find_set(self.p[x])
        return self.p[x]


if __name__ == '__main__':
    n, q = map(int, input().split())

    ds = DisjointSet(n)

    for _ in range(q):
        t, a, b = map(int, input().split())
        if t == 0:
            ds.unite(a, b)
        elif t == 1:
            if ds.same(a, b):
                print(1)
            else:
                print(0)



Measured memory_bytes: 6764
class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
			@rank = 0
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size, :rank
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		if u.rank > v.rank
			v.parent = u
			u.size += v.size
		elsif v.rank > u.rank
			u.parent = v
			v.size += u.size
		else
			u.parent = v
			v.rank += 1
			v.size += u.size
		end
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end
end

loop {
	n, m = gets.split.map &:to_i
	break if n == 0

	edges = (1..m).map{ gets.split.map &:to_i }.sort_by(&:last)
	min = Float::INFINITY

	until edges.empty?
		min_weight = edges[0][-1]
		uf = UnionFind.new
		edges.each{|i, j, w|
			uf.union(i, j)
			if uf.size(i) == n
				slim = w - min_weight
				min = slim if slim < min
				break
			end
		}

		edges.shift until edges.empty? || edges[0][-1] > min_weight
	end

	p min == Float::INFINITY ? -1 : min
}

Measured memory_bytes: 6988
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/
int main(){
   int n, t, kbr=0, cnt;
   cin >> n >> t;
   VI s(n);
   REP(i,n){
       cin >> s[i];
   }
   FOR(i, 1, n){
      cnt=s[i]-s[i-1];
      if(cnt>t){
          kbr+=(cnt-t);
      } 
   }
   cout << s[n-1]-kbr+t << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int i = 0; i < input; i++){
			num[i] = scan.nextInt();
		}
		
		shellSort(num, input);
		
		for(int n = 0; n < input; n++){
			System.out.println(num[n]);
		}
	}
	
	static int insertionSort(int A[], int n, int g){
		int v;
		int j;
		int c = 0;
		
		for(int i = g; i <= n - 1; i++){
			v = A[i];
			j = i - g;
			while(j >= 0 && A[j] > v){
				A[j + g] = A[j];
				j = j - g;
				c++;
			}
			A[j + g] = v;
		}
		return c;
	}
	
	static void shellSort(int A[], int n){
		int cnt = 0;
		int m = 0;
		int h = 1;
		
		while(h < n){
			h = h * 3 + 1;
			m++;
		}
		if(n == 1 && A[0] == 1){
			m = 1;
		}
		
		System.out.println(m);
		int[] G = new int[m];
		
		int temp = 0;
		for(int j = 0; j < m; j++){
			for(int i = 0; i < m - j; i++){
				temp = temp * 3 + 1;
				G[j] = temp;
				
			}
			if(j != m - 1){
				System.out.print(G[j] + " ");
			}else{
				System.out.println(G[j]);
			}
			temp = 0;
		}
		for(int i = 0; i <= m - 1; i++){
			cnt += insertionSort(A, n, G[i]);
		}
		
		System.out.println(cnt);
	}
}

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

map<long, long> pf(long n) {
  map<long, long> ma;
  for (long i = 2; i * i <= n; i++) {
    while (n % i == 0) ma[i]++, n /= i;
  }
  if (n != 1) ma[n]++;
  return ma;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);

  bool B = 1;
  vector<long> cnt(1e6+1);
  for (auto a : A) {
    for (auto [b, c] : pf(a)) {
      if (cnt.at(b)) {
        B = 0;
        goto NG;
      }
      cnt.at(b)++;
    }
  }
  NG:;
  if (B) return cout << "pairwise coprime" << "\n", 0;

  long G = 0;
  for (long i = 0; i < N; i++) G = gcd(G, A.at(i));
  if (G == 1) cout << "setwise coprime" << "\n", 0;
  else cout << "not coprime" << "\n";
}


Measured memory_bytes: 18772
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int n, q;
	cin >> n;
	vi s(n);
	REP(i, n) cin >> s[i];
	cin >> q;
	vi t(q);
	REP(i, q) cin >> t[i];
	int cnt = 0;
	REP(i, q)
	{
		if (t[i]<=s.back() && *lower_bound(ALL(s), t[i]) == t[i]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

#define fi first
#define se second

using namespace std;

typedef pair<int, int> ii;
typedef pair<int, ii> II;

int n, m, a[10][10];
int S, T, id;
vector<II> vres;

void add(int x, int y, int z) {
	vres.push_back(II(z, ii(x + 1, 200 - y)));
}

bool check(int x, int y, int z) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			int tmp = z + x * (i + 1) + y * (j + 1);
			if (tmp < a[i][j]) return 0;
		}
	}
	return 1;
}

void run(int A, int B) {
	for (int x = 0; x <= 100; ++x) for (int y = 0; y <= 100; ++y) {
		int z = a[A][B] - x * (A + 1) - y * (B + 1);
		if (z < 0) continue;
		if (check(x, y, z)) { add(x, y, z); return; } 
	}
	cout << "Impossible"; exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	S = 1, T = 200, id = 200;
	for (int i = 1; i < 100; ++i) vres.push_back(II(-1, ii(i, i + 1)));
	for (int i = 101; i < 200; ++i) vres.push_back(II(-2, ii(i, i + 1)));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			run(i, j);
		}
	}
	sort(vres.begin(), vres.end());
	vres.erase(unique(vres.begin(), vres.end()), vres.end());
	cout << "Possible\n";
	cout << id << ' ' << vres.size() << '\n';
	for (auto i : vres) {
		cout << i.se.fi << ' ' << i.se.se << ' ';
		if (i.fi == -1) cout << "X\n";
		if (i.fi == -2) cout << "Y\n";
		if (i.fi >= 0) cout << i.fi << '\n';
	}
	cout << S << ' ' << T;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int N;
    cin >> N ;
    string S,T;
    cin >> S >> T ;
    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var k = int.Parse(line[2]);
        var aL = line[0].Length;
        var a = getArray(line[0], aL);
        var b = getArray(line[1], aL);
        var c = getArray((int.Parse(line[0]) - int.Parse(line[1])).ToString(), aL);
        var d = getAns(a, b, aL);
        var count = 0;
        var ans = "";
        for (int i = aL - 1; i >= 0; i--)
            if (d[i] > c[i] && count < k) { ans += d[i].ToString(); count++; }
            else ans += c[i].ToString();
        Console.WriteLine(int.Parse(ans));
    }
    public static int[] getAns(int[] a, int[] b, int n)
    {
        var ret = new int[n];
        for (int i = 0; i < n; i++)
            ret[i] = a[i] < b[i] ? a[i] + 10 - b[i] : a[i] - b[i];
        return ret;
    }
    public static int[] getArray(string s, int n)
    {
        var sL = s.Length;
        var ret = new int[n];
        for (int i = 0; i < sL; i++)
            ret[i] = int.Parse(s[sL - 1 - i].ToString());
        return ret;
    }
}


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

/**
 * Blood Group
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int[] bs = new int[4];

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			words = line.split(",");

			if (words[1].length() > 1) {
				bs[2]++;
			} else {
				switch (words[1].charAt(0)) {
					case 'A':
						bs[0]++;
						break;
					case 'B':
						bs[1]++;
						break;
					case 'O':
						bs[3]++;
						break;
				}
			}
		}
		for (int i = 0; i < bs.length; i++) {
			System.out.println(bs[i]);
		}
	}
}

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

int main(){
  string s;
  cin >> s;
  for(int i=0;i<8;i++){
    int sum = s.at(0)-'0';
    string l;
    l += s.at(0);
    for(int j=0;j<3;j++){
      if( i & (1<<j) ){
        sum += s.at(j+1)-'0';
        l += '+';
        l += s.at(j+1);
      }else{
        sum -= s.at(j+1)-'0';
        l += '-';
        l += s.at(j+1);
      }
    }
    if( sum == 7 ){
      cout << l + "=7" << endl;
      return 0;
    }
  }
    
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    string s;
    ll k;
    cin >> s >> k;

    ll count=0;
    char ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            count++;
            if(count==k){
                ans='1';
                break;
            }
        }else{
            ans=s[i];
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604