akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false


int GCD(int m, int n)
{
	int k;
	do {
		k = m % n;
		m = n; n = k;
	} while (k != 0);
	return m;
}

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << (C % GCD(A, B) ? "NO" : "YES") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 X,Y,Z,K,cnt,cntt;

int main(){
    cin>>X>>Y>>Z>>K;
    ll A[X],B[Y],C[Z],E[K*K+1000],ANS[K*K+1000];
    rep(i,K*K+1000){
        E[i]=0;
        ANS[i]=0;
    }
    rep(i,X)cin>>A[i];
    rep(i,Y)cin>>B[i];
    rep(i,Z)cin>>C[i];
    sort(A,A+X,greater<ll>());
    sort(B,B+Y,greater<ll>());
    sort(C,C+Z,greater<ll>());
    rep(i,min(X,K)){
        rep(j,min(Y,K)){
            E[cnt]=A[i]+B[j];
            cnt++;
        }
    }
    sort(E,E+(K*K+1000),greater<ll>());
    rep(i,K){
        rep(j,min(Z,K)){
            ANS[cntt]=E[i]+C[j];
            cntt++;
        }
    }
    sort(ANS,ANS+(K*K+1000),greater<ll>());
    rep(i,K)out(ANS[i]);
}


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

using namespace std;
map<long long int,long long int> qmap;

