akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; // ???????????¨???
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back 
#define MAX_E 2017
#define MAX_V 1145
#define INF INT_MAX / 3

// make_pair ??????????????§
struct edge{int from, to, cost; };
edge es[MAX_E]; // ???
int d[MAX_V]; // ???????????¢
int V, E; // V???????????°???E????????°
//?§????s????????????????????????????????¢????±???????
bool find_negative_loop(int s){ 
    rep(i, V) d[i] = INF;
    d[s] = 0;
    rep(i, V){
        rep(j, E){
            edge e = es[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i == V - 1) return true;
            }
        }
    }
    return false;
}
int main(){
	int r;
	cin >> V >> E >> r;
	int s, t, w;
	rep(i, E)
	{
		cin >> s >> t >> w;
		es[i] = {s, t, w};
	}
	if(!find_negative_loop(r))
	{
		rep(i, V)
		{
			if(d[i] == INF) cout << "INF" << endl;
			else cout << d[i] << endl;
		}
	}
	else
	{
		cout << "NEGATIVE CYCLE" << endl;
	}
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using Graph = vector<vector<int>>;
 
int main(){
  int L,R,d;
  int ans = 0;
  cin >> L >> R >> d;
  FOR(i,L,R+1){
    if(i%d == 0) ans++;
  }
  cout << ans;
}


Measured memory_bytes: 3564
#!/usr/bin/env python3

s = int(input())



if s <= 2:
    print(0)
else:
    a = [0] * (s + 1)
    a[0] = 1
    for i in range(3, s + 1):
        a[i] = int((a[i - 1] + a[i - 3]) % (1e9 + 7))

    print(a[s])

Measured memory_bytes: 9184
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    first = max(A)
    idx = A.index(first)
    second = max(A[:idx]+A[idx+1:])
    for i in range(N):
        if i == idx:
            print(second)
        else:
            print(first)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14124
n, m = map(int, raw_input().split())

A = [[0 for j in xrange(m)] for i in xrange(n)]

B = [0 for i in xrange(m)]

for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        A[i][j] = tmp[j]
        
for i in xrange(m):
    B[i] = input()

for i in xrange(n):
    tmp = 0
    for j in xrange(m):
        tmp += A[i][j] * B[j]
    print tmp

Measured memory_bytes: 6640
#include <stdio.h>

int main() {
  int a,b,c,d,e,f=0;
  char g[1000]={};
  while(1){
    scanf("%s",g);
    if(g[0]!='-'){
      scanf("%d",&a);
      for(b=0;g[b]!='\0';b++){
        f=b+1;}
    for(b=0;b<a;b++){
      scanf("%d",&c);
      for(d=0;d<c;d++){
      g[f+d]=g[d];}
      for(d=0;d<f;d++){
        g[d]=g[c+d];}}
    for(b=0;b<f;b++){
      printf("%c",g[b]);}
    printf("\n");}
    else{break;}}
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
using int32 = __uint32_t;

void solve() {
    int h, w;
    cin >> h >> w;

    int n;
    cin >> n;

    vector<int>v(n);
    
    int ct = 0;
    int mat[h][w];

    bool rit = true;
    int cur = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        for(int j = 0; j < v[i]; j++){
            if(rit){
                mat[cur][ct] = i + 1;
                ct++;
                if(ct == w){
                    cur++;
                    ct--;
                    rit = false;
                }
            }
            else {
                mat[cur][ct] = i + 1;
                ct--;
                if(ct == -1){
                    ct++;
                    cur++;
                    rit = true;
                }
            }
         
        }
    }
    for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)cout << mat[i][j] << " \n"[j + 1 == w];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

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


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int Q = sc.nextInt();

		long[] s = new long[A+2];
		long[] t = new long[B+2];

		s[0] = -10_0000_000_000L;
		s[A+1] = 10_0000_000_000L;

		t[0] = -10_0000_000_000L;
		t[B+1] = 10_0000_000_000L;

		for(int i=0;i<A;i++) {
			s[i+1] = sc.nextLong();
		}
		for(int i=0;i<B;i++) {
			t[i+1] = sc.nextLong();
		}


		int si = 0;
		int ti = 0;

		for(int i=0;i<Q;i++) {
			long x = sc.nextLong();

			si = Arrays.binarySearch(s, x);
			if(si<0) si = -si -2;
			ti = Arrays.binarySearch(t, x);
			if(ti<0) ti = -ti -2;

			long a1,a2,a3,a4;

			a1 = Math.max(x - s[si], x - t[ti]);
			a2 = Math.min(x-s[si], t[ti+1]-x) * 2 + Math.max(x-s[si], t[ti+1]-x);
			a3 = Math.min(s[si+1]-x, x-t[ti]) * 2 + Math.max(s[si+1]-x, x-t[ti]);
			a4 = Math.max(s[si+1]-x, t[ti+1]-x);

			out.println(Math.min(Math.min(a1, a2), Math.min(a3, a4)));

		}


		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 97120
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n,q;
  string s;
  cin >> n >> q >> s;
  int count=0;
  vl ans(n+1);
  rep2(i,1,n+1){
    ans[i]=ans[i-1];
    if(s[i-2]=='A'&&s[i-1]=='C')ans[i]++;
  }
  rep(i,q){
    int l,r;
    cin >> l >> r;
    cout << ans[r]-ans[l] << endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#define endl '\n'
#define ll long long
#define pb push_back
#define pi 3.14159265358979323846264338327950288419716939937510
#define RUN_FAST ios::sync_with_stdio(false);
#define sz 100
using namespace std;

ll arr[100110];

int main()
{
    RUN_FAST;
    ll n, x, tmp, i, j, cnt;
    ll sum=0;
    scanf("%lld", &n);
    tmp=n;
    while (tmp--) {
        scanf("%lld", &x);
        arr[x]++;
        sum+=x;
    }
    ll q, a, b;
    scanf("%lld", &q);
    while (q--) {
        scanf("%lld %lld", &a, &b);
        tmp=arr[a];
        sum-=tmp*a;
        sum+=tmp*b;
        arr[b]=arr[b]+tmp;
        arr[a]=0;
        printf("%lld\n", sum);
    }
    return 0;
}


Measured memory_bytes: 4592
n,d,a = gets.split.map(&:to_i)
monsters = Array.new(n){ gets.split.map(&:to_i) } 

deq = []
acc_damage = 0
ans = 0

monsters.sort_by(&:first).each do |x,h|
  
  while deq.any? && deq[0][0] < x
    acc_damage -= deq.shift[1]
  end
  
  h -= acc_damage
  next if h <= 0
  
  n = ( h + a - 1 ) / a
  ans += n
  
  power = a * n
  acc_damage += power
  deq.push( [x + d*2, power] )
end

puts ans

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


int main(){

  int k;
  cin >> k;

 string s;
 cin >> s;
  int a;
  a = s.size();

  
  if (a <= k){
      cout << s;
  }
  else {
      cout << s.substr(0,k) << "..." << endl;
  }


    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;

const ll N = 50;

void next(ll arr[])
{
    ll idx, ma = 0;
    for (int i=0; i<N; i++) {
        if (ma < arr[i]) {
            ma = arr[i];
            idx = i;
        }
    }

    arr[idx] -= N;
    for (int i=0; i<N; i++) {
        if (i == idx) continue;
        arr[i]++;
    }
}

signed main()
{
    ll K;
    cin >> K;

    ll up = K / N + 1;

    ll a[N];
    REP(i,N) a[i] = N - 1 + up;

    ll nowK = N * up;
    //cout << "nowK = " << nowK << endl;
    REP(i,nowK-K) {
        next(a);
    }

    cout << N << endl;
    REP(i,N) {
        if (i != 0) cout << " ";
        cout << a[i];
    }

    cout << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
m = max(a)
x = a.index(m)
m2 = max(a[:x]+a[x+1:])
if m-m2:
    for i in range(n):
        if i-x: print(m)
        else: print(m2)
else:
    for i in range(n): print(m)

Measured memory_bytes: 14124
import itertools

N = int(input())
L = list(map(int, input().split()))

hen_list = list(itertools.combinations(L, 3))
ans = 0

for i in range(len(hen_list)):
  if len(hen_list[i]) == len(set(hen_list[i])):
    l = sorted(hen_list[i])
    if l[2] < (l[0] + l[1]):
      ans += 1
      
print(ans)

Measured memory_bytes: 20620
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        int i=1;
        while(true){
            if((long)Math.max(a,b)*i%(long)Math.min(a,b)==0){
                System.out.println((long)Math.max(a,b)*i);
                break;
            }
            i++;
        }
    }
}

Measured memory_bytes: 22732
#include<stdio.h>
int main(void)
{
	int a[100],b,c=0,x,y,z,price;
	for(b=0;;b++)
	{
		price=10000;
		scanf("%d",&a[b]);
		if(a[b]==0)
			break;
		for(x=0;x<=a[b]/200;x++)
			for(y=0;y<=(a[b]-200*x)/300;y++)
				for(z=0;z<=(a[b]-200*x-300*y)/500;z++)
					if(a[b]==200*x+300*y+500*z&&x%5*380+x/5*5*380*80/100+y%4*550+y/4*4*550*85/100+z%3*850+z/3*3*850*88/100<price)
						price=x%5*380+x/5*5*380*80/100+y%4*550+y/4*4*550*85/100+z%3*850+z/3*3*850*88/100;
		printf("%d\n",price);
	}
	return 0;
}

Measured memory_bytes: 600
import itertools
import numpy as np
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
count = 0
a = 0
b = 0
num = []
for i in range(1,n+1):
    num.append(i)
for balls in itertools.permutations(num):
    count = count + 1
    if(list(balls) == p):
         a = count
    if(list(balls) == q):
         b = count
print(np.abs(a-b))

Measured memory_bytes: 14448
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=55,M=205,P=1e9+7;
typedef long long ll;

vector<int>e[N];
int dfn[N],low[N],dfc,st[N],tp,fac[M],ifac[M];
int n,m,k,ans=1;
set<int>dat;

int fpow(int a,int t){static int r;for(r=1;t;t>>=1,a=(ll)a*a%P)if(t&1)r=(ll)r*a%P;return r;}
int C(int n,int m){return (ll)fac[n]*ifac[m]%P*ifac[n-m]%P;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int polya(int n){int r=0;for(int i=1;i<=n;i++)r=(r+fpow(k,gcd(n,i)))%P;return (ll)r*fpow(n,P-2)%P;}
int permu(int m){return C(m+k-1,k-1);}

void tarjan(int x,int fa){
	dfn[x]=low[x]=++dfc,st[++tp]=x;
	for(int v:e[x])if(v!=fa){
		if(!dfn[v]){
			tarjan(v,x),low[x]=min(low[x],low[v]);
			if(low[v]>=dfn[x]){
				dat.clear();
				int n=0,m=0,las;
				do dat.insert(st[tp]),las=st[tp],st[tp--]=0,n++;while(las!=v);
				dat.insert(x),n++;
				for(int u:dat)for(int v:e[u])if(dat.count(v))m++;m>>=1;
				if(m<n)ans=(ll)ans*k%P;
				else if(m==n)ans=(ll)ans*polya(n)%P;
				else ans=(ll)ans*permu(m)%P;
			}
		}else low[x]=min(low[x],dfn[v]);
	}
	if(fa==0)st[tp--]=0;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	fac[0]=1;
	for(int i=1;i<=m+k;i++)fac[i]=(ll)fac[i-1]*i%P;
	ifac[m+k]=fpow(fac[m+k],P-2);
	for(int i=m+k;i>=1;i--)ifac[i-1]=(ll)ifac[i]*i%P;
	for(int i=1,u,v;i<=m;i++)scanf("%d%d",&u,&v),e[u].pb(v),e[v].pb(u);
	for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
int A[1<<18];
priority_queue<pair<int,int>> pq[1<<18];

signed main(){
    cin >> N;
    rep(i, 1<<N) cin >> A[i];

    int ans = 0;
    rep(i, 1<<N){
        pq[i].push({ A[i],i });
        pair<int,int> m = pq[i].top();
        pq[i].pop();
        while(!pq[i].empty() && pq[i].top() == m) pq[i].pop();
        if(!pq[i].empty()) ans = max(ans, m.first+pq[i].top().first);
        if(i != 0) cout << ans << endl;

        int k = 0;
        while(i >= (1<<k)) k++;
        for(int j=i+(1<<k); j<(1<<N); j+=(1<<k)){
            pq[j].push(m);
            if(!pq[i].empty()) pq[j].push(pq[i].top());
        }
        for(int j=0; j<k; j++){
            if(((i>>j)&1) == 0){
                pq[i+(1<<j)].push(m);
                if(!pq[i].empty()) pq[i+(1<<j)].push(pq[i].top());
            }
        }
    }
}

Measured memory_bytes: 132696
W = input()
counters = []
for i in range(0, 26):
	counters.append(0)
for i in range(0, len(W)):
	counters[ord(W[i])-97] += 1
ans = 'Yes'
for i in range(0, 26):
	if counters[i]%2 == 1:
		ans = 'No'
		break
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;

using namespace std;

typedef long long ll;

void solve() {
	ll a, b;
	cin >> a >> b;
	if (a < b) {
		while (b--) {
			cout << a;
		}
	} else{
		while(a--) {
			cout << b;
		}
	}
	return ;
}

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


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean i = false;
		boolean j = false;
		boolean k = false;
		String[] s = new String[N];
		for(int l = 0;l < N;l++) {
			s[l] = sc.next();
			
		}
		for(int l = 0;l < N;l++) {
			if(s[l].equals("P")) {
				i = true;
			}
			else if(s[l].equals("W")) {
				j = true;
			}
			else if(s[l].equals("G")) {
				k = true;
			}
			else {
				i = false;
				j = false;
				k = false;
				break;
			}
		}
		if(i = true && j && k) System.out.println("Three");
		else if(!i && !j && !k) System.out.println("Four");
		sc.close();
	}

}


Measured memory_bytes: 21844
"use strict";

const main = (input) => {
    const spi = input.split('\n');
    let x = Number(spi[0]);
    let ans = Math.floor((x / 500)) * 1000;
    x %= 500;
    ans += Math.floor(x / 5) * 5;
    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30468
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int64_t dp[20005];
	dp[0]=0,dp[1]=0,dp[2]=0;
	dp[3]=1;
	for (int i=4;i<=n;i++){
		dp[i]=1;
		for (int j=i-3;j>=3;j--) dp[i]=(dp[i]+dp[j])%mod;
	}
	cout<<dp[n];
}

Measured memory_bytes: 3668
use proconio::input;

fn main() {
    input!{
        n: usize,
        m: i32,
        q: usize,
        qu: [(usize,usize,i32,i32); q]
    };
    let ans = dfs(1, m, &mut vec![1;n + 1], &qu[..]);
    println!("{}", ans);
}

fn dfs(i: usize, m: i32, seq: &mut Vec<i32>, qu: &[(usize, usize, i32, i32)] ) -> i32 {
    if i < seq.len() {
        let offset = seq[i - 1];
        (offset ..= m).map(|j| {
            seq[i] = j;
            dfs(i + 1, m, seq, qu)
        }).max().unwrap()
    } else {
        qu.iter().fold(0,|s,(a,b,c,d)|{
            if seq[*b] - seq[*a] == *c {
                s + *d
            } else {
                s
            }
        })
    }
}

Measured memory_bytes: 2184
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var ca = S.ToCharArray();
		for(int i=0;i<N;i++){
			if(S[i] != S[K]) ca[i] = '*';
		}
		Console.WriteLine(new String(ca));
	}
	int N;
	String S;
	int K;
	public Sol(){
		N = ri();
		S = rs();
		K = ri() - 1;
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
import java.util.*;
import java.io.*;
class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String record=sc.next();
        int cnt=0;
        int mval=0;
        for(char ch:record.toCharArray()){
            if(ch=='S'){
                mval=Math.max(mval,cnt);
                cnt=0;
            }else{
                cnt++;
            }
        }
        mval=Math.max(mval,cnt);
        System.out.println(mval);
    }
}

