akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 998244353
#define ALL(x) std::begin(x), std::end(x)


long long modpow(long long x, long long y)
{
  long long p = 1;

  for ( ; y; (x *= x) %= MOD, y >>= 1)
    if (y & 1)
      (p *= x) %= MOD;

  return p;
}


class ncr_t {
public:
  std::vector<long long> compute(int n) const {
    std::vector<long long> a(n + 1);

    a[0] = a[n] = 1;

    for (int i = 1; i <= n / 2; i ++) {
      long long c = a[i - 1];

      (c *= (n - (i - 1))) %= MOD;

      (c *= modpow(i, MOD - 2)) %= MOD;

      a[i] = a[n - i] = c;
    }

    return std::move(a);
  };
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  ncr_t ncr;

  long long A, B, K;

  std::cin >> N >> A >> B >> K;

  std::vector<long long> a = ncr.compute(N);
  
  long long C = 0;

  for (long long i = 0; i <= N; i ++) {
    long long r = K - A * i;

    if (r < 0)
      break;

    if (r % B)
      continue;

    long long j = r / B;

    if (j > N)
      continue;

    (C += a[i] * a[j] % MOD) %= MOD;
  }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 2560
s[51],a[51],b[51],t;short*p;Q(){for(p=a;*p=='=Q';p++);}main(i){for(;~scanf("%[^\n]\n",s);i=0)i||puts(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,a)-3||t-'~'|strcmp(a,b)?sscanf(s,">^%[Q=]~%c%c",a,&t,a)-2||t-'~'|(Q(),*p&7|p==a)?"NA":"B":"A");}

