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

int main()
{
    // 入力
    int N;
    cin >> N;
    vector<vector<int>> G(N);//木を隣接リストとして保存
    vector<pair<int,int>> vp;//辺を順番に記録しておく
    for(int i = 0; i < N-1; i++)
    {
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a,b);
    }

    // 色の種類の最大数
    int K = 0;
    // 出力結果をまとめる
    map<pair<int,int>,int> I;
    // あるノードと親との辺の色
    vector<int> cs(N,0);
    // 一度でも訪れたノードかどうか記録
    vector<bool> used(N,0);
    used[0] = true;
    // 次に探索するノード
    queue<int> que;
    que.emplace(0);

    // 深さ優先探索
    while(!que.empty())
    {
        // 探索するノード取得
        int v = que.front();
        que.pop();
        // ノードが持つ辺の数の最大値を更新
        K = max(K,(int)G[v].size());
        // ノードG[v]の辺をすべて探索
        int cur = 1;
        for(int u : G[v])
        {
            // すでに訪れたノードだったら次へ
            if(used[u] == true) continue;
            // 親と色がかぶったら変更
            if(cur == cs[v]) cur++;
            // 色を決定
            cs[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cur++;
            // 訪れたフラグを立てる
            used[u] = true;
            // 次に行くノードをキューに詰める
            que.emplace(u);
        }
    }

    // 解を出力
    cout << K << endl;
    for(auto p : vp) cout << I[p] << endl;
    return 0;
}

Measured memory_bytes: 19700
#include <bits/stdc++.h>
using namespace std;
map<int,int> p;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	int i;
	int sum=0;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		p[a[i]]=p[a[i]]+1;
	}
	int num=0;
	map<int,int>::iterator it;
	for(it=p.begin();it!=p.end();it++)
	{
		if(it->second<it->first)
		{
			num+=it->second;
		}
		else
		{
			if(it->second>it->first)
			{
				num+=it->second-it->first;
			}
		}
	}
	cout<<num;
	return 0;
}

Measured memory_bytes: 5120
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

a,b,c,k = map(int,input().split())
if k%2 == 0:
    print(a-b)
elif k%2 == 1:
    print(b-a)
elif abs(a-b)>10**18:
    print("Unfair")

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

int main()
{
	int i,j,k,n;
	cin>>n;
	int sum=0;
	while (n--)
	{
		int l,r;
		cin>>l>>r;
		sum+=(r-l)+1;
	}
	cout<<sum<<"\n";
}

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

int n,k;
int memo[4][4][4][102];
map <int,int> ma;

int rec(int b,int y,int t,int idx){
    if(b == y && y == t) return 0;
    if(ma[idx] != '\0' && ma[idx] != t) return 0;
    if(idx == n) return 1;
    if(memo[b][y][t][idx] != 0) return memo[b][y][t][idx];
    return memo[b][y][t][idx] = (rec(y,t,1,idx+1) + rec(y,t,2,idx+1) + rec(y,t,3,idx+1))%10000;
}

int main(){
    cin >> n >> k;
    for(int i=0;i<k;i++){
        int t,m; cin >> t >> m; ma[t] = m;
    }
    int ans = (rec(0,0,1,1) + rec(0,0,2,1) + rec(0,0,3,1))%10000;
    cout << ans << endl;
}

