akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

#define mod 1000000007

long mem[100001][2];

long rec(vector<int> adj[], int n, int id, bool vis[], int prev=-1)
{
  if(prev!=-1&&mem[id][prev]!=-1)
	return mem[id][prev];
  long ans=0,a=1,b=1;
  vis[id]=true;
  int cnt=0;
  for(int i=0;i<adj[id].size();i++)
  {
    if(!vis[adj[id][i]])
    {
      cnt++;
      a*=rec(adj,n,adj[id][i],vis,1);
      if(prev==1 or prev==-1)
        b*=rec(adj,n,adj[id][i],vis,0);
      a%=mod;
      b%=mod;
    }
  }
  vis[id]=false;
  long c=(a%mod+b%mod)%mod;
  ans=(ans%mod+c%mod)%mod;
  if(prev==0)
  	ans--;
  if(prev==-1)
	return ans;
  mem[id][prev]=ans;
  return ans;
  
}

int main(){
  int n;
  cin>>n;
  vector<int> adj[n+1];
  for(int i=0;i<n-1;i++)
  {
    int x,y;
    cin>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  bool vis[n+1]={0};
  memset(mem,-1,sizeof(mem));
  cout<<rec(adj,n,1,vis);
  
}

Measured memory_bytes: 17152
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
#include<list>
using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	cout << A * B << endl;

	return 0;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int grid_tate[2000][2000] = {}, grid_yoko[2000][2000] = {};

int main(void)
{
	int h, w;
	string s[2000];
	cin >> h >> w;
	rep(i, h) cin >> s[i];
	// 下処理
	rep(i, h){
		rep(j, w){
			if(s[i][j] == '#') grid_yoko[i][j] = 0;
			else if(j == 0) grid_yoko[i][j] = 1;
			else grid_yoko[i][j] = grid_yoko[i][j-1] + 1;
		}
	}
	rep(i, h){
		for(int j = w - 1; j >= 0; j--){
			if(s[i][j] == '#') grid_yoko[i][j] = 0;
			else if(j == w - 1) grid_yoko[i][j] = grid_yoko[i][j];
			else chmax(grid_yoko[i][j], grid_yoko[i][j+1]);
		}
	}
	rep(j, w){
		rep(i, h){
			if(s[i][j] == '#') grid_tate[i][j] = 0;
			else if(i == 0) grid_tate[i][j] = 1;
			else grid_tate[i][j] = grid_tate[i-1][j] + 1;
		}
	}
	rep(j, w){
		for(int i = h - 1; i >= 0; i--){
			if(s[i][j] == '#') grid_tate[i][j] = 0;
			else if(i == h - 1) grid_tate[i][j] = grid_tate[i][j];
			else chmax(grid_tate[i][j], grid_tate[i+1][j]);
		}
	}
	int ans = 0;
	rep(i, h){
		rep(j, w){
			// cout << grid_tate[i][j] + grid_yoko[i][j] << " ";
			chmax(ans, grid_tate[i][j] + grid_yoko[i][j]);
		}
		// cout << endl;
	}
	cout << ans - 1 << endl;
	return 0;
}

Measured memory_bytes: 35584
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();
      // 結果の初期化
      Integer kekka = 0;
      // 比較
      for(int i = 0; i < 3; i++){
        if(s.substring(i,i+1).equals(t.substring(i,i+1))){
        // 予報と実際が一致
          kekka++;
        }else{
          // 不一致
        }
      }
        		// 出力
		System.out.println(kekka);
      
    }
  
}

