akhauriyash/Code-Regression huggingface dataset:
use std::io::*;

fn main() {
  let mut buf = String::new();
  stdin().read_line(&mut buf).unwrap();

  let swapped = buf.chars().map(|c| match c {
    'A'...'Z' => (c as u8 + 0x20).into(),
    'a'...'z' => (c as u8 - 0x20).into(),
    c => c
  }).collect::<String>();

  print!("{}", swapped);
}



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

int main()
{
    int h, m, s;
    while(1){
        cin >> h >> m >> s;
        if(h == -1 && m == -1 && s == -1) break;
        int t = 2 * 3600 - (h * 3600 + m * 60 + s);
        int u = t * 3;
        printf("%02d:%02d:%02d\n", t / 3600, t % 3600 / 60, t % 3600 % 60);
        printf("%02d:%02d:%02d\n", u / 3600, u % 3600 / 60, u % 3600 % 60);
    }
}

Measured memory_bytes: 1156
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
string s; cin >> s;
int i = 0;
int j = s.size()-1;
while(s[i]!= 'A') i++;
while(s[j]!= 'Z') j--;
cout << j - i + 1 << endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String[] names = new String[n];
    int[] seconds = new int[n];
    StringTokenizer st;
    
    for(int i = 0; i < n; i++){
      st = new StringTokenizer(sc.nextLine());
      
      names[i] = st.nextToken();
      seconds[i] = Integer.parseInt(st.nextToken());
    }
    
    String slept = sc.nextLine();
    boolean awake = true;
    int ans = 0;
    
    for(int i = 0; i < n; i++){
      if(awake){
        if(slept.equals(names[i])){
          awake = false;
        }
      }else{
        ans += seconds[i];
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 35800
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define SIZEOF(x) sizeof(x)/sizeof(x[0])
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


template <class T>
T max(T *a , LL n){
    T maxi = a[0];
    for(LL i = 0; i < n; ++i){
        if(a[i] > maxi)maxi = a[i];
    }
    return maxi;
}
template <class T>
T min(T *a , LL n){
    T mini = a[0];
    for(LL i = 0; i < n; ++i){
        if(a[i] < mini)mini = a[i];
    }
    return mini;
}
template <class T>
T sum(T *a , LL n){
    T s=0;
    for(LL i = 0; i < n; ++i){
       s+=a[i]; 
    }
    return s;
}

#define MAX(x) max(x,SIZEOF(x))
#define MIN(x) min(x,SIZEOF(x))
#define SUM(x) sum(x,SIZEOF(x))





int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    cout<<SUM(a) - MAX(a); 




    return 0;

}


Measured memory_bytes: 504
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	string s;
	cin >> s;
	if (s[0]==s[2])
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
bool solve(vector<int>in){
  rep(k,9){
    int co=0;
    while(in[k]){
      co++;
      if(in[k]>=3)in[k]-=3;
      else if(k<7&&in[k]&&in[k+1]&&in[k+2]){
	in[k]--;in[k+1]--;in[k+2]--;
      }
      if(co==6)break;
    }
  }
  bool h=true;
  rep(k,9)if(in[k])h=false;
  return h;
}
int main(){
  string s;
  while(cin>>s){
    vector<int>in(9);
    vector<int>out;
    rep(i,s.size())in[s[i]-'1']++;
    rep(i,9){
      if(in[i]==4)continue;
      in[i]++;
      rep(j,9){
	if(in[j]<2)continue;
	in[j]-=2;bool hh=false;
	if(solve(in)){hh=true;out.pb(i+1);}
	in[j]+=2;
	if(hh)break;
      }
      in[i]--;
    }
    if(out.size()){
      rep(i,out.size()-1)cout<<out[i]<<" ";
      cout<<out[out.size()-1]<<endl;
    }else cout<<0<<endl;
  }
}

Measured memory_bytes: 1200
XKD = list(map(int,input().split()))
X = XKD[0]
K = XKD[1]
D = XKD[2]
X_list=[]

if abs(X)>K*D:
    print(abs(X)-K*D)
elif abs(X)//D%2 == K%2:
    print(abs(X)%D)
else:
    print(abs(abs(X)%D-D))

Measured memory_bytes: 9144
import numpy as np

xx, yy = map(int, input().split())

B = [(0, 0), (1, 0), (0, 1), (1, 1)]

ans = float("inf")
for i, j in B:
    x, y = xx, yy
    # print(f"i, j, {i}{j}")
    if i:
        x *= -1
    if j:
        y *= -1
    if y >= x:
        ans = min(ans, y-x + i + j)
    # print(ans)

print(ans)

Measured memory_bytes: 14440
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        String ans = (B-A)%2==1?"Borys":"Alice";
        System.out.println(ans);
    }
}


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

