akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll par[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		par[i]=par[i-1]+x;
	}
	ll ans=LONG_LONG_MAX;
	//~ for(int i=1;i<=n;i++)
		//~ for(int j=i+1;j<=n;j++)
			//~ for(int k=j+1;k<=n;k++){
				//~ vector<ll>v;
				//~ v.pb(par[i]);v.pb(par[j]-par[i]);
				//~ v.pb(par[k]-par[j]);v.pb(par[n]-par[k]);
				//~ sort(all(v));
				//~ if(umin(ans,v[3]-v[0])){
					//~ cout<<i<<" "<<j<<" "<<k<<endl;
				//~ }
			//~ }
		//~ cout<<ans<<endl;
		//~ exit(0);	
	vector<ll>v;
	for(int i=2;i<=n-2;i++){
		int a=lower_bound(par+1,par+n+1,par[i]/2)-par;
		umin(a,i-1);
		int b=lower_bound(par+1,par+n+1,par[i]+(par[n]-par[i])/2)-par;
		umin(b,n-1);
		for(int j=max(a-1,1);j<=min(a+1,n-1);j++)
			for(int k=max(b-1,1);k<=min(b+1,n-1);k++){
				v.clear();
				v.pb(par[j]);v.pb(par[i]-par[j]);
				v.pb(par[k]-par[i]);v.pb(par[n]-par[k]);
				sort(all(v));
				umin(ans,v[3]-v[0]);
			}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))

b = [a[i] - (i+1) for i in range(n)]

b.sort()

