akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s; cout<<s.substr(0,s.size()-8)<<"\n";
	return 0;
}

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

int main(){
  long N;
  int S=0;
  cin >> N;
  for(int i=0; i<=9; i++){
    S+= (N/(long)pow(10,i))%10;
  }
  if(N%S==0){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;
long long n,s,w[1005],v[1005],f[1005][100005];
int main()
    {
        cin>>n>>s;
        for (long i=1;i<=n;i++) cin>>w[i]>>v[i];
        for (long i=1;i<=n;i++)
        {
            for (long j=1;j<=s;j++)
            {
                if (j-w[i]>=0)
                {
                    f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]);
                }
                else
                {
                    f[i][j]=f[i-1][j];
                }
            }
        }
        cout<<f[n][s];
        return 0;
    }

Measured memory_bytes: 79360
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
using ll = long long;

int n;
long long a[1010];

ll poss[2]; // sum of positive elements ( odd , even )

void all_nega(){
  int MAX = -INT_MAX;
  int maxpos = -1;
  rep(i,n){
    if(a[i] > MAX) MAX = a[i],maxpos = i;
  }
  cout << MAX << '\n';
  cout << n - 1 << '\n';
  for(int i = n - 1;i > maxpos;i--)cout << i + 1 << '\n';
  for(int i = 0;i < maxpos;i++)cout << 1 << '\n';
}

int main(void){
  
  scanf("%d",&n);
  rep(i,n){
    scanf("%lld",&a[i]);
    poss[i%2] += max(a[i],0LL);
  }
  
  if(max(poss[0],poss[1]) == 0){
    all_nega();
    return 0;
  }
  
  int odd = (poss[1] >= poss[0]);
  
  vector<int> left;
  
  rep(i,n){
    if(i % 2 == odd && a[i] > 0) left.push_back(i);
  }
  
  vector<int> ans;
  
  for(int i = n - 1;i > left.back();i--) ans.push_back(i);
  for(int i = 0;i < left[0];i++) ans.push_back(0);
  
  for(int i = 0;i < left.size() - 1;i++){
    for(int j = 0;j < (left[i+1] - left[i] - 1) / 2;j++){
      ans.push_back(2);
    }
    ans.push_back(1);
  }
  
  cout << poss[odd] << '\n';
  cout << ans.size() << '\n';
  rep(i,ans.size())cout << ans[i] + 1 << '\n';
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

int main(){
	string O, E;
	cin >> O >> E;

	rep(i, (int)(E.size())){
		cout << O.at(i) << E.at(i);
	}
	if (O.size() > E.size()) cout << O.at(O.size() - 1);
	cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#include<climits>
#include<sstream>
using namespace std;

#define maxn 200010
struct ST{//返回[L,R]区间最小值的索引
    int n,a[maxn],st[maxn][30];
    void init(int n,int data[]){
        int i,j,l,r;
        for(i=0;i<n;i++) a[i]=data[i];
        memset(st,0,sizeof st);
        for(i=0;i<n;i++) st[i][0]=i;
        for(j=1;(1<<j)<=n;j++)
            for(i=0;i+(1<<j)-1<n;i++){
                st[i][j]=a[st[i][j-1]]<a[st[i+(1<<(j-1))][j-1]]?st[i][j-1]:st[i+(1<<(j-1))][j-1];
        }
    }
    int query(int l,int r){
        int k=(int)(log(r-l+1)/log(2.0));
        return a[st[l][k]]<a[st[r-(1<<k)+1][k]]?st[l][k]:st[r-(1<<k)+1][k];
    }
};

vector<vector<int> > g;
int h[maxn],dfn[maxn],depth[maxn],low[maxn];
int cnt=0;
void dfs(int deep,int x){
    dfn[cnt]=x;depth[cnt++]=deep;
    for(int i=0;i<g[x].size();i++){
        int y=g[x][i];
        if(h[y]==0){
            h[y]=1;
            dfs(deep+1,y);
            dfn[cnt]=x;depth[cnt++]=deep;
        }
    }
}
int n,q;
ST st;
int main(){

    int i,j,k,x,l,r;
    cin>>n;
    for(i=0;i<n;i++){//占位
        vector<int> tmp;
        g.push_back(tmp);
    }
    for(i=0;i<n;i++){
        cin>>k;
        for(j=0;j<k;j++){
            cin>>x;
            g[i].push_back(x);
        }
    }
    memset(h,0,sizeof h);
    memset(dfn,0,sizeof dfn);
    memset(depth,0,sizeof depth);
    memset(low,-1,sizeof low);
    dfs(0,0);
    for(i=0;i<2*n;i++)
        if(low[dfn[i]]==-1)
            low[dfn[i]]=i;


    st.init(2*n-1,depth);
    cin>>q;
    for(i=0;i<q;i++){
        cin>>l>>r;
        cout<<dfn[st.query(min(low[l],low[r]),max(low[l],low[r]))]<<endl;
    }
    return 0;
}



Measured memory_bytes: 40116
// I think of what the world could be, A vision of the one I see, A million dreams is all it's gonna take

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

int a[maxn], b[maxn];
    
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n, m, q;
    cin >> n >> m >> q;
    int mn1 = inf, mn2 = inf;
    for(int i = 0; i < n; i++){
	cin >> a[i];
	mn1 = min(mn1, a[i]);
    }
    for(int i = 0; i < m; i++){
	cin >> b[i];
	mn2 = min(mn2, b[i]);
    }
    int ans = mn1 + mn2;
    while(q--){
	int x, y, z;
	cin >> x >> y >> z;
	ans = min(ans, a[--x] + b[--y] - z);
    }
    return cout << ans << endl, 0;
}


Measured memory_bytes: 1024
use std::io::Read;

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

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: u32 = iterator.next().unwrap().parse().unwrap();
    let s: Vec<char> = iterator.next().unwrap().chars().collect();
    let mut result = String::new();
    for c in s {
        let mut u = c as u32 + n;
        if u > 'Z' as u32 {
            u = 'A' as u32 + u - 'Z' as u32 - 1;
        }
        result.push(std::char::from_u32(u).unwrap());
    }
    return result;
}