using namespace std;
int dp[100001];
int solve(int h[],int n,int k)
{
    if(dp[n]!=INT_MAX)return dp[n];
   if(n==0)return 0;
   if(n==1)return dp[n]=abs(h[1]-h[0]);

   for(int i=1;i<=k;i++)
   {
        if(n-i>=0)
       dp[n]=min(solve(h,n-i,k)+abs(h[n]-h[n-i]),dp[n]);
   }

   return dp[n];


}



int main()
{
    int n,k;
    cin>>n>>k;
    int h[n];

    for(int i=0;i<n;i++)
        dp[i]=INT_MAX;
    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        cin>>h[i];

    }
    cout<<solve(h,n-1,k)<<endl;
    //for(int i=0;i<=n;i++)
       // cout<<dp[i]<<" ";
}


Measured memory_bytes: 12112
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    n += 2;
    s = "a" + s + "a";
    vector<char> t(q), d(q);
    for (int i = 0; i < q; ++i) {
        cin >> t[i] >> d[i];
    }
    auto checkl = [&](ll mid) {
        for (int i = 0; i < q; ++i) {
            if (s[mid] == t[i]) {
                if (d[i] == 'L')
                    mid--;
                else
                    mid++;
            }
        }
        return mid == 0;
    };
    ll ok = 0;
    ll ng = n - 1;
    while (abs(ok - ng) != 1) {
        ll mid = (ng + ok) / 2;
        if (checkl(mid))
            ok = mid;
        else
            ng = mid;
    }
    auto checkr = [&](ll mid) {
        for (int i = 0; i < q; ++i) {
            if (s[mid] == t[i]) {
                if (d[i] == 'L')
                    mid--;
                else
                    mid++;
            }
        }
        return mid == n - 1;
    };
    ll okr = n - 1;
    ll ngr = 0;
    while (abs(okr - ngr) != 1) {
        ll mid = (ngr + okr) / 2;
        if (checkr(mid))
            okr = mid;
        else
            ngr = mid;
    }

    cout << okr - ok - 1 << "\n";
    return 0;
}

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

int main(void)
{
    int N;
    cin >> N;
    vector<int> P(N), Q(N);

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

    vector<int> from, to;
    if(P < Q){
        from = P;
        to = Q;
    } else {
        from = Q;
        to = P;
    }

    int ans = 0;
    while(true){

        if(from == to) {
            break;
        }
        next_permutation(from.begin(), from.end());
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int per(vector<int> a, vector<int> b)
{
    int cnt = 0;
    do {
        if (a == b) return cnt;
        else ++cnt;
    } while (next_permutation(a.begin(), a.end()));

    return cnt;
}

int main()
{
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) v[i] = i + 1;
    vector<int> p(n), q(n);

    for (int i = 0; i < n; ++i) cin >> p[i];
    for (int i = 0; i < n; ++i) cin >> q[i];

    int a1 = per(v, p);
    int a2 = per(v, q);

    cout << abs(a1 - a2) << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a)
    cin >> i;
  cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
    int n, x;
    while (cin >> n >> x, n + x)
    {
        int ans = 0;
 
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                for (int k = j + 1; k <= n; k++)
                {
                    if (i + j + k == x) ans++;
                }
            }
        }
 
        cout << ans << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
typedef pair<int ,int > pii;
typedef pair<int ,pii > pipii;

void solve();

int N,M,H,K;
int S[1010];
int now[1010];

