akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() {return abs((int) mt());}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

void chemthan() {
    int n; cin >> n;
    vi a(n);
    FOR(i, 0, n) cin >> a[i];
    uni(a), n = sz(a);
    vi nxt(n);
    vi lst(*max_element(all(a)) + 1, n);
    vi dp(n + 1);
    dp[n] = 1;
    FORd(i, n, 0) {
        nxt[i] = lst[a[i]];
        if (nxt[i] ^ n) {
            addmod(dp[i], dp[nxt[i]]);
        }
        addmod(dp[i], dp[i + 1]);
        lst[a[i]] = i;
    }
    cout << dp[0] << "\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <cstring>

using namespace std;

int a[26];
char s[200001];

int main() {
    int n, i;
    long long ans = 0;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    for (i = 0; i < n; i++) a[s[i] - 'a']++;
    
    ans = (long long)n * (n - 1) / 2 + 1;
    
    for (i = 0; i < 26; i++) ans -= (long long)a[i] * (a[i] - 1) / 2;
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 384
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
p.sort()
ans = -1
tmp = 1000
for i in range(0, 102):
    cnt = 0
    for j in range(n):
        if i == p[j]:
            cnt += 1001
            break
    cnt += abs(x - i)
    if cnt < tmp:
        tmp = cnt
        ans = i
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main(){
    int n, m; cin >> n >> m;
    vector<P> pos, check;
    vector<int> ans;
    rep(i,n){
        int a, b; cin >> a >> b;
        pos.push_back(P(a,b));
    }
    rep(i,m){
        int c, d; cin >> c >> d;
        check.push_back(P(c,d));
    }
    rep(i,n){
        int min_d = INF;
        int index = -1;
        rep(j,m){
            int tmp = abs(pos[i].first - check[j].first) + abs(pos[i].second - check[j].second);
            if(min_d > tmp){
                index = j;
                min_d = tmp;
            }
        }
        ans.push_back(index+1);
    }
    for(auto e : ans){
        cout << e << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

ll dp[2010][2010];

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

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<P> p(n);
	rep(i, n) {
		p[i].first = a[i];
		p[i].second = i;
	}
	sort(all(p)); reverse(all(p));
	rep(i, n + 1) {
		rep(j, n + 1) {
			if (i + j > n) continue;
			if (i != 0) chmax(dp[i][j], dp[i - 1][j] + p[i + j - 1].first*abs(p[i + j - 1].second - i + 1));
			if (j != 0) chmax(dp[i][j], dp[i][j - 1] + p[i + j - 1].first*abs(p[i + j - 1].second - n + j));
		}
	}
	ll ans = 0;
	rep(i, n + 1) chmax(ans, dp[i][n - i]);
	cout << ans << '\n';
}

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

int main()
{
	long long n;
	int q;
	
	cin>>n>>q;
	
	long long initial=(n-2)*(n-2);
	
	set<pair<int,int> > rows;
	set<pair<int,int> > cols;
	
	rows.insert({n-1,n-2});
	cols.insert({n-1,n-2});
	
	int type,ind;
	
	while(q--)
	{
		cin>>type>>ind;
		
		if(type==1)
		{
			auto itr=cols.lower_bound({ind,0});
			initial-=itr->second;
			
			//cout<<itr->second<<endl;
			
			int i=itr->first;
			
			int val1=rows.begin()->second;
			
			if(ind-2<val1)
			{
				rows.insert({itr->second+1,ind-2});
			}
		}
		else
		{
			auto itr=rows.lower_bound({ind,0});
			initial-=itr->second;
			
			//cout<<itr->second<<endl;
			
			int i=itr->first;
			
			int val1=cols.begin()->second;
			
			if(ind-2<val1)
			{
				cols.insert({itr->second+1,ind-2});
			}
		}
	}
	
	cout<<initial<<endl;
	
	return 0;
}

Measured memory_bytes: 12876
#include <iostream>
#include <bitset>
using namespace std;
 
//W hidari E migi
 
int main(){
    int N;
    cin >> N;
    int result = 100000;

    for(int A = 1; A < N; A ++ ){
        int current = 0;
        int B = N - A;
        int copyA = A;
        while(copyA > 0){
            current += copyA % 10;
            copyA /= 10;
        }
        while(B > 0){
            current += B % 10;
            B /= 10;  
        }
        if(result > current){
            result = current;
        }
    }

    cout << result << endl;  
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;

int[] p;
dchar[][] ban;
bool ok;
int h, w;

void main() {
    //int h, w;
    scan(h, w);

    ban = new dchar[][](h, w);
    iota(h).each!(i => ban[i] = readln.chomp.to!(dchar[]));

    p = new int[](h);
    p[] = -1;

    if (h & 1) {
        foreach (i ; 0 .. h) {
            p[i] = h / 2;
            dfs(h, 0);
            p[i] = -1;
        }
    }
    else {
        dfs(h, 0);
    }

    debug {
        writeln(cnt);
    }

    writeln(ok ? "YES" : "NO");
}

int cnt;
int num;

void dfs(int h, int i) {
    if (i == h) {
        debug {
            //writeln(p);
            cnt++;
        }
        solve();
        return;
    }

    if (p[i] != -1) {
        dfs(h, i + 1);
    }
    else {
        foreach (j ; 0 .. h) {
            if (j == i) continue;
            if (p[j] == -1) {
                p[i] = num;
                p[j] = h - 1 - num;
                num++;
                dfs(h, i + 1);
                num--;
                p[i] = p[j] = -1;
            }
        }
    }
}

void solve() {
    auto bb = new dchar[][](h, w);
    foreach (i ; 0 .. h) {
        bb[p[i]] = ban[i].dup;
    }

    debug {
        //writeln(bb);
    }

    auto bt = new dchar[][](w, 0);

    foreach (j;  0 .. w) {
        foreach (i ; 0 .. h) {
            bt[j] ~= bb[i][j];
        }
    }

    debug {
        //writeln(bt);
    }

    auto u = new bool[](w);

    foreach (i ; 0 .. w) {
        if (u[i]) continue;

        foreach (j ; i + 1 .. w) {
            if (equal(bt[i], bt[j].retro)) {
                u[i] = u[j] = 1;
                break;
            }
        }
    }

    int ucnt = u.count!"!a".to!int;

    if (ucnt > 1) {
        return;
    }

    if (ucnt == 0) {
        ok = 1;
        return;
    }

    debug {
        writeln(u.countUntil!"!a");
    }

    auto s = bt[u.countUntil!"!a"];

    if (equal(s, s.retro)) {
        ok = 1;
    }

    return;
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 1276
S=input()
list_A=[]
for letter in S:
    list_A.append(letter)
list_B=list_A[0::2]
list_C=list_A[1::2]
b=0
c=0
for letter2 in list_B:
    if letter2=='R'or letter2=='U'or letter2=='D':
        b+=1
for letter3 in list_C:
    if letter3=='L'or letter3=='U'or letter3=='D':
        c+=1
if b==len(list_B)and c==len(list_C):
        print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <climits>

#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,ll> pdl;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

ll calc(ll n){
	ll res=0;
	while(n>0){
		res+=n%10;
		n/=10;
	}
	return res;
}

int main(){
	ll k;
	cin>>k;
	vector<pdl> v;
	for(int i=1;i<=99;i++){
		v.pb(pdl((double)i/calc(i),i));
	}
	for(int d=3;d<=15;d++){
		ll n=0;
		for(int i=0;i<d-3;i++){
			n+=9*pow(10,i);
		}
		ll temp=n;
		for(int i=100;i<=999;i++){
			n=temp;
			n+=i*pow(10,d-3);
			v.pb(pdl((double)n/calc(n),n));
		}
	}
	sort(ALL(v));
	ll mn=10000000000000000;
	for(int i=0;i<v.size();i++){
		for(int j=i;j<v.size();j++){
			if(v[i].second>v[j].second){
				v[j].second=-1;
			}
		}
	}
	int cnt=0;
	for(int i=0;i<v.size();i++){
		if(v[i].second!=-1){
			//cout<<v[i].first<<" "<<v[i].second<<endl;
			cout<<v[i].second<<endl;
			cnt++;
		}
		if(cnt==k)break;
	}
	return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> ng(N + 10, false);
  REP(i, M) {
    int a;
    cin >> a;
    ng[a] = true;
  }
  ll dp[N + 10];
  REP(i, N + 10) dp[i] = 0;
  dp[0] = 1;
  REP(i, N) {
    if (ng[i]) dp[i] = 0;
    dp[i + 1] += dp[i];
    dp[i + 1] %= MOD;
    dp[i + 2] += dp[i];
    dp[i + 2] %= MOD;
  }
  cout << dp[N] << endl;
  return 0;
}

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

int main(){
    while(true){
        char a;
        scanf("%c", &a);
        if('A' <= a && a <= 'Z'){
            a = (a + 23 - 'A') % 26 + 'A';
            printf("%c", a);
        }else{
            printf("%c", a);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 936
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = 1e18;

const int mod = 1000000007;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll choose(ll n, ll a) {
  ll x = 1, y = 1;
  for (ll i = 0; i < a; i++) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

// パスカルの三角形
mint c[4005][4005];

// パスカルの三角形を前計算する
void init() {
  c[0][0] = 1;
  REP(i,4001) REP(j,i+1) {
    c[i+1][j] += c[i][j];
    c[i+1][j+1] += c[i][j];
  }
}

mint comb(int n, int k) {
  return c[n][k];
}

mint f2(int n, int k) {
  return comb(n+k-1,k-1);
}

// n個の中から、k個選ぶ
mint f(int n, int k) {
  if (n < k) return 0;
  if (n == 0 && k == 0) return 1;
  if (k < 1) return 0;
  return f2(n-k,k);
}

int main() {
  IOS;
  init();
  int n, k; cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    mint blue = f(k,i);
    // mint red = f2(n-k-(i-1), i+1);
    mint red = 0;
    {
      red += f(n-k,i-1); // 両端を含まない
      red += f(n-k,i); // 片方の端を含む
      red += f(n-k,i); // 片方の端を含む
      red += f(n-k,i+1); // 両端を含む
    }
    mint ans = blue * red;
    COUT(ans);
  }
  return 0;
}

Measured memory_bytes: 128872
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct Node{
  int parent;
  int left;
  int right;
}Node;

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

void depth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  depth(T[u].left,d+1);
  depth(T[u].right,d+1);
}

int high(int u){
  int h1=0,h2=0;

  if(T[u].left!=NIL)h1=high(T[u].left)+1;
  if(T[u].right!=NIL)h2=high(T[u].right)+1;
  return H[u]=(h1>h2 ? h1:h2);
}

int sibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)return T[T[u].parent].left;
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  int deg=0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",sibling(u));
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL)printf("root\n");
  else if(T[u].left==NIL&&T[u].right==NIL)printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int v,l,r,root=0,i;

  scanf("%d",&n);

  for(i=0;i<n;i++)T[i].parent=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }

  for(i=0;i<n;i++){
    if(T[i].parent==NIL)root=i;
  }

  depth(root,0);
  high(root);

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

  return 0;
}



Measured memory_bytes: 2108
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    input! {s:String}
    if s == "ABC" {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2112
//use std::convert::TryInto;
#![allow(dead_code)]

fn main(){
    input::<usize>();
    let mut ai: Vec<usize> = input_vec();
    // end input

    ai.sort();
    let a_max = *ai.last().unwrap();
    let mut sieve = vec![0; a_max+1];
    for &a in &ai {
        if sieve[a]>1 {continue;}

        for j in 1..=a_max {
            let p = j*a;
            if p>a_max { break; }
            else {sieve[p] += 1; }
        }
    }
    let ans = ai.iter().filter(|&&x| sieve[x]==1).count();

    println!("{}", ans);
    
}



/*
 * input function
 */
fn input<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn input_vec<T: std::str::FromStr>() -> Vec<T> {
    input::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 8248
import java.util.*;
public class Main
{
  public static void main(String []args)
  {
    Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
    long sum[] = new long[n];
    long mod = 1000000007;
    long arr[] = new long[n];
    for(int i = 0 ; i < n ; i++)
    {
      arr[i] = sc.nextLong();
    }
    sum[n-1] = arr[n-1];
    for(int i = n-2 ; i >= 0 ; i--)
    {
      sum[i] = sum[i+1]+arr[i];
      sum[i] %= mod;
    }
    long ans = 0;
    for(int i = 0 ; i < n-1 ; i++)
    {
      ans += arr[i]*sum[i+1]%mod;
      ans %= mod;
    }
    System.out.println(ans);
  }
  }


Measured memory_bytes: 64148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int from[210];
Int dif = 0;
Int n, a, b;
vector<Int> gray(Int n, Int dif){
  if(dif == 1){
    vector<Int> res;
    for(int i = (1 << n);i > 0;i--){
      Int k = i % (1 << n);
      res.push_back(k ^ (k >> 1));
    }
    return res;
  }
  if(dif % 2 == 0)dif++;
  Int l = (dif - 1) / 2, r = l;
  if(l % 2 == 0)l--,r++;
  vector<Int> tmpl = gray(n-1, l);
  vector<Int> tmpr = gray(n-1, r);
  vector<Int> res;
  for(Int i = 0;i < (1 <<(n-1));i++){
    res.push_back(tmpl[i] * 2);
  }
  for(Int i = 0;i < (1 <<(n-1));i++){
    Int hoge = tmpl.back() ^ (tmpr[i] << l);
    hoge = (hoge & ((1 << (n-1)) - 1)) ^ (hoge >> (n-1));
    res.push_back(hoge * 2 + 1);
  }  
  return res;    
}

int main(){
  cin >> n >> a >> b;
  for(int i = 0;i < n;i++){
    if(((a^b) >> i)% 2){
      from[i] = dif++;
    }
  }
  
  if(dif % 2 == 0){
    cout << "NO" << endl;
    return 0;
  }  
  cout << "YES" << endl;
  Int nondif = dif;
  for(int i = 0;i < n;i++){
    if(((a^b) >> i)% 2 == 0){
      from[i] = nondif++;
    }
  }
  for(auto num: gray(n, dif)){
    Int res = 0;
    for(int j = 0;j < n;j++){
      res += (1 << j) * ((num >> from[j]) % 2);
    }
    cout <<( res ^ a) << endl;
  }
  return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;


long n, k;
long *w;
long daisu, tsumi;

long checkDaisu(long p){
	for(long i = daisu = tsumi = 0; i < n; i++){
		tsumi += w[i];
		if(tsumi > p){
			i--;
			daisu++;
			tsumi = 0;
			
			if(daisu > k){
				break;
			}
		}
	}
	return ++daisu;
}

int main() {
    scanf("%ld %ld", &n, &k);
	
	long min = 1, max = 0;
	w = new long[n];
    for(int i = 0; i < n; i++){
        scanf("%ld", &w[i]);
        max += w[i];
    }
	
    while(1){
		long p = (min+max)/2;
		if(checkDaisu(p) > k){
			min = p;
		}else{
			max = p;
		}
		
		if(max - min <= 1){
			break;
		}
	}
	
	printf("%ld\n", checkDaisu(min) <= k ? min : max);
	
    return 0;
}

Measured memory_bytes: 1972
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	boolean J = true;
	  	int i,j;
	  	
	  	while(J) {
	  		
		  	int  h = scanner.nextInt();			//入力
		  	int  w = scanner.nextInt();
		  	
		  	if( h == 0 && w == 0 )
		  		break;
	  		
		  	for(i = 1; i <= h ; i ++){
		  		for(j = 1; j <= w ; j++){
		  			if(j == w) {
		  				if(i == h)
		  					System.out.println("#");
		  				else
		  					System.out.println("#");
		  				}
		  			else	
		  				System.out.print("#");
		  		}
		  	}
		  	System.out.print("\n");
		  	
  		}
        scanner.close();
  }
}


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

	
struct union_find2_2{//経路圧縮で高速化
	
    vector<int> par;//parは添字の親（または自分が根の時自身）を示す。
	
    union_find2_2(int sz){
	
        par.resize(sz);
	
        for(int i=0;i<sz;++i) par[i]=i;
	
    }
	
    int find(int a){//根を探す
	
        if(par[a]==a) return a;
	
        else return par[a] = find(par[a]); //経路圧縮！！！
	
    }
	
    void unite(int a,int b){
	
        int root_a = find(a),root_b = find(b);  //aの根,bの根を調べて代入。
	
        par[root_a] = root_b;                   //根aの親をbにする
	
    }
	
    bool same(int a,int b){
	
        return find(a)==find(b);
	
    }
	
};
int main() {
    int num,que;
    cin >> num >> que;
    union_find2_2 uf(num);
    for(int i=0;i<que;i++){
        int type,x,y;
        cin >> type >> x >> y;
        if(type) cout << uf.same(x,y) << endl ;
        else uf.unite(x,y);
    }    
}





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

int main(){
    int n,x[100],y[100];
    cin>>n;
    for (int i=0;i<n;i++) cin>>x[i];
    for (int i=0;i<n;i++) cin>>y[i];
    
    double d[4];
    for (int i=0;i<4;i++) d[i]=0.0;
    
    for (int p=1;p<=3;p++){
        for (int i=0;i<n;i++){
            d[p]+=pow(fabs(x[i]-y[i]),p);
        }
        d[p]=pow(d[p],1.0/p);
    }
    
    for (int i=0;i<n;i++){
        d[0]=(d[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):d[0]);
    }
    
    printf("%lf\n",d[1]);
    printf("%lf\n",d[2]);
    printf("%lf\n",d[3]);
    printf("%lf\n",d[0]);
    
    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main(void) {
int height, width, x, y, r;
int flag = 0;

scanf("%d %d %d %d %d", &width, &height, &x, &y, &r);

if (x + r <= width && x - r >= 0) {
if (y + r <= height && y - r >= 0) {
flag = 1;
}
}

if (flag == 1) printf("Yes\n");
else printf("No\n");

return 0;
}


Measured memory_bytes: 2108
n = int(input())
p = list(map(int,input().split()))

cnt = 0

for i in range(1,n-1):
    if p[i-1]<p[i]:
        if p[i]<p[i+1]:
            cnt += 1
    if p[i-1]>p[i]:
        if p[i]>p[i+1]:
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
str = input()
N = int(input())

for i in range(N):
    a = input().split()
    x = int(a[1])
    y = int(a[2])
    if a[0] == "print":
        print(str[x:y+1])
    elif a[0] == "replace":
        #str = str.replace(str[x:y+1],a[3],1)
        #s = str[x:y+1]
        str = str[:x] + a[3] + str[y+1:]
    elif a[0] == "reverse":
        # str_sub = str[x:y+1]
        # str_sub = str_sub[::-1]
        # str = str.replace(str[x:y+1],str_sub,1)
        str = str[:x] + str[x:y+1][::-1] + str[y+1:]



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

using namespace std;

int main(void) {
	int num, i = 0, ans = 0;
	cin >> num;
	vector<int> d(num);
	for (; i < num; i++) {
		scanf("%d", &d[i]);
		ans += d[i];
	}
	sort(d.begin(), d.end());
	if (ans % 10 != 0)
		cout << ans << "\n";
	else {
		i = 0;
		while (i < num && d[i] % 10 == 0)
			i++;
		if (i == num)
			printf("0\n");
		else
			cout << ans - d[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;


int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", (n+1)*n/2);
	return 0;
}

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

using namespace std;

int main(){
	int n,k;
	long long count = 0;
	cin>>n>>k;
	vector<long long> mon;
	for(int i = 0; i < n; i++){
		long long p;
		cin>>p;
		mon.push_back(p);
	}
	sort(mon.rbegin(), mon.rend());

	for(int i = 0; i < n; i++){
		if(k>0){
			mon[i] = 0;
			k--;
		}
		else{
			count+=mon[i];
		}
	}

	cout<<count<<endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int dp[1005][10005];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int h, n;
   cin >> h >> n;
   vector<int> a(n), b(n);
   rep(i, 0, n) cin >> a[i] >> b[i];
   rep(i, 0, 1005) rep(j, 0, 10005) dp[i][j] = INF;
   dp[0][0] = 0;
   rep(i, 0, n) {
      rep(j, 0, h + 1) {
         if (j < a[i]) {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + b[i]);
         } else {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
         }
      }
   }
   cout << dp[n][h] << endl;
   return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, i, j;
  cin >> n;
  for(i = 0; i < 100; i++) {
    for(j = 0; j < 100; j++) {
      if((i * 4) + (j * 7) == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
MOD = 10**9 + 7
li = []
for i in range(2*n):
    if i % 2 == 0 and s[i] == "B":
        li.append("W")
    elif i % 2 == 0 and s[i] == "W":
        li.append("B")
    elif i % 2 == 1 and s[i] == "B":
        li.append("B")
    elif i % 2 == 1 and s[i] == "W":
        li.append("W")
        
cnt = 0
ans = 1
for string in li:
    if string == "W":
        cnt += 1
    else:
        if cnt <= 0:
            print(0)
            exit()
        ans *= cnt
        cnt -= 1
    ans %= MOD

if cnt != 0:
    print(0)
    exit()

for i in range(1, n+1):
    ans *= i
    ans %= MOD

print(ans)

Measured memory_bytes: 53984
#include<stdio.h>

#define N 100000

int main(){
  int n, q;
  int count = 0;
  int left, mid, right;
  int S[N],T[N];
  int i, key;
  

  scanf("%d", &n);
  
  for(i = 0; i < n; i++) scanf("%d", &S[i]);
  
  scanf("%d", &q);
  
  for(i = 0; i < q; i++) scanf("%d", &T[i]);
  
  for(i = 0; i < q; i++){
    key = T[i];
    left = 0;
    right = n;
    
    while(left < right){
      mid = (left + right) / 2;
      
      if(key == S[mid]){
	count++;
	break;
      }

      if(key > S[mid]) left = mid + 1;
      else if(key < S[mid]) right = mid;
    }
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	int n=s.size();
	string t="";
	rep(i,n){
		if(s[i]!='B') t+=s[i];
		else{
			if(t.size()){
				string u=""; rep(j,t.size()-1) u+=t[j];
				t=u;
			}
		}
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
S = [list(input()) for _ in range(H)]

white = 0
for i in range(H):
  white += S[i].count('.')

q = [(0,0)]
S[0][0] = 0
while q:
  qq = []
  
  for xy in q:
    x,y = xy
    for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
      if not(0 <= x+dx < W) or not(0 <= y+dy < H):
        continue
      elif S[y+dy][x+dx] != '.':
        continue
      S[y+dy][x+dx] = S[y][x] + 1
      qq.append((x+dx,y+dy))
  if S[-1][-1]!=".":
      break    
  q = qq

print(white - S[-1][-1] -1 if S[-1][-1] != '.' else -1)


Measured memory_bytes: 40304
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();

		for (int i=0; i<s.length(); i++){
			if ((s.substring(i) + s.substring(0, i)).equals(t)){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
		return;
	}
}

Measured memory_bytes: 22740
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int even = sc.nextInt();
		int odd = sc.nextInt();
		//奇数+奇数か偶数+偶数しかありえない
		if(even == 0) {
			System.out.println(odd*(odd-1)/2);
			return;
		}
		if(odd == 0) {
			System.out.println(even*(even-1)/2);
			return;
		}
		
		System.out.println( odd*(odd-1)/2 + even*(even-1)/2);
		
	}
		
}

Measured memory_bytes: 22612
s = input()
if s == 'SUN':
    print('7')
elif s == 'MON':
    print('6')
elif s == 'TUE':
    print('5')
elif s == 'WED':
    print('4')
elif s == 'THU':
    print('3')
elif s == 'FRI':
    print('2')
else:
    print('1')
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> v(N); REP(i, N) cin >> v[i];

  sort(ALL(v));

  double ans = v[0];
  for (int i = 1; i < N; ++i) {
    ans = (ans+v[i])/2.;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace  std;

using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<int , int > pairs;
typedef complex<ll> G;
const int N=2e5+5;

const int INF = 1e9+5;
ll ap(ll n) {
    return (ll)floor(log2(n));
}

void done() {
    ll n, k;
    cin >> n>> k;

//      cout << __builtin_popcount(5^4)


}
void solve() {
    double a, b;
    cin >> a >> b;

}

void another() {
    ll n, m, k;

    cin >> n >> m >> k;
    ll a[n+1], b[m+1];
    a[0] = 0;
    b[0] = 0;
    for(int i=0; i< n;i++) {
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    for(int i=0;i < m;i++) {
        cin >> b[i+1];
        b[i+1] += b[i];
    }
    ll ans = 0;
    for(ll i=0, j=m;i <= n;i++) {
        if(a[i] > k)break;
        while(a[i]+b[j] > k && j >=0) {
            --j;
        }
        ans = max(i+j, ans);
    }
    cout << ans;
}
void test_case() {
    int t;
    cin >> t;
    while(t--)done();
}
int main() {

    fast;
    another();
}


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

int main(){
    string S;
    char c;
    cin >> S;
    int N,n,i;//N:size of S,n:# of 1 sentou
    long long int K;
    cin >> K;
    N = S.size();
    n = 0;
    for(i=0;i<N;i++){
        if(S.at(i)!='1'){
            c = S.at(i);
            break;
        }
        n++;
    }
    if(K <= n) cout << "1" << endl;
    else cout << c << endl;
    return 0;
}

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

int main() {
    cout << fixed << setprecision(10);
    
    int N, K; cin >> N >> K;
    int max_com = (N-1) * (N-2) / 2;
    if (K > max_com) {
        cout << -1 << endl;
        return 0;
    }

    // max のときのedgeの本数
    int n_edge = N-1;
    // あとこれだけ辺の追加が必要
    int need_edge = max_com - K;
    int M = n_edge + need_edge;
    cout << M << endl;
    // すでに繋がってる辺の分
    // N-1本
    rep(i, N-1) {
        cout << 1 << " " << i+2 << endl;
    }
    int l = 2;
    int r = 3;
    while (n_edge < M) {
        cout << l << " " << r << endl;
        if (r == N) {
            l += 1;
            r = l+1;
        } else {
            r += 1;
        }
        n_edge += 1;
    }
    return 0;
}

Measured memory_bytes: 256
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N, K = map(int, input().split())
MOD = 10**9 + 7

comb = Combination(N + 100)
red = N - K
blue = K

ans = []
for i in range(1, K + 1):
    if i - 1 > red:
        ans.append(0)
        continue

    b = max(comb.ncr(blue - 1, i - 1), 1)
    r = max(comb.ncr(red + 1, i), 1)
    ans.append(b * r % MOD)

print(*ans, sep='\n')

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

using namespace std;

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

    int h, w;
    cin >> h >> w;
    string s;
    int a[h][w];
    for (int i = 0; i < h; i++) {
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '.') a[i][j] = 0;
            else a[i][j] = 1;
        }
    }
    int res[h][w][2];
    res[0][0][0] = 0, res[0][0][1] = 1;
    for (int i = 1; i < h; i++) {
        if (a[i][0] == a[i - 1][0]) {
            res[i][0][0] = res[i - 1][0][0];
            res[i][0][1] = res[i - 1][0][1];
        } else {
            res[i][0][0] = res[i - 1][0][1];
            res[i][0][1] = res[i - 1][0][0] + 1;
        }
    }
    for (int i = 1; i < w; i++) {
        if (a[0][i] == a[0][i - 1]) {
            res[0][i][0] = res[0][i - 1][0];
            res[0][i][1] = res[0][i - 1][1];
        } else {
            res[0][i][0] = res[0][i - 1][1];
            res[0][i][1] = res[0][i - 1][0] + 1;
        }
    }
    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            if (a[i][j] == a[i - 1][j]) {
                res[i][j][0] = res[i - 1][j][0];
                res[i][j][1] = res[i - 1][j][1];
            } else {
                res[i][j][0] = res[i - 1][j][1];
                res[i][j][1] = res[i - 1][j][0] + 1;
            }
            if (a[i][j] == a[i][j - 1]) {
                res[i][j][0] = min(res[i][j][0], res[i][j - 1][0]);
                res[i][j][1] = min(res[i][j][1], res[i][j - 1][1]);
            } else {
                res[i][j][0] = min(res[i][j][0], res[i][j - 1][1]);
                res[i][j][1] = min(res[i][j][1], res[i][j - 1][0] + 1);
            }
        }
    }
    if (a[h - 1][w - 1] == 0) cout << res[h - 1][w - 1][0];
    else cout << res[h - 1][w - 1][1];
    cout << "\n";
    return 0;
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    vector<vector<int>> edge(n, vector<int>());
    vector<vector<int>> weight(n, vector<int>());
    for(int i=0; i<n-1; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--; c[i];
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
        weight[a[i]].push_back(c[i]);
        weight[b[i]].push_back(c[i]);
    }

    int q, k;
    cin >> q >> k;
    k--;

    vector<int> dis(n, -1);
    #if 0
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, k));
    while(!pq.empty()){
        int d = pq.top().first;
        int p = pq.top().second;
        pq.pop();
        if(dis[p] != -1) continue;
        dis[p] = d;
        for(int i=0; i<edge[p].size(); i++){
            int next = edge[p][i];
            if(dis[next] == -1){
                pq.push(make_pair(d + weight[p][i], next));
            }
        }
    }
    #else
    stack<int> s;
    s.push(k);
    dis[k] = 0;
    while(!s.empty()){
        int p = s.top();
        s.pop();
        for(int i=0; i<edge[p].size(); i++){
            int next = edge[p][i];
            if(dis[next] == -1){
                s.push(next);
                dis[next] = dis[p] + weight[p][i];
            }
        }
    }
    #endif


    for(int i=0; i<q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << dis[x] + dis[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 19804
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <time.h>

#define loop(i, num)  for (int i = 0; i < num; i++)

using namespace std;

bool isPrime[100000];

vector<int> isSimilar;

int n;

void getPrime() {
    
    isPrime[2] = 1;
    
    for (int i = 3; i < 100000; i += 2) {
        
        bool isPrime = 1;
        
        for (int j = 3; j <= sqrt(i); j += 2) {
            
            if (i % j == 0) {
                
                isPrime = 0;
                
                break;
                
            }
            
        }
        
        if (isPrime && ::isPrime[(i + 1) / 2]) {
            
            isSimilar.push_back(i);
            
        }
        
        ::isPrime[i] = isPrime;
        
    }
    
}

int main() {
    
    getPrime();
    
    cin >> n;
    
    loop (i, n) {
        
        int l, r;
        
        cin >> l >> r;
        
        auto res = (upper_bound(isSimilar.begin(), isSimilar.end(), r) - isSimilar.begin()) - (int) (lower_bound(isSimilar.begin(), isSimilar.end(), l) - isSimilar.begin());
        
        cout << res << endl;
        
    }
    
}


Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 

using namespace std;

int judge(int m);

int func(int a, int d, int n, int j);

int main()
{
	int a, d, n;
	while(1){
		cin >> a >> d >> n;
		if(a == 0 && d == 0 && n == 0) break;
		int ans, j;
		if(a == 1){
			if(d == 1 && n == 1) ans = 2;
			else ans = func(a+d, d, n, 0);
		} else {
			ans = func(a, d, n, 0);
		}
		cout << ans << endl;
	}
	return 0;
}

int judge(int m)
{
	int k = 2;
	while(1){
		if(k * k > m) return 1;
		else if(m % k == 0) return 0;
		else k++;
	}
}

int func(int a, int d, int n, int j)
{
	int c, cnt=0;
	while(1){
		c = a + (j * d);
		if(judge(c)) cnt++;
		if(cnt == n){
			return c;
			break;
		}
		j++;
	}
}

Measured memory_bytes: 1160
o = input()
e = input()
x = []
o = list(o)
e = list(e)

for i in range(0,max(len(o),len(e))):
  #print(x)
  if(len(o) != 0 and len(e) != 0):
    x.append(o[0])
    del o[0]
    x.append(e[0])
    del e[0]
  elif(len(o) != 0 and len(e) == 0):
    x.append(o[0])
    del o[0]
  elif(len(o) == 0 and len(e) != 0):
    x.append(e[0])
    del e[0]
print(''.join(x))
  

Measured memory_bytes: 38384
from functools import reduce
from operator import mul
import sys
input = sys.stdin.readline

count = int(input())
list = list(map(int, input().split()))
sum = list[0]
if 0 in list:
    print(0)
    exit()
else:
    for i in range(count - 1):
        sum = sum * list[i + 1]
        if sum > 1000000000000000000:
            print(-1)
            exit()


    print(sum)

Measured memory_bytes: 82052
#include<stdio.h>
#include<stdlib.h>
int main(){
  int k,i,num=1;
  scanf("%d",&k);
  long int a[100001];
  for(i=1;i<10;i++)
    a[num++]=i;
  i=1;
  while(num<=100000){
    if(a[i]%10!=0)
      a[num++]=a[i]*10+a[i]%10-1;
    a[num++]=a[i]*10+a[i]%10;
    if(a[i]%10!=9)
      a[num++]=a[i]*10+a[i]%10+1;
    i++;
  }
  printf("%ld\n",a[k]);
  return 0;
}

Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  int s, w;
  cin >> s >> w;
  cout << ((s <= w) ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3624
def shortest_dijkstra(nodes, edges, start, infinity: 1 << 32)
  costs = nodes.map{ |n| n == start ? 0 : infinity }
  ns = [start]
  determined = {}
  un = []
  while ui = ns.shift
    nu = ui
    u = costs[nu-1]
    (edges[nu] || {}).each{ |nv,w|
      next if costs[nv-1] <= u + w
      costs[nv-1] = u + w
      ns << nv
    }
  end  
  costs
end

n,m,s,t = gets.split.map(&:to_i)

rails_yn = {}
rails_sn = {}
(0...m).each{ 
  v,u,a,b = gets.split.map(&:to_i) 
  rails_sn[v] ||= {}; rails_sn[u] ||= {}
  rails_yn[v] ||= {}; rails_yn[u] ||= {}
  rails_yn[v][u] = rails_yn[u][v] = a
  rails_sn[v][u] = rails_sn[u][v] = b
}
ns = (1..n).to_a
INF = 1000000000000000

yh = shortest_dijkstra(ns, rails_yn, s, infinity: INF)
sh = shortest_dijkstra(ns, rails_sn, t, infinity: INF)
costs = (0...n).map{ |i| yh[i] + sh[i] }

min_costs = INF
puts costs.reverse.map{ |w|
  min_costs = [min_costs, w].min
  INF-min_costs
}.reverse


Measured memory_bytes: 83880
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin >> n >> k;
  if (k%2==1){
      cout << (ll) pow((n/k),3) << endl;
  }else{
      cout << (ll) pow(((n+(k/2))/k),3) + (ll) pow((n/k),3) << endl;
  }
}


Measured memory_bytes: 384