Measured memory_bytes: 0
#include <stdio.h>
int main() {
	int r, g, b, n, cnt = 0;
	scanf("%d%d%d%d", &r, &g, &b, &n);
	for (int i = 0; i <= n / r; i++) {
		for (int j = 0; j <= n / g; j++) {
			int num = n - i * r - j * g;
			if (num >= 0 && num % b == 0) {
				cnt++;
				// printf("%d %d %d\n", i, j, num / b);
			}
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stack>
#include <map>
#include <stdlib.h>
#include <string>
#include <locale>
#include <set>
#include <queue>
const unsigned int M = 1000000007;

using namespace std;
#define ll long long
#define sz (int)size()
#define pb push_back
#define lim(v) v.begin(),v.end()
#define se second
#define fi first
#define mp make_pair

map<int,int> col;
map<int,int> Dl;
map<int,int> Dr;




int main(){


char c;
  cin>>c;
  char b=c+1;
  cout<<b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  char c='a';
  for(int i=0;i<26;i++){
    for(int j=0;j<s.size();j++){
      if(s.at(j)==c)
        break;
      if(j==s.size()-1){
        cout<<c;
        return 0;
      }
    }
    c++;
  }
  cout<<"None";
}

Measured memory_bytes: 512
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

struct BIT {
    ll n;
    vector<ll> bit;
    BIT(ll n):n(n),bit(n+1,0) {}

    void add(ll i, ll x){
        if(i==0) return;
        for(ll k =i ; k <= n; k += (k & -k)){
            bit[k]+=x;
        }
    }

    ll sum(ll i) {
        if (i < 0) return 0;
        ll s = 0;
        for (int k = i; k > 0; k -= (k & -k)) {
            s += bit[k];
        }
        return s;
    }

    ll sum2(ll l, ll r) {
        return sum(r)-sum(l-1);
    }
};

void solve()
{
    IN(n, q);
    VIN(ll, c, n);
    rep(i, n) {
        --c[i];
    }
    V<pair<ll,pair<ll,ll>>> v;
    rep(i, q) {
        IN(l, r);
        v.emplace_back(r, make_pair(l,i));
    }
    sort(all(v));
    ll last[n];
    rep(i, n) {
        last[i] = INF;
    }
    int j = 0;
    BIT bit(n);
    ll res[q];
    rep(i, q) {
        for(int k = j; k < v[i].first; ++k) {
            ll l = last[c[k]];
            last[c[k]] = k+1;
            if (l != INF) bit.add(l, -1);
            bit.add(last[c[k]], 1);
        }
        j = v[i].first;
        res[v[i].second.second] = bit.sum2(v[i].second.first, v[i].first);
    }
    rep(i, q) {
        cout << res[i] << endl;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	
	UnionFind() {}
	UnionFind(int n) {
		init(n);
	}
	
	int operator[] (int x) {
		return find(x);
	}

	void init(int n) {
		par.resize(n);
		rank.resize(n);
		REP(i, n) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

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

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int n, m;
	while (cin >> n >> m, n || m) {
		
		priority_queue<pip, vector<pip>, greater<pip> > pq;
		REP(i, m) {
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			pq.push(pip(c, pii(a, b)));
		}
		
		UnionFind uf(n);
		int ans = 0;
		while (!pq.empty()) {
			pip now = pq.top(); pq.pop();
			
			int c = now.fi;
			int u = now.se.fi, v = now.se.se;
			
			if (uf.same(u, v)) continue;
			ans += c;
			uf.unite(u, v);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);

    $d = floor((int)$data[0] / (int)$data[1]);
    $r = (int)$data[0] % (int)$data[1];
    $f = (int)$data[0] / (int)$data[1];

    printf("%d %d %f\n", $d, $r, $f);
}

Measured memory_bytes: 15480
N, H = map(int, input().split())
ma = 0
B = []
for _ in range(N):
    a, b = map(int, input().split())
    ma = max(ma, a)
    B.append(b)
B = sorted([b for b in B if b > ma])
ans = 0
while H > 0 and B:
    H -= B.pop()
    ans += 1
if H > 0:
    ans += -(-H//ma)
print(ans)

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

ll solve(ll n,ll k){
return min(n%k,abs(k-n%k));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

ll n,k;

cin>>n>>k;
cout<<solve(n,k)<<endl;
return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end

using mint = ModInt<MOD>;

mint dp[1000010][2][2];
int main() {
    int N; cin >> N;
    dp[0][0][0] = mint(1);
    for(int i=0; i<N; i++) {
        for(int f1=0; f1<2; f1++) {
            for(int f2=0; f2<2; f2++) {
                for(int x=0; x<10; x++) {
                    dp[i+1][f1 || (x==0)][f2 || (x==9)] += dp[i][f1][f2];
                }
            }
        }
    }
    cout << dp[N][1][1] << endl;
    return 0;
}


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

int main(void){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    vector<int> vecx(n), vecy(m);
    for(int i=0; i<n; i++){
        cin >> vecx.at(i);
    }
    for(int i=0; i<m; i++){
        cin >> vecy.at(i);
    }
    sort(vecx.begin(), vecx.end());
    sort(vecy.begin(), vecy.end());

    string ans = "War";
    for(int i=x+1; i<=y; i++){
        if(vecx.at(n-1) < i && vecy.at(0) >= i){
            ans = "No War";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		double x[]=new double[100],y[]=new double[100],s;
		int n=scan.nextInt(),i;
		for(i=0;i<n;i++) x[i]=scan.nextDouble();
		for(i=0;i<n;i++) y[i]=scan.nextDouble();
		scan.close();
		s=0;
		for(i=0;i<n;i++) s+=Math.abs(x[i]-y[i]);
		System.out.println(s);
		s=0;
		for(i=0;i<n;i++) s+=Math.pow(Math.abs(x[i]-y[i]), 2);
		System.out.println(Math.sqrt(s));
		s=0;
		for(i=0;i<n;i++) s+=Math.pow(Math.abs(x[i]-y[i]), 3);
		System.out.println(Math.pow(s, 1./3));
		s=0;
		for(i=0;i<n;i++) if(Math.abs(x[i]-y[i])>s) s=Math.abs(x[i]-y[i]);
		System.out.println(s);
	}
}


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

int main()
{
 int i = 1;
 int x;
 while (cin >> x) {
   if ( x == 0 ){
     break;
   }
   cout << "Case" << " " << i << ": " << x << endl;
   ++i;
 }
}

Measured memory_bytes: 1160
import math


def main():
    H, W = [int(a) for a in input().split()]
    A = [[int(a) for a in input().split()] for _ in range(H)]

    od = None
    res = []
    for i in range(H):
        if i % 2 == 0:
            r = range(W)
        else:
            r = reversed(range(W))
        for j in r:
            cell = A[i][j]
            if od is None:
                if cell % 2 != 0:
                    od = i, j
            else:
                res.append((od[0],od[1], i, j))
                if cell % 2 == 0:
                    od = i, j
                else:
                    od = None

    print(len(res))
    for a, b, c, d in res:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22616
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
	for (auto x : V)	cout << x << ' ' ;
	cout << '\n';
}
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int32_t main()
{
	SYNC
	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n+x-1)/x) * t;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n, INF), b(n - 1);
    rep(i, 0, n - 1){
        cin >> b[i];
        a[i] = min(a[i], b[i]);
        a[i + 1] = min(a[i + 1], b[i]);
    }
    int ans = 0;
    rep(i, 0, n) ans += a[i];
    cout << ans << endl;
}

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

using namespace std;

int main() {
    string w, s;
    cin >> w;
    int count = 0;
    while (cin >> s) {
        if (s == "END_OF_TEXT") {
            break;
        }
        for (auto& c : s) {
            c = ::tolower(c);
        }
        if (s == w) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
#define h first
#define w second
vector<pair<bool,pair<int,int> > >v;
int n,m,p,q,r,i;
void Vp(bool a,int b,int c){v.push_back(make_pair(a,make_pair(b,c)));}
int main(){
	while(cin>>n&&n){
	cin>>m>>p>>q>>r;v.clear();
	Vp(1,1,r);Vp(0,r+1,n);
	while(m--){
		int x,y;cin>>x>>y;
		for(i=0;i<v.size();i++){
			int a=v[i].w.h,b=v[i].w.w;bool c=v[i].h;
			if(a<=x&&x<b){
				Vp(c,x+1,b);
				b=x;
			}
			if(a<=y&&y<b){
				Vp(c,y+1,b);
				b=y;
			}
			if(0<a&&b<=x)a+=n-x,b+=n-x;
			else if(x<a&&b<=y)a+=n-x-y,b+=n-x-y;
			else if(y<a&&b<=n)a-=y,b-=y;
			v[i].w.h=a,v[i].w.w=b;
		}
	}
	int ans=0;
	for(i=0;i<v.size();i++){
		if(v[i].h)ans+=max(0,1+min(v[i].w.w,q)-max(v[i].w.h,p));
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 900000000000000004
signed main(void){
    int h,w;cin>>h>>w;
    vector<vector<int>>G(81,vector<int>(81,0));
    rep(i,h)rep(j,w)cin>>G[i][j];
    rep(i,h)rep(j,w){
        int x;cin>>x;
        G[i][j]=abs(G[i][j]-x);
    }
    vector<vector<vector<bool>>>dp(81,vector<vector<bool>>(81,vector<bool>(6500,false)));
    rep(i,81)rep(j,81)rep(k,6500)dp[i][j][k]=false;
    dp[0][0][G[0][0]]=true;
    rep(i,h)rep(j,w)rep(k,6500){
        if(!dp[i][j][k])continue;
        dp[i][j+1][abs(k+G[i][j+1])]=true;
        dp[i][j+1][abs(k-G[i][j+1])]=true;
        dp[i+1][j][abs(k+G[i+1][j])]=true;
        dp[i+1][j][abs(k-G[i+1][j])]=true;
    }
    int ans=INF;
    rep(i,6500){
        if(dp[h-1][w-1][i])ans=min(ans,i);
    }
//    rep(i,h){
//        rep(j,w){
//int res=INF;
//            if(dp[i][j][k])res=min(res,k);
//        }
///        cout<<res<<' ';
//    }
//    cout<<endl;
//    }
    cout<<ans<<endl;
}
        


Measured memory_bytes: 6016
tasks = input()

tasks = [int(t) for t in tasks.split()]

# 0, 1, 2
cost0 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[1])

# 0, 2, 1
cost1 = abs(tasks[2] - tasks[0]) + abs(tasks[2] - tasks[1])

# 1, 0, 2
cost2 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[0])

# 1, 2, 0
cost3 = abs(tasks[1] - tasks[2]) + abs(tasks[2] - tasks[0])

# 2, 0, 1
cost4 = abs(tasks[2] - tasks[0]) + abs(tasks[0] - tasks[1])

# 2, 1, 0
cost5 = abs(tasks[2] - tasks[1]) + abs(tasks[0] - tasks[1])

min_cost = min([cost0, cost1, cost2, cost3, cost4, cost5])

print(min_cost)


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

typedef long long ll;

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

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

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


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

int main() 
{
//	cout<<"GfG!";

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a!=0  && c!=0)
    {
        c = c-b;
        if(c<=0)
            break;
        a = a - d;
        if(a<=0)
            break;
    }
    if(a>0)
        cout<<"Yes";
    else
        cout<<"No" ;
    
    
	return 0;
}

Measured memory_bytes: 3624
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input;
  var N =  Number(input);
  var result = 0;
  for(var i = 1; i <= N; i++){
    if(String(i).length%2 === 1){
      result++; 
    }
  }
  console.log(result);
 }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int p = 1,w = 1,g = 1,y = 1;
  int kind = 0;
 
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if ( S =="P" && p) {
      kind++;
      p--;
    }
    else if (S =="W" && w) {
      kind++;
      w--;
    }
    else if (S =="G" && g) {
      kind++;
      g--;
    }
    else if (S =="Y" && y) {
      kind++;
      y--;
    }
  }
  
  if (kind == 3) {
    cout << "Three" <<endl;
  }
  else if (kind == 4) {
    cout << "Four" <<endl;
  }
  else {
    cout << "error" <<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <string>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
#define MAX_V 100000
#define MAX_E 500000
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
const int INF = 1e9 + 7;

#define MAX_H 10
#define MAX_W 10000

int A[MAX_V];

int main() {
	int N;
	cin >> N;
	rep(i, N) cin >> A[i];
	sort(A, A + N, greater<int>());
	
	int s = 0, t = 0;
	rep(i, N-1) {
		if (s == 0 && A[i] == A[i + 1]) {
			s = A[i];
			i++;
		}
		else if (s != 0 && A[i] == A[i + 1]) {
			t = A[i];
			break;
		}
	}
	cout << (ll)s * t << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, a;
    cin >> x >> a;

    if (x < a)
        std::cout << 0 << '\n';
    else
        std::cout << 10 << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		long C=sc.nextLong();
		if(A+B+1>=C) {
			pl(B+C);
		}
		else {
			long e=B+A+B+1;
			pl(e);
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}



Measured memory_bytes: 21332
import collections
N = int(input())
A = list(map(int,input().split()))

A_count = collections.Counter(A)

sum = 0
for i in A_count.values():
    sum += i*(i-1) // 2

for i in range(N):
    count = A_count[A[i]]
    ans = sum - count + 1
    print(ans)

Measured memory_bytes: 26780
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void C();

int main()
{
	C();
	fflush(stdout);
	return 0;
}


static void C()
{
	int N;
	get(N);

	std::vector<int> fn(N, 0);

	for (int x = 1; x < N; x++) {
		for (int y = 1; x * x + y * y < N; y++) {
			for (int z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= N; z++) {
				int a = x * x + y * y + z * z + x * y + y * z + z * x;
				fn[a - 1]++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%d\n", fn[i]);
	}
}


Measured memory_bytes: 3684
import sys
list=input()
def split(a): 
    return [char for char in a]
list=split(list)
even_count=0
odd_count=0
for i in list:
  if even_count%2==0:
      even_count+=1
      continue
  if list[even_count]=="R":
    print("No")
    sys.exit()
  even_count+=1
for i in list:
  if odd_count%2==1:
      odd_count+=1
      continue
  if list[odd_count]=="L":
    print("No")
    sys.exit()
  odd_count+=1
print("Yes")

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


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

    ll ans = 0;
    for (auto c: n) {
        ans += c - '0';
    }

    if (ans % 9 == 0)
        prt("Yes");
    else
        prt("No");

    return 0;
}


Measured memory_bytes: 3756
import java.util.*;

class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      String S = sc.next();
      char[]chars = S.toCharArray();
      int[]ints = new int[chars.length];

      for (int i=0; i < chars.length; i++) {
        ints[i] = chars[i];
        ints[i] += N;
        if (ints[i] > 90) {
          ints[i] -= 26;
        }
        chars[i] = (char)ints[i];
        System.out.print(chars[i]);
      }
    }      
}

Measured memory_bytes: 27424
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<3;i++)
		if(s[i]==s[i+1])
		{
			puts("Bad");
			return 0;
		}
	puts("Good");
	return 0;
}

Measured memory_bytes: 256
n = int(input())

ans = 10 ** 5
for i in range(n // 9 + 1):
    m = n - 9 * i
    j, k = divmod(m, 6)
    cnt = k

    tmp = 0
    while 6 ** (tmp + 1) <= j: tmp += 1
    while tmp > 0 and j:
        jj, j = divmod(j, 6 ** tmp)
        cnt += jj
        tmp -= 1
    cnt += j

    tmp = 0
    while 9 ** (tmp + 1) <= i: tmp += 1
    while tmp > 0 and i:
        ii, i = divmod(i, 9 ** tmp)
        cnt += ii
        tmp -= 1
    cnt += i

    ans = min(ans, cnt)

print(ans)


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


int main(){
    int w;
    while( cin >> w, w+1 ){
        int c = 0, t;
        if( w > 10 ){
            t = w/20?10:w-10;
            c += t * 125;
        }
        if( w > 20 ){
            t = w/30?10:w-20;
            c += t * 140; 
        }
        if( w > 30 ){
            c += (w-30)*160;
        }
        cout << 3130 - c << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<ll> a(n + 1), b(n);
    for (ll &x : a) {
        cin >> x;
    }
    for (ll &x : b) {
        cin >> x;
    }
    ll res = 0;
    for (int i = n - 1; i >= 0; i--) {
        for (int j : {1, 0}) {
            ll &left = b[i];
            ll taking = min(left, a[i + j]);
            res += taking;
            left -= taking;
            a[i + j] -= taking;
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 1792
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    double tan;

    if(x < a*a*b/2){
        tan = a*b*b/(2*x);
    }else{
        tan = b - x/(a*a);
        tan *= 2/a;
    }

    printf("%.10lf%", atan(tan) * 180 / M_PI);
    return 0;}

Measured memory_bytes: 4084
k=int(input())
num=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
keta=0
for i in range(0,k):
  for j in range(0,len(num)-1):
    if num[j]==-1:
      num[j]=1
      keta=j
      break
    elif num[j]!=9 and (num[j+1]==-1 or (num[j]-num[j+1])<1):
      num[j]+=1
      break
  for x in range(j-1,-1,-1):
    num[x]=max(0,num[x+1]-1)

for i in range(keta,-1,-1):
  print(num[i],end='')
print()

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

signed main() {
  int N; cin >> N;
  //vector<int> vec(N);
  

  int ans = 0;
  

  cout << N*(N-1)/2 << endl;

}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int counter(int bitmask){
  return __builtin_popcount(bitmask);
}

int main(){
  FAST();

  int n;
  int A[16], x[16][16], y[16][16];

  cin >> n;
  REP(i, 1, n + 1){
    cin >> A[i];
    REP(j, 1, A[i] + 1)
      cin >> x[i][j] >> y[i][j];
  }

  int ans = 0, i, j, bitmask;
  for(int bitmask = 1; bitmask < (1<<n); bitmask++){   // bitmask to generate all possible subsets. ith is set if ith person is honest
    bool ok = true;
    for(i = 1; i <= n; i++){                            // for traversing through all bits of the bitmask
      if((bitmask & (1 << (i - 1))) == 0)               // ith bit in bitmask isn't set (person isn't honest)
        continue;
      for(j = 1; j <= A[i]; j++){                       // ith bit is set (person is honest), so check for contradicitng testimonies
        if(((bitmask >> (x[i][j] - 1)) & 1) ^ y[i][j])  // (bitmask >> (x[i][j] - 1)) checks if xth person is being discussed about talk. // (...... ^ y[i][j]) checks: y = 1: homest, y = 0: unkind
          ok = false;
      }
    }
    if(ok)
      ans = max(ans, counter(bitmask));
  }

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


Measured memory_bytes: 256
N, M = map(int, raw_input().split())
X = sorted(map(int, raw_input().split()))
D = [X[i+1]-X[i] for i in range(M-1)]
indexes = reversed([D.index(x) for x in sorted(D)[-(N-1):]])
start = 0
ans = 0
for index in indexes:
  ans += X[index]-X[start]
  start = index+1
ans += X[-1]-X[start]
if N == 1:
  print X[-1]-X[0]
else:
  print ans



Measured memory_bytes: 11252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  vll v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(all(v));
  ll ans = 0;
  while (v[1] < v[2]) {
    v[0]++;
    v[1]++;
    ans++;
  }
  while (v[0] < v[1]) {
    v[0] += 2;
    ans++;
  }
  if (v[0] > v[1]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
const int N = 10000;

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

    int x;
    cin >> x;
    int a, b;
    bool is_find = false;

    for (a = 0; a <= N; a++) {
        for (b = -N; b <= N; b++) {
            const int a5 = pow(a, 5LL), b5 = pow(b, 5LL);
            if (a5 - b5 == x) {
                is_find = true;
            }
            if (is_find) break;
        }
        if (is_find) break;
    }

    cout << a << " " << b << endl;
    cerr << pow(a, 5LL) - pow(b, 5LL) << endl;
}


Measured memory_bytes: 4436
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i =a; i<n; i++) 
#define ll long long
#define MOD 1000000007
using namespace std;
  
int main() {
  int N; cin >> N;
  ll ans =0;
  rep(i,1,N) ans += (N - 1)/i;
           
  cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n;
    std::cin >> n;

    std::unordered_map<ll, ll> umap; ll sum = 0;
    for (ll i = 0; i < n; i++) {
        ll a; std::cin >> a;
        umap[a]++; sum += a;
    }

    ll q;
    std::cin >> q;

    for (ll i = 0; i < q; i++) {
        ll b, c; std::cin >> b >> c;
        sum -= (b - c) * umap[b];
        umap[c] += umap[b], umap[b] = 0;
        std::cout << sum << '\n';
    }
}


Measured memory_bytes: 6996
/*  ex3_2
    pptenshi  */

#include<stdio.h>

int main(void) {
    int n;
    int n_1;  // nの1の位

    // input
    scanf("%d", &n);

    n_1 = n % 10;

    //output
    switch (n_1) {
        case 2: case 4: case 5: case 7: case 9:
            printf("hon\n");
            break;
        case 0: case 1: case 6:  case 8:
            printf("pon\n");
            break;
        case 3:
            printf("bon\n");
            break;
    }

    return 0;
}

Measured memory_bytes: 1644
#include<stdio.h>
main(){
  int i,j,count=0,n,a;
  int A[100];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  for(i=0;i<=n-1;i++)
    {
      for(j=n-1;j>=i+1;j--)
	{
	  if(A[j]<A[j-1])
	    {
	      a=A[j];
	      A[j]=A[j-1];
	      A[j-1]=a;
	      count++;
	    }
	}
    }
  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i<n-1) printf(" ");
    }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  int s = S.size();
  int t = T.size();
  int A = 1000;
  for (int i = 0; i < s - t + 1; i++) {
    int B = 0;
    for (int j = 0; j < t; j++) {
      if (S.at(i + j) != T.at(j)) {B++;}
    }
    if (A > B) {A = B;}
  }
  cout << A << endl;
}

Measured memory_bytes: 3560
#include <stdio.h>

void init_can(int* can, int len) {
  int i;
  for(i=0;i<len;i++) can[i] = 0;
}

int main() {
  int n, p, candidate[50];

  while(1) {
    scanf("%d %d", &n, &p);
    if(n==0) break;

    init_can(candidate, n);

    int turn=0, bowl=p;
    while(!(bowl==0 && candidate[turn]==p)){
      if(bowl==0) {
	bowl = candidate[turn];
	candidate[turn] = 0;
      } else {
	candidate[turn]++;
	bowl--;
      }
      turn = (turn + 1) % n;
    }
    printf("%d\n", turn);
  }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#define ll long long
using namespace std;

vector<ll> flag(300000,-1);
int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N+2);
    for(ll i=1;i<=N;i++){
        cin>>A[i];
    }
    ll unit;
    ll now=1;
    flag[now]=0;
    for(ll i=1;i<=K;i++){
        now=A[now];
        if(flag[now]!=-1){
            unit=i-flag[now];
            break;
        }else flag[now]=i;
    }
    if(unit!=0){
        ll C=(K-flag[now])/unit;
        for(ll i=flag[now]+C*unit+1;i<=K;i++){
            now=A[now];
        }
    }
    
    cout<<now<<endl;
    return 0;
}

Measured memory_bytes: 7176
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>

using namespace std;

inline bool is_triangle(int a, int b, int c) {
  return a < b + c && b < c + a && c < a + b;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 0;

  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      int sum = v[i] + v[j];
      int lo = j + 1, hi = n - 1;
      int index = -1;
      while(lo <= hi) {
        int mid = (lo + hi) >> 1;
        if(v[mid] < sum) {
          index = mid;
          lo = mid + 1;
        }else {
          hi = mid - 1;
        }
      }
      if(index != -1) {
        int len = index - j;
        ans += len;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+10;
int n,k;
int main()
{
	cin>>n>>k;
	int ans = 0;
	for(int i=0;i<n;++i)
	{
		int x; cin >> x;
		if(abs(x)<=abs(k-x))
		{
			ans += 2*x;
		}
		else
		{
			ans += 2*abs(k-x);
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 

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();}

int main(){
    std::ios::sync_with_stdio(false);
    int x, n;
    cin >> x >> n;
    set<int> p;
    for(int i=0;i<n;++i)
    {
      int tmp;
      cin >> tmp;
      p.insert(tmp);
    }

    int min_dist = 1 << 30;
    int ret = 0;
    for(int i=0;i<=101;++i)
    {
      if(p.find(i) == p.end()){
        if(abs(x - i) < min_dist)
        {
          min_dist = abs(x - i);
          ret = i;
        }
      }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
 
 int W,H,x,y,r;
 cin >> W >> H >> x >> y >> r;
 
 if (r <= x && x <= W - r && r <= y && y <= H - r) {
  cout << "Yes" << endl;
 }
 else {
  cout << "No" << endl;
 }
}



Measured memory_bytes: 3100
#include <iostream>
#include <cmath>

using namespace std;

void calculate(double, double, double, double, double, double, double&, double&);

int main(){
  int i, num;
  double x1, y1, x2, y2, x3, y3;
  double a, b, c, d, e, f;
  double l, m, n;
  double xp, yp, r;

  cin >> num;

  for(i=0; i<num; i++){
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    a = x1 - x2;
    b = y1 - y2;
    c = x2*x2 + y2*y2 - (x1*x1 + y1*y1);
    d = x2 - x3;
    e = y2 - y3;
    f = x3*x3 + y3*y3 - (x2*x2 + y2*y2);

    calculate(a, b, c, d, e, f, l, m);
    n = -(x1*x1 + y1*y1 + l*x1 + m*y1);

    xp = -l / 2;
    yp = -m / 2;
    r = 0.5 * sqrt(l*l + m*m - 4*n);

    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(3);
    cout << xp << " " << yp << " " << r << endl;
  }

  return 0;
}

void calculate(double a, double b, double c, double d, double e, double f, double& l, double& m){
    l = (c*e - f*b)/(a*e - d*b);

    if(b != 0)
      m = (c - a*l)/b;
    else
      m = (f - d*l)/e;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
bool OOA(int x, int y, int H, int W) { return (0 <= x && x<H) && (0 <= y && y<W); }


const LL b1=1676943010,mod=2147483647;
string T,P;

void sarch(string str,string key){
	LL sh=0ll,kh=0ll,sl=str.size(),kl=key.size(),bpk=1ll;
	for(int i=0;i<kl;i++){
		sh=sh*b1+(LL)str[i];
		sh%=mod;
		kh=kh*b1+(LL)key[i];
		kh%=mod;
	}
	for(int i=0;i<P.size();i++){
		bpk*=b1;
		bpk%=mod;
	}
	for(int i=0;i+kl<=sl;i++){
		if(sh==kh)
			cout<<i<<endl;
		sh=sh*b1-bpk*(LL)str[i]+(LL)str[i+kl];
		sh%=mod;
	}
}

int main(){
	cin>>T>>P;
	if(T.size()<P.size())return 0;
	sarch(T,P);
	return 0;
}




Measured memory_bytes: 4948
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())

    import math

    res = float(0.0)

    for score in range(1, N+1):
        p = float(1.0/N)
        while K > score:
            score = score * 2
            p = p/2
        res = res + p

    print(res)

# %%
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll dp[n + 1][4] = {};
    dp[0][0] = 1;
    rep(i, 0, n) {
        rep(j, 0, 4) dp[i + 1][j] += dp[i][j];
        if (s[i] == '?') rep(j, 0, 4) dp[i + 1][j] *= 3;
        if (s[i] == 'A' || s[i] == '?') dp[i + 1][1] += dp[i][0];
        if (s[i] == 'B' || s[i] == '?') dp[i + 1][2] += dp[i][1];
        if (s[i] == 'C' || s[i] == '?') dp[i + 1][3] += dp[i][2];
        rep(j, 0, 4) dp[i + 1][j] %= MOD;
    }
    cout << dp[n][3] << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
 
const int MOD = 1000000007;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=0;i<n;i++)
        cin>>arr[i+1];
    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);

    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n];

    return 0;
} 

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

int main()
{
  int N, K;
  std::cin >> N >> K;
  int b[N] = {0};
  for ( int i = 0; i < N; i++ ) {
    int a;
    std::cin >> a;
    b[a-1]++;
  }

  int count = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( b[i] != 0 ) {
      count++;
    }
  }

  std::sort(b, b+N);
  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( K >= count ) break;
    if ( b[i] != 0 ) {
      count--;
    }
    ans += b[i];
  }

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

Measured memory_bytes: 1024