akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL
#define maxN 1000007

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
// structure
#define ii pair<int, int>
#define iii pair<ii, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>

// get value
#define FF first
#define SS second

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const ii& a, const ii& b) {return (a.FF > b.FF || (a.FF == b.FF && a.SS >= b.SS));}
ll GCD(ll a, ll b) {return (a%b) ? GCD(b, a%b) : b;}

const string namePro = "tmp";

ll f[maxN], _f[maxN];
int a[maxN];

int main() {

    int n;
    scanf("%d", &n);

    multiset <int> st;
    fto (i, 1, 3*n) scanf("%d", &a[i]);

    fto (i, 1, n) {
        st.insert(a[i]);
        f[i] = f[i-1]+a[i];
    }

    fto (i, n+1, 2*n) {
        st.insert(a[i]);
        f[i] = f[i-1]+a[i];
        multiset <int> :: iterator it = st.begin();
        f[i] -= *it;
        st.erase(it);
    }

    st.clear();
    fdto (i, 3*n, 2*n+1) {
        st.insert(a[i]);
        _f[i] = _f[i+1]+a[i];
    }

    fdto (i, 2*n, n+1) {
        st.insert(a[i]);
        _f[i] = _f[i+1]+a[i];
        multiset <int> :: iterator it = st.end();
        --it;
        _f[i] -= *it;
        st.erase(it);
    }

    ll ans = -OO;
    fto (i, n, 2*n) {
        ans = max(ans, f[i]-_f[i+1]);
    }

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

Measured memory_bytes: 14336
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    string s;
    cin>>s;

    for(int i = 1;i < s.size();i++) {
        if(s[i-1] == s[i]) {
            cout<<"Bad"<<endl;

            return 0;
        }
    }

    cout<<"Good"<<endl;

    return 0;
}





Measured memory_bytes: 256
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	orig := io.ScanBytes()
	q := io.ScanInt()
	reversed := false
	head := make([]byte, 0)
	tail := make([]byte, 0)
	for i := 0; i < q; i++ {
		if io.ScanInt() == 1 {
			reversed = !reversed
			continue
		}
		f, c := io.ScanInt(), io.ScanBytes()
		if f == 1 && reversed || f == 2 && !reversed {
			tail = append(tail, c...)
		} else {
			head = append(head, c...)
		}
	}
	ReverseBytes(head)
	ans := append(head, append(orig, tail...)...)
	if reversed {
		ReverseBytes(ans)
	}
	io.Println(string(ans))
}

func ReverseStrings(s []string) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