int main()
{
    while(scanf("%d%d%d%d",&N,&M,&H,&K),N + M + H + K)
    {
        for(int i = 1; i < N + 1; i++)
        {
            scanf("%d",&S[i]);
        }
        solve();
    }
    return 0;
}

void solve()
{
    int ans = 0,mem = 0;
    vector<pii> l;
    for(int i = 0; i < M; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        l.push_back(make_pair(b,a));
    }
    sort(l.begin(),l.end());
    for(int i = 1; i < N + 1; i++)
    {
        now[i] = i;
    }
    for(int i = M - 1; i >= 0; i--)
    {
        int memo = S[l[i].second];
        S[l[i].second] = S[l[i].second + 1];
        S[l[i].second + 1] = memo;
    }
    for(int i = 1; i < K + 1; i++)
    {
        ans += S[i];
    }
    for(int i = 0; i < M; i++)
    {
        int Ma = max(now[l[i].second],now[l[i].second + 1]),
            Mi = min(now[l[i].second],now[l[i].second + 1]);
        if(Mi <= K && K < Ma)
        {
            mem = max(mem,S[Mi] - S[Ma]);
        }
        int memo = now[l[i].second];
        now[l[i].second] = now[l[i].second + 1];
        now[l[i].second + 1] = memo;
    }
    printf("%d\n",ans - mem);
    return;
}

Measured memory_bytes: 3960
#include <stdio.h>

int main(void) {
	int a,b;
	char op;
	while(scanf("%d%*c%c%*c%d%*c", &a, &op, &b)){
		if(op == '?') break;
		switch(op){
			case '+':
			printf("%d\n", a+b);
			break;
			case '-':
			printf("%d\n", a-b);
			break;
			case '*':
			printf("%d\n", a*b);
			break;
			case '/':
			printf("%d\n", a/b);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<int, int> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

struct SegTree{
	int size;
	vector<llint> seg, delay;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
		delay.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++){
			seg[i] = -inf;
			delay[i] = 0;
		}
	}
	
	void eval(int l, int r, int k)
	{
		if(delay[k]){
			seg[k] += delay[k];
			if(l < r){
				delay[k*2] += delay[k];
				delay[k*2+1] += delay[k];
			}
			delay[k] = 0;
		}
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}
	
	void add(int a, int b, int k, int l, int r, llint val)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			delay[k] += val;
			eval(l, r, k);
			return;
		}
		add(a, b, k*2, l, (l+r)/2, val);
		add(a, b, k*2+1, (l+r)/2+1, r, val);
		seg[k] = max(seg[k*2], seg[k*2+1]);
	}
	void add(int a, int b, llint val){
		if(a > b) return;
		add(a, b, 1, 0, (1<<size)-1, val);
	}

	llint query(int a, int b, int k, int l, int r)
	{
		eval(l, r, k);
		
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, m;
llint l[200005], r[200005], a[200005];
vector<P> vec[200005];
llint dp[200005];
SegTree seg(18);
BIT bit(200005);


int main(void)
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> a[i];
	
	for(int i = 1; i <= m; i++){
		vec[l[i]].push_back(make_pair(i, 0));
		vec[r[i]+1].push_back(make_pair(i, 1));
	}
	
	bit.init();
	seg.init(); seg.add(0, n, inf);
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < vec[i].size(); j++){
			int id = vec[i][j].first;
			if(vec[i][j].second == 0){
				bit.add(l[id], a[id]);
				seg.add(l[id], n, -a[id]);
			}
			else{
				bit.add(l[id], -a[id]);
				seg.add(l[id], n, a[id]);
			}
		}
		dp[i] = seg.query(0, i-1) + bit.query(i);
		seg.add(i, i, dp[i]);
	}
	
	llint ans = 0;
	for(int i = 0; i <= n; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	
	return 0;
	
}

Measured memory_bytes: 27904
#include<stdio.h>

