akhauriyash/Code-Regression huggingface dataset:
import math

def main():
    N = input()
    n = [input() for x in range(N)]
    c = 0

    for i in range(N):
        if prime(n[i]):
            c += 1

    print(c)

def prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            return False
    return True

main()

Measured memory_bytes: 5372
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

int main() {
	
	fast;
	
	ll a;
	long double b, p;
	cin>>a>>b;
	
	p = (long double)(a*b);
	ll x = floor(p);
	
	cout<<x;
	
	return 0;
}


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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

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


int main()
{
    string s;
    cin >> s;
    string t = "";
    int n = s.size();
    rep(i,n){
        if(i+1 < n && s[i] == 'B' && s[i+1] == 'C'){
            t += 'D';
            i++;
        }else{
            t += s[i];
        }
    }
    //cout << t << endl;
    ll ans = 0;
    ll tmp = 0;
    rep(i,n){
        if(t[i] == 'A'){
            tmp++;
        }else if(t[i] == 'D'){
            ans += tmp;
        }else{
            tmp = 0;
        }
    }
    cout << ans << endl;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll S[105];
//! [i番目までで][j個入れた時][重さ-w_1の和がkとなるような]=価値の最大値
ll dp[105][105][405];

int main()
{
    ll N, W;
    cin >> N >> W;
    REP(i, N)
    {
        cin >> S[i].first >> S[i].second;
    }
    ll w1 = S[0].first;
    dp[0][0][0] = 0;
    REP(i, N)
    {
        dp[i + 1][0][0] = 0;
        REP(j, i + 1)
        {
            REP(k, 301)
            {
                if ((j + 1) * w1 + k > W)
                    break;
                if (k - (S[i].first - w1) < 0)
                    dp[i + 1][j + 1][k] = dp[i][j + 1][k];
                else
                    dp[i + 1][j + 1][k] = std::max(dp[i][j + 1][k], dp[i][j][k - (S[i].first - w1)] + S[i].second);
            }
        }
    }

    ll max = 0;
    REP(i, N + 1)
    {
        REP(j, 301)
        {
            max = std::max(dp[N][i][j], max);
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 33152
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin>>x;
  long long ans;
  if(x%11>6){
    ans=(x/11)*2+2;
  }
  else if(x%11==0){
    ans=(x/11)*2;
  }
  else{
    ans=(x/11)*2+1;
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 256
unittest
{
	assert( [ "5 4", "1 4 2 3 5" ].parse.expand.solve == 4 );
	assert( [ "8 4", "4 2 4 2 4 2 4 2" ].parse.expand.solve == 7 );
	assert( [ "10 7", "14 15 92 65 35 89 79 32 38 46" ].parse.expand.solve == 8 );
	
	assert( [ "200000 1000000000", "1".repeat( 200000 ).join( " " ) ].parse.expand.solve == 20000100000 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}

auto solve( long k, long[] as )
{
	// 累積和表を作成
	auto ts = new long[ 1 + as.length ];
	foreach( i, a; as )
	{
		ts[ i + 1 ] = ts[ i ] + a;
	}
	
	// 部分列の条件は i < j かつ j - i < k かつ ( ts[ j ] - ts[ i ] ) % k == j - i なので、
	// ⇒ ( ts[ j ] - ts[ i ] ) % k - j + i == 0
	// ⇒ ( ( ts[ j ] - j ) - ( ts[ i ] + i ) ) % k == 0
	// ⇒ ( ts[ j ] - j ) % k == ( ts[ i ] - i ) % k
	// にできる。
	
	// 余りの値ごとに i を分類
	long[][ long ] pss;		// 通常配列だとkがでかすぎて死ぬ
	foreach( i, ref t; ts )
	{
		pss[ ( t - i ) % k ] ~= i.signed;
	}
	
	// i < j かつ j - i < k かつ 余りの値が同じ になるペアの数をしゃくとり法で計算
	auto ans = 0L;
	foreach( ps; pss )
	{
		for( auto l = 0L, r = 0L; l < ps.length; l++ )
		{
			while( r < ps.length && ps[ r ] - ps[ l ] < k ) r++;
			ans += r - l - 1;
		}
	}
	return ans;
}


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

namespace AtCoder.Abc
{
    class A_163_CirclePond
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            Console.WriteLine(2 * Math.PI * n);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27440
//AtCoder ABC115 C - Christmas Eve
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll N,K; cin>>N>>K;
    vector<ll> hn(N);
    for(auto&& h:hn){
		cin >> h;
	}
    sort(hn.begin(),hn.end());
    ll ans=INT64_MAX;
    for(ll i=0;i<=hn.size()-K;++i){
        ll d=hn[i+K-1]-hn[i];
        ans=min(d,ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void){
    int n, k;
    cin >> n >> k;
    if(k > ((n-1)*(n-2)/2)){
        cout << "-1" << endl;
        return 0;
    }
    int m = (n-1) + (n-1)*(n-2)/2 - k;
    cout << m << endl;
    for(int i=0;i<n-1;++i){
        cout << i+1 << " " << n << endl;
    }
    m -= n-1;
    for(int i=1;i<n-1;++i){
        if(m <= (n-1-i)){
            for(int j=i+1;j<=i+m;++j){
                cout << i << " " << j << endl;
            }
            break;
        }else{
            for(int j=i+1;j<=n-1;++j){
                cout << i << " " << j << endl;
            }
            m -= (n-1 - i);
        }
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int red = 0, blu = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            red++;
        else
            blu++;
    }
    cout << (red > blu ? "Yes" : "No") << endl;
}


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

int main() {
  int A, B, S = 0, count;
  
  cin >> A >> B;
  
  count = B - A + 1;
  
  for (int i = 0; i < count; i++) {
    int a = A / 10000;
    int t = A % 10000;
    int b = t / 1000;
    t %= 1000;
    int c = t / 100;
    t %= 100;
    int d = t / 10;
    t %= 10;
    int e = t;
    A += 1;

    
    if (a == e && b == d) {
      S++;
    }
  }
  cout << S << endl;
  
}


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

const long long MOD_CONST = 1000000007;

using namespace std;


int main() {
	int n;
	cin >> n;
	priority_queue<int> pq;
	vector<int> a;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		a.emplace_back(num);
		pq.push(num);
	}

	for (int i = 0; i < n; i++) {
		int num = pq.top();
		if (num == a[i]) {
			pq.pop();
			cout << pq.top() << endl;
			pq.push(num);
		}
		else {
			cout << num << endl;
		}
	}
}

Measured memory_bytes: 3436
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int i;
  long long n, c;
  scanf("%lld %lld", &n, &c);
  long long x[100010], v[100010], right[100010], left[100010], right_max[100010], left_max[100010];
  x[0] = 0;
  v[0] = 0;
  for (i = 1; i < n+1; i++) {
    long long xi, vi;
    scanf("%lld %lld", &x[i], &v[i]);
  }
  x[n+1] = c;
  v[n+1] = 0;
  right[0] = 0;
  right_max[0] = 0;
  for (i = 1; i < n+1; i++) {
    right[i] = right[i-1] + v[i] - (x[i] - x[i-1]);
    right_max[i] = max(right_max[i-1], right[i]);
  }
  left[0] = 0;
  left_max[0] = 0;
  for (i = 1; i < n+1; i++) {
    left[i] = left[i-1] + v[n+1-i] - (x[n+2-i] - x[n+1-i]);
    left_max[i] = max(left_max[i-1], left[i]);
  }
  /*for (i = 0; i < n+1; i++) {
    printf("x=%lld v=%lld r=%lld l=%lld rmax=%lld lmax=%lld\n", x[i], v[i], right[i], left[i], right_max[i], left_max[i]);
    }*/
  long long ans = 0;
  for (i = 0; i < n+1; i++) {
    ans = max(ans, right[i]);
    ans = max(ans, right[i] + (left_max[n-i] - x[i]));
    ans = max(ans, left[i]);
    ans = max(ans, left[i] + (right_max[n-i] - (c - x[n+1-i])));
  }
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 4864
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
#define MAX 1000005
#define forci(p,q) for(int i=p;i<q;i++)
bool prime[MAX];
/*ull sieve()
{
	memset(prime,true,sizeof(prime));
	for(ull p=2;p*p<MAX;p++)
	{
		if(prime[p]==true){
			for(ull i=2*p;i<MAX;i+=p)
			{
				prime[i]=false;
			}
		}
	}
	prime[0]=0;
	prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	int n;
	cin>>n;
	vector<int>g;
	int x;
	int freq[n+5]={0};
	for(int i=0;i<n-1;i++)
	{
		cin>>x;
		freq[x]++;	
	}
	for(int i=1;i<=n;i++)
	{
		cout<<freq[i]<<endl;
	}
}


Measured memory_bytes: 5212
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

constexpr ll modPow(ll a, ll b, ll c) {
	return (b&1) ? (a * modPow(a, b-1, c) % c)
		: (b ? modPow(a*a % c, b/2, c) : 1);
}

template<int P>
struct FactPrecalc {
	private:
		vector<int> fact;
		vector<int> inv_fact;
	public:
		FactPrecalc(int n) : fact(n+1, 1), inv_fact(n+1, 1) {
			for (int i = 2; i <= n; ++i) fact[i] = (ll)fact[i-1] * i % P;
			inv_fact[n] = modPow(fact[n], P-2, P);
			for (int i = n-1; i >= 0; --i) inv_fact[i] = (ll)inv_fact[i+1] * (i+1) % P;
		}
		ll operator()(int a, int b) const {
			if (a < b) return 0;
			ll div = (ll)inv_fact[a-b] * inv_fact[b] % P;
			return fact[a] * div % P;
		}
		ll operator[](int i) const { return fact[i]; }
		ll inv(int i) const { return inv_fact[i]; }
};

const int N = 1000;
ll dp[N+1];

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

	int n, k;
	cin >> n >> k;
	FactPrecalc<MOD> fp(n);

	dp[0] = 1;
	for (; k; --k) {
		int a;
		cin >> a;
		for (int i = n; i >= 0; --i) {
			for (int j = min(n, i+a); j > i; --j) {
				int d = j-i;
				ll mult = fp(n-i, d) * fp(n-d, a-d) % MOD;
				dp[j] = (dp[j] + mult * dp[i]) % MOD;
			}
			dp[i] = dp[i] * fp(n, a) % MOD;
		}
	}
	cout << dp[n] << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll H, W;
    cin >> H >> W;

    ll res = 1e18;
    for (ll h = 1; h < H; h++) {
        ll h1 = (H - h) / 2; 
        ll h2 = H - h - h1;
        vector<ll> a = {
            h * W,
            h1 * W,
            h2 * W
        }; 
        if (*min_element(all(a)) <= 0) {
            continue;
        }
        res = min(res, *max_element(all(a)) - *min_element(all(a)));
    
    }

    for (ll h = 1; h < H; h++) {
        ll w1 = W / 2; 
        ll w2 = W - w1;
        ll h1 = H - h;
        vector<ll> a = {
            h * W,
            h1 * w1,
            h1 * w2
        }; 
        if (*min_element(all(a)) <= 0) {
            continue;
        }
        res = min(res, *max_element(all(a)) - *min_element(all(a)));

    }

    //
    swap(W, H);
    for (ll h = 1; h < H; h++) {
        ll h1 = (H - h) / 2; 
        ll h2 = H - h - h1;
        vector<ll> a = {
            h * W,
            h1 * W,
            h2 * W
        }; 
        if (*min_element(all(a)) <= 0) {
            continue;
        }
        res = min(res, *max_element(all(a)) - *min_element(all(a)));
    }

    for (ll h = 1; h < H; h++) {
        ll w1 = W / 2; 
        ll w2 = W - w1;
        ll h1 = H - h;
        vector<ll> a = {
            h * W,
            h1 * w1,
            h1 * w2
        }; 
        if (*min_element(all(a)) <= 0) {
            continue;
        }
        res = min(res, *max_element(all(a)) - *min_element(all(a)));
    }

    put(res);

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
using namespace std;

int main() {
	unsigned int input;
	string output;

	bool head = false;
	bool tail = false;

	cin >> input;

	if (input / 100 > 12 || input / 100 == 0) head = true;
	if (input % 100 > 12 || input % 100 == 0) tail = true;

	if (head) {
		if (tail) {
			output = "NA";
		}
		else {
			output = "YYMM";
		}
	}
	else {
		if (tail) {
			output = "MMYY";
		}
		else {
			output = "AMBIGUOUS";
		}
	}

	cout << output;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//https://atcoder.jp/contests/abc172/submissions/14786792
fn main() {
    let n: usize = read();
    let m: usize = read();
    let k: i64 = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();
    let b: Vec<i64> = (0..m).map(|_| read()).collect();
    let mut a_ruisekiwa: Vec<i64> = vec![0; n];
    let mut b_ruisekiwa: Vec<i64> = vec![0; m];
    let mut read = 0;

    a_ruisekiwa[0] = a[0];
    for i in 1..n {
        a_ruisekiwa[i] += a_ruisekiwa[i - 1] + a[i];
    }
    b_ruisekiwa[0] = b[0];
    for i in 1..m {
        b_ruisekiwa[i] += b_ruisekiwa[i - 1] + b[i];
    }
    //println!("{:?}",b_ruisekiwa);

    for i in 0..n {
        let remaining_time = k - a_ruisekiwa[i];
        if remaining_time < 0 {
            break;
        }
        if remaining_time == 0 {
            read = std::cmp::max(read, i + 1);
            continue;
        }
        //二分探索
        let count = match b_ruisekiwa.binary_search(&remaining_time) {
            Ok(index) => index + 1,
            Err(index) => index,
        };
        read = std::cmp::max(read, i + 1 + count);
    }

    for i in 0..m {
        let remaining_time = k - b_ruisekiwa[i];
        if remaining_time < 0 {
            break;
        }
        if remaining_time == 0 {
            read = std::cmp::max(read, i + 1);
            continue;
        }
        //二分探索
        let count = match a_ruisekiwa.binary_search(&remaining_time) {
            Ok(index) => index + 1,
            Err(index) => index,
        };
        read = std::cmp::max(read, i + 1 + count);
    }
    println!("{}", read);
}


Measured memory_bytes: 8236
#include <stdio.h>

int main(void)
{
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0||w==0){
			break;
		}
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				if(i==1||i==h||j==1||j==w){
					printf("#");
				}
				
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2020
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int max = Math.max(Math.max(a, b), c);
        int op = max;
        for (int i = 0; i < k; i++) {
            op *= 2;
        }
        System.out.println(a + b + c - max + op);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	int n, T;
	cin >> n >> T;
	vector<int> c(n), t(n);

	int ans = 2000;
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
		if (t[i] <= T ) ans = min(ans, c[i]);
	}
	
	if (ans == 2000) cout << "TLE" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int a, b; cin >> a >> b;
    int c = min(a, b);
    int d = max(a,b);
    rep(i,d) {
        cout << c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int n,x;

int main() {
	std::cin>>n;
	x=n%10;
	if(x==2||x==4||x==5||x==7||x==9) puts("hon");
	else if(x==0||x==1||x==6||x==8) puts("pon");
	else puts("bon");
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    string tmp; cin>>tmp;
    string s="";
    rrep(i,sz(tmp)) s+=tmp[i];
    
    //sがこいつらで作れるか
    //
    //maerd
    //remeard
    //esare
    //resare
    
    ll now=0;
    while(now!=sz(s)){
        if(now>sz(s)-5){
            cout<<"NO"<<endl;
            return 0;
        }
        
        string t="";
        rep(i,5) t+=s[now+i];
        
        if(t=="maerd"){
            now+=5;
            continue;
        }
        if(t=="esare"){
            now+=5;
            continue;
        }
        
        
        
        
        if(now>sz(s)-6){
            cout<<"NO"<<endl;
            return 0;
        }
        t+=s[now+5];
        if(t=="resare"){
            now+=6;
            continue;
        }
        
        if(now>sz(s)-7){
            cout<<"NO"<<endl;
            return 0;
        }
        t+=s[now+6];
        if(t=="remaerd"){
            now+=7;
            continue;
        }
        
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
}



Measured memory_bytes: 3740
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a), s.insert(b), s.insert(c);
    if (sz(s) == 2) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

K = get_int

num = [0]

def count_up(num)
  cur = num.length - 1
  loop do
    num[cur] += 1
    if (num[cur-1] - num[cur]).abs > 1 || num[cur] > 9
      cur -= 1
    else
      break
    end
    if cur < 0 && num[0] > 9
      num.unshift(1)
      cur = 0
      break
    end

    if cur < 0
      cur = 0
      break
    end
  end

  if cur < num.length - 1
    v = num[cur] - 1
    cur += 1
    while cur < num.length
      num[cur] = v
      v -= 1 if v > 0
      cur += 1
    end
  end
end

K.times do
  count_up(num)
end

puts num.join('')


Measured memory_bytes: 14440
n, m = gets.chomp.split(' ').map(&:to_i)
scs = m.times.map { gets.chomp.split(' ').map(&:to_i) }

digits = {}
scs.each do |s, c|
    d = digits[s]
    if d.nil?
        digits[s] = c
        next
    end

    if d == c
        next
    end

    puts '-1'
    exit
end

if digits[1] == 0
    puts (n == 1) ? '0' : '-1'
    exit
end

if digits.count == 0
    puts (n == 1) ? 0 : 10 ** (n - 1)
    exit
end

result = 0
(0...n).each do |i|
    s = i + 1
    d = digits[s] || (s == 1 ? 1 : 0)
    result = result + d * (10 ** (n - s))
end

puts result


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

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

    if((a <= b && b <= a + W) || (a <= b + W && b + W <= a + W)) {
        cout << 0 << endl;
    } else if(b + W < a) {
        cout << a - (b + W) << endl;
    } else {
        cout << b - (a + W) << endl;
    }
}


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

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

    int n;
    cin >> n;
    map<int, int> mp;
    REP(i, n){
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    int cnt = 0;
    for(auto x : mp){
        if(x.first == x.second);
        else if(x.first < x.second) cnt += x.second - x.first;
        else cnt += x.second;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 4736
S = input("")
N = len(S) - 1
sum = 0;

for i in range(2**N):
    # iの下位からn番目のビットが1かどうかの判定
    # (i >> n) & 1 
    """
    例えば、3は011であり、この下から2ビット目は、0
    3を2ビット右シフトすると 0|11 となり0、1とのORをとりfalse
    """
    operator = [''] * N
    for n in range(N):
        if ((i>>n) & 1):
            operator[N-1-n] = '+'

    # print(operator)
    # Sとoperatorを交互につなげる

    operator.append('')
    formula = ""

    for s, o  in zip(S, operator):
        formula += s + o
    # print(formula)
    sum += eval(formula)
print(sum)

Measured memory_bytes: 9064
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

struct BK{string st;int p;};
int main(){
string str;
int N,iii=0;
BK B[101],T;
while(cin>>str>>N){
B[iii].st=str;B[iii].p=N;
iii++;
}
for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st<B[j-1].st){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
for(int j=iii-1;j>i;j--)
if(B[j].st==B[j-1].st&&B[j].p<B[j-1].p){T=B[j-1];B[j-1]=B[j];B[j]=T;}

for(int i=0;i<iii;i++)
{if(i==0)cout<<B[0].st<<endl<<B[0].p;
else if(i>0&&B[i].st==B[i-1].st){cout<<" "<<B[i].p;}
else cout<<endl<<B[i].st<<endl<<B[i].p;
}
cout<<endl;
return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long i = 0; i < n; ++i)

using namespace std;
using ll = long long;

void solve(long N, long K, int R, int S, int P, string T) {

  long ans(0);
  REP(i, N) {
    char t = T[i];

    if (i >= K && T[i-K] == t) {
      T[i] = 'X';
      continue;
    }
      
    switch (t) {
    case 'r':
      ans += P;
      break;
    case 's':
      ans += R;
      break;
    case 'p':
      ans += S;
      break;
    }
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  long N, K;
  int R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  solve(N, K, R, S, P, T);
  return 0;
}


Measured memory_bytes: 3736
n = int(input())
a = list(map(int, input().split()))

k = 0
if max(a) == min(a):
    print(0)
    exit()
elif max(a) * min(a) < 0:
    print((n - 1) * 2)
    if max(a) + min(a) >= 0:
        k = a.index(max(a)) + 1
    else:
        k = a.index(min(a)) + 1
    for i in range(1, n + 1):
        if i != k:
            print(k, i)
else:
    print(n - 1)
    if max(a) > 0:
        k = a.index(max(a)) + 1
    else:
        k = a.index(min(a)) + 1

if a[k - 1] > 0:
    for i in range(1, n):
        print(i, i + 1)
else:
    for i in range(n, 1, -1):
        print(i, i - 1)





Measured memory_bytes: 3064
#include <stdio.h>

#define ARR_LIMIT 10000

void InputNumber(int* number, int limitLow, int limitHigh);
void reverse(int* numArr, int size);

int main(void) {
	int n;
	int idx;
	int number[ARR_LIMIT];

	InputNumber(&n, 0, 100);

	for (idx = 0; idx < n; idx++) {
		InputNumber(&number[idx], 0, 999);
	}

	reverse(number, n);

	for (idx = 0; idx < n - 1; idx++) {
		printf("%d ", number[idx]);
	}
	printf("%d\n", number[idx]);

	return 0;
}

void InputNumber(int* number, int limitLow, int limitHigh) {
	int x;
	do {
		scanf("%d", &x);
	} while (x < limitLow || x > limitHigh);
	*number = x;
}

void reverse(int* numArr, int size) {
	int front = 0;
	int back = size - 1;
	int idx;

	for (idx = 0; idx < size / 2; idx++) {
		int tmp = *(numArr + front);
		*(numArr + front) = *(numArr + back);
		*(numArr + back) = tmp;
		front++;
		back--;
	}
}


Measured memory_bytes: 2052
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc141_a
import sys
#import collections

#n= int(input())
s= input()
#tmp = input().split()
#a = list(map(lambda a: int(a), tmp))

for i in range(len(s)):
	if(i%2==0):
		if(s[i]=="L"):
			print("No")
			sys.exit()
	else:
		if(s[i]=="R"):
			print("No")
			sys.exit()
		
print("Yes")


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

int main(void) {
	int array[10];
	for(int i = 0; i < 10; i++)
		scanf("%d", &array[i]);
	sort(array, array + 10, greater<int>());
	for(int i = 0; i < 3; i++)
		printf("%d\n", array[i]);
	return 0;
}

Measured memory_bytes: 760
#include <stdio.h>

#define H 250

int main(){
  int Heap[H];
  int n, i;

  scanf("%d", &n);
  for(i = 1; i <= n; i++)
    scanf("%d", &Heap[i]);

  for(i = 1; i <= n; i++){
    if(i == 1)
      printf("node 1: key = %d, left key = %d, right key = %d, \n"
	 , Heap[i], Heap[i*2], Heap[i*2+1]);

    else if(i*2 > n)
      printf("node %d: key = %d, parent key = %d, \n"
	   , i, Heap[i], Heap[i/2]);


    else if(i*2+1 >n)
      printf("node %d: key = %d, parent key = %d, left key = %d, \n"
	   , i, Heap[i], Heap[i/2], Heap[i*2]);

    else
      printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n"
	   , i, Heap[i], Heap[i/2], Heap[i*2], Heap[i*2+1]);
  }

  return 0;
}

Measured memory_bytes: 596
from functools import reduce

def modpow(a, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * a % mod
        a = a * a % mod
        m = m >> 1
    return ret

def modinv(a):
    return modpow(a, mod - 2)

def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(lambda a, b: a * b % mod, range(n, n - r, -1))
    under = reduce(lambda a, b: a * b % mod, range(1, r + 1))
    return over * modinv(under) % mod

x, y = [int(i) for i in input().split()]
if (x + y) % 3 or x > 2 * y or y > 2 * x:
    print(0)
else:
    mod = 10**9 + 7
    print(cmb((x + y) // 3, (2 * x - y) // 3))


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll a;
  	ci(a);
  if(a<1200) co("ABC")
    else co("ARC")
    }

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
const int MAX = 3;
int main(){
    int a = 0;
    int c = 0;
    string s;
    cin >> s;
    bool f = true;
    for(int i=0;i < s.length();i++){
        if(s[0] == 'A'){
            //区間にCがあるか
            if(i >= 2 && i <= s.length()-2 && s[i] == 'C'){
                if(c != 0){
                    f = false;
                    break;
                }
                c=1;
            }
            //区間外にCがあるか
            if(!(i >= 2 && i <= s.length()-2) && (s[i] == 'C')){
                
                f = false;
                break;
                
            }
            //[1,末尾):大文字ならNG
            if(i >= 1 && !(s[i] >= 'a' && s[i] <= 'z') && s[i] != 'C'){
                f = false;
                break;
            }
        }else{
            f = false;
            break;
        }
    }
    if(c != 1) f = false;

    if(f) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
N, x, *a = map(int, open(0).read().split())

cnt = 0
ans = 0

for i in range(N):
    cnt += a[i]
    if cnt > x:
        ans += cnt - x
        a[i] -= cnt - x
        cnt = x
        
    cnt -= a[i - 1] if i > 0 else 0
        
print(ans)



Measured memory_bytes: 71228
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main(){
	int i , j , n , h ;
	string str , st , s;
	while(1){
		cin >> str ;
		if( str == "-" )break;
		cin >> n ;
		for( j=0 ; j<n ; j++ ){
			cin >> h ;
			st ="";
			s="";
			for( i=0 ; i<h ; i++ )
				st += str[i];
			int x = str.size();
			for( i=h ; i<x; i++ )
				s += str[i];
			str = s+st;
		}
		cout << str << endl;
	}	
}

Measured memory_bytes: 3196
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
    int left, right, largest;
    left = i * 2;
    right = i * 2 + 1;
    
    if((left <= H) && (A[left] > A[i])) largest = left;
    else largest = i;
    if((right <= H) && (A[right] > A[largest])) largest = right;
    
    if(largest != i){
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if(H < 1) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key){
    if(key < A[i]) return;
    A[i] = key;
    while((i > 1) && (A[i/2] < A[i])){
        swap(A[i], A[i/2]);
        i = i / 2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main(){
    int key;
    char com[10];
    
    while(1){
        scanf("%s", com);
        if((com[0] == 'e') && (com[1] == 'n')) break;
        if(com[0] == 'i') {
            scanf("%d", &key);
            insert(key);
        }
        else{
            printf("%d\n", extract());
        }
    }
    
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    if(s.size() >= 4){
        string tmp = s;
        tmp = tmp.substr(0, 4);
        if(tmp == "YAKI"){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }


    return 0;
}

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


void solve(long N){
  long long sum = 0;
  for (long i = 1; i <= N; i++)
    {
      if (i % 3 == 0 || i % 5 == 0)
	continue;
      sum += i;
    }
  cout << sum << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long N;
    cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 2e5 + 5 ; 
const int P = 1e9 + 7 ; 
struct E {
	int to, next ; 
} e[N << 1] ; 
int n, cnt, head[N], dp[N], fac[N], inv[N], sz[N], ans[N] ; 
int fpow( int x, int k ) {
	int ans = 1, base = x % P ; 
	while( k ) {
		if( k & 1 ) ans = 1ll * ans * base % P ; 
		base = 1ll * base * base % P, k >>= 1 ; 
	} return ans % P ; 
}
void add( int x, int y ) {
	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,
	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 
}
void dfs( int x, int fa ) {
	sz[x] = 1, dp[x] = 1 ; 
	Next( i, x ) {
		int v = e[i].to ; if( v == fa ) continue ; 
		dfs( v, x ), sz[x] += sz[v] ; 
		dp[x] = 1ll * dp[x] * dp[v] % P * inv[sz[v]] % P ; 
	} dp[x] = dp[x] * fac[sz[x] - 1] % P ; 
}
void dfs2( int x, int fa ) {
	if( x != fa ) {
		int ans2 = dp[x] * inv[sz[x] - 1] % P ;
		int ans3 = 1ll * ans[fa] * inv[n - 1] % P * fpow( dp[x], P - 2 ) % P * fac[n - sz[x] - 1] % P * fac[sz[x]] % P; 
		int ans4 = 1ll * ans2 * ans3 % P * fac[n - 1] % P * inv[n - sz[x]] % P ; 
		ans[x] = ans4 ; 
	}
	Next( i, x ) {
		int v = e[i].to ; if( v == fa ) continue ; 
		dfs2( v, x ) ; 
	}
}
signed main()
{
	n = gi() ; int x, y ; fac[0] = inv[0] = 1 ; 
	rep( i, 2, n ) x = gi(), y = gi(), add( x, y ) ; 
	rep( i, 1, n ) fac[i] = fac[i - 1] * i % P, inv[i] = fpow( fac[i], P - 2 ) ;
	dfs( 1, 1 ) ;
	ans[1] = dp[1] ; 
	dfs2( 1, 1 ) ;
	rep( i, 1, n ) printf("%lld\n", ans[i] ) ;
	return 0 ;
}


Measured memory_bytes: 17920
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

//n -> big, a -> small
mint choose(int n,int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}
int main(){
	cout << fixed << setprecision(10);
	int x,y;
	cin >> x >> y;
	if((x+y)%3!=0){
		cout << 0 << endl;
		return 0;
	}
	if(2*x-y<0 || 2*y-x<0){
		cout << 0 << endl;
		return 0;
	}
	if((2*x-y)%3!=0 || (2*y-x)%3!=0){
		cout << 0 << endl;
		return 0;
	}
	cout << choose((2*x-y)/3+(2*y-x)/3,(2*x-y)/3).x << endl;
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 3005;

vector<int> G[maxn];
int n;
int a[maxn];
bool win[maxn];

void dfs(int u, int fa){
    win[u] = false;
    for(auto v : G[u]){
        if(v == fa)
            continue;
        dfs(v, u);
        if(a[u] > a[v] and !win[v]){
            win[u] = true;
        }
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(int i = 1;i < n;i++){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i = 1;i <= n;i++){
        dfs(i, i);
        if(win[i]){
            cout << i << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
string S,T;
cin>>S>>T;
int n=S.size();
string t=T;
for(int j=1;j<=n;j++){
for(int i=0;i<n;i++){
    T[(i+j)%n]=S[i];
    if(i==n-1){
        if(t==T){
            cout<<"Yes";
            return 0;
        }
    }
}
}
cout<<"No";
return 0;
}


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

int main(){
    int A,B,K;
    cin >> A >> B >> K;
    //int C[100]={0};
    
    int sum=0;
    for(int i=100;i>=1;i--){
        if(A%i ==0 && B%i ==0) {
            //C[i-1]=1;
            sum++;
            //cout << i << endl;
            if(sum==K){
                cout << i << endl;
                return 0;
            }
        }
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const string HEX = "0123456789ABCDEF";

int main(void) {
    char x,y;
    cin >> x >> y;
    if (HEX.find(x)<HEX.find(y)) {
        cout << '<' << endl;
    } else if (HEX.find(x)>HEX.find(y)) {
        cout << '>' << endl;
    } else {
        cout << '=' << endl;
    }
    return 0;
}


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

void rot(D& d) {
	d.push_back(d[0]);
	d.pop_front();
}

D f(D d) {
	D ret = d;
	for(int i = 0; i < 3; i++) {
		rot(d);
		ret = min(ret, d);
	}
	return ret;
}

int overlap(D d) {
	int ret = 1;
	D t = d;
	for(int i = 0; i < 3; i++) {
		rot(d);
		if(t == d) ret++;
	}
	return ret;
}

ll P(int n, int k) {
	ll ret = 1;
	for(int i = n - k + 1; i <= n; i++) ret *= i;
	return ret;
}

D C[400];

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

	map<D, int> m;
	map<D, int> cnt;
	for(int i = 0; i < N; i++) {
		C[i] = D(4);
		for(int j = 0; j < 4; j++) {
			cin >> C[i][j];
		}
		C[i] = f(C[i]);
		m[C[i]]++;
	}

	for(auto p : m) {
		cnt[p.first] = overlap(p.first);
	}

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		D d1 = C[i];
		m[d1]--;
		for(int j = i + 1; j < N; j++) {
			D d2 = C[j];
			m[d2]--;
			for(int r1 = 0; r1 < 4; r1++) {
				map<D, int> t;
				t[f(D({ d1[1], d1[0], d2[1], d2[0] }))]++;
				t[f(D({ d1[0], d1[3], d2[2], d2[1] }))]++;
				t[f(D({ d1[3], d1[2], d2[3], d2[2] }))]++;
				t[f(D({ d1[2], d1[1], d2[0], d2[3] }))]++;
				ll k = 1;
				for(auto p : t) {
					if(!m.count(p.first) || m[p.first] < p.second) {
						k = 0;
						break;
					}
					k *= P(m[p.first], p.second);
					for(int loop = 0; loop < p.second; loop++) {
						k *= cnt[p.first];
					}
				}
				ans += k;
				rot(d1);
			}
			m[d2]++;
		}
		m[d1]++;
	}

	cout << ans / 3 << endl;
}

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

bool is_pal(string a) {
    string b = a;
    reverse(b.begin(), b.end());
    return a == b ? true : false;
}

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    string s;
    cin >> s;
    int n = (int) s.size();
    string a = "", b = "";
    for (int i = 0; i < n / 2; i++) {
        a += s[i];
    }
    for (int i = (n / 2) + 1; i < n; i++) {
        b += s[i];
    }
    cout << (is_pal(s) and is_pal(a) and is_pal(b) ? "Yes" : "No") << '\n';
}

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

int main(void) {
  int n, a;
  cin >> n >> a;
  bool ans=false;
  
  for (int i=0; i<a+1; ++i) {
	if ((n-i) % 500 == 0) {
      ans = true;
      break;
    }
  }
  if (ans == true) cout << "Yes";
  else cout << "No";  
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var n int
  var s string
  fmt.Scan(&n)
  fmt.Scan(&s)

  for i := 0; i < len(s); i++ {
    modifyChar(n, s[i])
  }
}

func modifyChar(n int, s byte) {
  // A = 65 Z = 90
  c := n + int(s)
  if c > 90 {
    c = c - 90 + 64
  }
  fmt.Print(string(c))
}

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

int main() {
  int N;
  cin>>N;
  vector<int>c(N),s(N),f(N);
  int now=0;
  int train=0;
  for(int i=0;i<N-1;i++){
    cin>>c[i]>>s[i]>>f[i];
  }
  for(int i=0;i<N;i++){
    now=0;
    for(int j=i;j<N-1;j++){
      train=s[j];
      while(1){
      if(train>=now){
        now=train+c[j];
        break;
      }
      train+=f[j];
    }
  }
  cout<<now<<endl;
}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i, j;

    int height[10];
    for (i = 0; i < 10; i++) {
        scanf(" %d", &height[i]);
    }

    int tmp;
    for (i = 0; i < 3; i++) {
        for (j = i + 1; j < 10; j++) {
            if (height[i] < height[j]) {
                tmp = height[i];
                height[i] = height[j];
                height[j] = tmp;
            }
        }
    }

    for (i = 0; i < 3; i++) {
        printf("%d\n", height[i]);
    }

    return 0;
}

Measured memory_bytes: 600
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        h = I()
        if h == 0:
            break

        a = [LI() for _ in range(h)]
        f = True
        r = 0
        while f:
            f = False
            d = [[0]*5 for _ in range(h)]
            for i in range(h):
                for j in range(3):
                    if a[i][j] > 0 and a[i][j] == a[i][j+1] and a[i][j] == a[i][j+2]:
                        d[i][j] = 1
                        d[i][j+1] = 1
                        d[i][j+2] = 1
                        f = True
            for i in range(h):
                for j in range(5):
                    if d[i][j] == 1:
                        r += a[i][j]
                        a[i][j] = 0

            for i in range(h-2,-1,-1):
                for j in range(5):
                    if a[i][j] <= 0:
                        continue
                    k = i
                    while k < h-1 and a[k+1][j] == 0:
                        a[k+1][j] = a[k][j]
                        a[k][j] = 0
                        k += 1

        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9124