func ReverseBytes(bytes []byte) {
	for i, j := 0, len(bytes)-1; i < j; i, j = i+1, j-1 {
		bytes[i], bytes[j] = bytes[j], bytes[i]
	}
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(s string) {
	fmt.Fprintln(io.writer, s)
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define sz size()

const int MOD = 1e9 + 7;

void add(int& x, int y)
{
	x += y;
	if(x >= MOD)
		x -= MOD;
}

void sub(int& x, int y)
{
	x -= y;
	if(x >= MOD)
		x -= MOD;

	if(x < 0)
		x += MOD;
}

int main()
{
	ios::sync_with_stdio(0);

	int i, j, k, n;
	cin >> n >> k;
	vector<int> dp(k+1);

	dp[0] = 1;
	for(i=0;i<n;++i)
	{
		int a;
		cin >> a;

		vector<int> diff(k+1);

		for(int used=k;used>=0;--used)
		{
			int l = used + 1;
			int r = used + min(a, k - used);
			if(l <= r)
			{
				add(diff[l], dp[used]);
				if(r + 1 <= k)
					sub(diff[r+1], dp[used]);
			}
			
		}

		for(j=0;j<=k;++j)
		{
			if(j) add(diff[j], diff[j-1]);
			add(dp[j], diff[j]);
		}
	}

	
	cout << dp[k] << "\n";

	return 0;
}

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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<=n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define sz(v) ((int)(v).size())
#define get(a,st,en)  fl(i,st,en)       cin>>a[i]
#define pr(a,st,en)     fl(i,st,en)     cout<<a[i]<<" \n"[i==en]

const int MOD = 1e9+7;
void solve()    {
        int x, n;       cin>>x>>n;
        vector<int> arr(n);
        for(auto &i: arr)       cin>>i;
        sort(all(arr));
        for(int i=0; ; i++)     {
                if(!binary_search(all(arr), x-i))       {
                        cout<<x-i;      break;
                }
                if(!binary_search(all(arr), x+i))       {
                        cout<<x+i;      break;
                }
        }
}
int main()  {
    fast;
    //test()
        solve();
}
// credits @Benq
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/



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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    if (s[k - 1] == 'A') { s[k - 1] = 'a'; }
    if (s[k - 1] == 'B') { s[k - 1] = 'b'; }
    if (s[k - 1] == 'C') { s[k - 1] = 'c'; }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn];
int a,b,c,d;

int main()
{
	int T=read();
	while(T--)
	{
		scanf("%s",s+1);
		if(s[1]=='A') a++;
		if(s[1]=='W') b++;
		if(s[1]=='T') c++;
		if(s[1]=='R') d++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<b<<endl;
	cout<<"TLE x "<<c<<endl;
	cout<<"RE x "<<d<<endl;
	return 0;
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline

s = list(input().rstrip())
k = int(input())
n = len(s)

group = []

cnt = 0

from collections import Counter
c = Counter(s)
if len(c) == 1:
    print(n*k//2)
    sys.exit()

for i in range(n):
    if i == 0:
        cnt += 1
        continue
    elif i == n - 1:
        if s[i] == s[i - 1]:
            cnt += 1
            group.append(cnt)
        else:
            group.append(cnt)
            group.append(1)
        continue
    
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        group.append(cnt)
        cnt = 1
ans = 0
if k == 1:
    for i in group:
        ans += i//2
    print(ans)
    sys.exit()
from copy import deepcopy
first = deepcopy(group)
last = deepcopy(group)
if s[0] == s[-1]:
    first[-1] += last[0]
    last[0] = 0

for i in first:
    ans += i//2
for i in last:
    ans += i//2
if k == 2:
    print(ans)
    sys.exit()
mid = deepcopy(first)
if s[0] == s[-1]:
    mid[0] = 0
temp = 0
for i in mid:
    temp += i//2
ans += temp*(k - 2)
print(ans)




Measured memory_bytes: 3436
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
typedef long long ll;
ll a[100005];
 
int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        ans -= y;
        a[i] = x + y;
    }
    sort(a, a + n);
    for (int i = n - 1; i >= 0; i -= 2) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static int ans;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		String S3 = sc.next();
		sc.close();
		char c = S1.charAt(0);
		solve(S1.substring(1, S1.length()), S2, S3, c);
		if(ans == 1) System.out.println("A");
		else if(ans == 2) System.out.println("B");
		else System.out.println("C");
	}
	static void solve(String S1, String S2, String S3, char n) {
		//System.out.println(S1 + " " + S2 + " " + S3 + " " + n);
		if(n == 'a') {
			if(S1.length() == 0) {ans = 1; return;}
			char c = S1.charAt(0);
			solve(S1.substring(1, S1.length()), S2, S3, c);
		}else if(n == 'b') {
			if(S2.length() == 0) {ans = 2; return;}
			char c = S2.charAt(0);
			solve(S1, S2.substring(1, S2.length()), S3, c);
		}else if(n == 'c') {
			if(S3.length() == 0) {ans = 3; return;}
			char c = S3.charAt(0);
			solve(S1, S2, S3.substring(1, S3.length()), c);
		}

	}
}

Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <string>
#include <climits>
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '(') {
            ++cnt;
        } else if (cnt) {
            --cnt;
        } else {
            s.insert(s.begin(), '(');
            ++i;
            ++n;
        }
    }

    cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == ')') {
            ++cnt;
        } else if (cnt) {
            --cnt;
        } else {
            s.push_back(')');
        }
    }
    cout << s;

	return 0;
}


Measured memory_bytes: 256
N, C = map(int, input().split())
xs = []
vs = []
for i in range(N):
    x, v = map(int, input().split())
    xs += [x]
    vs += [v]

costOAs = [0] + xs
costOBs = [0] + [C - x for x in reversed(xs)]