long long INF=5e18;
long long n,a,b,c,d;
long long solveit(long long goal)
{
	if(goal==0)
		return 0;
	if(goal==1)
		return d;
	if(qmap.count(goal))
	{
		return qmap[goal];
	}
	long long best=INF;
	if(d<best/goal)
	{
		best=min(best,d*goal);
	}
	for(int i=0;i<3;i++)
	{
		long long mul=vector<long long > {2,3,5}[i];
		long long cost=vector<long long > {a,b,c}[i];
		if(goal%mul==0)
		{
			best=min( best , cost + solveit(goal / mul) );
		}		
		else
		{
			long long down= (goal / mul) * mul;
			best=min(best , cost + (goal - down) * d + solveit (goal / mul));
			long long up = down + mul;
			best=min(best, cost + (up - goal) * d + solveit(goal / mul + 1));
		}
	}
	qmap[goal]=best;
	return best;
}
int main()
{
	long long int t;
	cin>>t;
	while(t--)
	{
		qmap.clear();
		cin>>n>>a>>b>>c>>d;
		cout<<solveit(n)<<endl;
	}
	return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n, m, f[200009], g[200009], st[200009], top = 0;
char str[200009];
struct node {
    int v, id;
};
deque<node> q;

int main() {
    memset(g, -1, sizeof(g));
    memset(f, 0x3f, sizeof(f));
    scanf("%d%d", &n, &m);
    scanf("%s", str);
    f[0] = 0, q.push_back({f[0], 0});
    for (int i = 1; i <= n; i++) {
        while (!q.empty() && i - q.front().id > m)q.pop_front();
        if (str[i] == '1')continue;
        if (!q.empty())f[i] = q.front().v + 1, g[i] = q.front().id;
        while (!q.empty() && q.back().v > f[i])q.pop_back();
        if (f[i] != 0x3f3f3f3f)q.push_back({f[i], i});
    }
    if (g[n] == -1)return puts("-1"), 0;
    int now = n;
    while (g[now] != -1) { st[++top] = now - g[now], now = g[now]; }
    while (top) {
        printf("%d ", st[top--]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 2432
n,m=map(int,input().split())
l=[]
for i in range(n):l.append([])
for i in range(m):
    p,y=map(int,input().split())
    l[p-1].append((i,y))
rl=[]
for i in range(n):
    ll=l[i]
    ll.sort(key=lambda x:x[1])
    hd=("000000"+str(i+1))[-6:]
    rr=[(ll[j][0],hd+("000000"+str(j+1))[-6:]) for j in range(len(ll))]
    rl+=rr
rl.sort()
for e in rl:
    print(e[1])


Measured memory_bytes: 42336
import sys
input = sys.stdin.readline
import math
def main():
   N = int(input())
   A = list(map(int,input().split())) 
   B = list(map(int,input().split())) 
   CNT = 0

   for i in range(N):
       if A[i] >= B[i]:
           CNT += B[i]
       else:
           CNT += A[i]
           B[i] -= A[i]
           if A[i+1] >= B[i]:
               CNT += B[i]
               A[i+1] -= B[i]
           else:
               CNT += A[i+1]
               A[i+1] = 0
   print(CNT)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18624
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        int N = scan.NextInt();
        var min = scan.NextInt();
        var result = 1;
        for (int i = 1; i < N; i++) {
            var p = scan.NextInt();
            if (p >= min) continue;
            min = p;
            result++;
        }
        return result;
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
}

Measured memory_bytes: 41332
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x) memset(x,0,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=2e5+10;

    vc<pll> tt[N];map<ll,int> to;ll sum(int l,int r){return l>r?0:ll(r+l)*(r-l+1)/2;}
    ll abs(ll x){return x<0?-x:x;}
    void main()
    {
        int n=qread();ll X=qread(),D=qread();int cnt=0;
        if(D==0)
        {
            write(X==0?1:n+1);
            return;
        }
        fo(a,0,n)
        {
            ll now=a*X;int id=to[now%abs(D)];if(!id) id=to[now%abs(D)]=++cnt;
            ll tl=sum(0,a-1)*D,tr=sum(n-1-a+1,n-1)*D;if(tl>tr)swap(tl,tr);
            tt[id].PB({tl+now,tr+now});
        }
        ll ans=0;
        fo(i,1,cnt)
        {
            sort(all(tt[i]));
            ll lst=tt[i][0].FR-1;//ans+=(lst-tt[i][0].FR)/D+1;
            fo(t,0,sz(tt[i])-1)
            {
                // printf("i=%d (%d,%d)\n",i,tt[i][t].FR,tt[i][t].SE);
                if(lst<tt[i][t].FR) ans+=(tt[i][t].SE-tt[i][t].FR)/abs(D)+1;
                else
                {
                    ll left=max(lst,tt[i][t].FR);
                    if(left<=tt[i][t].SE) ans+=(tt[i][t].SE-left)/abs(D);
                }
                chmax(lst,tt[i][t].SE);
            }
        }
        write(ans);
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 29952
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int x, a, b;
  scanf("%d %d %d", &x, &a, &b);
  
  if(b - a <= 0) printf("delicious\n");
  else if(b - a <= x) printf("safe\n");
  else printf("dangerous\n");
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,s,d;
    std::cin >> a>>s>>d;
    int ans=0;
    
    while(a%2==0&&s%2==0&&d%2==0){
        ans++;
        int aa=a,ss=s,dd=d;
        a=ss/2+dd/2;
        s=aa/2+dd/2;
        d=aa/2+ss/2;
    //    std::cout << a<<s<<d << std::endl;
        if(a==s&&s==d){
            std::cout << -1 << std::endl;
            exit(0);
        }
    }
    std::cout << ans << std::endl;
    
}



Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
for i in range(N):
    A[i] -= i+1
A.sort()
ans = 10**30
S = sum(A); s = 0
for i in range(N):
    s += A[i]
    ans = min(ans, (S-s-A[i]*(N-i-1)) + A[i]*(i+1)-s)
print(ans)


Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
signed main(){
    string S;
    bool G[4]={};
    cin >> S;
    REP(i,S.size()){
        if(S[i]=='N'){
            G[0]=1;
        }else if(S[i]=='S'){
            G[1]=1;
        }else if(S[i]=='E'){
            G[2]=1;
        }else if(S[i]=='W'){
            G[3]=1;
        }
    }
    if(G[0]==G[1]&&G[2]==G[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 81;
const double PI = acos(-1);

pii Find_x(vector<ll> v, vector<ll> ps, ll mid){
    pii ans = {0, 0};
    ll n = v.size();

    for (int i=0; i<n; i++){
        ll pos = lower_bound(all(v), mid - v[i]) - v.begin();

        if (pos < n){
            ll N = (n - pos);
            ans.ff += N;
            ans.ss += ps[n - 1] - (pos == 0? 0 : ps[pos-1]) + (N)*v[i];
        }
    }

    return ans;
} 


int main (){
    ll n, m;
    cin >> n >> m;

    vector<ll> ps(n, 0), v(n, 0);

    for (auto& x: v) cin >> x;

    sort(all(v));
    ps[0] = v[0];

    for (int i=1; i<n; i++){
        ps[i] = ps[i-1] + v[i];
    }

    ll l = v.front()*2, r = v.back()*2, best = 0, ans = 0, cnt = 0;

    while (l <= r){
        ll mid = l + (r - l)/2;

        pii p = Find_x(v, ps, mid);

        if (p.ff >= m){
            best = mid;
            ans = p.ss;
            cnt = p.ff;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }

    while (cnt > m){
        ans-=best;
        cnt--;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll d,e;
  while(cin>>d>>e){
    if(d==0 && e==0){break;}
    D ans=1e18;
    for(int i=0;i<=d;i++){
      D x=i,y=d-i;
      ans=min(ans,abs(sqrt(x*x+y*y)-e));
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
  }
  


  return 0;
}



Measured memory_bytes: 3308
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main() {
  vector<int> A(3);
  for(int i = 0; i < 3; i++) cin >> A[i];
  sort(A.begin(), A.end());
  if (A[0] == 5 && A[1] == 5 && A[2] == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 764
/**
*    author:  souzai32
*    created: 14.08.2020 14:10:05
**/

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

int main() {

    int n,k;
    cin >> n >> k;
    vector<long long> x(n);
    rep(i,n) cin >> x.at(i);
    long long left,right;
    long long ans=1e9;

    rep(i,n-k+1){
        left=x.at(i);
        right=x.at(i+k-1);
        ans=min(ans,min(abs(left)+abs(left-right),abs(right)+abs(left-right)));
        // cout << left << ' ' << right << endl;    
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4036
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, k = MAP()
h = [INT() for _ in range(n)]
h.sort()
ans = inf
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)

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

using namespace std;

int
main() {
  int N, X, T;
  int n,ans;
  cin >> N >> X >> T;
  n = N / X;
  if(N % X > 0)
    n++;
  ans = n * T;
  cout << ans << endl;
  return 0;
}


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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a % 2 == 1) cnt = 1 - cnt;
  }
  cout << (cnt == 0 ? "YES\n" : "NO\n");

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    bool hi=true;
    bool first=true;
    for(int i=0; i<s.length()-1; i++){
        if(first==true){
            if(s[i]=='h'&&s[i+1]=='i'){
            first=false;
        }else{
            hi=false;
        }
        }else{
            if(s[i]=='i'&&s[i+1]=='h'){
                first=true;
            }else{
                hi=false;
            }
        }
    }
    
    if(hi&&s.length()%2==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
def resolve():
    import sys
    input = sys.stdin.readline
    n, k = [int(x) for x in input().rstrip().split()]
    n_set = set()
    while n not in n_set:

        n_set.add(n)
        if n == 0:
            break

        n = abs(k-n)
        if k < n:
          n = n - k*(abs(k-n)//k)
        # print(n)
        # print(n_set)

    print(min(n_set))

resolve()


Measured memory_bytes: 38256
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return
#-----------------------------------------------------
n,m = map(int,raw_input().split())

uf = UnionFind(n+m)

for i in xrange(n):
	langs = map(int,raw_input().split())
	for j in xrange(1,langs[0] + 1):

		uf.union(i,langs[j]+n-1)

a = uf.find(0)

for i in range(1,n):
	root = uf.find(i)

	if uf.find(i) != a:
		print 'NO'
		quit()

print 'YES'

Measured memory_bytes: 10680
#include<stdio.h>
#define NIL -1
#define MAX 10000

int setHeight(int );
void setDepth(int ,int );
int getSibling(int );
void print(int );

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

Node T[MAX];
int D[MAX],H[MAX],n;

int main(){
  int i;
  int a,b,c;
  int root=0;
  
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);
    T[a].l=b;
    T[a].r=c;
    if(b != NIL) T[b].p=a;
    if(c != NIL) T[c].p=a;
  }
  for(i=0;i<n;i++) if(T[i].p==NIL) root=i;

  setDepth(root,0);
  setHeight(root);

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

  return 0;
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL) h1=setHeight(T[u].l)+1;
  if(T[u].r!=NIL) h2=setHeight(T[u].r)+1;
  return H[u]=(h1>h2 ? h1:h2);
}
void setDepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].l,d+1);
  setDepth(T[u].r,d+1);
}
int getSibling(int u){
  if(T[u].p==NIL) return NIL;
  if(T[T[u].p].l !=u &&T[T[u].p].l!=NIL) return T[T[u].p].l;
  if(T[T[u].p].r!=u &&T[T[u].p].r!=NIL) return T[T[u].p].r;
  return NIL;
 }
void print(int u){
  printf("node %d: parent = %d, sibling = %d",u,T[u].p,getSibling(u));
  int degr=0;
  if(T[u].l!=NIL) degr++;
  if(T[u].r!=NIL) degr++;
  printf(", degree = %d, depth = %d, height = %d",degr,D[u],H[u]);
  if(T[u].p==NIL) printf(", root");
  else if(T[u].l==NIL && T[u].r==NIL) printf(", leaf");
  else printf(", internal node");
  printf("\n");
    }



Measured memory_bytes: 2104
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 300000
#define mmod 1000000007
using namespace std;
struct node{int x,y;}a[N];
struct node1{int l,r;}A[N];
struct node2{int d,id;}b[N];
int n,s[N],f[N];
inline int read()
{
	char c=getchar();int t=0,f=1;
	while(c!='-' && (c<'0' || c>'9')) c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(c>='0' && c<='9') {t=t*10+c-'0';c=getchar();}
	return t*f;
}
bool cmp(node2 x,node2 y)
{
	if(x.d<y.d) return 1;
	return 0;
}
void lsh()
{
	for(int i=1;i<=n;i++) b[i].d=a[i].y,b[i].id=i;
	sort(b+1,b+n+1,cmp);
	for(int i=1;i<=n;i++) a[b[i].id].y=i;
}
bool cmp1(node x,node y)
{
	if(x.x<y.x) return 1;
	return 0;
}
void pre()
{
	sort(a+1,a+n+1,cmp1);
	int t=n+1;
	for(int i=n;i>=1;i--) 
	{
		t=min(t,a[i].y);
		A[i].l=t;
	}
	t=0;
	for(int i=1;i<=n;i++)
	{
		t=max(t,a[i].y);
		A[i].r=t;
	}
}
bool cmp2(node1 x,node1 y)
{
	if(x.l<y.l) return 1;
	if(x.l>y.l) return 0;
	if(x.r<y.r) return 1;
	return 0;
}
void solve()
{
	sort(A+1,A+n+1,cmp2);
	s[0]=1;int j=0;
	for(int i=1;i<=n;i++)
	{
		int l=A[i].l,r=A[i].r;
		while(j<r-1) {j++;s[j]=(s[j-1]+f[j])%mmod;}
		int t=(f[r]+s[r-1])%mmod;
		if(l>1) t=(t-s[l-2])%mmod;
		f[r]=(f[r]+t)%mmod;
	}
	printf("%d\n",(f[n]+mmod)%mmod);
}
int main()
{

	n=read();
	for(int i=1;i<=n;i++) {a[i].x=read();a[i].y=read();}
	lsh();
	pre();
	solve();
	return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	ll n;
	cin>>n;
	vector<pair<ll,ll>> pa;
	ll x,y;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		pa.push_back(make_pair(x,y));
	}
	ll fl = 0;
	for(int i=0;i<pa.size();i++)
    {
    	if(pa[i].first == pa[i].second && fl<3)
    	{
    		++fl;
    	}
    	else if(pa[i].first == pa[i].second && fl>=3)
    	{
    		break;
    	}
    	else if(pa[i].first != pa[i].second && fl<3)
        {
        	fl = 0;
        	continue;
        }
    }
    if(fl >=3)
    {
    	cout<<"Yes\n";
    }
    else{
    	cout<<"No\n";
    }
    
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
	static class Tuple implements Comparable<Tuple> {
		int id;
		String str;
		int value;

		Tuple(int id, String str, int value) {
			this.id = id;
			this.str = str;
			this.value = value;
		}

		@Override
		public int compareTo(Tuple o) {
			if (this.str.equals(o.str)) {
				if (this.value > o.value) {
					return -1;
				} else if (this.value < o.value) {
					return 1;
				} else {
					return 0;
				}
			} else {
				return this.str.compareTo(o.str);
			}
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());

		List<Tuple> shops = new ArrayList<>();
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			shops.add(new Tuple(i + 1, tokens[0], Integer.parseInt(tokens[1])));
		}
		Collections.sort(shops);
		for (int i = 0; i < N; ++i) {
			System.out.println(shops.get(i).id);
		}
		in.close();
	}

}

Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <numeric>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;


int main() {
	int n, t;
	cin >> n >> t;
	VI v(n);
	REP(i, n) { cin >> v[i]; }

	sort(ALL(v));

	int count = 0;
	REPC(x, v) {
		if (t >= x) {
			t -= x;
			++count;
		} else {
			break;
		}
	}
	if (t != 0 && count == n) { --count; }
	cout << count << endl;
}


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

int n, m, q, x, y;
int connect[100001];
vector<int> g[100001];

void dfs(int v, int c) {
    connect[v] = c;
    
    int size_ = g[v].size();
    for (int i = 0; i < size_; ++i) {
        if (connect[g[v][i]] == 0) {
            dfs(g[v][i], c);
        }
    }
}

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

    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int c = 1;
    for (int i = 0; i < n; ++i) {
        if (connect[i] == 0) {
            dfs(i, c);
            c++;
        }
    }

    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> x >> y;
        if (connect[x] == connect[y]) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }

    return 0;
}

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

int main(){
	int w,h;
	scanf("%d%d",&h,&w);
	char d[100][100];
	for(int i=0;i<h;i++) scanf("%s",d[i]);
	for(int i=0;i<h;i++){
		int x=-1;
		for(int j=0;j<w;j++){
			if(x!=-1) x++;
			if(d[i][j]=='c') x=0;
			printf("%d%c",x,j==w-1?'\n':' ');
		}
	}
}

Measured memory_bytes: 1200
import sys

input = sys.stdin.readline
n = int(input())
p_list = []
for _ in range(n):
    p = int(input())
    p_list.append(p)
p_list.sort(reverse=True)
value = 0
for i in range(n):
    if i == 0:
        value += int(p_list[i]/2)
    else:
        value += p_list[i]
print(value)


Measured memory_bytes: 3060
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;
            var a = new int[N];
            var b = new int[N];
            var c = new int[M];
            var d = new int[M];
            var ans = new int[N];
            for(int i = 0; i < N; i++)
            {
                a[i] = cin.ReadInt;
                b[i] = cin.ReadInt;
                ans[i] = M - 1;
            }
            for(int i = 0; i < M; i++)
            {
                c[i] = cin.ReadInt;
                d[i] = cin.ReadInt;
            }
            for(int i = 0; i < N; i++)
            {
                for(int j = M - 2; j >= 0; j--)
                {
                    var nowAns = Abs(a[i] - c[ans[i]]) + Abs(b[i] - d[ans[i]]);
                    var dis = Abs(a[i] - c[j]) + Abs(b[i] - d[j]);
                    if(dis <= nowAns)
                    {
                        ans[i] = j;
                    }
                }
            }
            for(int i = 0; i < N; i++)
            {
                WriteLine(ans[i] + 1);
            }
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

long read_long() {
	long ret=0;char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9') {
		ret=ret*10+c-'0';
		c=getchar();
	}		return ret;
}

int main() {
	string s;
	cin>>s;
	long l=s.length(),ans=0;
	for(long i=1;i<=l/2;++i) {
		if(s[i-1]!=s[l-i])
			++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int N;
int K;
int A[112345];
int idx;

int GCD( int x, int y ){
	if( x < y ) swap( x, y );
	int a = x % y;
	if( a ) y = GCD( a, y );
	return y;
}

int main(){
	
	cin>>N>>K;
	
	REP( i, N ) scanf("%d", A+i);
	
	sort( A, A+N );
	
	idx = A[0];
	
	FOR( i, 1, N ){
		idx = GCD( idx, A[i] );
	}
	
	//cout<<K%idx<<endl;
	
	if( A[N-1] < K || K%idx ){
		puts("IMPOSSIBLE");
	}
	else{
		puts("POSSIBLE");
	}
	
	return 0;

}

Measured memory_bytes: 640
H,W,A,B = $stdin.gets.chomp.split(" ").map(&:to_i)
M = 1000000007

def modpow(n,r)
  b = n
  a = 1
  while r > 0
    if r%2 == 1
      a = (a * b) % M
    end
    b = (b * b) % M
    r = r / 2
  end
  a
end

$factor = [1]
$refact = [1]
(1..(H+W)).each{ |k|
  $factor << (($factor[-1] * k)%M) 
  $refact << modpow($factor[-1], M-2)
}

#p $factor
#p $refact

def c(n,k)
  (($factor[n] * $refact[n-k]) % M) * $refact[k] % M
end

puts (0...[H-A,W-B].min).map{ |k|
  i,j = H-1-A-k,B+k
  #$stderr.puts "#{i}, #{j}"
  c(i+j, i) * c(H-i-1+W-j-1, H-i-1) % M
}.inject(:+) % M


Measured memory_bytes: 5780
#include <stdio.h>
int main(){
 
  int i,j,k,H,W;
 
  while (1){
 
    scanf("%d %d",&H,&W);
   
    if (H != 0 && W != 0){
 
      for (i = 0; i < W; i++){
     
    printf("#");
 
      }
       
      printf("\n");
 
      for (j = 0; j < H-2; j++){
 
    printf("#");
     
    for (k = 0; k < W-2; k++){
       
      printf(".");
       
    }
     
    printf("#\n");
     
      }
       
      for (i = 0; i < W; i++){
     
    printf("#");
     
      }
       
      printf("\n\n");
       
    } else {
       
      break;
       
    }
     
  }
   
  return 0;
 
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<char> a(6);
    for (int i = 0; i < 6; i++){
        cin >> a.at(i);
    }
    if (a.at(2) == a.at(3) && a.at(4) == a.at(5))
        cout << "Yes" << endl;
    else
        cout << " No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0
f=g=h=0
a,b,c,x,y=map(int,input().split())
if a+b>2*c:
    f=1
if a>2*c:
    g=1
if b>2*c:
    h=1

if f:
    ans+=min(x,y)*c*2
    if x>=y:
        if g==1:
            ans+=(x-y)*c*2
        else:
            ans+=(x-y)*a
    else:
        if h==1:
            ans += (y-x)*c*2
        else:
            ans+=(y-x)*b
else:
    if g:
        ans+=x*2*c+y*b
    elif h:
        ans+=x*a+y*2*c
    else:
        ans+=x*a+y*b
print(ans)



Measured memory_bytes: 38384
using System;

namespace AOJ.Volume5
{
    public class WhoAreTheStudentYetToSubmit
    {
        public static void Main()
        {
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                var check = new bool[31];
                check[0] = true;
                for (int i = 1; i <= 30; i++) { check[i] = false; }

                int id;
                id = int.Parse(input);
                check[id] = true;
                for (int i = 2; i <= 28; i++)
                {
                    id=int.Parse(Console.ReadLine());
                    check[id] = true;
                }

                for (int i = 1; i <= 30; i++)
                {
                    if (!check[i]) { Console.WriteLine(i); }
                }
            }
        }
    }
}

Measured memory_bytes: 9124
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>

#define MOD 1000000007

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    string s;
    cin >> s;
    string ans = "";
    int pos = 0;
    while(pos != s.size()){
        if(s[pos] != 'B'){
            ans.push_back(s[pos]);
        }
        else{
            if(ans != ""){
                ans.pop_back();
            }
        }
        pos++;
    }
    cout << ans;
    return 0;
}

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

using namespace std;
typedef long long ll;

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

    vector<int> dp(h + 1, 1145141919);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int before = 0; before < h; before++) {
            int after = min(before + a, h);
            dp[after] = min(dp[after], dp[before] + b);
        }
    }

    cout << dp[h] << endl;
    return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll A,B,res;
  cin>>A>>B>>res;
  ll in;
  FOR(i,0,A){
    cin>>in;
    res=res+(B-1)/in+1;
  }
  cout<<res<<endl;
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr ll MOD = 1e18;
constexpr int INF = __INT_MAX__;                    // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__ / 10; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