Measured memory_bytes: 35612
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);


template<class T>
void show(const vector<T> &a) {
    for (T x : a)
        cout << x << " ";
    cout << endl;
}

const ll oo = 1e18;

const int N = 20;

int ans[1 << N];

string bin(int m) {
    stringstream ss;
    while (m) {
        if (m % 2 == 1) ss << "1";
        else ss << "0";
        m /= 2;
    }
    string s = ss.str();
    reverse(ALL(s));
    return s;
}

set<pii> dp[1 << N];
int a[1<<N];
int n;

void upd(set<pii> &a, set<pii> b) {
    a.insert(ALL(b));
    while (SZ(a) > 2) a.erase(a.begin());
}

void dfs(int v) {
    if (SZ(dp[v])) return;
    dp[v].insert(mp(a[v], v));
    for (int i = 0; i < n; ++i) if ((v >> i) & 1) {
        dfs(v ^ (1 << i));
        upd(dp[v], dp[v ^ (1 << i)]);
    }
}

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

    cin >> n;
    fori (i, (1 << n)) {
        cin >> a[i];

    }
    dfs((1 << n) - 1);

    for (int i = 0; i < (1 << n); ++i) {
        if (SZ(dp[i]) >= 2) ans[i] = (*dp[i].begin()).first + (*next(dp[i].begin())).first;
        if (i) mmax(ans[i], ans[i - 1]);
    }
    for (int i = 1; i < (1 << n); ++i)
        cout << ans[i] << endl;
}