m1 = b[n//2]
s1 = sum([abs(b[i] - m1) for i in range(n)])

if n % 2 == 1:
    m1 = b[n//2]
    s1 = sum([abs(b[i] - m1) for i in range(n)])
    print(s1)
else:
    m1 = b[n//2-1]
    m2 = b[n//2]
    if (m1 + m2) % 2 == 0:
        l1 = (m1 + m2) // 2
        s1 = sum([abs(b[i] - l1) for i in range(n)])
        print(s1)
    else:
        l1 = (m1 + m2) // 2
        l2 = l1 + 1
        s1 = sum([abs(b[i] - l1) for i in range(n)])
        s2 = sum([abs(b[i] - l2) for i in range(n)]) 

        print(min(s1, s2))

Measured memory_bytes: 33268
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
 
 
  int main(){
      lint n,q;
      string s;
      cin>>n;
       rep(i,21){
           if(i*1000>=n){
               cout<<i*1000-n;
               return 0;
           }
       }
      
     }
     
 

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	int t=1;
	//cin>>t;
	
	while(t--)
	{
		int n;
		cin>>n;
		
		int *arr=new int[n];
		for(int i=0;i<n;i++)
		{
			cin>>arr[i];
		}
		
		int* dp=new int[n];
		dp[0]=0;
		dp[1]=abs(arr[1]-arr[0]);
		
		for(int i=2;i<n;i++)
		{
			dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
		}
		
		
		cout<<dp[n-1]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 4404
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, ans;

int main()
{
	in >> N;
	std::vector<int>a(N);
	rep(i, N) in >> a[i];
	rep(i, N - 1)
	{
		if (a[i] == a[i + 1])
		{
			++ans;
			++i;
		}
	}
	out << ans << std::endl;
	return 0;
}


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

typedef long long ll;

using namespace std;

int take_digit(int n, int N, int s) {
    if (N == 3 && s == 1) {
        return n / 100;
    }
    if ((N == 3 && s == 2) || (N == 2 && s == 1)) {
        return n / 10 % 10;
    }
    if ((N == 3 && s == 3) || (N == 2 && s == 2) || (N == 1 && s == 1)) {
        return n % 10;
    }
    return -1;
}

bool is_correct(int n, int N) {
    if (n == 0 && N == 1) {
        return true;
    }
    int range = n / pow(10, N - 1);
    return 1 <= range && range < 10;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> d(M);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        d[i] = make_pair(s, c);
    }

    int ans = -1;
    for (int n = 0; n <= 999; n++) {
        bool match = true;
        for (int i = 0; i < M; i++) {
            if (take_digit(n, N, d[i].first) != d[i].second) {
                match = false;
            }
        }
        if (match && is_correct(n, N)) {
            ans = n;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
// 2015/04/20 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int C;

void bubbleSort(int A[], int N)
{
	bool flag = true;

	while(flag){
		flag = false;

		for(int j=N-1; j>=1; j--){
			if(A[j]<A[j-1]){
				swap(A[j], A[j-1]);
				C++;
				flag = true;
			}
		}
	}

	return;
}

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

	int A[100];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}

	C = 0;

	bubbleSort(A, N);

	for(int i=0; i<N; i++){
		cout << A[i];

		if(i<N-1){
			cout << ' ';
		}
		else{
			cout << endl;
		}
	}
	cout << C << endl;

	return 0;
}

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

int n, k;

int mn(int nu, int n) {
	if (n == 0) return nu;
	return min(mn(nu*2, n-1), mn(nu+k, n-1));
}

int main() {
    
    cin >> n >> k;
    cout << mn(1, n) << endl;
    
}


Measured memory_bytes: 256
def scheduling(A,n,q):
    ans = []
    time = 0
    while A != []:
        x = A.pop(0)
        if q < x[1]:
            x[1] -= q
            time += q
            A.append(x)
        elif x[1] <= q:
            time += x[1]
            x[1] = time
            ans.append(x)

    return ans



if __name__ == '__main__':
    n,q = [int(i) for i in input().split()]
    A = []
    for i in range(n):
        a = input().split()
        a[1] = int(a[1])
        A.append(a)
    ans = scheduling(A,n,q)
    for i in range(n):
        print(ans[i][0],ans[i][1])



Measured memory_bytes: 18644
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>

#define MAXN 55
#define MAXSILVER 2500

using ll = long long int;
std::vector< std::vector< std::pair<int, std::pair<int, ll> > > > g(MAXN);
//silver, transaction time for each gold
std::pair<ll, ll> trans[MAXN];
ll dist[MAXN][MAXSILVER];

struct Node
{
    ll distance;
    int y, z;

    Node(ll distance, int y, int z) {this->distance = distance; this->y=y; this->z = z;}

    bool operator<(const Node& other) const
    {
        return distance < other.distance;
    }
    bool operator>(const Node& other) const
    {
        return distance > other.distance;
    }
};

std::pair<ll, std::pair<int, int> > mp(ll x, int y, int z)
{
    return std::make_pair(x, std::make_pair(y, z));
}

void solve(int start, int silver)
{
    std::priority_queue< Node,
                        std::vector< Node >,
                            std::greater<Node> > s;
    s.push(Node(0, start, silver));
    dist[start][silver] = 0;

    while (!s.empty())
    {
        Node top = s.top();
        s.pop();
        ll curdist = top.distance;
        int v = top.y, silv = top.z;
        if (curdist > dist[v][silv]) continue;
//        if (s.size() > 100000) std::cout << s.size() << "\n";

        if (trans[v].first + silv <= MAXSILVER-2)
        {
            ll t = trans[v].second;
            int nextsilv = silv + trans[v].first;
            if (dist[v][silv] + t < dist[v][nextsilv])
            {
                dist[v][nextsilv] = dist[v][silv] + t;
                s.push(Node(curdist + t, v, nextsilv));
            }
        }

        for (std::pair< int, std::pair<int, int> > nxtpr : g[v])
        {
            int nxt = nxtpr.first;
            int silvtaken = nxtpr.second.first;
            ll timetaken = nxtpr.second.second;

            if (silv - silvtaken < 0) continue;
            int nxtsilver = silv - silvtaken;

            if (dist[v][silv] + timetaken < dist[nxt][nxtsilver])
            {
                dist[nxt][nxtsilver] = dist[v][silv] + timetaken;
                s.push(Node(curdist + timetaken, nxt, nxtsilver));
            }
        }
    }
}

int main()
{
    int n, m, s;
    std::cin >> n >> m >> s;

    s = std::min(s, MAXSILVER-3);
    int x, y, a, b;
    while (m--)
    {
        std::cin >> x >> y >> a >> b; --x; --y;
        g[x].push_back(std::make_pair(y, std::make_pair(a, b)));
        g[y].push_back(std::make_pair(x, std::make_pair(a, b)));
    }

    for (int i = 0; i < n; ++i)
        std::cin >> trans[i].first >> trans[i].second;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < MAXSILVER-2; ++j)
            dist[i][j] = 1e15;
    solve(0, s);

    for (int i = 1; i < n; ++i)
    {
        ll ans = 1e15;
        for (int j = 0; j < MAXSILVER-2; ++j)
        {
            ans = std::min(ans, dist[i][j]);
        }

        std::cout << ans << "\n";
    }
}


Measured memory_bytes: 6156
# import numpy as np
# import scipy as sp
# import sys
# input = sys.stdin.readline
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# a=[int(input()) for _ in range (n)]  #リスト入力  改行でa1 ... anのとき
# s=[list(map(str,list(input()))) for i in range(h)]  # 文字列の二次元配列入力
# s = [list(map(int, input().split())) for i in range(n)] # 数値の二次元配列入力
# a = b[:], a = [x[:] for x in b] # deepcopy
# chr(ord('a') + 1) # chrのインクリメント
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#　

n = int(input())
print(n//3)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <functional>

const int INF = 1 << 30;
using namespace std;
int solve();

int main(void) {
	
	//FILE *fpin = freopen("data.txt","r",stdin);
	
	solve();

	return 0;
}

int solve() {

	int N;
	cin >> N;

	vector<int> p(N+1,0);
	vector<int> ng(N+1,0);
	vector<int> ok(N+1,0);
	vector<int> cost(N+1,INF);
	vector<int> visited(N+1,0);
	vector<int> doneNode(N+1,0);
	vector<int> contain(N+1,0);

	for( int i = 0; i < N; i++ )
		cin >> p[i+1];

	//?????????????????????
	for( int i = 1; i < N; i++ ) {

		int pos = i;
		if( p[i] == 0 ) { continue; }
		if( ng[i] != 0 ) { continue; }
		if( ok[i] != 0 ) { continue; }

		visited.clear();
		visited.resize(N+1,0);

		while(true) {

			if( p[pos] == 0 ) {
				for( int j = 1; j < N; j++ ) {
					if( visited[j] ) 
						ok[j] = 1;
				}
				break;
			}

			if( visited[pos] != 0 || ng[pos] != 0 ) {

				for( int j = 1; j < N; j++ ) {
					if( visited[j] ) {
						ng[j] = 1;
						visited[j] = 0;
					}
				}

				break;
			}

			visited[pos] = 1;
			pos += p[pos];

		}

	}

	priority_queue<int,vector<int>,greater<int>> q;
	q.push(1);
	cost[1] = 0;

	while( !q.empty() ) {

		int cnode = q.top();
		contain[cnode] = 0;

		q.pop();
		doneNode[cnode] = 1;

		if( p[cnode] == 0 ) {

			for( int i = 1; i <= 6; i++ ) {

				int j = min(i+cnode,N);
				if( ng[j] ) { continue; }
				
				if( cost[j] == INF || cost[cnode] + 1 < cost[j] ) {
					cost[j] = cost[cnode] + 1;
					contain[j] = 1;
					q.push(j);
				}

			}

		} else {

			if( ng[cnode] == 0 ) {

				int j = min(cnode+p[cnode],N);

				if( cost[j] == INF || cost[cnode] < cost[j] ) {
					cost[j] = cost[cnode];
					contain[j] = 1;
					q.push(j);
				}


			}

		}

	}
	
	cout << cost[N] << endl;
	return 0;

}

Measured memory_bytes: 5412
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 0;
	rep(i,n){
		ll a;
		cin >> a;
		while(a%2 == 0){
			a /= 2;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


s = input()
k = inp()
n = min(len(s), k)
for i in range(n):
    if s[i] != '1':
        print(s[i])
        break
else:
    print(1)


 

Measured memory_bytes: 63980
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

vector<int>divisor(int n) {
	vector<int>value;
	FOR(i, 1, pow(n, 0.5) + 1) {
		if (n % i == 0) {
			value.push_back(i);
			if (i * i != n) {
				value.push_back(n / i);
			}
		}
	}
	return value;
}
int ans(int &gcd, vector<int>&divisor,vector<int>&a) {
	bool flag = true;
	int i = 0;
	while (flag) {
		int count = 0;
		rep(j, a.size()) {
			if (a[j] % divisor[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		if (count <= 1) {
			gcd = max(gcd, divisor[i]);
			flag = false;
		}
		else {
			i++;
		}
	}
	return gcd;
}

int main() {
	int n;
	int s=scanf("%d",& n);
	vector<int>a(n);
	rep(i, n) {
		int d=scanf("%d",&a[i]);
	}
	sort(all(a));

	int b = a[0];
	int c = a[1];
	vector<int>div_b,div_c;
	div_b = divisor(b);
	div_c = divisor(c);
	sort(all(div_b));
	reverse(all(div_b));
	sort(all(div_c));
	reverse(all(div_c));
	int gcd = 1;
	int answer = max(ans(gcd, div_c, a), 
		ans(gcd, div_b, a));
	cout << answer << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    vector <int> b(n);
    for (auto &i : a) cin >> i;
    for (auto &i : b) cin >> i;
    vector <int> ans;
    vector <int> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = i + 1;
    }
    int cnt = 0;
    do {
        if (a == p) {
            ans.pb(cnt);
        }
        if (b == p) {
            ans.pb(cnt);
        }
        ++cnt;
    } while (next_permutation(all(p)));
    cout << abs(ans[0] - ans[1]) << '\n';
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int a,b,c;
   cin>>a>>b;
   c=max(a,b);
   if(a==b)
     cout<<2*c<<endl;
   else
     cout<<2*c-1<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
vector<int> adj[MAXN];
bool visited[MAXN];
int n,m,mx=0,curr=0;

void dfs(int node){
    visited[node] = true;
    for(int next : adj[node]){
        if(!visited[next]){
            curr++;
            dfs(next);
        }
    }
}

int main(){
    cin >> n >> m;
    int a,b;
    for(int i=0; i<m; i++){
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    for(int i=0; i<n; i++){
        if(!visited[i]){
            curr = 1;
            dfs(i);
            mx = max(mx,curr);
        }
    }
    cout << mx << endl;
}


Measured memory_bytes: 20724
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;



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

	bool haveodd = false;
	rep (i, n) if (a[i] % 2) haveodd = true;
	
	cout << (haveodd ? 1LL<<n-1: p ? 0 : 1LL<<n) << endl;
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> food_scores(m, 0);
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int a;
            cin >> a;
            --a;
            ++food_scores[a];
        }
    }
    int num_liked = 0;
    for (auto food_score : food_scores) {
        if (food_score == n) {
            ++num_liked;
        }
    }
    cout << num_liked << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e933
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;cin>>n;
    vector<int> v(n);
    int sum=0;
    rep(i,0,n){
        cin>>v[i];
        sum+=v[i];
    }
    bool f=true;
    if(sum%10)cout<<sum<<endl,f=false;
    else {
        Sort(v);
        rep(i,0,n){
            if(v[i]%10){
                cout<<sum-v[i]<<endl;
                f=false;
                break;
            }
        }
    }
    if(f)cout<<0<<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[] nums = new int[n];
		int v = 0;
		int j;
		
		for(int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}

		for(int i = 0; i < n; i++) {
			v = nums[i];
			j = i - 1;

			while(j >= 0 && nums[j] > v) {
				nums[j+1] = nums[j];
				j--;
			}
			nums[j+1] = v;

			for(int index = 0; index < n; index++) {
				System.out.print(nums[index]);
				if(index < n - 1) {
					System.out.print(" ");
				}
			}
			System.out.println("");
		}
	}
}



Measured memory_bytes: 34288
from math import factorial as fa
def con(a,b):
    if a < b:
        return 0
    elif a < 0:
        return 1
    else:
        return int(fa(a)) // int(fa(b) * fa(a-b))
    
n,k = map(int,input().split())
for i in range(1,k+1):
    r_tmp = con(n-k+1,i)
    b_tmp = con(k-1,i-1)
    if r_tmp:
        print((r_tmp * b_tmp) % (10**9+7))
    else:
        print(0)

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

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

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

const int mod = 998244353;

map <string, int> f, g;
string s;

inline int F(const string &s);
inline int G(const string &s);

inline int F(const string &s) {
  if (s.length() == 1) {
    return s[0] - '0' + 1;
  }
  if (f.find(s) != f.end()) {
    return f[s];
  }
  int ret = G(s);
  for (int i = 1; i < s.length(); ++i) {
    ret = (1LL * G(s.substr(0, i)) * F(s.substr(i, s.length() - i)) + ret) % mod;
  }
  return f[s] = ret;
}

inline int G(const string &s) {
  if (s.length() == 1) {
    return s[0] - '0' + 1;
  }
  if (g.find(s) != g.end()) {
    return g[s];
  }
  int len = s.length(), ret = 0;
  for (int i = 1; i < len; ++i) {
    if (len % i == 0) {
      string nxt = s.substr(0, i);
      for (int j = 0; j < len; ++j) {
        if (s[j] == '0') {
          nxt[j % i] = '0';
        }
      }
      ret = (ret + F(nxt)) % mod;
    }
  }
  return g[s] = ret;
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  cin >> s;
  cout << F(s) << endl;
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    ll ans=0;
    ll ct=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]=='A') ct++;
        else if(s.substr(i,2)=="BC"){
            ans+=ct;
            i++;
        }
        else ct=0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

int gcd(int x, int y)
{
	if (y > x)
	{
		return gcd(y, x);
	}
	else if (y == 0)
	{
		return x;
	}
	else
	{
		return gcd(y, x % y);
	}
}

void Main()
{
	std::size_t N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
	std::vector<int> gcds(N );
	gcds[N - 1] = vec[N - 1];
	for (auto i : boost::irange<std::size_t>(1, N - 1) | adaptor::reversed)
	{
		gcds[i] = gcd(gcds[i + 1], vec[i]);
	}
	int max = gcds[1];
	int mygcd = vec[0];
	for (auto i : boost::irange<std::size_t>(0, N - 1))
	{
		mygcd = gcd(mygcd, vec[i]);
		max = std::max(max, gcd(mygcd, gcds[i + 2]));
	}
	mygcd = gcd(mygcd, vec[N - 1]);
	max = std::max(max, mygcd);
	std::cout << max << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1)+(x&1);
}


int main(){
    fast_io

    int n;
    cin>>n;

    int ans=180*(n-2);
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int H,W,N,sum = 0,s = 1;
	cin >> H >> W >> N;
    int* a = new int[H * W];
	int* b = new int[N];
	for(int i = 0;i < N;i++)
	{
		cin >> b[i];
		for(int k = 0;k < b[i];k++)
		    a[sum + k] = i + 1;
		sum = sum + b[i];	
    }
    while(s <= H)
    {
        if(s % 2 == 1)
        {
            for(int x = (s - 1) * W;x < s * W - 1;x++)
			    cout << a[x] <<" ";
		    cout << a[s * W - 1] << endl;
		    s++;
	    }
	    else if(s % 2 == 0)
	    {
		    for(int x = s * W - 1;x > (s - 1) * W;x--)
		        cout << a[x] << " ";
		    cout << a[(s - 1) * W] << endl;
		    s++;
	    }
    }
    delete []a;
    delete []b;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
mod = 10**9+7
a = list(map(int,input().split()))
m = 2**59
ans = 0
for i in range(60):
    c0 = 0
    c1 = 0
    for j in range(n):
        if a[j]//m == 1:
            c1 += 1
            a[j] -= m
        else:
            c0 += 1
    ans += (c0*c1*m)%mod
    #print(c0,c1,m,ans)
    ans %= mod
    m //= 2
print(ans)

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

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

    vector<vector<ll>> F(N, vector<ll>(10));
    vector<vector<ll>> P(N, vector<ll>(11));

    rep(i, N) rep(j, 10) cin >> F.at(i).at(j);
    rep(i, N) rep(j, 11) cin >> P.at(i).at(j);

    ll ans = -10e9;
    for (ll i = 1; i < (1 << 10); i++)
    {
        ll tmp = i;
        vector<ll> C(N, 0);

        ll cnt = 0;
        while (tmp > 0)
        {
            if (tmp % 2 == 1)
            {
                for (ll j = 0; j < N; j++)
                {
                    if (F.at(j).at(cnt) == 1)
                    {
                        C.at(j)++;
                    }
                }
            }
            tmp /= 2;
            cnt++;
        }

        ll sum = 0;
        rep(j, N)
        {
            sum += P.at(j).at(C.at(j));
        }
        ans = max(ans, sum);
    }

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

Measured memory_bytes: 3600
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <bitset>
#include <array>
#include <set>
#include <string>

#include <iterator>
#include <algorithm>
#include <numeric>

#include <ios>
#include <sstream>
#include <iostream>
#include <fstream>


#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,m,n) for(int i=m, i<n;i++)
#define each(i,n) for(auto i:n)
#define all(i) i.begin(),i.end()

#define makevv(i,j,k,l,m) vector<vector<i>> j(k,vector<i>(l,m))

using vi=std::vector<int>;
using vvi=std::vector<vi>;
using pii=std::pair<int,int>;
using ll=long long;


template <typename T>
std::string printItr(T b, T e, std::string delim=" ")
{
    std::stringstream ss;
    std::ostream_iterator<decltype(*b)> out_it(ss, delim.c_str());
    std::copy(b,e - 1, out_it);
    ss<<*(e-1);
    return ss.str();
}
using namespace std;

int main(void){
    int h,w;
    cin>>h>>w;
    vvi m(h+2,vi(w+2,0));
    vvi a(h+2,vi(w+2,0));
    rep(i,h)rep(j,w){
        char c;
        cin>>c;
        if(c=='#')m[i+1][j+1]=1;
    }
    vi v={1,0,-1,0,1,1,-1,-1,1};
    rep(i,h){
        rep(j,w){
            rep(k,8){
                a[i+1][j+1]+=m[i+1+v[k]][j+1+v[k+1]];
            }
            if(m[i+1][j+1]==1){
                cout<<"#";
            }else cout<<a[i+1][j+1];

        }
        cout<<endl;
    }
    
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vl v(n);
	REP(i, n)cin >> v[i];
	vvl dp(n, vl(2, -INF * INF));
	dp[0][0] = 0;
	REP(i, n - 1) {
		chmax(dp[i + 1][0], dp[i][0] + v[i]);
		chmax(dp[i + 1][0], dp[i][1] - v[i]);
		chmax(dp[i + 1][1], dp[i][0] - v[i]);
		chmax(dp[i + 1][1], dp[i][1] + v[i]);
	}
	cout << max(dp[n - 1][0] + v[n - 1], dp[n - 1][1] - v[n - 1]) << endl;
}

Measured memory_bytes: 6528
import bisect

def dfs(graph, root, A, res, lis):
    stack = [(root,)]
    while stack:
        # print(stack)
        state = stack[-1]
        del stack[-1]
        u = state[0]
        if res[u] == -1:
            a = A[u]
            p = bisect.bisect_left(lis, a)
            if p == len(lis):
                stack.append((u, -1))
                lis.append(a)
            else:
                stack.append((u, p, lis[p]))
                lis[p] = a
            res[u] = len(lis)
            for v in graph[u]:
                if res[v] == -1:
                    stack.append((v,))
        else:
            p = state[1]
            if p >= 0:
                lis[p] = state[2]
            else:
                del lis[-1]

n = int(input())
A = [int(x) for x in input().split()]
graph = [[] for i in range(n)]
for i in range(n - 1):
    u, v = [int(x) - 1 for x in input().split()]
    graph[u].append(v)
    graph[v].append(u)
res = [-1] * n
dfs(graph, 0, A, res, [])
print(*res, sep='\n')

Measured memory_bytes: 73856
#include<cstdio>

int a[100001],ans,n;
int dispo=1;
bool c[100001];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",a+i);
    }
    for(int i=1;i<=n;i++){
        if(dispo==2){
            printf("%d",ans);
            return 0;
        }else if(c[dispo]&1){
            printf("-1");
            return 0;
        }
        ++c[dispo];
        dispo=a[dispo];
        ++ans;
    }
}


Measured memory_bytes: 640
X, Y, A, B, C=map(int,input().split())
rp=list(map(int,input().split()))
bp=list(map(int,input().split()))
np=list(map(int,input().split()))
rp.sort()
bp.sort()
np.sort()
count=X+Y
red=len(rp)-1
blue=len(bp)-1
non=len(np)-1
lb = blue-Y
lr = red -X
N=0
ans =0

for k in range(count):
    if non > -1:
        nn= np[non]
    else:
        nn =0
    if blue > lb:
        bb= bp[blue]
    else:
        bb =0
    if red > lr:
        rr= rp[red]
    else:
        rr =0
    
    if red == lr:
        if bb >= nn or non ==-1:
            ans+=bb
            blue-=1        
        else:
            ans += nn
            non-=1

    elif blue == lb:
        if rr >= nn or non ==-1:
            ans+=rr
            red-=1        
        else:
            ans += nn
            non-=1
       
    elif non > -1:
        if nn >= rr and nn >= bb:
            ans+=nn
            non-=1
        else:
            if red > lr:
                if blue> lb:
                    if rr >= bb:
                        ans += rr
                        red-=1
                    else:
                        ans+=bb
                        blue-=1
                else:
                    ans += rr
                    red-=1

            else:
                ans += bb
                blue-=1
    elif rr >= bb:
        ans += rr
        red-=1
    else:
        ans+=bb
        blue-=1
            
print(ans)

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

string str;

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> str;
}

bool invalid()
{
    if(str.back() == '1') return true;
    if(str[0] != '1') return true;
    for(size_t i = 0; i < str.size()-1; i++)
    {
        if(str[i] != str[str.size()-2-i]) return true;
    }
    return false;
}

void process()
{
    if(invalid()) cout << -1 << endl;
    else
    {
        int cnt1 = 0;
        for(auto c:str) cnt1 += (c=='1'? 1 : 0);
        // middle
        // 1 2 ... (cnt1)+1, cnt1 edges
        for(int i = 0; i < cnt1; i++)
        {
            cout << i+1 << " " << i+2 << endl;
        }
        for(size_t i = 1, j = 2, k = cnt1+2, skip = 0; i < str.size(); i++)
        {
            if(str[i] == '1')
            {
                for(size_t c = 0; c < skip; c++) cout << j << " " << k++ << endl;
                j++;
                skip = 0;
            }
            else skip++;
        }
    }
}



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

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

  ll N, M, Q; cin >> N >> M >> Q;
  vector<vector<ll>> cells(N, vector<ll>(M, 0));
  for (ll i = 0; i < N; i++) {
    string S; cin >> S;
    for (ll j = 0; j < M; j++) {
      cells[i][j] = S[j] - '0';
    }
  }

  vector<vector<ll>> B(N + 1, vector<ll>(M + 1, 0));
  vector<vector<ll>> D(N + 1, vector<ll>(M + 1, 0));
  vector<vector<ll>> R(N + 1, vector<ll>(M + 1, 0));
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < M; j++) {
      B[i + 1][j + 1] = B[i + 1][j] + B[i][j + 1] - B[i][j];
      D[i + 1][j + 1] = D[i + 1][j] + D[i][j + 1] - D[i][j];
      R[i + 1][j + 1] = R[i + 1][j] + R[i][j + 1] - R[i][j];

      B[i + 1][j + 1] += cells[i][j];
      if (i > 0 && cells[i][j] == 1 && cells[i - 1][j]) D[i + 1][j + 1]++;
      if (j > 0 && cells[i][j] == 1 && cells[i][j - 1]) R[i + 1][j + 1]++;
    }
  }

  for (ll i = 0; i < Q; i++) {
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--;
    ll b = B[x2][y2] - B[x1][y2] - B[x2][y1] + B[x1][y1];
    x1++;
    ll d = D[x2][y2] - D[x1][y2] - D[x2][y1] + D[x1][y1];
    x1--; y1++;
    ll r = R[x2][y2] - R[x1][y2] - R[x2][y1] + R[x1][y1];
    cout << (b - d - r) << '\n';
    // cout << b << ' ' << d << ' ' << r << '\n';
  }
  return 0;
}

