akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll h,w,KKK;
    cin >> h >> w >> KKK;
    vector<vector<char>> c(h, vector<char>(w));
    rep(i,h){
        rep(j,w) cin >> c.at(i).at(j);
    }
    vector<char> dummy(w,'0');
    ll res = 0;
    rep(i,1<<h){
        vector<vector<char>> c2(h, vector<char>(w));
        vector<vector<char>> c3(h, vector<char>(w));
        c2 = c;
        rep(j,h){
            if(i>>j&1) c2.at(j) = dummy;
        }
        rep(k,1<<w){
            c3 = c2;
            rep(l,w){
                if(k>>l&1){
                    rep(m,h){
                        c3.at(m).at(l) = '0';
                    }
                }
            }
                ll temp = 0;
                rep(n,h){
                    rep(o,w){
                        if(c3.at(n).at(o)=='#') temp++;
                    }
                }
                if(temp==KKK) res++;
        }
    }
    cout << res << endl;
}

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

using namespace std;

using ll = long long;
const int N = 1e5 + 5;

int n;

int main()
{
    std::ios::sync_with_stdio(false);
    while (cin >> n)
    {
        if (n == 7 || n == 5 || n == 3)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}


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

using ll = long long;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> start(n+1);
  vector<int> end(n+1);
  for(int i = 0; i < m; i++){
    int a,b;
    cin >> a >> b;
    if(a == 1){
      start.at(b) = 1;
    }
    if(b == n){
      end.at(a) = 1;
    }
  }
  for(int i = 0; i < n+1; i++){
    if(start.at(i) == 1 && end.at(i) == 1){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 4808
#include<cstdio>
#include<algorithm>
#define ull unsigned long long
using namespace std;
ull f[40][10],n,t;//f[i][j]表示长度为i位，最高位为j时的方案数 

void output(int x,int y)
{
	putchar(y+'0');
	--x;
	
	while(x)
	{
		ull tmp=0,k;
		for(k=max(0,y-1);k<=min(9,y+1);++k)
		{
			tmp+=f[x][k];
			if(tmp>=n)
			{
				tmp-=f[x][k];
				n-=tmp;
				
				break;
			}
		}
		putchar(k+'0');
		y=k;--x;
	}
}

int main()
{
	scanf("%llu",&n);
	
	for(int j=0;j<=9;++j)
	{
		++f[1][j];
		if(j>0)
		{
			++t;
			if(t>=n)
			{
				t-=f[1][j];
				n-=t;
				
				output(1,j);return 0;
			}
		}
	}
	
	for(int i=2;;++i)
	{
		for(int j=0;j<=9;++j)
		{
			for(int k=max(0,j-1);k<=min(9,j+1);++k)f[i][j]+=f[i-1][k];
			if(j>0)
			{
				t+=f[i][j];
				if(t>=n)
				{
					t-=f[i][j];
					n-=t;
					
					output(i,j);return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 128
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
a = inl()
five = 0
seven = 0
for c in a:
    if c == 5:
        five += 1
    elif c == 7:
        seven+= 1
if five == 2 and seven == 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9080
#include <stdio.h>
#include <string.h>

int main()
{
    int n;
    int i;
    char taro[100+1], hanako[100+1];
    int scores[2] = {0, 0};
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%s %s", taro, hanako);
        if(strcmp(taro, hanako) == 0) {
            scores[0] += 1;
            scores[1] += 1;
        } else if(strcmp(taro, hanako) < 0) {
            scores[1] += 3;
        } else {
            scores[0] += 3;
        }
    }
    printf("%d %d\n", scores[0], scores[1]);
    return 0;
}


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

#define maxn 100005
#define NIL -1

struct Node {int p,l,r;};


Node T[maxn];
int n,D[maxn];

void print(int u){
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<D[u]<<", ";

    if(T[u].p==NIL) cout<<"root, ";
    else if(T[u].l==NIL) cout<<"leaf, ";
    else cout<<"internal node, ";

    cout<<"[";

    for(int i=0,c=T[u].l; c!=NIL; i++,c=T[c].r){
        if(i) cout<<", ";
        cout<<c;
    }
    cout<< "]"<<endl;
}

int rec(int u,int p){
    D[u]=p;
    if(T[u].r!=NIL) rec(T[u].r,p);
    if(T[u].l!=NIL) rec(T[u].l,p+1);
}

int main(){
    //freopen("data.in","r",stdin);
    cin>>n;
    for(int i=0;i<n;i++) T[i].p=T[i].l=T[i].r=NIL;

    int l,c,v,d,r;
    for(int i=0;i<n;i++){
        cin>>v>>d;
        for(int j=0;j<d;j++){
            cin>>c;
            if(j==0) T[v].l=c;
            else T[l].r=c;
            l=c; // this l is for record last node;
            T[c].p=v;
        }
    }

    for(int i=0;i<n;i++){
        if(T[i].p==NIL) r=i;
    }

    rec(r,0);

    for(int i=0;i<n;i++) print(i);

    return 0;
}

Measured memory_bytes: 7756
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int a[10], b[10];
void r1() {
	b[7] = b[1];
	b[1] = b[2];
	b[2] = b[6];
	b[6] = b[5];
	b[5] = b[7];
	return;
}
void r2() {
	b[7] = b[2];
	b[2] = b[3];
	b[3] = b[5];
	b[5] = b[4];
	b[4] = b[7];
	return;
}
bool bf() {
	for (int i = 1; i <= 6; i++)if (a[i] != b[i])return 0; return 1;
}
signed main() {
	for (int i = 1; i <= 6; i++)cin >> a[i];
	for (int i = 1; i <= 6; i++)cin >> b[i];
	bool bt = 0;
	//1
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	//2
	r1();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	//3
	r1();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	//4
	r1();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	//5
	r2(); r1();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	//6
	r1(); r1();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	if (bf())bt = 1; r2();
	cout << (bt ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
string s;
int q;
deque<char> t;
signed main(){
	 cin>>s>>q;
	 rep(i,s.size())t.push_back(s[i]);
	 int cnt=0;
	 rep(i,q){
	 	int T;
	 	cin>>T;
	 	if(T==1){
	 		cnt++;
	 	}
	 	else{
	 		int f;char c;
	 		cin>>f>>c;
	 		if(cnt%2==0){
	 			if(f==1)t.push_front(c);
	 			else t.push_back(c);
	 		}
	 		else{
	 			if(f==1)t.push_back(c);
	 			else t.push_front(c);
	 		}
	 	}
	 }
	 if(cnt%2==1)reverse(t.begin(),t.end());
	 rep(i,t.size()){
	 	cout<<t[i];
	 }
	 cout<<endl;
}


Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 2 * 1e5 + 5;
const int INF = 1e9;

int n;
long long c;
long long a[2 * MAXN];

long long _abs(long long f)
{
    if(f < 0) return -f;
    return f;
}

struct Sol
{
    int x;
    long long sum;

    long long get_sum(int y)
    {
        long long g = _abs(a[x] - a[y]);
        long long temp = (g * g) + c;
        return sum + temp;
    }

    Sol(){};
    Sol(int _x, long long _sum)
    {
        x = _x; sum = _sum;
    }

    int to(Sol other)
    {
        int l = max(x, other.x);
        int r = n;
        int ans = INF;

        while(l <= r)
        {
            int middle = (l + r) / 2;

            if(get_sum(middle) >= other.get_sum(middle))
            {
                ans = middle;
                r = middle - 1;
            }
            else
            {
                l = middle + 1;
            }
        }
        return ans;
    }
};

void read_input()
{
    scanf("%d %lld", &n, &c);

    for(int i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
}

Sol T[2 * MAXN];

void solve()
{
    int fptr = 0, bptr = 0;

    T[bptr++] = Sol(1, 0);

    for(int i = 2; i <= n; i++)
    {
        while(fptr + 1 < bptr && T[fptr].get_sum(i) >= T[fptr + 1].get_sum(i)) fptr++;

        Sol temp = Sol(i, T[fptr].get_sum(i));

        while(bptr - fptr >= 2 && T[bptr - 2].to(T[bptr - 1]) >= T[bptr - 1].to(temp)) bptr--;

        if(bptr - fptr >= 2 && T[bptr - 2].to(temp) != INF)
        {
            T[bptr++] = temp;
        }
        else if(bptr - fptr <= 1)
        {
            T[bptr++] = temp;
        }
    }

    printf("%lld\n", T[bptr - 1].sum);
}

int main()
{
    read_input();
    solve();

    return 0;
}


Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

using namespace std;

int main(){
	int a;
	cin>>a;
	if(a%10==9||a/10==9){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, M, X = map(int, input().split())
lst = [tuple(map(int, input().split())) for _ in range(N)]


INF = 10 ** 18
ans = INF

for i in range(1, 2 ** N):
    cost = 0
    tmp = [0] * M
    for j in range(N):
        if (i >> j) & 1: #買う
            cost += lst[j][0]
            for k in range(M):
                tmp[k] += lst[j][k + 1]
    
    min_  = min(tmp)
    if min_ >= X:
        ans = min(ans, cost)

if ans == INF:
    print (-1)
else:
    print (ans)

Measured memory_bytes: 9228
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	string s;
	cin >> s;
	int x1=0, x2=0;
	for (int i = 0; i < s.size()-1; i++) {
		if (s[i] ==s[i+1]&&s[i+1]=='1') {
			s[i + 1] = '0';
			x1++;
		}
		if (s[i] == s[i + 1] && s[i + 1] == '0') {
			s[i + 1] = '1';
			x1++;
		}
	}
	for (int i = s.size()-1; i ==0; i--) {
		if (s[i] == s[i + 1] && s[i + 1] == '1') {
			s[i + 1] = '0';
			x2++;
		}
		if (s[i] == s[i + 1] && s[i + 1] == '0') {
			s[i + 1] = '1';
			x2++;
		}
	}
	cout << max(x1, x2) << endl;
}


Measured memory_bytes: 512
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1,-1):
    for j in range(i-1,0,-1):
        x = L[i]-L[j]
        maxindex = bisect.bisect_right(L, x)
        if j>maxindex:
            ans += j-maxindex

print(ans)


Measured memory_bytes: 9252
/*
    一般に3次元imosはバグの元なんじゃ
  */

#include <cstdio>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef pair<pair<int, int>, int> Coor;
#define make_coor(x, y, z) make_pair(make_pair((x), (y)), (z))
#define get_coor(c, x, y, z)\
    do {\
        x = (c).first.first;\
        y = (c).first.second;\
        z = (c).second;\
    } while(0)

int area[401][401][401];
int n;
int g;
vector<int> newx;
vector<int> newy;
vector<int> newz;
vector<pair<Coor, Coor> > points;
map<int, int> revx;
map<int, int> revy;
map<int, int> revz;
long long int xval;
long long int yval;
long long int zval;
long long int ans;

int main() {
    scanf("%d %d", &n, &g);
    for (int i=0; i<n; i++) {
        int x1, x2;
        int y1, y2;
        int z1, z2;
        Coor c, c2;

        scanf("%d %d %d %d %d %d", &x1, &y1, &z1, &x2, &y2, &z2);
        newx.push_back(x1);
        newx.push_back(x2);
        newy.push_back(y1);
        newy.push_back(y2);
        newz.push_back(z1);
        newz.push_back(z2);

        c = make_coor(x1, y1, z1);
        c2 = make_coor(x2, y2, z2);
        points.push_back(make_pair(c, c2));
    }

    sort(newx.begin(), newx.end());
    sort(newy.begin(), newy.end());
    sort(newz.begin(), newz.end());
    newx.erase(unique(newx.begin(), newx.end()), newx.end());
    newy.erase(unique(newy.begin(), newy.end()), newy.end());
    newz.erase(unique(newz.begin(), newz.end()), newz.end());
    for (int i=0; i<newx.size(); i++) {
        revx[newx[i]] = i;
    }

    for (int i=0; i<newy.size(); i++) {
        revy[newy[i]] = i;
    }

    for (int i=0; i<newz.size(); i++) {
        revz[newz[i]] = i;
    }

    for (int uni=0; uni<points.size(); uni++) {
        pair<Coor, Coor> p = points[uni];
        Coor c = p.first;
        Coor c2 = p.second;
        int x, y, z;
        int x2, y2, z2;

        get_coor(c, x, y, z);
        get_coor(c2, x2, y2, z2);
        x = revx[x];
        x2 = revx[x2];
        y = revy[y];
        y2 = revy[y2];
        z = revz[z];
        z2 = revz[z2];

        for (int i=x; i<x2; i++) {
            for (int j=y; j<y2; j++) {
                for (int k=z; k<z2; k++) {
                    ++area[i][j][k];
                }
            }
        }
    }

    for (int i=0; i<newx.size()-1; i++) {
        for (int j=0; j<newy.size()-1; j++){
            for (int k=0; k<newz.size()-1; k++) {
                if (area[i][j][k] >= g) {
                    xval = newx[i+1] - newx[i];
                    yval = newy[j+1] - newy[j];
                    zval = newz[k+1] - newz[k];
                    ans += xval * yval * zval;
                }
            }
        }  
    }

    printf("%lld\n", ans);
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    string n;
    cin >> n;

    map<char, char> mp;
    mp['1'] = '9';
    mp['9'] = '1';
    for (int i = 0; i < 3; i++) {
        cout << mp[n[i]];
    }
    cout << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(i=(a);i<(b);i++)
#define fi first
#define se second
#define pb push_back 
#define mp make_pair
using namespace std;



int co[40000][17],c[50],dp[40000][17],num,sum1,x,y,z,sum2,x1,x2,len,b[50],a[20][20],i,j,k,n,m,d[50],t;
//map<pair<int,int>,int> cost;

int cost(int a,int b){
	int res=0;
	for(int ii=1;ii<=n;ii++) if ((1<<(ii-1))&b) res+=co[a][ii];
	return res;
}


int main(){
	scanf("%d%d",&n,&m);
	rep(i,0,m) {
		scanf("%d%d%d",&x,&y,&z);
		a[x][y]=z;
		a[y][x]=z;
	}
	rep(i,1,1<<n){
/*		x=i;len=0;
		while (len<n) {
			len++;b[len]=x%3;x/=3;
		}
		x1=0;x2=0;sum1=0;sum2=0;num=0;
		rep(j,1,len+1) {
			if (b[j]==1) {x1++;c[x1]=j;sum1+=1<<(j-1);}else
				if (b[j]==2) {x2++;d[x2]=j;sum2+=1<<(j-1);}
		}
		rep(j,1,x1+1) 
			rep(k,1,x2+1) num+=a[c[j]][d[k]];
			cost[mp(sum1,sum2)]=num*/
		rep(j,1,n+1) if (((1<<(j-1))&i)==0) {
			num=0;
			rep(k,1,n+1) if (((1<<(k-1))&i)) num+=a[j][k];
			co[i][j]=num;
		}
			
	}
	rep(i,1,1<<n) rep(j,1,n+1) dp[i][j]=1<<30;
	dp[1][1]=0;
	rep(i,1,(1<<n)){
		rep(j,1,n+1) if ((1<<(j-1))&i){
			rep(k,1,n+1) if (((1<<(k-1)&i)==0) && a[j][k]>0) 
				dp[i+(1<<(k-1))][k]=min(dp[i+(1<<(k-1))][k],dp[i][j]+cost(i-(1<<(j-1)),1<<(k-1)));
				x=((1<<n)-1)^i;
				for (t=x;t>0;t=(t-1)&x)	dp[i+t][j]=min(dp[i+t][j],dp[i][j]+cost(i-(1<<(j-1)),t));			
		}
	//	printf("%d\n",i);
	}
//	printf("%d %d %d %d %d\n",dp[1][1],dp[7][2],dp[14][4],dp[3][4],cost[mp(1,2)]);
	printf("%d",dp[(1<<n)-1][n]);

}

Measured memory_bytes: 5120
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
fir = []
sec = []

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        fir.append(b)
    elif a == n:
        sec.append(b)
    if b == 1:
        fir.append(a)
    elif b == n:
        sec.append(a)
fir.sort()
sec.sort()
flag = True
for i in fir:
    j = 0
    while flag and sec:
        if i > sec[j]:
            del sec[j]
        elif i == sec[j]:
            print("POSSIBLE")
            flag = False
        else:
            break
if flag == True:
    print("IMPOSSIBLE")

Measured memory_bytes: 11440
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,cnt[105],a[105],mx;

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i]; cnt[a[i]]++; mx=max(mx,a[i]);
    }
    for(int i=mx;i>=(mx+1)/2+1;i--){
        if(cnt[i]<2){
            cout << "Impossible";
            return 0;
        }
    }
    if(cnt[(mx+1)/2]!=1+mx%2){
        cout << "Impossible";
        return 0;
    }
    for(int i=(mx+1)/2-1;i>0;i--){
        if(cnt[i]){
            cout << "Impossible";
            return 0;
        }
    }
    cout << "Possible";
}


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

int main() {
    string s; cin >> s;
    ll ans = 1LL << 60;
    for (ll i = 0; i < s.size()-1; i++) {
        if (s[i] != s[i+1]) {
            ll val = max(i+1, (ll)s.size()-i-1LL);
            ans = min(ans, val);
        }
    }
    if (ans != 1LL << 60) cout << ans << endl;
    else cout << s.size() << endl;
}

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

using namespace std;

int main(){
	int n,d[2] = {0},c = 0,b = 0;
	string s;
	cin >> n >> s;
	
	
	for(int i = 0; i < n; i++){
		if(s[i] == '('){
			d[0]++;
		}
		else{
			if(d[0] != 0){
				d[0]--; 
			}
			else{
				d[1]++;
			}
		}
	}
	
	
	for(int i = 0; i < d[1]; i++)
		cout << '(';
	cout << s;
	for(int i = 0; i < d[0]; i++){
		cout << ')' ;
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        //入力値を設定する
        Integer firstNum = sc.nextInt();
        Integer secondNum = sc.nextInt();
        Integer thirdNum = sc.nextInt();
        
        if(firstNum + secondNum + thirdNum <= 21) {
            System.out.println("win");
        } else {
            System.out.println("bust");
        }

    }    
}


Measured memory_bytes: 21844
N, L = map(int, input().split())

first = L
end = N + L -1
 

if first>=0:
    print((first+1 + end)*(N-1)//2)
elif (first<=0 and end>=0):
    print((first+end)*N//2)
else:
    print((first + end -1)*(N-1)//2)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
using namespace std;

int INF=1e9;

int main(){
  int n,q;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
      cin>>a[i];
  }
  cin>>q;
  int com,b,e;
  int ans;
  int MAX=-INF,MIN=INF;
  for(int i=0;i<q;i++){
  cin>>com>>b>>e;
  if(com){
      ans=MAX;
      for(int i=b;i<e;i++){
          ans=max(a[i],ans);
      }
    }
   if(com==0){
       ans=MIN;
       for(int i=b;i<e;i++){
           ans=min(a[i],ans);
       }
    }
   cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3100
'use strict'

function Main(input) {
    const nums = input.split('\n')[1].split(' ').map(n => Number(n));
    let count = 0;
    for (let i = 0; i < nums.length; i++) {
      if (nums[i] === i + 1) {
        let tmp = nums[i + 1];
        if(tmp) {
          nums[i + 1] = nums[i];
          nums[i] = tmp;
          count += 1;
        } else {
          tmp = nums[i];
          nums[i] = nums[i - 1];
          nums[i - 1] = tmp;
          count += 1;
        }
      }
    }
    console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 16716
n  =int(input())
p = list(map(int, input().split()))

counter = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        counter += 1

print(counter)

Measured memory_bytes: 9132
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use smallvec::alloc::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
    n: usize,
    mut m: usize,
    a: [usize; n]
    }
    let mut heap = BinaryHeap::from(a);
    for _ in 0..m {
        let t = heap.pop().unwrap() / 2;
        heap.push(t)
    }
    let mut ans = 0;
    while !heap.is_empty() {
        ans += heap.pop().unwrap();
    }
    println!("{}", ans);
}


Measured memory_bytes: 3732
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto sa = readln.chomp;
    auto sb = readln.chomp;
    auto sc = readln.chomp;

    char t = 'a';
    for (;;) {
        switch (t) {
            case 'a':
                if (sa.empty) {
                    writeln("A");
                    return;
                }
                t = sa[0];
                sa = sa[1..$];
                break;
            case 'b':
                if (sb.empty) {
                    writeln("B");
                    return;
                }
                t = sb[0];
                sb = sb[1..$];
                break;
            case 'c':
                if (sc.empty) {
                    writeln("C");
                    return;
                }
                t = sc[0];
                sc = sc[1..$];
                break;
            default:
                return;
        }
    }
}

Measured memory_bytes: 256
n = int(input())
sl = list(input() for _ in range(n))
alf = "abcdefghijklmnopqrstuvwxyz"
alfl =[51]*26

for i in range(26):
    for j in range(n):
        t = sl[j].count(alf[i])
        alfl[i] = min(t,alfl[i])

res = ""

for k in range(26):
    res += alf[k]*alfl[k]
print(res)

Measured memory_bytes: 3188
#include<stdio.h>
main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int e=0;
  int f=0;
  int g=0;
  while(scanf("%d",&a)!=EOF){
    for(b=9;b>=0;b--){
      for(c=9;c>=0;c--){
	for(d=9;d>=0;d--){
	  for(e=9;e>=0;e--){
	    f=b+c+d+e;
	    if(f==a){
	      g=g+1;
	    }
	  }
	}
      }
    }
    printf("%d\n",g);
    f=0;
    g=0;
  }
  return 0;
}

Measured memory_bytes: 596
n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18
if n % 2:
    dp = [[[-INF,-INF,-INF] for i in range(2)] for i in range(n+1)]
    dp[0][0][0] = 0
    # 初期化条件考える
    for i,v in enumerate(a):
        for j in range(2):
            if j:
                dp[i+1][0][0] = max(dp[i+1][0][0],dp[i][1][0])
                dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][1][1])
                dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][1][2])
            else:
                dp[i+1][1][0] = max(dp[i+1][1][0],dp[i][0][0] + v)
                dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][0][0])
                dp[i+1][1][1] = max(dp[i+1][1][1],dp[i][0][1] + v)
                dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][0][1])
                dp[i+1][1][2] = max(dp[i+1][1][2],dp[i][0][2] + v)
    print(max(max(dp[n][0]),max(dp[n][1][1:])))
else:
    odd_sum,even_sum = 0,0
    cumsum = []
    for k,v in enumerate(a):
        if k % 2:
            odd_sum += v
            cumsum.append(odd_sum)
        else:
            even_sum += v
            cumsum.append(even_sum)
    ans = max(cumsum[n-2],cumsum[n-1])
    for i in range(2,n,2):
        ans = max(ans, cumsum[i-2]+cumsum[n-1]-cumsum[i-1])
    print(ans)

Measured memory_bytes: 152496
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#include <math.h>

int r;
double solve(){
   return 2*M_PI*r;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>r;
    cout<<setprecision(23)<<solve()<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int sum = 0;
  
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  
  int mini = sum;
  int prefix_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    prefix_sum += a[i];
    mini = min(mini, abs(prefix_sum - (sum - prefix_sum)));
  }
  
  cout << mini << endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
	}
	s := a[0]
	ans := 0
	if s == 0 && a[1] > 0 {
		s = -1
		ans += 1
	} else if s == 0 && a[1] < 0 {
		s = 1
		ans += 1
	}
	for i := 1; i < n; i++ {
		t := s + a[i]
		if s < 0 && t < 0 {
			ans += 1 - t
			s = 1
		} else if s > 0 && t > 0 {
			ans += t + 1
			s = -1
		} else if s < 0 && t == 0 {
			ans += 1
			s = 1
		} else if s > 0 && t == 0 {
			ans += 1
			s = -1
		} else {
			s = t
		}
	}
	s = a[0]
	ans2 := 0
	if s > 0 {
		s = -1
		ans2 += a[0] + 1
	} else if s < 0 {
		s = 1
		ans2 += 1 - a[0]
	} else if s == 0 && a[1] > 0 {
		s = 1
		ans2 += 1
	} else if s == 0 && a[1] < 0 {
		s = -1
		ans2 += 1
	}
	for i := 1; i < n; i++ {
		t := s + a[i]
		if s < 0 && t < 0 {
			ans2 += 1 - t
			s = 1
		} else if s > 0 && t > 0 {
			ans2 += t + 1
			s = -1
		} else if s < 0 && t == 0 {
			ans2 += 1
			s = 1
		} else if s > 0 && t == 0 {
			ans2 += 1
			s = -1
		} else {
			s = t
		}
	}
	fmt.Println(smaller(ans, ans2))
}
func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}


