akhauriyash/Code-Regression huggingface dataset:
//08, 09, 2018, 09:37:51 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< pii, pii > ope;
const int N = 600;
int tab[N][N];

vector< ope > operations;
int vi[] = {1, 1, 0, 0};
int vj[] = {0, 0, 1, 1};
int h, w;
bool mark[N][N];

bool ok(int i, int j){
    return i >= 1 && i <= h && j >= 1 && j <= w;
}

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

    cin >> h >> w;

    for(int i = 1 ; i <= h ; i++){
        for(int j = 1 ; j <= w ; j++){
            cin >> tab[i][j];
        }
    }

    for(int i = 1 ; i <= h ; i++){
        int st, inc, last;

        if(i & 1){
            st = 1;
            inc = 1;
            last = w + 1;
        }else{
            st = w;
            inc = -1;
            last = 0;
        }

        for(int j = st ; j != last ; j += inc){
            if(mark[i][j] || tab[i][j] % 2 == 0){
                continue;
            }

            int wi = i, wj = j;
            // cout << i << " " << j << " entrou" << endl;
            
            for(int k = i ; k <= h ; k++){
                int stx, incx, lastx;

                if(k & 1){
                    incx = 1, lastx = w + 1;

                    if(k == i){
                        stx = j + 1;
                    }else{
                        stx = 1;
                    }
                }else{
                    incx = -1, lastx = 0;

                    if(k == i){
                        stx = j - 1;
                    }else{
                        stx = w;
                    }
                }

                bool ok = false;

                for(int l = stx ; l != lastx ; l += incx){
                    
                    operations.push_back({{wi, wj}, {k, l}});
                    // cout << "added!" << endl;
                    tab[wi][wj]--;
                    tab[k][l]++;

                    mark[wi][wj] = true;
                    wi = k, wj = l;
                    
                    if(tab[k][l] % 2 == 0){
                        ok = true;
                        break;
                    }
                }

                if(ok){
                    break;
                }
            }
        }
    }

    // cout << " sai aqui oh!" << endl;
    cout << operations.size() << endl;
    
    for(int i = 0 ; i < operations.size() ; i++){
        cout << operations[i].first.first << " " << operations[i].first.second << " " << operations[i].second.first << " " << operations[i].second.second << endl;
    }

    return 0;
}

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

int main(){
	double a,b,c,d,e,f;
	double x,y;
	while(cin >> a >>b >>c>>d>>e >>f){
		y=(f*a-c*d)/(e*a-b*d);
		x=(c-b*y)/a;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <functional>
#include <algorithm>

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

using namespace std;

int main() {
    int N, H, a[100000], b[100000];
    cin >> N >> H;
    REP(i, N) cin >> a[i] >> b[i];

    int a_max = *max_element(a, a + N);
    sort(b, b + N, greater<int>());

    int ans = 0, i = 0;
    while (H > 0) {
        if (b[i] > a_max) {
            H -= b[i++];
            ans++;
        }
        else break;
    }
    if (H > 0)
        ans += ceil((double)H / a_max);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int S = sc.nextInt();
      int W = sc.nextInt();
      
      if(S<=W){
        System.out.println("unsafe");
      }
      else{
      System.out.println("safe");
      }
    }
}

Measured memory_bytes: 35696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, k; cin >> n >> k;
	int64_t a[n]; rep(i,n) cin >> a[i];
	for(int i = k; i < n; ++i) {
		int64_t pre = a[i - k];
		int64_t now = a[i];
		if(pre < now) {
			cout << "Yes" << '\n';
		} else {
			cout << "No" << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
#define ll long long
const int inf = 1000000000;

int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x=x2-x1,y=y2-y1;
    cout << x2-y << " " <<  y2+x  << " "<< x1-y << " " <<  y1+x << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;

ll dp[3005][3005][2];

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for(int i=a; i<=c; ++i) for(int j=b; j<=d; ++j){
    if(i==a && j==b){
      dp[a][b][0] = 1;
      continue;
    }
    dp[i][j][1] = (dp[i-1][j][0] + dp[i-1][j][1]) * j;
    dp[i][j][1] %= MOD;
    dp[i][j][0] = dp[i][j-1][1] + dp[i][j-1][0] * i;
    dp[i][j][0] %= MOD;
  }
  /*cout << "0:" << endl;
  for(int i=a; i<=c; ++i) for(int j=b; j<=d; ++j){
    cout << dp[i][j][0] << " ";
    if(j == d) cout << endl;
  }
  cout << "1:" << endl;
  for(int i=a; i<=c; ++i) for(int j=b; j<=d; ++j){
    cout << dp[i][j][1] << " ";
    if(j == d) cout << endl;
  }*/
  ll ans = (dp[c][d][1]+dp[c][d][0])%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 144392
n=int(input())
cnt=[0]*5
check='MARCH'
for i in range(n):
  s=input()
  for j in range(5):
    if s[0]==check[j]:
      cnt[j]+=1
      break
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=cnt[i]*cnt[j]*cnt[k]
print(ans)

Measured memory_bytes: 3064
#include<map>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;


int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n;
	int a[10005];
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	int time = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] % 2 == 0)
		{
			while (a[i] % 2 != 1)
			{
				a[i] /= 2;
				time++;
			}
		}
	}
	printf("%d\n", time);
}

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

