akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void){
    int R;
    cin >> R;
    if(R>=2800)
        cout << "AGC" << endl;
    else if(R>=1200)
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int x, y;
    cin >> x >> y;
    int s = -1, t = -1;
    if ((y - 2 * x) % 2 == 0)
        t = (y - 2 * x) / 2;
    s = x - t;
    if (s < 0 || t < 0)
    {
        c("No");
    }
    else
    {
        c("Yes");
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) cout<<#v<<": ";for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}


void solve(long long N){
  vector <ll> res;
  ll minv = 0;

  double boundary = sqrt(N);
  for (ll i = 1; i <= boundary; i++)
  {
    if(N%i==0){
      res.push_back(i);
      minv = max(i, minv);
      if(i != (N/i) && i*i != N){
        res.push_back(N/i);
      }
    }
  }
//   vout(res);

  ll gx = 0, gy = 0;
  gx = minv;
  gy = N/minv;

  cout << gx-1 + gy-1 << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
 
	// 解法
	ll ippen = y2-y1;
	ll x3 = x2 - y2 + y1;
	ll y3 = y2 + (x2 -  x1);
	ll x4 = x3 - (y3 - y2);
	ll y4 = y3 + (x3 - x2);
	printf("%d %d %d %d\n", x3, y3, x4, y4);
}
 


Measured memory_bytes: 256
s = input()
n = len(s)
target1 = s
target2 = s

count = 0
ans = 0
for i in range(n):
	if i % 2 == 0 and target1[i] == "1":
		count += 1
	elif i % 2 and target1[i] == "0":
		count += 1
	
	if i % 2 == 0 and target2[i] == "0":
		ans += 1
	elif i % 2 and target2[i] == "1":
		ans += 1
		
print(min(count, ans))
	

Measured memory_bytes: 3188
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
	print(0)
else:
	X.sort()
	Y = [0] * (M - 1)
	for i in range(M - 1):
		Y[i] = X[i+1] - X[i]
	Y.sort(reverse = True)
	print(max(X) - min(X) - sum(Y[:N - 1]))

Measured memory_bytes: 13968
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N;
	scanf("%d",&N);

	int maximum = 0,tmp,succeed_count = 0;
	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		if(tmp == 1){
			succeed_count++;
		}else{
			maximum = max(maximum,succeed_count);
			succeed_count = 0;
		}
	}
	maximum = max(maximum,succeed_count);

	printf("%d\n",maximum+1);

	return 0;
}



Measured memory_bytes: 3220
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<String, Integer> nMap = new HashMap<>();
		for (int i = 0; i < N; i++) {
			String s = sc.next();
			if (nMap.containsKey(s)) {
				Integer sAmount = nMap.get(s) + 1;
				nMap.put(s, sAmount);
			} else {
				nMap.put(s, 1);
			}
		}

		int M = sc.nextInt();
		Map<String, Integer> mMap = new HashMap<>();
		for (int i = 0; i < M; i++) {
			String t = sc.next();
			if (mMap.containsKey(t)) {
				Integer tAmount = mMap.get(t) - 1;
				mMap.put(t, tAmount);
			} else {
				mMap.put(t, -1);
			}
		}

		int maxAmount = 0;
		for (Entry<String, Integer> entry : nMap.entrySet()) {
			int currentAmount = entry.getValue();
			if (mMap.containsKey(entry.getKey())) {
				currentAmount += mMap.get(entry.getKey());
			}
			if (maxAmount < currentAmount) {
				maxAmount = currentAmount;
			}
		}

		// 出力
		System.out.println(maxAmount);

		sc.close();
	}
}


Measured memory_bytes: 22996
#N,P = map(int,input().split())
s = list(input())
N = len(s)
P = 2019
S = [0]*N

for i in range(N):
    S[i] = int(s[i])

count = 0

if P != 2 and P != 5:
    now = 0
    remainder = []
    for i in range(1,N+1):
        now += S[N-i] * (pow(10,(i-1),P) )
        remainder.append(now % P)

    result={}
    for i in range (0,len(remainder)):
        item = remainder[i]
        if item in result:
            result[item] = result[item]+1
        else:
            result[item] = 1

    for k in result.keys():
        if k == 0:
            if result[0] >= 2:
                count += result[0] + result[0]*(result[0]-1)//2
            else:
                count += result[0]
        else:
            count += result[k]*(result[k]-1)//2