# 時計回りに、A個目まで食べる場合
accV = 0
eneOAs = [0] * (N + 1)
maxOAs = [0] * (N + 1)
for A, v in enumerate(vs, 1):
    accV += v
    eneOAs[A] = accV - costOAs[A] # 差し引きエネルギー
    maxOAs[A] = max(maxOAs[A - 1], eneOAs[A])

# 反時計回りに、B個目まで食べる場合
accV = 0
eneOBs = [0] * (N + 1)
maxOBs = [0] * (N + 1)
for B, v in enumerate(reversed(vs), 1):
    accV += v
    eneOBs[B] = accV - costOBs[B] # 差し引きエネルギー
    maxOBs[B] = max(maxOBs[B - 1], eneOBs[B])

# O→B(→O→A)
ans = 0
for B in range(N + 1):
    ene = eneOBs[B] + max(0, -costOBs[B] + maxOAs[N - B])
    ans = max(ans, ene)

# O→A(→O→B)
for A in range(N + 1):
    ene = eneOAs[A] + max(0, -costOAs[A] + maxOBs[N - A])
    ans = max(ans, ene)

print(ans)


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int D, T, S;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::cin >> D >> T >> S;

    if(D <= S * T){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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 T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c,k; cin >> a >> b >> c >> k;
    int p = max({a,b,c}); int pp = p;
    while(k--)p*=2;
    out(a+b+c+p-pp);

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int n;
	scanf("%d ",&n);
	int a[n];
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++){
		if(i!=n-1)	printf("%d ",a[n-1-i]);
		else printf("%d", a[n-1-i]);
	}
	printf("\n");
}



Measured memory_bytes: 2728
/*Templates are for weak. -invictus_123*/
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void add_self(int &a, int b) {
	a += b;
	if(a >= MOD) {
		a -= MOD;
	}
}
int main() {
 	int h, w;
 	scanf("%d%d", &h, &w);
 	char grid[h][w];
 	vector <vector <int>> dp(h, vector <int>(w));
 	for(int i = 0; i < h; i ++) {
 		scanf("%s", grid[i]);
 	}    
 	dp[0][0] = 1;
 	for(int i = 0; i < h; i ++) {
 		for(int j = 0; j < w; j ++) {
 			if(i + 1 < h && j < w && grid[i][j] == '.') {
 				add_self(dp[i + 1][j], dp[i][j]);
 			}
 			if(i< h && j + 1 < w && grid[i][j] == '.') {
 				add_self(dp[i][j + 1], dp[i][j]);
 			}
 		}
 	}
 	printf("%d", dp[h - 1][w - 1] % MOD);
    return 0;
}

Measured memory_bytes: 5120
import sys
import math

sys.setrecursionlimit(10**7)

n = int(input())
l = []
if n%2 == 0:
    l.append(0)
    while n%2 == 0:
        l[0] += 1
        n /= 2

i = 3
while i*i <= n:
    if n%i == 0:
        l.append(0)
        while n%i == 0:
            l[-1] += 1
            n /= i
    i += 2
if n != 1:
    l.append(1)

ans = 0
for i in range(len(l)):
    j = 1
    while True:
        l[i] -= j
        j += 1
        if l[i] < 0:
            break
        ans += 1
print(ans)

