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

int A[200100];
int L[200100 / 2], R[200100 / 2];

long long merge(long long left, long long mid, long long right)
{
	long n1, n2;
	long long cnt = 0;
	n1 = mid - left;
	n2 = right - mid;
	for (long long i = 0; i < n1; i++) L[i] = A[left + i];
	for (long long i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = 0x7fffffff;
	for (long long k = left, j = 0, i = 0; k < right; k++)
	{
		if (L[i] <= R[j])
			A[k] = L[i++];
		else
		{
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

long long mergeSort(int left, int right)
{
	long long v1, v2, v3, mid;
	if (left + 1 < right)
	{
		mid = (left + right) / 2;
		v1 = mergeSort(left, mid);
		v2 = mergeSort(mid, right);
		v3 = merge(left, mid, right);
		return v1 + v2 + v3;
	}
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	printf("%lld\n", mergeSort(0, n));
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define M1 1000000007LL
typedef pair<int,int> ii;
typedef vector<int> vi;

int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int x,y;cin >> x >> y;
	cout << x + y/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int T[2], A[2];
    int t, a;
    scanf("%d %d %d %d", T, T + 1, A, A + 1);
    t = T[0] / A[1] + ((T[0] % A[1]) ? 1 : 0);
    a = A[0] / T[1] + ((A[0] % T[1]) ? 1 : 0);

    if (t >= a) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

s = [None] * N
l, c, r = 0, N//2, N-1

while True:
    for i in (l, c, r):
        if s[i] == None:
            print(i, flush=True)
            s[i] = input()
            if s[i] == 'Vacant':
                exit()
    if ((c-l)%2==0 and s[l]!=s[c]) or ((c-l)%2 and s[l]==s[c]):
        r = c
        c = (l + r) // 2
    else:
        l = c
        c = (l + r) // 2


Measured memory_bytes: 4424
#include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18

        signed main() {
 
    
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n,k;
        cin>>n>>k;
        vector<int> v(n+1);
        for(int i=1;i<=n;i++)
            cin>>v[i];

        map<int,int> mp;
        vector<int> loop;
        int jump=1;
        while(mp[jump]==0){
            mp[jump]=1;
            loop.pb(jump);
            jump = v[jump];
        }

        int sz = loop.size();
        int cnt=0;

        for(auto a : loop){
            if(a==jump){
                break;
            }
            cnt++;
        }

        sz = sz - cnt;
        
        if(k>cnt){
            k-=cnt;
            if(sz>0)
            k = k%sz;
            k = cnt+k;
            // cout<<k;
        }

        cout<<loop[k];
        return 0;
    }

Measured memory_bytes: 18560
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) cin >> A.at(i);
 
    ll lo = 0, hi = 1e6;
    ll ret = 0;
    ll cnt = 0;
    sort(A.begin(), A.end());
    vector<ll> AS(N + 1);
    for (ll i = 0; i < N; i++) AS[i + 1] = AS[i] + A[i];
 
    while (hi - lo > 1)
    {
        ll c = (lo + hi) / 2; //握手の幸福度
        ret = 0;
        cnt = 0;
        for (auto a: A) {
            auto itr = lower_bound(A.begin(), A.end(), c - a);
            ll i = itr - A.begin();
            cnt += A.end() - itr;
            ret += AS[N] - AS[i] + (A.end() - itr) * a;
        }
        (cnt >= M ? lo : hi) = c;
    }
    cout << ret - (cnt - M) * lo << endl;
}

Measured memory_bytes: 1792
a=int(input())
b=int(input())
c=int(input())
x=int(input())

ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x==(500*i+100*j+50*k):
                ans+=1
print(ans)


Measured memory_bytes: 3060
from operator import itemgetter as get
Res=[]
for i in range(int(input())):
    a,b=input().split()
    Res.append((a,int(b),i))
Res.sort(key=get(1))
Res.reverse()
Res.sort(key=get(0))
for i in Res:
    print(i[2]+1)


Measured memory_bytes: 3060
// Aizu 1166: Amazing Mazes
// 2017.9.14 bal4u@uu

#include <stdio.h>
#include <string.h>

#define QMAX 2000
#define N 1
#define E 2
#define S 4
#define W 8

typedef struct { int r, c; } Q;
Q que[QMAX+3]; int top, end;
char map[33][33], mk[33][33];
int w, h;
int m[4][4] = { { -1,0,N,S }, { 0,1,E,W }, { 1,0,S,N }, { 0,-1,W,E } }; 

int main()
{
	int i, r, c, r2, c2, tt, ans;

	while(scanf("%d%d", &w, &h) && w) {
		memset(mk, 0, sizeof(mk)), memset(map, 0, sizeof(map));
		for (r = 0; ; r++) {
			int a;
			for (c = 1; c < w; c++) { scanf("%d", &a); if (a) map[r][c-1] |= E, map[r][c] |= W; }
			if (r >= h-1) break;
			for (c = 0; c < w; c++) { scanf("%d", &a); if (a) map[r][c] |= S, map[r+1][c] |= N; }
		}
		ans = 0, tt = 1, que[0].r = que[0].c = 0, que[1].r = -1, top = 0, end = 2;
		while (top < end) {
			r = que[top].r, c = que[top++].c;
			if (r == h-1 && c == w-1) { ans = tt; break; }
			if (r < 0) { tt++, que[end].r = -1; if (++end >= QMAX) end = 0; continue; }
			for (i = 0; i < 4; i++) {
				r2 = r + m[i][0], c2 = c + m[i][1];
				if (r2 < 0 || r2 >= h || c2 < 0 || c2 >= w) continue;
				if ((map[r][c] & m[i][2]) || (map[r2][c2] & m[i][3])) continue;
				if (mk[r2][c2]) continue;
				mk[r2][c2] = 1;
				que[end].r = r2, que[end++].c = c2;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1724
#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
#include<stack>
//#include<Windows.h>
using namespace std;
typedef long long ll;typedef pair<int,int> pii;
typedef pair<ll,ll> pll;typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef vector<ll> vll;typedef vector<pll> vpl;
typedef unsigned long long ul;typedef queue<int> qii;typedef queue<pii> qpi;
int a[10005],n,m,k,ans;
char c;
bool use[1000005];
string s;
vector<int> v;
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			use[i*m+j*n-i*j*2]=1;
//	for(int i=0;i<=m*n;i++) if(use[i]) cout<<i<<'\n';
	use[k]?puts("Yes"):puts("No");
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int MX=(1<<20);
int n , m , Q;
int col[MX] , color;
bool vis[MX][11];
vector < int > v[MX];
void dfs(int x , int rem){
    if(rem < 0) return;
    for(int j = rem ; j < 11 ; j++) if(vis[x][rem]) return;
    vis[x][rem] = 1;
    if(!col[x])
        col[x] = color;
    for(auto nxt : v[x])
        dfs(nxt , rem - 1);
}
int main(){
    scanf("%d %d",&n,&m);
    for(int j = 1 ; j <= m ; j++){
        int a , b;
        scanf("%d %d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector < pair < int , pair < int , int > > > aa; cin>>Q;
    for(int j = 1 ; j <= Q ; j++){
        int a , b , c;
        scanf("%d %d %d",&a,&b,&c);
        aa.push_back({a , {b , c}});
    }
    for(int j = Q - 1; j >= 0 ; j--){
        color = aa[j].second.second;
        dfs(aa[j].first , aa[j].second.first);
    }
    for(int j = 1 ; j <= n ; j++) printf("%d\n",col[j]);
}


Measured memory_bytes: 34416
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
lld A[lim];

int main(){
    lld n = sc(), mn = INT_MAX, sum = 0;
    rep(i,0,n-1) A[i] = sc(), sum += A[i];
    sort(A, A + n);
    lld ans = A[n - 1];
    int ind = n - 2, count = 2;
    rep(i,1,n-2) {
        ans += A[ind];
        count--;
        if(count == 0) count = 2, ind--;
    }
    prL(ans);
    return 0;
}


Measured memory_bytes: 5388
using System;
using System.Linq;
//using System.Collections.Generic;

class Test
{
    static void Main()
    {
        string s;
        while ((s = Console.ReadLine()) != "0")
        {
            int n = int.Parse(s);
            double[] p = Console.ReadLine().Split().Select(double.Parse).ToArray();

            double m = p.Average();
            double sum = 0;
            foreach (double x in p)
            {
                sum += Math.Pow(x - m, 2);
            }

            Console.WriteLine(Math.Sqrt(sum / n));
        }
    }
}


Measured memory_bytes: 16360
n,xx,yy = map(int,input().split())
x = xx-1
y = yy-1

disset = [0]*(n-1)

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


for i in disset:
    print(i)

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

int main(){

    cout.precision(10);
    int N;
    long double temp1;
    cin >> N;
    vector<long double> p, q;
    for(int i=0;i<N;i++){
        cin >> temp1;
        p.push_back(temp1);
        q.push_back(1-temp1);
    }
    vector<vector<long double> > dp(N, vector<long double> (N+2, 0.0));
    dp[0][1] = q[0];
    dp[0][2] = p[0];
    for(int i = 1; i< N;i++){
        for(int j=1;j<N+2;j++){
            dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * q[i];
        }
    }

    auto it1 = dp[N-1].begin() + (N+3)/2;
    cout << accumulate(it1, dp[N-1].end(), 0.0) << endl;

    return 0;
}

Measured memory_bytes: 141184
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;

    ll mini = a * (n - 1) + b;
    ll maxi = a + b * (n - 1);

    cout << max(0LL, maxi - (mini - 1)) << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class CFennecVsMonster {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N, K;
        in >> N >> K;
        vector<ll> H(N);
        REP(i,0,N) in >> H[i];
        sort(all(H));
        ll answer = 0;
        REP(i,0,N-K) {
            answer += H[i];
        }
        out << answer << "\n";
    }
};


signed main() {
    CFennecVsMonster solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> m;
	ll cursum = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cursum += x;
		m[x]++;
	}
	int q;
	cin >> q;
	while(q--) {
		int b, c;
		cin >> b >> c;
		int num = m[b];
		m[b] = 0;
		m[c] += num;
		cursum += (c-b)*num;
		cout << cursum << endl;
	}
	return 0;
}



Measured memory_bytes: 7956
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,K; cin>>N>>K;
  vector<ll> h(N); rep(i,N) cin>>h[i];
  
  //dp
  vector<ll> table(N,INF);
  
  function<ll(ll)> dp=[&](ll i){
    if(i<=0) return 0LL;
    if(table[i]<INF) return table[i];
    
    ll ret=INF-1;
    for(int j=1;j<=K;j++) if(i-j>=0) chmin(ret,dp(i-j)+abs(h[i]-h[i-j]));
    
    return table[i]=ret;
  };
  
  cout<<dp(N-1)<<endl;
  
  return 0;
}

Measured memory_bytes: 12660
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int N, M;
map<string, int> m;

int main(void){
    cin >> N;
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        m[s]++;
    }

    cin >> M;
    for(int i = 0; i < M; i++){
        string t; cin >> t;
        m[t]--;
    }

    int res = 0;
    for(auto it: m){
        res = max(res, it.second);
    }

    cout << res << '\n';

    return 0;
}

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

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

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    int n, x;
    cin >> n >> x;
    int d = 0;
    int bound = 1;
    for (size_t i = 0; i < n; i++) {
        int l;
        cin >> l;
        d = d + l;
        if (d <= x) {
            bound++;
        }
    }
    cout << bound << endl;
}


Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


while True:
    input_str = input()
    if len(input_str) == 1 and input_str[0] == "0":
        break

    need,budget,aizu,normal,limit = map(int,input_str.split())

    left = 1;right = limit
    mid = (left+right)//2
    num_aizu = 0;num_normal = 0

    while left <= right:
        rest = budget-mid*aizu
        tmp_normal = rest//normal
        if rest >= 0 and mid+tmp_normal >= need:
            num_aizu = mid
            num_normal = tmp_normal
            left = mid+1
        else:
            right = mid-1
        mid = (left+right)//2

    if num_aizu == 0:
        print("NA")
    else:
        print("%d %d"%(num_aizu,num_normal))


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

using namespace std;
typedef long long ll;
const int nax = 20;

ll mat[nax][nax];

vector<ll>dp;
vector<ll>prec;

void solve(vector<int> free, int mask, int group, ll current_score, int poz)
{
    if(poz == free.size())
    {
        dp[mask] = max(dp[mask], current_score + prec[group]);
        return;
    }

    dp[mask] = max(dp[mask], current_score + prec[group]);
    solve(free, mask, group, current_score, poz + 1);
    solve(free, mask + (1 << free[poz]), group + (1 << free[poz]), current_score, poz + 1);
}

int main()
{
    int n;

    cin >> n;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> mat[i][j];

    dp.resize(1 << n);
    prec.resize(1 << n);

    for(int mask = 0; mask < (1 << n); mask++)
        for(int a = 0; a < n; a++)
            if(mask & (1 << a))
                for(int b = a + 1; b < n; b++)
                    if(mask & (1 << b))
                        prec[mask] += mat[a][b];

    for(int mask = 0; mask < (1 << n); mask++)
    {
        vector<int>free;
        for(int a = 0; a < n; a++)
            if(!(mask & (1 << a)))
                free.push_back(a);

        solve(free, mask, 0, dp[mask], 0);
    }

    cout << dp[(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 4292
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll x, y;
  cin >> x >> y;
  int ans = 0;
  while (x <= y) {
    ans++;
    x *= 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
 
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if((a % 3 == 0)||(b % 3 == 0)||((a + b) % 3 == 0)) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define IOS             ios::sync_with_stdio(false); cin.tie(nullptr)
#define deb(x)          cout << #x << " = " << x << endl
#define deb2(x, y)      cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)     for(i = a; i < n; i++)
#define f1(i, a, n)     for(i = a; i <= n; i++)
#define tc(t)           int t; cin >> t; while(t--)
#define ini(x, y)       memset(x, y, sizeof(x))
#define all(x)          x.begin(),x.end()
#define sz(x)           x.size()
#define ll              long long int
#define vi              vector<int>
#define si              set<int>
#define pb              emplace_back
#define ppb             pop_back
#define mp              make_pair
#define M               1000000007
#define endl            '\n'
#define bits(x)         __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)

using namespace std;

void solve() {
    int n, x, t, ans;
    cin >> n >> x >> t;
    ans = ceil(n/double(x)) * t;
    cout << ans << endl;
}

int main () {
    IOS;
    // tc(t)
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>

int main(){
    int N;
    std::vector<int> vec; 
    std::cin >> N;
    for(int i = 0; i < N; i++){
        int d;
        std::cin >> d;
        vec.push_back(d);
    }

    for(int i = 0; i < N; i++){
      //  std::cout << vec.at(i) << std::endl;

    }

    int total = 0;
    for(int i = 0; i < N - 1; i++){
        for(int j = i+1; j < N; j++){
            int x = vec.at(i);
            int y = vec.at(j);
            if(i == j){
                continue;
            }
            //std::cout << x << " " << y << std::endl;
            
            total = total + (x * y);
        }
    }
    std::cout << total << std::endl;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
ans = 0

if ans < a + b*10 + c: ans = a + b*10 + c
if ans < a + c*10 + b: ans = a + c*10 + b
if ans < b + a*10 + c: ans = b + a*10 + c
if ans < b + c*10 + a: ans = b + c*10 + a
if ans < c + a*10 + b: ans = c + a*10 + b

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

using namespace std;

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

  string ans = "NO";
  if(a <= x && x <= a + b) {
    ans = "YES";
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
L=["dream","dreamer","erase","eraser"]
S=input()
t=""
a,b=0,0

while len(t)<len(S):
  if S[a:a+7]=="dreamer" and S[a+5:a+8]!="era":
    t=t+"dreamer"
    a=a+7
  elif S[a:a+6]=="eraser":
    t=t+"eraser"
    a=a+6
  elif S[a:a+5]=="dream":
    t=t+"dream"
    a=a+5
  elif S[a:a+5]=="erase":
    t=t+"erase"
    a=a+5
  else:
    print("NO")
    break

if len(t)==len(S):
  print("YES")

Measured memory_bytes: 3316
#include <cstdint>
#include <string>
#include <iostream>

int main(int argc, char* argv[])
{
	int32_t L, R, d;
	std::cin >> L;
	std::cin >> R;
	std::cin >> d;
	int cnt = 0;
	for (int i = L; i <= R; ++i)
	{
		cnt += (i % d == 0) ? 1 : 0;
	}
	
	std::cout << cnt << std::endl;
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>

#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;

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


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	a := 0
	b := 0
	c := 0
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	ret := c - (a - b)
	if ret < 0 {
		ret = 0
	}
	fmt.Printf("%v\n", ret)
}


Measured memory_bytes: 512
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;


int main()
{
    int64_t N;
    std::cin >> N;

    using G = std::unordered_map<int64_t, std::vector<int64_t>>;

    G g;

    for (size_t i = 0; i < N-1; ++i) {
        int64_t a, b;
        std::cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    std::vector<int64_t> dfe(N, -1);
    std::vector<int64_t> dsu(N, -1);

    auto f = [&dfe, &g](auto F, int dist, int64_t from, int64_t prev) -> void {
        dfe[from] = dist;
        for (auto& to: g[from]) {
            if (dfe[to] == -1 && to != prev) {
                F(F, dist+1, to, from);
            }
        }
    };

    f(f, 0, 0, -1);

    auto s = [&dsu, &g](auto F, int dist, int64_t from, int64_t prev) -> void {
        dsu[from] = dist;
        for (auto& to: g[from]) {
            if (dsu[to] == -1 && to != prev) {
                F(F, dist+1, to, from);
            }
        }
    };
    s(s, 0, N-1, -1);

    size_t b, w;
    b = w = 0;
    for (size_t i = 0; i < N; ++i) {
        if (dfe[i] <= dsu[i]) {
            b++;
        }
        else {
            w++;
        }
    }
    if (b > w) {
        std::cout << "Fennec" << std::endl;
    }
    else {
        std::cout << "Snuke" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 15268
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N;
int main(){
    int n;
    cin >> N;
    n = N;
    int sum = 0;
    while(N > 0){
        sum += N % 10;
        N /= 10;
    }
    if(n % sum == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	int n;
	int res = 0;
	cin >> n ;

	ce(n*n);

	
}



int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

int main(){
  int n,ans = 1;
  int mod = 1000000007;
  scanf("%d",&n);
  bool flag = true;
  int a[(n+1)/2];
  fill(a,a+(n+1)/2,0);
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    a[x/2]++;
    if((x-n)%2==0||x>=n) flag = false;
  }
  if(n%2==0){
    if(a[0]!=2) flag = false;
    for(int i=1;i<(n+1)/2;i++) if(a[i]!=2) flag = false;
  }
  if(n%2==1){
    if(a[0]!=1) flag = false;
    for(int i=1;i<(n+1)/2;i++) if(a[i]!=2) flag = false;
  }
  for(int i=0;i<n/2;i++){
    ans *= 2;
    ans %= mod;
  }
  if(flag) printf("%d\n",ans);
  else printf("0\n");
  return 0;
}


Measured memory_bytes: 512
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    a.append(str(input()))
for j in range(m):
    b.append(str(input()))
#print(a)
#print(b)
isOK = False
#print(a[0][0:m])
#print(b[0])
#print(a[0][1:m+1])
#print(b[0])
#print(a[1][0:m])
#print(b[1])
#print(a[1][1:m+1])
#print(b[1])

for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j:j+m] == b[0]:
            cnt = 1
            for k in range(1,m):
                if a[i+k][j:j+m] == b[k]:
                    cnt += 1
            if cnt == m:
                isOK = True
                break
if isOK:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 9216
N = input()
i = 1
total = 0
digits = [i for i in range(len(N)) if i != 0 and i % 2 != 0]

if len(N) % 2 != 0:
    total = int(N) - int(str(1) + (len(N)-1)*"0") + 1
    for digit in digits:
        total += int("9"*digit) - int("1"+"0"*(digit-1)) + 1
elif len(N) % 2 == 0:
    for digit in digits:
        total += int("9"*digit) - int("1"+"0"*(digit-1)) + 1

print(total)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

int h, w;
vector<string> get_target_table(const vector<string> &table)
{
    vector<string> res;
    for (int i = 0; i < h; i++)
    {
        bool not_black = true;
        for (int j = 0; j < w; j++)
        {
            if (table[i][j] == '#')
                not_black = false;
        }
        if (not_black == false)
            res.push_back(table[i]);
    }
    return res;
}

void solve()
{
    cin >> h >> w;
    vector<string> table(h);
    for(int i = 0; i < h; i++) cin >> table[i];

    vector<string> ans = get_target_table(table);

    vector<int> v;
    for(int j = 0; j < w; j++)
    {
        bool not_black = true;
        for(int i = 0; i < h; i++)
        {
            if(table[i][j] == '#') not_black = false;
        }
        if(not_black) v.push_back(j);
    }

    reverse(v.begin(), v.end());
    for(int i = 0; i < ans.size(); i++)
    {
        for(int j = 0; j < w; j++)
        {
            bool ok = true;
            for(int k = 0; k < v.size(); k++)
            {
                if(v[k] == j) ok = false;
            }
            if(ok) cout << ans[i][j];
        }
        cout << endl;
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        if(a == b) {
            System.out.println((b != c) ? "Yes" : "No");
        } else if(b == c) {
            System.out.println((c != a) ? "Yes" : "No");
        } else if(c == a) {
            System.out.println((a != b) ? "Yes" : "No");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21972
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

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

    char a = N[N.size() - 1];

    if(a == '2' || a == '4' || a == '5' || a == '7' || a == '9'){
        cout << "hon" << endl;
    }else if(a == '0' || a == '1' || a == '6' || a == '8'){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
}

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

using namespace std;
typedef long long ll;

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

  int n, k;
  cin >> n >> k;

  int res = k;
  for (int i = 1; i < n; ++i) {
    res *= k - 1;
  }
  cout << res << "\n";
}


Measured memory_bytes: 3548
#include <stdio.h>

int main(void){
  int a[200];
  int b[200];
  int ans[200];
  int num;
  int cnt;
  
  int i=0;
  while(scanf("%d", a+i) != EOF){
    num = 0;
    scanf(" %d", b+i);
    num = a[i] + b[i];
    ans[i] = 0;
    while( num ){
      num /= 10;
      ans[i]++;
    }
    
    i++;
  }
  
  int j;
  for( j = 0; j < i; j++ ){
    printf("%d\n", ans[j]);
  }
    
    
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h,w;
  cin >> h >> w;
  vector<bool> x(w,false);
  vector<bool> y(h,false);
  vector<vector <char>> board(h,vector<char>(w));
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin >> board.at(i).at(j);
    }
  }
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (board.at(i).at(j) == '#') {
        y[i] = true;
        x[j] = true;
      }
    }
  }
  for (int i=0; i<h; i++) {
    if (y[i] == true) {
      for (int j=0; j<w; j++) {
        if (x[j] == true) {
          cout << board.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               int n,m;
               cin>>n>>m;
               int a[n+1];
               int b[n+1];
               memset(b,0,sizeof(b));
               b[1]=1;
               for(int i=1;i<=n;++i)
                    a[i] = 1;
               int count=0;
               int x,y;

               for(int i=1;i<=m;++i)
               {
                    cin>>x>>y;
                    if(b[x]==1)
                    {
                         b[y]=1;
                    }
                    a[x]--;
                    a[y]++;
                    if(a[x]==0)
                         b[x]=0;

               }
               for(int i=1;i<=n;++i)
               {
                    //cout<<b[i]<<" ";
                    if(b[i])
                         count++;
               }
               cout<<count;

       }
}


Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>
#define int long long 
int n;
map<P,int>ta;
vector<P>G[111111];
int x[111111],y[111111];
bool visit[111111];
int dist[111111];

signed main(){
    cin>>n;
    rep(i,n)cin>>x[i]>>y[i];

    vector<tuple<int,int,int> >tmp;
    tmp.clear();
    rep(i,n)tmp.pb(make_tuple(x[i],y[i],i));

    sort(tmp.begin(),tmp.end());
    rep(i,n-1){
        int a=get<0>(tmp[i]),c=get<2>(tmp[i]);
        int a2=get<0>(tmp[i+1]),c2=get<2>(tmp[i+1]);
        G[c].pb(mp(c2,a2-a));
        G[c2].pb(mp(c,a2-a));
    }


    tmp.clear();
    rep(i,n)tmp.pb(make_tuple(y[i],x[i],i));

    sort(tmp.begin(),tmp.end());
    rep(i,n-1){
        int a=get<0>(tmp[i]),c=get<2>(tmp[i]);
        int a2=get<0>(tmp[i+1]),c2=get<2>(tmp[i+1]);
        G[c].pb(mp(c2,a2-a));
        G[c2].pb(mp(c,a2-a));
    }

    priority_queue<P,vector<P>,greater<P> >q;
    q.push(mp(0,0));

    while(!q.empty()){
        int from=q.top().second,cost=q.top().first;
        q.pop();
        if(visit[from])
            continue;
        visit[from]=1;
        dist[from]=cost;
        for(int i=0;i<G[from].size();i++){
            int next=G[from][i].first,next_cost=G[from][i].second;
            q.push(mp(next_cost,next));
        }
    }
    int ans=0;
    rep(i,n)ans+=dist[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 24432
#include <iostream>
#include <unordered_set>
#include <iterator>
#include <vector>

long gcd(long a, long b)
{
  if (a<b) return gcd(b, a);
  else if (!b) return a;
  else return gcd(b, a%b);
}

long lcm(long x, long y)
{
  long g = gcd(x, y);
  return (x/g) * y;
}

int main()
{
  int N;
  std::unordered_set<long> s;
  std::vector<long> v;
  long long ans = 1;

  std::cin >> N;

  for (int i=0; i<N; i++) {
    long l;
    std::cin >> l;
    s.insert(l);
  }

  for (auto iter=s.begin(); iter!=s.end(); iter++) {
    v.push_back(*iter);
  }

  while(!(v.size() == 1)) {
    long l1 = v.back(); v.pop_back();
    long l2 = v.back(); v.pop_back();
    v.push_back(lcm(l1, l2));
  }

  ans = v.front();

  //std::cout << gcd(2,3);
  /*
  auto itr=s.begin();
  long l, m;
  l = *itr;
  itr++;
  for (; itr!=s.end(); itr++) {
    m = l;
    l = *itr;
    long g = gcd(l, m);
    //std::cout << g << std::endl;
    ans *= (l/g) * (m/g);
  }
  */

  std::cout << ans;
  return 0;
}


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

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

Measured memory_bytes: 256
a,b = map(int, input().split())

def height(n):
    sum = 0
    for i in range(n+1):
        sum += i
    return sum
    
#    if n==1:
#        return 1
#    else:
#        return n+height(n-1)
    
d = height(b-a)
print(d-b)

Measured memory_bytes: 2940
n = [int(x) for x in input()]
op_cnt= len(n)-1 #3
for bit in range(2**op_cnt):
    op = ["-"] * op_cnt
    for i in range(op_cnt):
        if ((bit>>i) & 1):
            op[op_cnt-1-i] = "+"
    lis = []
    lis.append(str(n[0]))
    lis.append(op[0])
    lis.append(str(n[1]))
    lis.append(op[1])
    lis.append(str(n[2]))
    lis.append(op[2])
    lis.append(str(n[3]))
    calc = ""
    for item in lis:
        calc += item
    if eval(calc) == 7:
        print(calc+ "=7")
        break
    

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
   int a,b,i;
   scanf("%d %d",&a,&b);

   if(a>b){
      for(i=0;i<a;i++){
         printf("%d",b);
      }
   } else {
      for(i=0;i<b;i++){
         printf("%d",a);
      }
   }
   return 0;
}


Measured memory_bytes: 1728
import java.util.Scanner;

/**
 *
 * @author kouki
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = y%x;
        if (z==0) {
            System.out.println(x+y);
        }else{
            System.out.println(y-x);
        }
        
    }
    
}

Measured memory_bytes: 23764
N, Y = map(int, input().split())
ans = '-1 -1 -1'

for i in range(N + 1):
    for j in range(N + 1):
        if Y == 10000 * i + 5000 * j + 1000 * (N - i - j)\
        and i + j + (N - i - j) <= N\
        and N - i - j >= 0:
            ans = str(i) + ' ' + str(j) + ' ' + str(N - i - j)
print(ans)

Measured memory_bytes: 3060
#include <iostream>

int main(){

  int i, n, x, m, min, all;
  min = 100010;
  all = 0;
  
  scanf("%d %d", &n, &x);
  for(i=0; i<n; i++){
    scanf("%d",&m);
    if(m<min)min = m;
    all += m;
  }
  printf("%d\n", (x-all)/min+n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        int n, a, b, c, x;
        while(scanf("%d%d%d%d%d", &n, &a, &b, &c, &x) && n){
                int y[n];
                rep(i, n) scanf("%d", &y[i]);
                int ans=0;
                int i=0;
                while(true){
                        if(y[i]==x){
                                ++i;
                                if(i==n) break;
                        }
                        x=(a*x+b)%c;
                        ++ans;
                        if(ans>10000) break;
                }
                printf("%d\n", ans>10000 ? -1 : ans);
        }
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int p, q, r;
    cin >> p >> q >> r;

    cout << min(p + q, min(q + r, r + p)) << endl;

    return 0;
}


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

int main(void)
{
	int x,n;
	cin>>x>>n;
	if(n == 0) {cout<<x<<endl; return 0;}
	int p[n];
	bool flag = false;
	for(int i = 0; i < n; i++)
	{
		cin>>p[i];
	}
	for(int y : p)
	{
		if(y == x)
		{
			flag = true;
			break;
		}
		else
		{
			flag = false;
		}
	}
	if(!flag)
	{
		cout<<x<<endl;
	}
	else
	{
		bool flaG = false;
		bool flaGG = false;
		int a = x;
		int b = x;
		while(1)
		{
			if(flaG)
			break;
			for(int y : p)
			{
				if(a == y)
				{
					flaG = false;
					break;
				}
				else
				{
					flaG = true;
				}
			}
			a++;
		}
		while(1)
		{
			if(flaGG)
			break;
			for(int y : p)
			{
				if(b == y)
				{
					flaGG = false;
					break;
				}
				else
				{
					flaGG = true;
				}
			}
			b--;
		}
		int q1 = abs(x - a);
		int q2 = abs(x - b);
		
		if(q1 < q2)
			cout<<--a<<endl;
		else
			cout<<++b<<endl;
	}
	return 0;
}


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

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

const int inf = (int)1e9 + 7;
char s[25][25];
vector <vector <int> > d;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int main(void){
  	int N, M;
  	cin >> N >> M;
  	REP(i,N) cin >> s[i];
  	
  	int ans = 0;
  	REP(i,N) REP(j,M) if (s[i][j] != '#'){
				d.clear();
				d.resize(N, vector<int> (M, inf));
				queue < pair <int, int> > q;
				q.push({i, j});
				d[i][j] = 0;
				while (!q.empty()){
		  		pair<int, int> p = q.front();
		  		q.pop();
		  		REP(D,4){
				  	int nx = p.first + dx[D];
				  	int ny = p.second + dy[D];
				  	if (nx >= 0 && nx < N && ny >= 0 && ny < M && s[nx][ny] != '#' && d[nx][ny] > d[p.first][p.second] + 1) {
						d[nx][ny] = d[p.first][p.second] + 1;
						ans = max(ans, d[nx][ny]);
						q.push({nx, ny});
				  	}
		  		}
			}
	}
  	cout << ans << endl;
  	return 0;
}

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

int main()
{
   int n,i;
   cin>>n;
   string s;
   cin>>s;
   int count=1;
   char prev=s[0];
   for(i=1;i<n;i++)
   {
       if(s[i]==prev)
        continue;
        else
        {
            count++;
            prev=s[i];
        }
   }
   cout<<count<<"\n";
   return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(long long i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int N,M;
  cin >> N >> M;
  cout << N*M - M - N + 1 << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int main(void) {
    int i, n;
    cin >> n;
    int ans = 0;
    REP (i,1,n) ans += i;
    cout << ans << 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[] array = new int[8];
        int free=0;
        for(int i=0;i<n;i++){
            int temp = sc.nextInt();
            if(temp<400) array[0]++;
            else if(temp<800) array[1]++;
            else if(temp<1200) array[2]++;
            else if(temp<1600) array[3]++;
            else if(temp<2000) array[4]++;
            else if(temp<2400) array[5]++;
            else if(temp<2800) array[6]++;
            else if(temp<3200) array[7]++;
            else free++;
        }
        int ans=0;
        for(int i=0;i<8;i++){
            if(array[i]!=0)  ans++;
        }
        if(ans==0) System.out.println(1+" "+free);
        else System.out.println(ans+" "+(ans+free));
        sc.close();
    }
}

Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
 int n;
   cin >> n;
  
  vector<long> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
   }
  
   int res=0;
   for(int i=1;i<n;i++){
   if(a[i]==a[i-1]){ a[i]=0;
     res++;
   }
  }  
  cout << res << endl;

}

Measured memory_bytes: 256