akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    string s;
    int Q;
    read(s, Q);

    deque<char> que;
    rep(i, s.length()) {
        que.push_back(s[i]);
    }

    int f = 0;
    rep(i, Q) {
        int t; read(t);
        if (t == 1) {
            f = 1 - f;
        } else {
            int k;
            char ch;
            read(k, ch);
            if (k == 1) {
                if (f) que.push_back(ch);
                else que.push_front(ch);
            } else {
                if (f) que.push_front(ch);
                else que.push_back(ch);
            }
        }
    }

    if (f) reverse(all(que));
    for (char ch: que) {
        cout << ch;
    }
    print();

    return 0;
}


Measured memory_bytes: 976
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int a[700][700] = {};
int main() {
	int n, m; cin >> n >> m;
	int used[700] = {};
	vector<int> G[700];
	rep(i, m) {
		int u, v; cin >> u >> v; u--; v--;
		a[u][v] = a[v][u] = 1;
	}
	rep(i, n) {
		rep(j, n) {
			if (i == j)continue;
			if (!a[i][j])G[i].push_back(j);
		}
	}
	queue<P> que; bool f = true;
	rep(i, n) {
		if (used[i])continue;
		queue<int> q;
		int c1 = 0; int c2 = 0;
		q.push(i); used[i] = 1;
		c1++;
		while (!q.empty()) {
			int x = q.front(); q.pop();
			int len = G[x].size();
			rep(j, len) {
				int v = G[x][j];
				if (!used[v]) {
					used[v] = -used[x]; q.push(v);
					if (used[v] == 1)c1++;
					else c2++;
				}
				else {
					if (used[v] == used[x]) {
						f = false; break;
					}
				}
			}
			if (!f)break;
		}
		if (!f)break;
		que.push({ c1,c2 });
	}
	if (!f) {
		cout << -1 << endl; return 0;
	}
	bitset<702> exi; exi[0] = 1;
	int len = que.size();
	rep(i, len) {
		P nex = que.front(); que.pop();
		exi = (exi << nex.first) | (exi << nex.second);
	}
	int out = (int)MOD;
	rep(i, n + 1) {
		if (exi[i]) {
			out = min(out, i*(i - 1) / 2 + (n - i)*(n - i - 1) / 2);
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#define int long long
using namespace std;
signed main(){
    int r=0,b=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0')r++;
        else b++;
    }
    cout<<min(r,b)*2<<endl;
    return 0;
}


















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

#define pb(a) push_back(a)
#define vi vector<int>
#define loop(i, n) for(int i=1;i<=n;i++)
#define loop0(i, n) for(int i=0;i<n;i++)
#define in(i) scanf("%d", &i);
#define out(i) printf("%d", i)

int n;
double a[3001];
double dp[3001][3001];

int main()
{
  in(n);
  double ans=0;
  dp[0][0]=1.0;
  loop(i, n)
  {
    scanf("%le", &a[i]);
    dp[i][0]=dp[i-1][0]*(1-a[i]);
    loop(j, i)
    {
      dp[i][j]+=dp[i-1][j-1]*a[i] +dp[i-1][j]*(1-a[i]);
    }
  }
  for(int i=n/2+1;i<=n;i++)
    ans+=dp[n][i];
  cout<<setprecision(10)<<ans<<"\n";
}


Measured memory_bytes: 49828
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) {
        rep(j, n) {
            rep(h, n) { ans += __gcd(__gcd(i + 1, j + 1), h + 1); }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[100001];
vector<int> g[100001];
ll dfs(int v,int p){
    ll sum=0,mx=0;
    rep(i,g[v].size()){
        if(g[v][i]==p) continue;
        if(g[g[v][i]].size()==1){
            sum+=a[g[v][i]];
            mx=max(a[g[v][i]],mx);
        }
        else{
            ll r=dfs(g[v][i],v);
            if(r==-1) return -1;
            else sum+=r;
            mx=max(mx,r);
        }
    }
    ll t=a[v]*2-sum;
    if(a[v]<mx||t<0||a[v]>sum) return -1;
    return t;
}
int main(){
    int n,ai,bi;
    cin>>n;
    rep(i,n) cin>>a[i];
    rep(i,n-1){
        cin>>ai>>bi;
        --ai,--bi;
        g[ai].pb(bi);g[bi].pb(ai);
    }
    if(n==2){
        if(a[0]==a[1]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
    }
    rep(i,n)if(g[i].size()>1){
        if(dfs(i,-1)==0){
            cout<<"YES"<<endl;
        }
        else cout<<"NO"<<endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 13184
import sys
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
if n==1: print(abs(a[0]-w));sys.exit()

x,y=[-1]*n,[-1]*n
x[n-1]=abs(a[n-1]-w)
y[n-2]=abs(a[n-1]-a[n-2])

for i in range(n-2,-1,-1):
    x[i]=abs(a[i]-a[n-1])
    for j in range(i+1,n-1):
        x[i]=min(x[i],y[j])
    y[i]=abs(a[n-1]-a[i])
    for j in range(i+1,n-1):
        y[i]=max(y[i],x[j])

print(max(x))

Measured memory_bytes: 3188
from operator import itemgetter
n = int(input())
lis =sorted([list(map(int,input().split())) for _ in range(n)], key = itemgetter(1))
t = 0
ans = "Yes"
for i in lis:
    t += i[0]
    if t > i[1]:
        ans = "No"
print(ans)

Measured memory_bytes: 55268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;

int main(void){
  ll A, B, C, D, E;
  I(A);
  I(B);
  I(C);
  I(D);
  I(E);
  if (A == 0) P(1)
  else if (B == 0) P(2)
  else if (C == 0) P(3)
  else if (D == 0) P(4)
  else if (E == 0) P(5)

}


Measured memory_bytes: 3580
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<tuple>
#include<set>
#include<cmath>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
const double PI=3.14159265358979323846; 
using namespace std;

int main(){
  int N;
  cin >> N;
  int ans = N % 10;
  if(ans == 3) cout << "bon" << endl;
  else if (ans == 0 || ans == 1 || ans == 6 || ans == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
}


Measured memory_bytes: 3116
import numpy as np
 
H, W = map(int, input().split())
#mapの入力
mymap = [] 
for i in range(H):
    mymap.append(list(input()))

#探索可能性をブーリアン表記
mymap = (np.array(mymap) == ".")
  
L = np.zeros((H, W), dtype=int) #左側から探索した場合の配列
R = np.zeros((H, W), dtype=int) #右側から探索した場合の配列
U = np.zeros((H, W), dtype=int) #上側から探索した場合の配列
D = np.zeros((H, W), dtype=int) #下側から探索した場合の配列

#列ごとに左から
for j in range(W):
  if j == 0: #左端
    L[:, j] = mymap[:, j] #true = 1, false = 0
  else:
    L[:, j] = (L[:, j - 1] + 1) * mymap[:, j] #trueの場合は1つ左の列の値を加算しながら

#列ごとに右から
for j in range(W - 1, -1, -1): #(引数：開始数，終了数，加算数）
  if j >= W - 1: #右端
    R[:, j] = mymap[:, j]
  else:
    R[:, j] = (R[:, j + 1] + 1) * mymap[:, j] 

#行ごとに上から
for i in range(H):
  if i <= 0: #上端
    U[i, :] = mymap[i, :]
  else:
    U[i, :] = (U[i - 1, :] + 1) * mymap[i, :]

#行ごとに下から
for i in range(H - 1, -1, -1):
  if i >= H - 1: #下端
    D[i, :] = mymap[i, :]
  else:
    D[i, :] = (D[i + 1, :] + 1) * mymap[i, :]

#総和から重複分(=3)の差をとって，最大値を出力
print(np.max(L + R + U + D - 3))



Measured memory_bytes: 239184
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

vll dx = {1, 0, -1, 0};
vll dy = {0, 1, 0, -1};

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

    ll m, d;
    cin >> m >> d;

    ll res = 0;
    REP(i, m){
        ll x = i + 1;
        REP(j, d){
            ll y = j + 1;
            ll d10 = y / 10, d1 = y % 10;
            if(d10 < 2 || d1 < 2) continue;
            if(d10 * d1 == x){
                //cout << x << " " << y << endl;
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
    int n, k;
    cin>>n>>k;
    vector<int> arr(n);
    for(auto &x : arr){
        cin>>x;
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    for(int i = 2; i < n; i++){
        dp[i] = INT_MAX;
        for(int j = 1; j <= k && j <= i; j++){
            dp[i] = min(dp[i],dp[i-j] + abs(arr[i]-arr[i-j]));
            // cout<<j<<" "<<dp[i]<<endl;
        }
        // cout<<i<<" "<<dp[i]<<endl;
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 3984
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

c = Counter(A)
n = len(c)
if ((n == 1 and c[0] > 0)
        or (n == 2 and c[0] == N//3)):
    print('Yes')
elif n == 3:
    x, y, z = c.keys()
    if x ^ y ^ z == 0 and all(n == N // 3 for n in c.values()):
        print('Yes')
    else:
        print('No')
else:
    print('No')


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

int main()
{
    ll n, ans = 0, p = powl(10, 9) + 7;
    cin >> n;
    ll a[300000];
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 1; i < (1LL << 60); i = i << 1)
    {
        ll b = 0, c = 0;
        for (ll j = 0; j < n; j++)
        {
            if ((a[j] & i) == 0)
            {
                b++;
            }
            else
            {
                c++;
            }
        }
        ans = (ans + (b * c) % p * (i%p) % p) % p;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	int N;
	cin>>N;
	
	string s;
	cin>>s;
	
	int K;
	cin>>K;
	
	K--;
	
	for(int i=0;i<N;i++){
		if(s[K]!=s[i]){
			s[i] = '*';
		}
	}
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())

max1 = 0
max2 = 0

arr = []

for i in range(N):
    a = int(input())
    arr.append(a)
    if a >= max1:
        max2 = max1
        max1 = a
    elif a > max2:
        max2 = a

for i in range(N):
    if arr[i] == max1:
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 12532
n, m = map(int, input().split())
s = [[int(i) for i in input().split()] for j in range(m)]
p = [int(i) for i in input().split()]
count = 0
for i in range(1 << n):
    light_bulbs = 0
    for j in range(m):
        on_switches = 0
        for k in range(s[j][0]):
            if (i >> s[j][k + 1] - 1) & 1:
                on_switches += 1
        if on_switches % 2 == p[j]:
            light_bulbs += 1
    if light_bulbs == m:
        count += 1
print(count)

Measured memory_bytes: 3064
import sys
import math
import heapq
import bisect
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

# j - i == S[j] - S[i] # MOD K
# S[i] - i == S[j] - j

N,K=LI()
As=LI()

Cum=[0]*(N+1)
for i in range(N):
    Cum[i+1] = Cum[i] + As[i]

REM2IDX = {}
for i in range(0,N+1):
    rem = (Cum[i] - i) % K
    if not rem in REM2IDX: REM2IDX[rem] = []
    REM2IDX[rem].append(i)

res = 0
for i in range(0,N+1):
    rem = (Cum[i] - i) % K
    cnt = len(REM2IDX[rem])
    l = bisect.bisect_right(REM2IDX[rem], i)
    r = bisect.bisect_right(REM2IDX[rem], i+K-1)
    res += (r-l)

print(res)


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

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> d[i];
  }
  
  int sum = 0;
  for (int i = 0; i < n - 1; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split.map(&:to_i)

count = 0
1.upto(n - 1){|i|
    (n - 1).downto(i){|j|
        if arr[j - 1] > arr[j]
            arr[j - 1], arr[j] = arr[j], arr[j - 1]
            count += 1
        end
    }
}
puts arr.join(" ")
puts count

Measured memory_bytes: 8720
let input = require("fs").readFileSync("/dev/stdin", "utf8")

function main() {
    const [N] = load()
    
    const divisors = new Array(N+1).fill(0)
    for(let i = 1; i <= N; i++) {
        for(let j = 1; j <= N; j++) {
            const val = i * j
            if(val > N) break
            divisors[val]++
        }
    }

    let result = 0
    for(let i = 1; i <= N; i++) {
        result += i * divisors[i]
    }

    return result
}


let inputs = input.split(/[\s\n]/)
console.log(main())


// 入力値を読み込む
function load(rows = 1, cols = 1, type = Number) {
    const length = rows * cols
    let result = inputs.splice(0, length)

    if(type !== String) result = result.map(type)
    if(cols > 1) {
        const arrays = new Array(cols)
        for(let col = 0; col < cols; col++) {
            arrays[col] = new Array()
            for(let row = 0; row < rows; row++) {
                arrays[col].push(result[row * cols + col])
            }
        }
        result = arrays
    }

    return result
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,3){
    if(s.at(i) == '1'){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b)
{
	if (!b){
		return (a);
	}
	return (gcd(b, a % b));
}

int main(void)
{
	int a1, a2, a3;
	int m1, m2, m3;
	int x, y, z;
	long long x_time, y_time, z_time;
	long long lcm, lcm_2;
	
	while (1){
		scanf("%d%d%d%d%d%d", &a1, &m1, &a2, &m2, &a3, &m3);
		if (a1 + m1 + a2 + m2 + a3 + m3 == 0){
			break;
		}
		
		x = 1;
		y = 1;
		z = 1;
		x_time = y_time = z_time = 0;
		do {
			x = (a1 * x) % m1;
			x_time++;
		} while (x != 1);
		
		do {
			y = (a2 * y) % m2;
			y_time++;
		} while (y != 1);
		
		do {
			z = (a3 * z) % m3;
			z_time++;
		} while (z != 1);
		
		if (x_time > y_time){
			lcm = gcd(x_time, y_time);
		}
		else {
			lcm = gcd(y_time, x_time);
		}
		
		lcm = (x_time / lcm) * y_time;
		
		if (lcm > z_time){
			lcm_2 = gcd(lcm, z_time);
		}
		else {
			lcm_2 = gcd(z_time, lcm);
		}
		
		lcm_2 = (lcm / lcm_2) * z_time;
		
		printf("%lld\n", lcm_2);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int player_point[100000];

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    for (int i = 0; i < N; i++) player_point[i] = 0;

    for (int i = 0; i < Q; i++) {
        int a;
        cin >> a;
        player_point[a-1] += 1;
    }

    for (int i = 0; i < N; i++) {
        if (Q - player_point[i] >= K)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, LL> Vec2;
LL h, w, n, m, s, t, ans = 0, a[100000], b[100000], num = 1, sum = 0, dp[3200][3200] = {};
string str;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int aaa;
		cin >> aaa;
		if (a[aaa] == 0)
			m++;
			a[aaa]++;
	}
	cout << m << endl;
	return 0;
}


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

int main(){
  while(1){
    
  char h[7]={};
  int L,min,max,f=0,sum[100000],i;
  cin>>h>>L;
  if(L==0) break;
  for(int i=strlen(h);i<L;i++) h[i]='0';
  sum[0]=atoi(h);
  i=1;
  while(1){
    if(f==1) break;
      sort(h,h+L);
    min=atoi(h);
    reverse(h,h+L);
    max=atoi(h);
    sum[i]=max-min;
    for(int j=0;j<i;j++){
      if(sum[j]==sum[i]){
	cout<<j<<" "<<sum[i]<<" "<<i-j<<endl;
	f=1;
	break;
      }
    }
    sprintf(h,"%d",sum[i]);
       for(int i=strlen(h);i<L;i++) h[i]='0';
     i++;
  }
  }
return 0;
}
    
  

Measured memory_bytes: 1236
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main(){
	map<int,bool> a;
	int N,ans=0;
	cin>>N;
	for(int i=0;i<N;i++){
		int inp;
		cin>>inp;
		if(a[inp]){
			a[inp]=false;
			ans--;
		}else{
			a[inp]=true;
			ans++;
		}
	}
	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

template <typename QvQ> inline QvQ Min(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max(QvQ a,QvQ b){if(a>b) return a;return b;}

#define inf 2147483647
#define dinf 0x3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define ull unsigned long long

#define bl putchar(' ')
#define ed putchar('\n')
#define test cout<<"this:" 

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define int long long
#define MAXM 1000005
#define lim 1000000
#define mod 998244353
int n;
int a[MAXM],vis[MAXM],c[MAXM],ans[MAXM],tot[MAXM];
int x[MAXM],p[MAXM],cnt;
ll in[MAXM];
ll qpow(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod; b>>=1; 
	}
	return ret;
}
ll solve()
{
	x[1]=1;
	for(rei i=2;i<=lim;++i)
	{
		if(!vis[i]) p[++cnt]=i,x[i]=-1;
		for(rei j=1;j<=cnt&&1ll*i*p[j]<=lim;++j)
		{
			vis[i*p[j]]=1;
			if(i%p[j]==0) break;
			else x[i*p[j]]=-x[i];
		}
	}
	for(rei i=1;i<=lim;++i)
	{
		for(rei j=i;j<=lim;j+=i)
		{
			ans[j]=(ans[j]+x[i]*i%mod)%mod;
			tot[i]=(tot[i]+c[j]*j%mod*in[i]%mod)%mod;
		}
	}
	ll ret=0;
	for(rei i=1;i<=lim;++i) ret=ret+1ll*i%mod*ans[i]%mod*tot[i]%mod*tot[i]%mod;
	for(rei i=1;i<=n;++i) ret=(ret-a[i]+mod)%mod;
	return ret*in[2]%mod;
}
signed main()
{
	read(n);
	for(rei i=0;i<=lim;++i) in[i]=qpow(i,mod-2);
	for(rei i=1;i<=n;++i) read(a[i]),++c[a[i]];
	write(solve());
	return 0;
}

Measured memory_bytes: 53504
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint INF = 1e16;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
vector<lint> mi;
vector<lint> other;
struct Node {
  lint a;
  vector<int> nbr;
  bool vst = false;
  void dfs() {
    vst = true;
    if(a < mi[mi.size()-1]) {
      other.push_back(mi[mi.size()-1]);
      mi[mi.size()-1] = a;
    } else {
      other.push_back(a);
    }
    for(int x : nbr) {
      if(!V[x].vst) {
        V[x].dfs();
      }
    }
  };
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  REP(i, N) {
    V.emplace_back();
    cin >> V[i].a;
  }
  REP(i, M) {
    int u, v;
    cin >> u >> v;
    V[u].nbr.push_back(v);
    V[v].nbr.push_back(u);
  }
  REP(i, N) {
    if(!V[i].vst) {
      mi.push_back(INF);
      V[i].dfs();
    }
  }
  if(mi.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  lint ans = 0;
  REP(i, mi.size()) ans += mi[i];
  sort(ALL(other));
  REP(i, mi.size()-2) {
    if(other[i] == INF) {
      cout << "Impossible" << endl;
      return 0;
    }
    ans += other[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 10348
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define For(x) for(int i = 0;i < x;i++)
int main()
{
  char S[20], T[20];
  cin >> S >> T;
  int len = strlen(S);
  For(len)if(S[i] != T[i])return puts("No"), 0;
  puts("Yes");
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

ll N, C;
ll x[112345], v[112345];
ll ma[112345];

ll solve() {
	fill(ma, ma + N + 1, -INFL);
	
	ma[N] = 0;
	for (int i = N - 1; i >= 0; i--) ma[i] = ma[i + 1] + v[i] - (x[i+1] - x[i]);
	for (int i = N - 1; i >= 0; i--) chmax(ma[i], ma[i+1]);
	
	ll res = 0;
	chmax(res, ma[0]);
	
	ll sum = 0; // 栄養の合計
	REP(i, N) {
		sum += v[i];
		ll cur = -x[i] + sum;
		chmax(res, cur);
		
		cur -= x[i];
		cur += ma[i + 1];
		chmax(res, cur);
	}
	return res;
}

int main() {
	cin >> N >> C;
	REP(i, N) scanf("%lld %lld", x + i, v + i);
	x[N] = C;
	
	ll ans = 0;
	chmax(ans, solve());
	
	REP(i, N) x[i] = C - x[i];
	sort(x, x + N + 1);
	reverse(v, v + N);
	
	chmax(ans, solve());
	cout << ans << endl;
	
	return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair

int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
      
        string s;
        cin>>s;
        int n=(int)s.length();
        if(n<26)
        {
			for(char c='a';c<='z';c++)
			{
				if(s.find(c)==string::npos)
				{
					cout<<s<<c<<"\n";
					return 0;
				}
			}
		}
		else
		{
			    for (int i = n - 2; i >= 0; i--) {
          if (s[i] < s[i + 1]) {
        char best = s[i + 1];
        for (int j = i + 1; j < n; j++) {
          if (s[j] > s[i]) {
            best = min(best, s[j]);
          }
        }
        s[i] = best;
        s = s.substr(0, i + 1);
        cout << s << '\n';
        return 0;
      }
    }
    cout << -1 << '\n';
    }
    return 0;
		
			
	    
  }
			
		

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define set multiset
#define null NULL
#define ort (b+s)/2

using namespace std;

typedef long long Lint;
typedef long double db;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<db,db> dd;
typedef pair<int,string> is;

const int maxn = 600020;
const int K = 320;
const int MOd = 1e9 + 7;

int ar[maxn], a;

map<string, int> mp;

void solve2() {
	bool ok = 1;
	int a;
	string s;
	int maxi = 0;
	scanf("%d",&a);
	for(int i=1,j;i<=a;i++) {
		cin >> s;
		mp[s]++;
		umax( maxi, mp[s] );
	}
	vector<string> v;
	for(map<string,int> :: iterator it = mp.begin();it!=mp.end();it++)
		if( it->se == maxi ) v.pb( it->fi );
	sort( all( v ) );
	for(int i=0;i<v.size();i++)
		cout << v[i] << endl;

}

int main(  ) {


    int n = 1;
    //scanf("%d",&n);
    while( n-- ) solve2();

    return 0;
}

Measured memory_bytes: 26868
import java.util.Scanner;

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

	public void solve(Scanner sc) {
		int a1 = Integer.parseInt(sc.next());
		int a2 = Integer.parseInt(sc.next());
		int a3 = Integer.parseInt(sc.next());
		
		int a12 = a1 - a2;
		if(a12 < 0) a12 *= -1;
		
		int a23 = a2 - a3;
		if(a23 < 0) a23 *= -1;
		
		int a31 = a3 - a1;
		if(a31 < 0) a31 *= -1;
		
		int max = Math.max(a12, a23);
		max = Math.max(max,  a31);
		System.out.println(a12 + a23 + a31 - max);
	}
}

Measured memory_bytes: 21844
n = 10005
f = [0]*10005
for i in range(1, int(n**0.5)):
    a = n - i**2
    if a >= 1:
        for j in range(1, int(a**0.5)):
            b = n - i**2 - j**2
            if b >= 1:
                for k in range(1, int(b**0.5)):
                    c = i**2 + j**2 + k**2 + i*j + j*k + k*i
                    if c <= 10001:
                        f[c] += 1

n = int(input())
for i in range(1, n+1):
    print(f[i])

Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
#define int long long
 
#define Sum(y1, x1, y2, x2) (A[y2][x2] - A[y2][x1] - A[y1][x2] + A[y1][x1])
 
int64 Two(int64** A, int Y, int X, int H, int W)
{
  int64 best = 0;
  for(int k = 1; k < H; k++) {
    best = max(best, min(Sum(0 + Y, 0 + X, k + Y, W + X), Sum(k + Y, 0 + X, H + Y, W + X)));
  }
  for(int k = 1; k < W; k++) {
    best = max(best, min(Sum(0 + Y, 0 + X, H + Y, k + X), Sum(0 + Y, k + X, H + Y, W + X)));
  }
  return(best);
}
 
int64 Three(int64** A, int Y, int X, int H, int W)
{
  int64 best = 0;
  
  for(int k = 1; k < H; k++) {
    best = max(best, min(Two(A, 0 + Y, 0 + X, k, W), Sum(k + Y, 0 + X, H + Y, W + X)));
    best = max(best, min(Sum(0 + Y, 0 + X, k + Y, W + X), Two(A, k + Y, 0 + X, H - k, W)));
  }
  
  for(int k = 1; k < W; k++) {
    best = max(best, min(Two(A, 0 + Y, 0 + X, H, k), Sum(0 + Y, k + X, H + Y, W + X)));
    best = max(best, min(Sum(0 + Y, 0 + X, H + Y, k + X), Two(A, 0 + Y, k + X, H, W - k)));
  }
  
  
  return(best);
}
 
 
int64 Four(int64** A, int H, int W)
{
  int64 best = 0;
  
  for(int k = 1; k < H; k++) {
    best = max(best, min(Three(A, 0, 0, k, W), Sum(k, 0, H, W)));
    best = max(best, min(Sum(0, 0, k, W), Three(A, k, 0, H - k, W)));
    best = max(best, min(Two(A, 0, 0, k, W), Two(A, k, 0, H, W)));
    best = max(best, min(Two(A, 0, 0, k, W), Two(A, k, 0, H - k, W)));
  }
  
 
  int64 L[633] = {};
 
  for(int i = 1; i < H; i++) {
    for(int k = i + 1; k < H; k++) {
      
      for(int j = 0; j < W; j++) {
        L[j] = min(Sum(0, 0, k, j), Sum(0, j, i, W));
      }
      for(int j = 1; j < W; j++) {
        L[j] = max(L[j - 1], L[j]);
      }
      for(int j = W - 1; j > 0; j--) {
        best = max(best, min({L[j], Sum(k, 0, H, j), Sum(i, j, H, W)})); 
      }
    }
  }
  
  return(best);
}
 
signed main()
{
  int H, W, N;
  int64* B[632];
  int64* C[632];
  int64* D[632];
  for(int i = 0; i < 632; i++) {
    B[i] = new int[632];
    C[i] = new int[632];
    D[i] = new int[632];
    for(int j = 0; j < 632; j++) {
      B[i][j] = C[i][j] = D[i][j] = 0;
    }
  }
  
  cin >> H >> W >> N;
  int64 ALL = 0;
  for(int i = 1; i <= H; i++) {
    for(int j = 1; j <= W; j++) {
      cin >> B[i][j];
      ALL += B[i][j];
      C[j][i] = B[i][j];
      B[i][j] += B[i][j - 1] + B[i - 1][j] - B[i - 1][j - 1];
      C[j][i] += C[j][i - 1] + C[j - 1][i] - C[j - 1][i - 1];
    }
  }
 
  
  if(N == 1) {
    cout << ALL << endl;
  } else if(N == 2) {
    cout << Two(B, 0, 0, H, W) << endl;
  } else if(N == 3) {
    cout << max(Three(B, 0, 0, H, W), Three(C, 0, 0, W, H)) << endl;
  } else {
    cout << max({Four(B, H, W), Four(C, W, H)}) << endl;
  }
}

Measured memory_bytes: 12512
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
int next_to[210000][26];

int main() {
    int ans=0;
    int N; cin >> N;

    if(N%2){
        ans=N*(N-1)/2-(N-1)/2;
        cout << ans << endl;
        for(int i=1; i<=N; i++){
            for(int j=1; j<i; j++){
                if(i+j==N) continue;
                cout << i << ' ' << j << endl;
            }
        }
    }else{
        ans=N*(N-1)/2-N/2;
        cout << ans << endl;
        for(int i=1; i<=N; i++){
            for(int j=1; j<i; j++){
                if(i+j==N+1) continue;
                cout << i << ' ' << j << endl;
            }
        }
    }
    return 0;
}

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

using namespace std;

int n;

void solve(){
    cin >> n;
    vector<double> p(n);
    for(int i = 0;i < n;i++) cin >> p[i];
    vector<double> dp(n+1,0);
    dp[0] = 1;
    for(int i = 0;i < n;i++){
        for(int j = i;j >= 0;j--){
            dp[j+1] += dp[j]*p[i];
            dp[j] = dp[j]*(1-p[i]);
        }
    }
    double ans = 0;
    for(int i = n/2+1;i <= n;i++) ans += dp[i];
    printf("%.20f",ans);
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll N;
  cin>>N;

  string res;
  while (N!=0) {
    if (N%2!=0) {
      res='1'+res;
      N--;
    } else {
      res='0'+res;
    }
    N/=-2;
  }
  if (res.empty()) res="0";
  cout<<res<<"\n";
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int N, K; cin >> N >> K;
    int ans = 0;
    while (N > 0) {
        if (ans == 0) N -= K;
        else N -= K - 1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Data.Char

a#b = abs$a-b

main = B.interact$B.pack.show.f.V.unfoldr(B.readInt.B.dropWhile isSpace)
f :: V.Vector Int -> Int
f v= q n hv
  where
    n = v V.! 0
    hv = V.slice 1 n v
q n hv = av V.! (n - 1)
  where
    av = V.generate n m
    m 0 = 0
    m 1 = (hv V.! 0) # (hv V.! 1)
    m i = min ((av V.! (i-2)) + ((hv V.! (i-2)) # (hv V.! i))) ((av V.! (i-1)) + ((hv V.! (i-1)) # (hv V.! i)))


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

const int N = 1e5 + 7;
int n , k , h[N] , f[N];

int main()
{
    cin >> n >> k;
    for(int i = 1 ; i <= n; ++i)
    {
        cin >> h[i];
        f[i] = INT_MAX;
    }
    f[1] = 0;
    for(int i = 2 ; i <= n; ++i)
    {
        for(int j = 1 ; j <= k; ++j)
        {
            if(i - j == 0)break;
            f[i] = min(f[i] , f[i-j] + abs(h[i-j] - h[i]));
        }
    }
    cout << f[n];
    return 0;
}


Measured memory_bytes: 4356
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int A = sc.nextInt();

        PriorityQueue<Pair> pq = new PriorityQueue<>((a,b)->a.x-b.x);
        for (int i = 0; i < N; i++) {
            int x = sc.nextInt();
            int h = sc.nextInt();
            pq.offer(new Pair(x, h));
        }

        long totalDamage = 0;
        long ans = 0;
        LinkedList<Pair> q = new LinkedList<>();
        while (!pq.isEmpty()) {
            Pair m = pq.poll();
            int x = m.x;
            long h = m.v;
            while (q.size() > 0 && q.peek().x < x) {
                totalDamage -= q.poll().v;
            }

            if (h >= totalDamage) {
                h -= totalDamage;
                long atackNum = Math.max((h+A-1)/A, 0);
                ans += atackNum;
                totalDamage += atackNum*A;
                q.offer(new Pair(x+2*D, atackNum*A));
            }
        }

        System.out.println(ans);
    }

    private static class Pair {
        private final int x;
        private final long v;
        Pair(int x, long v) {
            this.x = x;
            this.v = v;
        }
    }
}


Measured memory_bytes: 98984
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		if(s.equals(t)) {
			System.out.println("Yes");
			return;
		}
		for(int i = 0; i < s.length() + 1; i++) {
			s = s.charAt(s.length() - 1) + s.substring(0, s.length() - 1);
			if(s.equals(t)) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 21844
/*
参考にしたもの
・蟻本
・drkenさんのライブラリ
https://github.com/drken1215/algorithm/blob/master/DataStructure/union_find_tree_size.cpp
辺のverifyはしていない（は？）
*/

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;


struct UnionFind{
    vector<int> par;
    vector<int> es;
    UnionFind(int N) : par(N,-1),es(N,0) {}
    
    //初期化
    void init(int N){
        par.assign(N,-1);
        es.assign(N,0);
    }

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

    int usize(int x) {return -par[find(x)];}

    int esize(int x) {return es[find(x)];}
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        es[x]++;
        if(x==y) return;

        if(usize(x)<usize(y)) swap(x,y);
        par[x]+=par[y];
        es[x]+=es[y];
        par[y]=x;
    }

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

};

signed main(void){
    /*int N,M;
    cin>>N>>M;
    int A[110000],B[110000];
    for(int i=1;i<=M;i++){
        cin>>A[i]>>B[i];
        A[i]--; B[i]--;
    } 

    ll now=(ll)N*(N-1)/2;
    vector<ll> ans;
    UnionFind uf(N);
    ans.push_back(now);
    for(int i=M;i>=2;i--){
        int a=A[i],b=B[i];
        if(uf.same(a,b)) ;
        else{
            now-=(ll)uf.usize(a)*uf.usize(b);
            uf.unite(a,b);
        }
        ans.push_back(now);
    }
    reverse(ans.begin(),ans.end());
    for(int i:ans){
        cout<<i<<endl;
    }*/
    int N,Q;
    cin>>N>>Q;
    UnionFind uf(N);
    while(Q--){
        int q,a,b;
        cin>>q>>a>>b;
        if(q==0) uf.unite(a,b);
        else{
            if(uf.same(a,b)) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
typedef long long ll;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b&&a != c)
		cout << "Yes" << endl;
	else if (a==c&&a!=b)
		cout << "Yes" << endl;
	else if (b == c&&b != a)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
n,m,q=list(map(int,input().split()))
abcd=[[] for i in range(q)]
for i in range(q):
    abcd[i]=list(map(int,input().split()))
ans=0
l=list(itertools.combinations_with_replacement([a for a in range(1,m+1)],n))
x=(len(l))
for i in range(x):
    e=l[i]
    
    wa=0
    for t in range(q):
        if e[abcd[t][1]-1]-e[abcd[t][0]-1]==abcd[t][2]:
            wa+=abcd[t][3]
    ans=max(ans,wa)
print(ans)
            



Measured memory_bytes: 21496
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;


int main()
{
	int n, sum = 0;
	bool pink = false, white = false, green = false, yellow = false;
	cin >> n;
	char c;
	for(int i = 0; i < n; i++)
	{
		cin >> c;
		if( c == 'P' and pink == false )
		{
			sum++;
			pink = true;
		}else if( c == 'W' and white == false ){
			sum++;
			white = true;
		}else if( c == 'G' and green == false ){
			sum++;
			green = true;
		}else if( c == 'Y' and yellow == false ){
			sum++;
			yellow = true;
		}
	}
	if( sum == 3 )
		cout << "Three";
	else cout << "Four";
}

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

int a, b, c;
int main () {
	cin >> a >> b >> c;
	if (a == b){
		cout << c << endl;
	}
	else if (a == c){
		cout << b << endl;
	}
	else if (b == c){
		cout << a << endl;
	}
}


Measured memory_bytes: 256
n, m = gets.chomp!.split(" ").map!(&:to_i)
l = Array.new(0, m)
r = Array.new(0, m)
m.times do |i|
    l[i], r[i] = gets.chomp!.split(" ").map!(&:to_i)
end

=begin
memo = {}
n.times do |i|
    memo[i] = i
end

m.times do |i|
    l[i].upto(r[i]) do |j|
end

puts x.count
=end

tmp = (r.min - l.max) + 1
puts tmp > 0 ? tmp : 0


Measured memory_bytes: 3440
#include<stdio.h>
 
 
int main(){
  int k,x,i;
  int large,small;
  scanf("%d %d",&x,&k);
  x --;
  if(k+x >1000000){
    large = 1000000;
  }else{
    large = k+x;
  }
  if(k-x < -1000000){
    small = -1000000;
  }else{
    small = k-x;
  }
  for(i= 0;small<=large;small++){
    printf("%d ",small);
  }
  return 0;
}

Measured memory_bytes: 128
n, m, x = map(int,input().split())
hako = []#参考書、0=買わない、1=買う


def taka(y,z):
    global hako
    if len(z) == n:
        hako.append(z)
        return
    zz = z.copy()
    zz.append(y)
    for i in range(2):
        taka(i,zz)


for i in range(2):
    taka(i,[])

#print(hako)

sankousyo = []

for i in range(n):
    c_a = list(map(int,input().split()))
    sankousyo.append(c_a)

takahasikunn = [0]*(m+1)

ans = 13*10**5

for i in hako:
    clear = 0
    for j in range(n):
        if i[j] == 1:
            for k in range(m+1):
                takahasikunn[k] += sankousyo[j][k]
    for l in range(1,m+1):
        if takahasikunn[l] >= x:
            clear += 1
    if clear == m:
        ans = min(ans,takahasikunn[0])
    #print(takahasikunn)
    takahasikunn = [0]*(m+1)

if ans == 13*10**5:
    ans = -1

print(ans)





Measured memory_bytes: 9932
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, a;
ll ps, mis;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int mi = IINF;
  V<int> v;
  FOR(i, 0, n){
    int a;
    cin >> a;
    if(a >= 0){
      ps += a;
      mins(mi, a);
    }else{
      mis += -a;
      v.pb(-a);
    }
  }
  sort(all(v));
  if(sz(v)%2){
    cout << max(ps + mis - 2*v[0], ps+mis-2*mi) << endl;
  }else{
    cout << ps + mis << endl;
  }
}

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


bool comp(pair<int,int>x,pair<int,int>y)
{
    return x.first+x.second>y.first+y.second;
}

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n;
    cin>>n;
    pair<int,int>p[n];
    set<pair<int,int> >s[2];
    for(int i=0;i<n;i++)
    {
        cin>>p[i].first>>p[i].second;
    }
    sort(p,p+n,comp);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
            ans+=p[i].first;
        else
            ans-=p[i].second;
    }
    cout<<ans;
}


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

int n;
string s = "";
int main(){
	cin >> n;
	if (n==0) s = "0";
	else while (n != 0){
		int du = n%-2;
		n/=-2;
		if (du<0){
			du += 2;
			n += 1;
		}
		s = to_string(du) + s;
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256