Measured memory_bytes: 21716
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int a, b, c, d=0, ans=0;
  cin >> a >> b >> c;
  d = max({a, b, c}) * 3 - a - b - c;
  if (d%2==0) {
    ans = d/2;
  } else {
    ans = (d+3)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>

using namespace std;

#define f2sum(a,b) (a+b)%2 // 位数2の有限体の和
typedef pair<int, int> P;
struct edge {
    int u,v,w;
};

void coloring(char color[], int u, int v, int add){
    // u -> v +_{F_2} addする(0だった場合は同色, 1だった場合は異色)
    // printf("coloring: %d %d %d\r\n", u, v, add);
    color[v] = f2sum(color[u], add);
    
}

#define MAX_N 100000

int main(){
    int N;
    char color[MAX_N];
    vector<edge> edges[MAX_N];

    scanf("%d", &N);
    for (int i=0;i<N;i++)color[i] = -1; // -1: 未探索
    int u,v,w;
    for (int i=0 ; i < N-1 ; i++){
        scanf("%d %d %d", &u, &v, &w);
        edges[u-1].push_back({u-1, v-1, w});
        edges[v-1].push_back({v-1, u-1, w}); // 無効グラフ
    }

    // find first
    queue<edge> search_queue;
    int start = 0; // どこスタートにしてもいい
    for (vector<edge>::iterator itr = edges[start].begin(); itr != edges[start].end(); itr++){
        // printf("init (%d): %d %d %d\r\n", i, itr->u, itr->v, itr->w);
        search_queue.push({itr->u, itr->v, itr->w});
    }
    color[start] = 0; // 始点は既に探索済みとする

    // bfs
    do{
        edge p = search_queue.front();
        search_queue.pop();
        coloring(color, p.u, p.v, p.w % 2);
        for(vector<edge>::iterator itr = edges[p.v].begin() ; itr != edges[p.v].end() ; itr++){
            // printf("%d %d %d\r\n", itr->u, itr->v, itr->w);
            if (color[itr->v] == -1){
                search_queue.push(edge{itr->u, itr->v, itr->w});
            }
        }
    } while( search_queue.size() );

    for(int i=0; i<N; i++){
        printf("%d\r\n", color[i]);
        fflush(stdout);
    }

    return 0;
}

Measured memory_bytes: 7040
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

bool comp(P x, P y) {
    return x.second < y.second;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first >> a[i].second;
    }

    sort(all(a), comp);
    ll sum = 0;
    rep(i, n) {
        sum += a[i].first;
        if(sum > a[i].second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int N = 1e5+10;
ll a[N], x[N];
int main() {
	int n;
	cin >> n;
	//ll sum = 0;
	rep(i,n) {
		cin >> a[i+1];
		x[1] += a[i+1];
	}
	for (int i = 2; i <= n; i += 2)
	{
		x[1] -= 2*a[i];	
	}
	for (int i = 2; i <= n; i++)
	{
		x[i] = 2*a[i-1] - x[i-1];
	}
	rep(i,n) {
		cout << x[i+1] << ' ';
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 5184
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    ll x, y;
    cin >> x >> y;
    if (x < y) {
        if (x >= 0 || y <= 0)
            cout << y - x << endl;
        else if (abs(x) <= abs(y))
            cout << (x + y + 1) << endl;
        else
            cout << -x - y + 1 << endl;
    } else {
        if (x < 0 || y > 0)
            cout << x - y + 2 << endl;
        else if (x == 0 || y == 0)
            cout << x - y + 1 << endl;
        else if (abs(x) <= abs(y))
            cout << -x - y + 1 << endl;
        else
            cout << x + y + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int w,h,i=0,j=0;

    while(1)
        { scanf("%d%d",&h,&w);
        if (w==0&&h==0) break;

            for(i=1;i<=h;i++)
            {
                 if (i%2==1)
                    {
                        for (j=1;j<=w;j++)
                                {
                                    if (j%2==1) printf("#"); else printf(".");
                                }    printf("\n");}
                if (i%2==0)
                    {
                        for (j=1;j<=w;j++)
                                {
                                    if (j%2==1) printf("."); else printf("#");
                                }    printf("\n");}

            }    printf("\n");
        }
}



Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main()
{
	int x,i,cnt;
	char a[200001],b[200001];
	scanf("%s",a);
	scanf("%s",b);
	x=strlen(a);
	cnt=0;
	for(i=0;i<x;i++){
		if(a[i]!=b[i]) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
const ll MOD = 1e9+7;

int main() {
  ll n,k; cin >> n >> k;
  vector<ll> div;
  for(ll i=1; i*i <= n; i++){
    div.push_back(i);
    if(i != n/i) div.push_back(n/i);
  }
  div.push_back(0);
  sort(ALL(div));
  ll m = div.size()-1;
  //1-indexed
  vector<ll> num(m+1,0);
  REP(i, m) num[i+1] = div[i+1] - div[i];

  vector<vector<ll>> dp(k+1, vector<ll>(m+1,0));
  vector<ll> sum(m+1, 0);
  dp[0][1] = 1;

  REP(i, k){
    FOR(j, 1, m+1) sum[j] = (sum[j-1] + dp[i][j]) % MOD;
    FOR(j, 1, m+1) dp[i+1][j] = (num[j] *  sum[m-j+1])%MOD;
  }
  ll ans = 0;
  FOR(j, 1, m+1) (ans += dp[k][j]) %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 51960
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	int A,B;
	cin >> A >> B;
	string s;
	cin >> s;

	string ret = "Yes";
	FOR(i,0,A){
		if (!('0'<= s[i] && s[i] <= '9')) ret = "No";
	}
	if(s[A] != '-') ret = "No";
	FOR(i,A+1,A+B+1){
		if (!('0'<= s[i] && s[i] <= '9')) ret = "No";
	}

	cout << ret << endl;
	return 0;

}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (x, y) = (v[0], v[1]);
    let mut ans = 0;
    let mut cur = x;
    while cur <= y {
        cur *= 2;
        ans += 1;
    }
    println!("{}", ans);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];

  ll now = 0;
  ll ans = 0;

  REP(i, N) {
    ll po = (A[i] - 1) / (now + 1);
    ans += po;
    if (i == 0)
      now = 1;
    else if (po == 0) {
      now = max(now, A[i]);
    }
  }
  cout << ans << endl;

  return 0;
}


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

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXQ = 3e5 + 5;

int n, m;
int q;
pair<int, int> cords[MAXQ];

void solve() {
    cin >> n >> m >> q;
     map<int, int> counter;
    for (int i = 0; i < q; ++i) {
        cin >> cords[i].first >> cords[i].second; --cords[i].first, --cords[i].second;
        counter[cords[i].second]++;
    }
    sort(cords, cords + q);
    int ind = 0, ptr = 0;
    int ans = 1;
    multiset<int> have;
    for (auto p : counter) have.insert(p.second);
    while (ind < q) {
        while (ptr < q && cords[ptr].first == cords[ind].first) {
            //cout << "cur: " << cords[ptr].first << ' ' << cords[ptr].second << "\n";
            have.erase(have.find(counter[cords[ptr].second]));
            counter[cords[ptr].second]--;
            have.insert(counter[cords[ptr].second]);
            ++ptr;
        }
        int res = ptr - ind;
        int adding = 0;
       // cout << "have: " << endl;
        //for (auto p : have) cout << p << ' ';
        //cout << "\n";
        if (!have.empty()) adding = *have.rbegin();
        //cout << res + adding << "\n";
        ans = max(ans, res + adding);
        for (int j = ind; j < ptr; ++j) {
            have.erase(have.find(counter[cords[j].second]));
            counter[cords[j].second]++;
            have.insert(counter[cords[j].second]);
        }
        //cout << "have: " << endl;
        //for (auto p : have) cout << p << ' ';
        //cout << "\n";
        ind = ptr;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 34124
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>
#include <numeric>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0l);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
bool chmin(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}


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



int main() {
    srand(time(NULL));

    retry:
#ifdef LOCAL
    // gen();

    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
#endif

    string s;
    cin >> s;
    for (int i = 0; i < 12; i++) {
        if (i == 4) {
            cout << " ";
        }
        cout << s[i];
    }
    cout << endl;



    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    cout<<1+(N-K+K-2)/(K-1)<<endl;
}


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

using namespace std;

//入力
int N,M;


int main(){
  cin >> N;
  
  int A[N],Y[N]={0};
  int i;
  
  for(i=0;i<N-1;i++){
    cin >> A[i];
    Y[A[i]-1]++;
  }
  
  for(i=0;i<N;i++){
    cout << Y[i] << endl;
  }
}

Measured memory_bytes: 5204
N,K=map(int,input().split())
S=list(input())

R=0
c=0
f=2
for i in range(N):
    if S[i]=='R':
        R+=1
        if f==0:
            c+=1
        f=1
    else:
        if f==1:
            c+=1
        f=0

out=min(N-c-1+2*K,N-1)

print(out)


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

int main() 
{
    bool cards[4][14];
    int n, rank;
    char suit;

    for (int s = 0; s < 4; s++)
        for(int r = 1; r <= 13; r++)
            cards[s][r] = 0;

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> suit >> rank;
        if (suit == 'S') cards[0][rank] = 1;
        if (suit == 'H') cards[1][rank] = 1;
        if (suit == 'C') cards[2][rank] = 1;
        if (suit == 'D') cards[3][rank] = 1;
    }

    for (int s = 0; s < 4; s++) {
        for (int r =1; r <= 13; r++) {
            if (cards[s][r]) continue;
            if (s == 0) suit = 'S';
            if (s == 1) suit = 'H';
            if (s == 2) suit = 'C';
            if (s == 3) suit = 'D';
            cout << suit << ' ' << r << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3076
while True:
    a,op,b = input().split()     
    a =int(a)                   
    b =int(b)                   

    if op=="?": 
        break
    else:    
        if op=='+':
            print(a + b)
        elif op=='-':
            print(a - b)
        elif op=='*':
            print(a * b)
        elif op=='/':
            print(a // b)


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

sm = sum(a)

div = []
for i in range(1,int(sm**0.5)+1):
    if sm % i == 0:
        div.append(i)
        if i != (sm // i):
            div.append(sm//i)
div.sort()

answer = 1

for _ in range(len(div)):
    ans = div.pop()
    b = sorted(list(map(lambda x: x%ans, a)))

    lenb = len(b)
   
    l = 0
    r = ans*len(b) - sum(b)

    for i in range(lenb):
        l += b[i]
        r -= ans - b[i]
        if l <= k and l >= r and (l-r) %2 ==0:
            print(ans)
            exit()


Measured memory_bytes: 42716
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF=1e18;
const int mod = 1000000007;

int H,W;
long long d[305][305];

void floyd(){
  for(int k=0;k<=9;k++){
    for(int i=0;i<=9;i++){
      if(d[i][k]==INF){continue;}
      for(int j=0;j<=9;j++){
        if(d[k][j]==INF){continue;}
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
}

int main(){
  cin>>H>>W;
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      d[i][j]=((i==j)?0:INF);
    }
  }

  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      int c;
      cin>>c;
      d[i][j]=c;
    }
  }
  floyd();
  int sum=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int c;
      cin>>c;
      if(c>=0){sum+=d[c][1];}
    }
  }
  cout<<sum<<endl;
  return 0;                       
}

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

int main() {
    const int inf = 1000000000;
    int n, m;
    cin >> n >> m;

    int a[1000], b[1000], c[1000], dist[100][100];

    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) dist[i][j] = 0;
            else dist[i][j] = inf;
        }
    }

    for (int i = 0; i < m; i++) {
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = m;
    for (int i = 0; i < m; i++) {
        bool shortest = false;
        for (int j = 0; j < n; j++) if (dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
        if (shortest) ans--;
    }

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

Measured memory_bytes: 256
#include<stdio.h>


int main(){
int n=0,x=0,i,j,f,sumx=0,count=0;

while(1){
	count=0;
	scanf("%d %d",&n,&x);
	if(n==0 && x==0) break;
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			for(f=j+1;f<=n;f++){
				sumx=i+j+f;
				if(sumx==x){
					count=count+1;
			}
		}
	}
	}
printf("%d\n",count);
}

return 0;

}

Measured memory_bytes: 600
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b){
		if(a>c&&b<c){
			cout<<"Yes"<<endl;
			return 0;
			}
		}
	else if(a<b){
		if(a<c&&b>c){
			cout<<"Yes"<<endl;
			return 0;
			}
		}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
ll K;
int A[200000];
vector<int> v;
unordered_set<int> st;

signed main(){
    cin >> N >> K;
    rep(i, N){
        cin >> A[i];
        A[i]--;
    }

    int n = 0;
    do{
        v.pb(n);
        st.insert(n);
        n = A[n];
    } while(st.count(n) == 0);

    rep(i, v.size()){
        if(v[i] == n){
            if(K < i){
                cout << v[K]+1 << endl;
            }
            else{
                K -= i;
                cout << v[K%(v.size()-i) + i]+1 << endl;
            }
        }
    }
}

Measured memory_bytes: 12796
import java.util.Scanner;

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

    String run() {
        int N = in.nextInt();
        switch (N % 10) {
            case 3:
                return "bon";
            case 0:
            case 1:
            case 6:
            case 8:
                return "pon";
            default:
                return "hon";
        }
    }

    public static void main(String[] args) {
        System.out.println(new Main().run());
    }
}


Measured memory_bytes: 35620
#include<stdio.h>

typedef unsigned int uint;
typedef uint B;
#define REP(i,n) for(i=0; i<(int)(n); i++)

#define mask 0x07
#define get(d,i) (((d) >> ((i)*3)) & mask)
#define set(d,i,n) {d &= ~(mask << ((i)*3)); d |= (n << (3*(i)));}
#define get2(d,x,y) get(d, x+y*4)
#define set2(d,x,y,n) set(d, x+y*4, n)
#define ABS(x) ((x)<0?-(x):(x))

static inline B swap(B b, int p1, int p2){
  int d1 = get(b, p1);
  int d2 = get(b, p2);
  set(b, p1, d2);
  set(b, p2, d1);
  return b;
}

#define swap2(b,x1,y1,x2,y2) swap(b, (x1)+(y1)*4, (x2)+(y2)*4)


B q[8*7*6*5*4*3*2*1 + 10];
int flag[1<<24];

int main(){
  int tmp;
  int x,y,i;
  B ans = 0; REP(i,8) set(ans,i,i);

  int head = 0;
  int tail = 0;
  q[tail++] = ans;
  flag[ans] = 1;

  while(head != tail){
    B bb = q[head++];
    int nn = flag[bb];

    REP(y,2) REP(x,4){
      if(get2(bb,x,y) == 0){
        if(y == 0){
          B bbb = swap2(bb,x,y,x,y+1);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail++] = bbb;
          }
        }else{
          B bbb = swap2(bb,x,y,x,y-1);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail++] = bbb;
          }
        }
        if(x != 0){
          B bbb = swap2(bb,x,y,x-1,y);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail++] = bbb;
          }
        }
        if(x != 3){
          B bbb = swap2(bb,x,y,x+1,y);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail++] = bbb;
          }
        }
      }
    }
  }
  while(~scanf("%d",&tmp)){
    B b = 0;
    set(b,0,tmp);
    REP(i,7){
      scanf("%d",&tmp);
      set(b,i+1,tmp);
    }
    printf("%d\n",flag[b]-1);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;

int dx8[] = {0,1,1,1,0,-1,-1,-1};
int dy8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
    int h, w;
    cin >> h >> w;
    char c[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if(c[i][j] == '#') cout << '#';
            else{
                int bomb = 0;
                for (int d = 0; d < 8; d++) {
                    int dy = i + dy8[d];
                    int dx = j + dx8[d];
                    if(!(0<=dx && dx<w && 0<=dy && dy<h)) continue;
                    if(c[dy][dx] == '#') bomb++;
                }
                cout << bomb;
            }
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    long long ans;
    if (1 == N || 1 == M)
    {
        if (1 == N && 1 == M)
        {
            ans = 1;
        }else
        {
            ans = max(N, M) - 2;
        }
        
    }else
    {
        ans = ((long long)N - 2) * ((long long)M - 2);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define RNG(i,from,to) for(ll i=(from); i<(ll)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

int main(int argc, char const *argv[])
{
  ll A, B, K;
  cin >> A >> B >> K;
  auto a = A;
  auto b = B;
  set<ll> st;
  REP(i, K) {
    st.insert(A);
    A++;
    if (A > b) break;
  }
  REP(i, K) {
    st.insert(B);
    B--;
    if (B < a) break;
  }
  for (const auto i : st) {
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void){
	long A,B;
	char op;
	
	scanf("%ld %c %ld",&A,&op,&B);
	if(op=='+'){
		printf("%ld\n",A+B);
	}
	else{
		printf("%ld\n",A-B);
	}
	
	return 0;
}

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

using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll int 
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define N 2000001
#define M 1000000007
#define INF 1000000000000000
ll Arr[200001],size1[200001];


int root(int i)
    {
        while(Arr[ i ] != i)           //chase parent of current element until it reaches root
        {
         i = Arr[ i ];
        }
        return i;
    }


    /*modified union function where we connect the elements by changing the root of one of the elements*/

  void weightedunion(int A,int B)
    {
        int root_A = root(A);
        int root_B = root(B);
        if(root_A==root_B)return;
        if(size1[root_A] < size1[root_B ])
        {
    Arr[ root_A ] = Arr[root_B];
    size1[root_B] += size1[root_A];
    }
        else
        {
    Arr[ root_B ] = Arr[root_A];
    size1[root_A] += size1[root_B];
    }

    }
int main()
{
    ll n,m;
    cin>>n>>m;
    ll i,j,k;
    for(i=1;i<=n;i++)
    {
        
        Arr[i]=i;size1[i]=1;
    }
    map<pll,ll> mp;
    for(i=1;i<=m;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(mp[{x,y}] || mp[{y,x}])
        continue;
        else
        weightedunion(x,y);
       mp[{x,y}]++;
      // cout<<i<<endl;
    }
    ll ans=0;
    for(i=1;i<=n;i++)
    {
       // cout<<size1[i]<<endl;
        ans=max(ans,size1[i]);
    }
    cout<<ans;
  

   
    
}

Measured memory_bytes: 30124
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math, time
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIF(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')
#solve
def solve():
    n = II()
    s = [None] * n
    dp = [None] * n
    for i in range(n):
        dp[i] = [-1] * 26
        s[i] = [input().rstrip()[::-1], i]
    for i in range(n):
        si,_ = s[i]
        dpi = dp[i]
        for j in range(len(si)):
            x = ord(si[j]) - ord("a")
            dpi[x] = j
    d = [s]
    ans = 0
    for i in range(10 ** 6):
        nd = []
        if not d: break
        for lis in d:
            tmp = [[] for i in range(26)]
            for l, k in lis:
                p = ord(l[i]) - ord("a")
                if len(l) == i + 1:
                    for x, m in lis:
                        if k != m:
                            if dp[m][p] >= i:
                                ans += 1
                else:
                    tmp[p].append((l, k))
            for k in tmp:
                if k:
                    nd.append(k)
        d = nd
    print(ans)
    return
#main
if __name__ == '__main__':
    solve()

Measured memory_bytes: 209848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc084_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  
  vector<int> c(N - 1);
  vector<int> s(N - 1);
  vector<int> f(N - 1);
  rep(i, N - 1) { cin >> c[i] >> s[i] >> f[i]; }

  vector<int> ans(N, 0);
  rep(i, N - 1) {
    int time = 0;
    repi(j, i, N - 1) {
      if (time < s[j]) {
        time += s[j] - time;
      } else {
        int rest = (time - s[j]) % f[j];
        time += rest  == 0 ? 0 : f[j] - rest;
      }
      time += c[j];
    }
    ans[i] = time;
  }

  rep(i, N) cout << ans[i] << endl;

}

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

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            if (T.Length == S.Length + 1 && T.Substring(0, S.Length) == S)
            {
                Console.WriteLine("Yes");
            }
            else {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 25716
package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func f(i int, links [][]int, dp []int) int {
	if dp[i] != -1 {
		return dp[i]
	}
	if len(links[i]) == 0 {
		dp[i] = 0
	} else {
		t := -1
		for _, j := range links[i] {
			t = max(t, f(j, links, dp))
		}
		dp[i] = t + 1
	}
	return dp[i]
}

func main() {
	defer flush()

	N := readInt()
	M := readInt()

	links := make([][]int, N)
	for i := 0; i < M; i++ {
		x := readInt() - 1
		y := readInt() - 1
		links[x] = append(links[x], y)
	}

	dp := make([]int, N)
	for i := 0; i < N; i++ {
		dp[i] = -1
	}

	result := -1
	for i := 0; i < N; i++ {
		result = max(result, f(i, links, dp))
	}
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


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

int main(void)
{
	char s[300000];
	char t[300000];
	int l, i, ans = 0;

	scanf("%s", s);
	scanf("%s", t);

	l = strlen(s);

	for (i = 0; i < l; i++)
	{
		if (s[i] != t[i]) ans++;
	}

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

	return 0;
}


Measured memory_bytes: 2116
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	ll H, W;
	cin >> H >> W;
	ll res = INT64_MAX;
	for (int i = 1;i < H;i++) {
		ll s1, s2, s3;
		s1 = i*W;
		s2 = (H - i)*(W / 2);
		s3 = (H - i)*W - s2;
		res = min(res, max({ s1,s2,s3 })-min({ s1,s2,s3 }));
		s2 = ((H - i) / 2)*W;
		s3 = (H - i)*W - s2;
		res = min(res, max({ s1,s2,s3 }) - min({ s1,s2,s3 }));
	}
	swap(H, W);
	for (int i = 1;i < H;i++) {
		ll s1, s2, s3;
		s1 = i*W;
		s2 = (H - i)*(W / 2);
		s3 = (H - i)*W - s2;
		res = min(res, max({ s1,s2,s3 }) - min({ s1,s2,s3 }));
		s2 = ((H - i) / 2)*W;
		s3 = (H - i)*W - s2;
		res = min(res, max({ s1,s2,s3 }) - min({ s1,s2,s3 }));
	}
	cout << res << "\n";

	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ab = a + b, cd = c + d;
    if (ab > cd)
        cout << "Left";
    else if (ab < cd)
        cout << "Right";
    else
        cout << "Balanced" << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
PS=[list(input().split()) for _ in range(M)]

miss=[[0,False] for _ in range(N)]

for p,s in PS:
  p=int(p)
  if miss[p-1][1]==False and s=="WA":
    miss[p-1][0]+=1
  if s=="AC":
    miss[p-1][1]=True
pena=0
ac=0
for m,tf in miss:
  pena+=m*tf
  ac+=tf

print(str(ac)+" "+str(pena))


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

#define debug1(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair<ll,ll> pii;
#define prev prevv

/*-----------------------------------------------------------------------*/

ll check[3000][3000];
ll dp[3000][3000];
pii prev[3000][3000];

int main(){
   fastt;
   
   string s,t;
   cin>>s>>t;

   for(ll i=0;i<s.length();i++)
    for(ll j=0;j<t.length();j++){
      prev[i][j]=mp(-1,-1);
      if(i>0&&dp[i][j]<dp[i-1][j]){
        prev[i][j]=mp(i-1,j);
        dp[i][j]=dp[i-1][j];
      }
      if(j>0&&dp[i][j]<dp[i][j-1]){
        prev[i][j]=mp(i,j-1);
        dp[i][j]=dp[i][j-1];
      }
      if(s[i]==t[j]&&i>0&&j>0){
        if(dp[i-1][j-1]+1>dp[i][j]){
        check[i][j]=1;
        prev[i][j]=mp(i-1,j-1);
        dp[i][j]=dp[i-1][j-1]+1;}
      }
      else if(s[i]==t[j]){
        check[i][j]=1;
        prev[i][j]=mp(i-1,j-1);
        dp[i][j]=1;
      }
    }

   ll i=s.length()-1,j=t.length()-1;

   stack <char > stk;

   while(i!=-1&&j!=-1){
       if(check[i][j]==1)
          stk.push(s[i]);
       ll p=prev[i][j].fi;
       ll q=prev[i][j].se;
       i=p,j=q;
   }

   while(stk.size()){
      char cc=stk.top();
      stk.pop();
      cout<<cc;
   }

   cout<<endl;

   return 0;
}


Measured memory_bytes: 281344
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    int N;
    cin >> N;
    // N + 1個の素数
    vi primes;
    int search[55555];
    FOR(i, 0, 55555) {
        search[i] = i+2;
    }
    int ind = 0;
    while ((int)primes.size() <= N) {
        int test = search[ind];
        if (test % 5 == 1)
            primes.push_back(test);
        FOR(i, 0, 55555) {
            if (search[i] % test == 0) search[i] = 0;
        }
        ind++;
        while(search[ind] == 0)ind++;
    }
    
    FOR(i, 0, N) {
        cout << primes[i];
        if (i != N-1) cout << " ";
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

int main(int argc, char *argv[]) {  
	int n;
	std::cin >> n;
	int ans = 0;
	int aa = n;
	while(aa) {
		ans += aa%10;
		aa /= 10;
	}
	std::cout << (n%ans==0?"Yes\n":"No\n");
	return 0;
}

Measured memory_bytes: 256
import sys

for in_str in sys.stdin:
    comp_list = list(map(int, in_str.split(" ")))
#    a, b = map(int, in_str.split())
    a = comp_list[0]
    b = comp_list[1]
    if a == 0 and b == 0 : break
    elif a < b :
        print(a, b)
    else :
        print(b, a)

Measured memory_bytes: 7912
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
typedef pair< int, int > Pi;

bool cmp(const pair< Pi, Pi >& p, const pair< Pi, Pi >& q)
{
  if(p.first.first + p.second.first, q.first.first + q.second.first)
    return(p.first.first + p.second.first < q.first.first + q.second.first);
  return(p.first.first * p.first.second + p.second.first * p.second.second <
         q.first.first * p.first.second + q.second.first * q.second.second);
}

// ax + by = d
pair< Pi, Pi > ask(int a, int b, int d)
{
  pair< Pi, Pi > ret({INF, INF}, {INF, INF});
  for(int x = 0; x < 100000; x++) {
    int f = abs(d - a * x);
    if(f % b == 0) ret = min(ret, {{x, a}, {f / b, b}}, cmp);
  }
  return(ret);
}

int main()
{
  int a, b, d;
  while(cin >> a >> b >> d, a) {
    auto alpha = ask(a, b, d), beta = ask(b, a, d);
    auto ret = min(alpha, beta, cmp);
    if(ret == beta) swap(ret.first, ret.second);
    cout << ret.first.first << " " << ret.second.first << endl;
  }
}

Measured memory_bytes: 2968
import java.util.Scanner;
 
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt()){
int n=sc.nextInt();
int num=0;
if(n<=36){
for(int a=0;a<=9;a++){
for(int b=0;b<=9;b++){
for(int c=0;c<=9;c++){
if(binary_search(n-a-b-c)){
num++;
}
}
}
}
}
System.out.println(num);
}
}
public static boolean binary_search(int x){
int[] n=new int[10];
for(int a=0;a<=9;a++){
n[a]=a;
}
int l=0;
int r=10;
while(r-l>=1){
int i=(int)(l+r)/2;
if(x==n[i]){
return true;
}
else if(x>n[i]){
l=i+1;
}
else{
r=i;
}
}
return false;
}
}

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for (int i=0; i<1000; i++)
    {
        int nums[3] = {i/100%10, i/10%10, i%10};
        int k=0;
        bool pos=false;
        for (int p=0; p<S.length(); p++)
        {
            if (S[p]-'0'==nums[k])
            {
                k++;
            }
            if (k==3)
            {
                pos=true;
                break;
            }
        }
        if (pos) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

bool graph[8][8];
bool visited[8];

int dfs(int a, int n){
  bool all_visited = true;
  fr(i,n) if(visited[i] == false) all_visited = false;
  if(all_visited) return 1;
  int ret = 0;
  fr(i, n) {
    if(visited[i]) continue;
    if(graph[a][i] == true){
      visited[i] = true;
      ret += dfs(i, n);
      visited[i] = false;
    }
  }  
  return ret;
}

int main(void) {
  int n,m;cin>>n>>m;
  fr(i, m) {
    int a,b;cin>>a>>b;
    a--;b--;
    graph[a][b] = graph[b][a] = true;
  }
 // bool visited[8];
  fr(i, n) visited[i] = false;
  visited[0] = true;
  cout << dfs(0, n) << endl;
  return 0;
}

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

int32_t main(){
	int T;
	cin >> T;
	int x = 1, y = 1;
	while(T--){
		long double a, b;
		cin >> a >> b;
		if(a >= x && b >= y){
			x = a;
			y = b;
		}else if(a < x && b < y){
			long double vote = max(ceil(x/a), ceil(y/b));
			x = a*vote;
			y = b*vote;
		}else if(a >= x && b < y){
			x = a*ceil(y/b);
			y = b*ceil(y/b);
		}else if(a < x && b >= y){
			x = a*ceil(x/a);
			y = b*ceil(x/a);
		}
		cerr << " - " << x << " " << y << endl;
	}
	cout << x + y << endl;
}

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    x = lines[0]
    

    return (x, )


def solve(x):

    upper = set("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    lower = set("abcdefghijklmnopqrstuvwxyz")

    result = 'a'
    if x in upper:
        result = 'A'

    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    cout<<"ABC"+s<<endl;
}

Measured memory_bytes: 256