Measured memory_bytes: 93184
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge { ll to, cost; };
const ll INF = 9000000000000000000;

ll d[210000], n, a, b, c, q, k, x, y;
vector<edge> G[210000];

void dijkstra(ll s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + n + 1, INF);
    d[s] = 0;
    que.push(P(0, s));
    
    while (que.size()) {
        P p = que.top(); que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (ll i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n - 1; i++) {
        cin >> a >> b >> c;
        G[a].push_back(edge{b, c});
        G[b].push_back(edge{a, c});
    }
    cin >> q >> k;
    dijkstra(k);
    for (ll i = 0; i < q; i++) {
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }
}


Measured memory_bytes: 14192
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)
 
int main(){
    int n;
    cin>>n;
    int max_val=0;
    int max_pos=0;
    for(int i=1;i<n;i++){
        cout<<"? "<<1<<" "<<i+1<<endl;
        int res;
        cin>>res;
        if(res>max_val){
            max_val = res;
            max_pos = i;
        }
    }
    vector<int> ans(n);
    ans[0] = max_pos;
    rep(i,n){
        if(i==max_pos)continue;
        cout<<"? "<<max_pos+1<<" "<<i+1<<endl;
        int res;
        cin>>res;
        ans[res]=i;
    }
    cout<<"!";
    rep(i,n)cout<<" "<<ans[i]+1;
    cout<<endl;
}

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