Measured memory_bytes: 63724
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int T = scanner.nextInt();
		int ans = 2000;
		for (int i= 0; i<n; i++){
			int c = scanner.nextInt();
			int t = scanner.nextInt();
			if (t<=T) ans = Math.min(ans, c);
		}
		if (ans == 2000) System.out.println("TLE");
		else System.out.println(ans);
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define maxn 55
#define maxm 125010
typedef pair<int,long long> pii;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,X,D,l,s,ans,fa[maxn],pos[maxm];
long long f[maxm];
pii a[maxn],Q[maxm];
pii operator + (const pii &x,const pii &y)
{
	return {x.first+y.first,x.second+y.second};
}
bool cmp(const pii &x,const pii &y)
{
	return 1ll*x.first*y.second>1ll*y.first*x.second;
}
int main()
{
	read(n,X,D);
	a[1]={1,read<int>()};
	for(int i=2;i<=n;i++)
	{
		a[i]={1,read<int>()};
		read(fa[i]);
	}
	for(int i=n;i>=2;i--)
		a[fa[i]]=a[fa[i]]+a[i];
	sort(a+1,a+1+n,cmp);
	memset(f,0x7f,sizeof(f));
	f[0]=0;
	l=min(n,D);
	for(int i=1;i<=n;i++)
	{
		s+=n*a[i].first;
		for(int r=0;r<a[i].first;r++)
		{
			int tot=0;
			for(int j=r;j<=s;j+=a[i].first)
				pos[++tot]=j;
			int h=1,t=0;
			for(int j=tot,k=tot;j>=1;j--)
			{
				while(h<=t&&Q[h].first>j)
					h+=1;
				for(;k>=1&&k>=j-l;k--)
				{
					pii x={k,f[pos[k]]-a[i].second*k};
					while(h<=t&&Q[t].second>=x.second)
						t-=1;
					Q[++t]=x;
				}
				f[pos[j]]=min(f[pos[j]],Q[h].second+a[i].second*j);
			}
		}
	}
	for(int i=0;i<=s;i++)
	{
		if(f[i]>X)
			continue;
		int sum=X-f[i],res=i;
		for(int j=1;j<=n;j++)
		{
			int ned=sum/a[j].second;
			if(a[j].first<n)
				ned=min(ned,D-l);
			sum-=a[j].second*ned;
			res+=a[j].first*ned;
		}
		ans=max(ans,res);
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2432
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    count = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500 * i + 100 * j + 50 * k == x:
                    count += 1

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int main(){
	IOS;
	string s,t;
	cin>>s>>t;
	int dp[3002][3002];
	int n=s.length();
	int m=t.length();
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1])
			dp[i][j]=1+dp[i-1][j-1];
			else
			dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
	}
	int i=n,j=m;
	vector<char> ans;
	while(i&&j)
	{
		if(s[i-1]==t[j-1])
		{ ans.push_back(s[i-1]);
		i--;
		j--;
		}
		else if(dp[i][j-1]>dp[i-1][j])
		j--;
		else
		i--;
	}
	reverse(ans.begin(),ans.end());
	for(auto i:ans)
	cout<<i;
}

Measured memory_bytes: 38828
import java.util.Scanner;

/**
 * Counting of Trees
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] D = new int[N];
            for (int i = 0; i < N; i++) {
                D[i] = sc.nextInt();
            }

            int[] C = new int[N];
            for (int i = 0; i < N; i++) {
                C[D[i]]++;
            }

            if (D[0] != 0 || C[0] != 1) {
                System.out.println(0);
                return;
            }

            long ans = 1;
            for (int i = 1; i < N; i++) {
                for (int j = 0; j < C[i]; j++) {
                    ans = ans * C[i - 1] % 998244353;
                }
            }

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 51432
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<double> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    vector<int> id(N);
    iota(id.begin(), id.end(), 0);
    double res = 0;
    do {
      for (int i = 1; i < N; i++) {
        int a = id[i - 1];
        int b = id[i];
        res += hypot(y[a] - y[b], x[a] - x[b]);
      }
    } while (next_permutation(id.begin(), id.end()));
    for (int i = 0; i < N; i++) res /= (i + 1);
    printf("%.20f\n", res);
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int n,x; cin>>n>>x;
    int a[n]; rep(i,n) cin>>a[i];
    long ans=0;
    if(a[0]>x){
        ans+=a[1]+a[0]-x;
        a[0]=x;
        a[1]=0;
    }
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            int tmp=a[i+1];
            a[i+1]=x-a[i];
            ans+=tmp-a[i+1];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;
const int mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    bool f = 1;
    if(s[0] != 'A') f = 0;
    int C = 0, l = 0;
    for(int i=2; i<s.size()-1; i++){
        if(s[i] == 'C') C++;
    }
    rep1(i, s.size()){
        if('a' <= s[i] && s[i] <= 'z') l++;
    }
    if(C != 1) f = 0;
    if(l != s.size()-2) f = 0;
    cout << (f ? "AC":"WA") << endl;



}

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

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

  int m1 = a[0], m2 = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] > m1) {
      m2 = m1;
      m1 = a[i];
    } else if (a[i] > m2) {
      m2 = a[i];
    }
  }
  
  rep(i, n) {
    if (a[i] == m1) cout << m2 << endl;
    else cout << m1 << endl;
  }
  return 0;
}

Measured memory_bytes: 4060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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 T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
/*istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}*/
const ll INF=1e9+7;