Measured memory_bytes: 3072
irow , jcol = gets.split.map(&:to_i)
irowlist = []
table = Array.new(irow).map{Array.new(jcol,0)}

irow.times do |i|
    input = gets.to_s.chomp
    input.length.times do |j|
        table[i][j] = input.slice(j)
    end
end

for i in 0...irow do
    if table[i].all? {|w| w == '.'}
        for j in 0...jcol do
            table[i][j] = nil
        end
    end
end

for j in 0...jcol do
    work = true
    for i in 0...irow do
        if !(table[i][j] == '.' || table[i][j] == nil)
            work = false
        end
    end

    if work == true
        for i in 0...irow do
            table[i][j] = nil
        end
    end
end

for i in 0...irow do
    compactTable = table[i].compact
    if !compactTable.empty?
        puts compactTable.join("")
    end
end


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
int n;
int a[maxn],b[maxn];
pii val[maxn*2];
bool occ[maxn];

int main(){
	scanf("%d",&n);
	ll suma=0,sumb=0;
	REP(i,n){
		scanf("%d%d",&a[i],&b[i]);
		val[i]=mp(a[i],i);
		val[i+n]=mp(b[i],i);
		suma+=a[i];
		sumb+=b[i];
	}
	sort(val+1,val+1+2*n);
	ll ans=0;
	int tot=0,cnt=0,spe=0;
	REP(i,2*n){
		int id=val[i].snd;
		if(tot==n-1&&cnt==n-1&&!occ[id]){
			spe=id;
			continue;
		}
		if(!occ[id]){
			cnt++;
			occ[id]=true;
		}
		ans+=val[i].fst;
		tot++;
		if(tot==n)break;
	}
	if(spe){
		ll ans2=a[spe]+b[spe];
		REP(i,n-2)ans2+=val[i].fst;
		ans=min(ans,ans2);
	}
	printf("%lld\n",min(ans,min(suma,sumb)));
	return 0;
}