class SegmentTree {
private:
	std::vector<int64_t> sumContainer_, minContainer_;

	void lazyEvaluate(const int node_i)
	{
		minContainer_[node_i] += sumContainer_[node_i];
		if (node_i < ((int)sumContainer_.size() >> 1))
		{
			sumContainer_[2 * node_i] += sumContainer_[node_i];
			sumContainer_[2 * node_i + 1] += sumContainer_[node_i];
		}
		sumContainer_[node_i] = 0;
	}

	void addImplement(const int query_l, const int query_r, const int node_l, const int node_r, const int node_i, const int64_t added)
	{
		if (query_l <= node_l && node_r <= query_r)
		{
			sumContainer_[node_i] += added;
			lazyEvaluate(node_i);
			return;
		}
		lazyEvaluate(node_i);
		if (node_r <= query_l || query_r <= node_l) return;
		const int node_m{(node_l + node_r) >> 1};
		addImplement(query_l, query_r, node_l, node_m, 2 * node_i, added);
		addImplement(query_l, query_r, node_m, node_r, 2 * node_i + 1, added);
		minContainer_[node_i] = std::min(minContainer_[2 * node_i], minContainer_[2 * node_i + 1]);
	}

	int64_t findImplement(const int query_l, const int query_r, const int node_l, const int node_r, const int node_i)
	{
		if (node_r <= query_l || query_r <= node_l) return LLONG_MAX;
		lazyEvaluate(node_i);
		if (query_l <= node_l && node_r <= query_r) return minContainer_[node_i];
		const int node_m{(node_l + node_r) >> 1};
		return std::min(
			findImplement(query_l, query_r, node_l, node_m, 2 * node_i),
			findImplement(query_l, query_r, node_m, node_r, 2 * node_i + 1)
		);
	}
public:
	SegmentTree(const int n)
	{
		int size{1};
		while (size < n) size <<= 1;
		sumContainer_.resize(2 * size);
		minContainer_.resize(2 * size);
	}

