akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int linearSearch(int*,int,int);

int main(){
  int n,q,i,j;
  int s[10000],t,f=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&s[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    if(linearSearch(s,t,n))f++;
  }
  
  printf("%d\n",f);
  
  return 0;
}

int linearSearch(int A[],int t,int n){
  int i;
  for(i=0;i<n;i++){
    if(A[i]==t){
      return 1;
    }
  }
  return 0; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  //fact 階乗　iface 階乗の逆数
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  ll n,k;
  cin >> n >> k;
  // 前処理
  combination c(200005);
  // 計算例
  // mint now = c(n,k);
  // cout << now.x << endl;
  mint ans = 0;
  for(int i=0;i<=min(k,n);i++){
    ans += c(n,i) * c(n-1,n-i-1);
  }
  cout << ans.x << endl;
}


Measured memory_bytes: 3328
def main():
    s = "".join(reversed(list(input())))
    t = "".join(reversed(list(input())))
    anses = []

    for i in range(len(s)):
        for j in range(len(t)):
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            else:
                break
        else:
            # 合っていた
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            anses.append("".join(reversed(list(ans))))
            continue
    anses.sort()
    print(anses[0] if anses else "UNRESTORABLE")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import sys

str_a, str_b =input().split()
a=int(str_a)
b=int(str_b)
if not(a >= -1000 and a <=1000):
    sys.exit()
if not(b >= -1000 and b <=1000):
    sys.exit()
if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")


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

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if (b < a)
		swap (a , b);
	if (c < a)
		swap (c , a);
	if (c < b)
		swap (c , b);
		
	
	cout << a << " " << b << " " << c <<endl;

}