Measured memory_bytes: 2688
#include<stdio.h>
#define N 100000

int S[N],n;

int BinarySearch(int flag){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid = (left+right)/2;
    if(flag==S[mid])return 1;
    if(flag>S[mid])left=mid+1;
    else if(flag<S[mid])right=mid;
  }
  return 0;
}

int main(){
  int i,q,flag,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&flag);
    if(BinarySearch(flag)==1)sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}


//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int k=1;
  while(k*2<=n){
    k*=2;
  }
  cout<<k<<endl;
  return 0;
}




Measured memory_bytes: 256
#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;
    cin >> n;
    vector<vector<int>> d(n);
    vector<int> used(n+1,0);
    map<int,int> m;
    int max_num=0;
    int max_ind=0;
    int vec_ind=0;
    rep(i,n){
        int p;
        cin >> p;
        if(used[p-1]==0){
            m.insert(make_pair(p,vec_ind));
            d[vec_ind].push_back(p);
            used[p]=1;
            if(max_num<d[vec_ind].size()) max_num=d[vec_ind].size();
            vec_ind++;
        }
        else{
            int ind = m.at(p-1);
            d[ind].push_back(p);
            m.insert(make_pair(p,ind));
            if(max_num<d[ind].size()) max_num=d[ind].size();
            used[p]=1;
        }
    }
    /*
    cout <<"vec" << endl;
    rep(i,d.size()){
        for(auto v:d[i]) cout << v << " ";
        cout << endl;
    }
    cout << "maxlen " << max_num << endl; 
    */
    cout << n-max_num << endl;


}

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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




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