using namespace std;

//=================================================================
// Begginer Contest 116 C
int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    int ans = 0;

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

    while(true){
        bool cont = false;
        int sum=0;
        for(int i=0 ; i<N ; i++){
            sum += h[i];
            if(h[i]>0 && cont==false){
                h[i]--;
                cont = true;
            }
            else if(h[i]>0 && cont==true){
                h[i]--;
                continue;
            }else if(cont==true){
                ans++;
                cont = false;
            }
        }
        if(cont==true){
            ans++;
        }
        if(sum==0){
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int m,n;
int i,j,mark[8][8][8][8][8][8][8],q[1000000][10],p[7];

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int check(int a[]){
	int k;
	for(k=0;k<8;k++){if(a[k]!=k)return 0;}
	return 1;
}

void look(int a[],int dir){
	int k;
	for(k=0;k<10;k++)q[j][k]=a[k];
	if(dir==0){swap(&q[j][q[j][8]],&q[j][q[j][8]-1]);q[j][8]--;}
	if(dir==1){swap(&q[j][q[j][8]],&q[j][q[j][8]+1]);q[j][8]++;}
	if(dir==2){swap(&q[j][q[j][8]],&q[j][q[j][8]-4]);q[j][8]-=4;}
	if(dir==3){swap(&q[j][q[j][8]],&q[j][q[j][8]+4]);q[j][8]+=4;}
	q[j][9]++;
	if(mark[q[j][0]][q[j][1]][q[j][2]][q[j][3]][q[j][4]][q[j][5]][q[j][6]]==0){
		mark[q[j][0]][q[j][1]][q[j][2]][q[j][3]][q[j][4]][q[j][5]][q[j][6]]=q[j][9];
		j++;
	}
}

void inspect(int a[]){
	if(a[8]%4>0)look(a,0);
	if(a[8]%4<3)look(a,1);
	if(a[8]>3)look(a,2);
	if(a[8]<4)look(a,3);
}


int main(){
	mark[0][1][2][3][4][5][6]=1;
	for(i=0;i<8;i++)q[0][i]=i;
	q[0][8]=0;q[0][9]=1;
	i=0;j=1;
	while(i<j){inspect(q[i]);i++;}

	while(scanf("%d %d %d %d %d %d %d %*d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6])!=EOF){
		printf("%d\n",mark[p[0]][p[1]][p[2]][p[3]][p[4]][p[5]][p[6]]-1);
	}
	return 0;
}

Measured memory_bytes: 10104
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


ans = 0

for i in range(1, N+1):
    if i % 2 != 0:
        if len(make_divisors(i)) == 8:
            ans += 1
print(ans)


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

int pow(int n){

        int ans = 1;
        for(int i=0;i<n;i++){
            ans *= 10;
        }
    return ans;

}

int main()
{
    long long N,data,ans=0;
    cin >>N;

    std::vector<long long>A;
    rep(i,N){
        cin >> data;
        A.push_back(data);
    }
    int size = A.size();

    std::sort(A.begin(),A.end());

    rep(i,size-1){
        if(A[i]-A[i+1]==0){
            ans=1;
            break;
        }
    }


    if(ans==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;

}

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


int main(){
  int n,m;
  cin >> n >> m ;
  vector<int> k(m),p(m);
  vector<vector<int>> s(m,vector<int>(10));
  for(int i = 0;i<m;i++){
    cin >> k[i];
    for(int j = 0;j<k[i];j++){
      cin >> s[i][j];
    }
  }
  for(int i = 0;i<m;i++)cin >> p[i];

  //処理
  int ans = 0;
  for(int bit = 0; bit < (1<< n); bit ++){
    vector<int> swit(n);
    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
        swit[i] = 1;
      }
    }
    bool check = true;
    for(int i = 0;i < m;i++){
      int cnt = 0;
      for(int j = 0;j < k[i]; j++){
        cnt += swit[s[i][j]-1];
      }
      if(cnt%2 != p[i])check = false;
    }
    if(check)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
int main(){
      int a,b;
      cin>>a>>b;
      vector<int>vec;
      for(int i=0;i<a;i++){
        int x;
        cin>>x;
        vec.push_back(x);
      }
      sort(vec.begin(),vec.end());
        int c=0,flag=0;
      for(int i=0;i<a;i+=b-1){
            for(int j=i;j<i+b&&j<a;j++){
                if(vec[j]==vec[0])continue;
                else{
                    vec[j]=vec[0];
                    flag=1;
                }
            }
            if(flag==1){
                c++;
                flag=0;
            }

      }
      cout<<c<<endl;
}


Measured memory_bytes: 892
N = int(input())
data = [[x.split(), y ] for x, y in [ [ input(), z+1 ] for z in range(N) ]]

data_sorted = sorted(data, key=lambda x: x[0][0])

current_city_name = ""
result = []
sumup = 0

for elem in data_sorted:
    if current_city_name != elem[0][0] and current_city_name != "":
        result = sorted(result, key=lambda x: x[0])[::-1]
        for res_elem in result:
            print(res_elem[1])
        result = []
        sumup = 0
    result.append([int(elem[0][1]), elem[1]])
    current_city_name = elem[0][0]


result = sorted(result, key=lambda x: x[0])[::-1]
for res_elem in result:
    print(res_elem[1])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,en,st) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 1010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}

string s[N];
ll dp[N][N];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j,m;
    cin>>n>>m;
    rep(i,1,n){
        cin>>s[i];
        s[i]="#"+s[i];
    }
    dp[1][1]=1;
    rep(i,2,n){
        if(s[i][1]=='.')dp[i][1]=1;
        else break;}
    rep(i,2,m){if(s[1][i]=='.')dp[1][i]=1;else break;}
    rep(i,2,n)rep(j,2,m)
    {
        dp[i][j]= 0;
        if(s[i-1][j]=='.')dp[i][j]+=dp[i-1][j];
        if(s[i][j-1]=='.')dp[i][j]+=dp[i][j-1];
        if(dp[i][j]>=mod)dp[i][j]-=mod;
    }
    cout<<dp[n][m]<<"\n";


    
    return 0;
}


Measured memory_bytes: 9216
using System;
using System.Collections.Generic;

namespace ABC139_C
{
    class Program
    {
        static void Main(string[] args) {
            long n = long.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split();

            List<long> list = new List<long>();
            for (long index = 0; index < n; index++) {
                list.Add(long.Parse(input[index]));
            }

            long maxAns = 0;
            for(int index = 0; index < n - 1; index++) {
                long ans = 0;
                for (int j = index; j < n - 1; j++) {
                    if (index > 0 && list[index - 1] >= list[index]) {
                        break;
                    }

                    if (list[j] < list[j + 1]) {
                        break;
                    }

                    ans++;
                }

                if(maxAns < ans) {
                    maxAns = ans;
                }
            }

            
            Console.WriteLine(maxAns);
        }
    }
}

Measured memory_bytes: 26460
import java.util.stream.*;
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
        int[] gcd = new int[n];
        int[] temp = new int[n];

        for (int i = 1; i < n; i++)
            gcd[i] = gcd(gcd[i - 1], a[i - 1]);
        for (int i = n - 2; i >= 0; i--)
            temp[i] = gcd(temp[i + 1], a[i + 1]);
        for (int i = 0; i < n; i++)
            gcd[i] = gcd(gcd[i], temp[i]);

        Arrays.stream(gcd).max().ifPresent(System.out::println);
    }

    public static int gcd(int a, int b) {
        return 0 < b ? gcd(b, a % b) : a;
    }
}

