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

int main(void)
{
	long long N;
	scanf("%lld",&N);
	long long ans=30000000000000; 
	long long x = sqrt(N);
	for (long long i=1;i<=x;i++)
	{
		if (N%i) continue;
		ans = min(ans,i+N/i-2);
	}
	printf("%lld",ans);
	return 0;
 } 

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int m;
    cin >> m;
    cout << 48-m << endl;
    
    return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	for (int i = 0; i < M; ++i) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		A[x]++;
		A[y]++;
	}
	for (int i = 0; i < N; ++i) {
		cout << A[i] << endl;
	}
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

string make_code(string s, int k)
{
    string ret="";
    int S=s.size();

    ret+=s[0];
    rep(i,S-1)
    {
        string vowel="aiueo";
        bool flag=false;
        rep(j,5) if(s[i]==vowel[j]) flag=true;

        if(flag) ret+=s[i+1];
    }

    if(ret.size()>k) ret=ret.substr(0,k);
    return ret;
}

int main()
{
    int n;
    while(cin >>n,n)
    {
        vector<string> s(n);
        rep(i,n) cin >>s[i];
        int ans=-1;
        for(int k=1; k<=50; ++k)
        {
            set<string> codes;
            rep(i,n) codes.insert(make_code(s[i],k));
            if(codes.size()==n)
            {
                ans=k;
                break;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3264
#include <iostream>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

ll x[maxn],k[maxn];
ll n,a,b;

bool check(ll t){
    memcpy(k,x,sizeof(x));
    for(ll i=1; i<=n; i++){
        k[i] -= t*b;
    }
    ll more = (a-b),cnt=0;
    for(ll i=1; i<=n; i++){
        if(k[i]>0) cnt += (k[i]%more==0) ? (k[i]/more) : (k[i]/more+1);
    }
    return cnt <= t;
}

int main(){
    cin >> n >> a >> b;
    for(int i=1; i<=n; i++){
        x[i] = read();
    }

    ll ans,L=1,R=1e9;
    while(L<=R){
        ll mid = (L+R)/2;
        if(check(mid)) ans=mid,R=mid-1;
        else L=mid+1;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
//vacation dp problem
#include<bits/stdc++.h>
using namespace std;
struct activiy
{
    int A;
    int B;
    int C;

};

int maxEnjoy(vector<activiy>E,int n)
{
   int dp[n+1][3]; 

    //base
    dp[1][0]=E[1].A;
    dp[1][1]=E[1].B;
    dp[1][2]=E[1].C;
    
    for(int i=2;i<=n;i++)
    {
     //for(int j=0;j<=2;j++)
        
     dp[i][0]=E[i].A+max(dp[i-1][1],dp[i-1][2]);
     dp[i][1]=E[i].B+max(dp[i-1][0],dp[i-1][2]);
     dp[i][2]=E[i].C+max(dp[i-1][0],dp[i-1][1]);
 }

    return max(max(dp[n][0],dp[n][1]),dp[n][2]);

}

int main()
{
    int n;
    cin>>n;
    vector<activiy>enjoy(n+1);
    for(int i=1;i<=n;i++)
    {
       
            cin>>enjoy[i].A;
            cin>>enjoy[i].B;
            cin>>enjoy[i].C;
            
        }
    cout<<maxEnjoy(enjoy,n);
    return 0;
}


Measured memory_bytes: 3840
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    print(S[:-8])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9052
def solve(n, d):
    if n >= 24:
        return 0

    cnt = {i: 0 for i in range(12 + 1)}
    cnt[0] = 1
    for dd in d:
        cnt[dd] += 1

    # 同じ時刻の都市が存在する場合、
    # 時刻の差の最小値は、0になる
    # 鳩ノ巣
    if cnt[0] > 1:
        return 0
    elif cnt[12] > 1:
        return 0
    else:
        for i in range(1, 12):
            if cnt[i] > 2:
                return 0

    bit_cnt = 0
    for i in range(1, 12):
        if cnt[i] == 1:
            bit_cnt += 1

    res = -1
    for mask in range(1 << bit_cnt):
        t = [False] * 24
        t[0] = True

        cur = 0
        for i in range(1, 12):
            if cnt[i] == 1:
                if (mask >> cur) & 1 == 1:
                    t[i] = True
                else:
                    t[24 - i] = True
                cur += 1
            elif cnt[i] == 2:
                t[i] = True
                t[24 - i] = True

        if cnt[12] == 1:
            t[12] = True

        # print(*map(lambda x: 1 if x else '-', t))

        dist = 24
        frm = 0
        for i in range(1, 48 + 1):
            if t[i % 24]:
                dist = min(dist, (i - frm) % 24)
                frm = i

        res = max(res, dist)

    return res


if __name__ == '__main__':
    n = int(input())
    d = tuple(map(int, input().split()))

    res = solve(n, d)
    print(res)


Measured memory_bytes: 41200
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <stdio.h>
#include <string>


using namespace std;
int main()
{
    string strIn, strOut;

    cin >> strIn;

    if (strIn[strIn.size() - 1]=='s')
    {
        strOut = strIn + "es";
    }
    else
    {
        strOut = strIn + "s";
    }

    cout << strOut << endl;

    return 0;


}



Measured memory_bytes: 3604
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 10 ** 9 + 7
    n, a, b = map(int, input().split())

    def comb_c(n, r):
        if r > n - r:
            r = n - r
        a, b = 1, 1
        for i in range(r):
            a = a * (n - i) % MOD
            b = b * (i + 1) % MOD
        return a * pow(b, MOD-2, MOD)

    ans = pow(2, n, MOD) - 1
    ans -= comb_c(n, a)
    ans -= comb_c(n, b)
    ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>

int main()
{
	int sum=0,n=0;
	char c=getchar();
	while(c!='\n'){
		sum=sum+c-'0';
		n=10*n+c-'0';
		c=getchar();
	}
	if(n%sum)printf("No");
	else printf("Yes");
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans =0;
        if (a > b) {
            ans += a;
            a--;
        } else {
            ans += b;
            b--;
        }
        if (a > b) {
            ans += a;
            a--;
        } else {
            ans += b;
            b--;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100000;
const int MAX_N = 105;

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

int h,w;
string c[MAX_N];
int sx,sy,gx,gy;

int main(){
    cin >> h >> w;
    rep(i,h){
        cin >> c[i];
    }

    int count=0;
    rep(i,h){
        rep(j,w){
            if(c[i][j]=='.') count++;
        }
    }

    sx = sy = 0;
    gx = h-1;
    gy = w-1;

    vector<vector<int> > dist(h,vector<int>(w,-1));
    queue<P> que;

    dist[sx][sy] = 0;
    que.push(make_pair(sx,sy));

    while(!que.empty()){
        P current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop();

        rep(dir,4){
            int next_x = x + dx[dir];
            int next_y = y + dy[dir];

            if(next_x <0 || next_x>=h || next_y<0 || next_y>= w) continue;
            if(c[next_x][next_y]=='#') continue;

            if(dist[next_x][next_y]==-1){
                que.push(make_pair(next_x,next_y));
                dist[next_x][next_y] = dist[x][y] + 1;
            }
        }

    }

    int cost = dist[gx][gy];

    if(cost == -1){
        cout << -1 << endl;
    }else{
        cout << count-cost-1 << endl;
    } 



}

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

using namespace std;

#define ll long long

int main()
{
	ll N, M, K;
	cin >> N >> M >> K;

	vector < ll > A(N), B(M);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	vector < ll > SumA(N + 1), SumB(M + 1);
	SumA[0] = 0;
	SumB[0] = 0;
	for (int i = 0; i < N; i++) {
		SumA[i + 1] = SumA[i] + A[i];
	}

	for (int i = 0; i < M; i++) {
		SumB[i + 1] = SumB[i] + B[i];
	}

	ll ans = 0;
	ll j = M;

	for (ll i = 0; i <= N; i++) {
		if (SumA[i] > K) {
			break;
		}
		while (SumB[j] > K - SumA[i]) {
			j--;
		}
		ans = max(ans, i + j);
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debug_idx,v.size())cout<<" "<<v[debug_idx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debug_idx,n)cout<<" "<<v[debug_idx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

//
//　ダブリングを用いた実装
//
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    vi a(n);
    vector<vi> d(64, vi(n,-1)); //d[(2^i)回][移動した先]

    REP(i,n){
        cin>>a[i];
        a[i]--;
        d[0][i] = a[i];
    }

    FOR(i,1,64){
        //d[i][j]はd[i-1][j]を2回移動したものに等しい
        REP(j,n){
            d[i][j] = d[i-1][d[i-1][j]];
        }

        //DEBUG_VEC(d[i]);
    }

    int now=0;
    for(ll i=63; i>=0; i--){
        if(k & (1LL<<i)){
            now = d[i][now];
        }
        //DEBUG(now);
    }

    int ans = now;
    ans += 1;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 54940
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

int main() 
{
	unsigned int n;
	unsigned int i;
	vector<double> v;

	cin >> n;
	for (i = 0; i < n; i++)
	{
		unsigned int nn;
		cin >> nn;
		v.push_back(nn);
	}
	stable_sort(v.begin(), v.end());

	while (v.size() != 1)
	{
		v[0] = (v[0] + v[1]) / 2.0;
		v.erase(v.begin() + 1);
	}
	cout << v[0] << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.split(" ").map(&:to_i)
(n[0]+1).times{|t|
(n[0]-t+1).times{|k|
    if (10000*t + 5000*k + 1000*(n[0]-t-k) )== n[1] then
        print t," ",k," ",(n[0]-t-k)
        exit
    end
}
}
print "-1 -1 -1"

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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
    int n; cin >> n;
    rep(i, n) {
        ll a, b; cin >> a >> b;
        cost_due.push_back(P(a, b));
    }
    // 締め切りを昇順にソート
    sort(cost_due.begin(), cost_due.end(), compare_by_b);
    ll current = 0;
    rep(i, n) {
        P a = cost_due[i];        
        if (current + a.first <= a.second) {
            current += a.first;
        } else {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 6256
// ABC045B - 3人でカードゲームイージー

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	string Sa, Sb, Sc;
	cin >> Sa >> Sb >> Sc;

	queue<char> A, B, C;

	for (int i = 0; i < Sa.size(); i++) {
		A.push(Sa[i]);
	}
	for (int i = 0; i < Sb.size(); i++) {
		B.push(Sb[i]);
	}
	for (int i = 0; i < Sc.size(); i++) {
		C.push(Sc[i]);
	}

	char next = 'a';

	while (1) {
//		cout << next << ' ';
		if (next == 'a') {
			if (A.empty()) {
				cout << 'A' << endl;
				return 0;
			}
			next = A.front();
			A.pop();
		} else if (next == 'b') {
			if (B.empty()) {
				cout << 'B' << endl;
				return 0;
			}
			next = B.front();
			B.pop();
		} else if (next == 'c') {
			if (C.empty()) {
				cout << 'C' << endl;
				return 0;
			}
			next = C.front();
			C.pop();
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;


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

    int n, x;
    cin >> n >> x;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    auto it = upper_bound(nums.begin(), nums.end(), x);
    int d;
    if (it == nums.end()) {
        d = x - nums.back();
    } else if (it == nums.begin()) {
        d = nums[0] - x;
    } else {
        d = abs(*it - x);
        --it;
        d = min(d, abs(*it - x));
    }
    bool flag = true;
    for (int i = d; i >= 1; --i) {
        for (int j = 0; j < n; ++j) {
            if (abs(nums[j] - x) % i != 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << i << endl;
            break;
        } else {
            flag = true;
        }
    }

    return 0;
}

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

typedef long long ll;

void solve()
{
    double s, t, d;
    cin >> d >> t >> s;
    if (s >= d / t)
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef long long ll;

#define MOD 1000000007

ll pow (ll a, ll n) {
	if (n==0)
		return 1;
	if (n==1)
		return a;
	ll tmp = pow (a, n/2) % MOD;
	ll tmp2 = (tmp*tmp) % MOD;
	if (n%2==0) {
		return tmp2;
	}
	return (tmp2*a) % MOD;
}

int main () {
	int N;
	cin >> N;
	ll sum = 0, sq = 0;
	for (int i=0; i<N; i++) {
		ll tmp;
		cin >> tmp;
		sum += tmp;
		sum %= MOD;
		sq += tmp*tmp;
		sq %= MOD;
	}
	ll ans = sum*sum;
	ans %= MOD;
	ans += MOD - sq;
	ans %= MOD;
	ans *= pow (2, MOD-2);
	ans %= MOD;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <sstream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const int MAXN = 100;
const int MOD = 1000000007;

int len[MAXN];

int main()
{
	int n, k;
	int ans = 0;

	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> len[i];
	sort(len, len + n);
	for (int i = 1; i <= k; ++i)
		ans += len[n - i];
	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#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> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 pb push_back
#define pp 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)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

	string S; cin >> S;
	int left = 0, right = S.size() - 1;
	int cnt = 0;
	while(left < right) {
		if(S[left] != S[right]) cnt++;
		left++; right--;
	}
	cout << cnt << endl;
}

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

int n,i;
vector <int> veca;
int main()
{
    cin >> n;
    for (i=0;i<4;i++)
    {
        veca.push_back(n%10);
        n/=10;
    }
    reverse(veca.begin(),veca.end());
    if ((veca[0]==veca[1])&&(veca[1]==veca[2]))
        cout << "Yes" << endl;
    else if ((veca[1]==veca[2])&&(veca[2]==veca[3]))
        cout << "Yes" << endl;
    else if ((veca[0]==veca[1])&&(veca[1]==veca[2]) && (veca[2]==veca[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

N = int(input())
a = [0] * N

for i in range(N):
    a[i] = int(input())

i = a[0]
count = 1

for _ in range(N):
    if i == 2:
        break
    i = a[i - 1]
    count += 1

if i != 2:
    count = -1

print(count)


Measured memory_bytes: 8948
n, m = map(int, input().split())

ans=set()
lm=0
rm=n
for i in range(m):
  l, r = map(int, input().split())
  lm=max(l, lm)
  rm=min(r, rm)
if rm - lm < 0:
  print(0)
else:
  print(rm - lm + 1)

Measured memory_bytes: 3060
program aaa
implicit none

integer :: l, i, res1, res2
character(1),dimension(4) :: g=['A','C','G','T']
character(10) :: s

read*, s
s=trim(s)
l=len_trim(s)
res1=0
res2=0
do i=1,l
if(s(i:i)==g(1).or.s(i:i)==g(2).or.&
&s(i:i)==g(3).or.s(i:i)==g(4)) then
res1=res1+1
else
res2=max(res1,res2)
res1=0
end if
end do

write(*,'(i0)') max(res1,res2)

end program

Measured memory_bytes: 256
from collections import deque
n=int(input())
ans=10**18
xy=[list(map(int,input().split())) for _ in range(n)]
d=dict()
for i in range(n):
    a,b=xy[i]
    d[(a,b)]=i
def bfs(s,p,q,visited):
    queue=deque([s])
    visited[s]=1
    while queue:
        x=queue.popleft()
        a,b=xy[x]
        if (a+p,b+q) in d:
            idx=d[(a+p,b+q)]
            if visited[idx]==0:
                visited[idx]=1
                queue.append(idx)
        if (a-p,b-q) in d:
            idx=d[(a-p,b-q)]
            if visited[idx]==0:
                visited[idx]=1
                queue.append(idx)
for i in range(n-1):
    ai,bi=xy[i]
    for j in range(i+1,n):
        aj,bj=xy[j]
        p,q=ai-aj,bi-bj
        cnt=0
        visited=[0]*n
        for k in range(n):
            if visited[k]==0:
                bfs(k,p,q,visited)
                cnt+=1
        ans=min(ans,cnt)
if n==1:
    ans=1
print(ans)
#print(d)

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

int main(){
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	int ans = 0;
	ans += min(k, a);
	k -= min(k, a);
	if(k == 0){
		printf("%d", ans);
	}else{
		k -= min(k, b);
		if(k == 0){
			printf("%d", ans);
		}else{
			ans -= min(k, c);
			printf("%d", ans);
		}
	}
	return 0;
}


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;



int main(){
    int n,x,y; cin>>n>>x>>y;
    x--; y--;
    vector<int> ans(n-1);
    for(int i = 0; i <n-1; i++){
     for(int j = i+1; j < n; j++){
            int nowl,nowr;
            if(i>=x) nowl = i-x;
            else nowl = x-i;
            if(j>=y) nowr = j-y;
            else nowr = y-j;
            ans[min(j-i-1,nowl+nowr)]++;
        }
    } 
    for(int i = 0; i< n-1; i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;

// long long modexpo(long long x, long long p){
//     int res = 1;x = x%mod;
//     while(p){
//         if(p%2)res = res * x;
//         p >>= 1;
//         x = x*x % mod;
//         res %= mod;
//     }
//     return res;
// }

// int max(int a,int b){return (a>b?a:b);} 
// int min(int a,int b){return (a<b?a:b);}


struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

const int nax = 1e5 + 5;

int32_t main(){
    IOS
    int n;
    cin >> n;
    int arr[n];
    int cnt[nax];
    memset(cnt,0,sizeof(cnt));
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        cnt[arr[i]]++;
    }
    for(int i = nax-2; i >= 0; i--){
        cnt[i] += cnt[i+1];
    }   
    int ans = 0; 
    for(int i = 1; i < nax; i++){
        if(n-cnt[i] == cnt[i]){
            ans++;
        }
    }
    cout << ans << endl;
} 

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),m=read(),now=read();
    for(int i=1;i<=10;i++)now=n*now-m,pr2(now);
   	return 0;
}

Measured memory_bytes: 128
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  int32_t x, a, b;
  cin >> x >> a >> b;

  if (abs(x - a) < abs(x - b)) {
    cout << 'A';
  } else {
    cout << 'B';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
# B - Colorful Slimes
N,x = map(int,input().split())
A = list(map(int,input().split()))
B = A[:]
ans = sum(A)
for k in range(1,N):
    for i in range(N):
        B[i] = min(B[i],A[(i-k)%N])
    ans = min(ans,sum(B)+k*x)
print(ans)

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

const int N = 100002, kUnit = 50, kB = 10000 / kUnit;
int AN, BN, R;
int xa[N], ya[N], xb[N], yb[N];

typedef pair<int,int> P;
vector<P> sep[kB+2][kB+2];

bool input() {
  scanf("%d%d%d", &AN, &BN, &R);
  if (AN == 0)
    return false;
  rep(i,AN) scanf("%d%d", xa+i, ya+i);
  rep(i,BN) scanf("%d%d", xb+i, yb+i);
  return true;
}

int solve() {
  // バケット初期化
  rep(i,kB) rep(j,kB) sep[i][j].clear();
  
  // 弾をバケットに放り込む
  rep(i,BN) {
    int x = xb[i] / kUnit, y = yb[i] / kUnit;
    sep[y][x].push_back(P(xb[i], yb[i]));
  }

  int ans = 0;
  rep(i,AN) {
    int x = xa[i], y = ya[i];
    int ix = x / kUnit, iy = y / kUnit;
    for (int dy = -1; dy <= 1; ++dy) {
      for (int dx = -1; dx <= 1; ++dx) {
        int tix = ix + dx, tiy = iy + dy;
        if (0 > tix || 0 > tiy || tix >= kB || tiy >= kB) continue;
        // 同じバケット内の弾と比較
        rep(j,sep[tiy][tix].size()) {
          int dist_x = sep[tiy][tix][j].first - x,
              dist_y = sep[tiy][tix][j].second - y;
          int dist_pow = (dist_x * dist_x) + (dist_y * dist_y);
          if (16 * R * R >= dist_pow)
            ++ans;
        }
      }
    }
  }
  return ans;
}

int main() {
  while (input()) {
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 6120
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n) cin >> h[i];
  int tall = h[0];
  int cnt = 1;
  for(int i = 1; i < n; i++){
    if(h[i] >= tall){
      cnt++;
      tall = h[i];
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
tmp = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
    for j in range(i+1, n):
        if 2*j-i < n:
            if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                tmp-=1
print(tmp)


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl;

	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin>>s>>t;
    int ans=INT_MAX;
    for(int i=0;i<=s.length()-t.length();i++)
    {
        int k=0;
        for(int j=0;j<t.length();j++)
        {
            if(s[i+j]!=t[j])
            k++;
        }
        if(k<ans)
        ans=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define ld long double
const int mod=1e9+7;
int main()
{
    int n,m;
    cin>>n>>m;
    string arr[n];
    forl(i,0,n) cin>>arr[i];
    int dp[n][m];
    forl(i,0,n) forl(j,0,m) dp[i][j]=0;
    dp[0][0]=1;
    forl(i,0,n)
    {
        forl(j,0,m)
        {
            if(i==0 && j==0) continue;
            if(i-1>=0 && arr[i][j]=='.') dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
            if(j-1>=0 && arr[i][j]=='.') dp[i][j]=(dp[i][j]+dp[i][j-1])%mod; 
        }
    }
    cout<<dp[n-1][m-1]<<endl;
   

}

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Remoting.Contexts;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        public uint NextUint()
        {
            return uint.Parse(Next());
        }
    }

    class Program
    {
        private int D, N;
        private void Scan()
        {
            var sc = new Scanner();
            D = sc.NextInt();
            N = sc.NextInt();
        }


        public void Solve()
        {
            Scan();

            long a = (long)Math.Pow(100, D);
            Console.WriteLine(a * (N == 100 ? 101 : N));
        }

        static void Main() => new Program().Solve();
    }

}


Measured memory_bytes: 11092
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
print(180*(N-2))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
int ans;
int n;
int s;

void count_ans(int k,int C,int j){
	if(k==n){
		if(C==s){
			ans++;
		}
	}else{
		for(int i=j+1;i<10;i++){
			count_ans(k+1,C+i,i);
		}
	}
	
}


int main(){
	while(cin>>n>>s,(n!=0)||(s!=0)){
		ans=0;
		count_ans(0,0,-1);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define nn 808
int n,m,k,dist[nn][nn];
char locked[nn][nn];

int ax[]={0,1,-1,0},ay[]={-1,0,0,1};
void bfs(){
	queue<int> qx,qy;
	memset(dist,0x3f,sizeof dist);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(locked[i][j]=='S') 
					qx.push(i),qy.push(j),dist[i][j]=0;
	
	while(qx.size()){
		int x=qx.front(),y=qy.front();qx.pop(),qy.pop();
		for(int i=0;i<4;i++){
			int xx=ax[i]+x,yy=ay[i]+y;
			
			if(locked[xx][yy]=='.' and dist[xx][yy]>dist[x][y]+1){
				dist[xx][yy]=dist[x][y]+1;
				qx.push(xx),qy.push(yy);
			}
		}
	}
}

signed main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%s",locked[i]+1);
	bfs();int ans=6489648;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(dist[i][j]<=k)	
		ans=min(ans,1+(min(min(i-1,n-i),min(j-1,m-j))+k-1)/k);

	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(i==1 or i==n or j==1 or j==m)
		ans=min(ans,(dist[i][j]+k-1)/k);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3456
sS = input().rstrip()
iTotal = 0
iL = len(sS) - 1
iP = 2**(iL)
for i in range(iP):
    sB = ("{:0"+str(iL)+"b}").format(i)
    sThis = sS
    for i in range(len(sB)-1,-1,-1):
        if sB[i] == "1":
            sThis = "+".join([sThis[0:i+1],sThis[i+1:]])
    iTotal += eval(sThis)
print(iTotal)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  for(int d;cin>>d,d;){
    vector<pair<int,int> > result;
    for(int i=0;i<d;i++){
      int name,score=0;
      cin>>name;
      int a,b;
      bool spare=false,strike=false,dbl=false;
      for(int i=0;i<10;i++){
	cin>>a;
	score+=a;
	if(dbl) score+=a,dbl=false;
	if(strike) score+=a;
	if(spare) score+=a,spare=false;
	if(a==10){
	  if(strike)dbl = true;
	  strike = true;
	}
	else{
	  cin>>b;
	  score+=b;
	  if(strike)score+=b,strike=false;
	  if(a+b==10)spare = true;
	}
      }
      if(strike){
	cin>>a>>b;
	if(dbl)score+=a;
	score+=a+b;
      }
      if(spare){
	cin>>a;
	score+=a;
      }
      result.push_back(mp(-score,name));
    }
    sort(result.begin(),result.end());
    for(int i=0;i<d;i++){
      cout<<result[i].second<<" "<<-result[i].first<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ss () = read_line () |> split_on_char ' '

end

let () =
  try
    while true do
      let rec g l =
        if List.exists (fun e -> e = "the" || e = "this" || e = "that") l then String.concat " " l |> print_endline
        else
          List.map (fun s ->
            String.map (fun c ->
              if c < 'a' || c > 'z' then c
              else Char.chr (((Char.code c - Char.code 'a' + 1) mod 26) + Char.code 'a'))
            s) l |> g in
      IO.read_ss () |> g;
    done
  with _ -> ()

Measured memory_bytes: 2020
#include<bits/stdc++.h>
using namespace std;
int dp[3005][3005];
int p[3005][3005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	int lens = s.length();
	int lent = t.length();
	for(int i=1; i<=lens; i++) {
		for(int j=1; j<=lent; j++) {
			if(s[i-1]==t[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
				p[i][j] = 1;
			}
			else if(dp[i][j-1]>dp[i-1][j]) {
				dp[i][j] = dp[i][j-1];
				p[i][j] = 2;
			}
			else {
				dp[i][j] = dp[i-1][j];
				p[i][j] = 3;
			}
		}
	}
	string ans = "";
	int ni = lens, nj = lent;
	while(ni>0 && nj>0) {
		if(p[ni][nj]==1) {
			ans = s[ni-1] + ans;
			ni--, nj--;
		}
		else if(p[ni][nj]==2) nj--;
		else ni--;
	}
	cout << ans << "\n";
	return 0;
}

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

int main(){
  int N;
  int tgt=1;
  int goodrenga=0;
  int A;
  
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A;
   
    if(A==tgt){
      goodrenga+=1;
      tgt+=1;
    }
  }
  int res=-1;
  if(goodrenga!=0){
    res=N-goodrenga;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
from cmath import pi, rect
sys.setrecursionlimit(10**7)

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

A,B,H,M = LI()

H += M / 60
H = H/12 * 2*pi
M = M/60 * 2*pi

# 余弦定理
l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) )
 
# 複素数座標 Aexp(iθ)
zA = A * np.exp(H*1j)
zB = B * np.exp(M*1j)

l=abs(zA - zB)

print(l)


Measured memory_bytes: 27240
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    long n, sum=0;
    scanf("%ld", &n);
    int a[n+1], b[n];
    for(int i = 0; i<=n; i++) scanf("%d", &a[i]);
    for(int i = 0; i<n; i++) scanf("%d", &b[i]);
    for(int i=n-1; i>=0; i--){
        int nokoriTaoseru = b[i] - a[i+1];
        if(nokoriTaoseru > 0){
            sum += a[i+1];
            int nokorinoteki = a[i] - nokoriTaoseru;
            if(nokorinoteki > 0){
                sum += nokoriTaoseru;
                a[i] = nokorinoteki;
            }else{
                sum += a[i];
                a[i] = 0;
            }
        }else{
            sum += b[i];
        }
    }
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=2005;
const ll MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];
ll ans;
void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<MAX;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll COM(ll i,ll j){
	if(i<j) return 0;
	if(i<0||j<0) return 0;
	return fac[i]*(finv[j]*finv[i-j]%MOD)%MOD;
}
int main(void){
	COMinit();
	ll N,K; cin>>N>>K;
	ll R=N-K;
	for(int i=2;i<2+K;i++){
		//cout<<COM(R+1,i-1)<<" "<<COM(K-1,i-2)<<" ";
		ans=COM(R+1,i-1)*COM(K-1,i-2)%MOD;
		cout<<ans<<endl;
	}
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

const int mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> broken(n+1, 0);
    rep(i,m) {
        int a;
        cin >> a;
        broken[a] = 1;
    }
    vector<int> dp(n+2, 0);
    dp[n] = 1;
    for(int i = n-1; i >= 0; i--) {
        if(broken[i]) continue;
        dp[i] = (dp[i+1] + dp[i+2])%mod;
    }
    cout << dp[0] << endl;
    return 0;
}

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

typedef long long ll;
const int MAXN = 200010;
const int inf = 0x3f3f3f3f;

struct Node
{
	ll a, b;
	bool operator < (const Node &A) const
	{
		return a * (1 + A.b) > A.a * (1 + b);
	}
}o[MAXN];
ll p[MAXN];

int n, T, cnto, cntp;
ll f[40];

int main()
{
	scanf("%d %d", &n, &T);
	for(int i = 1; i <= n; ++i)
	{
		int x, y; scanf("%d %d", &x, &y);
		if(!x) p[++cntp] = y;
		else o[++cnto] = (Node){x, y};
	}
	sort(p + 1, p + 1 + cntp);
	sort(o + 1, o + 1 + cnto);
	for(int i = 1; i <= cntp; ++i) p[i] += p[i - 1] + 1;
	for(int i = 1; i < 40; ++i) f[i] = inf;
	for(int i = 1; i <= cnto; ++i)
		for(int j = 35; ~j; --j)
		{
			if(f[j] == inf) continue;
			f[j + 1] = min(f[j + 1], (f[j] + 1) * (o[i].a + 1) + o[i].b);
			if(f[j + 1] > T) f[j + 1] = inf;
		}
	int ans = 0;
	for(int i = 0; i <= 35; ++i)
		if(f[i] != inf)
		{
			int x = T - f[i];
			int l = 1, r = cntp, sol = 0, mid;
			while(l <= r)
			{
				mid = (l + r) >> 1;
				if(p[mid] <= x) sol = mid, l = mid + 1;
				else r = mid - 1;
			}
			ans = max(ans, i + sol);
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>


int main(){
	//入力機構
	int a,b;
	std::cin>>a>>b;
	//解答
	//1人が取れるケーキの数は最大16/2個
	//2人が共に16/2個ケーキを取る方法が存在する
	//その方法から数合わせでケーキを抜けば16/2以下の個数取る方法が作れる
	//つまり条件はa<=8かつb<=8
	bool flag=(a<=8 && b<=8);

	//結果出力
	std::cout<<(flag?"Yay!":":(")<<std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	//int i;
	int a[3];
	string ret;
	cin >> a[0] >> a[1] >> a[2];

	if (a[0] + a[1] + a[2] > 21) ret = "bust";
	else ret = "win";
	cout << ret;

	return 0;
}

Measured memory_bytes: 384
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)


def gcd (m,n)
  r = m % n
  m1 = m
  n1 = n
  while r > 0
    m1 = n1
    n1 = r
    r = m1 % n1
  end
  return n1
end

if n == 2 
    p a.max
else
    cnt = 1
    first = [a[0]]
    last = [a[n-1]]
    for i in 1..n-2 do
        first.push(gcd(first[i-1],a[i]))
        last.push(gcd(last[i-1],a[n-i-1]))
    end
    max = first.pop
    b = last.pop
    if max < b
        max = b
    end
    for i in 1..first.size do
        c = gcd(first[i-1], last[-i])
        if max < c
            max = c
        end 
    end
    p max
end



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

int main(){
  int mi = 124;
  int ma = -1;
  for(int i = 0; i < 5; i++){
    int a;
    cin >> a;
    mi = min(mi, a);
    ma = max(ma, a);
  }
  int k;
  cin >> k;
  if(ma - mi > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n;

int main() {
    int i, j;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int n;
    cin >> n;
    a *= 8;
    b *= 4;
    c *= 2;
    if (n % 2 == 0) {
        cout << (ll)n / 2LL * (ll)min(min(min(a, b), c), d) << endl;
        return 0;
    }
    ll ans = (ll)(n / 2) * (ll)min(min(min(a, b), c), d);
    ans += (ll)min(min(a / 2, b / 2), c / 2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
    using namespace std; 
    int main()
    {
        int n,a,b;
        cin>>n>>a>>b;
        if(n*a >b)
        {
            cout<<b<<endl;
        }
        else
        {
            cout<<n*a<<endl;
        }
    }

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

int main() {
	int a, b, c; cin >> a >> b >> c;
	int m = max({ a, b, c }) * 3;
	int rest = m - a - b - c;
	cout << (rest % 2 == 0 ? rest / 2 : (rest + 3) / 2) << endl;

	return 0;
}

Measured memory_bytes: 3628
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	string s;
	cin >> s;
	set<char> se;
	REP(i, s.size()){
		se.insert(s[i]);
	}
	if (se.size() == s.size()) cout << "yes" << endl;
	else cout << "no" << endl;
	
//	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
using namespace std;
struct process{
    int time;
    string name;
};
using namespace std;

int main()
{
    queue <struct process> a;
    int num,limit,time=0;
    cin>>num>>limit;
    struct process n,m;
    for(int i=0;i<num;i++) {
        cin >> n.name >> n.time;
        a.push(n);
    }
    while(!a.empty()) {
        if (a.front().time <= limit) {
            time += a.front().time;
            cout << a.front().name << " " << time << endl;
            a.pop();
        }
        else {
            time += limit;
            a.front().time -= limit;
            m = a.front();
            a.pop();
            a.push(m);
        }
    }
    return 0;
}



Measured memory_bytes: 6272
def isPrime(n):
    for i in range(2,N):
        if N%i == 0:
            return False
    return True
    
    
def find_next_prime(n):
    return find_prime_range(n, 2*n)

def find_prime_range(a, b):
    for p in range(a, b):
        for j in range(2, p):
            if p % j == 0:
                break
        else:
            return p
    return None

N = int(input())
if(isPrime(N)):
    print(str(N))
else:
    print(str(find_next_prime(N+1)))

Measured memory_bytes: 3064
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		int sum=0,c=0;

		double o=0;

		for(;sc.hasNextLine();c++){

			String buf = sc.nextLine();

			Scanner m = new Scanner(buf.replace(',',' '));

			int a =m.nextInt();

			int b =m.nextInt();

			sum += a*b;

			o += b;

		}

		System.out.println(sum+"\n"+(int)(o/c + 0.5));

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int main () {
    string a, b, c;
    cin >> a >> b >> c;

    if (a[a.size() -1] == b[0] && b[b.size() -1] == c[0]) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mi,mx,d,l,h,su=0,su1=0,su2=0,su3=0,su4=0,arr[10000];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(i==0){mi=arr[i]; mx=arr[i];}
        else{

            if(mi>arr[i]){mi=arr[i];}
            if(mx<arr[i]){mx=arr[i];}
        }
    }
    d=mx-mi;
    d=d/2;
    l=mi+d;
    h=mx-d;
    int f=0;
    for(int i=mi;i<=mx;i++)
    {su=0;
        for(int j=0;j<n;j++){
      su+=pow((arr[j]-i),2);

        }
         if(f==0)
      {
         d=su;
         f=1;
      }
      else{d=min(d,su);}


    }
    cout<<d<<endl;


}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

int main() {
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    for (long long b = 1; b <= n; ++b) {
        long long cur = (n / b) * std::max(0LL, b - k) + std::max(0LL, n % b + (k != 0) - k);
        ans += cur;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![0; n];
    for i in 0..n - 1{
    av[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    av[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    av.sort_by(|a, b| b.cmp(a));
    let mut sum_a = 0;
    let mut sum_b = 0;
    for i in 0..n {
        if i % 2 == 0 {
            sum_a += av[i];
        } else {
            sum_b += av[i];
        }
    }
    println!("{}", sum_a - sum_b);
}


Measured memory_bytes: 4352
def knapsack(sizes, vals, volume):
    n = len(sizes)

    dp = [[0] * (volume+1) for _ in range(n)] # j is 0...volume

    for i in range(n):
        for j in range(volume+1):
            dp[i][j] = max(dp[i][j], dp[i-1][j])
            if j - sizes[i] >= 0:
                dp[i][j] = max(dp[i][j], dp[i-1][j-sizes[i]] + vals[i])
            dp[i][j] = max(dp[i][j], dp[i-1][j])

    return dp[-1][-1]


if __name__ == "__main__":
    n, volume = [int(x) for x in input().split()]
    sizes, vals = [], []
    for _ in range(n):
        s, v = [int(x) for x in input().split()]
        sizes.append(s)
        vals.append(v)
    print(knapsack(sizes, vals, volume))


Measured memory_bytes: 120304