Measured memory_bytes: 1232
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
constexpr  int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	string s;
	cin>>s;
	for(auto i:s){
		cout<<(char(i+N)<='Z'?char(i+N):char(i+N-26));
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

// a>=0, b>=0, x*a+y*b=gcd>=0, a>0,b>0=>abs(y)<=a,abs(x)<=b
LL gcdex(LL a,LL b,LL& x, LL& y){
	LL ax=1,ay=0;
	LL bx=0,by=1;
	while(b){
		LL r=a/b;
		LL t=a-r*b; a=b; b=t;
		LL tx=ax-r*bx; ax=bx; bx=tx;
		LL ty=ay-r*by; ay=by; by=ty;
	}
	x=ax;
	y=ay;
	return a;
}
LL modinv(LL a, LL m){
	LL x,y;
	gcdex(a,m,x,y);
	if(x<0){
		x+=m;
	} else if(x>=m){
		x-=m;
	}
	return x;
}
int M;
// (x+a) * \Sum v[i]*x^i
void mul(int a,vector<int>& v)
{
	v.push_back(0);
	for(int i=v.size()-1;i>0;i--){
		v[i]=(v[i]*a+v[i-1]);
		v[i]%=M;
	}
	v[0]=v[0]*a%M;
}
void div(int a,vector<int>& v,vector<int>& ret)
{
	int r=v.back();
	for(int i=v.size()-2;i>=0;i--){
		ret[i]=r;
		r=(v[i]+M-r*a%M)%M;
	}
#if 0
	assert(r==0);
	vector<int> t=ret;
	mul(a,t);
	assert(t==v);
#endif
}
int eval(int a,vector<int>& v)
{
	int s=0;
	int k=1;
	for(int i=0;i<v.size();i++){
		s+=k*v[i]%M;
		s%=M;
		k*=a;
		k%=M;
	}
	return s;
}
void print(vector<int>& v){
	for(auto r:v){
		cerr << r << " ";
	}
	cerr << endl;
}
void solve(long long p, std::vector<long long> a){
	M=p;
	vector<int> v;
	v.push_back(1);
	for(int i=0;i<M;i++){
		mul(M-i,v);
	}
	//print(v);
	
	vector<int> ret;
	ret.resize(M);
	vector<int> t;
	t.resize(M);
	for(int i=0;i<M;i++){
		if(a[i]==0){
			continue;
		}
		div(M-i,v,t);
		//cerr << i << endl;
		//print(t);
		int e=eval(i,t);
		int c=modinv(e,M);
		//cerr << i << ": " << e << ", " << c << endl;
		//print(t);
		for(int j=0;j<t.size();j++){
			ret[j]+=c*t[j]%M;
			ret[j]%=M;
		}
	}

#if 0
	for(int i=0;i<M;i++){
		cerr << eval(i,ret) << " ";
	}
	cerr << endl;
#endif

	auto sp="";
	for(auto b:ret){
		cout << sp << b;
		sp=" ";
	}
	cout << endl;

}

int main(){
    long long p;
    scanf("%lld",&p);
    std::vector<long long> a(p-1-0+1);
    for(int i = 0 ; i < p-1-0+1 ; i++){
        scanf("%lld",&a[i]);
    }
    solve(p, std::move(a));
    return 0;
}


Measured memory_bytes: 384
def main():
	N = int(input())
	H = list(map(int,input().split()))
	
	count = 1
	for i,ryokan in enumerate(H[1:]) :
		flag = False
		for o in H[:i+1] :
			if o <= ryokan :
				flag = True
			else :
				flag = False
				break
		if flag == True :
			count += 1
	print(count)

if __name__ == "__main__" :
	main()

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

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main() {
    map<int, int> cnt;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    int ans = 0;
    for (auto p:cnt) {
        if (p.first > p.second) {
            ans += p.second;
        } else {
            ans += p.second - p.first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
#include<iostream>   //AA06( 19/ 04/ 20) If u see my code, Have a Good Day! (^_^)
using namespace std;

int main()
{
    int n, x, i = 0;
    cin >> n;

    while(n > 0) {
        x = n % 10;

        if(x == 7) {
            i++;
        }

        n = n / 10;
    }

    if(i > 0) {
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
char s[1000009], t[1000009]; int c[1000009];
int main() {
	scanf("%s", s);
	int n = strlen(s);
	int p = 0, z = 0;
	for (int i = 1; s[i - 1]; i++) {
		if (s[i] != s[i - 1]) {
			t[z] = s[i - 1];
			c[z] = i - p;
			p = i; z++;
		}
	}
	int ret = 0;
	for (int i = 1; i < z - 1; i++) {
		if (t[i - 1] != 'J' || t[i] != 'O' || t[i + 1] != 'I') continue;
		if (c[i - 1] < c[i] || c[i] > c[i + 1]) continue;
		if (ret < c[i]) ret = c[i];
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 8420
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll pow_mod(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 0x01) { 
            res *= a;
            res %= mod;
        }
        a = a*a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

ll combi_mod(ll n, ll k, ll mod) {
    if (k == 0) return 1;
    if (k == 1) return n%mod;

    ll nume = 1, denom = 1;
    FOR(i, 1, k + 1) {
        nume *= i;
        nume %= mod;
        denom *= i;
        denom %= mod;
    }
    nume %= mod;
    denom %= mod;
    FOR(i, 1, n-k+1) {
        nume *= k + i;
        nume %= mod;
        denom *= i;
        denom %= mod;
    }
    nume %= mod;
    denom %= mod;

    ll res = nume * pow_mod(denom, mod - 2, mod);
    res %= mod;
    return res;
}
#endif


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

    const ll MOD = (ll)1e9 + 7;
    ll N, M, K;  cin >> N >> M >> K;


    ll tx = 0;
    FOR(i, 1, M) {
        tx += i * (M - i) % MOD;
    }
    tx *= N % MOD;
    tx *= N % MOD;

    ll ty = 0;
    FOR(i, 1, N) {
        ty += i * (N - i) % MOD;
    }
    ty *= M % MOD; 
    ty *= M % MOD;

    ll ans = combi_mod(N*M - 2, K - 2, MOD) * (tx % MOD + ty % MOD);
    ans %= MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include <string.h>



int main() {
	int i, j, k, l = 0;
	int m, g, n, q;
	int f = 0;
	int point[110000] = { 0 };
	int a;
	char we[110];


	scanf("%s", we);

	n = sizeof(we);

	for (i = 0;i < n;i++) {
		if (i % 2 == 0) {
			if (we[i] == 'L') {
				f = 1;
			}
		}
		else {
			if (we[i] == 'R') {
				f = 1;
			}
		}
	}



	if (f==0) {
		printf("Yes");
	}
	else {
		printf("No");
	}





//	printf("%d", f);

	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
import math

N=int(input())
B = [int(input()) for _ in range(N)]

def insertionSort(A,n,g,cnt):
    for i in range(g,n):
        v=A[i]
        j=i-g
        while j>=0 and A[j]>v:
            A[j+g]=A[j]
            j=j-g
            cnt+=1
        A[j+g]=v
    
    return cnt

def shellSort(A,n):
    cnt=0
    G = []
    tmp=n//2
    while tmp:
        G.append(tmp)
        tmp=tmp//2
    
    if len(G)==0:
        G.append(1)
    m=len(G)
    print(m)
    print(*G)
    for i in range(m):
        cnt=insertionSort(A,n,G[i],cnt)
    print(cnt)
    
    for x in A:
        print(x)
    
shellSort(B,N)



Measured memory_bytes: 45588
#include<stdio.h>
#define MAX 2000000
int H,A[MAX+1];

void maxHeapify(i){
    int l,r,largest,change;
    l = 2*i;
    r = 2*i+1;
    if(l<=H && A[l] > A[i]){
        largest = l;
    }
    else largest = i;
    if(r <= H && A[r] > A[largest]){
        largest = r;
    }
    if(largest != i){
        change = A[i];
        A[i] = A[largest];
        A[largest] = change;
        maxHeapify(largest);
    }
}

int main(){
    int i;

    scanf("%d",&H);
    for(i=1;i<=H;i++)
    scanf("%d",&A[i]);
    for(i = H/2;i>=1;i--)
    maxHeapify(i);
    for(i=1;i<=H;i++){
        printf(" %d",A[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3752
program ABC_073_B_Theater
   implicit none
   integer N, i
   integer, allocatable :: l(:), r(:)
   read(*, *) N
   allocate(l(1: N))
   allocate(r(1: N))
   do i = 1, N
       read(*, *) l(i), r(i)
   end do
   write(*, *) sum(r - l) + N
end program ABC_073_B_Theater

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define N 50

int compare(const void *a, const void *b) {
	int pa = *(int *) a;
	int pb = *(int *) b;

	return pa - pb;
}

int main() {
	static int v[N];
	int n, i;
	double x;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &v[i]);
	qsort(v, n, sizeof *v, compare);
	x = v[0];
	for (i = 1; i < n; i++)
		x = (x + v[i]) / 2;
	printf("%f\n", x);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
map<long long int ,long long int> mp;
int main(){
    long long int az;
    long long int x;
    cin >> x;
    for(long long int i=1;i<2005;i++){
        az=i*i*i*i*i;
        mp[az]=i;
        mp[-az]=-i;
    }
    long long int tmp;
    long long int A,B;
    for(long long int i=1;i<2005;i++){
        tmp=i*i*i*i*i;
        if(tmp==x){
            A=i;
            B=0;
            break;
        }
        else if(mp[-tmp-x]!=0){
            A=-i;
            B=mp[-tmp-x];
            break;
        }
        else if(mp[tmp-x]!=0){
            A=i;
            B=mp[tmp-x];
            break;
        }
        else if(mp[x-tmp]!=0){
            A=i;
            B=mp[x-tmp];
            break;
        }
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 3880
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

int main()
{
    double d, t ,s; cin >> d >> t >> s;
    if (d / s <= t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3716
//4182_543_731 is vegetable
#include<cstdio>
#include<map>
#include<algorithm>
#define N 1000400
using namespace std;
int n,v2[N],fa[N];
long long v[N],sz[N],ds[N];
map<long long,int> tp;
bool cmp(int a,int b){return v[a]<v[b];}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&v[i]),tp[v[i]]=i,v2[i]=i,sz[i]=1;
	sort(v2+1,v2+n+1,cmp);
	for(int i=n;i>1;i--)
	{
		long long tp2=v[v2[i]]-n+sz[v2[i]]*2;
		if(!tp[tp2]){printf("-1\n");return 0;}
		int sb=tp[tp2];
		ds[sb]+=ds[v2[i]]+sz[v2[i]];
		sz[sb]+=sz[v2[i]];
		fa[v2[i]]=sb;
	}
	if(ds[v2[1]]!=v[v2[1]]){printf("-1\n");return 0;}
	for(int i=1;i<=n;i++)if(fa[i])printf("%d %d\n",i,fa[i]);
}

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

signed main() {
	int n;
	string s;
	cin >> n >> s;
	int cnt = 0;

	// "#." is NG
	// ###..##...##### n = 15 sharp = 5
	// ###.. ##... #... ###. #. ##... ###..... #####
	// ###..##...#...###.#.##...###.....#####
	//
	//
	// sharp = 5, dot = 5

	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}

	vector<int> sharp, dot;
	sharp.push_back(0);
	dot.push_back(0);

	int vecnum = 0;
	
	for (int i = 0; i < n; ++i) {
		if (i > 0 and s[i] == '#' and s[i - 1] == '.') {
			vecnum++;
			sharp.push_back(0);
			dot.push_back(0);
		}
		if (s[i] == '#') sharp[vecnum]++;
		if (s[i] == '.') dot[vecnum]++;
	}

	int N = sharp.size();
	vector<int> diff(N);

	for (int i = 0; i < N; ++i) {
		diff[i] = dot[i] - sharp[i];
	}

	reverse(diff.begin(), diff.end());

	int sum = accumulate(sharp.begin(), sharp.end(), 0);
	int ans = sum;

	for (int i = 0; i < N; ++i) {
		ans = min(ans, sum + diff[i]);
		sum += diff[i];

	}


	cout << ans << endl;

	/*
	for (auto e : sharp) cout << e << ' ';
	cout << endl;
	for (auto e : dot) cout << e << ' ';
	cout << endl;
	*/

}


Measured memory_bytes: 1784
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
#define MAX 1000000000000000000
int main(){
ll n,b ;
  cin>>n;
  ll ans=1;
  
 vector<ll> vec(100000,0);
 for(int i=0;i<n;i++){
     cin>>vec[i];
     if(vec[i]==0){
     cout<<0;
     return 0;
     }
 }
 
  for(int i=0;i<n;i++){
      if(vec[i]<=MAX/ans)
        ans*=vec[i];
    else{
            cout<<-1;
        return 0;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3636
_ = input()
s = input()

check = ['A', 'B', 'C']

count = 0
state = 0

for i in range(len(s)):
    c = s[i]
    if c != check[state]:
        if c == check[0]:
            state = 1
        else:
            state = 0
        continue
    
    state += 1
    if state == 3:
        count += 1
        state = 0

print(count)


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

using namespace std;

int main()
{
    int n,k,t;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t);
    }
    int ans;
     ans=(n-1)/(k-1);
    if((n-1)%(k-1)!=0)
        ans++;
    printf("%d",ans);

    return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    int a[102];
    int sum1[102] = {};
    int sum2[102] = {};
    Scd(N);

    Rep(i,N){
        Scd(a[i]);
        sum1[i] += a[i];
        sum1[i+1] = sum1[i];
    }
    Rep(i,N){
        Scd(a[N-i-1]);
    }
    Rep(i,N){
        sum2[i] += a[i];
        sum2[i+1] = sum2[i];
    }

    int ans = 0;
    Rep(i,N){
        ans = max(ans,sum1[i]+sum2[N-1-i]);
    }
    printf ("%d\n", ans);


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
	long long a,b,c;
	cin>>a>>b>>c;
    long long now=c-a-b;
    if(now<0) 
	{ 
		puts("No"); 
		return 0;
	}
    if(4*a*b>=now*now) 
		puts("No");
    else 
		puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


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

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



int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> A(N); rep(i, N) std::cin >> A[i];
  
  if ( N % 2 == 0 ) {
    std::vector<int> B(N);
    rep(i,N) B[A[i]]++;
    for(int i=1; i<=N-1; i+=2) {
      if ( B[i] != 2 ) {
        std::cout << 0 << std::endl;
        return 0;
      }
    }
  }
  else {
    std::vector<int> B(N);
    rep(i,N) B[A[i]]++;
    if ( B[0] != 1 ) {
      std::cout << 0 << std::endl;
      return 0;
    }
    for(int i=2; i<=N-1; i+=2){
      if ( B[i] != 2 ) {
        std::cout << 0 << std::endl;
        return 0;
      }
    }
  }
  mint p = 2; mint ans = p.pow(N/2);
  std::cout << ans.x << std::endl;

  return 0;
}


Measured memory_bytes: 1152
/*
AOJ 0033 Ball

?¢???????????§??????????????????¢???????§???§?\?????????????A??£?????\???????????????????????????????????????DE?????¶??????B?£???????C?£??????????
??°??????1-10??????????????????????????????A??£?????\???????????????????§???§??¶??????????????\?????\???B?£???????C?£???????????????????????????????????¢????

?????\????¬¬???????????\??°????????°N?????\?????\N??????N???????????°??????????????°?????????10?????´??°?????£??¨???????????\?????????

???????????????????????°????????\?????\?????¨?????????YES?????\????????¨?????????NO
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

int x[10];

bool check(int mask) {
  int lb = 0;
  REP(i, 10) if (mask & (1<<i)) {
    if (x[i] < lb) return false;
    lb = x[i];
  }
  return true;
}

bool go(void) {
  REP(i, 512) if (check(i) && check(1023-i)) return true;
  return false;
}

int main(int argc, char *argv[]) {
  int n;
  for (scanf("%d", &n); n; --n) {
    REP(i, 10) scanf("%d", &x[i]);
    puts(go()? "YES" : "NO");
  }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> s(N);
    rep(i, N) cin >> s[i];
    sort(s.begin(), s.end());

    int ans = 0;
    rep(i, N) ans += s[i];
    if (ans % 10) {
        cout << ans << endl;
        return 0;
    }

    rep(i, N) {
        if (s[i] % 10) {
            cout << ans - s[i] << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll N,H,W;
ll x[500000],y[500000],w[500000];
ll s[500000];

bool judge(ll W,ll x[]) {
	REP(i,W) {
		s[i] = 0;
	}

	REP(i,N) {
		s[max(x[i] - w[i],0ll)]++;
		s[x[i] + w[i] ]--;
	}

	REP(i,W - 1) {
		s[i + 1] += s[i];
	}

	REP(i,W) {
		if(s[i] <= 0) {
			return false;
		}
	}
	return true;
}

int main(){
	cin >> N >> W >> H;

	REP(i,N) {
		cin >> x[i] >> y[i] >> w[i];
	}

	if(judge(W,x) || judge(H,y)) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 7016
# 2019/09/09

from collections import Counter

n=int(input())
C=Counter(list(map(int,input().split())))

even=0
odd=0
ans=len(C)
for k,v in C.items():
    if v>1:
        if v%2:
            odd+=1
        else:
            even+=1

if even%2:
    ans-=1

print(ans)


Measured memory_bytes: 18648
function Main(input) {
  input = input.split("\n");
  const n = input[0].split(" ")[0];
  const d = input[0].split(" ")[1];
  var array = [];
  for (var i = 1; i <= n; i++) {
    array.push(input[i].split(" "));
  }
  
  

  var square = 0;
  var distance = [];
  for (var i = 0; i <= n - 2; i++) {
    for (var j = i + 1; j <= n - 1; j++) {
      for (var k = 0; k <= d - 1; k++) {
          square = square + Math.pow(( array[i][k] - array[j][k] ), 2);
      }
      distance.push(Math.pow(square, 1/2));
      square = 0;      
    }
  }

  var intDistance = distance.filter(function(value){
    return Number.isInteger(value);
  })
  console.log(intDistance.length);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};



void solve(){
    ll m;
    cin>>m;
    cout<<48-m<<endl;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int n, x, l[100], t = 0, a = 1;
	cin >> n >> x;
	rep(i, n){
		cin >> l[i];
		t+= l[i];
		if(t<=x) a++;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
goukei = 0
goukei2 = 0
goukei3 = 0
sa = 0

for i in W:
    goukei += i
sa = goukei

for i in W:
    goukei2 += i
    goukei3 = goukei - goukei2
    if(abs(goukei3 - goukei2) <= sa):
        sa = goukei3 - goukei2
    
print(abs(sa))

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
    int N;
    cin>>N;
    vector<string>s(N);
    REP(i,N)cin>>s[i];
    vector<string>ba,a,b,other;
    REP(i,N){
        if(s[i][0]=='B'&&s[i].back()=='A')ba.PB(s[i]);
        else if(s[i][0]=='B')b.PB(s[i]);
        else if(s[i].back()=='A')a.PB(s[i]);
        else other.PB(s[i]);
    }
    string res="";
    int acnt=0,bcnt=0,bacnt=0;
    if(SZ(a)!=0){
        res+=a[acnt];
        acnt++;
    }
    while(bacnt<SZ(ba)){
        res+=ba[bacnt];bacnt++;
    }
    if(SZ(b)!=0){
        res+=b[bcnt];
        bcnt++;
    }
    while(bcnt<SZ(b)&&acnt<SZ(a)){
        res+=(a[acnt]+b[bcnt]);
        bcnt++;
        acnt++;
    }
    while(bcnt<SZ(b)){
        res+=b[bcnt];bcnt++;
    }
    while(acnt<SZ(a)){
        res+=a[acnt];acnt++;
    }
    REP(i,SZ(other))res+=other[i];
    int num=0;
    REP(i,SZ(res)-1)if(res[i]=='A'&&res[i+1]=='B')num++;
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 1536
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner;

class Main{

    public static void main(String[] args) {

        int a,b;

        Scanner scan = new Scanner(System.in);

        a = scan.nextInt();
        b = scan.nextInt();

        BigDecimal aa = new BigDecimal(a);
        BigDecimal bb = new BigDecimal(b);

        //BigDecimal div = new BigDecimal("0.00000000");

        BigDecimal div = aa.divide(bb, 8, BigDecimal.ROUND_HALF_UP);

        DecimalFormat format = new DecimalFormat("#.#");
        //format.setMinimumFractionDigits(8);//?°?????????¨???8????????§??????
        format.setMaximumFractionDigits(8);//?????§8????????§??????

        System.out.println(a/b + " " + a%b + " "+ format.format(div) );
        scan.close();
    }
}

Measured memory_bytes: 26612
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int nrdiv[205];

int main() {
   // freopen("a.in", "r", stdin);
 //  freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    nrdiv[1] = 1;
    for(int i = 1; i <= n; i ++)
        for(int j = i; j <= n; j += i)
            nrdiv[j] ++;

    int sol = 0;

    for(int i = 1; i <= n; i += 2)
        if(nrdiv[i] == 8)
            sol ++;
    cout << sol;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

int n, a[N], lt[N], rt[N];
int main() {
	int i;
	cin >> n;
	for(i=1; i<=n; i++) {
		scanf("%d", &a[i]);
		lt[i] = max(lt[i-1], a[i]);
	}
	for(i=n; i; i--) {
		rt[i] = max(rt[i+1], a[i]);
	}
	for(i=1; i<=n; i++) {
		printf("%d\n", max(lt[i-1], rt[i+1]));
	}
    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline int rdi(){
	int x=0,f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	return f?-x:x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
const int N=100005;
int n,k,a[105];
bool dp[N][2];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;++i) cin>>a[i];
	for(int i=1;i<=k;++i) for(int j=0;j<2;++j) for(int l=0;l<n;++l) if(i>=a[l] and !dp[i-a[l]][j^1]) dp[i][j]=1;
	if(dp[k][0]) cout<<"First";
	else cout<<"Second";
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 2010
#define MOD 998244353
using namespace std;
typedef long long ll;
ll C[2*MAXN][2*MAXN],bits[2*MAXN];
int n,k;
ll count(int s,int tot){
    return C[s+tot-1][s-1]; 
}
ll solve(int i,int tot){
    int k2=min(k-i/2,(i-1)/2);
    int k1=k-k2*2-((i%2)==0);
    ll flag=1;
    ll res=0;
    for(int l=k2;l+k1>0&&l>=0;l--,flag=-flag)
	{
        res+=count(l+k1,tot-l)*bits[l]%MOD*C[k2][l]%MOD;
        res%=MOD;
    }
    return (res+MOD)%MOD;
}
int main()
{
    SF("%d%d",&k,&n);
    int sum=0;
    bits[0]=1;
    for(int i=1;i<=4000;i++)
        bits[i]=bits[i-1]*2ll%MOD;
    C[0][0]=1;
    for(int i=1;i<=4000;i++){
        C[i][0]=1;
        for(int j=1;j<=i;j++)
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
    }
    ll ans=0;
    for(int i=2;i<=2*k;i++){
        if(i%2==0){
            ans=(solve(i,n)+solve(i,n-1))%MOD;
        }
        else{
            ans=solve(i,n);
        }
        PF("%lld\n",ans);
    }
}

Measured memory_bytes: 124288
MOD = 10**9+7

n, k = map(int, input().split())
a = list(map(int, input().split()))
p, q = [], []
for x in a:
    if x >= 0: p.append(x)
    else: q.append(x)
lp, lq = len(p), len(q)

def sp():
    p.sort(reverse=True)
    q.sort()
    ans = p[0] if k % 2 else 1
    s = []
    for i in range(0, lq-1, 2):
        s.append(q[i]*q[i+1])
    for i in range(k % 2, lp-1, 2):
        s.append(p[i]*p[i+1])
    s.sort(reverse=True)
    for i in range(k//2):
        ans *= s[i]
        ans %= MOD
    print(ans)

def sq():
    a.sort(key=lambda x: abs(x))
    ans = 1
    for i in range(k):
        ans *= a[i]
        ans %= MOD
    print(ans)

if k % 2 and not p: sq()
elif n == k and lq % 2: sq()
else: sp()


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

int main(){
  int n,k;
  cin>>n>>k;
  int ans=1;
  for (int i = 0; i < n; i++)
  {
    /* code */
    ans=min(ans*2,ans+k);
  }
  cout<<ans<<endl;
  }

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <utility>
typedef long long int lli;
using namespace std;
 int main(){
    int w,h,n,x,y,a;
    cin >> w >> h >> n;
    int max_x=w;
    int min_x=0;
    int max_y=h;
    int min_y=0;

    for(int i=0; i<n; i++){
        cin >> x >> y >> a;
        if(a==1){
            min_x=max(min_x,x);
        }else if(a==2){
            max_x=min(max_x,x);
        }else if(a==3){
            min_y=max(min_y,y);
        }else{
            max_y=min(max_y,y);
        }
    }
    if(max_x - min_x < 0 )
        cout << 0;
    else if(max_y - min_y < 0)
        cout << 0;
    else
        cout << (max_x - min_x)*(max_y - min_y);


     return 0;
 }

Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
#include <vector>

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

#define INF 1000000000

using namespace std;

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

    cout << ((S[2] == S[3] && S[4] == S[5]) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.range, std.random, std.conv, std.string, std.math;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.sorting;

void main()
{
    long[] input = readln().strip.split().to!(long[]);
    long K = input[0];
    long A = input[1];
    long B = input[2];
    if(B-A<=2) { writeln(K+1);
    return; }
    if(K-2-(A-1) < 0)
    {
        writeln(K+1);
        return;
    }
    
    long bis = 1 + K;
    long c = (K-(A-1))/2;
    writeln((B-A)*c+(bis-c*2) + (c==0?1:0));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{
    for (int i = 0; i < INF; i++)
    {
        int a, b, ans;
        string op;
        cin >> a >> op >> b;
        if (op == "?")
        {
            break;
        }
        else if (op == "+")
        {
            ans = a + b;
        }
        else if (op == "-")
        {
            ans = a - b;
        }
        else if (op == "*")
        {
            ans = a * b;
        }
        else if (op == "/")
        {
            ans = a / b;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3156
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
s = [0]*(n+1)
def C(x):
    return x*(x-1)//2
for i in range(n):
    s[i+1] = s[i]+a[i]
c = Counter(s)
ans = 0
for v in c.values():
    ans += C(v)
print(ans)

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

#define FOR(i,x) for(int i=0; i<x; i++)
#define FORic(i,y,x) for(int i=y; i<=x; i++)
#define FORdc(i,y,x) for(int i=y; i>=x; i--)

vector<string> all;
int w, h, l, r;
int masu[12];
bool check[62][12];

void tadoru(int i, int j){
	if(all[i][j] == '.') return;
	if(check[i][j]) return;
	else check[i][j] = true;
	masu[j]++;
	tadoru(i-1, j);
	if(all[i][j]==all[i][j-1]) tadoru(i, j-1);
	if(all[i][j]==all[i][j+1]) tadoru(i, j+1);
	if(all[i][j]==all[i+1][j]) tadoru(i+1, j);
}

void siraberu(int i, int j){
	if(all[i][j] == '.' || all[i][j] == '#') return;
	if(check[i][j]) return;
	else check[i][j] = true;
	if(all[i+1][j] != all[i][j]){
		if(all[i+1][j] != '.'){
			l = min(l, j);
			r = max(r, j);
		}
	}
	if(all[i][j]==all[i-1][j]) siraberu(i-1, j);
	if(all[i][j]==all[i][j-1]) siraberu(i, j-1);
	if(all[i][j]==all[i][j+1]) siraberu(i, j+1);
	if(all[i][j]==all[i+1][j]) siraberu(i+1, j);
}

void init_check(){
	FOR(i2, h+2) {FOR(j2, w+2) check[i2][j2] = false;}
}

int main(){
	while(cin>>w>>h){
		if(!w&&!h) break;
		all.clear();
		string buf, tmpue, tmpsita;
		FOR(i, w+2) tmpue += '.';
		all.push_back(tmpue);
		FOR(i,h){
			cin>>buf;
			string tmp = '.' + buf + '.';
			all.push_back(tmp);
		}
		FOR(i, w+2) tmpsita += '#';
		all.push_back(tmpsita);
		bool dame = false;
		FORdc(i, h, 1){
			FORic(j, 1, w){
				if(all[i][j]!='.'){
					if(all[i][j] == all[i-1][j]) continue;
					if(all[i][j] == all[i][j-1]) continue;
					FOR(n,12) masu[n] = 0;
					l = 15;
					r = -1;
					init_check();
					tadoru(i, j);
					init_check();
					siraberu(i, j);
					int g=0;
					int sum=0;
					FORic(n,1,w){
						g += (2*n-1)*masu[n];
						sum += masu[n];
					}
					if(g<=(l-1)*2*sum || r*2*sum<=g){
						dame = true;
						break;
					}
				}
			}
			if(dame) break;
		}
		if(dame) cout<<"UNSTABLE"<<endl;
		else cout<<"STABLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
using It = vector<int>::iterator;
using ll = long long;

int const M = 1e9 + 7;

int merge(It b, It e, It w) {
  It mid = next(b, distance(b, e) / 2);
  It in1 = b;
  It in2 = mid;
  It out = w;
  int r = 0;
  while(in1 != mid && in2 != e) {
      if (*in1 <= *in2) {
          *out++ = *in1++;
      }
      else {
          r += distance(in1, mid);
          *out++ = *in2++;
      }
  }
  copy(in1, mid, prev(e, distance(in1, mid)));
  copy(w, out, b);
  return r;
}
         
int mergesort(It b, It e, It w) {
    auto d = distance(b, e);
    if (d < 2)
        return 0;
    It mid = next(b, d / 2);
    return mergesort(b, mid, w) + mergesort(mid, e, w) + merge(b, e, w);
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    int k;
    cin >> n >> k;
    vector<int> a(n), temp(n);
    for (int& x : a) {
        cin >> x;
    }
    int r = mergesort(begin(a), end(a), begin(temp));
    int p = 0, c = n * (n - 1) / 2 , l = 1;
    for (int x : a) {
        if (x == p) {
            l++;
        }
        else {
            c -= l * (l - 1) / 2;
            p = x;
            l = 1;
        }
    }
    cout << ((ll)r * k + (ll)k * (k - 1) / 2 % M * (c - l * (l - 1) / 2)) % M << '\n';
    return 0;
}
             

Measured memory_bytes: 256
#include<cmath>
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline ll in()
{
	ll k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
using std::map;
map<ll,ll>cx,dr;
map<ll,ll>::iterator it;
void sq_get(ll &a,ll &b,ll c)
{
	ll res=1,ret=1;
	for(ll i=2;i*i*i<=c;++i)
		if(c%i==0)
		{
			int t=0;
			while(c&&c%i==0)c/=i,++t;t%=3;
			if(!t)continue;
			res*=(t==1?i:i*i),ret*=(t==1?i*i:i);
		}
	if(c>1)
	{
		ll t=sqrt(c);
		if(t*t==c)
		{
			res*=c,ret*=t;
		}
		else
		{
			res*=c,ret*=c*c;
		}
	}
	a=res,b=ret;
}
int main()
{
	int n=in();ll a,b;
	for(int i=1;i<=n;++i)
	{
		sq_get(a,b,in());
		dr[a]=b;
		if(cx.find(a)!=cx.end())++cx[a];
		else cx[a]=1;
//		printf("%lld %lld\n",a,b);
	}
	int ans=0;
	for(it=cx.begin();it!=cx.end();++it)
		if((*it).second)
		{
			a=(*it).first;b=dr[a];
			if(a==1){++ans;continue;}
			if(cx.find(b)==cx.end()){ans+=cx[a];continue;}
			ans+=std::max(cx[a],cx[b]);
			cx[a]=cx[b]=0;
		}
	printf("%d\n",ans);
	return 0;
}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> a;
  rep(i, n) {
    int aa;
    cin >> aa;
    a.push(aa);
  }
  rep(i, m) {
    int tmp = a.top();
    a.pop();
    a.push(tmp / 2);
  }

  ll result = 0;
  rep(i, n) {
    result += a.top();
    a.pop();
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 892
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF 1e18

int main()
{
	io;
	ll x,n;
	
	cin>>x>>n;
	if(n==0){cout<<x;return 0;}
	set<ll> s;
	FOR(i,0,n)
	{
		ll in;
		cin>>in;
		s.insert(in);
	}
	FOR(i,0,500)
	{
		if(s.find(x-i)==s.end()){cout<<x-i;break;}
		if(s.find(x+i)==s.end()){cout<<x+i;break;}
	}
	return 0;
}


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e17;


ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}


int main(){
  ll n,a;
  cin>>n;
  for(int i=pow(n,0.5);i>0;i--){
  if(n%i==0){a=i;break;}
  }
  cout<<to_string(n/a).length()<<endl;
return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<math.h>
#include<utility>
const int MOD = 1e9 + 7;
typedef long long ll;
using namespace std;

int main() {
    string S;
    int day = 7;
    cin >> S;
    if (S == "MON") {
        day = 6;
    }
    if (S == "TUE") {
        day = 5;
    }
    if (S == "WED") {
        day = 4;
    }
    if (S == "THU") {
        day = 3;
    }
    if (S == "FRI") {
        day = 2;
    }
    if (S == "SAT") {
        day = 1;
    }
    cout << day << endl;
}

Measured memory_bytes: 256
def steps(c, s):
    # c: No. of elements,  s: sum of elements
    q, r = divmod(s, 9)
    if r != 0:
        cnt = (c-1) + q
    else:
        cnt = (c-1) + q-1
        r = 9
    return cnt, r

m = int(input())
tot_c, tot_s = 0, 0
for _ in range(m):
    d, c = map(int, input().split())
    tot_c += c
    tot_s += c*d

ans, r = steps(tot_c, tot_s)
print(ans)

Measured memory_bytes: 9184
#include <stdio.h>

#define MAX 500 //配列の大きさは500*500で十分です。

int main(void){
	while(1){
		//問題ではn, m, t, pとして与えられますが、
		//nはw、mはhとして変数を用意します。
		int w, h, t, p; 
		scanf(" %d %d %d %d", &w, &h, &t, &p);
		if(!w && !h && !t && !p) break;

		//2次元配列は行列のように、i行j列(kami[i][j])として考えます。
		//そのため、座標(x, y)は kami[y][x] となります。
		int kami[MAX][MAX] = {0};
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				kami[i][j] = 1;//折り紙が存在する部分を1で初期化
			}
		}

		int origin_x = 0, origin_y =0; //折り紙左上の角の座標を原点として記憶(kami[origin_y][origin_x])
		for(int k=0; k<t; k++){
			int d, c;
			scanf(" %d %d", &d, &c);

			if(d == 1){
				//もし d が 1 なら，左端から c だけ右側を通る垂直の折り線の左側を右側に折り重ねる．
				int dist = 1; //distは折られる前の座標と、折る先の座標の差の絶対値。
				for(int j=origin_x+c; j<origin_x+(2*c); j++){	//折られる先のx座標
					for(int i=origin_y; i<MAX; i++){	//垂直方向に折るループ
						kami[i][j] += kami[i][j-dist];
					}
					dist += 2;
				}
				origin_x += c;
			} else{
				//このプログラムの場合は、上下を入れ替えています。
				//	→もし d が 2 なら，上端から c だけ下側を通る水平の折り線の上側を下側に折り重ねる。
				int dist = 1; //distは折られる前の座標と、折る先の座標の差の絶対値。
				for(int i=origin_y+c; i<origin_y+(2*c); i++){	//折られる先のy座標
					for(int j=origin_x; j<MAX; j++){	//水平方向に折るループ
						kami[i][j] += kami[i-dist][j];
					}
					dist += 2;
				}
				origin_y += c;
			}
		}

		for(int k=0; k<p; k++){
			int x, y;
			scanf(" %d %d", &x, &y);
			printf("%d\n", kami[origin_y+y][origin_x+x]);
		}
	}

	return 0;
}


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

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    bool nsort=true;
    int sc=0;
    while (nsort){
        nsort=false;
        for (int i = 0; i < n-1; ++i) {
            if(a[i]>a[i+1]){
                int t=a[i];
                a[i]=a[i+1];
                a[i+1]=t;
                nsort=true;
                ++sc;
            }
        }
    }
    for (int i = 0; i < n-1; ++i) {
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<sc<<endl;
    return 0;
}


Measured memory_bytes: 3080