Measured memory_bytes: 61856
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

int calc(int n){
    if((n+1)%2==1){
        if((n+1)/2%2==0){
            return n;
        } else {
            return 1^n;
        }
    } else {
        if((n+1)/2%2==0){
            return 0;
        } else {
            return 1;
        }
    }
}

signed main() {
    int A,B; cin >> A >> B;
    if(A==0){
        cout << calc(B) << endl;
    } else {
        cout << (int)(calc(A-1)^calc(B)) << endl;
    }
}

Measured memory_bytes: 256
//package abc136;
import java.io.*;
import java.util.*;

public class Main {
	// ------------------------
	
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		// ------------------------
		int n = sc.nextInt(), last = 0;
		boolean ok = true;
		for(int i = 0; i < n; i++) {
			int x = sc.nextInt();
			if(last < x)
				last = x - 1;
			else if(last > x)
				ok = false;
		}
		out.println(ok ? "Yes" : "No");
		// ------------------------
		out.close();
	}
	//------------------------
	
	public static PrintWriter out;
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


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

int main() {
    int n;
    cin >> n;
    map<int, int> m{};
    rep(i,n) {
        int x;
        cin >> x;
        m[x]++;
    }
    int ans = 0;
    int64_t no1 = 0;
    int64_t no2 = 0;
    for(auto itr = m.begin(); itr != m.end(); itr++) {
        int stick_length = itr->first;
        int stick_quantity = itr->second;
        if (stick_quantity >= 4 && stick_length > no1) {
            no1 = stick_length;
            no2 = stick_length;
        }
        else if (stick_quantity >= 2 && stick_length > no1) {
            no2 = no1;
            no1 = stick_length;
        }
        else if (stick_quantity >= 2 && stick_length > no2) {
            no2 = stick_length;
        }
        else continue;
    }
    int64_t area = no1 * no2;
    cout << area << endl;
}