	void add(const int left, const int right, int64_t added)
	{
		addImplement(left, right, 0, sumContainer_.size() >> 1, 1, added);
	}

	int64_t find(const int left, const int right)
	{
		return findImplement(left, right, 0, sumContainer_.size() >> 1, 1);
	}
};

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	SegmentTree st(n);
	for (int q_i{}; q_i < q; q_i++)
	{
		int query, s, t;
		scanf("%d%d%d", &query, &s, &t);
		t++;
		if (query == 0)
		{
			int x;
			scanf("%d", &x);
			st.add(s, t, x);
		}
		else
			printf("%lld\n", st.find(s, t));
	}
	return 0;
}


Measured memory_bytes: 7052
import java.util.Scanner;

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

		int N = sc.nextInt();
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		int count = 0;

		for (int i = 0; i < N; i++) {
			int minj = i;
			for (int j = i; j < N; j++) {
				if (A[j] < A[minj]) {
					minj = j;
				}
			}
			if (i != minj) {
				count++;
			}
			int x = A[i];
			A[i] = A[minj];
			A[minj] = x;
		}
		for (int i = 0; i < N - 1; i++) {
			System.out.print(A[i] + " ");
		}
		System.out.println(A[N - 1]);
		System.out.print(count);
		System.out.printf("\n");

	}
}


Measured memory_bytes: 26268
#include <iostream>
#include <string>
//#include <string.h>
//#include <stdio.h>
using namespace std;

// A /////////////////////////////////////////////////

//int main()
//{
//	int input;//, output;
//
//	cin >> input;
//
//	cout << input + (input * input) + (input * input * input);
//
//	return 0;
//}


// B /////////////////////////////////////////////////

#define MAX_CHAR_LENGTH (200000)

int main()
{
	string S, T;
	int differentChars = 0, SLength, TLength;

	cin >> S;
	cin >> T;

	SLength = (int)(S.length());

	for (int i = 1; i <= SLength; i++) {
		if (S.compare(i - 1, 1, T,i-1,1) != 0) {
			differentChars++;
		}
	}

	cout << differentChars;

	return 0;
}

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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    if((10*g+b)%4==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
module Main where

import Numeric
import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; let (q,r) = divMod a b
  ; let s = fromIntegral a / fromIntegral b
  ; putStrLn . unwords $ [show q, show r, showFFloat Nothing s ""]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

done :: IO ()
done = return ()

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2 - x1, y = y2 - y1;
  cout << x2-y << ' ' << y2+x << ' ' << x1-y << ' ' << y1+x << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        int[] people = new int[n];

        int minPosition = 100;
        int maxPosition = 1;
        for (int i = 0; i < n; i++) {
            int val = sc.nextInt();
            minPosition = Math.min(minPosition, val);
            maxPosition = Math.max(maxPosition, val);
            people[i] = val;
        }

        int minValue = Integer.MAX_VALUE;
        for (int p = minPosition; p <= maxPosition; p++) {
            int val = 0;
            for (int i = 0; i < n; i++) {
                val += stamina(people[i], p);
            }
            minValue = Math.min(minValue, val);
        }
        System.out.println(minValue);
    }

    private static int stamina(int personStamina, int meetingIndex) {
        return (int) Math.pow(personStamina - meetingIndex, 2);
    }
}


Measured memory_bytes: 23124
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let price: f64 = read();
    let no_tax: f64 = price / 1.08;

    if (no_tax.ceil() * 1.08).trunc() == price { println!("{}", no_tax.ceil()); } else { println!(":("); }
}


Measured memory_bytes: 4352
import bisect
n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    a=a+bisect.bisect_left(l,l[i]+l[j])-j-1
print(a)


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

using namespace std;
typedef long long ll;

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

    set <int> s;
    int N; cin >> N;
    for (int i = 0; i < N; i++)
    {
        int x; cin >> x;
        s.insert(x);
    }
    if (s.size() == N) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 9600