print(count)

Measured memory_bytes: 96160
// atcoder - dp - 
#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

int n, h[N], dp[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	for (int i = 0; i < n-1; i++) {
		dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
		dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int> 
#define rep(i,a,n) for(i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int i,int n,vin &a){
    rep(i,0,n){
        cin>>a.at(i);
    } 
} 

signed main() {
    int i;
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }
    else{
        cout<<"win"<<endl;
    }

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 5;

struct node {
	int t, x, y;
} arr[MAXN];

bool cmp(node a, node b) {
	return a.t < b.t;
}

int abs(int x) {
	return x < 0 ? -x : x;
}

int dis(int i, int j) {
	return abs(arr[i].x - arr[j].x) + abs(arr[i].y - arr[j].y);
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d%d", &arr[i].t, &arr[i].x, &arr[i].y);
	}
	sort(arr, arr + n + 1, cmp);
	bool flag = true;
	for(int i = 0; i < n; ++i) {
		int d = dis(i, i + 1);
		int r = arr[i + 1].t - arr[i].t;
		if(d > r || (r - d) % 2 == 1) flag = false;
	}
	puts(flag ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 1280
n,m= input().split()
n = int(n)
m = int(m)
g=[input().split() for i in range(m)]
av =[-1,1000000]
for i in range(m):
  av[0] = max(int(g[i][0]),av[0])
  av[1] = min(int(g[i][1]),av[1])
print(max(av[1] -av[0]+1,0))

Measured memory_bytes: 32148
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;cin>>N;
	int ans = 0;
	rep(i,N){
		int t; cin>>t;
		while(t%2==0){
			++ans;
			t /= 2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int fanc(void );

int n, G[MAX][MAX];

int main(){
    int i,j,e;

    scanf("%d", &n);

    for(i = 0; i < n; i++ ){
        for(j = 0; j < n; j++ ){
           scanf("%d", &e);
           if(e == -1) G[i][j] = INFTY;
           else G[i][j] = e;
        }
    }

    printf("%d\n", fanc());

    return 0;
}

int fanc(void ){
    int i,u,v,sum,minv;
    int d[MAX],p[MAX],color[MAX];

    for(i = 0; i < n; i++ ){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while(1){
        minv = INFTY;
        u = -1;
        for( i = 0; i < n; i++ ){
            if( minv > d[i] && color[i] != BLACK ){
                u = i;
                minv = d[i];
            }
        }
        if( u == -1 ) break;
        color[u] = BLACK;
        for( v = 0; v < n; v++ ){
            if( G[u][v] != INFTY && color[v] != BLACK ){
                if(d[v] > G[u][v]) {
                    d[v] = G[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }

    sum = 0;
    for( i = 0; i < n; i++ ){
        if(p[i] != -1 ) {
          sum += G[i][p[i]];
        }
    }

    return sum;

}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string s, t;
  int N;
  cin >> N >> s >> t;
  REP(i, N) {
    if (s.substr(i, N - i) == t.substr(0, N - i)) {
      cout << 2 * N - (N - i) << endl;
      return 0;
    }
  }
  cout << 2 * N << endl;
}

Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()

    dp = [[0, 0] for _ in range(N+1)]
    # print(dp)
    dp[0][0] = (1000, 0)
    dp[0][1] = (0, 0)
    # print(dp)

    def buy(lst, a):
        mon, stock = lst
        n = mon // a
        mon = mon - n * a
        stock += n
        return mon, stock

    def sell(lst, a):
        mon, stock = lst
        mon += stock * a
        stock = 0
        return mon, stock

    for i in range(1, N+1):
        a = A[i-1]

        # Buy
        bb = buy(dp[i-1][0], a)
        sb = buy(dp[i-1][1], a)

        if bb[1] == sb[1]:
            if bb[0] > sb[0]:
                dp[i][0] = bb
            else:
                dp[i][0] = sb
        elif bb[1] > sb[1]:
            dp[i][0] = bb
        else:
            dp[i][0] = sb

        # Sell
        bs = sell(dp[i-1][0], a)
        ss = sell(dp[i-1][1], a)
        if bs[0] > ss[0]:
            dp[i][1] = bs
        else:
            dp[i][1] = ss

        # print(dp)

    print(max(dp[N][0][0], dp[N][1][0]))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 27196
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int main()
{
	vector<int> vec;
	vec.resize(3);
#if 1
	cin >> vec[0] >> vec[1] >> vec[2];
#else
	vec[0] = 1;
	vec[1] = 3;
	vec[2] = 4;
#endif

	int ans = vec[0]+vec[1]+vec[2];
	ans = std::min(ans, vec[0] + vec[1]);
	ans = std::min(ans, vec[2] + vec[1]);
	ans = std::min(ans, vec[2] + vec[0]);
	cout << ans << endl;

	return 0;
}

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


int main(){
  int a,b,c,x;cin>>a>>b>>c>>x;
  int n=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
     for(int k=0;k<=c;k++){
       int tmp=i*500+j*100+k*50;
       if(tmp==x)n++;
     }
    }
  }
  cout<<n<<endl;
  return 0;
}


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

int main()
{
  string T, S;
  cin >> T >> S;
  
  int count = 0;
  for(int i = 0; i < T.length(); i++)
  {
     if(T[i] == S[i])
       count++;
   }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <cmath>


using namespace std;

//  ||
// \

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        for (int i = 0; i <= N ; i ++) {
            //iを6^pで表現
            int count = 0;
            int t = i;
            while (t > 0) {
                count += t % 6;
                t /= 6;
            }
            int u = N - i;
            while (u > 0) {
                count += u % 9;
                u /= 9;
            }
            ans = Math.min(count, ans);
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 21332
def tentwo(N):
    ret = [0] * 60
    NN = N
    for i in range(60):
        ret[i] = NN % 2
        NN //= 2
    return ret

N = int(input())

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

B = [0] * N

for i in range(N):
    B[i] = tentwo(A[i])

ans = 0
for j in range(60):
    count = 0
    for i in range(N):
        if B[i][j] == 1:
            count += 1
    ans = (ans + (count * (N-count)) * (2 ** j)) % (10**9 + 7)

print(ans)

Measured memory_bytes: 203212
#include <cstdio>
#include <algorithm>
#include <cstring> 
using namespace std;
const int N=10,INF=0x3f3f3f3f;
int n,d[N][N],c,x,y,m;
int main(){
    while(~scanf("%d",&m),m){
        memset(d,INF,sizeof(d)); n=0;
        while(m--){
            scanf("%d%d%d",&x,&y,&c);
            d[x][y]=d[y][x]=c;
            n=max(n,max(x,y));
        }
        for(int k=0;k<=n;k++)
            for(int i=0;i<=n;i++)
                for(int j=0;j<=n;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        int ans=INF,pos=0;
        for(int i=0;i<=n;i++){
            int tmp=0;
            for(int j=0;j<=n;j++)if(i!=j)tmp+=d[i][j];
            if(tmp<ans)ans=tmp,pos=i;
        }printf("%d %d\n",pos,ans);
    }return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 999999999ll
#define MIN -999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define gcd(x,y) __gcd(x,y) 
#define Gput(a,b) G[a].push_back(b)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*(y/z);
}
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
vector<bool> seen;
void dfs(const Graph &G,ll v){
    seen[v]=true;
    for(auto nextv:G[v]){ 
        if(seen[nextv])continue;
        dfs(G,nextv);
    }
}
ll fact(ll n){
ll sum=0;
Loop(i,1,n+1){
sum+=i;
}
return sum;

}
int main() {
  cout << fixed << setprecision(16);
ll n;
cin>>n;
vector<string> s(n);
map<string,ll> count;
loop(i,n){
cin>>s[i];
sort(all(s[i]));
count[s[i]]++;
}
ll ans=0;
loop(i,n){
if(count[s[i]]>1){
ans+= fact(count[s[i]]-1);
count[s[i]]=0;
}
}
putout(ans);
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n);
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector<ll> ans(n);
    int INF = 1e9;
    for(int i = 0; i < n; i++)
    {
        ans[i] = INF;
    }
    int k;
    cin >> k;
    using P = pair<ll, int>;
    priority_queue<P> que;
    for(int i = 0; i < k; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        que.push(P(y, x));
    }
    while(!que.empty())
    {
        P p = que.top();
        que.pop();
        int now = p.second;
        if(ans[now] == p.first) continue;
        else if(ans[now] != INF && ans[now] != p.first)
        {
            cout << "No" << endl;
            return 0;
        }
        ans[now] = p.first;
        for(int i = 0; i < v[now].size(); i++)
        {
            int next = v[now][i];
            if(ans[next] == INF)
            {
                que.push(P(p.first-1, next));
            }
            else
            {
                if(ans[next] != p.first - 1 && ans[next] != p.first + 1)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 12144
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector> 
#include <algorithm>

using namespace std;

int main(){
	
	int k,n,p,output=0,i;
	vector<int> res = {};
	 cin >> n>>k;
    while(n--){
    	
        cin >> p;
        res.insert(res.end(),p);
    
	
} 
sort(res.begin(), res.end()); 
for(i=0;i<k;i++){
	output+=res[i];
}


//cout<<res[0]<<" "<<res[1]<<" "<<res[2]<<" "<<res[3];
cout<<output;
    
	
	return 0;
	
	
	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) {
    return cout << "(" << p.first << ", " << p.second << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    cout << "{"; for (int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "}"; }
const ld EPS = 0.0000000000001;
const int TIMES = 1000;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k; cin >> n >> k;
    vector<ld> x(n), y(n), c(n);
    map<pair<ll, ll>, int> cnt;
    cout << fixed << setprecision(100);
    for (int i = 0; i < n; i++) {
        ll xx, yy, cc; cin >> xx >> yy >> cc;
        x[i] = xx; y[i] = yy; c[i] = cc;
        cnt[make_pair(xx, yy)]++;
    }
    for (auto p: cnt) {
        if (p.second >= k) {
            cout << 0 << '\n';
            return 0;
        }
    }
    auto dist = [&](ld a, ld b, ld c, ld d) -> ld {
        return sqrt((a - c) * (a - c) + (b - d) * (b - d));
    };
    auto check = [&](ld xx, ld yy, ld t) -> bool {
        int res = 0;
        for (int i = 0; i < n; i++) {
            ld d = dist(xx, yy, x[i], y[i]);
            if (d * c[i] <= t + EPS) {
                res++;
            }
        }
        return res >= k;
    };
    ld lo = 0;
    ld hi = 1e6;
    for (int iter = 0; iter < TIMES; iter++) {
        ld mid = (lo + hi) / 2;
        ld t = mid;
        bool ok = false;
        for (int i = 0; i < n && !ok; i++) {
            for (int j = i + 1; j < n && !ok; j++) {
                ld ri = t / c[i];
                ld rj = t / c[j];
                ld d = dist(x[i], y[i], x[j], y[j]);
                ld ri2 = ri * ri;
                ld rj2 = rj * rj;
                ld d2 = d * d;
                ld sq = (2 * (ri2 + rj2) / d2 - (ri2 - rj2) * (ri2 - rj2) / (d2 * d2) - 1);;
                if (sq < 0) continue;
                sq = sqrt(sq);
                ld xx = (x[i] + x[j]) / 2;
                xx += (ri2 - rj2) / (2 * d2) * (x[j] - x[i]);
                ld yy = (y[i] + y[j]) / 2;
                yy += (ri2 - rj2) / (2 * d2) * (y[j] - y[i]);
                ld xa = sq / 2 * (y[j] - y[i]);
                ld ya = sq / 2 * (x[i] - x[j]);
                ok |= check(xx + xa, yy + ya, t);
                ok |= check(xx - xa, yy - ya, t);
            }
        }
        for (int i = 0; i < n; i++) {
            ok |= check(x[i], y[i], t);
        }
        if (ok) hi = mid;
        else lo = mid;
    }
    cout << (lo + hi) / 2 << '\n';
    return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using namespace atcoder;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll k;
  cin >> k;
  rep(i, k) cout << "ACL";
  cout << endl;

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define Maxn 100007
int n,ans=0;
pair<int,int> q[Maxn];
set<pair<int,int> >s1,s2;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d%d",&q[i].first,&q[i].second);
    sort(q+1,q+n+1);
    s1.clear();
    for (int i=1;i<=n;i++)
        s1.insert(make_pair(q[i].second,i));
    s2.clear();
    for (int i=1;i<=n;i++)
        s2.insert(make_pair(-q[i].first,i));
    for (int i=1;i<=n;i++)
    {
        s1.erase(make_pair(q[i].second,i));
        s2.erase(make_pair(-q[i].first,i));
        ans=max(ans,max(0,q[i].second-q[i].first+1)+max(0,(*s1.begin()).first+(*s2.begin()).first+1));
        s1.insert(make_pair(q[i].second,i));
        s2.insert(make_pair(-q[i].first,i));
    }
    int mn=1000000000;
    for (int i=1;i<n;i++)
    {
        mn=min(mn,q[i].second);
        s1.erase(make_pair(q[i].second,i));
        s2.erase(make_pair(-q[i].first,i));
        ans=max(ans,max(0,mn-q[i].first+1)+max(0,(*s1.begin()).first+(*s2.begin()).first+1));
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }


//codefes2016FinalC

#define MAX_N 200000
int par[MAX_N+1]; //親
int ran[MAX_N+1]; //木の深さ

//n要素で初期化
void init(int n) {
    rep(i,n) {
		par[i] = i; ran[i] = 0;
	}
}

//木の根を求める
int root(int x){ return par[x]==x ? x : par[x]=root(par[x]); }

//x,yの属する集合の併合
void unite(int x, int y) {
	x = root(x); y = root(y);
	if(x == y) return ;

	if(ran[x] < ran[y]) par[x] = y;
	else {
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}

//x,yが同じ集合に属するか
bool same(int x, int y) { return root(x) == root(y); }




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

    int n, q; cin >> n >> q;
    init(n);
    rep(i,q) {
        int cmp, x, y; cin >> cmp >> x >> y;
        if(cmp == 0) unite(x, y);
        else {
            if(same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define lson root<<1
#define rson root<<1|1
using namespace std;

int n;
int a[200010];
int sum[200010];

struct node
{
	int l, r, sum;
}tr[1600080];

int push_up(int root)
{
	tr[root].sum = tr[lson].sum + tr[rson].sum;
}

int build(int root, int l, int r)
{
	if (l == r)
	{
		tr[root].sum = 0;
		tr[root].l = l;
		tr[root].r = r;
		return 0;
	}
	tr[root].l = l;
	tr[root].r = r;
	int mid = (l + r) >> 1;
	build(lson, l, mid);
	build(rson, mid + 1, r);
	push_up(root);
}

int update(int root, int pos)
{
	if (pos == tr[root].l&&pos == tr[root].r)
	{
		tr[root].sum++;
		return 0;
	}
	int mid = (tr[root].l + tr[root].r) >> 1;
	if (pos <= mid)
	{
		update(lson, pos);
	}
	else
	{
		update(rson, pos);
	}
	push_up(root);
}

int query(int root, int l, int r)
{
	if (l > r) return 0;
	if (l <= tr[root].l&&tr[root].r <= r) return tr[root].sum;
	int mid = (tr[root].l + tr[root].r) >> 1;
	if (r <= mid)
	{
		return query(lson, l, r);
	}
	else
	{
		if (l > mid)
		{
			return query(rson, l, r);
		}
		else
		{
			return query(lson, l, mid) + query(rson, mid + 1, r);
		}
	}
}

int check(int x)
{
	long long ans = 0;
	memset(sum, 0, sizeof(sum));
	for (int i = 1; i <= n; i++)
	{
		sum[i] = sum[i - 1] + ((a[i] <= x) ? 1 : -1);
	}
	for (int i = 0; i <= n; i++)
	{
		sum[i] += n + 1;
	}
	build(1, 1, 200010);
	for (int i = 0; i <= n; i++)
	{
		ans += query(1, 1, sum[i] - 1);
		update(1, sum[i]);
	}
	return ans >= 1ll * n*(n + 1) / 4 + 1;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	int l = 1, r = 1e9, mid;
	while (l <= r)
	{
		mid = (l + r) >> 1;
		if (check(mid))
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
		if (r - l <= 1)
		{
			mid = check(l) ? l : r;
			break;
		}
	}
	printf("%d\n", mid);
}

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

int main(){
 
  string S;
  cin >> S;
  
  if (S == "Sunny"){
   
    cout << "Cloudy" << endl;
  }else if(S == "Rainy"){
    
    cout << "Sunny" << endl;
  }else{
    
    cout << "Rainy" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let N = scan.word::<usize>();
    let M = scan.word::<usize>();
    let H = scan.list::<usize>(N);

    let mut bad = vec![false; N];
    for _ in 0..M {
        let u = scan.word::<usize>() - 1;
        let v = scan.word::<usize>() - 1;

        if H[u] <= H[v] {
            bad[u] = true;
        }
        if H[v] <= H[u] {
            bad[v] = true;
        }
    }

    let count = (0..N).filter(|&u| !bad[u]).count();

    println!("{}", count);
}


Measured memory_bytes: 8000
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif 

using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#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 fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

void a();void b();void c();void d();void e();void f();

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

	// a();
	b();
	// c();
	// d();
	// e();
	// f();
	return 0;
}

void a(){
	string s;
	cin >> s;
	if(s == "ABC")puts("ARC");
	else puts("ABC");
}

void b(){
	int n, k;
	cin >> n >> k;
	vi adj[1500];
	forn(i, k){
		int d;
		cin >> d;
		forn(j, d){
			int x;
			cin >> x;
			adj[x].pb(i);
		}
	}
	int c = 0;
	for1(i, n){
		if(adj[i].size() == 0)c++;
	}
	cout << c;
}

void c(){

}

void d(){

}

void e(){

}

void f(){

}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8, pi = acos(-1.0);
bool eq(ld a, ld b){return (abs(b-a)<eps);}
ld dot(Point a, Point b){return real(conj(a)*b);}
ld cross(Point a, Point b){ return imag(conj(a)*b);}
int ccw(Point a, Point b, Point c){
  b-=a;c-=a;
  if(cross(b,c)>eps) return 1;//countor_crockwise
  if(cross(b,c)<-eps) return -1;//crockwise
  if(dot(b,c)<0) return 2;//c,a,b
  if(norm(b)<norm(c)) return -2;//a,b,c
  return 0;//a,c,b
}

int main(){
  ld xa,ya,xb,yb,xc,yc,xd,yd;
  Point a,b,c,d;
  while(scanf("%Lf,%Lf,%Lf,%Lf,%Lf,%Lf,%Lf,%Lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=-1){
    a=Point(xa,ya);
    b=Point(xb,yb);
    c=Point(xc,yc);
    d=Point(xd,yd);
    int abc = ccw(a,b,c);
    int bcd = ccw(b,c,d);
    int cda = ccw(c,d,a);
    int dab = ccw(d,a,b);
    if((abc==1&&bcd==1&&cda==1&&dab==1)||(abc==-1&&bcd==-1&&cda==-1&&dab==-1))
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1220
using System;
using System.Linq;

namespace A.Cats_and_Dogs
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABX = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = ABX[0];
            var B = ABX[1];
            var X = ABX[2];

            bool flg1 = X >= A;
            bool flg2 = X <= A + B;

            Console.WriteLine(flg1 && flg2 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13268
import sys
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))


def ok(x):
    b = []
    for an in a:
        b.append(an % x)
    b.sort(reverse=True)
    print(x, a, b, file=sys.stderr)
    t = int(sum(b) / x)
    print(t, sum(b[t:]), file=sys.stderr)
    if t == 0:
        return True
    return True if sum(b[t:]) <= k else False


s = 0
for an in a:
    s += an

ans = 1
for x in range(1, int(math.sqrt(s)) + 1):
    if s % x != 0:
        continue
    if ok(x):
        ans = max(ans, x)
    if ok(int(s / x)):
        ans = max(ans, int(s / x))

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    cout << T / A * B << endl;

    return 0;
}


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

int main(void)
{
	int n,i,a,max=0,count,ans;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		{
		a=i;
		count=0;
		while(a%2==0){count++, a/=2;}
		if(max<=count){max=count,ans=i;}
		}

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    ll n,x=0;
    cin>>n;
    ll a[n*3];
    red(i,n*3) cin>>a[i];
    sort(a,a+3*n); 
    reverse(a,a+3*n); 
    rep(i,n){
        x+=a[i*2+1];
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 2560
import sys

sys.setrecursionlimit(10 ** 9)

asc2en = lambda x: chr(x + 97)
N = int(input())


def rec(N):
    if (N - 1) // 26:
        return rec((N - 1) // 26) + asc2en((N - 1) % 26)
    return asc2en((N - 1) % 26)


print(rec(N))


Measured memory_bytes: 9172
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <math.h>

int main(void){
    using namespace std;
    long long a;
    long long b;

    cin >> a;


    long long num = 0;
    int l_a = log10(a)+1;


    for(int i=0; i < l_a; i++){
        if (a % 2 == 1){
            num += 1;
        }
        a = a / 10;
    }


    long long min_n;

    //cout << num << " " << l_a << endl;
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

using pchar = pair<char,char>;

lli data[200100];

lli simulate(const string &s,const vector<pchar> &td,int pos){
	for(auto c:td){
		if(s[pos]!=c.first)continue;
		if(c.second =='L')--pos;
		else ++pos;
		if(pos<0)return -1;
		if(pos>=(int)s.size())return 1;
	}
	return 0;
}

int solve(int N,const string&s, const vector<pchar> &td){
	lli low = -1, high=N;
	while(high-low>1){
		lli mid =(low+high)/2;
		if(simulate(s,td,mid)==-1)low=mid;
		else high = mid;
	}
	lli left_fall = high;

	low = -1,high=N;
	while(high-low>1){
		lli mid = (low+high)/2;
		if(simulate(s,td,mid)==1)high = mid;
		else low=mid;
	}
	lli right_fall = N-1-low;

	return N-(left_fall + right_fall);
}

signed main(){

	lli N,Q;string s;cin>>N>>Q>>s;
	vector<pchar> td(Q);
	for(lli i=0;i<Q;i++)cin>>td[i].first>>td[i].second;

	cout<<solve(N,s,td)<<endl;

	return 0;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int main(){
    char c,k;
    int ans=0;
    scanf("%c",&c);
    printf("%c",c);
    while(c=getchar()){
        if(c==' '||c=='\n')
            break;
        ans++;
        k=c;
    }
    printf("%d%c",ans-1,k);
    return 0;
}

Measured memory_bytes: 256
#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--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    string s;
    ll k;
    cin >> s >> k;
    ll roopcnt = 0;
    while(roopcnt < (ll)s.size()){
        if(s[roopcnt] != '1'){
            cout << s[roopcnt] << endl; 
            break;
        }
        else if(roopcnt == k-1){
            cout << 1 << endl;
            break;
        }

        roopcnt++;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int ans = 0;
		int num = 0;
		boolean flg = true;
		while(flg){
			if(ans >= b){
				flg = false;
				break;
			}
			ans += a;
			num++;
			if(ans < b){
				ans--;
			}

		}
		if(b == 1){
			num = 0;
		}
		System.out.println(num);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21332
import java.util.*;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        double distance = Math.sqrt(Math.pow((x2 - x1),2) + Math.pow((y2 - y1),2));
 
        System.out.printf("%.8f",distance);
    }
}


Measured memory_bytes: 27964
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
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; }
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

map<ll,ll> mp;
ll a,b,c,d;

ll dfs(ll x){
    if(x==0) return 0;
    if(x==1) return d;
    if(mp.count(x)) return mp[x];
    if(x<=LINF/d) mp[x]=x*d;
    else mp[x]=LINF;

    // chmin
    for(ll i=-4; i<=4; i++){
        ll now=x+i;
        if(now>=0 and now%2==0) chmin(mp[x],dfs(now/2)+abs(now-x)*d+a);
        if(now>=0 and now%3==0) chmin(mp[x],dfs(now/3)+abs(now-x)*d+b);
        if(now>=0 and now%5==0) chmin(mp[x],dfs(now/5)+abs(now-x)*d+c);
    }
    
    return mp[x];
}

int main(){
    ll t; cin>>t;
    rep(repp,0,t){
        mp.clear();
        ll n; cin>>n>>a>>b>>c>>d;
        cout<<dfs(n)<<endl;
    }
}

Measured memory_bytes: 6340
N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)


class UnionFindTree:
    def __init__(self, n):
        self.p = [i for i in range(n + 1)]
        self.r = [1 for _ in range(n + 1)]

    def find(self, x):
        if self.p[x] != x:
            self.p[x] = self.find(self.p[x])
        return self.p[x]

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.r[px] < self.r[py]:
                self.p[px] = py
                self.r[py] += self.r[px]
            else:
                self.p[py] = px
                self.r[px] += self.r[py]

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


uft = UnionFindTree(10**5)
X = [[] for _ in range(10**5 + 1)]
for a, b in zip(x, y):
    X[a].append(b)
Y = [[] for j in range(10**5 + 1)]
for a, b in zip(x, y):
    Y[b].append(a)
SX = set(x)
SY = set(y)
for j in SY:
    for i in Y[j]:
        uft.union(Y[j][0], i)

X2 = [[] for _ in range(10**5 + 1)]
for i in SX:
    X2[uft.find(i)].append(i)
ans = 0
for i in SX:
    S = set()
    for i2 in X2[i]:
        for j in X[i2]:
            S.add(j)
    ans += len(X2[i]) * len(S)
ans -= N

print(ans)


Measured memory_bytes: 124632
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<Integer>();
    int n = sc.nextInt();
    for (int i = 0; i < n; i++)
	  list.add(sc.nextInt());
    Collections.sort(list);
    System.out.println(list.get(list.size() / 2) - list.get(list.size() / 2 - 1));
  }
}

Measured memory_bytes: 59352
s = input()
t = input()
s_memo = {}
t_memo = {}

for i in range(len(s)):
    c1 = s[i]
    c2 = t[i]
    if (c1 in s_memo and s_memo[c1] != c2) or \
            (c2 in t_memo and t_memo[c2] != c1):
        print("No")
        exit()
    s_memo[c1] = c2
    t_memo[c2] = c1

print("Yes")

Measured memory_bytes: 3632
import sys
import collections

ni = lambda: int(sys.stdin.readline())
nl = lambda: list(map(int, sys.stdin.readline().split()))

N = ni()
A = nl()
counter = collections.Counter(A)
total = 0
for n in counter.values():
    total += n * (n - 1) // 2
for i in range(N):
    n = counter[A[i]]
    k = total - (n * (n - 1) // 2) + (n - 1) * (n - 2) // 2
    print(k)


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

bool f(int x) {
  int n = 0;
  while (x) {
    n++;
    x /= 10;
  }
  return (n%2) == 1;
}

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

  int ans = 0;
  for (int i=1; i <= n; i++) {
    if (f(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<LP> v(n);
    ll sum=0,ans=0;
    REP(i,n) cin>>v[i].first>>v[i].second;
    VSORT(v);
    int i=0;
    while(sum<m){
        //cout<<sum<<":"<<ans<<endl;
        if(sum + v[i].second > m){
            ans += (m-sum) * v[i].first;
            sum += (m - sum);
        }
        else{
            ans += v[i].first*v[i].second;
            sum += v[i].second;
        }
        i++;
    }
    cout<<ans<<endl;
}

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

int main()
{
   string s1;
   cin>>s1;
   string first = s1.substr(0,2);
   string second = s1.substr(2,2);

   int f = stoi(first);
   int s = stoi(second);

   if(f<=12 && f>=1 && s<=12 && s>=1)
   {
   	cout<<"AMBIGUOUS";
   }

   else if(f<=12 && f>=1)
   {
   	cout<<"MMYY";
   }

   else if(s<=12 && s>=1)
   {
   	cout<<"YYMM";
   }

   else
   {
   	cout<<"NA";
   }
   cout << endl;
   return 0;
}
 

Measured memory_bytes: 256