vector<ll> len;

ll dfs(ll N,ll X){
    if(N==0 && X==1) return 1;
    if(X==1) return 0;
    if(2<=X && X<=len[N-1]+1) return dfs(N-1,X-1);
    if(X==len[N-1]+2) return dfs(N-1,len[N-1])+1;
    if(len[N-1]+3<=X && X<=2*len[N-1]+2) return dfs(N-1,len[N-1])+dfs(N-1,X-len[N-1]-2)+1;
    if(X==2*len[N-1]+3) return 2*dfs(N-1,len[N-1])+1;
}

int main()
{
    ll n,x;
    cin >> n >> x;
    len.resize(n+1);
    len[0]=1;
    for(ll i=1;i<=n;i++){
        len[i]=2*len[i-1]+3;
    }
    cout << dfs(n,x) << endl;
    return 0;
} 


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
macro_rules! chmax {
    ($ base : expr ,$ cmp : expr ) => {
        $base = max($base, $cmp);
    };
}

#[fastout]
fn main() {
    input! {//
       mut s:Chars,
        mut t:Chars,
    }
    let s = con(&s);
    let mut ss = t.clone();
    ss.push('$');
    while ss.len() <= 2 * t.len() + t.len() + 1 {
        for &c in s.iter() {
            ss.push(c);
        }
    }
    for &c in s.iter() {
        ss.push(c);
    }
    let mut z = zalgo(&ss);
    let mut dp = vec![0; 3030300];
    let mut ans = 0;
    let mut i = ss.len() - 1;
    while ss[i] != '$' {
        if z[i] == t.len() {
            dp[i] = dp[i + t.len()] + 1;
        }
        chmax!(ans, dp[i]);
        i -= 1;
    }
    if ans > 0 && (t.len() % s.len() == 0) {
        println!("{}", -1);
    } else {
        println!("{}", ans);
    }
}

pub fn zalgo(s: &Vec<char>) -> Vec<usize> {
    let n = s.len();
    let mut a = vec![0usize; n];
    let mut from = 0;
    let mut last = 0;
    a[0] = n;
    for i in 1..n {
        let mut same = a[i];
        if from != 0 {
            same = std::cmp::min(a[i - from], if last > i { last - i } else { 0 });
        }
        while i + same < n && s[same] == s[same + i] {
            same += 1;
        }
        if last < i + same {
            last = i + same;
            from = i;
        }
        a[i] = same;
    }
    return a;
}
fn kmp(s: &Vec<char>) -> Vec<usize> {
    let n = s.len();
    let mut i = 0;
    let mut j = -1;
    let mut a = vec![!0; n + 1];
    while i < n {
        while (!j != 0 && s[i] != s[j as usize]) {
            j = a[j as usize] as i64;
        }
        a[i + 1] = (j + 1) as usize;
        i += 1;
        j += 1;
    }
    a
}
fn con(s: &Vec<char>) -> &[char] {
    let kmp = kmp(s);
    let c = s.len() - kmp[s.len()];
    if s.len() % c == 0 {
        &s[0..c]
    } else {
        &s[..]
    }
}


