akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
struct Node{
  int key;
  Node *right,*left,*parent;
};
Node *root,*NIL;
Node * find(Node *u,int k){
  while(u!= NIL && k !=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}
void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z = (Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
preorder(u->left);
preorder(u->right);
}
int main(){
  int n,i,x;
  string com;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    cin>>com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node *t=find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }else if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }
    else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}
      



Measured memory_bytes: 21928
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int a,b;

    cin>>a>>b;

    cout<<6-a-b<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define LEN 250
 
int A[LEN];

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
 
int main(){
  int n;
  int i;
 
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
 
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n)printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n)printf("right key = %d, ",A[right(i)]);
    puts("");
  }
 
  return 0;
}




Measured memory_bytes: 2112
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
    double r;
    cin >> r;
    //cout << (int)(a/b) << " " << (int)((int)a%(int)b) << " " << a/b << endl;
    printf("%.7f %.7f\n",(double)(r*r*M_PI),(double)(2*r*M_PI));
}



Measured memory_bytes: 3212
m[1<<20],v[1<<21],*d,*e,w,p[10],x,t,i,c;Q(y){m[y]&1&&v[y]<t?v[*++e=y]=v[x]+1:0;}main(n){scanf("%*d%d%d",&w,&n);for(x=w++;c=~getchar(x++);m[x]=c>12?p[c-13]=x,11:c)c=~c%88%35;for(;i<n;)for(d=e=v+(1<<20),t=++v[*e=p[i++]];c=v[p[i]],c<t;Q(x-1),Q(x+1),Q(x-w),Q(x+w))x=*d++;x=!printf("%d\n",c-n);}

Measured memory_bytes: 8536
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 100005;
#define sz(v) ((int)v.size())

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

struct func{
	lint out;
	lint B, A; // f(W) = max(W + B, A)
}val[MAXN];

vector<int> gph[MAXN];
int n, m, a[MAXN], b[MAXN];
int rev[MAXN];

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++){
		scanf("%d %d",&a[i],&b[i]);
		a[i] = max(a[i], b[i]);
	}
	vector<int> ord(n);
	iota(ord.begin(), ord.end(), 1);
	sort(ord.begin(), ord.end(), [&](const int &x, const int &y){
		return a[x] - b[x] < a[y] - b[y];
	});
	for(int i=0; i<sz(ord); i++) rev[ord[i]] = i;
	for(int i=0; i<m; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		s = rev[s]; e = rev[e];
		if(s > e) swap(s, e);
		gph[ord[e]].push_back(ord[s]);
	}
	disj.init(n);
	for(auto &x : ord){
		vector<func> vect;
		for(auto &i : gph[x]){
			int p = disj.find(i);
			if(disj.find(x) == p) continue;
			vect.push_back(val[p]);
			disj.uni(i, x);
		}
		lint bsum = 0;
		for(auto &i : vect) bsum += i.B;
		func ret = {(lint)1e18, b[x] + bsum, a[x] + bsum};
		for(auto &i : vect){
			lint cur_out = max(i.out + b[x], 1ll * a[x]);
			cur_out += bsum - i.B;
			ret.out = min(ret.out, cur_out);
		}
		if(vect.empty()) ret.out = a[x];
		val[disj.find(x)] = ret;
	}
	cout << val[disj.find(ord.back())].out << endl;
}


Measured memory_bytes: 10228
def abc():
    x1, y1, x2, y2 = map(int, input().split())
    dx = x2 - x1
    dy = y2 - y1
    x3 = x2 - dy
    y3 = y2 + dx

    dx = x3 - x2
    dy = y3 - y2
    x4 = x3 - dy
    y4 = y3 + dx

    print(x3, y3, x4, y4)