Measured memory_bytes: 127232
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String in = scanner.next();

        int result = 0;
        for (int i = 0; i < in.length(); i++) {
            if (in.charAt(i) == '1') {
                result++;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 23764
fun main(args: Array<String>) {
    keyence2019c()
}

fun keyence2019c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }
    val bList = readLine()!!.split(" ").map { it.toLong() }

    if (aList.sum() < bList.sum()) return println(-1)

    val diffs = aList.withIndex().map { it.value - bList[it.index] }.sortedDescending()
    val negativeDiffs = diffs.filter { it < 0 }

    var negativeDiffSum = negativeDiffs.sum()
    var needChangePositives = 0
    while (negativeDiffSum < 0) {
        negativeDiffSum += diffs[needChangePositives++]
    }

    val answer = negativeDiffs.size + needChangePositives

    println(answer)
}


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

using namespace std;

/**/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/**/

#define LL long long
const int MAXN = 100;
const int INF  = 0x3f3f3f3f;

int mark[MAXN], used[MAXN], a[MAXN], b[MAXN], c[MAXN];

int main () {

	ios_base::sync_with_stdio(false);  cin.tie(NULL); 

	int n; cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) cin >> b[i];
	for (int i = 1; i < n; ++i)  cin >> c[i];

	int s = 0; a[0] = INF;

	for (int i = 1; i <= n; ++i) {
		int x = a[i];
		int y = b[a[i]];
		
		if (used[x]) continue;
		used[x] = 1;

		s += y;
		if (a[i-1] + 1 == a[i]) s += c[x-1];
		// mark[x] = 1;
	}

	cout << s << '\n';


	return 0;
}



