akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

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

    int n;
    string line;
    cin >> n >> line;

    string ans = "";
    REP(i, 4) {
        string t_ans = "";
        int t = i;
        REP(j, 2) {
            t_ans += t & 1 ? "W" : "S";
            t >>= 1;
        }
        FOR(j, 2, n) {
            if(t_ans[j-1] == 'S') {
                if(line[j-1] == 'o') {
                    t_ans += t_ans[j-2] == 'S' ? "S" : "W";
                } else {
                    t_ans += t_ans[j-2] == 'S' ? "W" : "S";
                }
            } else {
                if(line[j-1] == 'o') {
                    t_ans += t_ans[j-2] == 'S' ? "W" : "S";
                } else {
                    t_ans += t_ans[j-2] == 'S' ? "S" : "W";
                }
            }
        }
#if DEBUG
        cout << t_ans << endl;
#endif
        string decode_check = "";
        REP(j, n) {
            if(t_ans[j] == 'S') {
                if(t_ans[(n+j-1) % n] == t_ans[(n+j+1) % n]) {
                    decode_check += "o";
                } else {
                    decode_check += "x";
                }
            } else {
                if(t_ans[(n+j-1) % n] == t_ans[(n+j+1) % n]) {
                    decode_check += "x";
                } else {
                    decode_check += "o";
                }
            }
        }
#if DEBUG
        cout << decode_check << endl;
#endif
        if(decode_check == line) {
            ans = t_ans;
            break;
        }
    }

#if DEBUG
    cout << "** RESULT **" << endl; // debug
#endif
    cout << (ans.length() == 0 ? "-1" : ans) << endl;
}


Measured memory_bytes: 904
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


k,q = map(int, input().split())
d = list(map(int, input().split()))

