akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>

typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for(ll i=init;i<(n);i++)

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

    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }

    bool c[26] = {false};
    int n = s.size();
    repi(i, n, 0) {
        c[s[i] - 'a'] = true;
    }
    if (n == 26) {
        for (int i = n - 1; i >= 0; i--) {
            bool flag = false;
            repi(j, 26, s[i] - 'a') {
                if (!c[j]) {
                    if (i + 1 != n) {
                        s.erase(i);
                    }
                    s.push_back('a' + j);
                    flag = true;
                    break;
                }
            }
            if (flag)break;
            c[s[i] - 'a'] = false;
            s.erase(i);
        }
    } else {
        for (int i = n - 1; i >= 0; i--) {
            bool flag = false;
            repi(j, 26, 0) {
                if (!c[j]) {
                    s.push_back('a' + j);
                    flag = true;
                    break;
                }
            }
            if (flag)break;
        }
    }

    cout << s << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll D[3][3];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>D[0][0]>>D[0][1]>>D[1][1];
	ll t=D[1][1]*3;
	D[0][2]=t-D[0][0]-D[0][1];
	D[2][0]=t-D[1][1]-D[0][2];
	D[2][1]=t-D[1][1]-D[0][1];
	D[2][2]=t-D[1][1]-D[0][0];
	D[1][0]=t-D[0][0]-D[2][0];
	D[1][2]=t-D[0][2]-D[2][2];
	
	
	FOR(y,3) _P("%lld %lld %lld\n",D[y][0],D[y][1],D[y][2]);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    string s; cin >> s;
    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)

const int MOD = (int)1e9 + 7;
const int INF = 1 << 30;
const ll INFF = 1LL << 62;

inline int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}

int N;
vector<int> A, B;

const int bucketSize = 317;

signed main() {

  cin >> N;

  A.resize(N);
  REP(i, N) cin >> A[i];

  B.resize(N / bucketSize + 10);
  {
    int g = 0, piv = 0;
    REP(i, N) {
      if ((i - 1) % bucketSize == 0) {
        B[piv++] = g;
        g = 0;
      } else {
        g = gcd(g, A[i]);
      }
    }
  }

  function<int(int,int)> query = [&](int l, int r) {
    int ret = 0;
    for (int x = l; x < r;) {
      int bi = x / bucketSize;
      if (l <= bi * bucketSize && (bi + 1) * bucketSize <= r) {
        // バケット
        ret = gcd(ret, B[bi]);
        x += bucketSize;
      } else {
        // 余った部分
        ret = gcd(ret, A[x]);
        ++x;
      }
    }
    return ret;
  };

  int res = 0;
  REP(i, N) res = max(res, gcd(query(0, i), query(i + 1, N)));
  cout << res << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
int main(){
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  FOR(i,0,N)cin >> S[i];
  sort(S.begin(),S.end());
  for(auto x:S)cout << x;
  cout << endl;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

#include <queue>
#include <tuple>
using P = tuple<int, int, int>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    REP(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
    }
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    const ll inf = 1LL << 60;
    auto cost = make_v(n, 3, inf);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, 0, s);
    while (pq.size()) {
        int c, v, m;
        tie(c, m, v) = pq.top();
        pq.pop();
        if (cost[v][m] < c) continue;
        cost[v][m] = c;
        REP(i, 0, G[v].size()) {
            int nxt = G[v][i];
            int nm = (m + 1) % 3;
            if (cost[nxt][nm] > c + 1) {
                cost[nxt][nm] = c + 1;
                pq.emplace(c + 1, nm, nxt);
            }
        }
    }

    cout << (cost[t][0] == inf ? -1 : cost[t][0] / 3) << endl;

    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

struct Edge {
    int u, v, c;
    Edge(int u = 0, int v = 0, int c = 0) : u(u), v(v), c(c) {}
};

Edge a[2010];
int n, m;
ll d[1010];

void fordBellman() {
    FOR(i,1,n) d[i] = 1e18;
    d[1] = 0;
    FOR(i,1,n)
        FOR(j,1,m) {
            int u = a[j].u;
            int v = a[j].v;
            int c = a[j].c;
            if (d[u] != 1e18) d[v] = min(d[v], d[u] + c);
        }
}

void fordBellman2() {
    FOR(i,1,n)
        FOR(j,1,m) {
            int u = a[j].u;
            int v = a[j].v;
            int c = a[j].c;
            if (d[u] != 1e18) d[v] = min(d[v], d[u] + c);
        }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        cin >> a[i].u >> a[i].v >> a[i].c;
        a[i].c = -a[i].c;
    }
    fordBellman();
    ll p = d[n];
    fordBellman2();
    ll q = d[n];
    if (p != q) cout << "inf";
    else cout << -p;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b, c, sum;
  cin >> a >> b>> c;
  if((b+c)>=a)sum = c+b-a;
    else sum = 0;
  cout << sum << endl;
}


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