int n,k;
cin>>n>>k;
vector<int>v(n);

for(int i=0;i<n;i++)
{
  cin>>v[i];
}

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

    int l = -2e18;
    int r = 2e18;
    int ans=-1e18;
    while(r-l>1)
    {
        int M = (l+r)/2;
        int cnt = 0;
        
        for(int i = 0; i<n; ++i)
        {
            int l = i, r = n; 
            while(r-l>1)
            {
                int m = (l+r)/2;
                if(v[i]*v[m]<=M)
                    (v[i]>0) ? l=m : r = m;
                else
                    (v[i]>0) ? r = m : l = m;
                
            }
            if(v[i]>0) cnt+=l-i;
            else cnt+=n-r;
        }
        (cnt<k)?l= M:r=M;
        
    }
    cout<<r<<"\n";
  
}



Measured memory_bytes: 1792
from fractions import gcd

a,b,c,d = map(int, input().split())

def lcm(c,d):
  return c*d//gcd(c,d)
a -= 1
lcm_ = lcm(c,d)
print(b-a - (b//c + b//d - a//c - a//d - (b//lcm_ -a//lcm_)))

Measured memory_bytes: 5048
import java.util.*;
class Main {
 
    
    public static void main(String[] str)
    {
    	Scanner s=new Scanner(System.in);
    	String s1=s.next();
    	String s2=s.next();
    	int n=s2.length();
    	int i=0;
    	String res=s2.substring(i,n-1);
    	if(res.equals(s1))
    	{
    		System.out.println("Yes");
    	}
    	else
    	{
    		System.out.println("No");
    	}
   
    	
    }
}

Measured memory_bytes: 35688
#include<bits/stdc++.h>
using namespace std;
int main(){
    bool b=0;
    int n,ans=0;
    string s;
    cin>>s;
    n=s.size();
    for(int i=0;i<n;i++){
        bool t;
        b=!b;
        if(s[i]=='g'){
            t=1;
        }else if(s[i]=='p'){
            t=0;
        }
        if(t==b){
            continue;
        }else if(t==1&&b==0){
            ans++;
        }else{
            ans--;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    X=ii()

    i = 1
    yen = 100
    while yen < X:
        r =  yen // 100
        yen += r
        i += 1

    print(i-1)




if __name__ == "__main__":
    main()

Measured memory_bytes: 62016
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define int long long
#define ll long long
#define vel vector<int>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define veb vector<bool>
#define pin pair<int,int>
#define mkp make_pair
#define mot pair<D,D>//time,dist
#define root pair<int,mot>
using namespace std;
vvel ta_min(0);
vvel ta_max(0);
int leth = 1024 * 512;
int siz = leth * 2;
void mmax(ll &a, ll b) { a = max(a, b); }
void mmin(ll &a, ll b) { a = min(a, b); }
int sum(int n) {
	if (n == 0) { return 0; }
	return n % 10 + sum(n / 10);
}
signed main() {
	int n; cin >> n;
	vel sum(n + 1,0);
	for (int i = 0; i < n; i++) { int a; cin >> a; sum[i + 1] = sum[i] + a; }
	sort(sum.begin(), sum.end());
	int ans = 0;
	for (int i = 0; i <= n; i++) { ans += i-(lower_bound(sum.begin(), sum.end(), sum[i]) - sum.begin()); }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>

int	main()
{
	char S[3];
	int	ans = 0;

	scanf("%s", S);
	if (!strcmp(S, "RRR"))
		ans = 3;
	else if(!strcmp(S, "RRS"))
		ans = 2;
	else if(!strcmp(S, "RSR"))
		ans = 1;
	else if(!strcmp(S, "RSS"))
		ans = 1;
	else if(!strcmp(S, "SRR"))
		ans = 2;
	else if(!strcmp(S, "SRS"))
		ans = 1;
	else if(!strcmp(S, "SSR"))
		ans = 1;
	else if(!strcmp(S, "SSS"))
		ans = 0;
	printf("%d\n", ans);
	return (0);
}


Measured memory_bytes: 1732
package main

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

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func decidePrice(age, price int) int {
	switch {
	case age >= 13:
		return price
	case age >= 6 && age <= 12:
		return price / 2
	default:
		return 0
	}
}

func main() {
	a, b := nextInt(), nextInt()
	p := decidePrice(a, b)
	fmt.Println(p)
}


Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int s, m, h;
    scanf("%d", &s);
    m = s/60;
    h = m/60;
    s = s%60;
    m = m%60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  
  vector<int> card(n);
  for (int i = 0; i < n; i++){
    cin >> card.at(i);
  }
  
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  
  int a = 0, b = 0;
  
  for (int i = 0; i < n; i++){
    if (i % 2 == 0)
      a += card.at(i);
    else
      b += card.at(i);
  }
  
  cout << a-b << endl;
}
  
  


Measured memory_bytes: 256
import math
a,b,C = map(float, input().split())
C = math.radians(C)
h = b * math.sin(C)
S = a * h * .5
L = a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(C))
print("{0:.6f}\n{1:.6f}\n{2:.6f}".format(S,L,h))

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

int main() {
  string S;
  cin >> S;
  
  int c0,c1 =0;
  for(char i: S) {
    if(i == '0') ++c0;
    else ++c1;
  }
  
  cout << 2 * min(c0,c1) << endl;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    int l,r,d;
    cin>>l>>r>>d;

    int ans=0;

    rep2(i,l,r){
        if(i%d==0)ans++;
    }

    cout<<ans<<endl;


}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int x_2000 = Integer.parseInt(sc.next());
        int[] x = new int[11];
        x[0] = x_2000;

        for(int i = 1; i < 11; i++){
            x[i] = r * x[i - 1] - d;
        }

        for(int i = 1; i < 10; i++){
            System.out.println("" + x[i] + "\n");
        }
        System.out.println(x[10]);
    }
}


Measured memory_bytes: 22608
def main():
    O = list(input())
    E = list(input())
    O.reverse()
    E.reverse()
    ans = ''
    for _ in range(200):
        ans += O.pop()
        if len(E) == 0:
            break
        ans += E.pop()
        if len(O) == 0:
            break
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9020
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    if (Math.abs(a - b) <= d && Math.abs(b - c) <= d) {
      System.out.println("Yes");
    } else if (Math.abs(a - c) <= d) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 23764
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,M;
	cin >> N>>M;
	ll X[M];
	for (ll i = 0; i < M; ++i) cin >> X[i];
 
	// 解法
	sort(X,X+M);
	ll gap[M];
	if (M>1){
		REP(i,M-1){
			gap[i] = X[i+1] - X[i];
		}
	}
	// REP(i,M) printf("%lld ", X[i]);printf("\n");
	// REP(i,M-1) printf("%lld ", gap[i]);printf("\n");
	sort(gap,gap+M-1, greater<ll>());
	ll ans = 0;
	ans = X[M-1] - X[0];
	// cout << ans<<endl;
	if (N>1 & N<M) REP(i,N-1) ans -= gap[i];
	if (N>=M) cout<<0<<endl;
	else cout << ans<<endl;
}


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

int main(){
    int N, L, Max = 0, sum = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> L;
        if(Max < L){
            sum += Max;
            Max = L;
        }else{
            sum += L;
        }
    }
    if(sum > Max) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};
