akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 10000
#define NIL -1
 
struct Node { int p, l, r; };
struct Node T[MAX];
int n;
 
void preParse(int u) {
    if ( u == NIL ) return;
    printf( " %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
     
}
 
void inParse(int u) {
    if ( u == NIL ) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}
 
void postParse(int u) {
    if ( u == NIL ) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}
 
int main() {
     
    int i, v, l, r, root;
     
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        T[i].p = NIL;
    }
    for ( i = 0; i < n; i++ ) {
        scanf ( "%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if ( l != NIL ) T[l].p = v;
        if ( r != NIL ) T[r].p = v;
    }
     
    for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;
     
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
     
}


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

using namespace std;

int main() {
//#define LOCAL
#ifdef LOCAL
    freopen("/Users/ttjy/Desktop/in.txt", "r", stdin);
#endif
    int n, k;
    cin >> n >> k;
    int p[1010];
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    sort(p, p + n);
    int sum = 0;
    while (k--) {
        sum += p[k];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memset( x, y, sizeof x )
using namespace std;

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

const int MAXN = 200010;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;

int n, x, y, f[MAXN], mn1, pos1, mn2, pos2, fac[MAXN], inv[MAXN];

struct node
{
	int c, w, id;
	bool operator < ( const node &b ) const { return c < b.c || ( c == b.c && w < b.w ); }
}e[MAXN];

struct info
{
	map < int, int > cnt;
	int size;
}g[MAXN];

inline int findfa(int x) { while( x ^ f[ x ] ) x = f[ x ] = f[ f[ x ] ]; return x; }

inline void merge(int x, int y) { f[ findfa( x ) ] = findfa( y ); }

inline int qpow(int x, int y) { int ret = 1; for( ; y ; y >>= 1, x = 1LL * x * x % mod ) if( y & 1 ) ret = 1LL * ret * x % mod; return ret; }

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	mn1 = mn2 = INF;
	scanf( "%d%d%d", &n, &x, &y );
	fac[ 0 ] = 1;
	for( int i = 1 ; i <= n ; i++ ) fac[ i ] = 1LL * fac[ i - 1 ] * i % mod;
	inv[ n ] = qpow( fac[ n ], mod - 2 );
	for( int i = n - 1 ; i ; i-- ) inv[ i ] = 1LL * inv[ i + 1 ] * ( i + 1 ) % mod;
	for( int i = 1 ; i <= n ; i++ ) scanf( "%d%d", &e[ i ].c, &e[ i ].w ), e[ i ].id = i, f[ i ] = i;
	sort( e + 1, e + n + 1 );
	for( int l = 1, r = 1 ; l <= n ; l = ++r )
	{
		while( r < n && e[ r + 1 ].c == e[ l ].c ) r++;
		for( int i = l + 1 ; i <= r ; i++ ) if( e[ i ].w + e[ l ].w <= x ) merge( e[ i ].id, e[ l ].id );
		if( e[ l ].w < mn1 ) mn2 = mn1, pos2 = pos1, mn1 = e[ l ].w, pos1 = l;
		else if( e[ l ].w < mn2 ) mn2 = e[ l ].w, pos2 = l;
	}
	for( int i = 1 ; i <= n ; i++ )
		if( e[ i ].c != e[ pos1 ].c )
			if( e[ i ].w + e[ pos1 ].w <= y )
				merge( e[ i ].id, e[ pos1 ].id );
	if( pos2 )
	for( int i = 1 ; i <= n ; i++ )
		if( e[ i ].c != e[ pos2 ].c )
			if( e[ i ].w + e[ pos2 ].w <= y )
				merge( e[ i ].id, e[ pos2 ].id );
	for( int i = 1 ; i <= n ; i++ )
		g[ findfa( e[ i ].id ) ].size++, g[ findfa( e[ i ].id ) ].cnt[ e[ i ].c ]++;
	int ret = 1;
	for( int i = 1 ; i <= n ; i++ ) if( findfa( i ) == i )
	{
		ret = 1LL * ret * fac[ g[ i ].size ] % mod;
		for( auto j : g[ i ].cnt ) ret = 1LL * ret * inv[ j.yy ] % mod;
	}
	cout << ret << endl;
}


Measured memory_bytes: 25216
#include <stdio.h>
int main(void){
int a,b,c;
while(1)
{
	scanf("%d %d %d",&a,&b,&c);
	if(a==-1&&b==-1&&c==-1)break;
	if(a==-1||b==-1)printf("F\n");
	else if(a+b>=80)printf("A\n");
	else if(a+b>=65 && a+b<80)printf("B\n");
	else if(a+b>=50 && a+b<65)printf("C\n");
	else if(a+b>=30 && a+b<50){
	if (c>=50)printf("C\n");
	else printf("D\n");
	}
	else if(a+b<30)printf("F\n");
}
return 0;
}

Measured memory_bytes: 584
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long N;

int main()
{
	scanf("%lld", &N);
	if(N < 1000) {
		printf("ABC\n");
	}
	else {
		printf("ABD\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC166D
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            for (int i = 1; i < 1000; i++)
            {
                for(int j = 0; j < i; j++)
                {
                    int A = i * i * i * i * i;
                    int B = j * j * j * j * j;
                    if (A - B == X)
                    {
                        Console.WriteLine("{0} {1}", i, j);
                        return;
                    }
                    else if (A + B == X)
                    {
                        Console.WriteLine("{0} {1}", i, -j);
                        return;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 27544
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    if (sum == max(a, max(b, c)) * 2) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from typing import List


def answer(w: int, h: int, n: int, xyas: List[List[int]]) -> int:
    bottom_left_corner_of_white = {'x': 0, 'y': 0}
    top_right_corner_of_white = {'x': w, 'y': h}

    for xya in xyas:
        x, y, a = xya
        if a == 1:
            if bottom_left_corner_of_white['x'] < x:
                bottom_left_corner_of_white['x'] = x
        if a == 2:
            if x < top_right_corner_of_white['x']:
                top_right_corner_of_white['x'] = x
        if a == 3:
            if bottom_left_corner_of_white['y'] < y:
                bottom_left_corner_of_white['y'] = y
        if a == 4:
            if y < top_right_corner_of_white['y']:
                top_right_corner_of_white['y'] = y

    width_of_white = max(0, top_right_corner_of_white['x'] - bottom_left_corner_of_white['x'])
    height_of_white = max(0, top_right_corner_of_white['y'] - bottom_left_corner_of_white['y'])

    return width_of_white * height_of_white


def main():
    w, h, n = map(int, input().split())
    xyas = [list(map(int, input().split())) for _ in range(n)]
    print(answer(w, h, n, xyas))


if __name__ == '__main__':
    main()

Measured memory_bytes: 10272
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    vector<int>dpa(n);
    vector<int>dpb(n);
    vector<int>dpc(n);
    dpa[0]=a[0];
    dpb[0]=b[0];
    dpc[0]=c[0];
    for(int i=1;i<n;i++)
    {
        dpa[i]=max(dpb[i-1],dpc[i-1])+a[i];
        dpb[i]=max(dpa[i-1],dpc[i-1])+b[i];
        dpc[i]=max(dpa[i-1],dpb[i-1])+c[i];
        //cout<<dpa[i]<<" "<<dpb[i]<<" "<<dpc[i]<<endl;
    }
    cout<<max(dpa[n-1],max(dpb[n-1],dpc[n-1]));
}


Measured memory_bytes: 4992
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //abc061 c
    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long k = in.nl();
        Pair[] pair = new Pair[n];
        for (int i = 0; i < n; i++) pair[i] = new Pair(in.ni(), in.ni());
        Arrays.sort(pair);
        for (int i = 0; i < n; i++) {
            if(k>pair[i].y){
                k -= pair[i].y;
            }else{
                out.println(pair[i].x);
                break;
            }
        }
    }
    public static class Pair implements Comparable<Pair>{
        Integer x; Integer y;
        public Pair(Integer x, Integer y){
            this.x = x;
            this.y = y;
        }
        @Override
        public int compareTo(Pair o) {
            return Integer.compare(x, o.x);
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 42860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
ll ans[300][300];

int main(void){
    ll h, w, k;
    cin >> h >> w >> k;

    string cake[h];
    rep(i, 0, h){
        cin >> cake[i];
    }

    ll count = 1;
    rep(i, 0, h){
        ll flag = 0;
        rep(j, 0, w){
            if(cake[i][j] == '#'){
                flag = 1;
            }
        }
        if(flag == 0){
            continue;
        }else{
            ll c = 0;
            rep(j, 0, w){
                if(cake[i][j] == '#'){
                    c++;
                }
                if(c <= 1){
                    ans[i][j] = count;
                }else{
                    ans[i][j] = count + c - 1;
                }
            }
            count += c;
        }
    }

    rep(i, 0, h - 1){
        rep(j, 0, w){
            if(ans[i + 1][j] == 0){
                ans[i + 1][j] = ans[i][j];
            }
        }
    }
    rrep(i, h - 1, 1){
        rep(j, 0, w){
            if(ans[i - 1][j] == 0){
                ans[i - 1][j] = ans[i][j];
            }
        }
    }

    rep(i, 0, h){
        rep(j, 0, w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//

int main() {
  use_cio();
  int n;
  cin >> n;
  vector<int> va(n);
  rep(i, n) cin >> va[i];
  reverse(all(va));
  vector<int> lds = {va[0]};
  for (int i = 1; i < n; i++) {
    if (lds.back() <= va[i])
      lds.push_back(va[i]);
    else
      lds[upper_bound(all(lds), va[i]) - lds.begin()] = va[i];
  }
  cout << lds.size() << endl;
}


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

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

typedef long long ll;
using namespace std;

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

  ll X, t;
  cin >> X >> t;
  cout << X - min(X, t) << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

n, y = map(int, input().split())


for m in range(n+1):
    for g in range(n-m+1):
        s = n - m -g
        if 10000*m + 5000*g + 1000*s ==y:
            print('{} {} {}'.format(m,g,s))
            sys.exit()

print('-1 -1 -1')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long int
#define INF 10000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;
ll height[100005], ans[100005];

ll F(ll j, ll K)
{
    if(j == 1)
        return 0;
    else if(ans[j] != -1)
        return ans[j];
    else
    {
        ll mn = INF;
        for(int i = 1; i <= K; i++)
        {
            if(j - i < 1)
                break;
            ll diff = abs(height[j] - height[j - i]);
            mn = min(mn, F(j - i, K) + diff);
        }
        return ans[j] = mn;
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++)
    {
        ans[i] = -1;
        cin >> height[i];
    }
    ll Ans = F(N, K);
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	int n;
	cin>>n;
	int ar[2][n];
	fore(i, 0, 2) fore(j, 0, n) cin>>ar[i][j];
	int ax[2][n];
	int t;
	int pl, pr, pll, prr;
	int res = 0;
	fore(i, 1, 30)
	{
		t = 1 << i;
		fore(i, 0, 2) fore(j, 0, n) ax[i][j] = ar[i][j] % t;
		fore(i, 0, 2) sort(ax[i], ax[i] + n);
		pl = pll = n-1;
		prr = pr = n-1;
		t /= 2;
		/*cout<<'\n';
		fore(i, 0, 2)
		{
			fore(j, 0, n) cout<<ax[i][j]<<' ';
			cout<<'\n';
		}cout<<'\n';*/
		fore(j, 0, n)
		{
			while(pl > -1 && ax[0][pl] + ax[1][j] >= t)
				pl--;
			while(pr > -1 && ax[0][pr] + ax[1][j] >= 2 * t)
				pr--;
			//pll = prr = pr;
			while(pll > -1 && ax[0][pll] + ax[1][j] >= 3 * t)
				pll--;
			while(prr > -1 && ax[0][prr] + ax[1][j] >= 4 * t)
				prr--;
			//cout<<pl<<' '<<pr<<' '<<pll<<' '<<prr<<'\n';
			//cout<<i<<' '<<j<<' '<<pr - pl + prr - pll - 2<<'\n';
			res ^= ((pr - pl + prr - pll) & 1) << (i-1);
		}
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

int main(){
  int n,d;
  cin >>n >>d;
  int D = 1+2*d;
  cout << (n+D-1)/D << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := 0
	answer := 1
	for i := 1; i <= n; i++ {
		x := i
		count := 0
		for x%2 == 0 {
			x = x / 2
			count = count + 1
		}
		if count > m {
			m = count
			answer = i
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll sum = 0;
	int n = 0;
	int a[50];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			sum += a[i] * a[j];
		}
	}
	cout << sum << endl;
}

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

ll a[200004],b[200004];
int n;
bool check(ll m){
    rep(i,n){
        ll tmp;
        if(i==0)tmp=0;
        else tmp=b[i-1];
        int ss=lower_bound(b+i,b+n+i,tmp+m)-b;
        int tt=lower_bound(b+i,b+n+i,b[ss]+m)-b;
        if(b[n+i-1]-b[tt]>=m) return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>a[i];
    for(int i=n;i<2*n;i++)a[i]=a[i-n];
    b[0]=a[0];
    for(int i=1;i<2*n;i++)b[i]=a[i]+b[i-1];
    ll l=1,r=b[n-1];
    while(r-l>1){
        ll mid=(l+r)/2;
        if(check(mid))l=mid;
        else r=mid;
    }
    cout<<l<<endl;
  return 0;
}



Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 55;
ll f[N], l[N];

ll g (ll n, ll x) {
  assert(x <= l[n]);
  if (n == 0) return x;
  if (x == l[n]) return f[n];
  if (x == 0) return 0;
  ll mid = l[n - 1] + 2;
  if (x < mid) return g(n - 1, x - 1);
  else if (x > mid) return 1 + f[n - 1] + g(n - 1, x - 2 - l[n - 1]);
  else return 1 + f[n - 1];
}

int main() {
  ll n, x;
  scanf("%lld%lld", &n, &x);
  f[0] = l[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = 1 + 2 * f[i - 1];
    l[i] = 3 + 2 * l[i - 1];
  }
  printf("%lld\n", g(n, x));
}



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

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

    int h,w,n;
    cin >> h >> w >> n;
    
    vector<int> arr;
    
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        
        for(int j = 0; j < a; j++){
            arr.push_back(i+1);
        }
    }
    
    vector<vector<int>> board(h,vector<int>(w));
    
    int i = 0,j = 0,itr = 0;

    while(true){
        
        for(i = 0; i < w; i++){
            board[j][i] = arr[itr];
            itr++;
        }
        j++;
        
        if(itr == h * w) break;
        
        for(i = w - 1; i >= 0; i--){
            board[j][i] = arr[itr];
            itr++;
        }
        j++;
        
        if(itr == h * w) break;
        
    }
    
    for(int k = 0; k < h; k++){
        for(int l = 0; l < w; l++){
            if(l == w - 1) cout << board[k][l] << endl;
            else cout << board[k][l] << " ";
        }
    }
    
    
}


Measured memory_bytes: 892
#!/usr/bin python3
# -*- coding: utf-8 -*-

k = int(input())
ret = 1
res = 7%k
while res != 0 and ret <= k:
    res *= 10
    res += 7
    res %= k
    ret += 1
if res != 0:
    print(-1)
else:
    print(ret)

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

#define M 1000000
#define L 12

char H[M][L];

int getcha(char ch)
{
	if(ch == 'A')
	{
		return 1;
	}
	else if(ch == 'C')
	{
		return 2;
	}
	else if(ch == 'G')
	{
		return 3;
	}
	else if(ch == 'T')
	{
		return 4;
	}
	else
	{
		return 0;
	}
}

long long getkey(char str[])
{

	long long sum = 0, p=1, i;
	
	for(i=0; i< strlen(str); i++)
	{
		sum += p*(getcha(str[i]));
		p *= 5;
	}

	return sum;
}

int h1(int key)
{
	return key%M;
}


int h2(int key)
{
	return 1+(key%(M-1));
}


int find(char str[])
{
	long long key, i, h;
	key = getkey(str);
	
	for(i=0; ; i++)
	{
		h = ( h1(key)+i*h2(key) )%M;
		
		if(strcmp(H[h],str) == 0)
		{
			return 1;
		}
		else if(strlen(H[h]) == 0)
		{
			return 0;
		}
	}
	
	return 0;
	
	
	
}


int insert(char str[])
{
	long long key, i, h;
	key = getkey(str);
	
	for(i=0; ; i++)
	{
		h = ( h1(key)+i*h2(key) )%M;
		
		if(strcmp(H[h],str) == 0)
		{
			return 1;
		}
		else if(strlen(H[h]) == 0)
		{
			strcpy(H[h], str);
			return 0;
		}
	}
	
	return 0;
	
}


int main(void)
{

int i, n, h;

char com[9], str[L];

for(i=0; i<M; i++)
{
	H[i][0] = '\0';
}

scanf("%d", &n);
	
for(i=0; i<n; i++)
{
	scanf("%s %s", com, str);
	
	if(com[0] == 'i')
	{
		insert(str);
	}
	else
	{
		if(find(str))
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}
}
	
	return 0;
	
	



}


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

int N, M;
vector<pii> G[100010];
int use[100010], dis[100010];

int dfs(int cur) {
  int tmp = 0;
  for (pii &e : G[cur]) {
    if (use[e.first]) {
      tmp += dis[e.first] != dis[cur] + e.second;
    } else {
      use[e.first] = 1;
      dis[e.first] = dis[cur] + e.second;
      tmp += dfs(e.first);
    }
  }
  return tmp;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int L, R, D;
    cin >> L >> R >> D;
    L--; R--;
    G[L].emplace_back(R, D);
    G[R].emplace_back(L, -D);
  }
  int no = 0;
  for (int i = 0; i < N; i++) {
    if (use[i]) continue;
    use[i] = 1;
    no += dfs(i);
  }
  cout << (no ? "No" : "Yes") << endl;

  return 0;
}

Measured memory_bytes: 12416
#include<iostream>
using namespace std;
int main(){
    int a[3];
    for(int i=0; i<3;i++) cin>>a[i];
    
    for(int i=2;i>0;i--){
        for(int j=0;j<i;j++)
        if(a[j]>a[j+1]) swap(a[j],a[j+1]);
    }
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
}


Measured memory_bytes: 3120
import math
a,b,h,m = map(int, open(0).read().split())
rm = m / 60 * 360
rh = h / 12 * 360 + (30 / 60 * m)
r = min(rh-rm, 360-(rh-rm))
y = r * (math.pi / 180)
c = a**2 + b**2 - (2 * a * b * math.cos(y))
ans = math.sqrt(c)
print(ans)


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define SZ(v)       (ll)(v).size()
#define ALL(v)      (v).begin(),(v).end()
#define UNIQ(v)     sort(ALL(v));(v).erase(unique(ALL(v)),(v).end())
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define BIT(n)      (1LL<<(n))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>
#define SHOW(x)     cout<<#x<<" = "<<x<<endl

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

int main() {
    ll N, T; cin >> N >> T;
    vector<ll> A(N); REP(i, N) cin >> A[i];
    
    ll minv = inf;
    ll maxv = 0;
    ll ans = 0;
    REP(i, N) {
        if (minv > A[i]) {
            minv = A[i];
        } else if (maxv < A[i] - minv) {
            maxv = A[i] - minv;
            ans = 1;
        } else if (maxv == A[i] - minv) {
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

int main(void)
{
    int A[5];
    for(int i = 0; i < 5; i++){
        cin >> A[i];
    }
    int min = 10;
    int num = -1;
    for(int i = 0; i < 5; i++){
        int t = (A[i]-1) % 10;
        if(min > t){
            min = t;
            num = i;
        }
    }

    int sum = 0;
    for(int i = 0; i < 5; i++){
        if(i != num){
            
            int ten;
            if(A[i] % 10 == 0){
                ten = (A[i]);
            }else{
                ten = (A[i] / 10 + 1) * 10;
            }
            sum += ten;
            //cout << i << " " << ten << endl;
        }
        
    }
    sum += A[num];
    cout << sum << endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const long double PI = acos(-1);

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


Measured memory_bytes: 256
def main():
    a,b,c,k = map(int, input().split())
    if a > k:
        ans = k
    elif a + b < k:
        c_n = k - (a+b)
        ans = a - c_n
    else:
        ans = a
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 61652
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



const int MOD = 1000000007;

long long dp[250][250];
int n;
char c[250];

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) cin >> c[i];
        
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= i; ++j) {
                
                if (c[i] == '-') {
                    (dp[i+1][j+1] += dp[i][j]) %= MOD;
                }
                else if (c[i] == 'U') {
                    (dp[i+1][j] += dp[i][j]) %= MOD;
                    (dp[i+1][j+1] += dp[i][j] * (i-j)) %= MOD;
                }
                else if (c[i] == 'D') {
                    (dp[i+1][j+1] += dp[i][j] * (i-j)) %= MOD;
                    (dp[i+1][j+2] += dp[i][j] * (i-j) * (i-j)) %= MOD;
                }
            }
        }
        
        cout << dp[n][n] << endl;
    }
    
    return 0;
}




                
                
                
                
                
                


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    int N;
    cin >> N;
    if(N == 1){
        cout << "Hello World" << endl;
    }else{
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
}


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

int main() {
   int N;
   cin>>N;
	   int x=0;
   for(int i=0;i<N;i++){
	   string S;
	   cin >>S;
	   x++;
	if(S=="Y"){
		cout <<"Four"<<endl;
		x=0; 
		break;
	}
   }
   if(x){
	   cout<<"Three"<<endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int R, C, N; cin >> R >> C >> N;
    map<int, int> M;
    auto toindex = [=](int x, int y) {
        if (y == 0) return x;
        if (x == R) return R+y;
        if (y == C) return R+C+R-x;
        if (x == 0) return R+C+R+C-y;
        return -1;
    };
    for (int i = 0; i < N; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int idx1 = toindex(x1, y1);
        int idx2 = toindex(x2, y2);
        if (idx1 == -1 || idx2 == -1) continue;
        M[idx1] = M[idx2] = i;
    }
    stack<int> S;
    for (auto& p : M) {
        int elem; tie(ignore, elem) = p;
        if (!S.empty() && S.top() == elem) S.pop();
        else S.push(elem);
    }
    auto YESNO = vector<string>{"NO", "YES"};
    cout << YESNO[S.empty()] << '\n';
    return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#include <complex.h>
#include <math.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace std;
// fendwick tree
//#include <ext / pb_ds / assoc_container.hpp> //required
//#include <ext/pb_ds/tree_policy.hpp>         //required
using namespace __gnu_pbds; //required
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<int> s;
ordered_set<int>::iterator itr;
// fendwick tree
/*
ll ans[200005];
void fun(ll a, ll b, ll c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        ll p = -a;
        a += (a & p);
    }
}
ll find1(ll a)
{
    ll sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        ll p = -a;
        a -= (a & p);
    }
    return sum;
}*/
long long int fastexpo(long long int a, long long int b, ll m)
{
    long long int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return ans;
}
int main()
{
    int t;

    cin >> t;
    int arr[t];
    int max1 = 0;
    int sum = 0;
    for (int i = 0; i < t; i++)
    {
        cin >> arr[i];
        max1 = max(max1, arr[i]);
        sum += arr[i];
    }
    cout << sum - (max1 / 2) << "\n";
    return 0;
}

Measured memory_bytes: 3544
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k, *a = map(int, read().split())
v = 0
ans = 0
for i in range(40, -1, -1):
    cnt = 0
    for aa in a:
        if (aa >> i) & 1:
            cnt += 1
    if n - cnt > cnt and v + (1 << i) <= k:
        v += 1 << i
        ans += (n - cnt) * (1 << i)
    else:
        ans += cnt * (1 << i)
print(ans)


Measured memory_bytes: 12492
#include <stdio.h>

double a(double x1,double y1,double x2,double y2,double x,double y){
	return (x1-x2)*(y-y1)-(y1-y2)*(x-x1);
}

int main(void){
	double xa,ya,xb,yb,xc,yc,xd,yd;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF){
		if(a(xa,ya,xc,yc,xb,yb)*a(xa,ya,xc,yc,xd,yd)<0&&a(xb,yb,xd,yd,xa,ya)*a(xb,yb,xd,yd,xc,yc)<0)
			puts("YES");
		else puts("NO");
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <vector>
using namespace std;
#define ll long long
int main()
{
	int x;
	cin >> x;
	while (1)
	{
		bool ok = true;
		for (int i = 2; i * i <= x; i++)
		{
			if (x % i==0)
			{
				ok = false; break;
			}
		}
		if (ok)	break;
		x++;
	}
	cout << x;
	system("pause>0");
	return 0;
}


Measured memory_bytes: 504
a_cards = list(input())
b_cards = list(input())
c_cards = list(input())

cur_turn = "a"

while True:
    if cur_turn == "a":
        if len(a_cards) == 0:
            print("A")
            break
        cur_turn = a_cards.pop(0)
    elif cur_turn == "b":
        if len(b_cards) == 0:
            print("B")
            break
        cur_turn = b_cards.pop(0)
    elif cur_turn == "c":
        if len(c_cards) == 0:
            print("C")
            break
        cur_turn = c_cards.pop(0)


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

int main(){
    std::vector<std::vector<int>> grid(3, std::vector<int>(3));
    int sum = 0;
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
            std::cin >> grid.at(i).at(j);
            sum += grid.at(i).at(j);
        }
    }

    int a, b, c, d, e, f;
    for(int i = 0; i < 2; ++i){
        a = grid.at(0).at(i + 1) - grid.at(0).at(i);
        b = grid.at(1).at(i + 1) - grid.at(1).at(i);
        c = grid.at(2).at(i + 1) - grid.at(2).at(i);
        d = grid.at(i + 1).at(0) - grid.at(i).at(0);
        e = grid.at(i + 1).at(1) - grid.at(i).at(1);
        f = grid.at(i + 1).at(2) - grid.at(i).at(2);
    }

    std::string ans = "No";
    if(a == b && b == c && d == e && e == f){
        ans = "Yes";
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
const int MAX = 1000000;
const int MOD = 1000000007;

long long 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(int argc, char const *argv[])
{
    COMinit();
    int x, y;
    cin >> x >> y;
    int ans = 0;
    rep(a, x + 1)
    {
        int b = y - 2 * a;
        if (b < 0 || 2 * b + a != x)
        {
            continue;
        }
        ans += COM(a + b, a);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23808
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    string ans;
    if(x==25){
        ans = "Christmas";
    }else if(x==24){
        ans = "Christmas Eve";
    }else if(x==23){
        ans ="Christmas Eve Eve";
    }else{
        ans = "Christmas Eve Eve Eve";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int K,S;
  int ans = 0;
  
  cin >> K;//最大値
  
  if (K > 1) {
    
    cin >> S;//合計
    
    if (S >=0 && S <= 3*K) {
      
      for(int x = 0; x <= K; x++){
        
		for(int y = 0; y <= K; y++){
          
			int z = S - x - y;
          
 			if(0 <= z and z <= K){
 				ans = ans + 1;
 			}
 		}
 	  }
    
      
    }
    
  }
  
  
cout << ans <<endl;
  
}

Measured memory_bytes: 3536
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

namespace IntegerMath
{
  int64_t sqrt(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::sqrtl( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t log2(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log2l( 
        static_cast<long double>(x)
      ) )
    );
  }    

  int64_t log10(int64_t x) {
    return static_cast<int64_t>(
      ::floorl( ::log10l( 
        static_cast<long double>(x)
      ) )
    );
  }

  int64_t number_of_digits(int64_t x) {
    return static_cast<int64_t>(
      ::ceill( ::log10l( 
        static_cast<long double>(x + 1)
      ) )
    );
  }

  uint64_t gcd(uint64_t a, uint64_t b)
  {
    uint64_t n = std::min(a, b), m = std::max(a, b);
    return (n == 0) ? m : gcd(m % n, n);
  }

  uint64_t lcm(uint64_t a, uint64_t b)
  {
    uint64_t d = gcd(a, b);
    return (a % d == 0) ? (a / d) * b : a * (b / d);
  }
};

int main(int argc, char **argv)
{
  uint64_t N;
  std::cin >> N;
  
  std::vector<uint64_t> A(N);
  N_TIMES(n, N) { std::cin >> A[n]; }
  
  std::vector<uint64_t> L(N, 1), R(N, 1);
  L[0] = A[0];
  N_TIMES(n, N - 1) {
    L[n + 1] = IntegerMath::gcd(L[n], A[n + 1]);
  }
  
  R[N - 1] = A[N - 1];
  N_TIMES_REV(n, N - 1) {
    R[n] = IntegerMath::gcd(R[n + 1], A[n]);
  }
  
  uint64_t M = 0;
  N_TIMES(n, N) {
    if (n == 0) {
      M = std::max(M, R[n + 1]);
    } else if (n == N - 1) {
      M = std::max(M, L[n - 1]);
    } else {
      M = std::max(M, IntegerMath::gcd(L[n - 1], R[n + 1]));
    }
  }
  std::cout << M << std::endl;
  
  return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    reverse(ALL(a));
    ll mn = 2;
    ll mx = 2;

    REP(i, n) {
        int x = a[i];
        mn = ((mn + x - 1) / x) * x;
        mx = (mx / x) * x + x - 1;
        if (mn > mx) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << mn << " " << mx << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	long long n; cin >> n;
	long long a = n;
	int keta = 1;
	long long ans = 0;
	while (a / 10 != 0) {
		keta++;
		a = a / 10;
	}
	if (keta % 2 == 0) {
		for (int i = 1; i < keta; i++) {
			if (i % 2 == 1) {
				ans += pow(10, i) - pow(10, i - 1) ;
			}
		}
	}
	else {
		for (int i = 1; i < keta; i++) {
			if (i % 2 == 1) {
				ans += pow(10, i) - pow(10,i-1);
			}
		}
			ans += n - pow(10, keta-1)+1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    string s; cin >> s;
    _LL pre[2];
    _LL next[2];
    pre[0] = 0; pre[1] = 10;
    _LL l = s.length();
    rep(i, l)
    {
        _LL t = s[l - 1 - i] - '0';
        next[0] = min(pre[0] + t, pre[1] + t + 1);
        next[1] = min(pre[0] + abs(10 - t), pre[1] + abs(10 - t - 1));
        swap(pre, next);
    } 
    cout << min( pre[0], pre[1] + 1);
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  int ab_count = 0;
  int b_s = 0;
  int s_a = 0;
  int b_s_a = 0;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    
    char prev = s[0];
    for(int j = 1; j < (int)s.size(); j++){
      if(s[j - 1] == 'A' && s[j] == 'B') ab_count++;
      prev = s[j];
    }
    
    if(s[0] == 'B'){
      if(s[s.size() - 1] == 'A') b_s_a++;
      else b_s++;
    }else if(s[s.size() - 1] == 'A'){
      s_a++;
    }
  }
  
  if(b_s == 0 && s_a == 0){
    ab_count += max(b_s_a - 1, 0);
  }else if(b_s == 0 || s_a == 0){
    ab_count += b_s_a;
  }else{
    ab_count += min(b_s, s_a) + b_s_a;
  }
  
  cout << ab_count << endl;
  
  return 0;
}

Measured memory_bytes: 256
x=int(input())
list=[]
for i in range(x):
    a,b,c=input().split()
    list.append((int(a),int(b),int(c)))
    a=int(a)
    b=int(b)
    c=int(c)
    if a*a==b*b+(c*c):
        print("YES")
    elif b*b==a*a+(c*c):
        print("YES")
    elif c*c==a*a+(b*b):
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
/*
x       0  1  2  3  4  5  6  7  8  9
bsr(x) -1  0  1  1  2  2  2  2  3  3
*/
int bsr(ll x){
	if(x==0) return -1;
	return 63 ^ __builtin_clzll(x);
}

ll dp[100010][2];
ll a[100010];
int main(){
	int N;
	cin>>N;
	rep(i,N) cin>>a[i];
	rep(i,N+1) rep(j,2) dp[i][j] = 1e18;
	rep(i,N){
		int k = bsr(a[i]);
		if(i==0){
			if((1LL<<k) == a[i]){
				dp[1][0]=k;
			}else{
				dp[1][1]=k+1;
			}
			continue;
		}
		int pk = bsr(a[i-1]);
		if((1LL<<k) == a[i]){
			rep(pt,2){
				chmin(dp[i+1][0],dp[i][pt]+k-min(k,pk+pt));
			}
		}else{
			rep(pt,2){
				rep(t,2){
					chmin(dp[i+1][1-t],dp[i][pt]+k+1-min(k+t,pk+pt));
				}
			}
		}
	}
	cout<<min(dp[N][0],dp[N][1])<<endl;
}


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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) cout << mat[i][j] << " "; cout << endl; }

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;


int main(){

	ll N; cin >> N;
	ll A[N+1], B[N];
	rep(i, 0, N+1) cin >> A[i];
	rep(i, 0, N) cin >> B[i];
	
	ll tt = 0;
	rep(i, 0, N){
		ll t = min(B[i], A[i]);
		tt += t;
		A[i]-=t, B[i]-=t;
		t = min(B[i], A[i+1]);
		tt += t;
		A[i+1]-=t, B[i]-=t;
	}
	
	cout << tt << '\n';
	
	return 0;
}

Measured memory_bytes: 1792
def main():
    s = input()

    for i in range(len(s) - 1):
        if s[i] != s[-1 - i]:
            print('No')
            exit()

    for i in range((len(s) - 1)//2):
        if s[i] != s[(len(s) - 1)//2 - 1 - i]:
            print('No')
            exit()

    print('Yes')

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384