Measured memory_bytes: 1164
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  bool b=false;
  rep(i,26){
    rep(j,15){
      if(4*i+7*j==n) b=true;
    }
  }
  if(b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main()
{
  char str[10000], ch;
  int key;
  cin >> key;
  cin >> str;

  for(int j = 0; str[j] != '\0'; ++j){
      ch = str[j];
      ch = ch + key;
      if(ch > 'Z'){
        ch = ch - 'Z' + 'A' - 1;
      }
      str[j] = ch;
  }

  cout << str;

    return 0;
}


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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  vector<int> b(n + 1, 0);

  auto divisors = [](int n) -> vector<int> {
    vector<int> d;
    for (int i = 1; i * i <= n; i++) {
      if (n % i != 0)
        continue;
      d.push_back(i);
      if (i * i != n)
        d.push_back(n / i);
    }
    return d;
  };

  vector<int> ans;
  for (int i = n; i > 0; i--) {
    if (a[i] == b[i])
      continue;
    for (auto d : divisors(i)) {
      b[d] = (b[d] + 1) % 2;
    }
    ans.push_back(i);
  }

  cout << ans.size() << endl;
  for (auto aa : ans)
    cout << aa << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 5300
n, a, b = gets.split.map(&:to_i)
MOD = 1_000_000_007
def modpow(a, n, mod)
  r = 1
  while n > 0
    r = r * a % mod if n & 1 == 1
    a = a * a % mod
    n >>= 1
  end
  r
end
def modinv(a, mod)
  modpow(a, mod - 2, mod)
end
def nCk(n, k, mod)
  a = 1
  b = 1
  k.times do |i|
    a *= n - i
    a %= mod
    b *= i + 1
    b %= mod
  end
  a * modinv(b, mod) % mod
end
ans = modpow(2, n, MOD) - 1
ans += MOD - nCk(n, a, MOD)
ans += MOD - nCk(n, b, MOD)
puts ans % MOD

Measured memory_bytes: 14344
n,m=map(int,input().split())
listn=[]
listm=[]
ans=[]
num=0
for i in range(n):
    listn.append(input().split())
for i in range(m):
    listm.append(input().split())
for i in range(n):
    numx=int(listn[i][0])
    numy=int(listn[i][1])
    count=10**10
    for j in range(m):
        numd=abs(int(listm[j][0])-numx)+abs(int(listm[j][1])-numy)
        if count>numd:
            count=numd
            num=j+1
    ans.append(num)
for i in range(n):
    print(ans[i])


Measured memory_bytes: 3064
A,B,C,X,Y = map(int,input().split())
if A+B<=2*C:
  print(X*A+Y*B)
else:
  Zmin=min(X,Y)*2
  Zmax=max(X,Y)*2
  ans=float("inf")
  for i in range(Zmin,Zmax+2,2):
    ans=min(ans,C*i+max(0,X-i//2)*A+max(0,Y-i//2)*B)
  print(ans)
 

Measured memory_bytes: 38768
#include <iostream>
using namespace std;
 int main(){
 int a,b,c,d,p,x,y;
 cin>>a>>b>>c>>d>>p;
 x=a*p;
 if(p<=c)y=b;
 else y=b+((p-c)*d);
 if(x<y)cout<<x<<endl;
 else cout<<y<<endl;
 return 0;
 }


Measured memory_bytes: 3080
n = int(input())
dat = list(map(int,input().split()))

cnt = dict()

for i in range(n):
    cnt[i] = 0
for d in dat:
    cnt[d]+=1

if n%2:
    if cnt[0] != 1:
        print(0)
        exit(0)
    for i in range(2,n,2):
        if cnt[i] != 2:
            print(0)
            exit(0)
else:
    for i in range(1,n,2):
        if cnt[i] != 2:
            print(0)
            exit(0)
print((2**(n//2))%1000000007)


Measured memory_bytes: 20700
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> P;
const int pmax=1299709;
bool iscomp[pmax+1];
void init()
{
	P.reserve(100000);
	for(int i=2;i<pmax+1;i++){
		if(iscomp[i])continue;
		P.push_back(i);
		for(int j=2;i*j<pmax+1;j++)
			iscomp[i*j]=true;
	}
}
int main()
{
	init();
	while(true){
		int n;
		cin>>n;
		if(n==0)return 0;
		int pos=lower_bound(P.begin(),P.end(),n)-P.begin();
		if(P[pos]==n)cout<<0<<endl;
		else{
			cout<<P[pos]-P[pos-1]<<endl;
		}
	}
}

Measured memory_bytes: 2588
#include<stdio.h>
int a[400005], b[400005];
int h[1000006], l;
int dist[200005];
int comp_h(int x, int y, int z)
{
	if (z == 0)
	{
		if (a[h[x]] > a[h[y]])
			return 1;
		return -1;
	}
	else
	{
		if (dist[h[x]] > dist[h[y]])
			return 1;
		return -1;
	}
}
void swap_h(int x, int y)
{
	int f = h[x];
	h[x] = h[y];
	h[y] = f;
	return;
}
void f1(int ne, int z)
{
	h[l] = ne;
	int p = l;
	l++;
	while (p > 0)
	{
		if (comp_h((p - 1) / 2, p, z) > 0)
			swap_h((p - 1) / 2, p);
		p = (p - 1) / 2;
	}
	return;
}
int f2(int z)
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2, z) > 0)
			{
				if (comp_h(p, 2 * p + 2, z) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1, z) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1, z) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	for (i = 0; i < m; i++)
	{
		i *= 2;
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		a[i + 1] = b[i];
		b[i + 1] = a[i];
		i /= 2;
	}
	l = 0;
	for (i = 0; i < 2 * m; i++)
		f1(i, 0);
	int c[400005];
	for (i = 0; i < 2 * m; i++)
		c[i] = f2(0);
	int min, mid, max;
	for (i = 0; i < n; i++)
		dist[i] = 2 * n;
	int ans[200005];
	l = 0;
	dist[0] = 0;
	f1(0, 1);
	while (l > 0)
	{
		i = f2(1);
		min = -1;
		max = 2 * m;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (a[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		if (max < 2 * m)
		{
			while (a[c[max]] == i)
			{
				if (dist[b[c[max]]] > dist[i] + 1)
				{
					ans[b[c[max]]] = i;
					dist[b[c[max]]] = dist[i] + 1;
					f1(b[c[max]], 1);
				}
				max++;
				if (max == 2 * m)
					break;
			}
		}
	}
	printf("Yes\n");
	for (i = 1; i < n; i++)
		printf("%d\n", ans[i] + 1);
	return 0;
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e6;

void solve() {
	int a, b;
	cin >> a >> b;
	cout << a * b;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <numeric>

using namespace std;
using ll = long long;

int main() {
    ll n;
    cin >> n;
    if (n % 2 == 1) {
        cout << "0\n";
    } else {
        ll res = 0;
        ll cur = 10;
        for (int i = 0; i < 26; ++i) {
            res += n / cur;
            cur *= 5;
        }
        cout << res << "\n";
    }
    return 0;
}


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

int N, L, minx = (1 << 30), minid = 0;

int main() {
	cin >> N >> L;
	for (int i = 1; i <= N; i++) {
		int S = L + (i - 1);
		if (minx > abs(S)) { minx = abs(S); minid = i; }
	}
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		if (i != minid) sum += L + (i - 1);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n, k = map(int, input().split())
e = [(int(i) + 1) / 2 for i in input().split()]
a = list(accumulate(e))
s = [a[i + k] - a[i] for i in range(n - k)]
print(max(a[k - 1], *s) if n > k else a[-1])

Measured memory_bytes: 25560
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[600][600];

int main(){
  cin >> n;
  ll x,y;
  ll a = 0,b = 0;
  cin >> a >> b;
  rep(i,0,n-1){
    cin >> x >> y;
    l = max((a + x - 1) / x,(b + y - 1) / y);
    a = l * x;
    b = l * y;
  }
  print(a + b);
  return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n,m,c;
  cin>>n>>m>>c;
  
  int B[m];
  rep(i,m) cin>>B[i];
  
  int cnt=0,x;
  rep(i,n){
    int ans=0;
    rep(j,m){
      cin>>x;
      ans+=x*B[j];
    }
    ans+=c;
    if(ans>0) cnt++;
  }
  
  cout<<cnt<<endl;
 
  return 0;
}

Measured memory_bytes: 3640
// C - Train Ticket
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void solve(const string &S){
	int a=S[0]-'0', b=S[1]-'0', c=S[2]-'0', d=S[3]-'0';
	rp(bit, 0, 8){
		int i = (bit&4)==4, j = (bit&2)==2, k = (bit&1)==1;
		int x = a;
		x += i? -b: b;
		x += j? -c: c;
		x += k? -d: d;
		if(x == 7){
			cout<<a<< (i? '-': '+') <<b<< (j? '-': '+')
				<<c<< (k? '-': '+') <<d<<"=7"<<endl;
			return;
		}
	}
}

int main(){
	string S; cin>>S;
	solve(S);
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

void visit(int);
void dfs(void);

int n,time,graph[MAX][MAX],d[MAX],f[MAX],color[MAX];

int main()
{
  int u,k,i,j,v;

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      graph[i][j] = 0;
    }
  }


  for(i = 1; i <= n; i++){
    scanf("%d%d",&u,&k);
    for(j = 1; j <= k; j++){
      scanf("%d",&v);
      graph[u][v] = 1;
    }
  }
  dfs();

  for( u = 1; u <= n; u++){
    printf("%d %d %d\n",u,d[u],f[u]);
  }

  return 0;
}

void dfs()
{
  int u;

  for(u = 1; u <= n; u++){
    color[u] = WHITE;
  }
  time = 0;
  for(u = 1; u <= n; u++){
    if(color[u] == WHITE) visit(u);
  }
}

void visit(int u)
{
  int v;

  color[u] = GRAY;
  d[u] = ++time;

  for(v = 1; v <= n; v++){
    if(graph[u][v] == 0) continue;
    if(color[v] == WHITE) visit(v);
  }
  color[u] = BLACK;
  f[u] = ++time;
}

Measured memory_bytes: 636
fn main() {
    proconio::input! {
        n: usize,
        xy: [(i64, i64); n],
    }

    let mut max0 = i64::min_value();
    let mut min0 = i64::max_value();
    let mut max1 = i64::min_value();
    let mut min1 = i64::max_value();
    for i in 0..n {
        let (x, y) = xy[i];
        max0 = max0.max(x - y);
        min0 = min0.min(x - y);
        max1 = max1.max(x + y);
        min1 = min1.min(x + y);
    }

    println!("{}", (max0 - min0).max(max1 - min1));
}


Measured memory_bytes: 8980
K, N = map(int, input().split())
if K % 2 == 0:
  print(K // 2, end = ' ')
  for i in range(1, N):
    if i != N - 1:
      print(K, end = ' ')
    else:
      print(K)
else:
  def superlist(L, n):
    if n % 2 == 1:
      return [L // 2 + 1] + superlist(L, n-1)
    else:
      Ax = [L // 2 + 1 for i in range(n)]
      j = n - 1
      for i in range(n // 2):
        Ax[j] -= 1
        if Ax[j] == 0:
          j -= 1
        else:
          for m in range(j + 1, n):
            Ax[m] = L
          j = n - 1
      return Ax
  if K == 1:
    for i in range((N - 1) // 2 + 1):
      if i != (N - 1) // 2:
        print(1, end = ' ')
      else:
        print(1)
  else:
    A = superlist(K, N)
    for _ in range(N):
      if _ != N - 1 and A[_] != 0:
        print(A[_], end = ' ')
      elif _ == N - 1 and A[_] != 0:
        print(A[_])

Measured memory_bytes: 17120
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long int 
#define fi first
#define se second
#define FIO {ios::sycnt2_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
#define int long long int
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
int32_t main()
{
int n;
cin>>n;
int a[n];
forn(i,n)cin>>a[i];
int cnt=0;
forn(i,n)
{
  for(int j=i+1;j<n;j++)
  {
    for(int k=j+1;k<n;k++)
    {
      int x=a[i];
      int y=a[j];
      int z=a[k];
      if((x+y)>z&&(x+z)>y&&(y+z)>x&&x!=y&&x!=z&&y!=z)
      {
        cnt++;
       // cout<<i+1<<j+1<<k+1<<endl;
      }
    }
  }
}
cout<<cnt;
}

Measured memory_bytes: 3640
def f(x1, x2):
  W = [[i, 1001] for i in range(n)]
  W[x1] = [x1, 0]
  W[x2] = [x2, 2000]
  i=0
  while 1:
    A = sorted(W, key = lambda x:x[1])
    p1, w1 = A[i]
    if p1 == x2: break
    for p2, w2 in A[i + 1:]:
      way=(p1, p2)
      if way in cost:
        tmp = w1 + cost[way]
        W[p2] = [p2, min([w2, tmp])]
    i += 1
  return W[x2][1]

n = int(raw_input())
m = int(raw_input())
cost = {}
for _ in [0] * m:
  a, b, c, d = map(int, raw_input().split(","))
  cost[(a-1, b-1)] = c
  cost[(b-1, a-1)] = d
x1, x2, y1, y2 = map(int, raw_input().split(","))
x1 -= 1
x2 -= 1
print y1 - y2 - f(x1, x2) - f(x2, x1)

Measured memory_bytes: 4288
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get_line().parse::<usize>().unwrap();
    let mut inputs: Vec<(usize, usize, usize)> = Vec::new();
    for i in 0..n {
        let a = get_line().parse::<usize>().unwrap();
        for _ in 0..a {
            let (x, y) = {
                let line = get_line().split_whitespace()
                    .map(|n| n.parse().unwrap())
                    .collect::<Vec<usize>>();
                (line[0], line[1])
            };
            inputs.push((i, x - 1, y));
        }
    }

    let mut max = 0;
    for bit in 0..(1 << n) {
        let mut ok = true;
        for &(i, x, y) in &inputs {
            if bit & (1 << i) != 0 && bit & (1 << x) != y << x {
                // iが正直者かつxについての仮定とiの人が言っているxの人のyが等しいかどうか
                ok = false;
                break;
            }
        }
        if ok {
            max = std::cmp::max(max, bit.count_ones());
        }
    }
    println!("{}", max);
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

bool cmp(const pii a, const pii b) {
    return (a.first == b.first ? a.second > b.second : a.first < b.first);
}

int idx_bs(const vector<pii> &ab, const int key) {
    int l = 0, r = ab.size();
    while(abs(l - r) > 1) {
        int mid = (l + r) / 2;
        if(ab[mid].first >= key) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    return r;
}

int main() {
    ll n;
    cin >> n;
    cout << (n * (n - 1) / 2) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    vector<ll> a(n);
    vector<int> digit(35, 0);
    for(int i=0; i<n; i++){
        cin>>a[i];
        for(ll j=0; j<32; j++){
            if(a[i] & (1LL << j)){
                digit[j]++;
            }
        }
    }

    int ans = 0;
    vector<bool> used(n, false);
    for(ll i=30; i>=0; i--){
        bool valid = false;
        ll num = (1LL << i);
        if(digit[i] % 2){
            for(int j=0; j<n; j++){
                if(a[j] == num && !used[j]){
                    ans++;
                    valid = true;
                    used[j] = true;
                    for(int k=i-1; k>=0; k--){
                        digit[k]++;
                    }
                    break;
                }
            }
        }
        else{
            valid = true;
        }

        for(int j=0; j<n; j++){
            if(num <= a[j] && !used[j]){
                a[j] -= num;
            }
        }

        if(!valid){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}

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

int main()
{
  int n;
  cin >> n;
  
  vector<int> x(n);
  int Sx = 0;
  int max = 0;
  int min = 101;
  
  for (int i = 0; i < n; i ++)
  {
    cin >> x.at(i);
    Sx += x.at(i);
    if (max < x.at(i)) max = x.at(i);
    if (min > x.at(i)) min = x.at(i);
  }

  int rally_min = 1000000000;
  
  for (int i = min; i <= max; i ++)
  {
    int temp = 0;
    for (int j = 0; j < n; j ++)
    {
      temp += (x.at(j) - i) * (x.at(j) - i);
    }
    if (temp < rally_min) rally_min = temp;
  }
  
  cout << rally_min << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
 
using namespace std;
int n,a,b;
int main (){
cin>>n>>a>>b;if(a>=b)cout<<"delicious"<<endl;else if(n>=(b-a)) cout<<"safe"<<endl;else cout<<"dangerous"<<endl;
 
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX_N 100005
int par[MAX_N];
int find(int x) {
	if(x==par[x])
		return x;
	else
		return  find(par[x]);
}



int main(){
	int n,q;
	while(true){
		scanf("%d %d",&n,&q);
		if(n==0&&q==0) break;
		int x;
		long long sum=0;
		for(int i=2;i<=n;i++){
			
			scanf("%d",&x);
			par[i] = x;
		}
		par[1] = 1;
		//flag[1] = true;
		
		getchar();
		char c;
		int p;
		while(q--){
			scanf("%c%d%*c",&c,&p);
			if(c=='Q'){
				sum+=find(p);
			}else{
				par[p] = p;
			}
		}
		printf("%lld\n",sum);
	}
}

Measured memory_bytes: 3540
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        long n=sc.nextInt();
        long a=sc.nextInt();
        long b=sc.nextInt();
        if(a>b||(n==1&&a!=b)){
            System.out.println(0);
        }else{
            System.out.println((b*(n-1)+a)-(a*(n-1)+b)+1);
        }
    }
}

Measured memory_bytes: 23124
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi a(n);
    int x;
    rep(i, n) {
        cin >> a[i];
        if(i>0) x=x^a[i];
        else x=a[i];
    }
    for(auto p:a)cout << (x^p) << ' ';
    return 0;
}

Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	set<string>s;
	cin>>n;
	while(n--)
	{
		string str;
		cin>>str;
		s.insert(str);
	}
	cout<<s.size()<<endl;
	return 0;

}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

ll gcd(ll x, ll y) {
    return y ? __gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
    return x/__gcd(x, y)*y;
}

int main() {
    ll n, x; cin >> n >> x;
    ll minx = x;
    vector<ll> v(n + 1);
    v[0] = x;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i];
        minx = min(minx, v[i]);
    }
    for (int i = 0; i <= n; ++i) {
        v[i] -= minx;
    }
    sort(v.begin(), v.end());

    ll ans = v[1];
    for (int i = 2; i <= n; ++i) {
        ans = gcd(ans, v[i]);
    }
    cout << ans << endl;
}



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

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


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

using namespace std;

#define TASK "c"
#define int long long


const int MOD = 1e9 + 7;

int bp (int x, int y) {
    if (y == 1)  return x;
    if (y & 1) return x * bp(x, y - 1) % MOD;
    int z = bp(x, y / 2);
    return z * z % MOD;
}

int dv (int x) {
    return bp(x, MOD - 2) % MOD;
}

void solve() {
    int x, y;
    cin >> x >> y;
    if ((2 * y - x) % 3) {
        cout << 0;
        return
        ;
    }
    int a = (2 * y - x) / 3;
    int b = x - y + a;
    if (a < 0 || b < 0) {
        cout << 0;
        return;
    }
    vector<int> fc(2e6 + 1, 1);
    for (int i = 1; i < fc.size(); ++ i) {
        fc[i] = fc[i - 1] * i % MOD;
    }
    cout << fc[a + b] * dv(fc[a]) % MOD * dv(fc[b]) % MOD;

}

signed main() {
    //freopen(TASK".in", "r", stdin);freopen(TASK".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
//    cout<<"7";
    solve();
}

Measured memory_bytes: 15872
#include <stdio.h>

int main() {
	long long int x;
	scanf("%lld", &x);
	long long int y[x];
	long long int total=1;
	
	for(int i=0;i<x;i++){
		scanf("%lld", &y[i]);
	}
	
	for(int j=0;j<x;j++) {
		if(y[j]==0) {
			printf("0");
			return 0;
		}
	}
	for(int k=0;k<x;k++) {
		if(y[k]<=1000000000000000000/total) {
			total=total*y[k];
		}

	else {
		printf("-1");
		return 0;
	}

}
	printf("%lld",total);
	return 0;
}

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

int main() {
    int a[101];
    int N, count = 0;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];
    int now = a[0], sub_count = 1;
    for (int i = 1; i < N; i++) {
        if (a[i] == now) {
            if (sub_count == 3) {
                count++;
                sub_count = 2;
            }
            else sub_count++;
        }
        else {
            if (sub_count == 2 || sub_count == 3) {
                count++;
            }
            now = a[i];
            sub_count = 1;
        }
        // cout << now << " " << sub_count << " " << count << endl;
    }
    if (sub_count == 2 || sub_count == 3) count++;
    else if (sub_count == 4) count += 2;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main() {
	int A, B, C, k;
	int count = 0;
	std::cin >> A >> B >> C >> k;
	if (k <= A) {
		std::cout << k;
	}
	else {
		if (k <= A + B) {
			std::cout << A;
		}
		else {
			k -= (A + B);
			std::cout << A - k;
		}
	}




}

Measured memory_bytes: 3628
import sys
import itertools
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,K=nm()

mod=10**9+7
ans=0

for i in range(K,N+2):
    ans+=(N+(N-i+1))*i/2-(0+(i-1))*i/2+1

print(int(ans%mod))

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct ban
{
    int x, y;
    int d;
    ban(){}
    ban(int x, int y, int d)
    {
        this->x = x;
        this->y = y;
        this->d = d;
    }
};
bool operator<(const ban& a, const ban& b)
{
    return a.d < b.d;
}

int n, m;
int a[N];
ban b[N];

int p[N];
int q[N], qv[N];
long long g[N];
int fi(int x)
{
    if (p[x] == x)
        return x;
    return p[x] = fi(p[x]);
}
void kpc(int x, int y)
{
    x = fi(x);
    y = fi(y);
    p[x] = y;
    q[y] += q[x];
    qv[y] += qv[x];
    g[y] += g[x];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i].x >> b[i].y >> b[i].d;
    sort(b, b + m);
    for (int i = 1; i <= n; ++i)
    {
        p[i] = i;
        g[i] = a[i];
    }
    int ans = 0;
    for (int i = 0; i < m; ++i)
    {
        int x = b[i].x;
        int y = b[i].y;
        int d = b[i].d;
        if (fi(x) == fi(y))
        {
            ++q[fi(x)];
            if (d <= g[fi(x)])
            {
                ++qv[fi(x)];
                ++ans;
            }
        }
        else
        {
            kpc(x, y);
            ++q[fi(x)];
            if (d <= g[fi(x)])
            {
                ans -= qv[fi(x)];
                qv[fi(x)] = q[fi(x)];
                ans += qv[fi(x)];
            }
        }
    }
    cout << m - ans << endl;
    return 0;
}


Measured memory_bytes: 3840
N = int(input())
INF = 10 ** 9

dp = [0] * (N + 1)
for i in range(1, N + 1):
    tmp = INF
    p = 1
    while p <= i:
        tmp = min(tmp, 1 + dp[i - p])
        p *= 6
    p = 1
    while p <= i:
        tmp = min(tmp, 1 + dp[i - p])
        p *= 9
    dp[i] = tmp

print(dp[N])


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

const int MOD = 998244353;
struct modint {
  long long val;
  modint(long long val=0) : val((val % MOD + MOD) % MOD){}
  modint operator-() const { return modint(-val); }
  modint& operator+=(const modint a) { if ((val += a.val)     >= MOD) val -= MOD; return *this; }
  modint& operator-=(const modint a) { if ((val += MOD-a.val) >= MOD) val -= MOD; return *this; }
  modint& operator*=(const modint a) { (val *= a.val) %= MOD; return *this; }
  modint operator+(const modint a) const { return (modint)*this += a; }
  modint operator-(const modint a) const { return (modint)*this -= a; }
  modint operator*(const modint a) const { return (modint)*this *= a; }
  modint pow(long long n) const { modint r(1), m(val); while (n > 0) { if (n & 1) {r *= m;} m *= m; n >>= 1; } return r; }
  modint inv() const { return pow(MOD-2); }
  modint& operator/=(const modint a) { return (*this) *= a.inv(); }
  modint operator/(const modint a) const { return (modint)*this /= a; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  friend ostream &operator<<(ostream &os, const modint &p) { return os << p.val; }
  friend istream &operator>>(istream &is, modint &a) { long long t; is >> t; a = modint(t); return (is); }
};

struct mod_combination {
  /* initialize: O(n) */
  /* choose    : O(1) */
  vector<modint> fact, fact_inv, inv;
  mod_combination(int n) : fact(n+1, 1), fact_inv(n+1, 1), inv(n+1, 1) {
    for (int i = 2; i <= n; i++) {
      fact[i] = fact[i - 1] * i;
      inv[i] = -inv[MOD % i] * (MOD / i);
      fact_inv[i] = fact_inv[i - 1] * inv[i];
    }
  }
  modint choose(int n, int k) { return fact[n] * fact_inv[k] * fact_inv[n - k]; }
};

int N,M,K;

signed main() {
  cin >> N >> M >> K;
  
  mod_combination mc(max(N,max(M,K)));

  modint ans = 0;
  for(int k=0; k<=K; k++) ans += mc.choose(N-1, k) * M * modint(M-1).pow(N-k-1);
  cout << ans << endl;
}


Measured memory_bytes: 7960
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if (Math.abs(a - c) <= d) {
            System.out.println("Yes");
        } else if (Math.abs(a - b) <= d && Math.abs(b - c) <= d) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 84436
n,m = map(int,input().split()) 
x=['0']*m 
y=['0']*m 
for i in range(m): 
    x[i],y[i] = map(str,input().split())

num = 0 
pena = 0

lis=[0]*n 
sw = [0]*n

for i in range(m): 
    if y[i] == 'WA':
        lis[int(x[i])-1] += 1
    else:
        if sw[int(x[i])-1] == 0:
            num += 1
            pena = pena + lis[int(x[i])-1]
            sw[int(x[i])-1] = 1

        else:
            pass
        
print(num,pena)

Measured memory_bytes: 17228
import math

n = int(input())

mod = 10**9 + 7
table = {}

for i in range(2, n + 1):

    tmp = i
    div = 2
    while tmp >= div:
        if tmp % div == 0:
            if div not in table:
                table[div] = 1
            else:
                table[div] += 1
            tmp //= div
        else:
            div += 1

ans = 1

for key, val in table.items():
    ans *= val + 1
    ans %= mod

print(ans)


Measured memory_bytes: 40304
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
using namespace std;

int main() {
  ll n;
  cin >> n;
  cout << ceil(n/2.0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




int main(){
    int N,A,B;
    cin >> N >> A >>B;
    
    cout << min(A*N , B) << endl;



}

Measured memory_bytes: 3596
/**
*    created: 10.05.2020 15:23:34
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int mx = 2000000;
    int c[mx];
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) c[a[i]]++;
    int sum = 0;
    rep(i,mx) {
        sum += c[i];
        c[i] = sum;
    }
    for (int i = n - 1; i >= 0; i--) {
        b[c[a[i]]-1] = a[i];
        c[a[i]]--;
    }
    rep(i,n) {
        if (i == 0) cout << b[0];
        else cout << " " << b[i];
    }
    cout << endl;
    return 0;
}



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

int main(){
    vector<int> v(3);
    for(int i=0;i<3;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    cout<<v[0]<<" "<<v[2]<<endl;
    return 0;
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
const int MOD = 1e9+7;
using namespace std;
int main(){
    long n;
    cin >> n;
    vector<long long> a(n);
    for(auto & in : a){
        cin >> in;
    }
    vector<int> d(60,0);
    for(auto i = 0; i < 60; ++i){
        for(const auto & x : a){
            if((x >> i) & 1){
                d[i]++;
            }
        }
    }
    long long ans = 0;
    for(auto i = 0; i < 60; ++i){
        ans += ((1ll<<i)%MOD *d[i]% MOD * (n - d[i])% MOD) % MOD;
        ans %= MOD;
    }
    cout << ans;
}




Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int n,a,b,c;
int main()
{
	cin>>a>>b;
	cin>>n>>c;
	if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
	{
		if(b==31)
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}	
	else if(a==2)
	{
		if(b==28)
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}	
	else
	{
		if(b==30)
			cout<<1<<endl;
		else
			cout<<0<<endl;	
	}				
} 

Measured memory_bytes: 256
class Union_Find():
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.siz = [1] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            #親を検索
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_checker(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.siz[y] += self.siz[x]
        else:
            self.par[y] = x
            self.siz[x] += self.siz[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        return self.siz[self.find(x)]
        
n, q = map(int, input().split())
union_find_tree = Union_Find(n)
for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        union_find_tree.union(x, y)
    else:
        if union_find_tree.same_checker(x, y):
            print(1)
        else:
            print(0)



Measured memory_bytes: 6120
#include <iostream>

using namespace std;

int main(){
	int amt,in;
	while(1){
		int r100=0,r500=0,r1000=0;
		cin >> amt >> in;
		if(amt==0&&in==0){ break; }
		in-=amt;
		while(in>=1000){
			in-=1000;
			r1000++;
		}
		while(in>=500){
			in-=500;
			r500++;
		}
		while(in>0){
			in-=100;
			r100++;
		}
		cout << r100 << " " << r500 << " " << r1000 << endl;
	}
}

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

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

Measured memory_bytes: 256
a = int(input())
b = 1
while a !=4 and a !=2 and a != 1:
    if a%2 == 0 :
        a=a//2
        b+=1 
    elif a%2!=0 :
        a=a*3+1
        b+=1 
else :
  print(b+3)
 

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

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

  if(A%3==0 || B%3==0 || (A+B)%3==0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
return 0;  
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	getline(cin, s);
	REP(i, s.length()) {
		if(islower(s[i])) s[i] = toupper(s[i]);
		else s[i] = tolower(s[i]);
	}
	cout << s << endl;
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    int sum=0;
    int pie[n+1];
    int m1,m2;
    for(int i=1;i<=n;i++){
        pie[i]=l+i-1;
        sum+=pie[i];
    }
    for(int i=1;i<=n;i++){
        if(i==1){
            m2=sum-pie[i];
            m1=abs(pie[i]);
            //cout<<m2<<endl;
        }
        else{
            if(abs(pie[i])<m1){
            m2=sum-pie[i];
            m1=abs(pie[i]);
           // cout<<m2<<endl;
            }
        }
    }
    cout<<m2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
struct Edge
{
    int from, to, cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using P = std::pair<int, int>;
constexpr int INF = 1e9;
bool operator<(const Edge &e, const Edge &f)
{
    return e.cost > f.cost;
}
std::vector<int> dijkstra(const Graph &g, int s)
{
    std::vector<int> d((int)g.size(), INF);
    d[s] = 0;
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(P(0, s));
    while (!que.empty())
    {
        int dist = que.top().first;
        int v = que.top().second;
        que.pop();
        if (d[v] < dist)
            continue;
        for (const auto &e : g[v])
        {
            if (d[e.to] <= d[v] + e.cost)
                continue;
            d[e.to] = d[v] + e.cost;
            que.push(P(d[e.to], e.to));
        }
    }
    return d;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double eps = 1e-10;
const int MOD = 1000000007;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n, m; cin >> n >> m;
    Graph g(3*n);
    for(int i=0;i<m;++i) {
      int x, y; cin >> x >> y;
      x--; y--;
      g[x].push_back(Edge(x, y+n, 1));
      g[x+n].push_back(Edge(x+n, y+2*n, 1));
      g[x+2*n].push_back(Edge(x+2*n, y, 1));
    }
    int s, t; cin >> s >> t;
    s--; t--;
    vector<int> dist = dijkstra(g, s);
    if(dist[t] == INF) {
      cout << -1 << endl;
    } else {
      cout << dist[t]/3 << endl;
    }
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

const int MAX_N=10005;
int dp[MAX_N], w[MAX_N], v[MAX_N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int H, n;
    cin >> H >> n;
    
    REP(i,n) {
        cin >> w[i] >> v[i];
    }
    REP(i, H+1) dp[i] = 1e9;
    dp[0] = 0;

    REP(i, n) {
        for(int j=1; j<=H; j++) {
            if(j<=w[i]) dp[j] = min(dp[j], v[i]);
            else {
                dp[j] = min(dp[j], dp[j-w[i]]+v[i]);
            }            
        }
    }

    cout << dp[H] << endl;
    return 0;
}

Measured memory_bytes: 384
num = int(input())
li = list(map(int, input().split()))

number = list(range(num))
data = dict(zip(number, li))
data_sorted = sorted(data.items(), key = lambda x:x[1])
data_key = [str(i[0] + 1) for i in data_sorted]
print(" ".join(data_key))

Measured memory_bytes: 32452
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

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

int n;
ll a[SIZE];

int main(){
  cin >> n;
  rep(i,0,n) cin >> a[i];
  ll ans = 0;
  ans += a[0]-1;
  a[0] = 1;
  ll mn = 2;
  rep(i,1,n){
    if(mn < a[i]) ans += (a[i]-1)/mn;
    else if(mn == a[i]){
      mn++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024