use std::collections::BinaryHeap;
use std::collections::VecDeque;

fn main() {
    let x: usize = read();
    let y: usize = read();
    let z: usize = read();
    println!("{} {} {}", z, x, y);

}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define ll long long
#define mk make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
using namespace std;
const int MAXN=1e5+9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin>>k;
	string s;
	cin>>s;
	int n=s.size();
	if(n<=k)
	{
		cout<<s<<endl;
		return 0;
	}
	cout<<s.substr(0,k)+"..."<<endl;
	return 0;
}

Measured memory_bytes: 3652
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  vector <int> ans;
  for (int it = 0; it < n; it++) {
    bool good = false;
    for (int i = (int) a.size() - 1; i >= 0; i--) {
      if (a[i] == i) {
        ans.push_back(i);
        a.erase(a.begin() + i);
        good = true;
        break;
      }
    }
    if (!good) {
      cout << -1 << '\n';
      return 0;
    }
  }
  reverse(ans.begin(), ans.end());
  for (int x : ans) cout << x + 1 << '\n';
}


Measured memory_bytes: 256
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(a[K-1])

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> d(n);
    for (int i=0; i<n; i++) {
        cin >> d.at(i);
    }
    ll ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    map<string, int> m;
    int q, op, x;
    string s;
    
    cin >> q;
    while(q-- > 0){
        cin >> op;
        if(op == 0){
            cin >> s >> x;
            m[s] = x;
        }
        if(op == 1){
            cin >> s;
            cout << m[s] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 27888
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
a, b = map(int, input().split()) # 入力が複数

if a == b:
    print('Draw')
elif a == 1:
    print('Alice')
elif b == 1:
    print('Bob')
elif a > b:
    print('Alice')
else:
    print('Bob')

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

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

    int ans = 0;
    ans += 1000 * (X / 500);
    X -= 500 * (X / 500);
    ans += 5 * (X / 5);

    cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define PI 3.14159265359

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, x; cin>>a>>b>>x;
	if (a*a*b < x*2){
		ll rest = a*a*b-x;
		double beta = (double)rest*2/(a*a);
		double theta = atan2((double)beta, a);
		cout << setp(12) << theta*180.0/PI << "\n";
	}else{
		double alpha = (double)x*2/(b*a);
		double theta = atan2((double)b, alpha);
		cout << setp(12) << theta*180.0/PI << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){


int n;
cin>>n;
string s;
int ac=0,wa=0,tle=0,re=0;
for(int i=0;i<n;i++){
    cin>>s;
    if(s=="AC")
        ac++;
    else if(s=="WA")
        wa++;
    else if(s=="TLE")
        tle++;
    else
        re++;
}
cout<<"AC x "<<ac<<endl;
cout<<"WA x "<<wa<<endl;
cout<<"TLE x "<<tle<<endl;
cout<<"RE x "<<re<<endl;

return 0;
}


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

int main() {
 int a,b,c,k;
    cin >> a >>b>>c>>k;
    
    int count = 0;
  while (b<=a) {
      b *= 2;
      count++;
   }
    
    while(c<=b) {
     c *= 2;
    count++;
    }
    if(count >k) {
     cout << "No";
    } else {
    cout << "Yes";
    }
}

Measured memory_bytes: 3560
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    int N;
    cin>>N;
    N %= 100;
    N %= 10;
    if(N==3)cout<<"bon"<<endl;
    else if((N==1) | (N==6) | (N==0) | (N==8)) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}



Measured memory_bytes: 3624