Measured memory_bytes: 4352
from fractions import gcd
 
 
def solve(n, m, s, t):
    g = gcd(n, m)
    ng = n // g
    mg = m // g
 
    for h in range(g):
        if s[ng * h] != t[mg * h]:
            return -1
    return ng * mg * g
 
 
n, m = list(map(int, input().split()))
s = input()
t = input()
print(solve(n, m, s, t))

Measured memory_bytes: 5432
S = input()
stack = []
stack.append(S[0])
for i in range(1, len(S)):
    if len(stack) == 0:
        stack.append(S[i])
        continue
    cube = stack.pop()
    if cube != S[i]:
        continue
    stack.append(cube)
    stack.append(S[i])
print(len(S) - len(stack))


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

int main() {
  vector<int> c(9);
  for(int i=0;i<9;i++){
    cin>>c.at(i);
  }
  bool ans=true;
  if(c.at(0)+c.at(4)!=c.at(1)+c.at(3))
    ans=false;
  if(c.at(1)+c.at(5)!=c.at(2)+c.at(4))
    ans=false;
  if(c.at(3)+c.at(7)!=c.at(4)+c.at(6))
    ans=false;
  if(c.at(4)+c.at(8)!=c.at(5)+c.at(7))
    ans=false;
  
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3604
def fac(n):  #nは2以上
    a=[]
    t=n
    if t%2==0:
        count=0
        while t%2==0:
            count+=1
            t//=2
        a.append([2,count])

    for i in range(3,n+1,2):
        if i*i>n:
            break
        if t%i==0:
            count=0
            while t%i==0:
                count+=1
                t//=i
            a.append([i,count])

    if t!=1:
        a.append([t,1])
    
    return a


from sys import stdin
def main():
    #入力
    readline=stdin.readline
    mod=10**9+7
    n=int(readline())

    d=dict()
    for i in range(1,n+1):
        tmp=fac(i)
        for j in range(len(tmp)):
            if tmp[j][0] not in d:
                d[tmp[j][0]]=tmp[j][1]
            else:
                d[tmp[j][0]]+=tmp[j][1]

    ans=1
    for v in d.values():
        ans*=(v+1)
        ans%=mod

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n; ll a; ll sum[200001];
	cin >> n;
	int i;
	sum[0] = 0;
	for (i = 0; i < n; i++) {
		cin >> a; sum[i+1] = sum[i] + a;
	}
	sort(sum, sum + n+1);
	ll out = 0;
	for (i = 0; i < n+1; i++) {
		ll memo = sum[i];
		ll j = 1;
		while (i+1<n+1&&memo == sum[i+1]) {
			i++; j++;
		}
		out += j * (j - 1) / 2;
	}
	cout << out << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;


int n;
vector<vector<ll>> edges, dp;

ll add(ll a, ll b){
    return (a + b) % mod;
}

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

void dfs(int u, int p){
    ll r1 = 1, r2 = 1;
    for(auto v : edges[u]){
        if(v == p) continue;
        dfs(v, u);
        r1 = mul(r1, add(dp[v][0], dp[v][1]));
        r2 = mul(r2, dp[v][1]);
    }
    dp[u][1] = r1, dp[u][0] = r2;
}

int main(){
    cin>>n;
    edges.resize(n+1);
    for(int i = 0; i < n - 1; i++){
        int u, v; cin>>u>>v;
        edges[u-1].push_back(v-1);
        edges[v-1].push_back(u-1);
    }
    dp.resize(n, vector<ll>(2));
    dfs(0, -1);
    ll res = add(dp[0][0], dp[0][1]);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 19584
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int p[10000];
bool isPrime[1000000];
 
int main(void){
  int pnum=0;
  //但多
  fill(isPrime,isPrime+1000000,true);
  for(int i=2;pnum<10000;i++){
     if(isPrime[i] == true){
      p[pnum++] = i;
      for(int j=2;i*j<1000000;j++){
	isPrime[i*j] = false;
      }
    }
  }
 
  int tmp;
  while(cin >> tmp){
    int ret=0;
    if(!tmp) break;
    for(int i=0;i<tmp;i++) ret+=p[i];
    cout << ret << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A>> B;
 
  if(B/K-A/K > 0)
    cout << "OK" << endl;
  
  else if(B%K == 0 || A%K == 0)
    cout << "OK" << endl;
      
    
  else {
    cout << "NG" << endl;
  }
}


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

std::vector<char>::const_iterator CheckStones(const std::vector<char> &stones, int firstWhiteIndex)
{
    if (firstWhiteIndex >= stones.size())
    {   // 白石が無いので、OK
        return stones.end();
    }

    // 白石より後に赤石があるとダメ
    return std::find(stones.begin() + firstWhiteIndex + 1, stones.end(), 'R');
}

int FindStone(const std::vector<char>& stones, char color, int offset)
{
    for (auto index = offset; index < stones.size(); ++index)
    {
        if (stones[index] == color)
        {
            return index;
        }
    }

    return stones.size();
}

int FindRed(const std::vector<char>& stones, int offset, int firstWhiteIndex)
{
    for (auto index = offset; index > firstWhiteIndex; --index)
    {
        if (stones[index] == 'R')
        {
            return index;
        }
    }

    return stones.size();
}

int main()
{
    int n;
    std::cin >> n;
    std::vector<char> stones(n);

    int firstWhiteIndex = n;
    for (auto index = 0; index < n; ++index)
    {
        std::cin >> stones[index];
        if (index < firstWhiteIndex && stones[index] == 'W')
        {
            firstWhiteIndex = index;
        }
    }

    int lastRedIndex = FindRed(stones, stones.size() - 1, firstWhiteIndex);
    size_t count = 0;
    while (true)
    {
        auto redPos = CheckStones(stones, firstWhiteIndex);
        if (redPos == stones.end())
        {
            break;
        }
        // 交換できるなら交換が早い、交換すべき物がないなら色変え
        stones[firstWhiteIndex] = 'R';
        if (lastRedIndex < n)
        {
            stones[lastRedIndex] = 'W';
            lastRedIndex = FindRed(stones, lastRedIndex - 1, firstWhiteIndex);
        }

        firstWhiteIndex = FindStone(stones, 'W', firstWhiteIndex + 1);

        ++count;
    }
    
    std::cout << count;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <map>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
    bool flag = true;
    map<char,char> A, iA;
    for (int i = 0; i < S.size(); ++i) {
        char s = S[i], t = T[i];
        if (A.count(s) && A[s] != t) flag = false;
        if (iA.count(t) && iA[t] != s) flag = false;
        A[s] = t; iA[t] = s;
    }
    cout << (flag?"Yes":"No") << endl; 
}

Measured memory_bytes: 3932
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
an=10000
c=0

for i in range(n):
    if abs(a-(t-h[i]*0.006)) < an:
        an=abs(a-(t-h[i]*0.006))
        c=i+1

print(c)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	private static Main instance = new Main();
	
	private Scanner scanner = new Scanner(System.in);
	
	public static void main(String[] args) {
		instance.solve();
	}
	
	private void solve() {
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		
		long answer = (long)(k * Math.pow(k-1, n-1));
		System.out.printf("%d", answer);
	}
}


Measured memory_bytes: 9804
#include<stdio.h>
#include<string.h>
int main()
{
    char ar[1001];
    int a,b,i,c,ar1[52]={0};
    scanf("%d",&b);
    getchar();
    gets(ar);
    a=strlen(ar);
    for(i=0;i<a;i++)
    {
        c=(ar[i]-96);
        ar1[c]++;
    }
    int d=0;
    for(i=1;i<=26;i++)
    {
        if(ar1[i]%2==1)d=1;
    }
    if(d==1)printf("No\n");
    else printf("Yes\n");
    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=int64_t;

int main(){
  ll N,M; cin >>N >>M;
  ll ans=0;
  if (N*2<=M) {
    ans+=N;
    M-=N*2;
    ans+=M/4;
  } else {
    ll temp=M/2;
    N-=temp;
    if (0<N) ans+=temp;
  }
  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);std::cout<<std::fixed<<std::setprecision(10);
    int N,M;
    cin >> N >> M;
    vector<pair<int,int>> city(M);
    vector<vector<int>> Pre(N,vector<int>(0));
    REP(i,M){
        cin >> city[i].first;
        cin >> city[i].second;
        city[i].first--;
        Pre[city[i].first].push_back(city[i].second);
    }
    REP(i,N)sort(Pre[i].begin(),Pre[i].end());
    REP(i,M){
        for(int l = 0;;l++){
            if(city[i].second == Pre[city[i].first][l]){
                city[i].second = l+1;
                break;
            }
        }
    }
    vector<string> zero(6);
    zero[0] = "";
    REP(i,5)zero[i+1] = zero[i] + "0";
    REP(i,M){
        cout << zero[6 - to_string(city[i].first+1).size()];
        cout << city[i].first + 1;
        cout << zero[6 - to_string(city[i].second).size()];
        cout << city[i].second<< "\n";
    }
}

Measured memory_bytes: 7808
N = int(input())
ABCDE = []
for i in range(5):
  ABCDE.append(int(input()))

arrived_time = -(-N//ABCDE[0])
for i in range(4):
  if ABCDE[i] <= ABCDE[i+1]:
    arrived_time += 1
    ABCDE[i+1] = ABCDE[i]
  else:
    num_left = N - (arrived_time - (i+1))*ABCDE[i+1]
    arrived_time += -(-num_left//ABCDE[i+1])
    
print(arrived_time)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stack>
#include <map>

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;

    std::map<int, std::vector<std::pair<int, long int> > > tree;

    int u,v;
    long int w;
    for(int i=0; i<N-1; ++i){
        std::cin >> u >> v >> w;
        tree[u].emplace_back(std::pair<int, long int>(v,w));
        tree[v].emplace_back(std::pair<int, long int>(u,w));
    }

    std::vector<long int> distance(N,-1);
    std::stack<int> stack;
    int parent = 1;
    distance[parent-1]=0;
    stack.push(parent);
    int id;
    long int length;
    while(!stack.empty()){
        parent = stack.top();
        stack.pop();
        for(const auto &child : tree[parent]){
            id = child.first;
            length = child.second;
            if(distance[id-1]<0){
                distance[id-1] = (distance[parent-1]+length)&1;
                stack.push(id);
            }
        }
    }

    for(const auto &d : distance){
        std::cout << d << std::endl;
    }
    return 0;
}


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

using namespace std;

int main (){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a,a+3);
    
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    
    return 0;
    
 
}

Measured memory_bytes: 3136
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &e : a) cin >> e;
  sort((a).begin(), (a).end());
  ll ans = 0;
  if(n % 2 == 0) {
    for(int i = 0; i < n/2; i++) ans -= a[i]*2;
    for(int i = n/2; i < n; i++) ans += a[i]*2;
    ans += a[n/2-1];
    ans -= a[n/2];
  } else {
    ll res = 0;
    for(int i = 0; i < n/2; i++) res -= a[i]*2;
    for(int i = n/2; i < n; i++) res += a[i]*2;
    res -= a[n/2];
    res -= a[n/2+1];
    for(int i = 0; i < n/2+1; i++) ans -= a[i]*2;
    for(int i = n/2+1; i < n; i++) ans += a[i]*2;
    ans += a[n/2];
    ans += a[n/2-1];
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define R(i,a,n) for(int i=a;i<n;i++)
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int ddx[]={0,1,1,1,0,-1,-1,-1};
int ddy[]={-1,-1,0,1,1,1,0,-1};
int dp[111111];
#define pb push_back
vector<int>v;
signed main(){
  int n,c=0;
  cin>>n;
  for(int i=9;i<=100000000;i*=9){
    v.pb(i);
  }
  for(int i=6;i<=100000000;i*=6){
    v.pb(i);
  }
  v.pb(1);
  sort(v.begin(),v.end());
  for(int i=0;i<=100000;i++)dp[i]=i;
  for(int i=1;i<=18;i++){
    for(int j=1;j<=100000;j++){
      if(j-v[i]>=0)dp[j]=min(dp[j],dp[j-v[i]]+1);
    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n, mod = 1e9+7, ans = 0;
    cin >> n;
    ll a=1, b=1, c=1;
    for(int i = 0; i < n; i++){
        a = (a*10) % mod;
        b = (b*9) % mod;
        c = (c*8) % mod;
    }

    cout << ((a - b - b + c) % mod + mod) % mod << endl;
}

Measured memory_bytes: 3656
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) System.out.print(" " + i);
			else if (i % 10 == 3)  System.out.print(" " + i);
			else {
				int j = i;
				while (j > 0) {
					j /= 10;
					if (j < 3) break;
					else if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 26392
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

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

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 1e3;

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

  int N;
  cin >> N;
  ll a[N];
  REP(i, N) {
    cin >> a[i];
  }

  ll s[N];
  s[0] = a[0];
  for(int i = 1;i < N;i++) {
    s[i] = s[i-1] + a[i];
  }

  // REP(i, N) {
  //   cerr << s[i] << " ";
  // }
  // cerr << "\n";

  ll m = 1e16, d;
  for(int i = 0;i < N-1;i++) {
    d = abs(s[N-1] - s[i] * 2);
    if (d < m) m = d;
  }

  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int r, D, x; cin >> r >> D >> x;
    for (int i = 1; i < 11; ++i) {
        int x1 = r * x - D;
        cout << x1 << endl;
        x = x1;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n;
lin l[101];

int main(void)
{
    cin >> n;
    rep(i,n)
    {
        cin >> l[i];
    }

    sort(l, l+n);
    
    lin s = 0;
    rep(i, n-1)
    {
        s += l[i];
    }

    if(s <= l[n-1])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
d = []
a = []
for _ in range(k):
    d.append(int(input()))
    a.append(list(map(int, input().split())))
s = [0] * n
for ai in a:
    for i in range(len(ai)):
        s[ai[i] - 1] += 1
ans = 0
for si in s:
    if si == 0:
        ans += 1
print(ans)


Measured memory_bytes: 9136
#include<iostream>
#include<algorithm>
using namespace std;
void selectionSort()
{
    int A[100];
    int N;
    cin >> N;
 
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int m = i;
        for (int j = i + 1; j < N; j++)
        {
            if (A[m] > A[j])
            {
                m = j;
            }
        }
 
        if (m != i)
        {
            int temp = A[i];
            A[i] = A[m];
            A[m] = temp;
            ans++;
        }
    }
 
    for (int i = 0; i < N; i++)
    {
        if (i != N - 1)
        {
            cout << A[i] << " " << flush;
            continue;
        }
        else
        {
            cout << A[i] << endl;
        }
    }
 
    cout << ans << endl;
}
 
int main()
{
    selectionSort();
    return 0;
}


Measured memory_bytes: 3108
n = int(input())
a = list(map(int,input().split()))
maxim = 0
for x in a:
    maxim = max(x,maxim)
delta = a
halfFloor = maxim//2
halfCeil = halfFloor
if maxim%2 == 1:
    halfCeil += 1
delta = maxim
for x in a:
    if x == maxim:
        continue
    if x <= halfFloor:
        if halfFloor - x < delta:
            candidate = x        
            delta = halfFloor - x
    else:
        if x - halfCeil < delta:
            candidate = x
            delta = x - halfCeil
print(maxim,candidate)


Measured memory_bytes: 14060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int n,m; 
    cin >> n >> m;
    if(n < m){
        for(int i = 0; i < m; i++){
            cout << n;
        }
    }else{
        for(int i = 0; i < n; i++){
            cout << m;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int H1, H2, M1, M2, K, minute_sum = 0;
    scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);

    minute_sum += (H2 * 60 + M2) - (H1 * 60 +M1);
    printf("%d", minute_sum - K);

    return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  vector<int>v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(a-1);
  v.push_back(b-1);
  sort(v.begin(),v.end());
  cout<<v[3]+v[2];
  return 0;
}


Measured memory_bytes: 256
# simpleバージョン
class BinaryIndexedTree:
    def __init__(self,size):
        self.N = size
        self.bit = [0]*(size+1)
    def add(self,x,w): # 0-indexed
        x += 1
        while x <= self.N:
            self.bit[x] += w
            x += (x & -x)
    def _sum(self,x): # 1-indexed
        ret = 0
        while x > 0:
            ret += self.bit[x]
            x -= (x & -x)
        return ret
    def sum(self,l,r): # [l,r)
        return self._sum(r) - self._sum(l)
    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.N)]
        return str(arr)


class BIT:
    """ 区間加算BIT(区間加算・区間合計取得) """
 
    def __init__(self, N):
        # 添字0が使えないので、内部的には全て1-indexedとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N
 
    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k
 
    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s
 
    def add(self, l, r, x):
        """ 区間[l,r)に値xを追加 """
 
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)
 
    def query(self, l, r):
        """ 区間[l,r)の和を取得 """
 
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
             - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)

def ctoi(c):
    return ord(c) - ord('a')

def main():
    N = int(input())
    S = input()
    Q = int(input())
    query = [input().split() for i in range(Q)]
    bits = [BIT(N) for i in range(26)]
    s = []
    for i, c in enumerate(S):
        bits[ctoi(c)].add(i,i+1,1)
        s.append(c)

    for a, b, c in query:
        if a == '1':
            i = int(b) - 1
            bits[ctoi(s[i])].add(i,i+1,-1)
            bits[ctoi(c)].add(i,i+1,1)
            s[i] = c
        else:
            l = int(b) - 1
            r = int(c)
            a = 0
            for i in range(26):
                if bits[i].query(l,r):
                    a += 1
            print(a)




if __name__ == "__main__":
    main()

Measured memory_bytes: 297076
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>

int main(void)
{
    int N, Y;
    std::cin >> N >> Y;
    for(int a=0; a<=N; ++a)
    {
        int t = (Y-1000*N-9000*a);
        if(t >= 0 && t % 4000 == 0)
        {
            int b = t/4000;
            int c = N-a-b;
            if(c < 0)
                continue;
            std::cout << a << " " << b << " " << c << std::endl;
            return 0;
        }
    }
    std::cout << "-1 -1 -1" << std::endl;
    return 0;
}


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

int main(){
  string S;
  cin>>S;
  
  //cout<<S<<endl;
  
  int N=S.size();
  int n=0;
  
  //cout<<N<<endl;
  
  for(int i=0;i<N;i++){
    if (i%2==0 && S.at(i)=='1') n++;
    if (i%2==1 && S.at(i)=='0') n++;
  }

  
  if (n>N/2) n=N-n;
  cout<<n<<endl;
}

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

int main(){
    int N, counter=0;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i < N; i++) {cin >> A[i];}

    while(true){
        
        bool exist_odd = false; 
        for (int x=0; x < A.size(); x++) {
             if (A[x]%2 != 0) {exist_odd = true;}
             }
        
        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++counter;  // 操作回数をインクリメント
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int n,l;
bool cmp(int a,int b) {
	return abs(a)<abs(b);
}
int main() {
	cin >> n >> l;
	int a[210];
	for(int i=1;i<=n;i++)
		a[i]=l+i-1;
	sort(a+1,a+n+1,cmp);
	int sum=0;
	for(int i=2;i<=n;i++)
		sum+=a[i];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

bool isPrime(int n) {
	if (n == 2)
		return true;

	if (n < 2 || n % 2 == 0)
		return false;

	for (int i = 3, k = sqrt(n); i <= k; i += 2) {
		if (n % i == 0)
			return false;
	}

	return true;
}

int main() {
    int x;
    cin >> x;
    for (; ; ++x) {
        if (isPrime(x)) {
            cout << x << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
//#include <search.h>
#include <algorithm>
//#include <vector>
using namespace std;
int main()
{
    int x=0,n,maxx=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
                x++;
                if(x>maxx) maxx=x;
        }
        else{
                x--;
                if(x>maxx) maxx=x;
        }
    }
    cout<<maxx;


return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	X := make([]int, 5)
	for i := 0; i < 5; i++ {
		fmt.Scanf("%d", &X[i])
	}
	var a int
	for i := 0; i < 5; i++ {
		if X[i] == 0 {
			a = i + 1
		}
	}
	fmt.Println(a)
}


Measured memory_bytes: 1816
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N = I()
    L = sorted(LI())
    ans = 0

    for i in range(N):
        k = i
        for j in range(i+1, N):
            while k < N and L[k] < L[i] + L[j]: k += 1
            ans += k - (j + 1)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 73276
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	ll a[n];For(i,0,n){
		cin>>a[i];
		a[i]--;
	}
	ll f[n];
	For(i,0,n) f[a[i]]=i;
	For(i,0,n){
		cout<<f[i]+1<<" ";
	}
	cout<<endl;































	
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        char[] s = stdin.next().toCharArray();
        if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
            System.out.println("Bad");
        } else {
            System.out.println("Good");
        }
    }
}

Measured memory_bytes: 23764
/*In The Name of AintAH*/
#include <bits/stdc++.h>
#define inf 1000000000000007
#define mod	1000000007
#define MAX 505 
#define ll long long
#define fr first
#define sc second
#define endl '\n'
using namespace std;
set<int> s;
void get_div(int x){
	for(int i = 1; i*i <= x; i ++){
		if(x % i == 0){
			s.insert(i);
			s.insert(x/i);
		}
	}
}
int a[MAX];

int main(){ 
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,sum = 0,k;
	cin>>n>>k;
	for(int i = 0; i < n ;i ++)cin>>a[i],sum += a[i];
	get_div(sum);
	for(auto it = s.rbegin() ; it != s.rend() ; it++){
		int d = *it;
		vector<int> v;
		for(int i = 0; i < n; i++) v.push_back(a[i]%d);
		
		sort(v.begin(), v.end());
		int right = v.size() - 1;
		int left = 0,sum = 0;
		while(left < right){
			if(v[left] == 0){left++;continue;}
			if(v[right] == d){right--;continue;}
			if(v[right] + v[left] >= d){
				v[left] -= d - v[right];
				sum += d - v[right];
				v[right] = d;
			}else{
				v[right] += v[left];
				sum += v[left];
				v[left] = 0;
			}
		}
		if(sum <= k )return cout<<d , 0;
		
	}
	return 0; 
}

Measured memory_bytes: 384
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val S = sc.next
    val red = S.count(_.==('0'))
    val blue = S.length - red
    val result = Math.min(red, blue) * 2
    println(result)
  }
}