abc()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int fa[maxn];
int n,m;
ll num[maxn];
void init()
{
	repd(i,0,n)
	{
		fa[i]=i;
		num[i]=1;
	}
}
struct node
{
	int f;
	int t;
}b[maxn];
ll cnt[maxn];
int findpar(int x)
{
	if(x==fa[x])
	{
		return x;
	}else
	{
		fa[x]=findpar(fa[x]);
        num[x]=max(num[x],num[fa[x]]);
//		num[fa[x]]=max(num[x],num[fa[x]]);
		return fa[x];
	}
	// return x==fa[x]?x:fa[x]=findpar(f[x]);
}
void Merg(int x,int y)
{
	x=findpar(x);
	y=findpar(y);
	if(x!=y)
	{
		fa[x]=y;
		num[y]+=num[x];
	}
}
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n>>m;
	init();
	repd(i,1,m)
	{
		cin>>b[i].f>>b[i].t;
	}
	ll v;
	for(int i=m;i>=1;i--)
	{

		if(findpar(b[i].t)!=findpar(b[i].f))
		{
		    v=num[b[i].t]*num[b[i].f];
		    Merg(b[i].t,b[i].f);
			cnt[i]=v;
		}
	}
	ll ans=0;
	repd(i,1,m)
	{
		ans+=cnt[i];
		cout<<ans<<endl;
	}


    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


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

using namespace std;

long long solve(long long h) {
  if (h == 1) {
    return 1;
  }
  return 2 * solve(h / 2) + 1;
}

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

  long long h;
  cin >> h;
  cout << solve(h);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
// const ll Mod = 1e9 + 7;
const ll Mod = 1000000007;
const int mxN = 2e5 + 5;
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
ll power[mxN];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    power[0] = 1;
    for (int i = 1; i < mxN; i++) {
        power[i] = power[i - 1] * 2 % Mod;
    }
    int n;
    cin >> n;
    ll special = Mod - 1;
    map<pair<ll, ll>, pair<int, int>> mp;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if (a == 0LL && b == 0LL) {
            special++;
            continue;
        }
        if (make_pair(a, b) < make_pair(0ll, 0ll))
            a = -a, b = -b;
        ll g = gcd(abs(a), abs(b));
        a = a / g, b = b / g;
        if (b > 0)
            mp[{ a, b }].first++;
        else
            mp[{ -b, a }].second++;
    }

    ll ans = 1;
    for (auto& p : mp) {
        ans = ans * (power[p.second.first] + power[p.second.second] - 1) % Mod;
    }
    cout << (ans + special) % Mod << '\n';
}

Measured memory_bytes: 17584
import itertools

n, m, q = map(int, input().split())
abcd_list = [[int(i) for i in input().split()] for _ in range(q)]
ans = 0
for i in itertools.combinations_with_replacement(range(1, m+1), n):
  A = sorted(i)
  score = 0
  for a, b, c, d in abcd_list:
    if A[a-1] + c == A[b-1]:
      score += d
  ans = max(ans, score)
print(ans)

Measured memory_bytes: 9204
# coding: utf-8

import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    qA = []                     # (-t, -a, i)
    qB = []                     # (-t, -b, i)
    for i in range(N):
        a, b = MI()
        t = a + b
        heapq.heappush(qA, (-t, -a, i))
        heapq.heappush(qB, (-t, -b, i))

    tA, tB = 0, 0
    used = set()
    for x in range(N):
        if x % 2 == 0:
            # a
            while True:
                t, a, i = heapq.heappop(qA)
                if i not in used: break
            tA -= a
            used.add(i)
        else:
            # b
            while True:
                t, b, i = heapq.heappop(qB)
                if i not in used: break
            tB -= b
            used.add(i)

    return tA - tB


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 41820
#include<bits/stdc++.h>
using namespace std;
int dp[3][100005];

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int N;
    cin>>N;
    vector<int> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) {
        cin>>a[i]>>b[i]>>c[i];
    }

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i < N; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][N-1], dp[1][N-1]), dp[2][N-1]) <<endl;

    return 0;
}


Measured memory_bytes: 2560
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]

Yes = 0
for i in range(N-2):
    if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
        Yes = 1
        break

print('Yes') if Yes==1 else print('No')

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
ll a[200005];
char s[200005];
ll dp[200005]={0};
ll gow[200005]={0};
ll goc[200005]={0};
int main(void)
{
	ll n;
	scanf("%lld",&n);
	scanf("%s",s+1);
	ll ans=0;
	ll lef;
	for(ll i=1;i<=n;i++)
	{
		if(s[i]=='W') gow[i]++;
		gow[i]+=gow[i-1];
	}
	ll get=gow[n];
	for(ll i=n;i>=1;i--)
	{
		if(get==0) break;
		if(s[i]!='W')
		{
			ans++;
		}
		get--;
	}
	printf("%lld\n",ans);
}

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

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)