from collections import deque

N = int(input())

L = [[] for i in range(N)]

for i in range(N-1) :
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    L[a].append([b,c])
    L[b].append([a,c])
    

Q,K = map(int,input().split())

K -= 1

DISTANCE = [float("inf") for i in range(N)]

DISTANCE[K] = 0

q = deque([K])

while q :
    from_ = q.popleft()
    for to_, weight in L[from_] :
        dist = DISTANCE[from_] + weight
        if dist < DISTANCE[to_] :
            DISTANCE[to_] = dist
            q.append(to_)
            
ans = []

for i in range(Q) :
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    
    calc = DISTANCE[x] + DISTANCE[y]
    ans.append(calc)

print(*ans, sep="\n")


Measured memory_bytes: 56532
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args) {

            var line = Console.ReadLine();
            var data = line.Split(' ');

            var a = int.Parse(data[0]);
            var b = int.Parse(data[1]);

            var str = (a * b) % 2 == 0 ? "Even" : "Odd";

            Console.WriteLine($"{str}");
        }
    }
}


Measured memory_bytes: 13140
package main
 
import(
  "fmt"
)
 
func main(){
  var n, m int
  var tmp_x, tmp_y int
  var x[] int
  var y[] int
  fmt.Scanf("%d %d", &n, &m)
  x = make([]int, m)
  y = make([]int, m)
  for i:=0 ; i < m; i++{
  fmt.Scanf("%d %d", &tmp_x, &tmp_y)
    if tmp_x > tmp_y {
      x[i], y[i] = tmp_y, tmp_x
    }else{
      x[i], y[i] = tmp_x, tmp_y
    }
  }
  u := newUnionFind(n)
  //fmt.Println(u)
  for i:= 0; i < m; i++{
    //fmt.Printf("%d %d", x[i]-1, y[i]-1)
    u.unite(x[i]-1, y[i]-1)
  }
  fmt.Println(u.countRoot()-1)
}

type UnionFind struct {
    par []int
    depth []int
}
 
/* コンストラクタ */
func newUnionFind(N int) *UnionFind {
    u := new(UnionFind)
    u.par = make([]int, N)
    u.depth = make([]int, N)
  for i:=0 ; i < N; i++ {
      u.depth[i] = 1
      u.par[i] = -1
    }
    return u
}
 
/* xの所属するグループを返す */
func (u UnionFind) root(x int) int {
    if u.par[x] < 0 {
        return x
    }else{
      u.par[x] = u.root(u.par[x])
      return u.par[x]
    }
}

func (u UnionFind) countRoot()int{
  var ans int
  for _, par:= range u.par{
    //fmt.Printf(par)
    if par < 0 {
      ans++
    }
  }
  return ans
}
 
/* xの所属するグループ と yの所属するグループ を合体する */
func (u UnionFind) unite(x, y int) {
    xr := u.root(x)
    yr := u.root(y)
    //fmt.Println(u.par[xr]," ",u.par[yr])
    if xr == yr {
        return
    }
  //ツリーの深さが小さい方に統合
  if u.depth[xr] > u.depth[yr]{
    xr, yr = yr, xr 
  }else if(u.depth[xr] == u.depth[yr]){
    u.depth[yr]++
  }
    u.par[yr] += u.par[xr]
    u.par[xr] = yr
}

Measured memory_bytes: 7076
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func main() {
	line1 := inputs(1)

	n, _ := strconv.Atoi(line1[0])

	var sum int64

	for i := 1; i < (n + 1); i++ {
		if i%3 == 0 || i%5 == 0 {
			continue
		} else {
			sum += int64(i)
		}
	}

	fmt.Println(sum)
}

Measured memory_bytes: 1828
K, N = map(int, input().split())
A_list = list(map(int, input().split()))
max1 = -1
for i in range(N):
    if i!=N-1:
        dis = abs(A_list[i]-A_list[i+1])
    else:
        if A_list[0]!=0:
            dis = abs(K-A_list[-1])+A_list[0]
        else:
            dis = abs(K-A_list[-1])
    if dis > max1:
        max1 = dis
print(K-max1)


