akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int h, w;
vector<vector<char>> canbas;
void solve() {
	cin >> h >> w;
	canbas.resize(h + 2);
	for (int i = 0; i < (h + 2); ++i) {
		canbas[i].resize(w + 2);
	}
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			cin >> canbas[i][j];
		}
	}
	int cnt = 0;
	for (int i = 1; i <= h; ++i) {
		for(int j = 1; j <= w; ++j) {
			if (canbas[i][j] == '#' && canbas[i - 1][j] != '#' && canbas[i + 1][j] != '#' && canbas[i][j - 1] != '#' && canbas[i][j + 1] != '#') {
				cnt++;
			}
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
// DECLARAÇÕES
int N;
int aux, soma = 0;

// INSTRUÇÕES
scanf ("%d",&N);
aux = N;

while (aux > 0){
    soma += aux%10;
    aux = aux/10;
}

if (N%soma == 0)
    printf ("Yes\n");
else
    printf("No\n");


return 0;
}



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

static const int M = 1046597;
static const int L = 14;
char T[M][L];
char com[6], word[L];

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

int getKey(char str[]) {
  int key = 0;
  rep(i,0,(int) strlen(str))
  {
    key += getChar(str[i]);
    key *= 5; //左シフト(5進数)
  }
  return key;
}

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

//Mとh2は互いに素に
int hash2(int key) {
  //素数Mより小さい数はみなMと互いに素
  //h2の周期はM未満であればなんでも可
  //1を加えるのはkey%(M-1)==0のときにずれなくなるのを防ぐため
  //この関数は1 ~ M-1の間の値をとる
  return 1 + (key % (M - 1));
}

bool insert(char str[]) {
  ll key, h;
  key = getKey(str);
  ll h1 = hash1(key), h2 = hash2(key);
  for (ll i = 0;; ++i) {
    h = (h1 + i * h2) % M;
    if (strcmp(T[h], str) == 0) {
      return false; //すでに格納済
    } else if (strlen(T[h]) == 0) {
      strcpy(T[h], str);
      return true;
    }
  }
  return false;
}

bool find(char str[]) {
  ll key, h;
  key = getKey(str);
  ll h1 = hash1(key), h2 = hash2(key);
  for (ll i = 0;; ++i) {
    h = (h1 + i * h2) % M;
    if (strcmp(T[h], str) == 0) {
      return true;
    } else if (strlen(T[h]) == 0) {
      return false;
    }
  }
  return false;
}

void solve() {
  rep(i,0,M)
  {
    T[i][0] = '\0'; //すべて空文字列で初期化
  }
  int n;
  scanf("%d", &n);
  rep(i,0,n)
  {
    scanf("%s %s", com, word);
    if (com[0] == 'i') {
      insert(word);
    } else {
      if (find(word)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 17428
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

bool solve() {
  string S, T;
  cin >> S;
  cin >> T;
  int n = S.size();

  map<char, char> mp1, mp2;
  REP(i, n) {
    auto it = mp1.find(S[i]);
    if (it != mp1.end()) {
      if (it->second != T[i]) {
        DEBUG("BAD1", i, T[i], S[i], it->second);
        return false;
      }
    } else {
      mp1[S[i]] = T[i];
    }

    auto it2 = mp2.find(T[i]);
    if (it2 != mp2.end()) {
      if (it2->second != S[i]) {
        DEBUG("BAD2", i, T[i], S[i], it2->second);
        return false;
      }
    } else {
      mp2[T[i]] = S[i];
    }
  }
  return true;
}

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

  cout << (solve() ? "Yes" : "No") << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > P(M);
    if(N%2){
        rep(i, M){
            P[i] = make_pair(i+1, N-i);
        }
    } else {
        rep(i, M) {
            if(N-2*i -1 <= N/2){
                P[i] = make_pair(i+1, N-i-1);
            } else {
                P[i] = make_pair(i+1, N-i);
            }
        }
    }
    rep(i, M) {
        cout << P[i].first << ' ' << P[i].second << endl;
    }
}

Measured memory_bytes: 3896
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

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

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

struct UnionFind {
	vector<int> p, r;
	int gn;
	UnionFind(int N) {
		p.resize(N); r.resize(N);
		fill(begin(p), end(p), -1);
		fill(begin(r), end(r), 1);
		gn = N;
	}
	void merge(int a, int b) {
		int x = group(a), y = group(b);
		if (x == y) return; //same
		gn--;
		if (r[x] < r[y]) p[x] = y;
		else if (r[x] > r[y]) p[y] = x;
		else {p[x] = y; r[x]++;}
	}
	int group(int a) {
		if (p[a] == -1) return a;
		return p[a] = group(p[a]);
	}
	bool same(int a, int b) {
		return group(a) == group(b);
	}
};

int main() {
	int N = in();
	int M = in();
	vint p(N);
	rep(i, N) p[i] = in() - 1;
	vpint xy(M);
	rep(i, M) xy[i] = mp(in() - 1, in() - 1);
	
	UnionFind uf(N);
	rep(i, M) uf.merge(xy[i].first, xy[i].second);
	int ans = 0;
	rep(i, N) if (uf.same(i, p[i])) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
int main() {
     int a, b;
     char op;
     while (true) {
         std::cin >> a >> op >> b;
         if (op == '?') {
             break;
         }
         int result = 0;
         switch (op) {
             case '+':
                 result = a + b;
                 break;
             case '-':
                 result = a - b;
                 break;
             case '*':
                 result = a * b;
                 break;
             case '/':
                 result = a / b;
                 break;
             default:
                 break;
         }
         std::cout << result << std::endl;
     }
     return 0;
}


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

int sum(int x, int y)
{
	return x+y;
}
int sub(int x, int y)
{
	return x-y;
}
int mul(int x, int y)
{
	return x*y;
}

int main(void)
{
	int a, b, sm, sb, ml, gr;
	scanf("%d %d", &a, &b);
	
	sm = sum(a, b);
	sb = sub(a, b);
	ml = mul(a, b);
	
	if(sm > sb && sm > ml) gr = sm;
	else if(sb > sm && sb > ml) gr = sb;
	else if(ml > sm && ml > sb) gr = ml;
	
	printf("%d\n", gr);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll v[55], w[55], m[55];
ll dp[2505];

int main() {
    init();
    ll N,W;
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i] >> m[i];
    
    ll v_max = *max_element(v, v + N);
    if(v_max==0){
        cout << 0 << endl;
        return 0;
    }

    vc<ll> m1(N, v_max - 1), m2(N);
    rep(i, N){
        chmin(m1[i], m[i]);
        m2[i] = m[i] - m1[i];
    }

    // 各荷物をmin(m[i], v_max - 1)個としてdp
    ll WQ = N * v_max;
    fill(dp + 1, dp + WQ + 1, INF);

    vl deq(WQ + 1), deqv(WQ + 1);

    rep(i,N){
        rep(r, v[i]){
            ll s = 0, t = 0;
            rep(j, (WQ - r)/v[i]+1){
                if(dp[j * v[i] + r] != INF){
                    ll val = dp[j * v[i] + r] - j * w[i];
                    while (s < t and deqv[t - 1] >= val) t--;
                    deq[t] = j, deqv[t] = val;
                    t++;
                }
                if(s<t){
                    dp[j * v[i] + r] = deqv[s] + j * w[i];
                    if (deq[s] == j - m1[i]) s++;
                }
            }
        }
    }

    ll ans = 0;
    vl id(N);
    iota(all(id), 0ll), sort(all(id), [&](ll i1, ll i2) { return v[i1] * w[i2] > v[i2] * w[i1]; });

    rep(i, WQ + 1){
        if (dp[i] > W) continue;
        ll rest = W - dp[i], cost = i;
        repa(d, id){
            ll usem = min(max(m2[d], m[d] - dp[i]/w[d]), rest / w[d]);
            // err(i, m2[d], rest / w[d], usem);
            if (usem == 0) continue;
            cost += usem * v[d], rest -= usem * w[d];
        }

        chmax(ans, cost);
    }

    cout << ans << endl;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> cnt(M,0);
    for(int i = 0; i < N; i++){
        int K; cin >> K;
        for(int j = 0; j<K ; j++){
           int A; cin >> A; A--;
           cnt.at(A)++;
        }
        }
    
    int ans = 0;
    for(int i = 0; i<M ; i++){
        if(cnt[i] == N){
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll A, B, C;
    cin >> A >> B >> C;

    ll D = abs(B - A) + abs(C - A); 
    ll E = abs(A - B) + abs(C - B);
    ll F = abs(A - C) + abs(B - C);

    cout << min({D, E, F});

    return 0;
}

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

using namespace std;

int main(){
	
	string str;
	
	int k;
	
	cin >> str >> k;
	
	for(int i = 0; i < str.size(); i++){
		if(str[i] != 'a' && 26 - (str[i] - 'a') <= k){
			k -= 26 - (str[i] - 'a');
			str[i] = 'a';
		}
	}
	
	str[str.size() - 1] = 'a' + (str[str.size() - 1] - 'a' + k) % 26;
	
	cout << str << endl;
	
	return 0;
}



Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if a[i] > b[i]:
        cnt += b[i]
    else:
        cnt += a[i]
        b[i] -= a[i]
        if a[i+1] > b[i]:
            cnt += b[i]
            a[i+1] -= b[i]
        else:
            cnt += a[i+1]
            a[i+1] = 0
print(cnt)

Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  int ans=0;
  rep(i,n) {
    cin>>a[i];
    ans+=a[i];
  }
  sort(rall(a));
  ans-=a[0]/2;
  cout<<ans<<endl;
}

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

#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...)        GET_MACRO(__VA_ARGS__, repn, rep0)(__VA_ARGS__)
#define rep0(i, b)      for(int i = 0; i < (b); ++i)
#define repn(i, a, b)   for(int i = a; i < (b); ++i)
#define trav(a, b)      for(auto& a : (b))
#define all(a)          (a).begin(),(a).end()
#define endl            '\n'
#define M               1000000007
#define tests           int ___;cin>>___;while(___--)

using namespace std;
using ll = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<int, int>;
using vpi = vector<pi>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);

    int n,m; cin >> n >> m;
    vi r(n, -1);

    if (n==1&&!m) {
        cout << "0\n"; return 0;
    }
    rep(i,m) {
        int s,c; cin >> s >> c;s--;
        if (r[s] != -1 && r[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        r[s] = c;
    }

    if (r[0] == 0 && n != 1) {
        cout << -1 << endl;
        return 0;
    }
    cout << (r[0] == -1 ? 1 : r[0]);
    rep(i, n-1) cout << (r[i+1] == -1 ? 0 : r[i+1]);
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		try {
			int lim = Integer.parseInt(in.readLine());

			String[] a = in.readLine().split(" ");
			String[] c = new String[a.length];
			String[] ori = new String[a.length];
				
			for (int i = 0; i < a.length; i++) {
				c[i] = a[i];
				ori[i] = a[i];
			}
			
			for (int i = 0; i < c.length; i++) {
				for (int j = (c.length - 1); j > i; j--) {
					int vala = c[j - 1].charAt(1);
					int valb = c[j].charAt(1);
					
					if (valb < vala) {
						String tmp = c[j];
						c[j] = c[j - 1];
						c[j - 1] = tmp;
					}
				}
			}

			System.out.print(c[0]);
			for (int i = 1; i < c.length; i++) {
				System.out.print(" " + c[i]);
			}
			System.out.println();
			
			boolean flag = true;
			int p = 0;
			for (int j = 1; j < 10; j++) {
				int index = -1;
				while (p < c.length) {
					if (c[p].charAt(1) != (j + '0')) break;

					for (int i = 0; i < ori.length; i++) {
						if (c[p].equals(ori[i])) {
							if (index == -1) {
								index = i;
								break;
							} else if (i < index) {
								System.out.println("Not stable");
								flag = false;
								break;
							}
						}
					}
					p++;
					
					if (flag == false) break;
				}
				if (flag == false) break;
			}
			if (flag) System.out.println("Stable");
			
			for (int i = 0; i < a.length; i++) {
				int mini = i;
				for (int j = i; j < a.length; j++) {
					int vala = a[j].charAt(1);
					int valb = a[mini].charAt(1);
					
					if (vala < valb) {
						mini = j;
					}
				}

				if (i != mini) {
					String tmp = a[i];
					a[i] = a[mini];
					a[mini] = tmp;
				}
			}
			
			System.out.print(a[0]);
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
			System.out.println();

			flag = true;
			p = 0;
			for (int j = 1; j < 10; j++) {
				int index = -1;
				while (p < a.length) {
					if (a[p].charAt(1) != (j + '0')) break;

					for (int i = 0; i < ori.length; i++) {
						if (a[p].equals(ori[i])) {
							if (index == -1) {
								index = i;
								break;
							} else if (i < index) {
								System.out.println("Not stable");
								flag = false;
								break;
							}
						}
					}
					p++;
					
					if (flag == false) break;
				}
				if (flag == false) break;
			}
			if (flag) System.out.println("Stable");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24344
N,M = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(M)]

right = N
left = 0

for i in e:
    if left < i[0]:
        left = i[0]
    if right > i[1]:
        right = i[1]
if right >= left:
    print(right - left + 1)
else:
    print("0")

Measured memory_bytes: 21156
import itertools
n=int(input())
A=tuple(map(int,input().split()))
B=tuple(map(int,input().split()))
arr=[i+1 for i in range(n)]
arr2=list(itertools.permutations(arr))
for num,i in enumerate(arr2):
    if A==i:
        a=num+1
    if B==i:
        b=num+1
print(abs(a-b))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long K;
    cin >> K;
    string S,result;
    cin >> S;

    if (S.length() <= K) {
        cout << S << endl;
    } else {
        result = S.substr(0,K);
        result += "...";
        cout << result << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[1100];
    int i=1,n=0,m=0;
    while(cin>>a[i])
    {
    if(a[i]=='C')
    n=i;
    if(a[i]=='F')
    m=i;
    i++;
    }
    if(n<=m&&n!=0&&m!=0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> list(n);
    for (int i = 0; i < n; i++) {
        cin >> list[i];
    }
    for (int i = n - 1; i >= 0; i -= 2) {
        cout << (i != n - 1 ? " " : "") << list[i];
    }
    for (int i = (n % 2 == 0 ? 0 : 1); i < n; i += 2) {
        cout << " " << list[i];
    }
    cout << endl;
}


Measured memory_bytes: 2944
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))

    na.sort()

    r = 0
    k = int((na[2] - na[0]) / 2)
    r += k
    na[0] += k * 2
    k = int((na[2] - na[1]) / 2)
    r += k
    na[1] += k * 2

    if na[0] < na[2] and na[1] < na[2]:
        r += 1
    elif na[0] < na[2]:
        r += 2
    elif na[1] < na[2]:
        r += 2


    print(r)


if __name__ == '__main__':
    main()



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

int main(){
    string S;
    cin >> S;
    if(S.size() == 2) cout << S;
    else{
        char tmp = S[0];
        S[0] = S[2];
        S[2] = tmp;
        cout << S;
    }
    return 0;
}


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

int main(){
	int h,n;
	cin >> h >> n;
	int a[n];
	int sum = 0;
	for(int i = 0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	if(h - sum > 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

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

const int N = 200000;
const long long P = 998244353LL;

inline long long fastpow(long long x, long long n){
    long long res = 1; x %= P;
    while (n){ if (n & 1) res = res * x % P; x = x * x % P; n >>= 1; }
    return res;
}

long long fact[N+5];
void find_fact(long long n){
    fact[0] = 1LL;
    for (long long i = 1; i <= n; ++i){
        fact[i] = fact[i-1] * i % P;
    }
}

int main(){
    find_fact(N);
    long long n, m, k;
    cin >> n >> m >> k;
    long long ans = 0;
    for (long long i = 0; i <= k; ++i){
        ans = (ans + fact[n-1] * fastpow(fact[n-1-i], P-2) % P * fastpow(fact[i], P-2) % P
                * m % P * fastpow(m-1, n-i-1) % P) % P;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5200
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    string s;
    cin >> s;
    REP(i, 19) {
        if(s[i]== ',') cout << ' ';
        else cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())

li = []
for i in range(n):
    lis = list(map(int, input().split()))
    lis.pop(0)
    li += lis

ans = 0
for i in range(m):
    if n == li.count(i+1):
        ans += 1

print(ans)


Measured memory_bytes: 3060
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
 * 考虑边界，推导结论，子问题递归求解

  如果 S <= p[1] 或者 S >= p[n] ，显然所有人投票都是一个方向，不妨假设 p[1] < S < p[n] 。

  考虑处在最边上的 1 号点和 n 号点，如果 a[1] >= a[n] ，那么一定先到 1 ，否则先到 n 。归
纳证明，如果 n = 2 显然成立，对于 n >= 3 ，若 S >= a[n - 1] 显然成立，否则 S < a[n - 1] ，
此时考虑 1 和 n - 1 ，如果先到 n - 1 就会回到 S >= a[n - 1] 的情况。

  不妨假设 a[1] >= a[n] ，那么到 n 的时间就一定是到 1 的时间加上 1 到 n 的距离，那么 n 想
要最小化到达 n 的时间其实就是等价于最小化到达 1 的时间，可以赋值 a[1] = a[1] + a[n] 并赋
值 n = n - 1 转换为子问题，递归求解，可以求出每个点的到达时间。

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

const int maxn = 1000005;
int p[maxn];
ll a[maxn];
ll t[maxn];

void solve (int l, int r, int S) {
	if (S <= p[l]) {
		for (int i = l; i <= r; i ++)
			t[i] = p[i] - S;
		return;
	}
	if (S >= p[r]) {
		for (int i = l; i <= r; i ++)
			t[i] = S - p[i];
		return;
	}
	if (a[l] >= a[r]) {
		a[l] += a[r];
		solve(l, r - 1, S);
		t[r] = t[l] + p[r] - p[l];
	} else {
		a[r] += a[l];
		solve(l + 1, r, S);
		t[l] = t[r] + p[r] - p[l];
	}
}

int main () {
	int n = read, S = read;
	for (int i = 1; i <= n; i ++) read(p[i], a[i]);
	solve(1, n, S);
	ll ans = 0;
	for (int i = 1; i <= n; i ++) ans = std::max(ans, t[i]);
	printf("%lld\n", ans);
}


Measured memory_bytes: 9600
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
import bisect
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
    n,k=ints()
    a=ints()
    passed=[]
    flg=0
    p=0
    while flg==0:
        if a[p] == 'passed':
            flg=1
            s=passed.index(p)
            break
        else:
            passed.append(p)
            pp=p
            p=a[pp]-1
            a[pp]='passed'
    l=len(passed)
    if k<l:
        print(passed[k]+1)
    else:
        print(passed[(k-s)%(l-s)+s]+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 96204
l, r = gets.chomp.split.map(&:to_i)
ans = 2019
l.upto((r - 1 <= l + 2018) ? (r - 1) : (l + 2018)) do |i|
  (i+1).upto((r <= i + 2019) ? r : (i + 2019)) do |j|
    re = (i * j) % 2019
    ans = re if re < ans
  end
end
puts ans

Measured memory_bytes: 1788
x = list(map(int,input().split()))
a = x[0]
b = x[1]
k = x[2]
while k > 0:
    if a % 2 != 0:
        a -= 1
    b = b + a//2
    a = a // 2
    k -= 1
    if k <= 0:
        break
    if b % 2 != 0:
        b -= 1
    a = a + b//2
    b = b // 2
    k -= 1
print(a,b)

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

using namespace std;

bool isPowerOf5(int b) {
	b = abs(b);
	for(int i=0; i*i*i*i*i<=b; i++)
		if(i*i*i*i*i == b) return true;
	return false;
}

int fifthRoot(int b) {
	int sign = b < 0 ? -1 : 1;
	b = abs(b);
	for(int i=0; i*i*i*i*i<=b; i++) {
		if(i*i*i*i*i == b) {
			return sign*i;
		}
	}
	return 0;
}

int main() {
	long long x; cin>>x;
	bool found = 0;

	for(long long a=-1000; a<=1000 && !found; a++) {
		for(long long b=-1000; b<=1000 && !found; b++) {
			if(a*a*a*a*a - b*b*b*b*b == x) {
				cout<<a<<" "<<b<<endl;
				found = 1;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1e5+7;

bool done[MAXN];
int dist[MAXN];

void dfs(int now, vector<vector<pair<int,int>>> &edge) {
	for(int i=0;i<edge[now].size();i++) {
		int next = edge[now][i].first;
		int len = edge[now][i].second;
		if(done[next]) {
			if(dist[next] != dist[now] + len) {
				cout << "No" << endl;
				exit(0);
			}
		} else {
			done[next] = true;
			dist[next] = dist[now] + len;
			dfs(next, edge);
		}
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<pair<int,int>>> edge(N+1);
	for(int i=0;i<M;i++) {
		int l, r, d;
		cin >> l >> r >> d;
		edge[l].push_back({r, d});
		edge[r].push_back({l, -d});
	}
	for(int i=1;i<=N;i++) {
		if(!done[i]) {
			done[i] = true;
			dfs(i, edge);
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 12032
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

bool isPrimes[1000000];

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int res = 0;
		for (int i = 0; i <= n; ++i)
			isPrimes[i] = true;
		isPrimes[0] = isPrimes[1] = false;
		for (int i = 2; i <= n; ++i)
		{
			if (isPrimes[i])
			{
				for (int j = i*2; j <= n; j += i)
					isPrimes[j] = false;
				++res;
			}
		}
		printf("%d\n", res);
	}

	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;



void solve(long long N){
    int ans=1000-(N%1000);
    if(ans==1000)ans=0;
    cout<<ans<<endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3660
module A = Array
module C = Char
module I = Int64
module L = List
module Q = Queue

let pf = Printf.printf
let sf = Scanf.scanf
let ssf = Scanf.sscanf

let read_int () = sf "%d " (fun x -> x)
let read_float () = sf "%f " (fun x -> x)
let read_array read n = A.init n (fun _ -> read ())
let err s = raise (Failure s)

let _ =
    let n = read_int () in
    let len = read_int () in
    let a = read_array read_int n in
    let (max_len, pos) = A.init (n - 1) (fun x -> x) |>
                             A.map (fun i -> (a.(i) + a.(i+1), i)) |>
                             A.fold_left max (0, 0) in
    if max_len >= len
    then A.append (A.init pos (fun x -> x+1)) (A.init (n-pos-1) (fun x -> n-x-1)) |>
         (print_endline "Possible";
          A.iter (fun x -> string_of_int x |> print_endline) )
    else print_endline "Impossible"


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

int main(){
  int h,w;
  cin>>h >>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      string s;
      cin>>s;
      if(s=="snuke"){
        cout<<(char)('A'+j)<<i+1<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int X = intArray[0];
            int Y = intArray[1];
            if(X * 2 > Y || X * 4 < Y || Y % 2 != 0)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
            

        }
    }
}



//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28100
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(C >= A){
    if(B >= C){
      cout << "Yes" << endl;
    }
    else  {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define read        freopen("in.txt", "r", stdin)
#define write       freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define PB push_back
#define F first
#define S second
#define MP make_pair

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

const int M = 998244353 ;
const int MAX = (2e5) + 10;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll x;
int n, ara[MAX];

int main() {
    ios::sync_with_stdio(false);
    //read;
    //write;

    cin >> n; n *= 2;
    FOR(i,0,n-1) {
        cin >> ara[i];
    }
    sort(ara, ara + n);
    for(int i = 0; i < n; i += 2) {
        x += ara[i];
    }
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); }
  ModInt operator-() const { return ModInt() - *this; }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v);
    return ModInt(u);
  }
  ModInt pow(int64_t e) const {
    ModInt ret(1);
    for (ModInt b = *this; e; e >>= 1, b *= b)
      if (e & 1) ret *= b;
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int modulo() { return mod; }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  using Mint = ModInt<int(1e9 + 7)>;
  int N;
  cin >> N;
  Mint ans = 1;
  int x[3] = {0, 0, 0};
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    debug(A);
    int cnt = 0;
    for (int j = 0; j < 3; j++) {
      if (x[j] == A) {
        if (!cnt) x[j]++;
        cnt++;
      }
    }
    ans *= cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>

int *s;
int *t;

int linearsearch(int key,int n)//見つかれば1,でなければ0を返す
{
	int i=0;
	while(s[i]!=key){
		i++;
		if(i==n) return 0;
	}
	return 1;
}

int main(void)
{
	int i;
	int n,q;
	int cnt=0;
	scanf("%d",&n);
	s=(int*)malloc(sizeof(int)*n);//s読み込み
	for(i=0;i<n;i++) scanf("%d",&s[i]);
	scanf("%d",&q);
	t=(int*)malloc(sizeof(int)*q);
	for(i=0;i<q;i++) scanf("%d",&t[i]);//t読み込み
	for(i=0;i<q;i++){
		cnt+=linearsearch(t[i],n);//cntに返り値を加算
	}
	printf("%d\n",cnt);
	free(s);
	free(t);
}


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

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

    char prev = securityCode.at(0);
    bool isBad = false;
    for (int i = 1; i < 4; ++i)
    {
        char comparing = securityCode.at(i);
        if (comparing == prev)
        {
            isBad = true;
            break;
        }
        else
        {
            prev = comparing;
        }
    }

    cout << (isBad ? "Bad" : "Good") << endl;
}

Measured memory_bytes: 256
#ABC 084 D - 2017 Like Number
from itertools import accumulate

def isPrime(x):
    if x == 2: flag = True
    else:
        flag = True
        if x % 2 == 0:
            flag = False
        
        i = 3
        while i**2 <= x and flag == True:
            if x % i == 0:
                flag = False
            else:
                i += 2
    return True if flag == True else False

q = int(input())
arr = []
max_v = 0
for i in range(q):
    l,r = map(int, input().split())
    arr.append((l,r))
    max_v = max(max_v, r)

res_arr = [0]*(max_v+1)
for i in range(3,max_v+1,2):
    v1, v2 = i, (i+1)//2
    if isPrime(v1) == True and isPrime(v2) == True:
        res_arr[i] = 1

cumsum = list(accumulate(res_arr))
#print(res_arr)
#print(cumsum)
for i in range(q):
    l,r = arr[i][0], arr[i][1]
    print(cumsum[r] - cumsum[l-1])

Measured memory_bytes: 86664
M=int(input())
N=str(M)
s=int(N[-1])
if s==2 or s==4 or s==5 or s==7 or s==9:
  print("hon")
if s==0 or s==1 or s==6 or s==8:
  print("pon")
if s==3:
  print("bon")

Measured memory_bytes: 9128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define int long long
const int M = 2005;
const int N = 30005;
const int o = 15000;

bool ab[N],ac[N],bc[N];

bool match(char x,char y) {
    return x=='?' || y=='?' || x==y;
}
string a,b,c;
int la,lb,lc;
signed main() {   
    cin>>a>>b>>c;
    la=a.length();
    lb=b.length();
    lc=c.length();
    for(int i=0;i<la;i++) 
        for(int j=0;j<lb;j++)
           if(!match(a[i],b[j])) 
              ab[i-j+o]=1;
    for(int i=0;i<la;i++) 
        for(int j=0;j<lc;j++)
           if(!match(a[i],c[j])) 
              ac[i-j+o]=1;
    for(int i=0;i<lb;i++) 
        for(int j=0;j<lc;j++)
           if(!match(b[i],c[j])) 
              bc[i-j+o]=1;
    int ans=0x3f3f3f3f;
    for(int i=-2*M;i<=2*M;i++) 
        for(int j=-2*M;j<=2*M;j++) 
        {
        if(!ab[i+o] && !ac[j+o] &&! bc[j-i+o]) {
            ans=min(ans, max(la,max(lb+i,lc+j))-min((int)0,min(i,j)));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

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

const int INF = 1e9 + 7;

string s[55];
int a[55];


signed main()
{
	IO_OP;
	
	int n, ans = -1;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> s[i] >> a[i];
	string t;
	cin >> t;
	for(int i=0;i<n;i++) {
		if(ans >= 0)
			ans += a[i];
		if(s[i] == t)
			ans = 0;
	}
	cout << ans << endl;
}





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


int main()
{
    int n,i;
    cin>>n;
    long int ans=0;
    long int arr[n-1];
    for(i=0;i<n-1;i++){
        cin>>arr[i];
    }
    ans=arr[0]+arr[n-2];
    for(i=1;i<n-1;i++){
        ans+=min(arr[i],arr[i-1]);
    }

    cout<<ans<<endl;


}


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

vector<pair<int,int> >bara,koma;

bool comp1(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.second<b.second);
}

bool comp2(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return (a.first>b.first);
}

int main()
{
    int t;
    cin>>t;
    int open,close;
    while(t--)
    {
        string s;
        cin>>s;
        open=0;
        close=0;
        for(char c : s)
        {
            if(c=='(')
            {
                open++;
            }
            else
            {
                if(open)
                    open--;
                else
                    close++;
            }
        }
        if(open>=close)
            bara.push_back({open,close});
        else
            koma.push_back({open,close});
    }

    sort(bara.begin(), bara.end(),comp1);
    sort(koma.begin(),koma.end(),comp2);

    bara.insert(bara.end(),koma.begin(),koma.end());

    int ans=0;
    for(auto x : bara)
    {
        ans-=x.second;
        if(ans<0)
        {
            cout<<"No"<<endl;
            return 0;
        }
        ans+=x.first;
    }
    if(ans==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 18896
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
long long n,a[100000],b[100000],cnt=0;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    for(int i=n-1;i>=0;i--){
        if((a[i]+cnt)%b[i])cnt+=b[i]-((a[i]+cnt)%b[i]);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s="";
  string ans="";
  cin>>s;
  for(int i=0;i<10;i++){
    char temp=s[i];
    if(temp=='0')ans.push_back('0');
    if(temp=='1')ans.push_back('1');
    if(temp=='B'&&!ans.empty())ans.pop_back();
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    for ( ;; ) {
      int a = ni();
      int l = ni();

      if ( ( a | l ) == 0 ) {
        break;
      }

      String as = Integer.toString( a );
      HashMap<String, Integer> map = new HashMap<String, Integer>();

      int idx = 0;
      for ( ; !map.containsKey( as ); ++idx ) {
        map.put( as, idx );

        int len = as.length();
        for ( int i = len; i < l; ++i ) {
          as += "0";
        }

        ArrayList<Character> min = new ArrayList<Character>();
        for ( char c : as.toCharArray() ) {
          min.add( c );
        }
        ArrayList<Character> max = new ArrayList<Character>( min );
        Collections.sort( min );
        Collections.sort( max, Collections.reverseOrder() );

        String mins = "";
        for ( Character c : min ) {
          mins += c;
        }
        String maxs = "";
        for ( Character c : max ) {
          maxs += c;
        }

        // debug(idx, maxs, mins);

        as = Integer.toString( Integer.parseInt( maxs )
            - Integer.parseInt( mins ) );
      }

      System.out.println( map.get( as ) + " " + as + " "
          + ( idx - map.get( as ) ) );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

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

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 23992
import bisect
n, q = map(int, input().split())
s = str(input())
A, C = [], []
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        A.append(i)
        C.append(i + 1)
for i in range(q):
    l, r = map(int, input().split())
    print(bisect.bisect_right(C, r - 1) - bisect.bisect_left(A, l - 1))

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

int main()
{
    std::ios_base::sync_with_stdio(0);
    int64_t n;
    std::cin >> n;
    int64_t m = n-1;
    for (int64_t i=2;i*i<=n;++i)
    {
        if (n%i == 0) m = std::min(m, i+n/i-2);
    }
    std::cout << m;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int main() {
    int n, q;
    cin >> n;
    vector<ll> s(n);
    rep(i,n) cin >> s[i];
    cin >> q;
    vector<ll> t(q);
    rep(i,n) cin >> t[i];

    int cnt = 0;
    rep(i, q) {
        rep(j, n) {
            if(t[i] == s[j]) {
                ++cnt;
                break;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3168
N = int(input())
S = input()
MOD = 10**9 + 7

dp = [[0]*(N+1) for i in range(N+1)]
P = [0]*(N+1); Q = [0]*(N+1)
P[1] = 1
for i in range(N-2, 0, -1):
    r = 0
    if S[i-1] == '<':
        if S[i] == '<':
            for k in range(1, N-i+1):
                Q[k] = r = (r + P[k-1]) % MOD
        else:
            for k in range(1, N-i+1):
                Q[k] = r = (r + P[N-i-k]) % MOD
    else:
        if S[i] == '<':
            for k in range(1, N-i+1):
                Q[k] = r = (r + P[N-i-k]) % MOD
        else:
            for k in range(1, N-i+1):
                Q[k] = r = (r + P[k-1]) % MOD
    P, Q = Q, P
print(sum(P) % MOD)

Measured memory_bytes: 113756
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace AOJ2
{
    class Program
    {

        static void Main(string[] args)
        {
            List<string> resultList = new List<string>();

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                int[] set = input.Split(' ').Select(s => int.Parse(s)).ToArray();
                int child = set[0];
                int mother = set[1];

                string str = "";

                child %= mother;
                
               
                Dictionary<int, int> childDict = new Dictionary<int, int>();
                childDict[child] = 0;
                int loop = -1;

                child *= 10;
                for (int i = 1; i <= 80; i++)
                {

                    str += (child / mother).ToString();
                    if (child % mother == 0)
                    {
                        break;
                    }
                    child %= mother;
                    
                    if (childDict.ContainsKey(child))
                    {
                        loop = childDict[child];
                        break;
                    }
                    else
                    {
                        childDict[child] = i;
                    }

                    child *= 10;
                }

                resultList.Add(str);
                if (loop != -1)
                {
                    string cursol = "";
                    for (int j = 0; j < str.Length; j++)
                    {
                        if (j < loop)
                        {
                            cursol += " ";
                        }
                        else
                        {
                            cursol += "^";
                        }
                    }
                        resultList.Add(cursol);
                }
            }

            foreach (string s in resultList)
            {
                Console.WriteLine(s);
            }

        }
    }
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;
int n;

// void init(){
//   vector<int> tmp(100010, INT_MAX);
//   tmp[0] = 1;
//   // tmp[1] = 1;
//   dp = tmp;
// }

int main(){
  cin >> n;
  vector<int> dp(100100, INT_MAX);
  dp[0] = 0;

  for (int i = 1; i < 100100; i++) {
    int power = 1;
    while(power <= i) {
      dp[i] = min(dp[i], dp[i-power]+1);
      power *= 6;
    }

    power = 1;
    while(power <= i) {
      dp[i] = min(dp[i], dp[i-power]+1);
      power *= 9;
    }
  }

  cout << dp[n] << endl;
}


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

using namespace std;

const int maxn = 1e2 + 10;
int a[maxn];

int main()
{
	int n;
	string s,t;
	cin >> n >> s >> t;
	bool c = true;
	
	for (int i = 0; i < n; i ++)
	{
		for (int j = 0; j <= n - 1 - i; j ++)
		{
			if (t[j] != s[n - 1 - (n - 1 - i) + j])
			{
				c = false;
				break;
			}
		}
		if (c)
		{
			cout << i + n;
			return 0;
		}
		c = true;
	}
	if (c)
	{
		cout << 2 * n;
	}
	return 0 ;
}


Measured memory_bytes: 256