akhauriyash/Code-Regression huggingface dataset:
// g++ temp.cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string>
#include <climits>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
//#define REP(i,n) FOR(i,1,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
const unsigned long long MOD = 100000000000000000;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
void solve(){
  ll a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;   
}
int main(){
  solve();
  return 0;
}

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

int t=0,k,n;
int gone[100+10]={},a[100+10][100+10]={},d[200+10],f[200+10];

void dfs(int cur){
    if(gone[cur]!=1){
        t+=1;
        d[cur]=t;
        gone[cur]=1;
    }
    for(int m=1;m<=n;m++){
        if(a[cur][m]==1){
            if(gone[m]==0){
                dfs(m);
            }
        }
    }
    t+=1;
    f[cur]=t;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        int u,p;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> p;
            a[i][p]=1;
        }
    }
    for(int q=1;q<=n;q++){
        if(gone[q]!=1) dfs(q);
    }
    for(int r=1;r<=n;r++){
        cout << r << " " << d[r] << " " << f[r] << endl;
    }
}

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << N*N*N << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    if (S.size() == 2){
        cout << S << endl;
    } else {
        cout << S[2] << S[1] << S[0] << endl;
    }
}

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


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

s = ['A', 'C', 'G', 'T']
invs = ['AGC', 'ACG', 'GAC']

d = {}
for c1 in s:
    for c2 in s:
        for c3 in s:
            d[c1+c2+c3] = 1 if c1+c2+c3 not in invs else 0

dn = {}
for _ in range(N - 3):
    for c1 in s:
        for c2 in s:
            for c3 in s:
                cnt = 0
                for c0 in s:
                    if c0+c2+c3!='AGC' and c0+c1+c3!='AGC':
                        cnt += d[c0+c1+c2]
                dn[c1+c2+c3] = cnt%1000000007 if c1+c2+c3 not in invs else 0
    dn, d = d, dn

print(sum(d.values())%1000000007)





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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int a, b;
    cin >> a >> b;
    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }
    int d = 1;
    rep(i, 100) {
        d += a - 1;
        if (d >= b) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a_b_tuple = [tuple(map(int, input().split())) for _ in range(N)]
c_d_tuple = [tuple(map(int, input().split())) for _ in range(M)]
for a_b in a_b_tuple:
    flg = 0
    tmp = 20000000000
    for i, c_d in enumerate(c_d_tuple):
        if tmp > abs(a_b[0] - c_d[0]) + abs(a_b[1] - c_d[1]):
            tmp = abs(a_b[0] - c_d[0]) + abs(a_b[1] - c_d[1])
            flg = i
    print(flg + 1)


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

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

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC096D();

#if 1
int main()
{
	ABC096D();
	fflush(stdout);
	return 0;
}
#endif

template <class _T> void tp_getPrimes(_T targ, std::map<_T, _T>& primes)
{
	_T target = targ;
	_T i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;
			primes[i]++;
		}
		else {
			i++;
		}
	}
	if (target > 1) {
		primes[target]++;
	}
}