void func(long long A, long long B){
    int ans = -1;
    rep(i,10){
        long long num = (10*B)+i;
        if ((long long)(num*0.08) == A) {
           ans = num;
           break;
       } 
    }
    cout << ans << endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(A, B);
    return 0;
}


Measured memory_bytes: 256
# B - Qualification simulator

N, A, B = map(int, input().split())
S = list(str(input()))

total = 0
total_B = 0
for s in S:
    if s == 'a' and total < (A + B):
        total += 1
        print('Yes')
    elif s == 'b' and total < (A + B) and total_B < B:
        total += 1
        total_B += 1
        print('Yes')
    else:
        print('No')     

Measured memory_bytes: 4712
#include <stdio.h>

int main(void){

   int a;
   int b;
   int c;
   int d, e, f;
   int min;
   
   
   char buf1[30];
   fgets(buf1, 30, stdin);
   sscanf(buf1, "%d %d %d", &a, &b, &c);
   

   
   d = a + b;
   e = b + c;
   f = c + a;
   
   min = d;
   if (e < min) min = e;
   if (f < min) min = f;
   
   printf("%d", min);
   
   return 0;
}

Measured memory_bytes: 128
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define min3(a,b,c)     min(a,min(b,c))


int main(){ FastIO;

ll h,n,i,j,k,inf=INT_MAX;cin>>h>>n;
ll a[n],b[n];
for(i=0;i<n;i++) cin>>a[i]>>b[i];
ll dp[n+1][h+1];
for(i=0;i<n+1;i++)
{
	for(j=0;j<h+1;j++) dp[i][j]=inf;
}
for(i=1;i<n+1;i++)
{
	for(j=1;j<h+1;j++)
	{
		if(j-a[i-1]<=0) dp[i][j]=min(b[i-1],dp[i-1][j]);
		else dp[i][j]=min3(dp[i][j-a[i-1]]+b[i-1],dp[i-1][j-a[i-1]]+b[i-1],dp[i-1][j]);
	}
}
cout<<dp[n][h];


return 0;
}

Measured memory_bytes: 78464
// ABC 150-C
// 2020.1.11 bal4u

#include <stdio.h>
#include <string.h>

int K = 9;
char PP[10] = { 0, 1,2,3,4,5,6,7,8,9 };   // 0はダミ
//int *perm = PP + 1;                    // action()ではPP[1]から利用

/* 与えられた並び PP[] の次に大きい並べ替えを求める */
void next_perm()   // 順列の大きさはK
{
	int i, j, k, t;

	/* 上位桁のほうが下位桁よりも小さいところまで移動 */
	i = K; while (PP[i - 1] >= PP[i]) i--;

	/* 次の並べ替えがない */
	if (i == 1) return;

	/* PP[i-1]より値の大きい最も下位の桁をPP[j]とする */
	j = K; while (PP[i - 1] >= PP[j]) j--;

	/* PP[i-1]とPP[j]とを交換 */
	t = PP[i - 1], PP[i - 1] = PP[j], PP[j] = t;

	/* PP[i]から最下位までを逆順 */
	k = (K - i) >> 1; for (j = 0; j <= k; j++)
		t = PP[i + j], PP[i + j] = PP[K - j], PP[K - j] = t;
}

char P[10], Q[10];