long long modpow(long long m, long long p) {
    if (p < 0) return 0;
    if (p == 0) return 1;
    if (p > 50) return INFLL / 3;
    if (p % 2)
        return m * modpow(m, p - 1);
    else {
        long res = modpow(m, p / 2);
        return res * res;
    }
}
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;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vi a(n + 1);
    rep(i, n + 1) cin >> a[i];

    vl bound(n + 1);
    ll b = 1;
    bound[0] = 1;
    repeat(i, 1, n + 1) {
        b = min(b * 2, INFLL);
        bound[i] = b;
        b -= a[i];
    }

    ll sum = 0;
    ll child = 0;
    bool ok = true;
    revrepeat(i, 1, n + 1) {
        if (a[i] + (child + 1) / 2 > bound[i]) ok = false;
        child += a[i];
        child = min(child, bound[i]);
        sum += child;
    }
    if (n != 0 and a[0] != 0) ok = false;
    if (n == 0 and a[0] != 1) ok = false;
    if (ok) {
        if (n == 0)
            out(1);
        else
            out(sum + 1);
    } else
        out(-1);
    return 0;
}


Measured memory_bytes: 4516
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  double a,b,x;
  cin >> a >> b >> x;

  double z=2*x/(a*b);

  if(z>a){
    z=2*x/(a*a)-b;
    double t=atan((b-z)/a);
    t*=180/M_PI;
    printf("%.10f\n", t);
  }
  else{
    double t=atan(b/z);
    t*=180/M_PI;
    printf("%.10f\n", t);    
  }

  
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int INF = 0x3f3f3f3f;
const ll  LINF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

