akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

ll in[200100];
ll dist[200100];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    int i;
    memset(dist, 0x3f, sizeof(dist));
    xrep(i, 1, n + 1) cin >> in[i];
    dist[1] = 0;
    ll d(0);
    ll now(1);
    while (1) {
        d++;
        ll next = in[now];
        if (dist[next] < d) {
            ll cyc = d - dist[next];
            k %= cyc;
            ll st = dist[next];
            while (k < st) k += cyc;
            xrep(i, 1, n + 1) if (dist[i] == k) cout << i << endl;
            break;
        }
        else {
            if (d == k) {
                cout << next << endl;
                return 0;
            }
            dist[next] = d;
            now = next;
        }
    }
}


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

int main(){
  string s;
  cin >> s;
  int l = 0, r = s.size() - 1;
  int cnt = 0;
  while (l < r) {
    if (s[l] == s[r]) {
      l++;
      r--;
      continue;
    } else {
      if (s[l] != 'x' && s[r] != 'x') {
        cout << -1 << endl;
        return 0;
      }
      if (s[l] == 'x') {
        l++;
      } else {
        r--;
      }
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

int main()
{
    double n, d; cin>>n>>d;
    int count =0;
    int x,y;
    while (n--)
    {
        cin>>x>>y;
        double l = double(sqrt(pow (x,2) + pow(y,2)));
       // cout <<l<<endl;
        if (l<=d) count ++;
    }
    cout <<count <<endl;
}


Measured memory_bytes: 3740
firstMountainHeight  = 0
secondMountainHeight = 0
thirdMountainHeight  = 0

while 1:

	try :

		i = int(raw_input())

		if firstMountainHeight    < i :
			thirdMountainHeight  = secondMountainHeight
			secondMountainHeight = firstMountainHeight
			firstMountainHeight  = i

		elif secondMountainHeight < i :
			thirdMountainHeight  = secondMountainHeight
			secondMountainHeight = i
			
		elif thirdMountainHeight  < i :
			thirdMountainHeight   = i
			
    	except:
	    	print"%d" % (firstMountainHeight)
	    	print"%d" % (secondMountainHeight)
	    	print"%d" % (thirdMountainHeight)

	    	break

Measured memory_bytes: 4208
#include <iostream>
#include <cstdio>

using namespace std;
int f[10005];
int n,m;
int getf(int p)
{
    if(f[p] == p)
        return p;
    else
        return f[p] = getf(f[p]);
}
void unite(int x,int y)  //合并x,y
{
    int t1,t2;
    t1 = getf(x);
    t2 = getf(y);
    if(t1 != t2)
    {
        for(int i=0;i<m;i++)
        {
            if(f[i] == t2)
                f[i] = t1;
        }
        f[t2] = t1;
    }
    return ;
}
int same(int x,int y)
{
    if(f[x] == f[y])
        return 1;
    else
        return 0;
}
int main()
{
    int t,a,b;
    scanf("%d%d",&m,&n);
    for(int i=0;i<m;i++)
        f[i] = i;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&t,&a,&b);
        if(t == 0)
            unite(a,b);
        else
        {
            if(same(a,b) == 1)
                printf("1\n");
            else
                printf("0\n");
        }

    }
    return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    sort(p.begin(),p.end());
    ll ans=0;
    rep(i,k)ans+=p[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  ll ba = 0;
  ll b = 0;
  ll a=0;
  ll ans = 0;
  rep(i,n){
      string s;cin >> s;
      if(s[0] == 'B' && s[s.size()-1] == 'A') ba++;
      else if(s[0] == 'B') b++;
      else if(s[s.size()-1] == 'A') a++;
      rep(j,s.size()-1){
          if(s[j]=='A' && s[j+1] == 'B') ans++;
      }
  }
  if(ba){
      ans += ba - 1;
      if(a) ans++;
      if(b) ans++;
      if(a&&b) ans += min(a,b)-1;
  }else{
      ans += min(a,b);
  }
  cout<< ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

using namespace std;

int main(void){
    int D;
    long long G;
    cin >> D >> G;
    vector<long long> p(D), c(D);
    for(int i = 0; i < D; i++) cin >> p[i] >> c[i];

    long long ans = LLONG_MAX;
    int N = (1 << D);
    for(int n = 0; n < N; n++){
        int nn = n;
        long long sc = 0;
        long long sp = 0;
        for(int d = D - 1; d >= 0; d--){
            if(nn % 2 == 1){
                sc += 100 * (d + 1) * p[d] + c[d];
                sp += p[d];
            }
            nn /= 2;
        }
        nn = n;
        for(int d = D - 1; d >= 0; d--){
            if(nn % 2 == 0){
                if(100 * (d + 1) * (p[d] - 1) <= (G - sc)){
                    sc += 100 * (d + 1) * (p[d] - 1);
                    sp += p[d] - 1;
                }else{
                    int pm = max(0LL, (G - sc + 100 * (d + 1) - 1) / (100 * (d + 1)));
                    sc += 100 * (d + 1) * pm;
                    sp += pm;
                }
            }
            nn /= 2;
        }
        // cout << n << " " << sp << endl;
        if(sc >= G) ans = min(ans, sp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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

int main()
{
  // input & declare
  int n, h;
  cin >> n >> h;
  std::vector<int> va;
  std::vector<int> vb;
  int tmp;
  for(int i = 0; i < n; i++)
  {
    cin >> tmp;
    va.push_back(tmp);
    cin >> tmp;
    vb.push_back(tmp);
  }

  sort(va.begin(),va.end());
  sort(vb.begin(),vb.end());

  int maxa = va[n-1];

  int maxa_index = n;
  for(int i = 0; i < n; i++){
    if (vb[i] > maxa) {
      maxa_index = i;
      break;
    }
  }

  // process
  int result = 0;
  for(int i = n-1; i >= maxa_index; i--)
  {
    h -= vb[i];
    result++;
    if (h <= 0) {
      std::cout << result << '\n';
      exit(0);
    }
  }

  while (true) {
    if (h <= 0) {
      std::cout << result << '\n';
      exit(0);
    }
    h -= maxa;
    result++;
    if (h <= 0) {
      std::cout << result << '\n';
      exit(0);
    }
  }
}


Measured memory_bytes: 1276
import collections
N = int(input())
K = int(input())

memo = [
    collections.defaultdict(int),
    collections.defaultdict(int),
    collections.defaultdict(int),
    collections.defaultdict(int)
]


def rec(n, k):
    if k == 0:
        return 1
    elif n < 10:
        if k == 1:
            return n
        else:
            return 0
    elif n in memo[k]:
        return memo[k][n]
    digit = len(str(n))
    top = (n // (10**(digit - 1))) * 10**(digit - 1)
    residue = n - top
    hoge = rec(top - 1, k) + rec(residue, k - 1)
    memo[k][n] = hoge
    return hoge


print(rec(N, K))


Measured memory_bytes: 4340
#include<stdio.h>

int main(void){
	int a,b,c,d;
	scanf("%d\n%d\n%d",&a,&b,&c);
	if(a>b){
		d = a,a = b,b = d;
	}else{
	}
	if(b>c){
		d = b,b = c,c = d;
	}else{
	}
	if(a>b){
		d = a,a = b,b = d;
	}else{
	}
	printf("%d %d %d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a1,a2,a3;
  cin>>a1>>a2>>a3;
  int s=0;
  s=s+a1+a2+a3;
  if(s>=22){
  	cout<<"bust"<<endl;
  	
  }
  
  else{
  	
  	cout<<"win"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
ll N, A, B;
bool visit[3];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> N >> A >> B;
	ll left = (N % (A + B) > A) ? A : (N % (A + B));
	cout << N / (A + B) * A + left << "\n";
}

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

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

  vector<string> strings;
  for (int i=0; i<n; i++) {
    string str;
    cin >> str;
    sort(str.begin(), str.end());
    strings.push_back(str);
  }

  char alpabet = 'a';
  int counts[26];
  for (int i=0; i<26; i++) {
    counts[i] = 0;
  }

  for (int i=0; i<26; i++) {
    int min_count = 50;
    for (int j=0; j<n; j++) {
      int count=0;
      for (int k=0; k<strings[j].size(); k++) {
          if (strings[j][k] == alpabet+i) {
            count++;
          }
      }
      if (count < min_count) {
        counts[i] = count;
        min_count = count;
      }
    }
  }

  string ans;
  for (int i=0; i<26; i++) {
    //cout << counts[i] << endl;
    string s(counts[i], 'a'+i);
    ans += s;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]

P = [int(x) - 1 for x in input().split()]

pear = []
for i in range(M):
	pear.append([int(x) - 1 for x in input().split()])


par = []
for i in range(N):
	par.append(i)

def root(x):
	if par[x] == x:
		return x
	else:
		par[x] = root(par[x])
		return par[x]

def same(x, y):
	return root(x) == root(y)

def unite(x, y):
	X = root(x)
	Y = root(y)
	if X != Y:
		par[X] = Y

for i in range(M):
	unite(pear[i][0], pear[i][1])

ans = 0

for i in range(N):
	if same(i, P[i]):
		ans += 1

print(ans)

Measured memory_bytes: 29116
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
int main()
{
	register ll a=ri()*100,b=ri()*100,c=ri(),d=ri(),e=ri(),f=ri(),i,j,u,v,r1=1e9,r2=-1e9;
	for(i=0;i*a<=f;i++)
		for(j=0;i*a+j*b<=f;j++)
			for(u=0;(u*c)*100<=e*(i*a+j*b)&&i*a+j*b+u*c<=f;u++)
				for(v=0;(u*c+v*d)*100<=e*(i*a+j*b)&&i*a+j*b+u*c+v*d<=f;v++)
				{
					if((u*c+v*d)*r1>r2*(i*a+j*b+u*c+v*d))
					{
						r1=(i*a+j*b+u*c+v*d);
						r2=(u*c+v*d);
					}
				}
	printf("%lld %lld\n",r1,r2);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

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

int main()
{
	int K;
	cin >> K;
	ll ans = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			if (gcd(i, j) == 1) {
				ans += K;
			}
			else {
				int num = gcd(i, j);
				for (int k = 1; k <= K; k++) {
					ans += gcd(num, k);
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int N, F[100][10], P[100][11], cnt[100];

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

    cin >> N;
    rep(i, N)rep(j, 10)cin >> F[i][j];
    rep(i, N) {
        rep(j, 11)cin >> P[i][j];
    }

    ll ans = LLONG_MIN;
    FOR(S, 1, 1 << 10) {
        MEM(cnt, 0);
        rep(i, N)rep(j, 10) if (S >> j & 1) {
            cnt[i] += F[i][j];
        }
        ll profit = 0;
        rep(i, N)profit+=P[i][cnt[i]];
        smax(ans, profit);
    }
    cout << ans << endl;
}


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

using namespace std;

int l[2222];

int main() {
    int n;
    cin >> n;
    for(int i=0;i<n;i++) cin >> l[i];
    sort(l,l+n);
    int r = 0;
    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++) {
            int p = lower_bound(l,l+n,l[i]+l[j])-l;
            r += max(0,p-j-1);
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
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の最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  cin >> n;
 
  vector<pair<int,int>> p(n);
  rep(i,n){
  int x,y;
  cin >> x >> y;
  p[i].fi=x+y;
  p[i].se=x-y;
  }
  
  sort(all(p));  
  
  int hi=p[0].fi;
  int ans=1;
  repo(i,n){
    if(hi<=p[i].se) {
    hi=p[i].fi;
    ans++;
    }
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();

		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += Math.abs(scanner.nextInt() - scanner.nextInt()) + 1;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 25832
import java.util.Scanner;

class Main
{
public static void main(String[] args)
{
	Scanner scan = new Scanner(System.in);
	
	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	
	int x = 0;
	
	for (int i=a; i<=b; i++){
		if (c%i==0){
			x++;}}
	
	System.out.println(x);
	}
}


Measured memory_bytes: 26336
n=int(input())
l=[]
for i in range(n):
  v=int(input())
  l.append(v)
l.sort()
sum=0
for i in range(n):
  sum+=l[i]
if sum%10==0:
  for i in range(n):
    if l[i]%10!=0:
      print(sum-l[i])
      break
    if i==n-1:
      print(0)
else:
  print(sum)

Measured memory_bytes: 3064
from math import gcd

def main():
    k = int(input())
    ans = 0
    for i in range(1, k+1):
        for j in range(1, k+1):
            for k in range(1, k+1):
                ans += gcd(gcd(i, j), k)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
ll X,Y;
cin>>X>>Y;
for (ll y = 0; y <= X;y++){
    if(Y==2*X+2*y){
        cout<<"Yes"<<endl;
        return 0;
    }
}
cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string a, b, c;
  cin >> a >> b >> c;

  cout << a[0] << b[0] << c[0] << endl;

  return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
if H % 2 == 0 && W % 2 == 0
    n4, n2, n1 = H*W/4, 0, 0
elsif H % 2 == 0
    n4, n2, n1 = H*(W-1)/4, H/2, 0
elsif W % 2 == 0
    n4, n2, n1 = (H-1)*W/4, W/2, 0
else
    n4, n2, n1 = (H-1)*(W-1)/4, (H+W)/2-1, 1
end

hash = Hash.new(0)
H.times do |i|
    gets.chomp.split('').each do |c|
        hash[c] += 1
    end
end

nums = hash.values
nums.length.times do |i|
    if nums[i] % 2 == 1 && n1 == 1
        nums[i] -= 1
        n1 = 0
    end
    while nums[i] > 0
        if n4 > 0 && nums[i] >= 4
            nums[i] -= 4
            n4 -= 1
        else
            nums[i] -= 2
            n2 -= 1
        end
    end
end

puts nums.all?(&:zero?) && [n4, n2, n1].all?(&:zero?) ? 'Yes' : 'No'

Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll min=0, max=0;
    auto minx = [&](ll x){
        min = x * (x-1) / 2;
    };
    auto maxx = [&](ll x){
        max = (2*n-x+1) * x / 2;
    };
    ll ans = 0;
    for(ll i = k; i <= n+1; i++){
        minx(i);
        maxx(i);
        ll add = max - min + 1;
        ans = (ans + add)%mod;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3520
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


vector<int> vis;
vector<int> d;
vector<vector<int> > g;
vector<vector<int> > anc;

void dfs( int curr, vector<int>& vv )
{
    vis[curr]=1;
    d[curr]=(int)vv.size();

    int k=1;
    while(k<=d[curr]) {
        anc[curr].push_back(vv[d[curr]-k]);
        k*=2;
    }

    vv.push_back( curr );
    int i;
    for(i=0; i<(int)g[curr].size(); i++) {
        if( !vis[g[curr][i]] ) {
            dfs( g[curr][i], vv );
        }
    }
    vv.pop_back();

    return;
}

int getanc( int a, int b )
{
    if(d[a]>d[b]) swap(a, b);
    int delta = d[b]-d[a];
    int cnt=0;
    while(delta>0) {
        if(delta & (1<<cnt)) {
            b = anc[b][cnt];
            delta -= (1<<cnt);
        }
        cnt++;
    }
    assert(d[a]==d[b]);
    if(a==b) return a;

    int N=(int)anc[a].size();
    int i;
    for(i=N-1; i>=0; i--) {
        if((int)anc[a].size()>i) {
            if(anc[a][i]!=anc[b][i]) {
                a = anc[a][i];
                b = anc[b][i];
            }
        }
    }
    return anc[a][0];
}

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vis.resize(n);
    g.resize(n);
    d.resize(n);
    anc.resize(n);

    int i,j;
    for(i=0; i<n; i++) {
        int num;
        scanf("%d", &num);
        for(j=0; j<num; j++) {
            int tmp;
            scanf("%d", &tmp);
            g[i].push_back(tmp);
            g[tmp].push_back(i);
        }
    }

    vector<int> vv;
    dfs(0, vv );

    int q;
    scanf("%d", &q);
    for(i=0; i<q; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        int p = getanc(a, b);

        printf("%d\n", p);
    }
 
    return 0;
}



Measured memory_bytes: 26144
#include <iostream>
using namespace std;
int main(){
  int N;cin>>N;
  int P[N];
  for (int i=0;i<N;++i)cin>>P[i];
  
  int ans=0;
  for (int i=1;i<N-1;++i){
    if (P[i-1]<P[i] && P[i]<P[i+1])++ans;
    if (P[i-1]>P[i] && P[i]>P[i+1])++ans;
  }
  cout<<ans<<endl;
}
    


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int main(void)
{
	char S[60], T[60];
	char ANS[120];
	int count = 0;
	scanf("%s%s", S, T);
	//printf("%s%s", S, T);
	//return 0;
	int i = 0;
	int y = 0;
	int x = 0;
	while (1) {

		if (i % 2 == 0) {
			ANS[i] = S[i-y];
			if (S[i-y] == '\0') {
				count++;
			}
			x++;

		}
		else {
			ANS[i] = T[i-x];
			if (T[i-x] == '\0') {
				count++;
			}
			y++;
		}
		i++;
		if (count == 2)
			break;
		
	}
	printf("%s", ANS);
	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int n,a,ans;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a;
		ans+=a-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll;
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; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N;
int A[2 * MAX];

int main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }

    ll ans = 0;
    int sumxor = A[0];
    int sumadd = A[0];
    for (int i = 0, j = 0; i < N; ) {
        ans += j - i;
        while (j < N) {
            if (sumxor != sumadd) {
                break;
            }
            ans++;
            j++;
            if (j >= N) break;
            sumxor ^= A[j];
            sumadd += A[j];
        }
        sumxor ^= A[i];
        sumadd -= A[i];
        i++;
    }
    write(ans);
}

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

#define int long long

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

    int sum = 0;
    for(int i = 0; i < s.size(); i++) {
        sum += (int)s[i] - '0';
    }

    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N, M;
    cin >> N >> M;
    vector<int> box(N, 1), prob(N, 0);
    prob[0] = 1;
    REP(i, M){
        int x, y;
        cin >> x >> y;
        x--; y--;
        if(box[y] == 0) prob[y] = prob[x];
        else prob[y] = prob[x] | prob[y];
        box[x]--;
        box[y]++;
    }
    int ans = 0;
    REP(i, N){
        //cout << box[i] << " " << prob[i] << "\n";
        if(box[i] != 0 && prob[i] == 1) ans++;
    }

    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n,ans="No";cin>>n;
  if(n[0]==n[1]&&n[1]==n[2])ans="Yes";
  if(n[1]==n[2]&&n[2]==n[3])ans="Yes";
  cout <<ans<<endl;
}

Measured memory_bytes: 256
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL N,K;
    R(N,K);
    N%=K;
    W(min(N,K-N));
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = tuple(map(int, input().split(' ')))

bits = [0] * (N + 1)

i = N
while i > 0:
    j = i
    ones = 0
    while j <= N:
        ones += bits[j]
        j += i
    if ones % 2 != A[i - 1]:
        bits[i] = 1
    i -= 1

indexes = []
for i in range(1, N + 1):
    if bits[i] == 1:
        indexes.append(i)

print(len(indexes))
if indexes:
    print(*indexes)


Measured memory_bytes: 17732
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
ll dp[3001][3001];
ll arr[3001];
ll ana;
ll n;
ll solve(ll index,ll sum){
  ll ans=0;
  if(index==n){
    if(!sum)return 1;
    return 0;
  }
  if(dp[index][sum]!=-1)return dp[index][sum];
  if(sum-arr[index]>=0){
    ans=(ans+solve(index+1,sum-arr[index]))%998244353;
  }
  ans=(ans+2*solve(index+1,sum))%998244353;
  return dp[index][sum]=ans;
}
int main()
{
  ll s;
  cin>>n>>s;
  memset(dp,-1,sizeof dp);
  for (int i = 0; i < n; ++i)
  {
    cin>>arr[i];
  }
  cout<<solve(0,s);
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 74124
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_V = 1010;
const int MAX_E = 2010;
 
struct edge{int from, to, cost; };
 
edge es[MAX_E];
 
ll d[MAX_V];
int V, E;
 
void shortest_path(int s) {
    // for(int i = 0; i < V; i++) d[i] = INF;
    // d[s] = 0;
    // while(true){
    rep(_, 2*E){
        bool update = false;
        for(int i = 0; i < E; i++) {
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}

int main(){
    cin >> V >> E;
    rep(i, E) {
        cin >> es[i].from >> es[i].to >> es[i].cost;
        --es[i].from;
        --es[i].to;
        es[i].cost *= -1;
    }
    for(int i = 0; i < V; i++) d[i] = INF;
    d[0] = 0LL;
    shortest_path(0);
    auto tmp = d[V-1];
    shortest_path(0);
    if(tmp != d[V-1]) cout << "inf" << endl;
    else cout << -d[V-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  int n, h, w;
  cin >> n >> h >> w;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  int ans = 0;
  rep(i, n) {
    if (a[i] >= h && b[i] >= w) ans++;
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;
int main(){
	//乱数srand((unsigned)time(NULL));
	ll N; cin>>N;
	vll a(N); rep(i,N) cin>>a[i];
	ll mans=1;
	rep(i,N){
		if(mans==a[i]) mans++;
	}
    if(mans==1) cout<<-1<<endl;
	else cout<<N-mans+1<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;
int h,w;
char board[10][10];
bool used[10][10];
bool check(int i, int j) {
	return (i >= 1) && (i <= h) && (j >= 1) && (j <= w) && (board[i][j] == '#')&&(!used[i][j]);
}
bool dfs(int i,int j){
    if(i==h&&j==w){
        int num=0;
        if(check(i-1,j))num++;
        if(check(i,j-1))num++;

        if(num==0)return true;
        else return false;
    }
    int up=0,down=0,left=0,right=0;
    if(check(i+1,j))down++;
    if(check(i,j+1))right++;
    if(check(i-1,j))up++;
    if(check(i,j-1))left++;

    if((up!=0)||(left!=0))return false;
    else{
        if((down==1)&&(right==1))return false;
        else{
            if(down==1){
                used[i][j]=true;
                return dfs(i+1,j);
            }
            else{
                if(right==1){
                    used[i][j]=true;
                    return dfs(i,j+1);
                }
                else return false;
            }
        }
    }
}

int main(void){
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>board[i][j];
        }
    }
    if(dfs(1,1))cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut dp = vec![0; 45];
    dp[0] = 1;
    dp[1] = 1;
    for i in 0..n - 1 {
        dp[i + 2] = dp[i] + dp[i + 1];
    }
    println!("{}", dp[n]);
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int n;
    cin >>n >> s;
    
    for (int i = 0; i < s.length();i++) {
        s[i] += n;
        if (s[i] > 90) {
            s[i] -= 26;
        }
    }
    cout << s;
}

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

using namespace std;
int n;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    int mn = 1e9;
    for (int i = 1; i < n; i++) {
        int a = i;
        int b = n - i;
        int s = 0;
        while (a != 0) {
            s += a % 10;
            a /= 10;
        }
        while (b != 0) {
            s += b % 10;
            b /= 10;
        }
        if (s < mn) mn = s;
    }
    cout << mn << "\n";
    return 0;
}


Measured memory_bytes: 384
#include <utility>
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
inline ll quick_pow(ll a, int n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
int arr[105];
std::pair<ll, ll> work(int l, int r, int d)
{
	int pos = l;
	for (int i = l; i <= r; i++)
	{
		if (arr[i] < arr[pos])
			pos = i;
	}
	ll val = quick_pow(2, arr[pos] - d);
	if (l == r)
		return {val, val};
	if (pos == l)
	{
		auto res = work(l + 1, r, arr[pos]);
		return {(2 * res.first + (val - 1) * res.second) % MOD, val * res.second % MOD};
	}
	if (pos == r)
	{
		auto res = work(l, r - 1, arr[pos]);
		return {(2 * res.first + (val - 1) * res.second) % MOD, val * res.second % MOD};
	}
	auto x = work(l, pos - 1, arr[pos]), y = work(pos + 1, r, arr[pos]);
	return {4 * x.first % MOD * y.first % MOD + (val - 1) * x.second % MOD * y.second % MOD
		, val * x.second % MOD * y.second % MOD};
}
int main()
{
	// freopen("AGC026-D.in", "r", stdin);
	int n; 
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", arr + i);
		arr[i]--;
	}
	printf("%lld\n", work(0, n - 1, 0).first * 2 % MOD);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;  //10000  5000  1000
int main()
{
	int a,b,c,m,n,p=0;
	int e1,e2,e3;
	cin>>m>>n;
	for(int i=0;i<=m;i++)
		for(int j=0;j<=m-i;j++)
			for(int o=0;o<=m-j-i;o++)
				if(i+j+o==m&&10000*i+5000*j+1000*o==n)
				{
					p=1;
					e1=i;e2=j;e3=o;
				}
	if(p==0)
	{
		cout<<"-1 -1 -1";
		return 0;
	}
	else cout<<e1<<" "<<e2<<" "<<e3;
	return 0;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

llint my_binary_search(llint ary[], llint key, llint left, llint right) {
	llint middle;
	if (right < left) {
		return -(INF64);
	} else {
		middle = left + (right - left) / 2;
		if (ary[middle] > key) {
			return my_binary_search(ary, key, left, middle - 1);
		} else if (ary[middle] < key) {
			return my_binary_search(ary, key, middle + 1, right);
		} else {
			return middle;
		}
	}
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}
	
	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	
	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}
	
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main (void)
{
	//INPUT
	llint X;
	cin >> X;
	
	
	//SOLVE
	// llint ans=0;
	// llint dp[6][X+1];
	// llint val[6];
	// llint buf;
	// 
	// val[0] = 100;
	// val[1] = 101;
	// val[2] = 102;
	// val[3] = 103;
	// val[4] = 104;
	// val[5] = 105;
	// 
	// 
	// for(llint i=0;i<=5;i++) {
	// 	for(llint j=0;j<=X;j++) {
	// 		dp[i][j] = 0;
	// 	}
	// }
	// 
	// for(llint i=0;i<=4;i++) {
	// 	for(llint j=0;j<=X-1;j++) {
	// 		dp[i+1][j] = dp
	// 	}
	// }
	// dp[1] = 
	
	
	llint modbuf = X % 100;
	
	llint bufn=0;
	
	llint ans = 0;
	
	for(llint i=5;i>=1;i--) {
		bufn+= modbuf/i;
		modbuf %= i;
	}
	
	if (bufn * 100 <= X) {
		ans = 1;
	} else {
		ans = 0;
	}
	
	//OUTPUT
	cout << ans << endl;
	
	return 0;
}






Measured memory_bytes: 256
sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Measured memory_bytes: 38384
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;

vector<long long> enum_div(long long n)//nの約数を列挙
{
	std::vector<long long> ret;
	for (long long i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

int main()
{
	long long n;
	cin >> n;
	
	vector<long long> r = enum_div(n);
	long long ans = 0;
	
	for (long long i = 0; i < r.size(); i++) {
		long long m = n / r[i] - 1;

		if (m != 1 && m > r[i]) {
			ans = ans + n / r[i] - 1;
			
		}
	}

	cout << ans << endl;
	return 0;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n,m;
	cin>>n>>m;
	vector<vi> arr(n+1,vi());
	while(m--) {
		int a,b;
		cin>>a>>b;
		arr[a].push_back(b);
		arr[b].PUB(a);
	}
	bool r = false;
	for(int i:arr[1]) {
		for(int j:arr[i]) {
			if(j==n) {
				r=true;
				break;
			}
		}
		if(r)break;
	}
	cout<<(r?"POSSIBLE":"IMPOSSIBLE");
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 14944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, ans, a[22], b[22], c[22];

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) cin >> a[i];
	FOR(i, 1, n) cin >> b[i];
	FOR(i, 1, n-1) cin >> c[i];
	FOR(i, 1, n) {
		ans += b[a[i]];
		if (a[i+1] == a[i] + 1) ans += c[a[i]];
	}
	cout << ans;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    set<int> st;
    rep(i, n){
        int in;
        cin >> in;
        st.insert(in);
    }
    if(st.size() == n) YES();
    else NO();
}

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

int main(void){
    
    string S;
    cin >> S;
    string ans = "";
    for(int i = 0; i < S.size();i++){
        
        if(S[i]!='B')ans +=S.substr(i,1);
        else {
            if(ans.size()>=1)ans.erase(ans.size()-1,1);
        }
        //cout << ans <<endl;
    }
    cout << ans <<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n,m,l; cin >> n >> m >> l;
  ll G[n][n];
  rep(i,n) rep(j,n) {
    if(i == j) G[i][j] = 0;
    else G[i][j] = G[j][i] = INF;
  }
  rep(i,m) {
    int a,b,c; cin >> a >> b >> c;
    a--; b--;
    G[a][b] = G[b][a] = c;
  }

  rep(k,n) rep(i,n) rep(j,n) chmin(G[i][j], G[i][k] + G[k][j]);

  ll ans[n][n];
  rep(i,n) rep(j,n) {
    if(i == j) ans[i][j] = 0;
    else ans[i][j] = ans[j][i] = INF;
  }

  rep(i,n) rep(j,n) if(G[i][j] <= l) ans[i][j] = ans[j][i] = 1;

  rep(k,n) rep(i,n) rep(j,n) chmin(ans[i][j], ans[i][k] + ans[k][j]);

  int Q; cin >> Q;
  rep(q,Q) {
    int s,t; cin >> s >> t; s--; t--;
    ll sol = ans[s][t];
    if(sol == INF) sol = 0;
    cout << sol-1 << endl;
  }
}

Measured memory_bytes: 1920
/* author: Tarek */ 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
int k;
cin>>n>>k;
if(n!=1&&k!=1)cout<<"1"<<endl;
else if(n!=2&&k!=2)cout<<"2"<<endl;
else cout<<"3"<<endl;
       	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define PB push_back
#define REP(i,a,b) for(int i=a; i<b; i++)
typedef long long ll;
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k,q=0,ans=0;
	cin>>k;
	string s;
	cin>>s;
	for(int i=0; i<k; i++){
		if(s[i]=='R') q++;
	}
	for(int i=0; i<q; i++){
		if(s[i]=='W') ans++;
	}
	cout<<ans;
}

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


char const ch[4] = {'m', 'c', 'x', 'i'};
int const d[4] = {1000, 100, 10, 1};

int sptoi(char*s)
{
  int num = 1, ans = 0;
  while(*s) {
    for (int i = 0; i < 4; i++)
      if (*s == ch[i])
        ans += d[i] * num;
    
    if (isdigit(*s))
      num = *s - '0';
    else
      num = 1;
    
    s++;
  }
  return ans;
}


int main()
{
  int N;
  cin >> N;
  while (N--) {
    char sp1[10], sp2[10];
    cin >> sp1 >> sp2;

    int sum = sptoi(sp1) + sptoi(sp2);

    char sp[10];
    for (int i = 0; i < 4; i++) {
      int x = sum / d[i];
      sum %= d[i];

      if (x >= 2)
        cout << x;
      if (x >= 1)
        cout << ch[i];
    }
    cout << endl;
  }
    
}

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

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

    set<char> value;
    for (int i=0; i<s.size(); i++) value.insert(s[i]);

    for (char c='a'; c<='z'; c++) {
        if (value.count(c) == 0) {
            cout << c << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}


Measured memory_bytes: 512