int a;
std::string b[4] ;
int main()
{
	b[0] = "ABC";
	b[1] = "ABD";
	std::cin >> a;

	if(a < 1000)
	{
		std::cout << b[0]  << std::endl;
	} else{
		std::cout << b[1]  << std::endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
const int mo=998244353;
int fac[N],inv[N],n,m,ans;
int C(int x,int y){
	return 1ll*fac[x]*inv[y]%mo*inv[x-y]%mo;
}
int main(){
	fac[0]=inv[0]=inv[1]=1;
	for (int i=2;i<N;i++)
		inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	for (int i=1;i<N;i++)
		fac[i]=1ll*fac[i-1]*i%mo,
		inv[i]=1ll*inv[i-1]*inv[i]%mo;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n&&i<=m;i++)
		ans=(ans+1ll*C(i*2,i)*C(n+m-i*2,n-i))%mo;
	ans=1ll*ans*inv[n+m]%mo*fac[n]%mo*fac[m]%mo*(mo+1)/2%mo;
	printf("%d",(ans+max(n,m))%mo);
} 

Measured memory_bytes: 8192
N, M, K = map(int, input().split())
P = int(1e9+7)
N -= 1
M -= 1

def comb(n, r):
    if n < r or r < 0:
        return 0
    nume = 1
    deno = 1
    for i in range(1, r + 1):
        nume = (nume * (n - i + 1)) % P
        deno = (deno * i) % P
    deno_inv = pow(deno, P-2, P)
    return (nume*deno_inv)%P

ans = 0

def sum_man_dist_ur(u, r):
    ret = 0
    u, r = min(u, r), max(u, r)
    if u == 0:
        ret =  r * (r + 1) // 2
    else:
        ret += (u * (u + 1) * (u - 1)) // 3
        ret += (u+1)*(r-u+1)*(r+u)//2
        ret += u * (u + 1) * (u + 3 * r + 2) // 6
    return ret%P

def sum_man_dist(x, y):
    ret = 0
    ret += sum_man_dist_ur(N - x, M - y)
    ret = (ret + sum_man_dist_ur(N - x, y)) % P
    ret = (ret + sum_man_dist_ur(x, M - y)) % P
    ret = (ret + sum_man_dist_ur(x, y)) % P
    ret -= (N-x)*(N-x+1)//2
    ret -= (x)*(x+1)//2
    ret -= (M-y)*(M-y+1)//2
    ret -= (y) * (y + 1) // 2
    return ret%P

ans = 0
c = comb((N+1)*(M+1)-2, K-2)
for x in range(N + 1):
    for y in range(M + 1):
        ans = (ans + c * sum_man_dist(x, y)) % P
print(ans*pow(2, P-2, P)%P)


Measured memory_bytes: 74652
import sys
n,m = map(int,input().split())
py = []
d = dict()

for i in range(m):
    (a,b) = map(int,input().split())
    py.append((a,b))
sort_py = sorted(py)

tmp_p = sort_py[0][0]
cnt = 1
for p,y in sort_py:
    if p == tmp_p:
        d[(p,y)] = cnt
    else:
        tmp_p = p
        cnt = 1
        d[(p,y)] = cnt
    cnt += 1

for i in range(m):
    print('{0}{1}'.format(str(py[i][0]).zfill(6), str(d[py[i]]).zfill(6)))    


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

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();
	int ans = 1e9;
	for (int i = 0; i <= n - m; i++) {
		int res = 0;
		string ss, tt;
		for (int j = i; j < i + m; j++) {
			if (s[j] != t[j - i]) res++;
			tt += t[j - i];
			ss += s[j];
		}
		ans = min(ans, res);
	}
	cout << ans << '\n';
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1


#define Ten5 100000
#define Ten9 1000000000

int main() {

    int n;
    int a[Ten5 + 1];

    Scd(n);
    Rep(i,n){
        Scd(a[i]);
    }

    ll ans1 = 0;
    ll ans2 = 0;
    long long int minus = 0;
    long long int plus = 0;
    Rep(i,n){
        minus += a[i];
        plus += a[i];
        if( i%2 ){
            if( minus <= 0 ){
                ans1 += 1 - minus;
                minus = 1;
            }
            if( plus >= 0 ){
                ans2 += 1 + plus;
                plus = -1;
            }
        }else{
            if( minus >= 0 ){
                ans1 += 1 + minus;
                minus = -1;
            }
            if( plus <= 0 ){
                ans2 += 1 - plus;
                plus = 1;
            }
        }
        //printf ("%llu -- %llu\n", ans1, ans2);
    }

    printf ("%llu\n" , min( ans1, ans2));

    return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int	main()
{
	int	A, B;
	int	i = 0;
	int	follows = 1;
	char	S[13];

	scanf("%d %d\n%s", &A, &B, S);
	while (i < A && follows)
	{
		if ('0' <= S[i] && S[i] <= '9')
			i++;
		else
			follows = 0;
	}
	if (S[i] != '-')
		follows = 0;
	i++;
	while (i < (A + B + 1) && follows)
	{
		if ('0' <= S[i] && S[i] <= '9')
			i++;
		else
			follows = 0;
	}
	if (follows)
		printf("Yes\n");
	else
		printf("No\n");
	return (0);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int x,y;

  while(1){
    scanf("%d%d", &x,&y);
    if(x == 0 && y == 0) break;
    if(x > y){
      printf("%d %d\n", y, x);
    }else{
      printf("%d %d\n", x, y);
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 32);
double EPS = 1e-4;

ll MOD = 1000000007;

int main() {
  ll H, W;
  cin >> H >> W;

  vvi a(H, vi(W));
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }

  vpii v;
  for (ll i = 0; i < H; i++) {
    if (i % 2 == 0) {
      for (ll j = 0; j < W; j++) {
        v.push_back(make_pair(i, j));
      }
    } else {
      for (ll j = W - 1; j >= 0; j--) {
        v.push_back(make_pair(i, j));
      }
    }
  }

  vector<pair<pii, pii>> ans;

  ll cur = 0;
  for (ll i = 0; i < v.size(); i++) {
    auto p = v[i];

    if (a[p.first][p.second] % 2) {
      if (cur) {
        cur = 0;
        a[p.first][p.second] += 1;
      } else {
        cur = 1;
        a[p.first][p.second] -= 1;
      }
    }

    if (cur && i < v.size() - 1) {
      ans.push_back(make_pair(p, make_pair(v[i + 1].first, v[i + 1].second)));
    }
  }
  if (cur) {
    auto p = v.back();
    a[p.first][p.second] += 1;
  }

  cout << ans.size() << endl;

  for (auto p: ans) {
    cout << p.first.first + 1 << ' ' << p.first.second + 1 << ' ' << p.second.first + 1 << ' ' << p.second.second + 1 << endl;
  }
}

Measured memory_bytes: 14316
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 210; 
const ll INF = 1e8;

using namespace std;

ll adj[N][N];

main()
{
    fast;
    int n,m,R,i,j,k;
    cin>>n>>m>>R;
    int r[R];
    for (i=0;i<R;i++)
        cin>>r[i];
    int a,b;
    ll c;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
            adj[i][j]=(i==j)?0:INF;
    }
    for (i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        adj[a][b]=min(adj[a][b],c);
        adj[b][a]=min(adj[b][a],c);
    }
    //Floyd-Warshall Algorithm: O(n^3) - All pairs shortest paths
    //Edges can be negative - DP approach (uses adjacency matrix)
    //dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
    for (k=1;k<=n;k++)
    {
        for (i=1;i<=n;i++)
        {
            for (j=1;j<=n;j++)
                adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
        }
    }
    ll ans=INF,temp;
    sort(r,r+R);
    do{
        temp=0;
        for (i=0;i<R-1;i++)
            temp+=adj[r[i]][r[i+1]];
        ans=min(ans,temp);
    } while (next_permutation(r,r+R));
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
ll dp[2][(1 << 15) + 1][10];
ll h = 0;

int main() {
	dp[0][0][0] = 1;
	for (ll i = 1; i*i <= (1 << 15); i++) {
		h = i % 2;
		rep(j, (1 << 15) + 1)rep(k, 5)dp[h][j][k] = 0;
		rep(j, (1 << 15) + 1) {
			int nxt = j + i*i;
			rep(k, 5) {
				dp[i % 2][j][k] += dp[(i - 1) % 2][j][k];
				if (k != 4 && nxt < ((1 << 15) + 1)) {
					dp[i % 2][nxt][k + 1] += dp[i % 2][j][k];
				}
			}
		}
	}
	while (cin >> n&&n) {
		ll ans = 0;
		rep(i, 5) {
			ans += dp[h][n][i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 8120
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
using namespace std;


int main()
{
    int n;
    cin >> n;
    
    bool flag = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                flag = true;
                break;
            }
        }
    }
    
    if (flag) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
   
    return 0;   
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int A,B,C;

  cin >> A >> B >> C;
  if( A<C && C<B)
    cout << "Yes" << endl;
  else if( A>C && C>B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


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

void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main()
{
	ll();
long long n;
cin>>n;
int i=1;
while(i*2<=n)
{
	i*=2;
}
cout<<i<<endl;
}


Measured memory_bytes: 3636
require 'pp'

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力を文字列の配列で返す
def get_s_list()
  gets.chomp.split(" ")
end

s_list = gets_nsp_list
Q = gets_i

i = s_list.size - 1
is_reversed = false

Q.times do
  i += 1
  t, f, c = get_s_list
  if t == "1"
    is_reversed = !is_reversed
  elsif f == "1"
    if is_reversed
      s_list.push(c)
    else
      s_list.unshift(c)
    end
  elsif f == "2"
    if is_reversed
      s_list.unshift(c)
    else
      s_list.push(c)
    end
  end
end
s_list.reverse! if is_reversed
puts s_list.join

Measured memory_bytes: 29308
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	vector<long long> A( N );
	vector<long long> B( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i] >> B[i];
	}

	reverse( A.begin(), A.end() );
	reverse( B.begin(), B.end() );
	long long ans = 0;
	for( int i = 0; i < N; i++ ) {
		long long m = ((A[i] + ans) % B[i]);
		if( m ) m = B[i] - m;
		ans += m;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4848
N = int(input())
A = [int(x) for x in input().split()]
A_str = [str(a) for a in A]
print(" ".join(A_str))

for i in range(1, N):
    j = i-1
    while A[i] < A[j] and j >=0:
        A[j], A[i] = A[i], A[j]
        j -= 1
        i -= 1
    A_str = [str(a) for a in A]
    print(" ".join(A_str))


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int k; gi(k);
	int ans = 0;
	rep1(a, k) rep1(b, k) {
		int v = __gcd(a, b);
		rep1(c, k) ans += __gcd(v, c);
	}
	print(ans);
}


Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <cctype>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
int toint(char c){
	if('a'<=c&&c<='z') return c-'a';
	else return c-'A'+26;
}
int sz[52];
map<int,int> val[52];
string s;
int ex(int& be){
	if(isdigit(s[be])){
		int num=0;
		while(isdigit(s[be])){
			num*=10;
			num+=s[be]-'0';
			be++;
		}
		return num;
	}
	char c=toint(s[be]);
	be+=2;
	if(isdigit(s[be])){
		int num=0;
		while(isdigit(s[be])){
			num*=10;
			num+=s[be]-'0';
			be++;
		}
		if(sz[c]<=num) return -1;
		if(val[c].count(num)==0) return -1;
		return val[c][num];
	}else{
		int x=ex(be);
		if(x==-1) return -1;
		if(sz[c]<=x) return -1;
		if(val[c].count(x)==0) return -1;
		return val[c][x];
	}
}
int main(){
	while(true){
		rep(i,52) sz[i]=0;
		rep(i,52) val[i].clear();
		int bug=0;
		int tt;
		for(tt=0;;tt++){
			cin>>s;
			if(s[0]=='.') break;
			bool def=true;
			rep(i,s.size()) if(s[i]=='=') def=false;
			if(def){
				int now=2,num=0;
				while(isdigit(s[now])){
					num*=10;
					num+=s[now]-'0';
					now++;
				}
				sz[toint(s[0])]=num;
//				cout<<s[0]<<" "<<num<<endl;
			}else{
				int c=toint(s[0]);
				int be=2;
				int x=ex(be);
				while(s[be]!='=') be++;
				be++;
				int y=ex(be);
				if(x==-1||sz[c]<=x||y==-1){
//					show(x);
//					show(y);
					bug=tt+1;
//					puts("bughere");
					string ss;
					while(true){
						cin>>ss;
						if(ss[0]=='.') break;
					}
					break;
				}
				val[c][x]=y;
			}
		}
		if(tt==0) break;
		cout<<bug<<endl;
	}
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if (n == 1) {
        if (m == 1) cout << 1 << endl;
        else cout << m - 2 << endl;
    } else {
        if (m == 1) cout << n - 2 << endl;
        else cout << (n - 2) * (m - 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
	while(cur != nil && cur->key != key)
	{
		cur = cur->next;
	}
	return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
	if(t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void delete(int key){
	deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32948
#include <cstdio>

int main(){
  int N, A, B; scanf("%d%d%d", &N, &A, &B);

  if(A > B){ puts("0"); return 0; }

  if(N == 1){
    printf("%d\n", (A == B ? 1 : 0));
    return 0;
  }

  printf("%lld\n", 1LL * (B - A) * (N - 2) + 1);
  return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    int t = 0;
    int n = s.length();
    while (t < n - 1 - t) {
        if (s[t] != s[n - 1 - t]) cnt++;
        t++;
    }
    print(cnt);

    return 0;
}


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

int main() {
	// your code goes here
	long long int a,b;
	char x;
	
	cin>>a;
	cin>>x;
	cin>>b;
	
	if(x == '+')
	    cout<<a+b<<"\n";
	else
	    cout<<a-b<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, X, T;
	cin >> N >> X >> T;
	float one = (float)T/(float)X;
	int a= ceil(((float)N*one)/(float)T);
	int ans = T * a;
	cout << ans; 	
}



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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    double T, X; cin >> T >> X;
    cout << T / X << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.nextLine();
        final int[] counter = new int[26];

        for (int i = 0; i < s.length(); i++) {
            counter[s.charAt(i) - 'A']++;
        }

        for(int i = 0;i<counter.length;i++){
            if(counter[i] != 0 && counter[i] != 2){
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }
}


Measured memory_bytes: 22100
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

int N;
vector<PI> tree[100000];
int color[100000];

int dfs(int n){
    REP(i, tree[n].size()){
        if(color[tree[n][i].first] == -1){
            color[tree[n][i].first] = tree[n][i].second%2?(1^color[n]):color[n];
            dfs(tree[n][i].first);
        }
    }
    return 0;
}

int main(void){
    cin >> N;
    REP(i,N) color[i] = -1;
    int u,v,w;
    REP(i,N-1){
        cin >> u >> v >> w;
        tree[u-1].push_back(PI(v-1, w));
        tree[v-1].push_back(PI(u-1, w));
    }
    color[0] = 0;
    dfs(0);
    REP(i,N) cout << color[i] << endl;

    return 0;
}



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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

#define EPS 1e-12

#define DEBUG_PRINT 1
#define idp if (DEBUG_PRINT)
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" << f << endl
#define p7(a, b, c, d, e, f, g) idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" << f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" << f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" << f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" << f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl


typedef pair<li, li> PI;

li a[200100];
li sum[200100];
li n;

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

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

    map<li, li> cnt;
    li res = 0;
    rep(i, n + 1) {
        res += cnt[sum[i]];
        cnt[sum[i]]++;
    }
    cout << res << endl;


    return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            int n = ReadAndParseInt();
            var s = n.ToString();
            string ans = s[0] == s[2] ? "Yes" : "No";
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int minx,miny;
  minx = min(a,b);
  miny = min(c,d);
  cout << minx+miny;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int check(int j){
	if (j==2 || j==4 ||j==3)
	return j;
	else
	return 3;
}
int main(){
	int board[22][22];
	int w,h;
	char t;
	while(1){
		cin >>w >>h;
		if(w==0 && h==0) break;
		for(int i=0;i<=21;i++){
			for(int j = 0;j<=21;j++){
				board[j][i]=4;
			}
		}//initialization
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> t ;
				if(t == '.')board[j][i] = 1;
				else if(t=='#')board[j][i]=2;
				else board[j][i] = 3;
			}
		}// input end
		int cmem = 2000;
		int c  = 0;
		while(cmem-c !=0){
				cmem = c;
			for(int i=1;i<=h;i++){
				for (int j= 1;j<=w;j++){
					if(board[j][i] ==3){
					board[j-1][i] =check(board[j-1][i]);
					board[j+1][i] =check(board[j+1][i]);
					board[j][i-1] =check(board[j][i-1]);
					board[j][i+1] =check(board[j][i+1]);
					}
				}
			}
			c = 0;
			for(int i=1;i<=h;i++){
				for (int j= 1;j<=w;j++){
					if (board[j][i] ==3) c+=1;
				}
			}
	
		}	
	
		cout <<c << endl;	
	}//while loop end
	return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
#define deg_to_rad(deg) (((long double)(deg)/360.0)*2*M_PI)
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;
#define PI 3.14159265358979323846264338327950L
int main() {

    int A, B, H, M;
    cin >> A >> B >> H >> M;

    long double rad = PI * 2 * (
    (long double)H / 12.0 + ((long double)M / 60.0) / 12.0 - (long double)M / 60.0);

    // int hun = H*60+M;

    // long double tansin = (long double)(360*hun/(720));
    // long double tyosin = (long double)(M*6);

    // long double kakudo;
    // if(abs(tansin-tyosin)>180){
    //     kakudo = 360-abs(tansin-tyosin);
    // }else{
    //     kakudo = abs(tansin-tyosin);
    // }

    // kakudo = deg_to_rad(kakudo);

    long double a;

    /* 余弦定理 */
    a = (long double)A * A + B * B - 2 * A * B * (long double)cosl( rad );
    /* 平方根 */
    a = sqrtl( a );

    printf("%20.20Lf\n", a);

    // cout << a;
}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



Measured memory_bytes: 4132
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};

struct UF
{
  vector<int> par; // 親のインデックスを記憶する配列
  vector<int> sz; // サイズを記憶する。
  vector<int> rank;
  // 初期化
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  // 親を求める
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  // xとyの属する集合を併合
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  // xとyが同じ集合ならtrue
  bool same(int x, int y) { return find(x) == find(y); }
  // 素の集合のサイズを求める
  int size(int n){return sz[find(n)];}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vi lang(m+10);
  UF uni(n+10);
  for(int i=0;i<n;i++){
    int k;cin>>k;
    for(int j=0;j<k;j++){
      int num;cin>>num;
      if(i==0)lang[num]=1;
      else{
	if(lang[num]){
	  uni.merge(i+1,lang[num]);
	}else{
	  lang[num]=i+1;
	}
      }
    }    
  }
  bool ans=false;
  for(int i=0;i<=n;i++)
    if(uni.size(i)==n)
      ans=true;
  YES(ans);
  return 0;
}


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

using namespace std;

const int limit = 50;

int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visit[limit];

void dfs(int next)
{
    visit[next] = true;
    for (int i = 0; i < n; i++) {
        if (visit[i] == true) continue;
        if (graph[i][next] == false) continue;
        dfs(i);
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    for (int k = 0; k < m; k++) {
        int i = a[k], j = b[k];

        if (!graph[i][j]) continue;

        for (int i = 0; i < n; i++) visit[i] = false;

        graph[i][j] = graph[j][i] = false;

        dfs(0);

        bool a = false;
        for (int i = 0; i < n; i++) if (visit[i] == false) a = true;
        if (a) ans += 1;

        graph[j][i] = graph[i][j] = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
 
int main() {
  ll x[5];
  rep(i,5){
    cin>>x[i];
  }
  if(x[0]==0){
    cout<<'1'<<endl;
  }
  else if(x[1]==0){
    cout<<'2'<<endl;
  }
  else if(x[2]==0){
    cout<<'3'<<endl;
  }
  else if(x[3]==0){
    cout<<'4'<<endl;
  }
  else if(x[4]==0){
    cout<<'5'<<endl;
  }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using P = pair<int, int>;
#define LARGE 1000000007

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

	int size = x.size();

	if(x[size-1] != 's') {
		cout << x << 's' << endl;
	} else {
		cout << x << 'e' << 's' << endl;
	}

	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	int n;
	cin >> n;
	int s1 = 0, s2 = 0;
	vector<string> S1(n);
	vector<string> S2(n);
	for (int i = 0; i < n; i++) {
		cin >> S1[i] >> S2[i];
		if (S1[i].compare(S2[i]) < 0) {
			s2 += 3;
		}
		else if (S1[i].compare(S2[i]) == 0) {
			s1++;
			s2++;
		}
		else {
			s1 += 3;

		}
	}
		cout << s1 << " " << s2 << endl;
}

Measured memory_bytes: 1328
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var k     = int.Parse(spl[1]);
        var pp = ToIntArray(input.ReadLine(), n);

        long max = 0;
        long total = 0;
        int maxp = 0;

        for(int i=0; i<n; i++) {
            if (i < k-1) {
                total += pp[i];
                //Debug.WriteLine("+" + pp[i]);
                continue;
            }
            total += pp[i];
            //Debug.WriteLine("+" + pp[i]);
            if(i >= k) {
                total -= pp[i - k];
                //Debug.WriteLine("-" + pp[i-k]);
            }
            if(total >= max) {
                max = total;
                maxp = i - k + 1;
            }
        }
        
        //Debug.WriteLine(max);
        //Debug.WriteLine(maxp);
        //
        double ans = 0;
        for(int i=maxp; i<maxp+k; i++) {
            var p = pp[i];
            ans += (double)ctotal(p) / (double)p;
        }
        return ans;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }

    static long ctotal (long n) {
        return (n+1) * n / 2;
    }
}


Measured memory_bytes: 26716
#include<bits/stdc++.h>
using namespace std;
  vector<long>kai(200001);
long ncrmodp(int n,int r,long p){
  long ans = 1;
  long tmp = 1;
  int i;

  ans = kai[n];
  tmp = (kai[r]*kai[n-r])%p;


  for(long bit = 1;bit<=p-2;bit*=2){
    if(bit & p-2){
      ans *= tmp;
      ans %= p;
    }
    tmp = tmp* tmp;
    tmp %= p;
  }
  return ans;
}

int main(){
  long n,k;
  cin >> n >> k;
  long p = 1000000007;
  int i;
  kai[0]=1;
  for(i=1;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=p;
  }
  vector<long>nc(n+1);
  vector<long>nc1(n);
  for(i=0;i<n;i++){
    nc[i]=ncrmodp(n,i,p);
    nc1[i]=ncrmodp(n-1,i,p);
  }
  nc[n]=1;


  if(k>=n)k=n-1;
  long ans = 1;
  for(i=1;i<=k;i++){
    ans += nc[i]*nc1[i];
    ans %= p;
  }
  cout << ans << endl;








}


Measured memory_bytes: 4992
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, X;
    std::cin >> N >> X;

    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    // 前回の回転範囲までを考慮した、個体nについての最小コスト個体の値
    std::vector<int64_t> memo(N, INT64_MAX);

    int64_t ans = INT64_MAX;
    for (int64_t r = 0; r < N; ++r) {

        // r回転まで行う場合の個々の個体の最小要素
        int64_t s = 0;
        for (int64_t i = 0; i < N; ++i) {
            int64_t idx = i < r ? N - (r-i) : i - r;

            memo[i] = std::min(memo[i], A[idx]);
            s += memo[i];
        }

        ans = std::min(ans, s + (r * X));
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256