Measured memory_bytes: 4992
x,n = map(int,input().split())
P = list(map(int,input().split()))

if n == 0:
    print(x)
    exit()

for i in range(51):
    if x-i not in P:
        print(x-i)
        break
    elif x+i not in P:
        print(x+i)
        break

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

int n,tot=0;
int a[100005],b[100005],c[100005];

int p[100005][205];

signed main()
{
	cin>>n;
	n++;
	for (int i=1;i<=n;i++)  cin>>a[i];
	
	b[1]=1,c[n]=a[n];
	for (int i=2;i<=n;i++)  b[i]=(b[i-1]-a[i-1])*2;
	for (int i=n-1;i>=1;i--)  c[i]=c[i+1]+a[i];
	for (int i=1;i<=n;i++)  tot+=min(b[i],c[i]);
	for (int i=1;i<=n;i++)
	{
		if (a[i]>b[i])  return cout<<-1<<endl,0;
	}
	cout<<tot<<endl;
	
	return 0;
}

Measured memory_bytes: 5972
import heapq
import sys
from itertools import accumulate
from collections import defaultdict

input = sys.stdin.readline

def main():
    X, Y, A, B, C = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    ans = 0
    P_d = defaultdict(int)
    Q_d = defaultdict(int)
    R_d = defaultdict(int)

    for i in range(len(P)):
        P[i] = -P[i]
        P_d[P[i]] += 1
        
    for i in range(len(Q)):
        Q[i] = -Q[i]
        Q_d[Q[i]] += 1

    
    for i in range(len(R)):
        R[i] = -R[i]
        R_d[R[i]] += 1

    H = P + Q + R
    heapq.heapify(H)
    red = 0
    green = 0
    nocl = 0
    ans = 0
    for i in range(A + B + C):
        tmp = heapq.heappop(H)
        if red + green + nocl == X + Y:
            print(-ans)
            exit()

        if P_d[tmp] >= 1 and red < X:
            P_d[tmp] -= 1
            red += 1
            ans += tmp
        elif Q_d[tmp] >= 1 and green < Y:
            Q_d[tmp] -= 1
            green += 1
            ans += tmp
        elif R_d[tmp] >= 1:
            R_d[tmp] -= 1
            nocl += 1
            ans += tmp
    





if __name__ == "__main__":
    main()