int main()
{
	int i, N, n, x, y;
	
	scanf("%d", &N); K = N;
	for (i = 0; i < N; ++i) scanf("%d", P+i);
	for (i = 0; i < N; ++i) scanf("%d", Q+i);
	
	n = 0;
	for (i = 0; n < 2; ++i) {
		if (memcmp(PP+1, P, N) == 0) x = i, ++n;
		if (memcmp(PP+1, Q, N) == 0) y = i, ++n;
		next_perm();
	}
	x -= y;
	if (x < 0) x = -x;
	printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

int main() {
    int n; cin >> n;
    vint t(n+1,-inf), a(n+1,-inf);
    REP(i,n+1) cin >> t[i];
    rep(i,n) cin >> a[i];
    vector<int> det_t(n,-1), det_a(n,-1);
    vector<int> mx_t(n,-1), mx_a(n,-1);
    rep(i,n) {
        if (t[i] != t[i+1]) det_t[i] = t[i+1];
        else mx_t[i] = t[i+1];
    }
    for (int i = n-1; i >= 0; i--) {
        if (a[i] != a[i+1]) det_a[i] = a[i];
        else mx_a[i] = a[i+1];
    }
    mint ans = 1;
    rep(i,n) {
        if (det_t[i] == -1) {
            if (det_a[i] != -1) {
                if (det_a[i] > mx_t[i]) {
                    cout << 0 << endl;
                    return 0;
                }
            }
            if (det_a[i] == -1) {
                ans *= min(mx_a[i],mx_t[i]);
            }
        } 
        if (det_t[i] != -1) {
            if (det_a[i] != -1) {
                if (det_t[i] != det_a[i]) {
                    cout << 0 << endl;
                    return 0;
                }
            }
            if (det_a[i] == -1) {
                if (det_t[i] > mx_a[i]) {
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5588
#include <iostream>

using namespace std;

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

    int i = 0;
    string ans;
    while (n != 0) {
        if (n & 1) {
            ans += "1";
            if (i%2==0) n -= 1;
            else n += 1;
        }
        else ans += "0";
        n /= 2;
        i++;
    }
    if (ans == "") ans = "0";
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

//中身は0になっているはず
//ll dp[1919][1919][3019];

//配るDP
int main() {

    ll N, A; cin >> N >> A;
    vector<ll > card(N, 0);
    for(ll i = 0; i < N; i++){
        cin >> card[i];
    }
    vector<vector<vector<ll > > > dp(55, vector<vector<ll > >(55, vector<ll >(3019, 0)));
    //今までに何をいくつ配り、その時の総和を記録しておく
    //平均がAとすると平均A満たすある数Bは必ずAの倍数である
    //そのようなBをとる総和を考えてやると今までに配った全てのカードに対する平均記録しておかなくて良い
    dp[0][0][0] = 1;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        for(ll num = 0; num <= N; num++){
            //制約的に最大総和50*50が考えられるので余裕を持って3000
            for(ll sum = 0; sum <= 3000; sum++){
                if(dp[i][num][sum] == 0) continue;

                //そのカードを使わないとき
                dp[i+1][num][sum] += dp[i][num][sum];
                
                //カードを使う時
                ll tmp = dp[i][num][sum];
                ll new_sum = sum + card[i];
                ll new_num = num + 1;
                //平均値Aになるかの判定
                if(new_sum == new_num * A){
                    ans += tmp;
                }
                dp[i+1][new_num][new_sum] += tmp;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 73088
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int A,B,C;
  cin >> A >> B >> C;
  if((A==B && A!=C) || (A==C && A!=B) || (C==B && A!=C)){
    Yes
  }
  else No
  return 0;
}


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

int main(){
    int h,w;cin >>h>>w;
    int board[h][w];
    vector<vector<int>> ans;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >>board[i][j];
        }
    }
    for(int i=0;i<h-1;i++){
        for(int j=0;j<w;j++){
            if(board[i][j]%2==1){
                ans.push_back({i+1,j+1,i+2,j+1});
                board[i+1][j]++;
            }
        }
    }
    for(int j=0;j<w-1;j++){
        if(board[h-1][j]%2==1){
            ans.push_back({h,j+1,h,j+2});
            board[h-1][j+1]++;
        }
    }
    cout<<ans.size()<<endl;
    for(auto&& w:ans)cout<<w[0]<<" "<<w[1]<<" "<<w[2]<<" "<<w[3]<<endl;
}

Measured memory_bytes: 9904
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

const ll mod = 998244353;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	if(b == 0) return 1;
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll k, a, b;
	cin >> k >> a >> b;
	if(b - a >= 3) {
		if(k <= a-1) cout << k+1 << endl;
		ll now = a;
		k -= (a-1);
		now += (b-a) * (k / 2);
		now += (k%2);
		cout << now << endl;
	}
	else cout << k+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
 
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    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){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(ALL(a));
    vector<mint> two(n+1);
    two[0] = 1;
    rep(i,n) two[i+1] = two[i]*2;
    mint ans;
    rep(i,n){
        int l = i,r = n - 1 - i;
        mint now = two[r];
        if(r!=0) now += two[r-1] * r;
        now *= two[l];
        now *= a[i];
        ans += now;
    }
    ans *= two[n];
    cout << ans.x << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    int a; cin >> a; cout << a + a * a + a * a * a;
}


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

using namespace std;

const int INF = 1e9;

int ans = 0;

void up(int & x, int y)
{
    if(x < y)
    {
        x = y;
        if(ans < y)
            ans = y;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 ///   freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    vector <vector <int> > a(n, vector <int>(3));
    for(auto & v : a)
        for(int & x : v)
            cin >> x;

    vector <vector <int> > dp(n, vector <int>(3));
    for(int i = 0; i < 3; ++i)
        up(dp[0][i], a[0][i]);
    for(int i = 1; i < n; ++i)
        for(int prev = 0; prev < 3; ++prev)
            for(int cur = 0; cur < 3; ++cur)
                if(prev != cur)
                    up(dp[i][cur], a[i][cur] + dp[i - 1][prev]);

    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll N; cin >> N;
  vector<int> A(N+1,0);
  for(int i=1;i<=N;i++){
    for(int j=i;j<=N;j+=i){
      A[j]++;
    }
  }
  ll ans = 0;
  rep(i,N+1) ans += (ll)i*A[i];
  cout << ans << endl;
  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve() {
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k%2==0) cout<<a-b<<"\n";
	else cout<<b-a<<"\n";

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


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

int main()
{ 
    int n;
    cin>>n;
    string s;
    char cha[11];
    vector<string> str(n);
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=0;j<11;j++){
            cha[j]=s[j];
        }
        sort(cha,cha+10);
        s=cha;
        str[i]=s;
    }
    sort(str.begin(),str.end());
    long long int cnt=0;
    long long int ans=0;
    for(int i=0;i<n-1;i++){
        if(str[i]==str[i+1]){
            cnt++;
        }
        else{
            ans=ans+cnt*(cnt+1)/2;
            cnt=0;
        }
    }
    ans=ans+cnt*(cnt+1)/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7296
import sys,queue,math,copy,itertools,bisect,collections,heapq

class Node:
    def __init__(self,x):
        self.data = x
        self.left = None
        self.right = None

def insert(node,x):
    if node is None: return Node(x)
    elif x < node.data:
        node.left = insert(node.left,x)
    else:
        node.right = insert(node.right,x)
    return node

def search_min(node):
    if node.left is None: return node.data
    return search_min(node.left)

def delete_min(node):
    if node.left is None: return node.right
    node.left = delete_min(node.left)
    return node

def delete(node,x):
    if node:
        if x == node.data:
            if node.left is None:
                return node.right
            elif node.right is None:
                return node.left
            else:
                node.data = search_min(node.right)
                node.right = delete_min(node.right)
        elif x < node.data:
            node.left = delete(node.left,x)
        else:
            node.right = delete(node.right,x)
    return node


def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    p = [LI() for _ in range(M)]

    p.sort()

    r = [[] for _ in range(N+1)]
    d = 0
    j = 0
    root = None
    for i in range(1,N):
        update = False
        while j < M and p[j][0] == i:
            root = insert(root,d + p[j][2])
            update = True
            r[p[j][1]].append(d + p[j][2])
            j += 1
        for z in r[i]:
            root = delete(root,z)
            update = True
        if root == None:
            print(-1)
            return
        if update:
            d = search_min(root)
    print(d)

if __name__ == '__main__':
    main()

Measured memory_bytes: 108424
n, m = map(int, input().split())
r = [""] * n
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if (r[s] == ""):
        r[s] = c
    elif (r[s] != c):
        print(-1)
        exit()

if r[0] == "0":
    if (n == 1):
        print(0)
        exit()
    print(-1)
    exit()
elif r[0] == "":
    if (n == 1):
        print(0)
        exit()
    print("1", end="")
else:
    print(r[0], end="")
for i in range(1, n):
    if r[i] == "":
        print("0", end="")
    else:
        print(r[i], end="")


Measured memory_bytes: 3064
MAX = 10 ** 5 * 2
mod = 10 ** 9 + 7
frac = [1]
inv_frac=[1]
def pow(a, n):
    if n == 0 : return  1
    elif n == 1 : return a
    tmp = pow(a, n//2)
    tmp = (tmp * tmp) % mod
    if n % 2 == 1 :
        tmp = (tmp * a) % mod
    return tmp
def inv(x):
    return pow(x, mod - 2 )
for i in range(1,MAX + 1 ):
    frac.append( (frac[-1] * i) % mod )
    inv_frac.append(inv(frac[-1])%mod)
def comb(n, k):
    if k >= n or k < 0 : return 1
    return (frac[n]*inv_frac[n-k] * inv_frac[k]) %mod
n,k = map(int,input().split())
count=0
b=inv(n)
for i in range(min(n,k+1)):
    a=comb(n,i)
    count=(count+a*a*(n-i)*b)%mod
print(count)

Measured memory_bytes: 75656
#include <stdio.h>
#include <algorithm>
#define rep(i,r) for (int i = 0; i < r; i++)

using namespace std;

long lpow2(long num) {
  return
    num == 0 ? 1
    : num % 2 == 0 ? lpow2(num / 2) * lpow2(num / 2)
    : 2 * lpow2(num - 1);
}

int main() {
  long H;
  scanf("%ld", &H);
  int r;
  while (H > 0) {
    H /= 2;
    r++;
  }
  printf("%ld", lpow2(r) - 1);
  return 0;
}


Measured memory_bytes: 128
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

// number一個取得
// eslint-disable-next-line no-unused-vars
const next = () => +cin[cid++];

// 文字列一個取得
// eslint-disable-next-line no-unused-vars
const nextstr = () => cin[cid++];

// BigInteger一個取得
// eslint-disable-next-line no-unused-vars
const nextbig = () => BigInt(cin[cid++]);

// 長さnの配列として取得。aは文字列フラグ
// eslint-disable-next-line no-unused-vars
const nexts = (n, a) =>
    a ? cin.slice(cid, (cid += n)) : cin.slice(cid, (cid += n)).map((a) => +a);

// w個ずつを組にして長さhの配列。aは文字列フラグ。
// eslint-disable-next-line no-unused-vars
const nextm = (h, w, a) => {
    var r = [],
        i = 0;
    if (a) for (; i < h; i++) r.push(cin.slice(cid, (cid += w)));
    else for (; i < h; i++) r.push(cin.slice(cid, (cid += w)).map((a) => +a));
    return r;
};
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
// eslint-disable-next-line no-unused-vars
const xArray = (...args) => {
    var a = args,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + a[0] + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
};

console.log(main().toString());

function main() {
    let N = next();
    let M = next();
    let K = xArray(0, M);
    let S = xArray(0, N, M);
    for (let i = 0; i < M; i++) {
        K[i] = next();
        S[i] = nexts(K[i]).map((v) => v - 1);
    }
    let P = nexts(M);

    let ans = 0;
    let pat_bits = Array(N);
    for (let pat = 0; pat < 2 ** N; pat++) {
        // 2進数n-bit目をswitchのon/offに対応させる。
        // S[i]のnビット目をチェックすることに等しい。
        for (let n = 0; n < N; n++) {
            pat_bits[n] = (pat >> n) % 2;
        }
        let flag = true;
        //console.log("Pattern=", pat_bits);
        for (let i = 0; i < M; i++) {
            //console.log("denkyu:" + i, "switch=" + S[i], "正解=", P[i]);
            let value = 0;
            for (let n = 0; n < K[i]; n++) {
                value += pat_bits[S[i][n]];
            }
            if (value % 2 != P[i]) {
                //console.log("Value=" + value, "FAIL");
                flag = false;
                break;
            }
            //console.log("Value=" + value, "accept!");
        }
        if (flag) {
            ans++;
        }
    }
    return ans;
}


Measured memory_bytes: 32640
#include "bits/stdc++.h"
#include <set>

using namespace std;
#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	rep(i, 5) {
		int a;
		cin >> a;
		if (a == 0) {
			print(i + 1);
		}
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;

int n,A[N],B[N],C[N],dp[N][4];

int calc(int idx,int cur){
    if(idx==n)
    return 0;
    
    int &ret = dp[idx][cur];
    
    if(ret != -1)
    return ret;
    
    if(cur==1)
    return ret = max(A[idx]+calc(idx+1,2) , A[idx]+calc(idx+1,3));
    else if(cur==2) 
    return ret = max(B[idx]+calc(idx+1,1) , B[idx]+calc(idx+1,3));
    else 
    return ret = max(C[idx]+calc(idx+1,1) , C[idx]+calc(idx+1,2));
}

int main(){
cin>>n;
for(int i=0;i<n;++i)
scanf("%d%d%d",&A[i],&B[i],&C[i]);

memset(dp,-1,sizeof(dp));
cout<<max(calc(0,1),max(calc(0,2),calc(0,3)));

return 0;    
}

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

int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> A(M);
  int COUNT = 0;
    for (int i = 0; i < M; i++) {
    cin >> A.at(i);
      if (X > A.at(i))
      COUNT++;
      }
    cout << min(COUNT,M-COUNT) << endl;
}

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

typedef long long ll;
const int MAX_N = 300030;    // Change as necessary
const ll  MODD = 1000000009; //

int A[MAX_N],B[MAX_N],C[MAX_N];

vector<int> adj[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  for(int i=1;i<n;i++){
    cin >> A[i]; A[i]--;
    B[A[i]]++;
  }
  
  priority_queue<pair<int,int> > pq;
  for(int i=0;i<n;i++)
    if(B[i] == 0)
      pq.emplace(0,i);
  
  while(!pq.empty()){
    pair<int,int> t = pq.top(); pq.pop();
    int v = t.second;
    if(v == 0) break;
    C[A[v]] = 1+max(C[A[v]],C[v]);
    B[A[v]]--;
    if(B[A[v]] == 0)
      pq.emplace(-C[A[v]],A[v]);
  }
  
  cout << C[0] << endl;
  
  return 0;
}


Measured memory_bytes: 9080
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

#define ll long long

int main()
{
    const ll MAX = 1LL << 60;
    int N, K;
    std::cin >> N >> K;

    std::vector<ll> steps(N);
    for (int i=0; i<N; ++i)
    {
        std::cin >> steps[i];
    }

    std::vector<ll> dp(N+1, MAX);
    dp[0] = 0;

    for (int i=0; i<N; ++i)
    {
        // i番目の足場へうつる -> 1つ前から飛んだ時 or 2つ飛ばしで来たときのスコア
        //dp[i+1] = std::min(dp[i] + std::abs(steps[i+1] - steps[i]), dp[i+1]);

        for (int k=1; k<=K; k++)
        {
            if (i + k < N)
            {
                // i+2番目の足場へ移る
                dp[i+k] = std::min(dp[i] + std::abs(steps[i+k] - steps[i]), dp[i+k]);
            }
        }
    }

    std::cout << dp[N-1] << std::endl;
}

Measured memory_bytes: 1792
from collections import deque
import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
list1 = deque(list1)
L = deque([0])
R = deque([0])
M = []

for i in range(len(list1)-1):
	L.append(math.gcd(L[i],list1[i]))
	R.append(math.gcd(R[i],list1[n-i-1]))

for i in range(len(L)):
	M.append(math.gcd(L[i],R[len(R)-i-1]))
print(max(M))

Measured memory_bytes: 94312
#include <stdio.h>

int main(){
    int a,b,c;
    c=0;
    scanf("%d %d",&a,&b);
    for(int i=a;i<b+1;i++){
        if((i/10000)!=(i%10))continue;
        if(((i/1000)%10)!=((i/10)%10))continue;
        c++;
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 128
N, A, B = map(int, input().split())
 
ab = [A, B]
max_katu = min(ab)
 
if A+B >= N:
    min_katu = A+B-N
else:
    min_katu = 0
 
 
ans = [str(max_katu), str(min_katu)]
print(' '.join(ans))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int k;
    cin >> k;
    ll ans = 0;
    REP(a, 1, k + 1) REP(b, 1, k + 1) REP(c, 1, k + 1) {
        ans += __gcd(a, __gcd(b, c));
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

int main(void) {
  ios::sync_with_stdio(false);
  string a, b;
  cin >> a >> b;
  string c = a + b;
  int d = stoi(c);
  int e = (int)sqrt(d);
  if (e * e == d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
using namespace std;

int dp[10000],w[100],v[100];
int main(){
    int n,ww;
    cin>>n>>ww;
    rep(i,n) cin>>v[i]>>w[i];
    rep(i,n){
        rep(j,ww-w[i]+1) dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
    }
    cout<<dp[ww]<<endl;
    return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;

map<char, int> m;
int main()
{
	string op;
	cin >> op;
	int n = op.size();
	if(n < 2)
	{
		cout << "-1 -1" << endl;
		return 0;
	}
	for(int i = 0; i < n-1 ;i++)
	{
		char tmp = op[i];
		if(tmp == op[i+1])
		{
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
		if(i < op.size() -2 && tmp == op[i+2])
		{
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
	return 0;
		
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int h,w,k; cin >> h >> w >> k;
    vector<string> field(h);
    rep(i,h) cin >> field.at(i);
    ll ans = 0;
    rep(is, 1<<h) rep(js, 1<<w){
        ll cnt = 0;
        rep(i, h) rep(j, w){
            if(is>>i & 1) continue;
            if(js>>j & 1) continue;
            if(field.at(i).at(j) == '#') cnt++;
        }
        if(cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n, k;
	cin >> n >> k;
	n = n % k;
	if (n < abs(n - k)) {
		cout << n << endl;
	}
	else {
		cout << abs(n - k) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# F - LCS
s=input()
t=input()
ns=len(s)
nt=len(t)
dp=[[0]*(nt+1) for i in range(ns+1)]

for i in range(ns):
    for j in range(nt):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1)
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j])
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1])
ans=''
i,j=ns,nt
while i>0 and j>0:
    # (i-1, j) -> (i, j) と更新されていた場合
    if dp[i][j]==dp[i-1][j]:
        i-=1
    #  (i, j-1) -> (i, j) と更新されていた場合
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    #  (i-1, j-1) -> (i, j) と更新されていた場合
    else:
        ans=s[i-1]+ans
        i-=1
        j-=1
print(ans)

Measured memory_bytes: 114396
#include "iostream"
using namespace std;

int N;
char ans[20];
int num;

int main() {
	cin >> N;
	while (N != 0) {
		if (N % 3 == 0) {
			ans[num++] = '0';
		}
		else if (N % 3 == 1) {
			ans[num++] = '+';
			N--;
		}
		else {
			ans[num++] = '-';
			N++;
		}
		N /= 3;
	}
	for (int i = num-1; i >= 0; i--) {
		cout << ans[i];
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {
int main(void) {
  int n;cin>>n;
  vector<int> buka(n+10,0);
  int a;
  rep(i,0,n-2) {
    cin>>a;
    a--;
    buka[a]++;
  }
  rep(i,0,n-1) {
    pr(buka[i]);
  }
  return 0;
}


Measured memory_bytes: 4048
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    if length(s)%2==0 && s=="hi"^div(length(s),2)
        println("Yes")
    else
        println("No")
    end
end
main()

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

int main(){
    string s;
    while(cin >>s, s!="#"){
        int y,m,d;
        cin >>y >>m >>d;

        string ans = "HEISEI";
        if(y>31 || (y==31 && m>4)){
            y -= 30;
            ans = "?";
        }

        cout << ans << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
vector <ll> adj[300000];
ll cnt,maxi;
ll vis[300000];
void dfs(ll x)
{
	vis[x]=1;
	cnt++;
	for(auto it:adj[x])
	{
		if(!vis[it])dfs(it);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,m,i;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		ll u,v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	for(i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			cnt = 0;
			dfs(i);
			maxi = max(maxi, cnt);
		}
	}
	cout<<maxi<<nl;
	return 0;
}

Measured memory_bytes: 24748
using System;
using System.Collections.Generic;
using System.Linq;

class C
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var AB = Enumerable.Range(0, N).Select(i => Console.ReadLine().Split(' ').Select(long.Parse).ToList()).ToList();
        var diff = AB.Select((ab, i) => Tuple.Create(ab[0] + ab[1], ab[0], ab[1])).OrderByDescending(d => d.Item1).ToList();
        long a = 0;
        long b = 0;
        for (int i = 0; i < N; i++)
        {
            if (i % 2 == 0) a += diff[i].Item2;
            else b += diff[i].Item3;
        }
        Console.WriteLine(a - b);
    }
}

Measured memory_bytes: 37776
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll k;
    string s;
    cin >> s >> k;
    ll i = 0;
    while(k>0){
        if (s[i] == 'a' and i != s.length()-1){
            i++;
            continue;
        }
        if (i == s.length()-1) {
            if (k >= (26 - (s[i] - 'a'))) {
                s[i] = ((k - (26 - (s[i] - 'a'))) % 26) + 'a';
                k = 0;
            } else {
                s[i] += k;
                k = 0;
            }
        }else if(26 - (s[i] - 'a') <= k){
            k -= (26 - (s[i] - 'a'));
            s[i] = 'a';
            i++;
        }else{
            i++;
        }
    }

    cout << s << endl;
}



Measured memory_bytes: 512