Measured memory_bytes: 40244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10,p=119<<23|1,inv2=(p+1)>>1;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
int mul(int x,int y){return (ll)x*y%p;}
int power(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=mul(x,x))
		if (y&1) ans=mul(ans,x);
	return ans;
}
int n,m,fac[N],ifac[N],ans;
int C(int n,int m){return mul(fac[n],mul(ifac[m],ifac[n-m]));}
int main()
{
	scanf("%d%d",&n,&m);
	fac[0]=1;
	for (int i=1;i<=n+m;i++) fac[i]=mul(fac[i-1],i);
	ifac[n+m]=power(fac[n+m],p-2);
	for (int i=n+m;i;i--) ifac[i-1]=mul(ifac[i],i);
	if (n<m) swap(n,m);
	int ans=0;
	for (int i=1;i<=m;i++) ans=inc(ans,mul(C(i+i,i),C(n+m-i-i,n-i)));
	ans=mul(ans,mul(inv2,power(C(n+m,n),p-2)));
	printf("%d\n",inc(ans,n));
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
     int main() {
       int N, K, X, Y;
       std::cin >> N;
       std::cin >> K;
       std::cin >> X;
       std::cin >> Y;
       
       if (N >= K) {
         int ans = K * X + (N - K) * Y;
       
       std::cout << ans <<std::endl;
       } else {
         int ans = N * X;
         std::cout << ans <<std::endl;
       }
       return 0;
     }

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

int main()
{
	int n;
	long long a[10000],sum=0,ans1,ans2;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	//????°????
	for (int i = 0; i < n-1; i++) {
		if (a[i] < a[i + 1]) {
			swap(a[i], a[i + 1]);
		}
	}
	ans1 = a[n - 1];
	//?????§???
	for (int i = 0; i < n-1; i++) {
		if (a[i] > a[i + 1]) {
			swap(a[i], a[i + 1]);
		}
	}
	ans2 = a[n - 1];
	//????¨?
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}

	cout <<ans1<<" "<<ans2<<" "<< sum<< endl;

	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

const ll mod = 1000000007;
const ll INF = 1000000000000;

ll N, M, p, A[5010], B[5010], C[5010], d[2510];

bool rp[2510];

vector<P> G[2510];

int main()
{
	ll a, b;
	cin >> a >> b;

	cout << max(a + b, max(a - b, a * b)) << endl;

	int www;
	cin >> www;
}

Measured memory_bytes: 256
N = int(input())
def is_square(n):
    m = int(n**.5)
    return True if abs(m*m - n) < 1e-6 else False
divs = []
f = False
if is_square(N):
    divs = [int(N**.5)]*2
    f = True
for i in range(int(N**.5),0,-1):
    if f: break
    if N % i == 0: divs += [i, N//i]
    if len(divs) >= 2: break
print(max([len(str(x)) for x in divs]))

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;
    ll taka;
    ll ao;

    cin >> taka >> ao;

    for (ll i = 2; i <= n; ++i) {
        ll t, a; cin >> t >> a;

        ll bt = (taka + (t - 1)) / t;
        ll ba = (ao + (a - 1)) / a;

        ll mx = max(bt, ba);

        taka = t * mx;
        ao = a * mx;
    }

    cout << taka + ao << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
using ll = long long;
class UnionFindTree
{
private:
    vector<int> parent;
    vector<int> rank;
public:
    UnionFindTree(int n)
    {
        init(n);
    }

    void init(int n)
    {
        parent.resize(n);
        rank.resize(n, 0);

        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
        }
    }

    // find root node
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        // already in the same tree.
        if (x == y)
            return;

        if (rank[x] < rank[y])
        {
            parent[x] = y;
        }
        else
        {
            parent[y] = x;
            if (rank[x] == rank[y])
            {
                rank[x]++;
            }
        }
    }

    bool same(int x, int y)
    {
        return (find(x) == find(y));
    }
};

int main(void) {
    int N, M;
    cin >> N >> M;

    UnionFindTree uft(N);

    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;

        uft.unite(a, b);
    }

    map<int, int> groupCnt;
    
    for (int i = 0; i < N; i++)
    {
        int par = uft.find(i);
        groupCnt[par]++;
    }
    
    int ans = 0;
    
    for (auto const& elem : groupCnt)
    {
        ans = max(elem.second, ans);
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13860
#include <iostream>
#include <algorithm>
using namespace std;
int n,m;
struct o{
	long long c;
	long long b; //c商店的价格 b数量 
};
int cmp(o a,o b){
	return a.c<b.c;
} 
int main()
{
	cin>>n>>m;
	o a[n+1]; 
	for(int i=1;i<=n;i++) {
		cin>>a[i].c;
		cin>>a[i].b;
	}
	sort(a+1,a+n+1,cmp);
	int p=m;
	long long t=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].b<=p){
			t+=a[i].c*a[i].b;
			p-=a[i].b;
		}
		else{
			t+=p*a[i].c;
			break;
		}
		if(p==0) break;
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  string S; cin >> S;
  bool flag=true;
  rep(i,3){
      if(S[i]==S[i+1]){
          flag=false;
      }
  }
  if(flag) cout << "Good" << endl;
  else cout << "Bad" << endl;
  
}


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

