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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    ll n, i, q;
    cin >> n >> q;
    queue<pair<int, string>> que;
    rep(i, n) {
        string name;
        int    time;
        cin >> name >> time;
        que.push(mp(time, name));
    }
    ll gen = 0;
    while (que.size()) {
        auto it = que.front();
        que.pop();
        if (it.first > q) {
            it.first -= q;
            gen += q;
            que.push(it);
        } else {
            gen += it.first;
            cout << it.second << " " << gen << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 6216
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
#define INF 1e9
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int E[100][100],d[100],n,ans,goal;
bool is_visited[100] = {false};

void dijkstra(int s){
    
    d[s] = 0;
    while(1){
        int v = -1;
        
        rep(u,0,n){
            if(!is_visited[u] && (v == -1 || d[u] < d[v])) v = u;
        }
        
        if(v == -1) break;
        
        is_visited[v] = true;
        
        rep(u,0,n){
            d[u] = min(d[u],d[v]+E[v][u]);
        }
    }
    
    return;
}

int main(){
    int a,b,c,k;
    
    
    while(1){
        ans = INF;
        cin >> n >> k;
        if(n+k == 0) break;
        
        rep(i,0,n){
            rep(j,0,n){
                E[i][j] = INF;
            }
            is_visited[i] = false;
            d[i] = INF;
        }
        
        rep(i,0,k){
            ans = INF;
            cin >> a;
            if(a){
                cin >> a >> b >> c;
                a--;b--;
                E[a][b] = min(c,E[a][b]);
                E[b][a] = min(c,E[b][a]);
            }
            else{
                cin >> a >> b;
                a--;b--;
                goal = b;
                
                dijkstra(a);
                
                if(d[goal] == INF)cout << -1 << endl;
                else cout << d[goal] << endl;
                
                
                rep(i,0,n){
                    is_visited[i] = false;
                    d[i] = INF;
                }
                
                
            }
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <climits>

using namespace std;

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

    if (x + 1 <= b - a)
        cout << "dangerous";
    else if (a >= b)
        cout << "delicious";
    else
        cout << "safe";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
/*int main(){
    ll c=0,d=0,k=0,n,m,h,w,p,q;
    const int max = 100000;
    string s,s1,s2;
    ll num[max+1];

    cin >> n >> k;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        num[a] += b;
    }

    for (int ans=1; ans<=max; ans++){
        if(k <= num[ans]){
            cout << ans << endl;
            break;
        }
        k -= num[ans];
    }

    return 0;
}*/
const int AMAX = 100000;
ll cnt[AMAX + 1];

int main(void) {
ll N;
ll K;
cin >> N >> K;

for (int i = 0; i < N; ++i) {
 int A, B;
 cin >> A >> B;
 cnt[A] += B;
 }

for (int ans = 1; ans <= AMAX; ++ans){
 if (K <= cnt[ans]) {
 cout << ans << endl;
 break;
}
 K -= cnt[ans];
 }

 return 0;
 }

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
        int i;
        int an,bn;
        char a[11],b[11],c[11];

        scanf("%s%s%s",&a,&b,&c);

        an=0;
        bn=0;
        for(i=0;a[i]!='\0';i++)
                an++;
        for(i=0;b[i]!='\0';i++)
                bn++;

        if(a[an-1]==b[0])
                if(b[bn-1]==c[0]){
                        printf("YES\n");
                        return 0;
                }

        printf("NO\n");

        return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def WF(mat, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j])
    return mat


N, M, L = map(int, input().split())
roads = [[float('inf')]*N for _ in [0]*N]
kyuyu = [[float('inf')]*N for _ in [0]*N]
for _ in range(M):
    a, b, c = map(int, input().split())
    roads[a-1][b-1] = c
    roads[b-1][a-1] = c

roads = WF(roads, N)
for i in range(N):
    for j in range(i+1, N):
        if roads[i][j] <= L:
            kyuyu[i][j] = 1
            kyuyu[j][i] = 1
kyuyu = WF(kyuyu, N)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    dist = kyuyu[s][t]
    if dist == float('inf'):
        print(-1)
    else:
        print(dist-1)


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

int main(){
  int n;cin >> n;
  vector<int> p(n);for(int i=0;i<n;++i)cin >> p[i];
  vector<int> P = p;
  sort(P.begin(),P.end());
  int j = 0;
  for(int i=0;i<n;i++){
    if(p[i] != P[i])j += 1;
  }
  if(j <= 2){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import math

n = int(input())
a = math.ceil(n**0.5)
ans = 10000000000000000000000000

for i in range(1,a+1):
    if n % i == 0:
        r = int(n/i)
        ans = min( ans , max(len(str(i)) , len(str(r))))
        
print(ans)

Measured memory_bytes: 39024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int k, x;
    cin >> k >> x;
    if (500 * k >= x) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int mod=1e9+7;
int n;
int fn(int p){
	int j=1;
	for (int i=0;i<n;i++)
		j=(j*p)%mod;
	re j;
}
void sol(){
	cin>>n;
	cout<<(fn(10)-2*fn(9)+fn(8)+10*mod)%mod;
}
signed main()
{
	sol();
	re 0;
}


Measured memory_bytes: 3632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    vector<pair<Int, Int>> A(N);

    rep(i, 0, N) {
        cin >> A[i].first;
        A[i].second = i;
    }

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    rep(i, 0, N) {
        if (A[0].second == i) {
            cout << A[1].first << "\n";
        }
        else
            cout << A[0].first << "\n";
    }
}


Measured memory_bytes: 4736
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, r;
        cin >> n >> r;
        if(n == 0)
            return 0;

        int sy = INT_MAX;
        int sx = INT_MAX;
        int gy = INT_MIN;
        int gx = INT_MIN;
        vector<int> x1(n), y1(n), x2(n), y2(n);
        for(int i=0; i<n; ++i){
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            sy = min(sy, y1[i]);
            sx = min(sx, x1[i]);
            gy = max(gy, y2[i]);
            gx = max(gx, x2[i]);
        }

        int ret1 = 0;
        int ret2 = 0;
        for(int a=0; a<11; ++a){
            for(int b=0; b<11; ++b){
                int yMin = a * 1000 - 1;
                int yMax = (a+1) * 1000 - 1;
                int xMin = b * 1000 - 1;
                int xMax = (b+1) * 1000 - 1;

                if(gy < yMin || gx < xMin || sy > yMax || sx > yMax)
                    continue;

                vector<vector<int> > s(1001, vector<int>(1001, 0));
                for(int i=0; i<n; ++i){
                    if(y2[i] < yMin || x2[i] < xMin || y1[i] > yMax || x1[i] > xMax)
                        continue;

                    ++ s[max(yMin, y1[i])-yMin][max(xMin, x1[i])-xMin];
                    if(x2[i] <= xMax)
                        -- s[max(yMin, y1[i])-yMin][x2[i]-xMin];
                    if(y2[i] <= yMax)
                        -- s[y2[i]-yMin][max(xMin, x1[i])-xMin];
                    if(y2[i] <= yMax && x2[i] <= xMax)
                        ++ s[y2[i]-yMin][x2[i]-xMin];
                }

                for(int i=0; i<1001; ++i){
                    for(int j=0; j<1000; ++j){
                        s[i][j+1] += s[i][j];
                    }
                }
                for(int i=0; i<1001; ++i){
                    for(int j=0; j<1000; ++j){
                        s[j+1][i] += s[j][i];
                    }
                }

                for(int i=0; i<1000; ++i){
                    for(int j=0; j<1000; ++j){
                        if(s[i][j] > 0)
                            ++ ret1;
                        if((s[i][j] > 0) ^ (s[i+1][j] > 0))
                            ++ ret2;
                        if((s[i][j] > 0) ^ (s[i][j+1] > 0))
                            ++ ret2;
                    }
                }
            }
        }

        cout << ret1 << endl;
        if(r == 2)
            cout << ret2 << endl;
    }
}

Measured memory_bytes: 5292
import math , sys

X , N = list(map(int, input().split()))

A = list(map(int, input().split()))

F = math.inf
ans = math.inf
B  =[]
for i in range( -2 , 102):
    if i not in A:
        B.append(i)
#print(A,B)
for i in range(len(B)):
    d = abs( X - B[i] )
    #print(B[i] , d)
    if d < F:
        F = d
        ans = B[i]
    elif d==F:
        if B[i] < ans:
            ans = B[i]
print(ans)

Measured memory_bytes: 62084
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    if(n % k) cout << 1;
    else cout << 0;

    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  1234
//
//  Created by Moha Jain on 14/04/20.
//  Copyright © 2020 Moha Jain. All rights reserved.
//
 
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<math.h>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
 
using namespace std;
 
 
 
int main()
{
    string s,t;
    cin>>s>>t;
    int count =0;
    for(int i=0;i<s.length();i=i+1)if(s[i]!=t[i])count++;
    cout<<count<<endl;
}


 


Measured memory_bytes: 3916
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

r1 = 'U' * dy + 'R' * dx
r2 = 'D' * dy + 'L' * dx
r3 = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1)+'D'
r4 = 'R'+'D'*(dy+1)+'L'*(dx+1)+'U'
ans = r1 + r2 + r3 + r4
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int nums[5];
  int res = 0;
  for(int i=0; i<5; ++i){
    cin >> nums[i];
    if(nums[i] == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<pair<T, T> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string num;
	cin >> num;

	for (int i = 0; i < num.size(); ++i) {
		if (num[i] - '0' == 7) {
			cout << "Yes\n";
			return 0;
		}
	}

	cout << "No\n";

	return 0;

}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N % 2 == 0) {
        if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
    } else {
        cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=[int(input()) for i in range(n)]
if sum(s)%10!=0:
  print(sum(s))
else:
  s.sort()
  flag=0
  for i in range(n):
    if s[i]%10!=0:
      print(sum(s)-s[i])
      flag=1
      break
  if flag==0:
    print(0)

Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,ans=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N;i++){
    map<char,pair<bool,bool>> mp;
    for(int j=0;j<N;j++){
      if(i<=j){
        mp[S[j]].first=true;
      }else{
        mp[S[j]].second=true;
      }
    }
    int cnt=0;
    for(auto e:mp){
      cnt+=e.second.first && e.second.second;
    }
    ans=max(cnt,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int DMAX = 365;

bool dp[DMAX + 1][3][3][7][7][7][7];
bool can_move[DMAX + 1][3][3];

int main(){
  int D;
  const int N = 4;
  
  memset(dp, false, sizeof(dp));
  
  while(cin >> D && D){

    REP(i, D){
      int F[4][4];
      REP(r, N)REP(c, N) cin >> F[r][c];
      
      REP(r, N - 1)REP(c, N - 1){
        can_move[i][r][c] = true;
        REP(dr, 2)REP(dc, 2) can_move[i][r][c] &= F[r+dr][c+dc] == 0;
      }
    }
    
    memset(dp, false, sizeof(dp));
    dp[0][1][1][0][0][0][0] = true;
    
    REP(i, D)REP(r, N - 1)REP(c, N - 1){
      if(i == 1 && (r != 1 || c != 1)) continue;
      
      int dr[9] = {0, 0, 0, 0, 0, 1, 2, -1, -2};
      int dc[9] = {0, 1, 2, -1, -2, 0, 0, 0, 0};
      
      REP(s, 7)REP(t, 7)REP(u, 7)REP(v, 7)if(dp[i][r][c][s][t][u][v]){
        REP(p, 9){
          int r2 = r + dr[p];
          int c2 = c + dc[p];
          
          if(0 <= r2 && r2 < N-1 && 0 <= c2 && c2 < N-1 && can_move[i][r2][c2]){
            int s2 = (r2 == 0 && c2 == 0) ? 0 : s + 1;
            int t2 = (r2 == 0 && c2 == N - 2) ? 0 : t + 1;
            int u2 = (r2 == N - 2 && c2 == 0) ? 0 : u + 1;
            int v2 = (r2 == N - 2 && c2 == N - 2) ? 0 : v + 1;
            if(s2 < 7 && t2 < 7 && u2 < 7 && v2 < 7){
              dp[i+1][r2][c2][s2][t2][u2][v2] = true;
            }
          }
        }
      }
    }
    
    bool ok = false;
    REP(r, 3)REP(c, 3)REP(s, 7)REP(t, 7)REP(u, 7)REP(v, 7){
      if(D > 1){
        ok |= dp[D][r][c][s][t][u][v];
      }else{
        ok |= dp[D][1][1][s][t][u][v];
      }
    }
    cout << ok << endl;
  }
  return 0;
}

Measured memory_bytes: 8892
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
ll comb(ll, ll);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }

    int ans = 0;
    rep(i, n) { ans ^= a[i]; }

    if (ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

ll comb(ll a, ll b) {
    if (a < b) {
        return 0;
    }

    ll v[a + 1][a + 1] = {};

    rep(i, a + 1) {
        v[i][0] = 1;
        v[i][i] = 1;
    }

    repd(k, 2, a + 1) {
        repd(j, 1, k) { v[k][j] = v[k - 1][j - 1] + v[k - 1][j]; }
    }

    return v[a][b];
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


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

const int maxn = 307;

inline void read(int &x) {
    int w = 1; x = 0; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-' ) w = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x*=w;
}

inline void print(int x) {
	if (x < 0) putchar('-'), x = -x;
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int n;
char s[maxn][maxn];

int main() {
	int n; scanf("%d", &n);
	
	static char st[maxn];
	for (int i = 1; i <= n; ++i) {
		scanf("%s", st);
		for (int j = 1; j <= n; ++j) {
			s[i][j] = st[j - 1];
		}
	}
	
	int ans = 0;
	
	for (int k = 0; k < n; ++k) {
		bool flag = true;
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				if (s[i][j] != s[(j + k - 1) % n + 1][(i - k + n - 1) % n + 1]) {
					flag = false;
					break;
				}
			}
			if (!flag) break;
		}
		if (flag) ans += n;
	}
	
	print(ans);
	
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

Int calc(vector<P> &vec)
{
    int n = vec.size();
    Int ans = 0;
    sort(vec.rbegin(), vec.rend());
    set<int> not_used;
    for (int i = 0; i <= n; i++) {
        not_used.insert(i);
    }
    for (auto p : vec) {
        Int score = p.first;
        Int k = p.second;
        auto before = *prev(not_used.upper_bound(k));
        if (before == 0)
            continue;
        not_used.erase(before);
        ans += score;
    }
    return ans;
}

void solve()
{
    Int n, k, l, r;
    cin >> n;
    Int base = 0;
    vector<P> lefts, rights;
    for (int i = 0; i < n; i++) {
        cin >> k >> l >> r;
        base += min(l, r);
        if (l > r)
            lefts.push_back(P(l - r, k));
        if (r > l)
            rights.push_back(P(r - l, n - k));
    }
    cout << base + calc(lefts) + calc(rights) << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 11136
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;

ll mod(ll x)
{
    return ((x%M +M)%M);
}
ll add(ll a,ll b)
{
    return mod(mod(a)+mod(b));
}
ll minu(ll a,ll b)
{
    return mod(mod(a)-mod(b));
}
ll mul(ll a,ll b)
{
    return mod(mod(a)*mod(b));
}

ll modPow(ll a,ll b)
{
    if(b==0)
    {
        return 1LL;
    }
    if(b==1)
    {
        return a%M;
    }
    ll res=1;
    while(b)
    {
        if(b%2==1)
        {
            res=mul(res,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return res;
}

ll fnc(ll n)
{
    if(n<=1)
    {
        return 0;
    }
    if(n==2)
    {
        return 2;
    }
    ll ret = minu(add(modPow(10,n),modPow(8,n)),add(modPow(9,n),modPow(9,n)));
    return ret;
}
int main()
{
    ll i,j,a,b,c,d,n,m,t;
    cin>>n;
    cout<<fnc(n)<<endl;
    return 0;
}


Measured memory_bytes: 3536
#include <stdio.h>
struct data{
    int par;
    int left;
    int right;
};
typedef struct data node;
void postParse(int);
node tree[100000];
int max,tmp;
int main(){
    int n,i,j,cur,cur_n,m=0,par,dep=0;
    for(i=0;i<100000;i++){
        tree[i].par=-1;
        tree[i].left=-1;
        tree[i].right=-1;
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&cur);
        scanf("%d %d",&tree[cur].left,&tree[cur].right);
        tree[tree[cur].left].par=cur;
        tree[tree[cur].right].par=cur;
    }
    /*
    for(i=0;i<n;i++){
        printf("%d   %d %d %d\n",i,tree[i].par,tree[i].sib,tree[i].son);
    }
    */

    for(i=0;i<n;i++){
        printf("node %d: parent = %d, ",i,tree[i].par);
        cur=i;
        if(tree[cur].par==-1){
            printf("sibling = -1, ");
        }
        else{
            if(tree[tree[cur].par].left==cur){
                printf("sibling = %d, ",tree[tree[cur].par].right);
            }
            else{
                printf("sibling = %d, ",tree[tree[cur].par].left);
            }    
        }
        if(tree[cur].left!=-1) m++;
        if(tree[cur].right!=-1) m++;
        printf("degree = %d, ",m);
        while(1){
            if(tree[cur].par==-1) break;
            dep++;
            cur=tree[cur].par;
        }
        cur=i;
        printf("depth = %d, ",dep);
        dep=0;
        m=0;
        tmp=-1;
        max=-1;
        postParse(cur);
        printf("height = %d, ",max);
        if(tree[cur].par==-1){
            printf("root\n");
        }
        else if(tree[cur].right==-1 && tree[cur].left==-1){
            printf("leaf\n");
        }
        else{
            printf("internal node\n");
        }
    }
    return 0;
}

void postParse(int u){
    tmp++;
    if(u==-1){
        tmp--;
        if(max<tmp)max=tmp;
        return;
    }
    postParse(tree[u].left);
    postParse(tree[u].right);
    tmp--;
}


Measured memory_bytes: 3032
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

class UnionFindTree {
private:
  vector<int> par;
  vector<int> rnk;
  vector<int> siz;

public:
  UnionFindTree(int n) {
    par.assign(n, -1);
    rnk.assign(n, -1);
    siz.assign(n, -1);

    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rnk[i] = 0;
      siz[i] = 1;
    }
  }

  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

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

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (rnk[x] < rnk[y]) {
      par[x] = y;
      siz[y] += siz[x];
    } else {
      par[y] = x;
      siz[x] += siz[y];
      if (rnk[x] == rnk[y])
        ++rnk[x];
    }
  }

  int size(int x) {
    x = find(x);
    return siz[x];
  }
};

void solve(long long N, long long K, long long L, std::vector<long long> p,
           std::vector<long long> q, std::vector<long long> r,
           std::vector<long long> s) {
  map<ll, vector<ll>> roadConnected;
  {
    UnionFindTree uf(N + 1);
    rep(k, K) { uf.unite(p[k], q[k]); }
    rep(n, N) { roadConnected[uf.find(n + 1)].push_back(n + 1); }
  }

  UnionFindTree trainConnected(N + 1);
  rep(l, L) { trainConnected.unite(r[l], s[l]); }

  vector<ll> ans(N + 1);
  for (auto iter = roadConnected.begin(); iter != roadConnected.end(); iter++) {
    vector<ll> sameRoadConnected = iter->second;
    map<ll, ll> cnts;
    for (auto city : sameRoadConnected) {
      cnts[trainConnected.find(city)]++;
    }

    for (auto city : sameRoadConnected) {
      ans[city] = cnts[trainConnected.find(city)];
    }
  }

  rep(n, N) {
    cout << ans[n + 1];
    if (n != N - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  long long L;
  scanf("%lld", &L);
  std::vector<long long> p(K);
  std::vector<long long> q(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &p[i]);
    scanf("%lld", &q[i]);
  }
  std::vector<long long> r(L);
  std::vector<long long> s(L);
  for (int i = 0; i < L; i++) {
    scanf("%lld", &r[i]);
    scanf("%lld", &s[i]);
  }
  solve(N, K, L, std::move(p), std::move(q), std::move(r), std::move(s));
  return 0;
}


Measured memory_bytes: 27568
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

H,W = I()
maze = [list(s()) for _ in range(H)]
ans = [[0]*(W-1) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            cnt = 0
            Flag1 = 0
            Flag2 = 0
            Flag3 = 0
            Flag4 = 0
            if i != 0:
                if maze[i-1][j] == '#':
                    cnt += 1
                Flag1 = 1
            if i != H-1:
                if maze[i+1][j] == '#':
                    cnt += 1
                Flag2 = 1
            if j != 0:
                if maze[i][j-1] == '#':
                    cnt += 1
                Flag3 = 1
            if j != W-1:
                if maze[i][j+1] == '#':
                    cnt += 1
                Flag4 = 1
            if Flag1 == Flag3 == 1:
                if maze[i-1][j-1] == '#':
                    cnt += 1
            if Flag1 == Flag4 == 1:
                if maze[i-1][j+1] == '#':
                    cnt += 1
            if Flag2 == Flag3 == 1:
                if maze[i+1][j-1] == '#':
                    cnt += 1
            if Flag2 == Flag4 == 1:
                if maze[i+1][j+1] == '#':
                    cnt += 1
            maze[i][j] = str(cnt)
for m in maze:
    print(''.join(m))

Measured memory_bytes: 10192
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

int main(){
    int a; cin >> a;
    cout << (a + a*a + a*a*a) << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1LL<<60
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;



int main() {
	
	int n, m;
	cin >> n >> m;

	vector<int>a(m), b(m);
	set <int> check;
	for (int i = 0; i < m; i++)cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++) {
		if (a[i] == 1)check.insert(b[i]);
	}
	for (int i = 0; i < m; i++) {
		if (check.count(a[i]) != 0&&b[i]==n) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
string s;
cin>>s;
if(s.length()<4)
{
	ol("No");
	return 0;
}
if(s.substr(0,4)=="YAKI")ol("Yes");
else
ol("No");
return 0;
}



Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
a = h.times.map{ gets.split.map(&:to_i) }

rows = []
[*0...h].product([*0...w]) do |x1, y1|
  next if a[x1][y1].even? || (x1 == h - 1 && y1 == w - 1)
  x2, y2 = (y1 == w - 1) ? [x1 + 1, y1] : [x1, y1 + 1]
  a[x1][y1] -= 1
  a[x2][y2] += 1
  rows << [x1, y1, x2, y2]
end

puts rows.size
rows.each do |row|
  puts row.map(&:succ).join(' ')
end

Measured memory_bytes: 29180
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N;
  cin >> N;
  ll answer = numeric_limits<ll>::max();
  for (ll a = 1; a * a <= N; a++) {
    if (N % a == 0) {
      const ll b = N / a;
      answer = min(a + b - 2, answer);
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int		long long
#define mp		make_pair
#define pb		push_back
#define pf		push_front
#define db(x)	{ cerr << #x << " = " << x << endl; }
#define sz(x)	((int)(x).size())
#define w(x)		int x; cin>>x; while(x--)
#define rep(i,a,n)		for (int i=a;i<n;i++)
#define per(i,a,n)		for (int i=n-1;i>=a;i--)

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int k; cin>>k;
	string s; cin>>s;
	int n = sz(s);
	if(n<=k){cout<<s;}
	else{
		s={s,0,k};
		s=s+"...";
		cout<<s;
	}
	return 0;
}


Measured memory_bytes: 3644
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
		int[] check = new int[26];
		int x=0;
		for(int i=0;i<s.length();i++) {
			int num= s.charAt(i)-'a';
			//System.out.println(num);
			check[num]+=1;
			if(check[num]==2) {
				x=1;
				break;
			}
		}
		System.out.println((x==1)? "no":"yes");
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s.at(i);
	vector<vector<ll>> dp(h + 1, vector<ll>(w + 1));
	dp[0][0] = 1;
	rep(i,h){
		rep(j,w){
			if(i + 1 < h && s[i + 1][j] == '.'){
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
			}
			if(j + 1 < w && s[i][j + 1] == '.'){
				dp[i][j + 1] += dp[i][j];
				dp[i][j + 1] %= mod;
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 9216
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
K=II()
A,B=MI()

for i in range(A,B+1):
    if i%K==0:
        print('OK')
        exit()
print('NG')

Measured memory_bytes: 10464
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){

	while(1){
		int n;
		cin >> n;

		if(n == 0) break;

		int s[n];
		double m = 0;
		for(int i = 0; i < n; i++){
			cin >> s[i];
			m += s[i];
		}
		m /= n;

		double a = 0;
		for(int i = 0; i < n; i++){
			a += pow(s[i] - m, 2);
		}
		a = sqrt(a / n);

		cout << fixed << a << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

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


	public void exec() throws Exception{
		final int N = sc.nextInt();
		final String S = sc.next();
		final String T = sc.next();
		for(int i=0;i<N;i++) {
			out.print(S.charAt(i));
			out.print(T.charAt(i));
		}
		out.println();

	}
}


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

using namespace std;

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    vector<string> vs;
    string str;
    getline(cin, str);
    while (n--) {
      getline(cin, str);
      //cout << str << endl;
      int k = 0;
      rep (i, str.size()) {
	if (str[i] == ' ') {
	  vs.push_back(str.substr(k, i - k));
	  k = i + 1;
	}
      }
      vs.push_back(str.substr(k));
    }
    //rep (i, vs.size()) cout << vs[i] << endl;
    char top;
    cin >> top;
    //cout << top << endl;
    vector<string> v;
    rep (i, vs.size()) {
      if (vs[i][0] == top) v.push_back(vs[i]);
    }
    sort(v.begin(), v.end());
    //rep (i, v.size()) cout << v[i] << endl;
    vector<pair<int, string> > res;
    rep (i, v.size()) {
      if (i > 0 && v[i - 1] == v[i]) {
	--res[res.size() - 1].first;
      } else {
	res.push_back(make_pair(-1, v[i]));
      }
    }
    sort(res.begin(), res.end());
    if (res.size() == 0u) {
      cout << "NA" << endl;
      continue;
    }
    rep (i, min(int(res.size()), 5)) {
      if (i > 0) cout << " ";
      cout << res[i].second;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
/*
ID: victorn2
LANG: C++
TASK: fact4
*/

// 178

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define trie bakayerou_konayarou
#define pb push_back
#define INF 0x3f3f3f3f
#define ll long long
#define int long long
#define endl '\n'
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, ll> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;
const ll MOD = 9901;
const int LINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 200005;
#define fin cin
#define fout cout

int a, b, c, n, m, k;
string s, t;

int32_t main() {
	cin >> a;
	cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
vector<vector<pair<int,ll>>> G;
vector<ll> point;
vector<bool> visited;
vector<int> flag;
void dfs(int x, int p, int d){
    if(!visited[x]){
        point[x] = d;
        visited[x] = true;
    }
    else{
        if(flag[x] != -1){
            flag[x] = ((point[x] == d) ? 1:-1);
        }
        return;
    }
    for(auto nx:G[x]){
        if(nx.first == p)continue;
        dfs(nx.first, x, d + nx.second);
    }
}
int main() {
    int N,M;
    cin>>N>>M;
    G.resize(N);
    point.assign(N,0);
    visited.assign(N,false);
    flag.assign(N, 0);
    rep(i,M){
        int L,R,D;
        cin>>L>>R>>D;
        L--;R--;
        G[L].push_back({R,D});
        G[R].push_back({L,-D});
    }
    rep(i,N){
        if(!visited[i]){
            dfs(i,-1,0);
        }
    }
    string ans = "Yes";
    rep(i,N){
        if(flag[i] == -1){
            ans = "No";
        }
    }
    cout<< ans <<endl;
}

Measured memory_bytes: 16896
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n = 0, m = 0;
		try (Scanner sc = new Scanner(System.in)) {
			while (true) {
				m = sc.nextInt();
				n = sc.nextInt();
				if(m == 0 && n == 0) {
					break;
				}
				if(m > n) {
					m = m ^ n;
            		n = m ^ n;
            		m = m ^ n;
				}
				System.out.println(String.format("%d %d",m, n));
			}
		}
	}
}



Measured memory_bytes: 41528
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val shops = (0 until n).map {
        val (a, b) = readLine()!!.split(' ').map { it.toLong() }
         Pair(a, b)
    }.sortedBy { it.first }

    var ans = 0L
    var x = m.toLong()

    for (i in (0 until n)) {
        val c = Math.min(shops[i].second, x)
        ans += shops[i].first * c
        x -= c
        if (x == 0L) {
            break
        }
    }

    println(ans)
}


Measured memory_bytes: 86660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007

const int Nmax=200010;

int main() {
	int N;
	cin >> N;
	if(N <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	
	
	return 0;
}

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

typedef long long ll;

bool val(vector<ll>d){
	sort(d.begin(),d.end());
	for(ll i=1;i<d.size();++i){
		ll diff = abs(d[i-1] - d[i]);
		if(diff >= 2){
			return false;
		}
	}
	return true;
}

int main(){
	ll n;
	cin >> n;
	vector<ll> d(n);
	vector<ll> vm(n,0);
	for(int i=0;i<n;++i){
		cin >> d[i];
//		cout << "-" <<endl;
		vm[d[i]]++;
	}
//	cout << "--" <<endl;

	if(d[0] != 0){
		cout << 0 <<endl;
		return 0;
	}
//	cout << "--" <<endl;
	if(val(d) == false || vm[0] != 1){
		cout << 0 <<endl;
		return 0;		
	}
//	cout << "--" <<endl;

	ll res = 1;
	for(ll i=2;i<vm.size();++i){
		if(vm[i] == 0) break;
		for(int j=1;j<=vm[i];++j){
			res *= vm[i-1];
			res %= 998244353;
		}
	}
	cout << res <<endl;
	

	return 0;
}


Measured memory_bytes: 2560