Measured memory_bytes: 125428
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DStringFormation {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;
        deque<char> deq;
        for (auto c : s) deq.push_back(c);
        int Q;
        cin >> Q;
        int front = 0;
        while (Q--) {
            int t;
            cin >> t;
            if (t == 1) {
                front ^= 1;
            } else {
                int f;
                char c;
                cin >> f >> c;
                if (f == 1) {
                    if (front == 0) {
                        deq.push_front(c);
                    } else {
                        deq.push_back(c);
                    }
                } else {
                    if (front == 0) {
                        deq.push_back(c);
                    } else {
                        deq.push_front(c);
                    }
                }
            }
        }
        string res;
        while (!deq.empty()) {
            if (front == 0) {
                res += deq.front();
                deq.pop_front();
            } else {
                res += deq.back();
                deq.pop_back();
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DStringFormation solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1368
import sys

A, B, C = map(int, input().split())

# +に進む
if A < B:
    if A < C < B:
        print('Yes')
        sys.exit()
    print('No')
    sys.exit()

# -に進む
if A > B:
    if B < C < A:
        print('Yes')
        sys.exit()
    print('No')
    sys.exit()

Measured memory_bytes: 3060
# D - FT Robot
# coding: utf-8

def check(d, to_d):
  meu = set([0])
  for i in to_d:
    hoge = set([])
    for j in meu: hoge.add(j+i), hoge.add(j-i)
    meu = hoge
  return d in meu

S = map(len, raw_input().split('T'))
x, y = map(int, raw_input().split())
to_x, to_y = S[2::2], S[1::2]

print "Yes" if check(x-S[0],to_x) and check(y,to_y) else "No"


Measured memory_bytes: 3280
def shift_only():
    _ = int(input())
    A = sorted(set(map(int, input().split())))

    count = 0
    temp = A
    while True:
        temp = [num / 2 for num in temp if num % 2 == 0]
        if len(temp) == len(A):
            count += 1
        else:
            print(count)
            break

if __name__ == "__main__":
    shift_only()


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

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

  bool flag = false;

  if (N/100 == 7) flag = true;
  if ((N/10)%10 == 7 ) flag = true;
  if (N%10 ==7) flag = true;

  if(flag)  cout << "Yes" << endl;
  else  cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>



int GCD(int c, int d){
    if(c%d == 0){
        return d;
    }
    else{
        return GCD(d, c%d);
    }
}

int main(void){
    long int a, b;
    while(scanf("%ld %ld", &a, &b) != EOF){
        if(a < b){
            long int x = a;
            a = b;
            b = x;
        }
        long int gcd_a_b = GCD(a, b);
        printf("%d %d\n", gcd_a_b, a*b/gcd_a_b);
    }
    return 0;
}




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


#----------
N = int(input().strip())
S_list = [input().strip() for _ in range(N)]

M = int(input().strip())
T_list = [input().strip() for _ in range(M)]
#----------
text_dic = {}

for word in S_list:
    if word not in text_dic:
        text_dic[word] = 1
    else:
        text_dic[word] += 1

for word in T_list:
    if word not in text_dic:
        text_dic[word] = -1
    else:
        text_dic[word] -= 1

result = max(text_dic.values())
if result < 0:
    result = 0

print(result)


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

int main() {
  int N;
  cin >> N;
  vector<int> ans(N, 0);
  rep(i, N - 1) {
    int A;
    cin >> A;
    A--;
    ans.at(A)++;
  }
  rep(i, N) {
    cout << ans.at(i) << endl;
  }
  return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+9;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL my_pow(int x, int y){
	LL a=1;
	REP(i,y){
		a *= x;
		a %= MOD;
	}
	return a % MOD;
}


void Main()
{
	int n; cin>>n;
	
	VI a(n);
	REP(i, n) cin >> a[i];
	
	int now = 1;
	int result = 0;

	REP(i,n){
		if(a[i] == now){
			now++;
		}
		else{
			result ++ ;
		}
	}
	if(result == n){
		cout << "-1" << endl;
		return;
	}
	cout << result << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define tam 3100
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
string txt;
ll tot=0;
void f(int pos,ll cuanto,ll auxtot)
{
    
    if (pos==txt.size())
    {
        //cout<<auxtot+cuanto<<endl;
        tot+=auxtot+cuanto;
        return;
    }
    f(pos+1,txt[pos]-'0',auxtot+cuanto);
    f(pos+1,cuanto*10+txt[pos]-'0',auxtot);
}
int main()
{
    cin>>txt;

    f(0,0,0);
    cout<<tot/2<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] h = in.nextLongArray(n);
            long[] dp = new long[n];

            dp[0] = 0;
            dp[1] = Math.abs(h[0] - h[1]);
            for (int i = 2; i < n; i++)
                dp[i] = Math.min(dp[i - 1] + Math.abs(h[i - 1] - h[i]), dp[i - 2] + +Math.abs(h[i - 2] - h[i]));

            out.println(dp[n - 1]);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

    }
}



Measured memory_bytes: 23892
n, x, m = $stdin.readline.chomp.split.map(&:to_i)
dv = Array.new(m, 0)
used = Hash.new

res = 0
q = []
m.times do |i|
  if i == 0
    y = x
  else
    y = (dv[i - 1] ** 2) % m
  end

  if !used[y].nil?
    used[y].step(i - 1) do |j|
      q << dv[j]
    end
    n -= i
    break
  else
    dv[i] = y
    used[y] = i
    res += y
  end
end

q.size.times do |i|
  res += q[i] * ((n - i + q.size - 1) / q.size)
end
puts res

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

using namespace std;

int last(int d, int i, vector<int>& t)
{
	int date = 0;

	for (int j = d ; j >= 0; j--)
	{
		if (t[j] == i)
		{
			date = j;
			break;
		}
	}
	return date;
}

int satisfy(int d, vector<int>& c, vector<int>& t)
{
	int sum = 0;
	for(int j = 0 ; j < 26 ; j++)
	{
		sum += c[j] * (d - last(d, j, t));
	}
	return sum;
}

int main()
{
	int D;

	cin >> D;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	vector<int> t(D);

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

	for (int i = 0; i < D; i++)
	{
		for (int j = 0; j < 26; j++)
		{
			cin >> s[i][j];
		}
	}


	int S = s[0][0];
	int index = 0;
	for (int i = 1; i < 26; i++)
	{
		if (s[0][i] > S)
		{
			S = s[0][i];
			index = i;
		}
	}
	t[0] = index;


	int type_s;
	int best_type = 0;
	for (int d = 1; d < D; d++)
	{
		type_s = s[d][0] - satisfy(d, c, t);

		for (int i = 1; i < 26; i++)
		{
			if (s[d][i] - satisfy(d, c, t) >= type_s)
			{
				type_s = s[d][i] - satisfy(d, c, t);
				best_type = i;
			}
		}
		t[d] = best_type;
		S += type_s;
	}

	for (int i = 0; i < D; i++)
	{
		cout << t[i] + 1 << endl;
	}

}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

#include <iostream>
using namespace std;

const int MAX = 1000005;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int X,Y;cin>>X>>Y;
    if((X+Y)%3==0 && 2*X>=Y && 2*Y>=X){
        int U=(2*X-Y)/3,V=(2*Y-X)/3;
        cout<<COM(U+V,U)<<endl;
    }else{
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n,k,a[100005],b[100005],c[100005],dp[100005][3];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(int i=1;i<n;i++)
	{		
		dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

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

  int tmp;
  bool negative = false;
  int minimum = 1e9+1;
  ll ans = 0;
  
  rep(i,n) {
    cin >> tmp;
    if (tmp < 0) {
      tmp *= -1;
      negative ^= true;
    }
    ans += tmp;
    minimum = min(minimum, tmp);
  }
  
  if (negative) {
    ans -= 2 * minimum;
  }
  
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int N,M;
	cin >> N >> M;
	int a;
	priority_queue<int> Q;
	for (int i = 0; i < N; ++i)
	{
		cin >> a;
		Q.push(a);
	}

	int temp;

	for (int i = 0; i < M; ++i)
	{
		temp = Q.top();
		Q.pop();
		temp /= 2;
		Q.push(temp);
	}

	ll ans = 0;

	for (int i = 0; i < N; ++i)
	{
		temp = Q.top();
		Q.pop();
		ans += temp;
	}

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

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool z = 0;
    for (int i = 0; i < s.length(); i++) {
        if (i % 2 && s[i] != 'i') z = 1;
        if (i % 2 == 0 && s[i] != 'h') z = 1;
    }
    if (z || s.length() % 2) cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
#define INFTY 1000000000

int merge(int A[], int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1];
    int R[n2 + 1];
    for(i=0; i<n1; i++){
        L[i] = A[left + i];
    }
    for(i=0; i<n2; i++){
        R[i] = A[mid + i];
    }
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0;
    j = 0;
    for(k=left; k<right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i += 1;
        }
        else{
            A[k] = R[j];
            j += 1;
        }
    }
    return (right - left);
}

int mergeSort(int A[], int left, int right){
    int mid = (left + right) / 2;
    int cnt = 0;
    if((left+1) < right){
        cnt += mergeSort(A, left, mid);
        cnt += mergeSort(A, mid, right);
        cnt += merge(A, left, mid, right);
    }
    return cnt;
}

int main(){
    int n;
    std::cin >> n;
    int S[n];
    for(int i=0; i<n; i++){
        std::cin >> S[i];
    }

    int left = 0;
    int right = n;
    int cnt = mergeSort(S, left, right);

    for(int i=0; i<n; i++){
        if(i != n-1) std::cout << S[i] << " ";
        else std::cout << S[i] << '\n';
    }
    std::cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 6892
#include <bits/stdc++.h>
 
#define x first
#define y second
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
 
const int mod=1000000000+7;
 
int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}
 
template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}
 
const int maxn=200000;
int N,ct[maxn];
vi al[maxn];
int X,Y;
 
int a,b,g;
void gcd(int m,int n) {
    if (n==0) {a=1;b=0;g=m;return;}
    gcd(n,m%n);
    int t=a-b*(m/n);
    a=b;b=t;
}
 
int inv(int a,int mod) {
	gcd(mod,a);
	return g>0?b:-b;
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> N >> X >> Y;
	for (int i=0;i<N;i++) {
		int c,w;
		cin >> c >> w;
		c--;
		al[c].push_back(w);
	}
	for (int i=0;i<N;i++) {
		sort(al[i].begin(),al[i].end());
	}
 
	sort(al,al+N,[](const vi& a,const vi& b) -> bool {
			if (a.size()==0) return 0;
			if (b.size()==0) return 1;
			return a[0]<b[0];
			});
 
	for (int i=0;i<N;i++) if (al[i].size()==0)
		N=i;
 
	for (int i=0;i<N;i++) if (al[i][0]+al[0][0]>Y) N=i;
	if (N<2) {
		cout << 1 << endl;
		return 0;
	}
 
	ll ans=1;
	ll tot=0;
	for (int i=0;i<N;i++) {
		for (;ct[i]<al[i].size() && (al[i][ct[i]]+al[i][0]<=X || al[i][ct[i]]+al[!i][0]<=Y);) {
			ans=ans*++tot%mod*inv(++ct[i],mod)%mod;
		}
	}
 
	if (ans<0) ans+=mod;
	cout << ans << endl;
}

Measured memory_bytes: 9856
#include <stdio.h>
#include <stdlib.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	for(int i=0;i<b;i++) a[i]=c;
	return;
}

int dp[101][301];
int main(void)
{
	int n,w,a,b,sum=0,ans=0;
	int i,j,k;
	ll p,m;
	scanf("%d%d",&n,&w);
	FOR(i,0,n){
		scanf("%d%d",&a,&b);
		if(i==0) m=a;
		a-=m;
		for(j=i;j>=0;j--){
			for(k=sum;k>=0;k--){
				dp[j+1][k+a]=MAX(dp[j+1][k+a],dp[j][k]+b);
			}
		}
		sum+=a;
	}
	FOR(i,0,n+1){
		FOR(j,0,sum+1){
			p=m*i+j;
			if(p<=w) ans=MAX(ans,dp[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}
    

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
typedef long long LL;
//typedef __int128 LL;
using namespace std;
const int maxn=55;
const int maxm=maxn*maxn*maxn;
const int IINF=1E9+77;
const LL INF=1E18+77;

int N,X,D,M[maxn],P[maxn],T;
LL DP[2][maxm];


struct NODE{
	int v;
	LL s;
	int c;
	bool operator <(const NODE &o)const{
		if(v*o.s != o.v*s){
			return v*o.s > o.v*s;
		}else{
			return s<o.s;
		}
	}
}nodes[maxn];

struct EDGE{
	int to,next;
}edges[maxn];
int cEdge=1,head[maxn];
void addEdge(int from,int to){
	edges[cEdge]=(EDGE){to,head[from]};
	head[from]=cEdge++;
}

void dfs(int u){
	nodes[u]=(NODE){1,M[u],u==1?IINF:D};
	for(int k=head[u];k;k=edges[k].next){
		int v=edges[k].to;
		dfs(v);
		nodes[u].v+=nodes[v].v;
		nodes[u].s+=nodes[v].s;
	}
}

pair<LL,int> Q[maxn][maxn*maxn];
int qh[maxn],qr[maxn];

void push(int x,LL v,int p){
	while(qh[x]!=qr[x] && v <= Q[x][qr[x]-1].first) --qr[x];
	Q[x][qr[x]++]=make_pair(v,p);
}

LL query(int x,int p){
	while(qh[x]!=qr[x] && Q[x][qh[x]].second < p) ++qh[x];
	return Q[x][qh[x]].first;
}

int main(){
	scanf("%d%d%d",&N,&X,&D);
	scanf("%d",M+1);
	for(int i=2;i<=N;++i){
		scanf("%d%d",M+i,P+i);
		addEdge(P[i],i);
	}

	dfs(1);

	//for(int i=1;i<=N;++i) cerr<<nodes[i].v<<" "<<nodes[i].s<<" "<<nodes[i].c<<endl;

	for(int i=1;i<maxm;++i){
		DP[T][i]=INF;
		//if(i<9) cerr<<"DP["<<1<<"]["<<i<<"]="<<DP[T][i]<<endl;
	}

	for(int i=1;i<=N;++i){
		T^=1;
		int v=nodes[i].v;
		LL s=nodes[i].s;
		int c=min(nodes[i].c,maxn);
		nodes[i].c-=c;
		for(int j=0;j<maxm;++j){
			push(j%v,DP[T^1][j]-(j/v)*s,j/v);
			DP[T][j]=query(j%v,(j/v)-c)+(j/v)*s;
			//if(j<9) cerr<<"DP["<<i<<"]["<<j<<"]="<<DP[T][j]<<endl;
		}
		memset(qh,0,sizeof(qh));
		memset(qr,0,sizeof(qr));
		//cerr<<endl;
	}

	for(int i=maxm-2;i>=0;--i){
		DP[T][i]=min(DP[T][i],DP[T][i+1]);
		//if(i<9) cerr<<"DP["<<i<<"]="<<DP[T][i]<<endl;
	}

	//cerr<<"??"<<endl;

	sort(nodes+1,nodes+N+1);
	int p=1,V=0,ans=0;
	LL S=0;
	for(int i=maxm-1;i>=0;--i){
		while(true){
			while(p<=N && !nodes[p].c) ++p;
			if(p<=N && DP[T][i]+S+nodes[p].s <= X){
				int t=(X-DP[T][i]-S)/nodes[p].s;
				if(t>nodes[p].c) t=nodes[p].c;

				V+=nodes[p].v*t;
				S+=nodes[p].s*t;
				nodes[p].c-=t;
			}else{
				break;
			}
		}
		if(DP[T][i]+S <= X){
			//cerr<<i<<":"<<DP[T][i]<<"  S:"<<S<<endl;
			//cerr<<"dp["<<i<<"]="<<DP[T][i]<<endl;
			//if(i+V > ans) cerr<<":"<<i<<" "<<V<<endl;
			ans=max(ans,i+V);
		}
	}

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

Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
vector<int>adj[200010];
vector<int>tp[2];
void dfs(int x,int p,int t)
{
    tp[t].eb(x);
    for(int&v:adj[x])
        if(v!=p)
            dfs(v,x,t^1);
    return;
}
vector<int>mod[3];
int col[200010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    dfs(1,0,0);
    if(tp[0].size()>tp[1].size())
        swap(tp[0],tp[1]);
    for(int i=0;i++<n;)
        mod[i%3].eb(i);
    vector<int>ver;
    vector<int>cv;
    for(int&t:tp[0])
        ver.eb(t);
    for(int&t:tp[1])
        ver.eb(t);
    if(tp[0].size()>=mod[2].size())
    {
        for(int&t:mod[2])
            cv.eb(t);
        for(int&t:mod[0])
            cv.eb(t);
        for(int&t:mod[1])
            cv.eb(t);
    }
    else
    {
        for(int&t:mod[0])
            cv.eb(t);
        for(int&t:mod[1])
            cv.eb(t);
        for(int&t:mod[2])
            cv.eb(t);
    }
    for(int i=0;i<n;i++)
        col[ver[i]]=cv[i];
    for(int i=0;i++<n;)
        cout<<col[i]<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 24304
a=input()
s=[(int(a[0])*10)+int(a[1]),(int(a[2])*10)+int(a[3])]

if s[0]>=13 and s[1]==0:
  print("NA")
elif s[0]==0 and s[1]==0:
  print("NA")
elif s[0]>=13 and s[1]>=13:
  print("NA")
elif 1<=s[0]<=12 and 1<=s[1]<=12:
  print("AMBIGUOUS")
elif s[0]>=13 and 1<=s[1]<=12:  
  print("YYMM")
elif s[0]==0 and 1<=s[1]<=12:
  print("YYMM")
elif 1<=s[0]<=12 and s[1]==0:
  print("MMYY")
elif 1<=s[0]<=12 and s[1]>=13:
  print("MMYY")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	double x,h;
	while(true){
	scanf("%lf%lf",&x,&h);if(x==0&&h==0)break;
	double ans=x*x+2*x*sqrt((x/2)*(x/2)+h*h);
	printf("%.50lf\n",ans);
	}

	return 0;
}

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

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  if (a > b) {
    printf("Alice");
  } else if (a == b) {
    printf("Draw");
  } else {
    printf("Bob");
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#define X first
#define Y second
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7; 

string s;
int q,t,f,x;
char c;
vector<char>a,b;

int main()
{
	cin>>s>>q;
	
	while(q--)
	{
		scanf("%d",&t);
		
		if(t==1) x++;
		else 
		{			
			scanf("%d",&f);
			cin>>c;
			
			if(x&1)
			{
				if(f==1) s.insert(s.end(),c);
				else s.insert(s.begin(),c);
			}
			else 
			{
				if(f==1) s.insert(s.begin(),c);
				else s.insert(s.end(),c);
			}
		}
	}

	
	if(x&1) reverse(s.begin(),s.end());
	
	cout<<s<<endl;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}









Measured memory_bytes: 900
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll stone[100005]={0};
int in[100005]={0};
int idx[100005]={0},nidx[100005]={0};
vector<int> kn[100005],node[100005];
ll dp[100005]={0};
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>stone[i];
  vector<P> vec;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    vec.push_back(P(a,b));
    in[a]++;
    in[b]++;
    kn[a].push_back(b);
    kn[b].push_back(a);
  }
  if(n==2){
    if(stone[1]==stone[2]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
  }
  int ma=0,mp=0;
  for(int i=1;i<=n;i++){
    if(ma<in[i]){
      ma=in[i];
      mp=i;
    }
  }
  queue<int> que;
  vector<bool> used(n+1,false);
  int cnt=0;
  que.push(mp);
  while(!que.empty()){
    int pos=que.front();
    que.pop();
    used[pos]=true;
    idx[cnt]=pos;
    nidx[pos]=cnt;
    cnt++;
    for(int i=0;i<kn[pos].size();i++){
      int to=kn[pos][i];
      if(!used[to]) {
        que.push(to);
        node[pos].push_back(to);
      }
    }
  }
  /*cout<<mp<<endl;
  for(int i=0;i<n;i++) cout<<idx[i]<<" ";
  cout<<endl;*/
  for(int i=n-1;i>=0;i--){
    int pos=idx[i];
    if(node[pos].size()==0) {
      dp[pos]=stone[pos];
      continue;
    }
    ll a=0,a1=20000000000,a2=0;
    for(int j=0;j<node[pos].size();j++){
      int son=node[pos][j];
      a+=dp[son];
      a1=min(a1,dp[son]);
      a2=max(a2,dp[son]);
    }
    ll c=stone[pos];
    ll p=a-c;
    if(p<0||a-a2-p<0||p*2>a){
      cout<<"NO"<<endl;
      return 0;
    }
    else dp[pos]=2*c-a;
  }
  /*for(int i=1;i<=n;i++) cout<<dp[i]<<" ";
  cout<<endl;*/
  if(dp[mp]==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 14708
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);
    sort(begin(A), end(A));
    int mi = 1<<30;
    for (int i = A[0]; i <= A[N-1]; i++) {
        int sum = 0;
        rep(j,N) sum += pow(A[j] - i, 2);
        mi = min(mi, sum);
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
#include <stdio.h> 
int main(void){ 
     int x,y; 
     while(1){ 
         scanf("%d %d", &x, &y); 
         if(x==0 && y==0)break; 
         if(x<y){ 
             printf("%d %d\n", x, y); 
         }else{ 
             printf("%d %d\n", y, x); 
         } 
 } 
    return 0; 
 } 





Measured memory_bytes: 1920