Measured memory_bytes: 26420
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    lint ans=0;
    for(lint i=1;i<=n;i++){
        ans+=i*(i%3&&i%5);
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 3652
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<"  "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll a[n];
	ll xo=0;
	rep(i,0,n){
		cin >> a[i];
		xo^=a[i];
	}
	if(xo==0) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 1024
const lines = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
let i = 0;
while(true) {
  const [h, w] = lines[i++].split(" ").map(Number);
  if (!h&&!w) break;
  console.log(`${"#".repeat(w)}\n`.repeat(h));
}



Measured memory_bytes: 15860
#include<stdio.h>

int main(void)
{
	int n, m, l, i, j,k;
	long a[100][100], b[100][100], c[100][100];

	scanf("%d %d %d", &n, &m, &l);

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%ld", &a[i][j]);
		}
	}

	for (j = 0; j < m; j++)
	{
		for (k = 0; k < l; k++)
		{
			scanf("%ld", &b[j][k]);
		}
	}

	for (i = 0; i < n; i++)
	{
		for (k = 0; k < l; k++)
		{
			c[i][k] = 0;

			for (j = 0; j < m; j++)
			{
				c[i][k] = c[i][k] + a[i][j] * b[j][k];
			}
		}
	}

	for (i = 0; i < n; i++)
	{
		for (k = 0; k < l - 1; k++)
		{
			printf("%ld ", c[i][k]);
		}
		printf("%ld\n", c[i][l - 1]);
	}

	return 0;
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 2e+5;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> B(N + 2);
  B[0] = INF;
  B[N] = INF;
  rep(i, N - 1) std::cin >> B[i + 1];

  ll ans = 0;
  rep(i, N) {
    ans += std::min(B[i], B[i + 1]);
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long min = 1000000;
		long max = -1000000;
		long sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i < n; i++) {
			min = Math.min(min, a[i]);
			max = Math.max(max, a[i]);
			sum += a[i];
		}
		System.out.println(min + " " + max + " " + sum);
		sc.close();
	}
}


Measured memory_bytes: 41440
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
	long long a,b,n,ans=0;
    scanf("%lld %lld %lld",&a,&b,&n);
	long long i=min(n,b-1);
	ans=max(ans,a*i/b-a*(i/b));
    printf("%lld\n",ans);
    return 0;
}
/*
 floor(Ax/B)−A×floor(x/B) 
 =Ax/B-Ax%B-A(x/B-x%B)
 =Ax/B
*/

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

int main() {
  int N, l, r;
  int s = 0;
  cin >> N;

  for ( int i = 0; i < N; i++) {
    cin >> l >> r; 
    s += r - l + 1;
  }
  cout << s << endl;
}

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

using ll = long long;

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

 	double n;
 	cin >> n;

 	double x = (double)(n/3);
 	double y = (n-(2*x));
 	
 	double ans = x*x*x;
	printf("%.10f",ans);
 	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    string ans;

    cin >> s;
    
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == '0' || s.at(i) == '1') {
            ans += s.at(i);
        }
        else {
            if (ans.size() > 0) {
                ans.pop_back();
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3588
// ABC077_C
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))

int main() {
    // input
    ll N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    // calculation
    ll now_B, num_A, num_C, res = 0;
    ll idx_bound_A, idx_bound_C;

    for (ll i = 0; i < N; ++i) {
        now_B = B[i];
        num_A = 0;
        num_C = 0;

        // 1 段目: now_B 未満の数を求める
        auto iter_A = lower_bound(A.begin(), A.end(), now_B);
        idx_bound_A = distance(A.begin(), iter_A);
        num_A = (iter_A == A.end())? N: (idx_bound_A + 1) - 1;

        // 3 段目: now_B より大きい数
        auto iter_C = upper_bound(C.begin(), C.end(), now_B);
        idx_bound_C = distance(C.begin(), iter_C);
        num_C = (iter_C == C.end())? 0: N - idx_bound_C;

        res += num_A*num_C;
    }

    cout << res << "\n";

    return 0;
}

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

int H,W;
vector<string> field(50);
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
vector<vector<bool>> seen(50,vector<bool>(50,false));
bool ans=true;
void dfs(int h,int w){
  seen[h][w]=true;
  bool ok=true;
  for (int i=0;i<4;i++){
    int nh=h+dh[i];
    int nw=w+dw[i];
    if (nh<0||nh>H-1||nw<0||nw>W-1){
      continue;
    }
    if (field[nh][nw]=='#'){
      ok=false;
      if (!seen[nh][nw]){
        dfs(nh,nw);
      }
    }
  }
  if (ok){
    ans=false;
  }
}