set<string> vals;
ll ans[maxn];

ll s_to_ll(string s){
    ll v=0,base=1LL;
    int n = s.size();
    for(int i=n-1;i>=0;--i){
        v+=((s[i]-'0')*base);
        base*=10LL;
    }
    return v;
}

bool ok(string s){
    return s_to_ll(s) <= 3234566667LL;
}

void generate(string curr){
    if(vals.count(curr) || !ok(curr)) return;
    vals.insert(curr);
    for(char i='0';i<='9';++i){
        string next = curr;
        next.pb(i);
        int prev = curr.back()-'0';
        if(abs(prev-(i-'0'))<=1){
            generate(next);
        }
    }
}

void solve(){
	int k;
    cin >> k;
    cout << ans[k-1] << endl;
}

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

    int t = 1;

    // cin >> t;

    generate("1");
    generate("2");
    generate("3");
    generate("4");
    generate("5");
    generate("6");
    generate("7");
    generate("8");
    generate("9");

    int i=0;

    for(auto x:vals){
        ans[i++] = s_to_ll(x);
    }

    sort(ans,ans+i);

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

    return 0;
}

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

int main() {
  string s;
  int q;
  cin >> s >> q;
  bool asc = 1;
  string beg = "";
  string end = "";
  for (int i = 0; i < q; i++) {
    int temp;
    cin >> temp;
    if (temp == 1)
      asc = !asc;
    else {
      int temp;
      char ch;
      cin >> temp >> ch;
      if (temp == 1) {
        if (asc)
          beg += ch;
        else
          end += ch;
      } else {
        if (asc)
          end += ch;
        else
          beg += ch;
      }
    }
  }
  if (asc) {
    reverse(beg.begin(), beg.end());
    cout << beg + s + end << endl;
  } else {
    reverse(s.begin(), s.end());
    reverse(end.begin(), end.end());
    cout << end + s + beg << endl;
  }
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int n=s.size();
    int z=0;
    if(s[0]!='1'||s[n-1]!='0') z=1;
    rep(i,n-1) if(s[i]!=s[n-i-2]) z=1;
    if(z){
        cout<<-1;
        return 0;
    }
    int a=1;
    rep(i,n-1){
        cout<<a<<" "<<i+2<<"\n";
        if(s[i]=='1') a=i+2;
    }
}