static void ABC096D()
{
	int N;
	getint(N);
	
	int count = 0;
	std::vector<int> primeNumbers;
	for (int i = 2; i <= 55555; i++) {
		std::map<int, int> primes;
		tp_getPrimes<int>(i, primes);
		if ((primes.size() == 1) && (primes.begin()->second == 1)) {
			if (primes.begin()->first % 5 == 1) {
				primeNumbers.push_back(primes.begin()->first);
			}
		}
	}

	std::string str;
	for (int i = 0; i < N; i++) {
		char tmp[16] = { 0 };
		sprintf(tmp, "%d", primeNumbers[i]);

		if (i) {
			str += ' ';
		}
		str += tmp;
	}
	printf("%s\n", str.c_str());
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <array>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

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

int main() {
  LL N;
  std::cin >> N;
  std::vector<int> P(N);
  REP(i,N) {
    std::cin >> P[i];
    P[i]--;
  }
  std::vector<int> idx(N);
  for(LL i=0; i<N; i++) {
    idx[P[i]] = i;
  }

  LL ans = 0;
  std::set<int> larges; // indexes of P that are larger than target
  larges.insert(idx[N-1]);

  for(LL t=N-2; t >= 0; t--) {
    larges.insert(idx[t]);
    std::array<LL,2> ridxes = {N,N};
    std::array<LL,2> lidxes = {-1,-1};
    auto it = larges.find(idx[t]);
    it++;
    if( it != larges.end()) {
      ridxes[0] = *it;
      it++;
      if (it != larges.end()) { ridxes[1] = *it; }
    }
    it = larges.find(idx[t]);
    if( it != larges.begin() ) {
      it--;
      lidxes[0] = *it;
      if( it != larges.begin() ) { it--; lidxes[1] = *it; }
    }

    // one larger element on right
    ans += (t+1) * (ridxes[1]-ridxes[0]) * (idx[t]-lidxes[0]);
    // one larger element on left
    ans += (t+1) * (lidxes[0]-lidxes[1]) * (ridxes[0]-idx[t]);
  }

  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int fac[2000007],inv[2000007];
int x3,x4;
int y3,y4;
void init(){
	fac[0]=1;fac[1]=1;inv[0]=1;inv[1]=1;
	for(int i=2;i<2000007;i++){
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	}
	for(int i=2;i<2000007;i++){
		inv[i]=1ll*inv[i]*inv[i-1]%mod;
	}
}
int c(int x,int y){
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int f(int x,int y){
	return c(x+y,x);
}
int calc(int xs,int ys,int xt,int yt){
	int s=0,i;
	y3--;
	for(i=x3;i<=x4;i++){
		s=(s+1ll*f(i-xs,y4-ys)*f(xt-i,yt-y4-1)%mod*(i-xs+y4-ys))%mod;
		s=(s-1ll*f(i-xs,y3-ys)*f(xt-i,yt-y3-1)%mod*(i-xs+y3-ys))%mod;
	}
	y3++;
	x3--;
	for(i=y3;i<=y4;i++){
		s=(s+1ll*f(x4-xs,i-ys)*f(xt-x4-1,yt-i)%mod*(x4-xs+i-ys))%mod;
		s=(s-1ll*f(x3-xs,i-ys)*f(xt-x3-1,yt-i)%mod*(x3-xs+i-ys))%mod;
	}
	x3++;
	return s;
}
int main(){
	init();
	int ans=0;
	int x1,x2,x5,x6;
	int y1,y2,y5,y6;
	scanf("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
	scanf("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
	vector<pair<pair<int,int>,int> > v1,v2;
	v1.push_back(make_pair(make_pair(x1-1,y1-1),1));
	v1.push_back(make_pair(make_pair(x1-1,y2),-1));
	v1.push_back(make_pair(make_pair(x2,y1-1),-1));
	v1.push_back(make_pair(make_pair(x2,y2),1));
	v2.push_back(make_pair(make_pair(x6+1,y6+1),1));
	v2.push_back(make_pair(make_pair(x6+1,y5),-1));
	v2.push_back(make_pair(make_pair(x5,y6+1),-1));
	v2.push_back(make_pair(make_pair(x5,y5),1));
	for(int i=0;i<v1.size();i++){
		for(int j=0;j<v2.size();j++){
			ans=(ans+calc(v1[i].first.first,v1[i].first.second,v2[j].first.first,v2[j].first.second)*v1[i].second*v2[j].second)%mod;
		}
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
/*
int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= 3000; i++)
    for (int j = 0; j <= 3000; j++) {
      int v = i * R + j * G;
      if (N-v >=  && (N - v) % B == 0) ans++;
    }
  cout << ans << endl;
}
*/

int main(){

 int n,cnt=0,cnt1=0,cnt2=0,cnt3=0;
  cin>>n;

 while(n--){

  string das; cin>>das;

   for(int i=0;i<das.length();i++){
       if(das[i] == 'A' && das[i+1] == 'B')
        cnt++;
   }

   if(das[0] == 'B' && das[das.length()-1] == 'A')
    cnt1++;
   if( das[0] == 'B' && das[das.length()-1] != 'A')
    cnt2++;
   if(das[0] != 'B' && das[das.length()-1] == 'A')
     cnt3++;
 }

 if(cnt1 == 0 )
    cout<<cnt+cnt1+min(cnt2,cnt3)<<endl;
 else if(cnt1 != 0 && cnt2+cnt3 > 0)
    cout<<cnt+ cnt1 + min(cnt2,cnt3)<<endl;
 else if(cnt1 != 0 && cnt2+cnt3 == 0)
    cout<<cnt+cnt1-1<<endl;

return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int>v;
    for(int i=0; i<n; i++){
        int h;
        cin >> h;
        h--;
        v.push_back(h);
    }
    
    int now = 0, c = 0;
    for (int i = 0; i < n; i++){
        if(now==1){
            cout << c << endl;
            return 0;
        }
        if(c>=n){
            cout<<-1<<endl;
            break;
        }
        
        c++;
        now = v[now];
        
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef pair<ll, ll> PL;
typedef long double ldouble;
typedef tuple<int,int,int> t3;

const int MX = 55;

bitset<55> pos[MX][MX];
int A[MX], B[MX];
int N;

bool check(int i, int k, bitset<55> X)
{
  int ch = 0;
  for(int j = 0; j <= 50; j++){
    if(X[j]) ch |= pos[i][k][j];
  }
  return ch;
}

ll dfs(int k, bitset<55> P[MX]){
  if(k == 0) return 0;
  int ch = 1;
  for(int i = 1; i <= N; i++){
    if(!check(i, k-1, P[i])) ch = 0;
  }
  if(ch) return dfs(k-1, P);
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= 50; j++){
      P[i][j%k] = P[i][j%k] | P[i][j];
    }
  }
  return dfs(k-1, P) + (1ll << k);
}

int main()
{
  scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", A+i);
  for(int i = 1; i <= N; i++) scanf("%d", B+i);
  for(int i = 1; i <= N; i++) pos[i][0][B[i]] = 1;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j < MX; j++){
      pos[i][j] = pos[i][j-1];
      for(int k = 0; k < j; k++){
        for(int l = 1; l*j + k < MX; l++) pos[i][j][k+j*l] = pos[i][j][k+j*l] | pos[i][j][k];
      }
    }
  }
  int ch = 1;
  for(int i = 1; i <= N; i++) ch &= pos[i][50][A[i]];
  if(!ch) return !printf("-1\n");

  bitset<55> P[MX] = {};
  for(int i = 1; i <= N; i++) P[i][A[i]] = 1;
  ll ans = dfs(50, P);
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
/*
	Auth: Loxilante
	Time: 2020/09/19
	Prog: ABC179C
	Lang: cpp
*/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#endif
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
signed main(void)
{
	clock_t Begin = clock();

	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n = next(), ans = 0;

	hrp(i, 1, n)
	{
		int contin = 0;
		hrp(j, 1, n)
		{
			if (i*j < n) ans++;
			else {contin = 1; break;}
		}
		if (contin) continue;
	}
	
	cout<<ans<<endl;
	
	clock_t InputFinished = clock();
	
	
	
	clock_t End = clock();
	
	D((double)(End-Begin)/CLOCKS_PER_SEC);
	D((double)(End-InputFinished)/CLOCKS_PER_SEC);
	
	return 0;
}
/*

 */

Measured memory_bytes: 3644
// https://beta.atcoder.jp/contests/abc061

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

ui64 N, K;
map<int, ui64> int_to_count;

int main() {
    cin >> N >> K;
    ui64 a, b;
    for (int i = 0; i < N; ++i) {
        cin >> a >> b;
        int_to_count[a] += b;
    }

    int ans = 0;
    ui64 sum = 0;
    for (auto p : int_to_count) {
        sum += p.second;
        if (K <= sum) {
            ans = p.first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int H,W;
int h[2010][2010] = {},w[2020][2020] = {};
char F[2010][2010];

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

int dfs(int x,int y,int dx,int dy,int c){
    if(!in(x+dx,y+dy) || F[x+dx][y+dy]=='#'){
        if(dx==1) h[x][y] = c;
        else w[x][y] = c;
        return c;
    }else{
        int a = dfs(x+dx,y+dy,dx,dy,c+1);
        if(dx==1) h[x][y] = a;
        else w[x][y] = a;
        return a;
    }
}

int main(){
    cin >> H >> W;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++) cin >> F[i][j];
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(F[i][j]!='#' && h[i][j]==0){
                dfs(i,j,1,0,1);
            }
            if(F[i][j]!='#' && w[i][j]==0){
                dfs(i,j,0,1,1);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(F[i][j]!='#') ans = max(ans,h[i][j]+w[i][j]-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35840
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strArray = new String[2];
    StringBuilder sb = new StringBuilder();
    String line;
    while (true) {
      line = br.readLine();
      strArray = line.split(" ");
      int h = Integer.parseInt(strArray[0]);
      int w = Integer.parseInt(strArray[1]);
      if(h == 0 && w == 0) {
        break;
      }
      for (int i = 0;i < h;i++) {
        for (int f = 0;f < w;f++) {
          sb.append("#");
        }
        sb.append("\n");
      }
      sb.append("\n");
    }
    System.out.print(sb);
  }
}

Measured memory_bytes: 25556
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;


int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << (t / a)*b << endl;
	return 0;
}


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

int main() {
	int n, x;
	cin >> n >> x;
	array <int, 110> L, D;
	D[1]= 0;
	for (int i = 1; i <= n;i++) {
		cin >>L[i];
	}
	for (int i = 2; i <= n + 1; i++) {
		D[i] = D[i - 1] + L[i - 1];
		if (D[i]>x){
			cout << i - 1;
			return 0;
		}
	}
	cout << n + 1;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e9; 
int a[10];
int n;
string s;
ll num1,num2;
void go(){
	num1=0,num2=0;
	int cur=0;
	while(cur<(int)s.size()&&s[cur]!='.')num1=num1*10+s[cur]-'0',cur++;
	if((int)s.size()==cur)return;
	cur++;
	int now=8;
	while(cur<(int)s.size())num2+=a[now]*(s[cur]-'0'),now--,cur++;
}
int wants[20][20];
int p2,p5;
void intbreak(ll x){
	p2=0,p5=0;
	while(x%2==0)p2++,x/=2;
	while(x%5==0)p5++,x/=5;
}
ll ans=0;
int main(){
	cin>>n;
	a[0]=1;
	for(int i=1;i<9;i++)a[i]=a[i-1]*10;
	for(int i=1;i<=n;i++){
		cin>>s;
		go();
		num1=num1*INF+num2;
		intbreak(num1);
		p2=min(p2,18),p5=min(p5,18);
		ans+=wants[p2][p5];
		int P2=18-p2,P5=18-p5;
		for(int j=P2;j<19;j++)for(int k=P5;k<19;k++)wants[j][k]++;
	}
	cout<<ans;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    long long k;
    cin >> n >> k;
    long long a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    vector<long long> arrive;
    arrive.push_back(0);
    vector<long long>::iterator itr;
    long long P = 0;

    set<long long >s;
    s.insert(0);

    for(int i = 0; i < n; i++) {
        long long next = a[arrive[i]];
        s.insert(next);
        int ssize = s.size();
        if(ssize == i + 2) {
            arrive.push_back(next);
            continue;
        }

        itr = find(arrive.begin(), arrive.end(), next);
        P = (long long) distance(arrive.begin(), itr);
        break;
    }

    int size = arrive.size();
    int period = size - P;

    long long index;
    if(k <= P) index = k;
    else index = P + (k - P) % period;

    cout << arrive[index] + 1 << endl;

    return 0;
}

Measured memory_bytes: 15576
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5+5 , M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const double Pii = 3.14159265359;
ll n;
ll a[N];
int main()
{
    FIO
    cin >> n;
    ll tot = 0;
    for(int i=0; i<n; ++i)
    {
        cin >> a[i];
        tot ^= a[i];
    }
    for(int i=0; i<n; ++i) a[i]^= tot;
    for(int i=0; i<n; ++i) cout << a[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 5148
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int D,G,sum=0,ans=1000000000;
    cin>>D>>G;
    int p[10],c[10];
    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
    }
    for(int i=0;i<(1<<D);i++){
        int count=0;
        int unused =0;
        sum=0;
        for(int k=0;k<D;k++){
            if(i & 1<<k){
                sum=sum+100*(k+1)*p[k];
                sum=sum+c[k];
                count += p[k];
            } else {
                unused = k;
            }
        }
        for(int k = 0; k< p[unused] - 1;k++){
            if(sum<G){
                sum += 100*(unused+1);
                count++;
            }else{
                break;
            }
        }
        //cout<<count<<endl;
        if(sum>=G)ans=min(count,ans);
    }
    cout<<ans<<endl;
    return 0;
}



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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<vector<int>> grid(h, vector<int>(w, 0));
    bool forw = true;
    int i = 0, j = 0;
    for (int c = 1; c <= n; c++) {
        int a;
        cin >> a;
        while (a--) {
            grid[i][j] = c;
            if (forw)
                j++;
            else
                j--;
            if (j == w || j == -1) {
                forw = !forw;
                i++;
                j = (j == w ? w - 1 : 0);
            }
        }
    }
    for (auto v : grid) {
        for (int x : v) {
            cout << x << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,ans=0;
int main(){
    ll n;
    string s;
    cin>>n>>s;
    vl k(26,0);
    rep(i,n){
        k[s[i]-'a']++;
    }
  ans=1;
    for(int i=0;i<26;i++){
        ans=(ans*(k[i]+1))%1000000007;
    }
 
    cout<<ans-1<<endl;
}

Measured memory_bytes: 512
//ALDS1_7B
#include <iostream>
using namespace std;

#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
 if(u==NIL) return;
 D[u]=d;
 setDepth(T[u].l,d+1);
 setDepth(T[u].r,d+1);
}

int setHeight(int u){
 int h1=0,h2=0;
 if(T[u].l!=NIL) h1=setHeight(T[u].l)+1;
 if(T[u].r!=NIL) h2=setHeight(T[u].r)+1;
 return H[u]=(h1>h2 ? h1:h2);
}

int setSibling(int u){
 if(T[u].p==NIL) return NIL;
 if(T[T[u].p].l!=u && T[T[u].p].l!=NIL) return T[T[u].p].l;
 if(T[T[u].p].r!=u && T[T[u].p].r!=NIL) return T[T[u].p].r;
 return NIL;
}

void print(int u){
 int i,c;
 cout<<"node "<<u<<": ";
 cout<<"parent = "<<T[u].p<<", ";
 cout<<"sibling = "<<setSibling(u)<<", ";
 int deg=0;
 if(T[u].l!=NIL) deg++;
 if(T[u].r!=NIL) deg++;
 cout<<"degree = "<<deg<<", ";
 cout<<"depth = "<<D[u]<<", ";
 cout<<"height = "<<H[u]<<", ";
 if (T[u].p==NIL) cout<<"root";
 else if(T[u].l==NIL && T[u].r==NIL) cout<<"leaf";
 else cout<<"internal node";
 cout<<endl;
}

int main(){
 int v,l,r,root=0;
 cin>>n;
 for(int i=0;i<n;i++) T[i].p=NIL;
 for(int i=0;i<n;i++){
  cin>>v>>l>>r;
  T[v].l=l;
  T[v].r=r;
  if(l!=NIL) T[l].p=v;
  if(r!=NIL) T[r].p=v;
 }
 for(int i=0;i<n;i++){
  if(T[i].p==NIL) root=i;
 }
 setDepth(root,0);
 setHeight(root);
 for(int i=0;i<n;i++) print(i);
 return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST freopen("in.txt","r",stdin);
#define ab(a) ((a < 0) ? (-(a)) : (a))
#define all(a) a.begin(), a.end()
#define ones(a) __builtin_popcount(a)

const int N = 2002;
int n,k,q; 
int arr[N];
bool allow[N];

int find_answer(int w){
  for(int i = 0;i < N;i ++ )
    allow[i] = true;
  for(int i = 0;i < n;i ++ )
    if(arr[i] < w)
      allow[i] = false;
  vector<int>it;
  vector<int>tot;
  for(int i = 0; i < n;i ++ ){
    if(allow[i] == false){
      sort(it.begin(), it.end());
      for(int j = 0;j < (int)it.size() - k + 1;j ++ ){
        tot.push_back(it[j]);
      }
      it.clear();
    }
    else{
      it.push_back(arr[i]);
    }
  }
  sort(it.begin(), it.end());
  for(int j = 0;j < (int)it.size() - k + 1;j ++ ){
    tot.push_back(it[j]);
  }
  it.clear();
  sort(tot.begin(), tot.end());
  if(tot.size() < q)  
    return (int)2e9 + 9;
  return tot[q-1]-w;
}

int main(){
  fastIO;
  cin >> n >> k >> q;
  for(int i = 0;i < n;i ++ )
    cin >> arr[i];
  int ans = (int)2e9 + 9;
  for(int i = 0;i < n;i ++ )
    ans = min(ans, find_answer(arr[i]));
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <string>
#include  <cstdlib>

#define pass()


int main(void)
{
	int A, B, C, K;

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

	std::string ans = "No";

	for(int i = 0; i < K; i++)
	{
		if(B <= A)
			B = 2 * B;
		else if(C <= B)
			C = 2 * C;
		else
			pass();

		if(A < B && B < C)
		{
			ans = "Yes";
			break;
		}
	}

	std::cout << ans << std::endl;

	return EXIT_SUCCESS;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T;
  cin >> S >> T;
  map<char, char> m1;
  int size = S.size();
  bool ok = true;
  for(int i = 0; i < size; i++) {
    if(m1.count(S[i])) {
      if(m1[S[i]] != T[i]) {
        ok = false;
        break;
      }
    } else {
      m1[S[i]] = T[i];
    }
  }
  map<char, char> m2;
  for(int i = 0; i < size; i++) {
    if(m2.count(T[i])) {
      if(m2[T[i]] != S[i]) {
        ok = false;
        break;
      }
    } else {
      m2[T[i]] = S[i];
    }
  }

  if(ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
	int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
	int K ;
	cin >> K ;
	cout << a[K - 1] << endl ;
	
	
	
	return 0 ;
}

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

int main(){
  int N, M; cin >> N >> M;
  vector<pair<int, int>> AB(N);
  for (int i=0; i<N; i++){
    cin >> AB[i].first >> AB[i].second;
  }
  sort(AB.begin(), AB.end(), [](const auto& a, const auto& b){ return a.first < b.first; });
  priority_queue<int> que;
  int ans = 0;
  int pos = 0;
  for (int i=1; i<=M; i++){
    while(pos<N&&AB[pos].first <= i){
      que.push(AB[pos].second);
      pos++;
    }
    if (!que.empty()){
      ans += que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long LL;

const int N = 110;

int n, t, res = 0x3f3f3f3f;

int main()
{
    cin >> n >> t;
    while(n--)
    {
        int a, b;
        cin >> a >> b;
        if(b <= t) res = min(res, a);
    }

    if(res == 0x3f3f3f3f) puts("TLE");
    else cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(void){
    int i,sum,len,ix[1001]={};
    char x[1001]={};
    for(;;){
        sum=0;
        scanf("%s",x);
        len=strlen(x);
        if(len==1 && x[0]=='0')break;
        for(i=0;i<len;i++){
            if(x[i]!=0){
                ix[i]=x[i]-'0';
                sum+=ix[i];
            }
        }
        printf("%d\n",sum);
        
    }
    return 0;
}



Measured memory_bytes: 1852
n, a, b = map(int,input().split(" "))
s = input()

count_dome = 0
count_fore = 0

for i in range(len(s)):
    if (s[i] == "c"):
        print("No")
    elif (s[i] == "a"):
        if (count_dome + count_fore < a + b):
            print("Yes")
            count_dome += 1
        else:
            print("No")
    else:
        if (count_dome + count_fore < a + b):
            if (count_fore < b):
                print("Yes")
                count_fore += 1
            else:
                print("No")
        else:
            print("No")


Measured memory_bytes: 4024
N, M, C = [int(i) for i in input().split()]
b_ls = [int(i) for i in input().split()]
a_ls = list()
for i in range(N):
    a_ls.append([int(i) for i in input().split()])
a_ls = [sum([a*b for a, b in zip(line, b_ls)]) + C for line in a_ls]
a_ls = [a for a in a_ls if a > 0]
print(len(a_ls))

Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

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

int main(){
  int N, T;

  cin >> N >> T;

  VI v(N);
  REP(i, 0, N){
    cin >> v[i];
  }

  int maxv = 0, minv = v[0], index = 0, min_ind = 0, ini_max, ans = 0;
  REP(i, 1, N){
    if(maxv < v[i] - minv){
      maxv = v[i] - minv;
      min_ind = index;
      ini_max = maxv;
    }
    maxv = max(maxv, v[i] - minv);
    if(minv > v[i]){
      minv = v[i];
      index = i;
    }
  }

  v[min_ind]++;
  ans++;
  //cout << "ind:" << min_ind << " " << v[min_ind] << endl;

  maxv = 0; minv = v[0];
  int same_num = 1;
  REP(i, 1, N){
    maxv = max(maxv, v[i] - minv);
    if(maxv == ini_max){
      ans += same_num;
      maxv = 0;
      minv = INF*3;
      same_num = 1;
    }
    if(minv == v[i]){
      same_num++;
    }
    if(minv > v[i]){
      minv = v[i];
      same_num = 1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
S = input()

mod = 2019
cnt = [0] * 2019
cur = 0  # 現在検討中の部分文字列
cnt[cur] = 1
d = 1   # 桁

for s in S[::-1]:
    cur += int(s) * d
    cur %= mod
    cnt[cur] += 1
    d *= 10
    d %= mod

ans = 0
for c in cnt:
    ans += c * (c-1) // 2

print(ans)

Measured memory_bytes: 9368
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    c = 1000
    s = 0

    for i in range(0, n-1):
        j = i + 1  # 比較対象(翌日)
        diff = A[j] - A[i]
        # 次にup 今持っている現金を全て株にする
        if diff > 0:
            s += c // A[i]
            c = c % A[i]
        # 次にdown 今持っている株を全て現金にする
        elif diff < 0:
            c += s * A[i]
            s = 0
        #print(i, s, c)

    # 最後に株を全て現金に戻す
    c += s * A[n-1]

    print(c)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
int n,m,q,a1,b1,a2,b2,a[2005][2005],s1[2005][2005],s2[2005][2005],s3[2005][2005];char c[2005];
int gao1(int a1,int b1,int a2,int b2){return s1[a2][b2]-s1[a1-1][b2]-s1[a2][b1-1]+s1[a1-1][b1-1];}
int gao2(int a1,int b1,int a2,int b2){return s2[a2][b2]-s2[a1-1][b2]-s2[a2][b1-1]+s2[a1-1][b1-1];}
int gao3(int a1,int b1,int a2,int b2){return s3[a2][b2]-s3[a1-1][b2]-s3[a2][b1-1]+s3[a1-1][b1-1];}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++){scanf("%s",c+1);for(int j=1;j<=m;j++) a[i][j]=c[j]-'0';}
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
        s1[i][j]=a[i][j];
        if(a[i][j]&&a[i][j+1]) s2[i][j]=1;
        if(a[i][j]&&a[i+1][j]) s3[i][j]=1;
    }
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
        s1[i][j]+=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1];
        s2[i][j]+=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1];
        s3[i][j]+=s3[i-1][j]+s3[i][j-1]-s3[i-1][j-1];
    }
    while(q--) scanf("%d%d%d%d",&a1,&b1,&a2,&b2),printf("%d\n",gao1(a1,b1,a2,b2)-gao2(a1,b1,a2,b2-1)-gao3(a1,b1,a2-1,b2));
}

Measured memory_bytes: 64640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

struct Edge {
  int to, cost;
  Edge(int to_, int cost_) {
    to = to_; cost = cost_;
  }
};

struct State {
  int room, cost, bit;
  State(int room_, int cost_, int bit_) {
    room = room_; cost = cost_; bit = bit_;
  }
  bool operator<(const State& s) const {
    return cost < s.cost;
  }
  bool operator>(const State& s) const {
    return cost > s.cost;
  }
};

int N, M, L, K;
int S, G;
int ball_room[8];
vector<Edge> graph[51];

int dij()
{
  priority_queue<State, vector<State>, greater<State> > q;
  int used[51][1 << 8] = {{0}};
  int cnt = 0; //これがKになったらコストを返す

  Rep(i, L) {
    if( ball_room[i] == S ) {
      q.push( State(S, 0, 1 << i) );
      break;
    }
    if( i == L-1 ) q.push( State(S, 0, 0) );
  }

  while( !q.empty() ) {
    State p = q.top(); q.pop();
    int room = p.room, cost = p.cost, bit = p.bit;
    if( room == G && bit == (1 << L)-1 ) {
      cnt++;
      if( cnt == K ) return cost;
    }
  
    if( used[room][bit] > K ) continue;
    used[room][bit]++;

    vector<Edge> e = graph[room];
    Rep(i, e.size()) {
      int next = e[i].to, next_bit = bit, next_cost = cost + e[i].cost;
      Rep(j, L) {
	if( ball_room[j] == next ) {
	  next_bit = (next_bit | (1 << j)); 
	  break;
	}
      }
      if( used[next][next_bit] > K ) continue;
      q.push( State(next, next_cost, next_bit) );
    }
  }

  return -1;
}



int main()
{
  while( cin >> N >> M >> L >> K, N ) {
    Rep(i, 51) graph[i].clear();
    Rep(i, M) {
      int a, b, c;
      cin >> a >> b >> c;
      a--; b--;
      graph[a].pb( Edge(b, c) );
      graph[b].pb( Edge(a, c) );
    }
    
    cin >> S >> G;
    S--; G--;
    
    Rep(i, L) {
      cin >> ball_room[i];
      ball_room[i]--;
    }
    
    int ans = dij();
    if( ans == -1 ) cout << "NA" << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 43268
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    ll rep = 1;
    for (ll i = 2;i * i <= n;i++){
        if (n % i != 0) continue;
        ll ex = 0;
        while(n % i == 0){
            ex++;
            n /= i;
        }
        long long cnt = 1;
        while(cnt <= ex){
            ans++;
            ex -= cnt;
            cnt++;
        }
    }
    if (n != 1) ans++;
    cout <<ans << endl;
    return 0;
}

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

def main():
    a, b = map(int, input().split())

    def check(x):
        return x < 1 or x > 9


    if check(a) or check(b):
        print(-1)
    else:
        print(a*b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int x, y; cin >> x >> y;
    cout << x + y / 2 << endl;
}


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

int a[4];

void sol(int n,int i,string ans)
{
	if(n==7&&i==4)
	{
		for(int i = 0;i<3;i++)
		{
			cout<<a[i]<<ans[i+1];
		}
		cout<<a[3]<<'='<<7<<endl;
		exit(0);
	}
	if(i==4)return;
	string s = ans;
	sol(n+a[i],i+1,ans+"+");
	sol(n-a[i],i+1,ans+"-");
}

int main()
{
	string s;
	cin >> s;
	for(int i = 0;i<s.size();i++)
	{
		a[i] = s[i]-'0';
	}	
	sol(0,0,"");
	return 0;
}

Measured memory_bytes: 256
a = input()
p, q = int(a[:2]), int(a[2:])
if 0<p<13 and 0<q<13:
    print("AMBIGUOUS")
elif 0<p<13:
    print("MMYY")
elif 0<q<13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
from itertools import accumulate
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
S = [0]+list(accumulate(A))
S = Counter(S)
S = list(S.values())
count = 0

for i in range(len(S)):
  count += (S[i]*(S[i]-1)//2)
print(count)

Measured memory_bytes: 41492
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::fs::File;
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::io::Stdin;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

type BoxResult<T> = Result<T, Box<std::error::Error>>;

fn main() {
    let mut scanner = Scanner::new(stdin());
    let param = scanner.read_vector::<usize>().unwrap();
    let (n, m) = (param[0], param[1]);
    let (mut minimum, mut maximum) = (1, n);
    for _ in 0..m {
        let line = scanner.read_vector::<usize>().unwrap();
        let (l, r) = (line[0], line[1]);
        minimum = max(l, minimum);
        maximum = min(r, maximum);
    }
    if minimum > maximum {
        println!("0");
        return;
    }
    println!("{}", maximum - minimum + 1);
}

#[allow(dead_code)]
struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}

impl<R> Scanner<R>
where
    R: Read,
{
    #[allow(dead_code)]
    fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner { reader: reader, buffer: buffer }
    }

    #[allow(dead_code)]
    fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner { reader: reader, buffer: buffer }
    }

    #[allow(dead_code)]
    fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }

    #[allow(dead_code)]
    fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }

    #[allow(dead_code)]
    fn read_matrix<T>(&mut self, lines: usize) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MOD 1000000007
#define MAXN 100000

int N, K, A[MAXN + 3];
LL fact[MAXN + 3];

LL fastExponentiation(int base, int p) {
    if (p == 0)
        return 1;

    LL half = fastExponentiation(base, p/2);
    LL halfhalf = (half * half)%MOD;

    if (p%2 == 0)
        return halfhalf;
    else
        return (halfhalf * base)%MOD;
}

LL C(int n, int k) {
    LL numerator = fact[n];
    LL denominator = (fact[k] * fact[n - k])%MOD;
    return (numerator * fastExponentiation(denominator, MOD - 2))%MOD;
}

int main() {
    fact[0] = 1;
    for (int i = 1; i <= MAXN; i++)
        fact[i] = (fact[i - 1] * i)%MOD;

    cin >> N >> K;
    for (int i = 1; i <= N; i++)
        cin >> A[i];

    sort(A + 1, A + N + 1);

    LL answer = 0;

    //Count contribution of A[i] as the maximum element
    for (int i = K; i <= N; i++) {
        LL contribution = (C(i - 1, K - 1) * A[i])%MOD;
        answer = (answer + contribution)%MOD;
    }

    //Count contribution of A[i] as the minimum element
    for (int i = 1; i <= N - K + 1; i++) {
        LL contribution = (C(N - i, K - 1) * A[i])%MOD;
        answer = (answer - contribution + MOD)%MOD;
    }

    cout << answer << endl;
}


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

int main(){
    int n,debut,fin;
    string s;

    cin >> s;
    n=s.size();
    debut=0;
    fin=n-1;
    while(s[debut]!='A') debut++;
    while(s[fin]!='Z') fin--;

    cout << fin-debut+1 << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main() {
  string S;
  ll C=0;
  cin >> S;
  rep(i,(S.size()+1)/2){
    if(S[i]!=S[S.size()-i-1]){
      C++;
    }
  }
  cout << C << endl;
}

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

const int N = 4e6 + 5;

bitset <N> dp;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  	int n; cin >> n;
  	dp[0] = true;
  	int sum = 0;
  	while (n--){
      	int x; cin >> x; sum += x;
      	dp |= dp << x;
    }
  	sum = (sum + 1) / 2;
  	while (1){
		if (dp[sum]) return cout << sum, 0;
      	sum++;
    }
}

Measured memory_bytes: 5108
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll F[2100010];

ll Mul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
ll square(ll x) {
	return (x * x) % mod;
}

ll power(ll x, ll y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

ll Div(ll a, ll b) {
	return Mul(a, power(b, mod - 2));
}
ll p(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

ll C(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	ll ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}

ll H(ll n, ll r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

ll calc(ll n, ll r) {
	ll ret = 1;
	for (ll x = n, i = 0; i < r; i++, x--) ret = Mul(ret, x);
	for (ll i = 1; i <= r; i++) ret = Div(ret, i);
	return ret;
}
int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = power(2, n) - 1;
	ans -= (calc(n, a) + calc(n, b));
	if (ans < 0) ans += 2ll * mod;
	cout << ans % mod << endl;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    cin >> m;
    vector<int> t(m);
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());
    int cur = 0;
    for (int i = 0; i < n; i++) {
        if (t[cur] == d[i]) cur++;
        if (cur == m) break;
    }
    cout << (cur == m ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

int K, T;
vector<int> a;
int main(){
  cin >> K >> T;
  REP(i,T){
    int b;
    cin >> b;
    a.push_back(b);
  }
  int x = 0;
  int y = 0;
  sort( a.begin(), a.end() );
  reverse( a.begin(), a.end() );
  REP( i, T ){
    if( x > y ){
      y += a[i];
    }else{
      x += a[i];
    }
  }
  cout << max(0, abs(x - y) - 1) << endl;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  var nandm = lines[0].split(' ');
  var n = Number(nandm[0]);
  var m = Number(nandm[1]);

  var start = [];
  var end = [];

  for(i=1; i<=m; i++){
    var tmp = lines[i].split(' '); 
    start.push(Number(tmp[0]));
    end.push(Number(tmp[1]));
  }
  var s = Math.max(...start);
  var e = Math.min(...end);

  var output = (e-s)+1;
  if(output < 0){
    output = 0;
  }
  console.log(output);
  
});

Measured memory_bytes: 49336