Measured memory_bytes: 256
m = int(input())
for _ in range(m):
    s = int(input())
    y = int(input())
    n = int(input())
    a = 0
    for _d in range(n):
        t, p, b = map(float, input().split())
        tem = 0
        ts = s
        if t:
            for _y in range(y):
                ts += int(ts * p)
                ts -= b
            a = max(a, ts)
        else:
            tp = 0
            for _y in range(y):
                tp += int(ts * p)
                ts -= b
            a = max(a, ts + tp)
    print(int(a))


Measured memory_bytes: 5632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <climits>
#include <string>
#include <vector>

using namespace std;

int main () {
    int n = 0;
    cin >> n;
    vector<int> num(n);
    for (int i=0; i<n; i++) {
        cin >> num.at(i);
    }
    sort(num.begin(), num.end());
    vector<vector<long long>> ope(n-1, vector<long long>(2));
    int plus = lower_bound(num.begin(), num.end(), 0) - num.begin();
    long long ans = num.at(0);
    int check = 0;
    if (plus > n-1) plus = n-1;
    if (plus == 0) plus++;
    for (int i=plus; i<n-1; i++) {
        ope.at(check).at(0) = ans;
        ope.at(check).at(1) = num.at(i);
        check++;
        ans -= num.at(i);
    }
    ope.at(check).at(0) = num.at(n-1);
    ope.at(check).at(1) = ans;
    check++;
    ans = num.at(n-1) - ans;
    for (int i=1; i<plus; i++) {
        ope.at(check).at(0) = ans;
        ope.at(check).at(1) = num.at(i);
        check++;
        ans -= num.at(i);
    }
    cout << ans << endl;
    for (vector<long long> a : ope) {
        cout << a.at(0) << " " << a.at(1) << endl;
    }
    return 0;
}