int main(){

	int a=0,b=0;

	for (int i = 0; i < 4; i++){
		scanf("%d%d", &a,&b);
		switch (a){
		case 1:
			printf("%d\n", b * 6000);
			break;
		case 2:
			printf("%d\n", b * 4000);
			break;
		case 3:
			printf("%d\n", b * 3000);
			break;
		default:
			printf("%d\n", b * 2000);
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1028
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, c, p, a, n, q, k, i, l, m, u, f, j, x, y, b, z, d;
 cin>>k;
 for(i=0;i<k;i++)
 cout<<"ACL";
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
 
int main() {
	
string w;
cin>>w;
map<char,int> a;
fx(w.size()){
	a[w.at(x)]++;
}

bool check=true;
fx(w.size()){
	if(a[w.at(x)]%2!=0){
		check=false;
		break;
	}
}

if(check){
	ce("Yes")
}else{
	ce("No")
}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    rep(i,0,a.size())
    {
        cin>>a[i];
    }
    vector<int> psum(n+1,0);
    psum[n] = a[n];
    repr(i,n-1,0)
    {
        psum[i] = (psum[i+1]) + a[i];
    }
    int ans = 0;
    bool ok = true;
    int prev = 1;
    // rep(i,0,psum.size())
    // {
    //     out1(psum[i]);
    // }
    rep(i,0,a.size())
    {
        int x = prev - a[i];
        if ( x < 0 )
        {
            ok = false;
            break;
        }
        ans += (min(prev,psum[i]));
        prev = (min(2*x,psum[i]));
    }
    // cout<<ans<<endl;
    if(!ok)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }
    
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 4784
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
ans=0
for i in range (q):
    a=0
    b=n-1
    while True:
        c=(a+b)//2
        if c==b or c==a:
            break
        if S[c]>T[i]:
            b=c
        elif S[c]<T[i]:
            a=c
        else:
            break
    if S[a]==T[i] or S[c]==T[i] or S[b]==T[i]:
        ans+=1
print(ans)
        


Measured memory_bytes: 16712
import collections, math, bisect
from fractions import Fraction

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()


N, K = ints()

oneprob = Fraction(1, N)
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=Fraction(1,2)**doubling_amounts

ans*=oneprob

if N>=K:
    ans+=Fraction(N-K+1, N)

print("{:.20f}".format(float(ans)))

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")





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

int main() {
  
  char c;
  cin >> c;
  
  if(c=='a') cout << 'b';
  if(c=='b') cout << 'c';
  if(c=='c') cout << 'd';
  if(c=='d') cout << 'e';
  if(c=='e') cout << 'f';
  if(c=='f') cout << 'g';
  if(c=='g') cout << 'h';
  if(c=='h') cout << 'i';
  if(c=='i') cout << 'j';
  if(c=='j') cout << 'k';
  if(c=='k') cout << 'l';
  if(c=='l') cout << 'm';
  if(c=='m') cout << 'n';
  if(c=='n') cout << 'o';
  if(c=='o') cout << 'p';
  if(c=='p') cout << 'q';
  if(c=='q') cout << 'r';
  if(c=='r') cout << 's';
  if(c=='s') cout << 't';
  if(c=='t') cout << 'u';
  if(c=='u') cout << 'v';
  if(c=='v') cout << 'w';
  if(c=='w') cout << 'x';
  if(c=='x') cout << 'y';
  if(c=='y') cout << 'z';
  
}


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

int main(void){
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  string ans = "";
  for(int i = 0;i < N;i++){
    if(i != K-1)ans += S[i];
    else ans += (S[i] + 32);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,cnt_red=0,cnt_blue=0;
    cin>>a;
    char k;
    for(int i=0;i<a;i++){
        cin>>k;
        if(k=='R'){
            cnt_red++;
        }else{
            cnt_blue++;
        }
    }
    
    if(cnt_red>cnt_blue){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int T,i,weight[10000],sum,sum1,d,j,diff[10000];
    scanf("%lld",&T);
    sum=0;
    for(i=0;i<T;i++)
    {
        scanf("%lld",&weight[i]);
        sum+=weight[i];
    }
    for(i=0;i<T-1;i++)
    {
        sum1=0;
        for(j=i;j>=0;j--)
        {
            sum1+=weight[j];
        }
        d=abs(sum-sum1);
        diff[i]=abs(d-sum1);
    }
    sort(diff,diff+T-1);
    printf("%lld\n",diff[0]);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
    int cost[100000] = {0};
    int plat[100000] = {0};
    int n = 0;

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

    cost[0] = 0;
    cost[1] = abs(plat[0] - plat[1]);
    cost[2] = abs(plat[0] - plat[2]);
    for (int j = 3; j < n; ++j) {
        cost[j] = min((cost[j-1] + abs(plat[j-1] - plat[j])),(cost[j-2] + abs(plat[j-2]-plat[j])));
    }

    cout << cost[n-1];
    return 0;
}

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

a.sort(reverse=True)

ans=0
index=0
for i in range(len(a)-1):
    if i == 0:
        ans+=a[i]
    else:
        if i%2!=0:
            index+=1
        ans+=a[index]
print(ans)

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

vector<LL> a;
vector<list<int>> e;

struct res{
  LL num;
  int child;
  bool ok;
};

struct res dfs(int n,int parent){
  LL total=0;
  int count=0;
  struct res ans;
  bool ok=true;
  // cout << n << endl;
  list<LL> l;
  for(auto itr=e[n].begin();itr!=e[n].end();itr++){
    if((*itr)!=parent){
      ans=dfs((*itr),n);
      l.push_back(ans.num);
      total+=ans.num;
      ok=ok&&ans.ok;
      count++;
    }
  }
  if(count==0){
    return {a[n],0,true};
  }else if(count==1){
    return {a[n],1,ok&&(total==a[n])};
  }else{
    // cout << total-a[n] << endl;
    int t=0;
    for(auto itr=l.begin();itr!=l.end();itr++){
      t+=max(0,(*itr)-(total-a[n]));
    }
    // cout << t << endl;
    if(t>2*a[n]-total) ok=false;
    return {2*a[n]-total,2,ok&&(2*a[n]-total>=0&&total-a[n]>=0)};
  }
}

int main(){
  int n;
  cin >> n;
  a=vector<LL>(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  e=vector<list<int>>(n,list<int>());
  int u,v;
  for(int i=0;i<n-1;i++){
    cin >> u >> v;
    u--,v--;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  struct res ans=dfs(0,-1);
  if(ans.ok&&(ans.child!=2||ans.num==0)){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 18176
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  bool han=false;
  while(cin>>s){
    if(s[s.size()-1]=='.'||s[s.size()-1]==',')s=s.substr(0,s.size()-1);
    if(s.size()>2&&s.size()<7){
      if(han==true)cout<<" ";
      han=true;
      cout<<s;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 1180
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    MOD = 998244353
    N, S = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    dp = [[0] * 3010 for _ in range(3010)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(S + 1):
            dp[i + 1][j] += 2 * dp[i][j]
            dp[i + 1][j] %= MOD
            if j + A[i] <= S:
                dp[i + 1][j + A[i]] += dp[i][j]
                dp[i + 1][j + A[i]] %= MOD
    print(dp[N][S])


if __name__ == '__main__':
    solve()


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

  int N;
  cin >> N;

  int A[N][N];

  rep0(i, N) {
    rep0(j, N - 1) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }

  ll total = N * (N - 1) / 2;
  ll count = total;
  ll countBefore = total;
  ll ans = 0;

  vector<int> pos(N, 0);

  while(1) {
    vector<int> check(N, 0);

    rep0(j, N) {
      ll a1 = -1, a2 = -1;
      if (check[j]) continue;
      if (pos[j] >= N - 1) continue;
      a1 = A[j][pos[j]];

      if (check[a1]) continue;
      if (pos[a1] >= N - 1) continue;
      a2 = A[a1][pos[a1]];

      if (j == a2) {
        // cout << SP << a1 << SP << a2 << BR;
        pos[a1]++;
        pos[a2]++;
        check[a1] = 1;
        check[a2] = 1;
        count--;
      }
    }
        // cout << count << BR;
    if (countBefore == count) break;
    countBefore = count;
    ans++;
  }

  if (count != 0) ans = -1;

  cout << ans;
  return 0;
}

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

#define  mp(a,b)      make_pair(a,b)
#define  pb(a)        push_back(a)
#define  SIZE5        100001               /// 1e5+1
#define  SIZE6        1000001              /// 1e6+1
#define  SIZE7        10000001             /// 1e7+1
#define  MOD          1000000007           /// 1e9+7


using namespace std;

typedef long long int ll;


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

    ll X;
    cin >> X;

    map<ll,ll> ss;
    for(ll i=0; i<120; i++)
    {
        ll a = i*i*i*i*i;
        ll b = (-1ll)*a;
        ss[a] = i;
        ss[b] = (-1ll)*i;
    }

    for(ll i=0; i<120; i++)
    {
        ll a = i*i*i*i*i;
        if(ss.find(a-X) != ss.end())
        {
            cout << i << " " << ss[a-X];
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
//解説AC
int main() {
  int n;
  long long k;
  cin >>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  long long kotae=0;
  long long count=0;
  long long count2=0;
  //1セットのなかにある転倒数　入力例3だと43個
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a[i] >a[j]){
        //cout<<a[i]<<" "<<a[j]<<endl;
        count++;
      }
    }
  }
  //他のセットと組み合わせてできる転倒数　入力例3だと45個
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(a[i] >a[j]){
        //cout<<a[i]<<" "<<a[j]<<endl;
        count2++;
      }
    }
  }
  //cout<<count<<" "<<count2<<endl;
  kotae+=count*k%MOD;//kセット分
  kotae%=MOD;
  kotae+=(k-1)*k/2%MOD*count2%MOD;//kセットから2つを選んだとき
  kotae%=MOD;  
  cout<<kotae<<endl;
  return 0;
}

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

using namespace std;
int t, n;
int cost[] = {0, 6000, 4000, 3000, 2000};
int main(){
 for(int i = 0;i < 4;i++){
  cin >> t >> n;
  cout << cost[t] * n << endl;
 }
 return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
	int a,b,c,d;

	scanf("%d%d%d%d",&a,&b,&c,&d);
	if (a+b>c+d)
		printf("Left");
	else if(a+b<c+d)
		printf("Right");
	else
		printf("Balanced");
	return 0; 
}

Measured memory_bytes: 128
N, P = map(int, input().split())

from collections import defaultdict
d = defaultdict(int)
i = 2
while P >= i*i:
    if P%i==0:
        P //= i
        d[i] += 1
    # elif i == 2:
    #     i += 1
    else:
        i += 1
        # i += 2
if P != 1:
    d[P] += 1

ans = 1
for k, v in d.items():
    # print(k, v)
    z = v // N
    ans *= k**z
print(ans)


Measured memory_bytes: 3316
from collections import deque
n, m = map(int, input().split())
q = deque()
t = {i: set() for i in range(1, n + 1)}
v = [-1] * n

for _ in range(m):
    a, b = map(int, input().split())
    t[a].add(b)
    t[b].add(a)
q.append(1)
v[0] = 1
while q:
    next = q.popleft()
    for i in t[next]:
        if v[i - 1] == -1:
            q.append(i)
            v[i - 1] = next
print('Yes')
print(*v[1:], sep='\n')

Measured memory_bytes: 72484
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7;
const double error = 1e-7;
const double PI = acos(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise\n"
#define tham getchar()
mt19937 rng((unsigned int) chrono::system_clock::now().time_since_epoch().count());

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9+5;
const ll infl = 1e18+1;
const int nmax = 1e3+5;
///====================== template =========================

int main(){
    FASTIO;
    int n;
    cin>>n;
    vector<int> hat(n);
    for(int i = 0; i<n; i++) cin>>hat[i];

    int mx = *max_element(hat.begin(), hat.end());
    int mn = *min_element(hat.begin(), hat.end());

    if(mx > mn+1){
        cout<<"No";
        return 0;
    }

    if(mx == mn){
        if(mx == n-1){
            cout<<"Yes";
            return 0;
        }
        if(mx*2 <= n){
            cout<<"Yes";
            return 0;
        }
        cout<<"No";
        return 0;
    }

    int mxcnt = 0;
    for(int i = 0; i<n; i++) if(hat[i] == mx) mxcnt++;

    if(mxcnt == 1){
        cout<<"No";
        return 0;
    }

    int mncnt = n - mxcnt;

//    debug(mxcnt);
//    debug(mncnt);
//    debug(mx);

    if(mncnt < mx && 2*(mx - mncnt) <= mxcnt){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans=0,tmp=0;
    rep(i,n) {
        if (a[i]<tmp) ans+=tmp-a[i];
        else tmp=a[i];
    } 
    cout << ans << endl;
   
    return 0;   
}

Measured memory_bytes: 4764
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Diverta2().SolveA(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
  
  class Diverta2
    {
        public void SolveA(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var k = cin.ReadInt;
            if (k == 1) WriteLine(0);
            else WriteLine(n - k);
            ReadLine();
        }
    }
}


Measured memory_bytes: 11220
N = int(input())
a = [int(input()) for _ in range(N)]

if N == 1:
    print(1)
    exit()

a.sort()
ans = 0
tmp = a[0]
a = a[1:]
count = 1
for aa in a:
    if aa == tmp:
        count += 1
    else:
        if count % 2 == 1:
            ans += 1
        tmp = aa
        count = 1
if count % 2 == 1:
            ans += 1

print(ans)


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

int main(){

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

	ll* table = new ll[N+1];

	table[0] = 0;
	for(int i = 1; i <= N; i++){
		scanf("%lld",&table[i]);
		table[i] += table[i-1];
	}

	ll S,tmp_sum,ans;
	int left,calc_left,calc_right,m;

	for(int loop = 0; loop < Q; loop++){
		scanf("%lld",&S);

		ans = 0;
		calc_left = 1;
		for(int right = 1; right <= N;right++){
			if(table[right]-table[right-1] > S)continue;

			calc_right = right;
			m = (calc_left+calc_right)/2;

			while(calc_left <= calc_right){
				tmp_sum = table[right]-table[m-1];

				if(tmp_sum <= S){
					left = m;
					calc_right = m-1;
				}else{ //tmp_sum > S
					calc_left = m+1;
				}
				m = (calc_left+calc_right)/2;
			}

			ans += (right-left+1);
			calc_left = left;
		}

		printf("%lld\n",ans);
	}

	return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#include<unordered_set>
#include <random>
#include <ctime>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MAX=2e5+1;
const ll MM=1e16;
const ll mod=1e9+7;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}

vl adj[MAX];
void solve()
{
   ll x1,x2,x3,x4,x5;
   cin>>x1>>x2>>x3>>x4>>x5;
   if(x1==0)
   cout<<1<<endl;
   else if(x2==0)
   cout<<2<<endl;
   else if(x3==0)
   cout<<3<<endl;
   else if(x4==0)
   cout<<4<<endl;
   else
   {
       cout<<5;
   }
   

       
}

int main()
{
  boost;
  ll t=1;
  //cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 8292
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int nennrei = sc.nextInt();
        int b = sc.nextInt();

        if(nennrei > 12){
          System.out.println(b);
        }else if(nennrei < 6){
          System.out.println(0);
        }else{
          System.out.println(b/2);
        }
    }
}


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

int main () {
    char s[100001];
    int i, len;

    scanf("%s", s);
    len = strlen(s);

    //printf("%d", len);

    for (i=0; i<len; i++) {
        if ((i%2)==0) {
            printf("%c", s[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

// N, E, S, W
int dx[4] = {-1, 0,  1,  0};
int dy[4] = { 0, 1,  0, -1};

map<char, int> mpdir = {
    {'N', 0},
    {'E', 1},
    {'S', 2},
    {'W', 3}
};

string dir = "NESW";

struct State {
    int x, y, d;
    State() {}
    State(int _x, int _y, int _d) : x(_x), y(_y), d(_d) {}
    bool operator== (const State& state) const {
        return x == state.x && y == state.y && d == state.d;
    }
    bool operator!= (const State& state) const {
        return !(*this == state);
    }
    bool operator< (const State& state) const {
        return x == state.x ? (y == state.y ? d < state.d : y < state.y) : x < state.x;
    }

    void print() {
        cout << x + 1 << " " << y + 1 << " " << dir[d] << endl;
    }
};

int H, W, L;
vector<string> s;
vector<State> v;
set<State> st;

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

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

    while (cin >> H >> W >> L, H) {
        s.clear();
        s.resize(H);
        v.clear();
        st.clear();

        State state;
        rep(i, H) {
            cin >> s[i];
            rep(j, W) {
                if (isalpha(s[i][j])) {
                    state.x = i;
                    state.y = j;
                    state.d = mpdir[s[i][j]];
                }
            }
        }

        rep(t, 50000) {
            if (st.count(state) != 0) {
                int offset;
                for(offset = 0; v[offset] != state; offset++) {
                    assert(offset < v.size());
                }

                int last_id = L;
                if (last_id >= offset) {
                    int T = t - offset;
                    last_id = (L - offset) % T + offset;
                }

                v[last_id].print();
                break;
            }

            v.emplace_back(state);
            st.insert(state);

            while (!inside(state.x + dx[state.d], state.y + dy[state.d]) || s[state.x + dx[state.d]][state.y + dy[state.d]] == '#') {
                state.d = (state.d + 1) % 4;
            }

            state.x += dx[state.d];
            state.y += dy[state.d];
        }
    }

}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, m;
bool bb[100];
ll p[100];

int main() {
	cin >> n >> m;
	rep(i, n)cin >> bb[i];
	rep(i, m)cin >> p[i];
	ll ans = INF;
	rep(i, 2) {
		bool b[100];
		bool ok = true;
		ll sum = 0;
		int now = 0;
		int cnt = 0;
		bool f = i;
		rep(j, 100)b[j] = bb[j];
		rep(j, n) {
			if (f != b[j]) {
				//cout << j;
				ll pos = -1;
				FOR(k, j + 1, n) {
					if (f == b[k]) {
						pos = k;
						break;
					}
				}
				if (pos == -1)ok = false;
				else {
					for (int k = pos; k > j; k--) {
						swap(b[k], b[k - 1]);
						sum++;
					}
				}
			}
			cnt++;
			if (cnt == p[now]) {
				now++;
				cnt = 0;
				f = !f;
			}
		}
		//cout << endl;
		//cout << sum << endl;
		if (ok)ans = min(ans, sum);
	}
	cout << ans << endl;
}


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

int main(void)
{
    ll N, ans = 0;
    cin >> N;
    vector<ll>  l(N);
    for(ll i = 0; i < N; i++) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());

    if(l.size() == 1 || l.size() == 2)
        cout << 0;
    else{
    for(ll i = 0; i < N - 2; i++) {
        for(ll j = i + 1; j < N - 1; j++) {
            for(ll k = j + 1; k < N; k++) {
                if(l.at(i) + l.at(j) > l.at(k) && (l.at(i) != l.at(j) && l.at(j) != l.at(k) && l.at(k) != l.at(i)))
                    ans++;
            }
        }
    }

    cout << ans;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> IntegerToVector(ll bit,ll N){
    vector<ll> S;
    rep(i,N){
        if(bit&(1<<i))S.push_back(1);
        else S.push_back(0);
    }
    return S;
}

int main()
{
    ll N,M,X;
    cin>>N>>M>>X;
    vector<vector<ll>> A(N,vector<ll>(M));
    vector<ll> C(N);
    rep(i,N){
        cin>>C.at(i);
        rep(j,M)cin>>A.at(i).at(j);
    }
    ll sum=0;
    ll cost=0;
    ll cmin=MOD;
    bool ok=true;
    rep(bit,1<<N){
        cost=0;
        ok=true;
        rep(i,M){
            sum=0;
            rep(j,N){
              sum+=A.at(j).at(i)*IntegerToVector(bit,N).at(j);  
            }
            if(sum<X)ok=false;
        }
        if(ok){
            rep(i,N)cost+=C.at(i)*IntegerToVector(bit,N).at(i);
            cmin=min(cost,cmin);
        }
    }
    if(cmin==MOD)cmin=-1;
    cout<<cmin<<endl;
}

Measured memory_bytes: 3640