Measured memory_bytes: 31260
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n, a[100007], b[100007], c[100007], dp[100007][4];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i] >> c[i];
		dp[i][1] = a[i];
		dp[i][2] = b[i];
		dp[i][3] = c[i];
		if(i > 1){
			dp[i][1] += max(dp[i - 1][2], dp[i - 1][3]);
			dp[i][2] += max(dp[i - 1][1], dp[i - 1][3]);
			dp[i][3] += max(dp[i - 1][1], dp[i - 1][2]);
		}
	}
	cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
}



Measured memory_bytes: 2944
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            while (a > 0 && Long.highestOneBit(a) == Long.highestOneBit(b)) {
                long flip = Long.highestOneBit(a);
                a ^= flip;
                b ^= flip;
            }
            if (b == 0) {
                out.println(1);
                return;
            }
            int first = Long.numberOfTrailingZeros(Long.highestOneBit(b));
            int second;
            if (b == (1L << first)) {
                second = -1;
            } else {
                second = Long.numberOfTrailingZeros(Long.highestOneBit(b ^ (1L << first)));
            }
            long res = b - a + 1;
            res += ((1L << first) + (1L << (second + 1)) - 1 - b);
            if (a == 0 || Long.numberOfTrailingZeros(Long.highestOneBit(a)) <= second) {
                res += (1L << (first + 1)) - ((1L << first) + (1L << (second + 1)));
            } else {
                int middle = Long.numberOfTrailingZeros(Long.highestOneBit(a));
                res += (1L << (first + 1)) - ((1L << first) + (1L << (middle + 1)));
                res += (1L << (middle + 1)) - a;
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 23508
#include <cassert>
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <random>
#include <chrono>
using namespace std;
//#define int long long

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x, a;
	cin >> x >> a;
	if (x < a)
		cout << 0 << "\n";
	else
		cout << 10 << "\n";

	
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

vector<int> a[5050];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    cin >> p[i].first >> p[i].second;
  }

  sort(p.begin(), p.end());
  vector<int> res;
  rep(i, n) {
    res.push_back(p[i].second);
    sort(res.begin(), res.end());
    a[i] = res;
  }

  while (m--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int ans = 0;
    int left = -1, right = n;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (p[mid].first <= x2) left = mid;
      else right = mid;
    }
    if (left == -1) {
      cout << ans << '\n';
      continue;
    }
    int left2 = -1, right2 = left + 1;
    while (right2 - left2 > 1) {
      int mid2 = (left2 + right2) / 2;
      if (a[left][mid2] <= y2) left2 = mid2;
      else right2 = mid2;
    }
    ans += left2 + 1;
    left2 = -1, right2 = left + 1;
    while (right2 - left2 > 1) {
      int mid2 = (left2 + right2) / 2;
      if (a[left][mid2] >= y1) right2 = mid2;
      else left2 = mid2;
    }
    ans -= right2;
    left = -1, right = n;
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (p[mid].first >= x1) right = mid;
      else left = mid;
    }
    if (left == -1) {
      cout << ans << '\n';
      continue;
    }
    left2 = -1, right2 = left + 1;
    while (right2 - left2 > 1) {
      int mid2 = (left2 + right2) / 2;
      if (a[left][mid2] <= y2) left2 = mid2;
      else right2 = mid2;
    }
    ans -= left2 + 1;
    left2 = -1, right2 = left + 1;
    while (right2 - left2 > 1) {
      int mid2 = (left2 + right2) / 2;
      if (a[left][mid2] >= y1) right2 = mid2;
      else left2 = mid2;
    }
    ans += right2;
    cout << ans << '\n';
  }

  




  
  return 0;
}