int main() {
  cin >> H >> W;
  for (int i=0;i<H;i++){
    cin >> field[i];
  }
  for (int h=0;h<H;h++){
    for (int w=0;w<W;w++){
      if (field[h][w]=='#'&&!seen[h][w]){
        dfs(h,w);
      }
    }
  }
  if (ans){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 512
/**
*    created: 29.06.2020 18:24:46
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

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

    int a, b;
    cin >> a >> b;
    cout << max({a+b,a-b,a*b}) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  unordered_map<string,ll> m;
  m["SAT"]=1;
  m["FRI"]=2;
  m["THU"]=3;
  m["WED"]=4;
  m["TUE"]=5;
  m["MON"]=6;
  m["SUN"]=7;
  
  string s;
  cin>>s;
  cout << m[s] << endl;
  
  

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

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

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

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

using namespace std;

int main()
{
  int N;

  cin >> N;

  int such[7];
  such[0] = 1;
  for(int i = 1; i < 7; i++) such[i] = such[i - 1] * 26;

  set< string > st[6];

  for(int i = 0; i < N; i++) {
    string S;
    cin >> S;
    for(int k = 0; k < S.size(); k++) {
      string FF;
      for(int l = 0; l < 5; l++) {
        if(k + l >= S.size()) break;
        FF += S[k + l];
        if(FF.size() == such[FF.size()]) continue;
        st[FF.size()].insert(FF);
      }
    }
  }


  for(int i = 1; i < 7; i++) {
    if(st[i].size() < such[i]) {
      string minimum = string(i, 'a');
      for(auto &s : st[i]) {
        if(minimum == s) {
          for(int j = minimum.size() - 1; j >= 0; j--) {
            minimum[j] = (minimum[j] - 'a' + 1) % 26 + 'a';
            if(minimum[j] != 'a') break;
          }
        } else {
          cout << minimum << endl;
          return (0);
        }
      }
      cout << minimum << endl;
      return (0);
    }
  }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  char c;
  cin >> c;
  bool b = ( c == 'T' );
  for(int i=1;i<n;++i) {
    cin >> c;
    if( b == false ) b = true;
    else b = ( c == 'T' );
  }
  puts(b?"T":"F");
  return 0;
}



Measured memory_bytes: 3096
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H == 0 && W == 0){
				break;
			}
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					System.out.printf("#");
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
		}
	}
}


Measured memory_bytes: 65360
import sys
input = sys.stdin.readline
INT_MAX = (1<<31) - 1
_N,num = map(int, input().split())
Q = [list(map(int, input().split())) for i in range(num)]
N = 1<<17
N1 = N - 1
N2 = N1 // 2
ars = 2*N - 1
A = [INT_MAX]*(ars)
L = [-1]*(ars)

def propagate(k):

    if(L[k] == -1):
        return
    left = k*2+1
    right = k*2+2
    if(k < N2):
        A[left] = A[right] = L[left] = L[right] = L[k]
        L[k] = -1
        return
    if(k < N1):
        A[left] = A[right] = L[k]
        L[k] = -1

def update(s,t,x,k,l,r):

    if (r <= s or t <= l):
        return
    if (s <= l and r <= t):
        A[k] = x
        if(k < N1):
            L[k] = x
        return

    propagate(k)
    mid = (l+r)//2
    left = k*2 + 1
    right = k*2 + 2
    update(s, t, x, left, l, mid)
    update(s, t, x, right, mid, r)

    A[k] = min(A[left], A[right])

def find(s,t,k,l,r):

    if (r <= s or t <= l):
        return INT_MAX

    if(s <= l and r <= t):
        return A[k]

    propagate(k)
    mid = (l+r)//2
    left = k*2 + 1
    right = k*2 + 2
    v_left = find(s, t, left, l, mid)
    v_right = find(s, t, right, mid, r)
    return min(v_left,v_right)

res = []
for q in Q:
    # update
    if(q[0]==0):
        update(q[1],q[2]+1,q[3],0,0,N)
    # find
    else:
        res.append(find(q[1],q[2]+1,0,0,N))

print("\n".join([str(r) for r in res]))



Measured memory_bytes: 33740
import java.util.*;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int cnt = 0;
    for (int i = 0; i < S.length() - 1; i++) {
      if (S.charAt(i) != S.charAt(i + 1)) {
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}


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

int N=0, L=0, cnt=0, ans_sum=0;

int main(){
  cin >> N >> L;
  rep(i, N){
    ans_sum += L + cnt;
    cnt ++;
  }
  if (L > 0) cout << ans_sum - L << endl;
  else if(L + N - 1 < 0) cout << ans_sum - (L + N - 1) << endl;
  else cout << ans_sum << endl;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  char b;cin>>b;
  if(b=='A')cout<<'T'<<endl;
  else if(b=='T')cout<<'A'<<endl;
  else if(b=='C')cout<<'G'<<endl;
  else if(b=='G')cout<<'C'<<endl;

  return 0;
}


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

typedef long long ll;

ll N;
vector<ll> V, W;
ll Q;
const ll K = 9, L = 100000;
vector<vector<ll>> Dp;
ll I;

ll solve(ll i, ll l) {
  if (i <= I) return Dp[i][l];
  ll res = solve(i / 2, l);
  if (l >= W[i]) res = max(res, V[i] + solve(i / 2, l - W[i]));
  return res;
}
int main() {
  cin >> N;
  V.resize(N + 1);
  W.resize(N + 1);
  for (ll i = 1; i <= N; ++i) cin >> V[i] >> W[i];
  I = min(N, (1ll << K) - 1);
  Dp.resize(I + 1);
  for (auto &dp : Dp) dp.resize(L + 1);
  for (ll i = 1; i <= I; ++i) {
    for (ll l = 0; l <= L; ++l) {
      Dp[i][l] = Dp[i / 2][l];
      if (W[i] <= l) Dp[i][l] = max(Dp[i][l], Dp[i / 2][l - W[i]] + V[i]);
    }
  }
  cin >> Q;
  for (ll q = 0; q < Q; ++q) {
    ll i, l;
    cin >> i >> l;
    cout << solve(i, l) << endl;
  }
  return 0;
}


Measured memory_bytes: 408692