def sub(n,x,m):
    X = 0
    init = x%m
    x%=m
    n -= 1
    if n<=k:
        for i in range(n):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        ans = X
    else:
        for i in range(k):
            if x<(x+d[i])%m:
                X += 1
            x = (x+d[i])%m
        diff = (x-init)
        ans = (n//k) * X - (init + (diff*(n//k))) // m
        nn = n-(n//k)*k
        xx = (init + (diff*(n//k))) % m
#         if xx<init:
#             ans -= 1
        for i in range(nn):
            if xx<(xx+d[i])%m:
                ans += 1
            xx = (xx+d[i])%m
    return ans
#         else:
#             ans = (n//k) * X + (init + (diff*(n//k)))
ans = [None]*q
for i in range(q):
    n,x,m = map(int, input().split())
    ans[i] = sub(n,x,m)
write("\n".join(map(str, ans)))

Measured memory_bytes: 75080
def main():
  N, M = [int(n) for n in input().split(" ")]

  if abs(N - M) >= 2:
    print(0)
  elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % 1000000007)
  else:
    print((factorial(N) * factorial(M) * 2) % 1000000007)

def factorial(n):
  ret = 1
  for i in range(1, n + 1):
    ret = (ret * i) % 1000000007
  return ret
    
main()


Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(b - a) <= d && abs(c- b) <= d) || abs(c - a) <= d) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;

class Ab{
  static void Main(){
    int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    int A = Ar[0];
    int B = Ar[1];
    
    if (A - B * 2 > 0) Console.WriteLine(A - B * 2);
    else Console.WriteLine("0");
  }
}

Measured memory_bytes: 11092
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,B,C,k=get_i
ans=0
ans+=min(A,k)
k-=A
if k<=0
    puts ans
    exit
end
k-=B
if k<=0
    puts ans
    exit
end
ans-=min(C,k)
puts ans

Measured memory_bytes: 14328
N,M = map(int,input().split())
ab = [[int(i) for i in input().split()] for i in range(M)]

def dfs(Graph, Start, Visited=None):
    if (Visited==None):  Visited = []
    Visited.append(Start) 
    for Next in Graph[Start]: 
        if ( Next in Visited ):  
            continue 
        Visited = dfs(Graph, Next, Visited)
    return Visited
 
ans = 0
for it in range(M):
    hoge = list(ab)
    del hoge[it]
    l = [[] for i in range(N)]
    for pi in hoge:
        l[pi[0]-1].append(pi[1]-1)
        l[pi[1]-1].append(pi[0]-1)
    if(N != len(dfs(l, 0))):
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

	int N, M, i, result;
	int A[10001];
	int sum = 0;

	scanf("%d %d", &N, &M);

	for (int i = 0; i < M;  i++) {

		scanf("%d", &A[i]);

		sum = sum + A[i];

	}

	for (int i = 0; i < M; i++) {

		result = N - sum;

	}

	if (result < 0) {
		printf("-1");
	}
	else {
		printf("%d", result);
	}

	return 0;
}

Measured memory_bytes: 1772
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IL inline
using namespace std;
typedef long long LL;
typedef unsigned int U;
typedef unsigned long long LLU;
typedef pair<int,int> PII;
typedef long double LD;
IL LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
#define io read()
#define int LL
const int N=200008;
int n; 
int a[N],s[N],sum[N];
int fl[N],fr[N];
int ans,mn;
signed main()
{
	n=io;
	for(int i=1;i<=n;++i){
		a[i]=io;
		sum[i]=sum[i-1]+a[i];
		s[i]=s[i-1];
		if((a[i]&1)^1)	++s[i];
		fl[i]=fl[i-1];
		if(a[i]==0)	fl[i]+=2;
		if(a[i]&1)	++fl[i];
		fl[i]=min(fl[i],sum[i]);
	}
	for(int i=n;i>=0;--i){
		fr[i]=fr[i+1];
		if(i<n&&a[i+1]==0)	fr[i]+=2;
		if(a[i+1]&1)	++fr[i];
		fr[i]=min(fr[i],sum[n]-sum[i]);	
	}
	ans=fr[0];
	mn=0;
	for(int i=1;i<=n;++i){
		//cout<<i<<' '<<fl[i]<<' '<<fr[i]<<'\n';
		mn=min(mn,fl[i]-s[i]);
		ans=min(ans,mn+fr[i]+s[i]);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>

int main(void)
{
	int n;
	int ans;
	int k;
	int i;
	bool f;
	
	while (scanf("%d", &n), n){
		ans = n + 1;
		f = false;
		for (i = 0; i < n; i++){
			scanf("%d", &k);
			if (k == 0){
				ans--;;
			}
			if (k > 1){
				f = true;
			}
		}
		if (f == true){
			printf("%d\n", ans);
		}
		else {
			printf("NA\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 1040
local read = io.read
local N, K = read("*n", "*n")

local number_of_types = {}
local have_types_s = {}
for i = 1, N do
	local readed = read("*n")
	if have_types_s[readed] then
		local index = have_types_s[readed]
		number_of_types[index] = number_of_types[index] + 1
	else
		local new_index = #number_of_types + 1
		have_types_s[readed] = new_index
		number_of_types[new_index] = 1
	end
end

table.sort(number_of_types)

local out = 0
for i = 1, #number_of_types - K do
	out = out + number_of_types[i]
end

print(out)


Measured memory_bytes: 6988
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    A,B,C = map(int, sys.stdin.readline().split())

    if B > A*C:
        print(C)
    else:
        if B>=A:
            print(B//A)
        else:
            print(0)

Measured memory_bytes: 5072
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000

int S[MAX];
int top=0;

void initialize(){
   top = 0;
 }

int isEmpty(){
   if(top==0)return 0;
   return -1;
}
 int isFull(){
   if(top>=MAX)return 0;
   return -1;
}

 void push(int x){
   if(isFull()==0){
     fprintf(stderr,"Push ERROR\n");
     exit(1);
   }
   top++;
   S[top] = x;
}

int pop(){
    if (isEmpty()==0){
      fprintf(stderr,"Pop ERROR\n");
      exit(2);
    }
      top--;
      return S[top+1];
}

int main(void){
  int num, Masato1, Masato2, N;
  char C[100];

  initialize();

  while(scanf("%s", C)!=EOF){

    if('1'<=C[0]&&C[0]<='9')num=1;
    else if(C[0]=='+')num=2;
    else if(C[0]=='-')num=3;
    else if(C[0]=='*')num=4;
    else {
      fprintf(stderr,"Input ERROR\n");
      exit(3);
    }
    switch(num){
      case 1:/*数字*/
      N=atoi(C);
      push(N);
      break;

      case 2:/*足し算*/
      Masato1=pop();
      Masato2=pop();
      push(Masato1+Masato2);
      break;

      case 3:/*引き算*/
      Masato2=pop();
      Masato1=pop();
      push(Masato1-Masato2);
      break;

      case 4:/*掛け算*/
      Masato1=pop();
      Masato2=pop();
      push(Masato1*Masato2);
      break;
    }
    Masato1=0;
    Masato2=0;
  }
  printf("%d\n",pop());

  return 0;
}


Measured memory_bytes: 2144
import math;

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def main():
    n = int(input())
    A = [x for x in map(int,input().split())]
    ans = A[0]
    for i in range(1,n):
        ans = gcd(ans,A[i])
    print(ans)
    return

if __name__ == '__main__':
    main()

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

int main() {
	int n;
	cin >> n;
	int F[50];
	F[0] = F[1] = 1;
	for (int i = 2; i <= n; i++) {
		F[i] = F[i - 1] + F[i - 2];
	}
	cout << F[n] << endl;

	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define f first
#define s second
 
#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)
 
#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)
 
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"
 
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;
 
const int sz= 1e5+5;
const int M = 998244353;

vi prime;

void seive(int n){
	int sqn = sqrt(n), sq2n = sqrt(sqn);

	bool isprime[sqn+1];
	memset(isprime,1,sizeof(isprime));

	for(int i=2;i<=sq2n;++i){
		if(isprime[i])
			for(int j=i<<1;j<=sqn;j+=i)
				isprime[j]=0;
	}
	for(int i=2;i<=sqn;++i)
		if(isprime[i])
			prime.pb(i);

	// finding primes in [i+1,i+sqn]; i is a multiple of sqn
	for(int i=sqn;i<n;i+=sqn){
		memset(isprime,1,sizeof(isprime));
		sq2n = sqrt(i+sqn);
		for(int p: prime){
			if(p>sq2n)
				break;
			for(int j=(i/p+1)*p;j<=i+sqn;j+=p)
				isprime[j-i]=0;
		}
		for(int j=1;j<=sqn;++j)
			if(isprime[j])
				prime.pb(j+i);
	}
}

ll pow_mod(ll base, ll pow){
	ll ans = 1;
	while(pow){
		if(pow&1)
			ans = ans*base%M;
		base = base*base%M;
		pow>>=1;
	}
	return ans;
}

ll fac[200005];
ll inv_fac[200005];

void factorial(int n){
	fac[0] = fac[1] = 1;
	for(int i=2;i<=n;++i)
		fac[i] = fac[i-1]*i%M;

	inv_fac[n] = pow_mod(fac[n],M-2);
	for(int i=n-1;i>=0;--i){
		inv_fac[i] = inv_fac[i+1]*(i+1)%M;
	}
}

ll multinomial(vi& list){
	ll sum = 0, ans = 1;
	for(int i=0;i<list.size();++i){
		sum+=list[i];
		ans = ans*inv_fac[list[i]]%M;
	}
	ans = ans*fac[sum]%M;
	return ans;
}

//----------------------------------------------


int main() {
	ll a;
	string b;
	cin>>a>>b;
	b.erase(b.end()-3);
	ll c = stoi(b);
	cout<<a*c/100;










	return 0;
}

Measured memory_bytes: 3724
N,M=map(int,input().split())
a=0
if N-M==1:
    t=1
    for i in range(1,M+1):
        t=t*i%(10**9+7)
    a=t**2*N%(10**9+7)
elif M-N==1:
    t=1
    for i in range(1,N+1):
        t=t*i%(10**9+7)
    a=t**2*M%(10**9+7)
elif M==N:
    t=1
    for i in range(1,N+1):
        t=t*i%(10**9+7)
    a=2*t**2%(10**9+7)
print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,n;
ll getans(ll a,ll b,ll x)
{
    return a*x/b-a*(x/b);
}
int main()
{
    cin>>a>>b>>n;
    if(n<b) printf("%lld\n",getans(a,b,n));
    else printf("%lld\n",getans(a,b,b-1));
}


Measured memory_bytes: 3760
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

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

signed main()
{
    fastio;
    int n;
    cin>>n;
    int a[n];
    int minn=-1;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<minn)ans+=abs(minn-a[i]);
        if(i!=0 && a[i]>minn)
        {
            
            minn=max(a[i],minn);
        }
        else if(a[i]>minn)
        {
            minn=max(a[i],minn);
        }

        //cout<<ans<<" "<<minn<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5200
#include <iostream>

int main()
{
    uint64_t a, b, c, d, e, n;
    std::cin >> n >> a >> b >> c >> d >> e;
    uint64_t min = std::min(a, b);
    min = std::min(min, c);
    min = std::min(min, d);
    min = std::min(min, e);

    uint64_t time = 0;
    if (min >= n) time = 1;
    else if (n % min == 0) time = n / min;
    else time = n / min + 1;
    time += 4;

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


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

int main() {
    int n;cin>>n;
    //月曜土曜素数列挙
    vector<int> smPrimes;
    for(int i=0; i<300000/7; i++){
        for(int p : {1, 6}){
            p = p + 7*i;
            if(p == 1) continue;
            bool flag = false;
            for(int a : smPrimes){
                if(p%a == 0){
                    flag = true;
                    break;
                }
                if(a > sqrt(p)) break;
            }
            if(!flag){
                smPrimes.push_back(p);
            }
        }
    }
    while(n != 1){
        string ans = to_string(n) + ":";
        for(int i=0; i<smPrimes.size(); i++){
            if(n%smPrimes[i] == 0){
                ans += " " + to_string(smPrimes[i]);
            }
        }
        cout << ans << endl;
        cin>>n;
    }
}



Measured memory_bytes: 3256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    vll a(k);
    REP(i,k) cin >> a[i];
    ll mx = 2;
    ll mn = 2;
    for(ll i=k-1;i>=0;--i){
        ll x = ((mn-1)/a[i]+1)*a[i];
        if(x>mx){
            cout << -1  << endl;
            return 0;
        }
        ll y = (mx/a[i])*a[i];
        if(y<mn){
            cout << -1 << endl;
            return 0;
        }
        mx = y+a[i]-1;
        mn = x;
    }
    cout << mn << " " << mx << endl;

    return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (a >= b) {
    cout << "delicious" << endl;
  }
  else if (a + x >= b) {
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int i,j,k,m,n;
int b[N];
double a[N],ans;
int f(int y)
{
	for(j=0;j<=20;j++)
	{
		if(b[j]*y>=k) break;
	}
	return j;
}
int main()
{
	scanf("%d%d",&n,&k);
	a[0]=1.00;
	b[0]=1;
	for(int i=1;i<=20;i++) a[i]=a[i-1]/2;
	for(int i=1;i<=20;i++) b[i]=b[i-1]*2;
	for(int i=1;i<=n;i++)
	{
		int x=f(i);
		ans=ans+((double)(1.00/(double)n))*a[x];
	}
	printf("%.12f",ans);
	return 0;
}

Measured memory_bytes: 2304
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}
 
fn main() {
    let r = get_line().parse::<f64>().unwrap();
 
    println!("{}", 2. * r * std::f64::consts::PI);
}

Measured memory_bytes: 2212
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;



int main(){
  int n; cin>>n;
  vector<string> v;
  for(int i=0;i<n;i++){
    string tmp;
    cin>>tmp;
    sort(tmp.begin(),tmp.end());
    v.push_back(tmp);
  }
  long long cur=1;
  string cst;
  sort(v.begin(),v.end());
  cst=v[0];
  long long ans=0;
  for(int i=1;i<n;i++){
    if(v[i-1]==v[i]){
      cur++;
    }
    else{
      ans+=cur*(cur-1)/2;
      cur=1;
    }
  }
  ans+=cur*(cur-1)/2;
  cout<<ans<<endl;

}


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

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
	fast();
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> green(a), red(b), color(c + x + y);
	
	for(int i = 0; i < a; ++i){
		cin >> green[i];
	}
	for(int i = 0; i < b; ++i){
		cin >> red[i];
	}
	for(int i = 0; i < c; ++i){
		cin >> color[i];
	}
	sort(green.begin(), green.end());
	sort(red.begin(), red.end());
	int j = c;
	int lef = green.size() - 1, rr = green.size() - x;
	for(int i  = lef; i >= rr; --i){
		color[j++] = green[i];
	}
	int l = red.size() - 1, r = red.size() - y;
	//cout << l << r;
	for(int i  = l; i >= r; --i){
		color[j++] = red[i];
	}
	//cout <<"llll";
	sort(color.begin(), color.end());
	ll ans = 0;
	for(int i = color.size() - 1; i >= color.size() - x - y; --i){
		ans += (ll)color[i];
	}
	cout << ans <<"\n";
}			

Measured memory_bytes: 2176
#include<stdio.h>
#define N 100000
#define Q 50000

int S[N],a;
int binarySearch( int );


int binarySearch( int key ){
  
  int left = 0,right,mid;
  
  right = a ;

  while( left < right ){
    mid = ( left + right )/2;
    if( S[mid] == key )
      return 1;
    else if( S[mid] < key )
      left = mid + 1;
    else if( S[mid] > key )
      right = mid;
	}
  return 0;
}

main(){
  int T[Q],b,count=0,i;
  
  scanf("%d",&a);
  for( i =0 ; i < a ; i++ )
    scanf("%d",&S[i]);
  scanf("%d",&b);
  for( i = 0 ; i < b ; i++ ){
    scanf("%d",&T[i]);
    count += binarySearch(T[i]);
      }

  printf("%d\n",count);

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int r = N % 2;
  int res = N / 2;
  
  if (r == 0) {
    cout << res << endl;
  } else {
    cout << res + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3640
import sys
import itertools
if sys.platform =='win32':
	sys.stdin=open('input.txt')
input = sys.stdin.readline
def MAP(): return [int(x) for x in input().split()]


N, M = MAP()
G = [[] for _ in range(N)]
for i in range(M):
	a,b = MAP()
	G[a-1].append(b-1)
	G[b-1].append(a-1)

permutations = (list(itertools.permutations(range(len(G)))))

paths = [p for p in permutations if p[0]==0]

count = 0
for path in paths:
	#print(path)
	for idx,v in enumerate(path):
		if idx == len(path)-1:
			count+=1
			break
		if path[idx+1] in G[v]: continue
		else: break

print(count)

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int value[128];
vector<string> strs;
int ans = 0;
bool leading[128];
bool used[10];
int to_num(const string &s) {
  int res = 0;
  for(const auto &c : s) {
	res = res * 10 + value[c];
  }
  return res;
}

void dfs(int keta,int tate,int sum){
  if(keta == -1){
	ans++;
/*	for(const auto &s : strs) {
	  cout << to_num(s) << endl;
	}
	cout << endl;
*/	
	return ;
  }
  char m = strs[tate][keta];
  if(tate == n-1){
	
	if(value[m] == -1){
	  if(sum%10 == 0 && leading[m] || used[sum%10])return ;
	  value[m] = sum%10;
	  used[sum%10] = true;
	  dfs(keta-1,0,sum/10);
	  used[sum%10] = false;
	  value[m] = -1;
	  
	}
	
	else if(value[m] == sum%10){
		dfs(keta-1,0,sum/10);
	}
	
	return ;
  }
  if(value[m] != -1){
	dfs(keta,tate+1,sum+value[m]);
  }else{
	for(int i = leading[m]? 1:0;i < 10;i++){
	  if(used[i])continue;
	  used[i] = true;
	  value[m] = i;
	  dfs(keta,tate+1,sum+value[m]);
	  used[i] = false;
	}
	value[m] = -1;
  }
  
}
int main(){
  while(cin >> n && n){
	fill(begin(value),end(value),-1);
	fill(begin(leading),end(leading),false);
	fill(begin(used),end(used),false);
	ans = 0;
	strs.clear();
	value['#'] = 0;
	for(int i = 0;i < n;i++){
	  string tmp;
	  cin >> tmp;
	  if(tmp.size() > 1){
		leading[tmp[0]] = true;
	  }
	  strs.emplace_back((string(8,'#')+tmp).substr(tmp.size()));
	}
	dfs(7,0,0);
	cout << ans << endl;
  }
  
  
   
  return 0;
}

Measured memory_bytes: 1220
local MOD=2019
local function add(a,b)return (a+b)%MOD end
local function sub(a,b)return (a-b)%MOD end
local function mul_(a,b)
	local ret=0
	while(b>0)do
		if(b%2==1)then ret=(ret+a)%MOD end
		a=(a+a)%MOD
		b=math.floor(b*.5)
	end
	return ret
end
local function mul(a,b)
	return a<b and mul_(b,a)or mul_(a,b)
end
local function pow(a,b)
	local ret=1
	while(b>0)do
		if(b%2==1)then ret=mul(ret,a)end
		a=mul(a,a)
		b=math.floor(b*.5)
	end
	return ret
end
local function inv(x)
	local a=x
	local b,u,v=MOD,1,0
	repeat
		local t=math.floor(a/b)
		a,b=b,a-t*b
		u,v=v,u-t*v
	until(b==0)
	return u%MOD
end
local function div(a,b)return mul(a,inv(b))end
t={}
s={0}
while 1 do
	local a=io.read(1)
	if not(a)then break end
	table.insert(t,tonumber(a))
	table.insert(s,s[#s]+t[#t])
end
N=#t

dp={[0]=0}
a={[0]=1}
for i=1,N do
	dp[i]=add(dp[i-1],mul(t[N-i+1],pow(10,i-1)))
	if(a[dp[i]])then
		a[dp[i]]=a[dp[i]]+1
	else
		a[dp[i]]=1
	end
end
c=0
for _,v in pairs(a)do
	c=c+v*(v-1)/2
end
print(c)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  int ans = 0;
  int before = a[0];
  int tmp = 1;
  REP(i, N) {
    if (i == 0) continue;
    if (before == a[i])
      tmp++;
    else {
      ans += tmp / 2;
      tmp = 1;
    }
    before = a[i];
  }
  ans += tmp / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    string s;
    cin>>n>>s;
    int ans = 0;
    int c= 0;
    for(auto x : s)
        if(x=='R')
            c++;
    for (int i = 0; i < c; ++i)
    {
        if(s[i]=='W')
            ans++;
    }
    cout<<ans;
    printclock;
    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  int b;
  int c;
  
  cin >> a;
  cin >> b;
  cin >> c;
  
  int x;
  x = a;
  a = b;
  b = x;
  
  x = a;
  a = c;
  c = x;
  
  cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<iomanip>
#include <string>
#include<math.h>
using namespace std;
int main() {
	string str;
	cin >> str;
	if ((str[2] == str[3]) && (str[4] == str[5]))
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int a[100001]={};

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a[x]++;
  }
  int two=0,sum=0;
  for(int i=1;i<=100000;i++){
    if(a[i]>=2){
      if(a[i]%2){
        a[i]=1;
      }else{
        a[i]=2;
        two++;
      }
    }
    sum+=a[i];
  }
  //cout<<sum<<" "<<two<<endl;
  if(two%2){
    sum-=(two-1)+2;
  }else{
    sum-=two;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios::sync_with_stdio(0);cin.tie(0);


int main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int N; cin>>N;
    map<string, int> m;
    while (N--)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
    return 0;

}

Measured memory_bytes: 3672
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

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

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

int vals[4];

void init()
{
}

void solve()
{
    int ans;
    REP(i, 1<<3){
        int sum = vals[0];
        REP(j, 3){
            int b = (i>>j)&1;
            sum += b == 1 ? vals[j+1] : -vals[j+1];
        }
        if(sum == 7){
            ans = i;
            break;
        }
    }
    REP(i, 3){
        int b = (ans>>i)&1;
        cout << vals[i] << (b == 1 ? '+' : '-');
    }
    cout << vals[3] << "=7" << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    REP(i, 4) vals[i] = s[i] - '0';
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define		int 			long long int
#define		pb				push_back
#define		fi(n)			for(int i=0;i<n;i++)
#define		fi1(n)			for(int i=1;i<n;i++)
#define		fj(n)			for(int j=0;j<n;j++)
#define		rep(z,a,n)		for(z=a;z<n;z++)
#define		rep2(z,a,n)		for(z=a;z<n;z+=2)
#define		clr(x)			memset(x, 0, sizeof(x))
#define		print(x,n)		for(int i=0;i<n;i++) cout<<x[i]<<" ";  cout<<"\n"
#define		nl 				"\n"
#define		vi				vector<int>
#define		mp 				make_pair
#define		pairi			pair<int,int>
#define		vpairi			vector<pair<int,int>>
#define		ff				first
#define		ss				second
#define		inf 			2e18
#define 	input 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt"
#define 	output 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt"
#define 	error 			"C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt"

int ctoi(char a){ int x=a-48;return x;}
string itos(int a){
	string out_string;
	stringstream ss;
	ss<<a;
	out_string=ss.str();
	return out_string;
}
char itoc(int a){ return itos(a)[0];}
int pow(int e,int x){
	int ans=1;
	while(x>0){
		if(x&1) ans*=e;
		e*=e;
		x>>=1;
	}return ans;
}
string bin(int x){
	bitset<sizeof(1)*CHAR_BIT> bits(x);
	string b=bits.to_string(); return b;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	#endif
	int T=1;
	// cin>>T;
	while(T--){
		int n,k,m,x,y;
		cin>>n>>m;
		// int a[n];clr(a);
		int a[n][m];clr(a);
		char c[n][m];
		fi(n){
			fj(m) cin>>c[i][j];
		}
		fi(n){
			fj(m){
				if(i==0 && j==0){
					a[i][j]=1;
				}
				else if(i==0){
					if(c[i][j]=='.') a[i][j]=a[i][j-1];
				}
				else if(j==0){
					if(c[i][j]=='.') a[i][j]=a[i-1][j];
				}
				else{
					if(c[i][j]=='.') a[i][j]=(a[i-1][j]+a[i][j-1])%1000000007;
				}
			}
		}
		cout<<a[n-1][m-1]<<nl;

	}
	return 0;
}


Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, k;
  scanf("%d %d", &n, &k);

  char s[51];
  scanf("%s", s);

  switch (s[k - 1])
  {
  case 'A':
    s[k - 1] = 'a';
    break;
  case 'B':
    s[k - 1] = 'b';
    break;
  case 'C':
    s[k - 1] = 'c';
    break;
  default:
    break;
  }
  printf("%s\n", s);
  return 0;
}


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

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int d[n];
	d[0]=0;
	d[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		int min=abs(a[i]-a[i-1])+d[i-1];
		int ind=i-1;
		for(int j=i-2;j>i-k-1 && j>-1;j--)
		{
			if(abs(a[i]-a[j])+d[j]<min)
			{
			ind=j;
			min=abs(a[i]-a[j])+d[j];}
		}
		d[i]=min;
	}
	cout<<d[n-1];
	
}

Measured memory_bytes: 1024
#include<stdio.h>

void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}

int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};

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

    rep(i,n-1){
        a[i+1] = __gcd(a[i],a[i+1]);
    }
     cout << a[n-1] << endl;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

n, m = map(int, input().split())

# print(n)
# print(m)

count = 0
for i in range(n + m):
    for j in range(n + m):
        if i == j:
            continue
        # print("{} {}".format(i, j))
        
        if i < n and j < n:
            count += 1
        if i >= n and j >= n:
            count += 1
        
# print(count)
print(count // 2)

Measured memory_bytes: 3060
from typing import List


class RollingHash:
    """Rolling Hash"""

    __slots__ = ["_source", "_length", "_base", "_mod", "_hash", "_power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self._source = source
        self._length = len(source)
        self._base = base
        self._mod = mod
        self._hash = self._build_hash_from_zero()
        self._power = self._build_base_power()

    def _build_hash_from_zero(self) -> List[int]:
        """Compute hash of interval [0, right)."""
        res = [0] * (self._length + 1)
        for i, c in enumerate(self._source, 1):
            res[i] = (res[i - 1] * self._base + ord(c)) % self._mod
        return res

    def _build_base_power(self) -> List[int]:
        """Compute mod of power of base."""
        res = [1] * (self._length + 1)
        for i in range(1, self._length + 1):
            res[i] = res[i - 1] * self._base % self._mod
        return res

    def get_hash(self, left: int, right: int):
        """Return hash of interval [left, right)."""
        return (
            self._hash[right] - self._hash[left] * self._power[right - left]
        ) % self._mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()
    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


Measured memory_bytes: 11368
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll p[212335];
ll mod=998244353;

ll modinv(ll a, ll m){
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u%=m;
    if(u<0){ u+=m; }
    return u;
}

ll modC(ll n, ll k){
    const ll L=1e6;
    static ll fact[L], rfact[L];
    if(k==0) return 1;
    if(fact[0]==0){
        fact[0]=1;
        REP(i,1,L){                                                     
            fact[i]=(i*fact[i-1])%mod;
        }
    }
    return ((fact[n]*modinv(fact[n-k],mod))%mod*modinv(fact[k],mod))%mod;
}

int main(){
    ll N=ii(),M=ii(),K=ii();
    p[1]=M;
    REP(i,2,N+1){
        p[i]=p[i-1]*(M-1);
        p[i]%=mod;
    }
    ll ret=p[N];

    REP(i,1,K+1){
        ll c=modC(N-1,i);
        ret+=(p[N-i]*modC(N-1,i))%mod;
        ret%=mod;
    }
    oie(ret);

    return 0;
}


Measured memory_bytes: 12992
#include <bits/stdc++.h>
using namespace std;
const int inf = (int) 1e9;
int main(){
  int K,T;
  cin>>K>>T;
  vector<int> a(T,0);
  int maxa=-1;
  for(int i=0;i<T;i++){
    cin>>a[i];
    maxa=max(maxa,a[i]);
  }
  int res=0;
  if(K%2==0){
    res=(maxa-(K/2))*2-1;
  }else{
    res=(maxa-((K+1)/2))*2;
  }
  res=max(0,res);
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
INF = float('inf')
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] * (N+1)
b = [0] * (M+1)
for i,x in enumerate(A):
    a[i+1] = a[i] + x

for i,x in enumerate(B):
    b[i+1] = b[i] + x

ans = 0
j = M
for i, va in enumerate(a):
    if va > K:
        break
    while va + b[j] > K:
        #print(va, b[j], ans)
        j -= 1
        if j < 0:
            break
    ans = max(i+j, ans)
print(ans)


Measured memory_bytes: 48528
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int q = sc.nextInt();
			int[] A = new int[q];
			int head=0,foot=0;
			for(int i=0;i<q;i++) {
				int query = sc.nextInt();
				if(query==0) {
					switch(sc.nextInt()) {
					case 0:
						head--;
						A[(head+q)%q] = sc.nextInt();
						break;
					case 1:
						A[(foot+q)%q] = sc.nextInt();
						foot++;
						break;
					}
				}
				else if(query==1) {
					System.out.println(A[(head+sc.nextInt()+q)%q]);
				}
				else if(query==2) {
					switch(sc.nextInt()) {
					case 0:
						head++;
						break;
					case 1:
						foot--;
						break;
					}
				}
			}
		}
	}
}


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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-10;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

ll n;
void solve() {
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i * i <= n - 1; ++i) {
        if (i * i == n - 1) ++ans;
        else if ((n - 1) % i == 0) ans += 2;
    }
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i != 0) continue;
        ll now = n;
        while (now % i == 0) now /= i;
        if (now % i == 1) ++ans;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
// ???????????????
#include<vector>
#include<tuple>
#include<algorithm>
// ???
typedef int Weight;
// ?????????
class Tree {
public:
  explicit Tree(int n);
  int size() const;
  void join(int u, int v, Weight w);
  Weight diameter() const;
  Weight height(int root) const;
  const std::vector<Weight> height() const;
  Weight height_dfs(int u, int v, std::vector<std::vector<Weight>>& cost) const;
private:
  struct Edge {int from, to; Weight weight;};
  struct Farthest {int vertex; Weight cost;};
  const Farthest farthest(int current, int previous) const;
  std::vector<std::vector<Edge>> edge_;
};
// ?????????????????????
Tree::Tree(int n) : edge_(n) {}
// ????????°
int Tree::size() const {return edge_.size();}
// ????????????
void Tree::join(int u, int v, Weight w) {
  edge_[u].push_back({u, v, w});
  edge_[v].push_back({v, u, w});
}
// ???????????¨?????¢
const Tree::Farthest Tree::farthest(int current, int previous) const {
  Farthest result({current, 0});
  for(const auto& e: edge_[current]) {
    if(e.to == previous) continue;
    auto f = farthest(e.to, e.from);
    f.cost += e.weight;
    if(result.cost < f.cost) result = f;
  }
  return result;
}
// ??´???
Weight Tree::diameter() const {
  int v = farthest(0, 0).vertex;
  return farthest(v, v).cost;
}
// ?????????????????????????????§????????¢
//   ?????????farthest????????¢???????????¨????????????
Weight Tree::height(int root) const {return farthest(root, root).cost;}
// ?????????????????????????????§????????¢
//   memo[v][e]: ??????v?????????e????????£?????¨????????????????????§????????¢
const std::vector<Weight> Tree::height() const {
  std::vector<std::vector<Weight>> memo(size());
  for(int v = 0; v < size(); ++v) for(int e = 0; e < edge_[v].size(); ++e) memo[v].push_back(-1);
  for(int v = 0; v < size(); ++v) for(int e = 0; e < edge_[v].size(); ++e) if(memo[v][e] == -1) height_dfs(v, e, memo);
  std::vector<Weight> result(size(), 0);
  for(int v = 0; v < size(); ++v) for(int e = 0; e < edge_[v].size(); ++e) result[v] = std::max(result[v], memo[v][e]);
  return result;
}
Weight Tree::height_dfs(int v, int e, std::vector<std::vector<Weight>>& memo) const {
  if(memo[v][e] != -1) return memo[v][e];
  memo[v][e] = edge_[v][e].weight;
  int next_v = edge_[v][e].to;
  for(int next_e = 0; next_e < edge_[next_v].size(); ++next_e)
    if(edge_[next_v][next_e].to != v)
      memo[v][e] = std::max(memo[v][e], edge_[v][e].weight + height_dfs(next_v, next_e, memo));
  return memo[v][e];
}

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

int main() {
  int n;
  cin >> n;
  Tree t(n);
  for(int i = 0; i < n - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    t.join(u, v, w);
  }
  for(const auto& i: t.height()) cout << i << endl;
}

Measured memory_bytes: 3372
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//---------------------------------------------------
int n;
int a[200000];
int dp[6000000][30];
//dp[i][j]=iを含む数字かつj桁目以上が一致しているものの個数
int c[3000000];
signed main() {
	cin >> n;
	int res = 0;
	int mx = 0;
	c[0] = 1;
	rep(i, n) {
		cin >> a[i];
		dp[a[i]][0]++;
		mx = max(mx, a[i]);
	}
	for (int i = 1; i < 3000000; i++) {
		c[i] = c[i - 1] * 2 % mod;
	}
	rep(j, 21) {
		for (int i = 2000000; i > 0; i--) {
			if (!(i & (1 << j))) {
				dp[i][j + 1] = dp[i][j] + dp[i | (1 << j)][j];
			}
			else {
				dp[i][j + 1] = dp[i][j];
			}
		}
	}
	int ans = c[n];
	for (int i = 1; i < 2000000 ; i++) {
		if (bitcount(i) % 2 == 0) {
			ans += c[dp[i][21]];
		}
		else {
			ans -= c[dp[i][21]];
		}
		ans %= mod;
	}
	cout << (ans + mod) % mod << endl;
}


Measured memory_bytes: 496076
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    min_A = A[0]
    diff = []
    for a in A[1:]:
        diff.append(a - min_A)
        min_A = min(a, min_A)

    print(max(diff))


if __name__ == '__main__':
    main()



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

int main(){
    
    int N, count = 0, count_a = 0;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if (A[i] % 2 == 0){
            count++;
            if (A[i] % 3 == 0 || A[i] % 5 == 0) count_a++;
        }
    }
    
    if (count == count_a) printf("APPROVED");
    else printf("DENIED");
    
    return 0;
    
}

Measured memory_bytes: 256