Measured memory_bytes: 52172
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
    }
    deque<int> DQ;
    if(N % 2 == 0){
        for(int i = 0;i<N;i++){
            if(i % 2 == 0){
                DQ.push_back(retu.at(i));
            }
            else{
                DQ.push_front(retu.at(i));
            }
        }
    }
    else{
        for(int i = 0;i<N;i++){
            if(i % 2 == 0){
                DQ.push_front(retu.at(i));
            }
            else{
                DQ.push_back(retu.at(i));
            }
        }
    }
    for(int V : DQ) cout << V << endl;
}


Measured memory_bytes: 3840
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

double prob[3001];
double dp[3001][3001];


// top down
double f(int n, int nh){
	// base case
	if(nh == 0)
		return 1.0;
	if(n == 0)
		return 0;

	if(dp[n][nh] != -1.0){
		return dp[n][nh];
	}

	// rec case
	double p1 = prob[n]*f(n-1, nh-1);
	double p2 = (1 - prob[n])*f(n-1, nh);
	return dp[n][nh] = (p1 + p2);
}

double fbup(int n){
	for(int i=0; i<=n; i++) dp[i][0] = 1;

	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			dp[i][j] = prob[i]*dp[i-1][j-1] + (1 - prob[i])*dp[i-1][j];
		}
	}

	return dp[n][n/2 + 1];
}