int main(){
   int n,m;cin>>n>>m;
   vector<int> ok(n,0),wa(n,0);

   rep(i,m){
       int p;
       string s;
       cin>>p>>s;p--;
       if(s=="WA"){
           if(!ok[p])wa[p]++;
           
       }
       else{
           ok[p]=1;
       }
   }
   int cnt=0,pn=0;
    rep(i,n){
        if(ok[i]){
            cnt++;
            pn += wa[i];
        }
    }
printf("%d %d",cnt,pn);

return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int main(){
	int n=read();
	printf("%d\n",360/__gcd(360,n));
}

Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main() {
    int c[52],n,a;
    char x;
    
    for(int i=0;i<52;i++){
            c[i]=0;
        }
        
        cin >> n;
        
        for(int j=1;j<=n;j++){
            cin >> x >> a;
            
            if(x=='S')
                c[a-1]=a;
                
            if(x=='H')
                c[a+13-1]=a;
                
            if(x=='C')
                c[a+26-1]=a;
                
            if(x=='D')
                c[a+39-1]=a;
        }
        
        
        for(int k=0;k<52;k++){
            
            if(c[k]==0){
                
                if(k<13)
                cout << "S " << k+1 << endl;
                
                else if(k<26)
                cout << "H " << k-12 << endl;
                
                else if(k<39)
                cout << "C " << k-25 << endl;
                
                else
                cout << "D " << k-38 << endl;
            }
            
        }
        
    }



Measured memory_bytes: 3096
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		s += "T";
		int x = sc.nextInt();
		int y = sc.nextInt();
		int right = 0;
		while (s.startsWith("F")) {
			s = s.substring(1);
			right++;
		}
		x -= right;
		ArrayList<Integer> RorL = new ArrayList<>();
		ArrayList<Integer> UorD = new ArrayList<>();
		boolean isRorL = true;
		int count = 0;
		for (char c : s.toCharArray()) {
			if (c == 'T') {
				if (isRorL) {
					if (count != 0) {
						RorL.add(count);
					}
				} else {
					if (count != 0) {
						UorD.add(count);
					}
				}
				count = 0;
				isRorL = !isRorL;
			} else {
				count++;
			}
		}
		final int magic = 20000;
		x += magic;
		y += magic;
		//テーブル構築//dp[i][j]でi回目の操作で座標軸上のn+magicに居られるかどうか
		boolean xdp[][] = new boolean[RorL.size() + 1][2*magic+100];
		boolean ydp[][] = new boolean[UorD.size() + 1][2*magic+100];
		//dp初期条件
		xdp[0][magic] = true;
		ydp[0][magic] = true;
		//dp
		for (int i = 0; i < RorL.size(); i++) {
			for (int j = 0; j < 2*magic+100; j++) {
				if (xdp[i][j]) {
					if (j - RorL.get(i) >= 0) {
						xdp[i + 1][j - RorL.get(i)] = true;
					}
					if (j + RorL.get(i) < 2*magic+100) {
						xdp[i + 1][j + RorL.get(i)] = true;
					}
				}
			}
		}
		for (int i = 0; i < UorD.size(); i++) {
			for (int j = 0; j < 2*magic+100; j++) {
				if (ydp[i][j]) {
					if (j - UorD.get(i) >= 0) {
						ydp[i + 1][j - UorD.get(i)] = true;
					}
					if (j + UorD.get(i) < 2*magic+100) {
						ydp[i + 1][j + UorD.get(i)] = true;
					}
				}
			}
		}
		if (xdp[RorL.size()][x] && ydp[UorD.size()][y]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 244180
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n+1),bs(n);
  for(Int i=0;i<=n;i++) cin>>as[i];
  for(Int i=0;i<n;i++) cin>>bs[i];

  Int ans=0;
  for(Int i=0;i<n;i++){
    {
      Int num=min(as[i],bs[i]);
      as[i]-=num;
      bs[i]-=num;
      ans+=num;
    }
    {
      Int num=min(as[i+1],bs[i]);
      as[i+1]-=num;
      bs[i]-=num;
      ans+=num;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
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 argc, char const *argv[])
{
    scanf("%d", &n);

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

    for(int i=0; i<n;i++){
        int l, id, r;
        scanf("%d %d %d", &id, &l, &r);
        T[id].l = l;
        T[id].r = r;
        if(l != NIL) T[l].p = id;
        if(r != NIL) T[r].p = id;
    }
    
    int root;
    for(int 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");

    return 0;
}



Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll
 
const int N 	= 1e6;
const int INF 	= 0x3f3f3f3f3f3f3f3fLL;
int n;
int a[N];
int b[N];
 
signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);
	
	cin >> n;
	for (int i = 0; i <= n; ++i) {
		cin >> a[i];
	}
	if (n == 0) {
		if (a[0] != 1) {
			cout << "-1\n";
		} else {
			cout << "1\n";
		}
		return 0;
	}
	if (a[0]) {
		cout << "-1\n";
		return 0;
	}
	b[0] = 1;
	for (int i = 1; i <= n; ++i) {
		b[i] = min(INF, 2 * b[i - 1] - a[i]);
		if (b[i] < 0) {
			cout << "-1\n";
			return 0;
		}
	}
	b[n] = 0;
	for (int i = n; i > 0; --i) {
		b[i - 1] = min(b[i - 1], a[i] + b[i]);
	}
	int answer = 0;
	for (int i = 0; i <= n; ++i) {
		answer += a[i] + b[i];
	}
	cout << answer << "\n";
    return 0;
}


Measured memory_bytes: 5240
#include <iostream>
using namespace std;
//using ll=long long;

int main(){
    int D;
    cin >> D;
    if(D == 25) cout << "Christmas" << endl;
    else if(D == 24) cout << "Christmas Eve" << endl;
    else if(D == 23) cout << "Christmas Eve Eve" << endl;
    else if(D == 22) cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 504
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll h, w;
string row;

int main() {
    fast_io; cout_precision;
    cin >> h >> w;
    for (ll i = 0; i < h; i++) {
        cin >> row;
        cout << row << endl << row << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10001000];
int i,j;
int n;
void pk()
{
    int maxn=10000000;
    a[2]=1;
    for(i=3; i<=maxn; i++)
    {
        if(i%2==1)
            a[i]=1;
    }
    for(i=3; i<=maxn; i+=2)
    {
        if(a[i]==1)
        {
            for(j=3*i; j<=maxn; j+=2*i)
            {
                a[j]=0; 
            }
        }
    }

}
int main()
{
    pk();
    cin>>n;
    {
        if(a[n]!=0)
           cout<<n<<endl;
        else {
          int i=n;
          while(a[i]==0){
          i++;
          }
          cout<<i<<endl;
          }
        }
}


Measured memory_bytes: 39296
#include <stdio.h>
int main(){

  int a,b;

  scanf("%d%d",&a,&b);
  if(a < b){
    printf("a < b\n");
  }
  else if(a > b){
    printf("a > b\n");
  }
  else printf("a == b\n");

  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()


int main(){
  int ab, bc ,ca;
  cin >> ab >> bc >> ca;

  cout << ab*bc/2;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            graph = Enumerable.Repeat(0, (int)N).Select(_ => new List<long>()).ToArray();
            for (var i = 0; i < N - 1; ++i)
            {
                var (a, b) = Slice2<long>();
                --a; --b;
                graph[a].Add(b);
                graph[b].Add(a);
            }

            void dfs(long root, long parent, long[] dst)
            {
                foreach (var g in graph[root])
                {
                    if (g == parent) continue;
                    dst[g] = dst[root] + 1;
                    dfs(g, root, dst);
                }
            }
            var fDst = new long[N];
            var sDst = new long[N];
            dfs(0, -1, fDst);
            dfs(N - 1, -1, sDst);
            var fMasu = 0L;
            for (var i = 0; i < N; ++i)
            {
                if (fDst[i] <= sDst[i])
                    ++fMasu;
            }
            if (N - fMasu < fMasu)
                WriteLine("Fennec");
            else
                WriteLine("Snuke");
        }
        static List<long>[] graph;

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 57992