Measured memory_bytes: 3740
n, m = map(int, input().split())
x = [int(i) for i in input().split(maxsplit=(n-1))]

sum = 0
count = 0
for i in x:
    sum += i

con = (1/(4*m))*sum

for i in x:
    if i >= con:
        count += 1
    if count == m:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 3064
int main(){
	int w,f;
	for(;scanf("%d",&w),~w;){
		if(w<10)
			f=1150;
		else if(w<20)
			f=1150+(w-10)*125;
		else if(w<30)
			f=1150+10*125+(w-20)*140;
		else
			f=1150+10*125+10*140+(w-30)*160;
		printf("%d\n",4280-f);
	}
	exit(0);
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll x;
  cin >> x;

  ll ans = 100;
  ll cnt = 0;

  while (ans < x) {
    ans *= 1.01;
    ++cnt;
  }
  cout << cnt << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

int main(){
  int i,k,sum;
  char numbers[1001];

  while(1){
    scanf("%s",&numbers);
    if(numbers[0]==48){break;}
    else{
      sum=0;
      k=strlen(numbers);
      for(i=0; i<k; i++){
        sum=sum + (numbers[i]-48);
      }
      printf("%d\n",sum);
    }   
  }

  return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    clock_t stt = clock();
    ll n;
    cin >> n;
    /*vector<ll> num(n + 1);
    for(int i = 1; i <= n; i++){
        ll idx = i;
        while(idx <= n){
            num[idx]++;
            idx += i;
        }
    }
    ll total = 0;
    for(int i = 1; i <= n; i++){
        total += (i * num[i]);
    }
    cout << total << "\n";*/
    ll total = 0;
    for(ll i = 1; i <= n; i++){
        ll cur = i * ((n / i) * (n / i + 1) / 2);
        //cout << cur << "\n";
        total += cur;
    }
    cout << total << "\n";
    clock_t end = clock();
    const double time = static_cast<double>(end - stt) / CLOCKS_PER_SEC * 1000.0;
    //printf("time %lf[ms]\n", time);
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;string s;char c[52];cin>>n>>s;
  for(int i=0;i<26;i++){c[i]=65+i;c[i+26]=65+i;}
  for(int i=0;i<s.length();i++)cout<<c[s[i]+n-65];
  cout<<endl;
}

Measured memory_bytes: 256
def f(n, t):
    if n % 2 == 0:
        n = int(n / 2)
    else:
        n = n * 3 + 1
    t += 1
    if n == 1:
        return t
    else:
        return f(n, t)


while True:
    _n = int(input())
    if _n == 0:
        break
    print(0 if _n == 1 else f(_n, 0))

Measured memory_bytes: 7792
# -*- coding utf-8 -*-

s = input()
ansf = 0
anss = 0
for i in s:
    if i== "A" or i =="C" or i =="G" or i == "T":
        ansf += 1
    else:
        ansf = 0
    anss = max(anss,ansf)

print(anss)


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

using namespace std;

typedef long long ll;

double Snuke(ll x) {
	ll tmp = 0, c = x;
	while(c) {
		tmp += c % 10;
		c /= 10;
	}
	return 1.0 * x / tmp;
}

int main() {
	int K;
	cin >> K;
	ll res = 0, x = 1;
	while(K--) {
		double t1, t2;
		while(true) {
			t1 = Snuke(res + x), t2 = Snuke(res + x * 10);
			if(t1 <= t2) break;
			x *= 10;
	//		cout<<t1<<" "<<t2<<endl;
		}
		res += x;
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n){
        cin >> a[i];
        a[i]--;
    }

    int j = 0;
    int count = 0;
    int ans = -1;
    while(true){
        count++;
        if(a[j] == 1){
            ans = count;
            break;
        }
        j = a[j];
        if(count == n)break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#define int int64_t
#define M 1000000007
#define SZ 200005
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;



int32_t main()
{
	int n;
	cin>>n;
	int d=n%10;
	if(d==3)
	{
		cout<<"bon\n";
	}
	else if(d==0||d==1||d==6||d==8)
	{
		cout<<"pon\n";
	}
	else cout<<"hon\n";
	return 0;
}

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

	string s;
		cin>>s;

	ifstream cin("input.txt");
	ofstream cout("output.txt");
*/

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

int main() {
  int N, K;
  int l[60];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
  	cin >> l[i];
  }
  
  sort(l, l + N, greater<int>());
  int sum = 0;

  for (int i = 0; i < K; i++) {
    sum += l[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int a,b,c,d; cin>>a>>b>>c>>d;
    if(a*b>=c*d){
        cout<<a*b<<endl;
    }else{
        cout<<c*d<<endl;
    }

}

Measured memory_bytes: 256