Measured memory_bytes: 7808
object Main extends App {
	val k = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	
	val N = k(0)
	val M = k(1)

	def pow(x: Int): Int = {
		x match {
			case 0 => 1
			case _ => 2*pow(x-1)
		}
	}

	println((1900*M + 100*(N-M))*pow(M));

}


Measured memory_bytes: 25512
#include<bits/stdc++.h>
using namespace std;
int main(){
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    double ans=w*h/2.0;
    cout<<ans<<" ";
    if(w/2.0==x&&h/2.0==y)cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int a, b;
    cin >> a >> b;
    for(int i = 0;i <= 1000;i++){
        if(i*8/100 == a && i*10/100 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void dfs(ll n, ll m, ll i, vector<ll> &v){
  if(i == n){
  }else{
    for(int k = 1; k <= m; k++){
      v.push_back(k);
      dfs(n, m, i+1, v);
      v.pop_back();
    }
  
  }
}

void solution(){
  ll n;
  cin >> n;
  ll o = n%10;
  if(o == 2 || o == 4 || o == 5 || o == 7 || o == 9){
    cout << "hon" << endl;
  }else if(o == 0 || o == 1 || o == 6 || o == 8){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
}     



Measured memory_bytes: 3156
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
int main(){
	int N;
	std::cin >> N;
	vector<int> vec;
	for(int a = 0;a < N;a++){
		int b;cin >> b;
		vec.push_back(b);
	}
	int ins  = 0;
	bool flag1 = true;
	bool flag2 = true;
	for(int a = 0;a < N-1;a++){
		ins-=10;
		ins = max(ins,vec.at(a));
		if(ins < 10)flag1 = false;
	}
	ins = 0;
	for(int a = N-1;a >= 1;a--){
		ins -=10;
		ins = max(ins,vec.at(a));
		if(ins < 10)flag2 = false;
	}
	cout<<(flag1&&flag2?"yes":"no")<<endl;
}



Measured memory_bytes: 4948
import sys
input = sys.stdin.readline

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

    F.sort(reverse=True)
    A.sort()
    l = -1
    r = 0
    for i in range(N):
        if A[i]*F[i] > r:
            r = A[i]*F[i]
    r += 1
    while r-l > 1:
        m = (r+l)//2
        q = []
        cost = 0
        for i in range(N):
            if F[i]*A[i] > m:
                cost += (F[i]*A[i]-m)//F[i]
                if (F[i]*A[i]-m)%F[i] != 0:
                    cost += 1
        if cost <= K:
            r = m
        else:
            l = m

    print(r)


if __name__ == "__main__":
    main()

Measured memory_bytes: 106956
import bisect
a,b,q = map(int,input().split())
s = [-10**11]+[int(input()) for _ in range(a)]+[10**11]
t = [-10**11]+[int(input()) for _ in range(b)]+[10**11]
for i in range(q):
  ans = 10**11
  x = int(input())
  l = bisect.bisect(s,x)
  m = bisect.bisect(t,x)
  arr = [[s[l-1],s[l]],[t[m-1],t[m]]]
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      t0 = now-arr[j][i >> j & 1]
      S += t0*((-1)**(t0<0))
      now -= t0
    if ans > S:
      ans = S
  for i in range(4):
    S = 0
    now = x
    for j in range(2):
      t0 = now-arr[1-j][i >> j & 1]
      S += t0*((-1)**(t0<0))
      now -= t0
    if ans > S:
      ans = S
  print(ans)

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

using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b, tt, ans;
  cin >> n >> a >> b;
  tt = n/(a+b);
  ans = tt*a;
  n %= (a + b);
  if(n < a) {
    ans += n;
  } else {
    ans += a;
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 3664