int main()
{
	ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

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

    int nh = (n/2 + 1);

    cout<<setprecision(10)<<fbup(n)<<endl;

	return 0;
}


Measured memory_bytes: 70528
#include <stdio.h>
#define INF 1001001001
int main() {
	int n;
	scanf("%d", &n);
	int f[100][10];
	int p[100][10];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%d", &f[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			scanf("%d", &p[i][j]);
		}
	}
	int ans = -INF;
	for (int bit = 1; bit < 1 << 10; bit++) {
		int c[100] = {0};
		int prf = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 10; j++) {
				if (f[i][j] && (bit >> j & 1)) {
					c[i]++;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			prf += p[i][c[i]];
		}
		if (ans < prf) {
			ans = prf;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<string.h>
int main(){
    char w[100];
    char s;
    int c,l;
    int i,j=0;

    scanf("%s",w);
    l=strlen(w);
    while(j<l){
        if(w[j]=='0')j++;
        s=w[j];
        c=0;
        for(i=0;i<l;i++){
            if(w[i]==s){
            w[i]='0';
            c++;
            }
        }
        if(c%2!=0){
            printf("No\n");
            break;
        }
        if(j==l-1)printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;

 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
 
inline ll mul(ll a,ll b){
 
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}
 
  
 
 
#define all(x) (x).begin(),(x).end()




//s.reserve(32768); //updated !
//s.max_load_factor(0.25);


ll a[200005];


int main(){
 
    

    int n;
    cin>>n;

    int a=(n+999)/1000;
    cout<<a*1000-n<<"\n";

    
    


    



    
    
    




    

}
    

    






    
    

    
 
    
 

 
 
    
 
 


Measured memory_bytes: 3444