akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint A, B, Q;
lint a[100002], b[100002], x;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> A >> B >> Q;
	a[0] = -INF;
	b[0] = -INF;
	REP(i, A) {
		cin >> a[i + 1];
	}
	REP(i, B) {
		cin >> b[i + 1];
	}
	a[A + 1] = INF;
	b[B + 1] = INF;
	sort(a, a + A + 2);
	sort(b, b + B + 2);

	vector<lint> ans;
	REP(i, Q) {
		cin >> x;
		lint lb_a = a[upper_bound(a, a + A + 2, x) - a - 1];
		lint ub_a = a[upper_bound(a, a + A + 2, x) - a];
		lint lb_b = b[upper_bound(b, b + B + 2, x) - b - 1];
		lint ub_b = b[upper_bound(b, b + B + 2, x) - b];
		lint minv = 2*INF;
		chmin(minv, ub_b - lb_a + min(ub_b - x, x - lb_a));
		chmin(minv, ub_a - lb_b + min(ub_a - x, x - lb_b));
		chmin(minv, max(x - lb_a, x - lb_b));
		chmin(minv, max(ub_a - x, ub_b - x));
		ans.push_back(minv);
	}
	REP(i, Q) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 5824
N=int(input())
X=list(map(int,input().split()))
X2=sorted(enumerate(X),key=lambda x:x[1])
X3=sorted(enumerate(X2),key=lambda x:x[1][0])
ans=[0]*N
for i in range(N):
  if X3[i][0] < N//2:print(X2[N//2][1])
  else:print(X2[N//2-1][1])

Measured memory_bytes: 61608
h,n=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
inf=10**9
dp=[inf]*(h+10**5)
dp[0]=0
#dp[i]=モンスターの体力をi減らすのに魔力が最低でいくつ必要か
for i in range(h):
    for a,b in l:
        dp[i+a]=min(dp[i+a],dp[i]+b)
ans=10**9
for i in range(10**5):
    ans=min(ans,dp[i+h])
print(ans)

Measured memory_bytes: 75012
#include <stdio.h>

int main() {
	int b, i, n, flag, cnt, a[100];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	flag = 1;
	cnt = 0;

	while (flag == 1) {
		flag = 0;

		for (i = n - 1; i > 0; i--) {
			if (a[i - 1] > a[i]) {
				b = a[i];
				a[i] = a[i - 1];
				a[i - 1] = b;
				cnt++;
				flag = 1;
			}
		}
	}

	for (i = 0; i < n-1; i++) {
		printf("%d ", a[i]);
	}
	printf("%d\n", a[n - 1]);
	printf("%d\n", cnt);

	return 0;
}

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

int main() {
    string S;  cin >> S;
    int N = S.size();
    vector<int> f(N), f_cp(N);
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') f[i] = f_cp[i] = i + 1;
        else f[i] = f_cp[i] = i - 1;
    }

    int K = 1e5;
    vector<int> now(N), now_cp(N);
    for (int i = 0; i < N; ++i) now[i] = now_cp[i] = i;
    while (K) {
        if (K & 1) {
            for (int i = 0; i < N; ++i) now[i] = f[now_cp[i]];
            now_cp = now;
        }
        for (int i = 0; i < N; ++i) f[i] = f_cp[f_cp[i]];
        f_cp = f;
        K >>= 1;
    }

    vector<int> ans(N);
    for (int i = 0; i < N; ++i) ++ans[now[i]];
    for (int i = 0; i < N; ++i) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int n = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) ++n;
  }
  cout << n << endl;
  return 0;
}


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

int main(void){
    int n, m;
    cin >> n >> m;
    
    int *mat;
    mat = new int[n*m];
    
    int i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> mat[i * m + j];
//            cout << mat[i * m + j];
        }
    }
    
    int *vec;
    vec = new int[m];
    for(j = 0; j < m; j++) cin >> vec[j];
    
    int result;
    for(i = 0; i < n; i++){
        result = 0;
        for(j = 0; j < m; j++){
            result += (mat[i * m + j])*vec[j];
        }
        cout << result << endl;
    }
    
    delete vec;
    delete[] mat;
    mat = 0;
    return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    bool a[n+1];
    memset(a,false,sizeof(a));
    ll b;
    ll p[n+1]={0};
    ll g=0;
    ll d=0;
    string c;
   for(int x=0;x<m;x++)
   {
       cin>>b>>c;
       if(!a[b])
       {
           if(c[0]=='W')
            {
                ++p[b];
            }
            else if(c[0]=='A')
            {
                ++g;
                d+=p[b];
                a[b]=true;
            }
       }
   }
   cout<<g<<" "<<d;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
using namespace std;
int n, q, l[100000], r[100000];
int ac_count[100000];
string s;
int main() {
  cin >> n >> q >> s;
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }

  if (s[0] == 'A' && s[1] == 'C') {
    ac_count[0] = 1;
  }
  for (int i = 1; i < (n - 1); i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      ac_count[i] = ac_count[i - 1] + 1;
    } else {
      ac_count[i] = ac_count[i - 1];
    }
  }

  for (int i = 0; i < q; i++) {
    if (l[i] == 0) {
      cout << ac_count[r[i] - 1] << endl;
    } else {
      cout << ac_count[r[i] - 1] - ac_count[l[i] - 1] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2176
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n;
vi a;
vi nst;

signed main(){
    I(n);
    a.resize(n);
    REP(i,n) I(a[i]);
    int suma = accumulate(all(a), 0LL);
    int mini = *min_element(all(a));
    int maxi = *max_element(all(a));
    int once = (n+1) * n / 2;
    int nop = suma / once;
    if (suma % once != 0 || mini < nop || maxi > nop * n ){
        cerr << "input kill" << endl;
        cout << "NO" << endl;
        return 0;
    }
    nst.resize(n);
    // 差は 1 か 1-n か
    // a_i+1 - a_i = x + (1-n)(o-x)
    //             = o - no + nx

    REP(i,n){
        int neigh = (i+1) % n;
        int nx = (a[neigh] - a[i]) - (nop - nop * n);
        if (nx % n != 0 || nx/n < 0 || nx/n > nop){
            cerr << neigh << " NG" << endl;
            cout << "NO" << endl;
            return 0;
        }
        nst[neigh] = nx/n;
    }
    
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void count(int t, int cnt[]) {
		int tmp = t;
		int i = 0;
		while (tmp > 0) {
			if ((tmp & 1) == 1)
				cnt[i]++;
			tmp >>= 1;
			++i;
		}
	}

	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();
		sc.close();
		int cnt[][] = new int[n][21];
		for (int i = 0; i < n; ++i)
			count(a[i], cnt[i]);
		long ans = n, sum[] = new long[21];
		boolean flag = true;
		int start = 0;
		for (int i = 0; i < n; ++i) {
			flag = true;
			for (int j = 0; j < cnt[i].length; ++j) {
				sum[j] += cnt[i][j];
				if (sum[j] > 1)
					flag = false;
			}
			if (!flag) {
				for (int j = start; j < i; ++j)
					ans += i - j - 1;
				while (!flag) {
					flag = true;
					for (int j = 0; j < cnt[start].length; ++j) {
						sum[j] -= cnt[start][j];
						if (sum[j] > 1)
							flag = false;
					}
					start++;
				}
				for(int j = start; j < i; ++j)
					ans -= i - j - 1;
			}
		}
		for (int i = start; i < n; ++i)
			ans += n - i - 1;
		System.out.println(ans);
	}

}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long

void solve(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = 0;
	for(int i=0; i<k; i++) ans += a[i];
	cout << ans << "\n";
}

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

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

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H); for(int i = 0; i < H; i++) cin >> S[i];
    int ans = 1e9;
    queue<pair<int, pair<int, int>>> Q;
    Q.push(make_pair(1, make_pair(0, 0)));
    int sh[4] = {0, -1, 0, 1};
    int sw[4] = {1, 0, -1, 0};
    bool map[H][W];
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) map[i][j] = false;
    map[0][0] = true;
    while(!Q.empty()){
        int c = Q.front().first;
        int x = Q.front().second.first;
        int y = Q.front().second.second;
        Q.pop();
        if(x == H-1 && y == W-1) ans = min(ans, c);
        for(int i = 0; i < 4; i++){
            if(0 <= x+sh[i] && x+sh[i] < H && 0 <= y+sw[i] && y+sw[i] < W && map[x+sh[i]][y+sw[i]] == false){
                if(S[x+sh[i]][y+sw[i]] != '#') {
                    Q.push(make_pair(c+1, make_pair(x+sh[i], y+sw[i])));
                    map[x+sh[i]][y+sw[i]] = true;
                    
                }
            }
        }
    }
    int bnum = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#') bnum++; 
        }
    }
    if(ans == 1e9) {
        cout << -1 << endl;
        return 0;
    }
    cout << H*W-bnum-ans << endl;
}

Measured memory_bytes: 256
N, M, X, Y = [int(x) for x in input().split()]
xs = [int(x) for x in input().split()]
ys = [int(x) for x in input().split()]

x = max(X, max(xs))
y = min(Y, min(ys))
ans = x >= y

print("War" if ans else "No War")



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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a >= 13){
            System.out.println(b);
        }else if( a >= 6){
            System.out.println(b/2);
        }else{
            System.out.println(0);
        }

    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}



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

using namespace std;

#define REPEAT(i, N) for (int i = 0; i < (N); i++)

int main() {
    int A, B, C, D;
    
    cin >> A >> B >> C >> D;
    
    while (true) {
        C -= B;
        
        if (C <= 0) {
            cout << "Yes" << endl;
            
            return 0;
        }
        
        A -= D;
        
        if (A <= 0) {
            cout << "No" << endl;
            
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3632
import math
N, D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for _ in range(N)]
 
ans = 0
for i in range(N):
    for j in range(i+1, N):
        yz = [abs((y - z)**2) for y, z in zip(X[i], X[j])]
        v = math.sqrt(sum(yz))
        if v == int(v):
            ans += 1
            
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        dp[1] = Math.abs(nums[1] - nums[0]);
        for(int i = 2; i < n; i++) {
            for(int h = k; h >= 1; h--) {
                try{
                    dp[i] = Math.min(dp[i], dp[i - h] + Math.abs(nums[i] - nums[i - h]));
                } catch(Exception e) {

                }

            }
        }
        System.out.println(dp[n - 1]);
    }
}


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

using namespace std;
int main(int argc, char const *argv[])
{
    int d, g, res = 10000;
    cin >> d >> g;

    int p[11], c[11];
    for (int i = 0; i < d; i++)
        cin >> p[i] >> c[i];

    for (int bit = 0; bit < (1 << d); bit++)
    {
        bool flag = false;
        int resmax = 0, restmp = 0, score = 0;
        for (int i = 0; i < d; i++)
        {
            if (bit & (1 << i))
            {
                score += 100 * (i + 1) * p[i] + c[i];
                restmp += p[i];
            }
            else
                resmax = max(resmax, i);
        }
        for (int i = 0; i < p[resmax]+1; i++)
        {
            if (g <= score + (100 * (resmax + 1) * i))
            {
                restmp += i;
                flag = true;
                break;
            }
        }
        if (flag)
            res = min(restmp, res);
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8, i8)")
def chmax(a, b):
    if a > b:
        return a
    else:
        return b


@nb.njit("i8(i8,i8,i8[:,:])")
def solve(N, W, wv):
    dp = np.zeros(shape=(N + 1, W + 1), dtype=np.int64)
    for i in range(1, N + 1):
        w, v = wv[i - 1]
        for j in range(1, W + 1):
            if j < w:
                dp[i, j] = dp[i - 1, j]
            else:
                dp[i, j] = chmax(dp[i - 1, j - w] + v, dp[i - 1, j])
    return dp[-1, -1]


def main():
    N, W = map(int, input().split())
    wv = np.zeros(shape=(N, 2), dtype=np.int64)
    for i in range(N):
        w, v = map(int, input().split())
        wv[i] = w, v

    ans = solve(N, W, wv)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 189884
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nm = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var ai = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var m = nm[1];
            var answer = 0L;
            var dict = new Dictionary<long, long>();
            dict[0] = 1;
            var aggregate = 0L;

            for (var i = 0; i < ai.Length; i++)
            {
                aggregate += ai[i];
                var tmp = aggregate % m;
                dict[tmp] = dict.ContainsKey(tmp) ? dict[tmp] + 1 : 1;
            }

            foreach (var count in dict.Values) answer += count * (count - 1);
            Console.WriteLine(answer / 2);
        }
    }
}


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

const int MAX = 200005;
const int mod = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){

COMinit();

 long long int N;
 long long int M;
 long long int K;
 cin >> N >> M >> K;
int i,j;
long long int count = 0;
 for(i=1;i<N;i++){
     count+=(i*(M*((M*(((N-i)*COM(N*M-2,K-2))%mod))%mod)%mod))%mod;
     count %= mod;
 }
  for(i=1;i<M;i++){
     count+=(i*(N*((N*(((M-i)*COM(N*M-2,K-2))%mod))%mod)%mod))%mod;
     count %= mod;
 }
cout << count%mod << endl;
 }

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

using namespace std;

vector<long long> solve(const vector<long long>& a){
    const int N = a.size();
    vector<long long> res(N+1, 0);
    bool zero = false;
    if(a.back() < 0) res[N-1] = 1;
    else if(a.back() == 0) zero = true;
    vector<pair<int, int>> mergin;
    for(int i=N-2;i>=0;i--){
        auto cur = a[i], next = a[i+1];
        if(zero){
            if(cur != 0){
                for(int j=0;j<=i;j++) res[j] = -1;
                return res;
            } else {
                res[i] = res[i+1];
                continue;
            }
        } else if(cur == 0){
            zero = true;
            res[i] = res[i+1];
            continue;
        }
        res[i] = res[i+1] + (a[i] < 0 ? 1 : 0);
        if(cur < 0) cur *= -2;
        if(next < 0) next *= -2;
        if(cur <= next){
            int m = 0;
            while(4*cur <= next){
                m += 2;
                cur *= 4;
            }
            if(m > 0) mergin.emplace_back(m, i);
        } else {
            int m = 0;
            while(next < cur){
                m += 2;
                next *= 4;
            }
            while(m > 0){
                if(mergin.empty()){
                    res[i] += (N-1-i) * m;
                    break;
                } else {
                    int sub = min(m, mergin.back().first);
                    res[i] += (mergin.back().second-i) * sub;
                    m -= sub;
                    mergin.back().first -= sub;
                    if(!mergin.back().first) mergin.pop_back();
                }
            }
        }
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<long long> a(N);
        for(auto& t : a) cin >> t;
        auto p = solve(a);
        reverse(a.begin(), a.end());
        for(auto& t : a) t *= -1;
        auto n = solve(a);
        long long res = -1;
        for(int i=0;i<=N;i++){
            if(p[i] == -1 || n[N-i] == -1) continue;
            long long cur = p[i] + n[N-i];
            if(res == -1 || cur < res) res = cur;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 4992
N = gets.to_i
@s = s = gets.chomp

c = [
  [true, true],
  [true, false],
  [false, true],
  [false, false],
]

def check_at(n, ans)
  case ans[n]
  when true
    (@s[n] == "o" && ans[n-1] == ans[n+1]) || (@s[n] == "x" && ans[n-1] != ans[n+1])
  when false
    (@s[n] == "o" && ans[n-1] != ans[n+1]) || (@s[n] == "x" && ans[n-1] == ans[n+1])
  end
end

c.each do |ans|
  (N-2).times do |i|
    case
    when ans[i+1] && s[i+1] == "o"
      ans << ans[i]
    when ans[i+1] && s[i+1] == "x"
      ans << !ans[i]
    when !ans[i+1] && s[i+1] == "o"
      ans << !ans[i]
    else
      ans << ans[i]
    end
  end

  if check_at(0, ans) && check_at(-1, ans)
    puts ans.map { |i| i ? "S" : "W" }.join
    exit
  end
end
p -1


Measured memory_bytes: 10236
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<std::pair<int, int>> vec;
	for(int loop = 0; loop < 2; loop++) {
		for(int i = 0; i < n; i++) {
			int a; scanf("%d", &a);

			vec.push_back({a, loop});
		}
	}
	sort(begin(vec), end(vec));

	const int MOD = 1e9 + 7;
	i64 ans = 1, A = 0, B = 0;
	for(auto v: vec) {
		if(v.second) {
			if(B) (ans *= B--) %= MOD;
			else A++;
		} else {
			if(A) (ans *= A--) %= MOD;
			else B++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    ll K, X;
    cin >> K >> X;
    cout << (K * 500 >= X ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX (1e+9)+7
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

int main(void){
  ull N;
  cin >> N;
  ull A[N];
  ull zero_num[60] = {0}, one_num[60] = {0};
  rep(i, N) {
    cin >> A[i];
    rep(j, 60){
      if (A[i] >> j&1) one_num[j]++;
      else zero_num[j]++;
    }
  }
  
  ull ans = 0;
  ull mod = (ull)MAX;
  ull two_kai;
  
  rep(i, 60) {
    two_kai  =1;
    rep(j, i){
      two_kai = two_kai*2%(1000000007);
    }
    ans=(ans+(one_num[i]*zero_num[i]%(ull)(1000000007))*two_kai)%(ull)(1000000007);
  }
  cout << ans << endl;

}


Measured memory_bytes: 2560
Acsum=[]
acsum=0
for i in range(10**5):
  acsum+=i
  Acsum.append(acsum)
def binarysearch(x):
  ng=-1
  ok=10**5
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if Acsum[mid]>=x:
      ok=mid
    else:
      ng=mid
  return ok
n=int(input())
print(binarysearch(n))

Measured memory_bytes: 7448
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 2; i <= n; i++) a[i] += a[i - 1];
    int ans = 0;
    for(int i = k ;i < n + 1; i++){
        ans = max(ans, a[i] - a[i - k]);
    }
    printf("%.16lf\n", (ans + k) * 0.5);
    return 0;
}

Measured memory_bytes: 1024
N, Q = map(int, input().split())
S = input()
memo = [0]

tmp = 0
for i in range(1, N):
    if S[i-1]+S[i] == "AC":
        tmp += 1
    memo.append(tmp)

for _ in range(Q):
    l, r = map(int, input().split())
    print(memo[r-1] - memo[l-1])


Measured memory_bytes: 6100
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 500000
#define DUMMY 2000000001

struct Node{
  int key;
  struct Node *left,*right;
};

struct Node *make_node(int x){
  struct Node *node = malloc(sizeof(struct Node));
  if(node != NULL){
    node->key = x;
    node->left = NULL;
    node->right = NULL;
  }
  return node;
}

struct Node *root;

struct Node *insert(int,struct Node*);
void insort(struct Node*);
void presort(struct Node*);
void find(int,struct Node*);

int main(void){
  int m,n=0;
  int i;
  int k;
  char order[7];

  root = NULL;

  scanf("%d",&m);

  for(i=0;i<m;i++){
    scanf("%s",order);
    if(strcmp(order,"insert") == 0){
      scanf("%d",&k);
      root = insert(k,root);
    }else if(strcmp(order,"print") == 0){
      insort(root);
      printf("\n");
      presort(root);
      printf("\n");
    }else if(strcmp(order,"find") == 0){
      scanf("%d",&k);
      find(k,root);
    }
  }
}

struct Node *insert(int key,struct Node *node){
  if (node == NULL)
    return make_node(key);
  else if (key < node->key)
    node->left = insert(key, node->left);
  else if (key > node->key)
    node->right = insert(key, node->right);
  return node;
}

void find(int key,struct Node *node){
  while (node != NULL) {
    if (node->key == key){
      printf("yes\n");
      return;
    }
    else if(key < node->key)
      node = node->left;
    else
      node = node->right;
  }
  printf("no\n");
  return;
}

void insort(struct Node *node){

  if(node == NULL) return;

  insort(node->left);

  printf(" %d",node->key);

  insort(node->right);
}

void presort(struct Node *node){

  if(node == NULL) return;

  printf(" %d",node->key);
  
  presort(node->left);
  presort(node->right);
}


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

constexpr long long int M = 1000000007;

template<int N>
struct Fact{
  long long int val[N];
  long long int v2[N];
  constexpr Fact() : val(), v2() {
    val[0] = 1;
    for(int i = 1; i < N; ++i)val[i] = val[i - 1] * i % M;
    for(int i = 1; i < N; ++i)v2[i] = val[i - 1] * val[i] % M;
  }
};

template<int N, long long F>
struct IFact{
  long long int val[N];
  constexpr IFact() : val() {
    val[N - 1] = F;
    for(int i = N - 1; i > 0; --i)val[i - 1] = val[i] * i % M;
  }
};

long long int N, ans;
constexpr auto fact = Fact<1000001>();
constexpr auto ifact = IFact<1000001, 397802501>();

int main(){
    scanf("%lld", &N);
    for(int i = N / 2; i < N - 1; ++i){
        ans += fact.v2[i] * ifact.val[i * 2 - N] % M;
    }
    ans = fact.val[N] - fact.val[N - 1] - ans;
    ans %= M;
    printf("%lld\n",(ans > 0 ? ans : M + ans));
    //cout << (ans > 0 ? ans : M + ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

const long int INF=1L << 60;

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

void swmin(long int* origin, long int* comp) {
    if(*origin > *comp) {
        swap(origin, comp);
    }
}

int N;

int main() {
    cin >> N;
    int h[N];
    long int dp[N];
    for(int i=0; i<N; i++) {
        cin >> h[i];
    }
    
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    
    for(int i=0; i<N-1; i++) {
        if(i<N-2) {
            dp[i+2] = INF;
            long int tmp = dp[i] + abs(h[i]-h[i+2]);
            swmin(&dp[i+2], &tmp);
        }
        
        long int tmp = dp[i] + abs(h[i]-h[i+1]);
        swmin(&dp[i+1], &tmp);
    }
    
    cout << dp[N-1] << endl;

    return 0;
    
}

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


n,m,s,t= map(int, input().split())
a= [list(map(int, input().split())) for i in range(m)]
b = [[] for i in range(n)] # 円のグラフ
c = [[] for i in range(n)] # スヌークのグラフ

for i in range(m):
    b[a[i][0]-1].append((a[i][1]-1,a[i][2]))
    b[a[i][1]-1].append((a[i][0]-1,a[i][2]))

for i in range(m):
    c[a[i][0]-1].append((a[i][1]-1,a[i][3]))
    c[a[i][1]-1].append((a[i][0]-1,a[i][3]))

from heapq import heappush, heappop

def dijkstra(edges, size, source):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    INF=pow(10,15)
    distance = [INF] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance

x=dijkstra(b,n,s-1)
y=dijkstra(c,n,t-1)
ans=[0]*n
w=pow(10,15)
for i in range(n):
    v=x[n-1-i]+y[n-1-i]
    w=min(v,w)
    ans[n-1-i]=w

for i in range(n):
    print(pow(10,15)-ans[i])

Measured memory_bytes: 123100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n;
    cin>>n;
    int a[n+1];
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int c=0;
    for (int i=1;i<=n;i++)
    {
        if (a[i]>i&&a[a[i]]==i)
        {
            c++;
        }
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3968
n = int(input())
a = list(map(int,input().split()))
max_num = 0
count = 0
for i in range(1,n):
  if a[i-1]>=a[i]:
    count+=1
  else:
    max_num = max(count,max_num)
    count = 0
  if i == n-1:
    max_num = max(count,max_num)
print(max_num)

Measured memory_bytes: 85352
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int t,x;cin>>t>>x;
	printf("%.12lf\n",t/(double)x);
}

Measured memory_bytes: 256
from collections import defaultdict
a, *D,  = [s.split()[0] for s in open(0)] 
d = defaultdict(int)

for w in D:
    d[w] += 1 

d = sorted(d.items(),key = lambda x:(-x[1], x[0]))
max_v = d[0][1]
for v in d:
    if v[1] == max_v:
        print(v[0])

Measured memory_bytes: 59560
n, x = map(int, input().split())
l = sorted(list(map(int, input().split())))
kids = 0
ans = 0
for i in range(n):
    kids += l[i]
    if kids <= x:
        ans += 1
    else:
        break

if sum(l) >= x:
    print(ans)
else:
    print(ans - 1)

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

int main() {
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] c = sc.nextLine().toCharArray();
		StringBuilder sb = new StringBuilder();
		sc.close();
		for(int i = 0;i < c.length;i += 2) {
			sb.append(c[i]);
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a[100];
    long long n;
    cin >>n;
    a[0]=2;
    for (int i=1;i<=n;i++)
    	a[i]=2*a[i-1]+2;
    cout <<a[n];
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200000)
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

ans=0
dx=[0,0,1,-1]
dy=[1,-1,0,0]

was=[[0 for i in range(W)] for j in range(H)]

def dfs(x,y):
    global cc
    global was
    was[x][y]=1
    if S[x][y]=="#":
        cc[1]+=1
    else:
        cc[0]+=1
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        if nx>=0 and ny>=0 and nx<H and ny<W and S[nx][ny]!=S[x][y] and not was[nx][ny]:
            dfs(nx,ny)

for i in range(H):
    for j in range(W):
        if not was[i][j]:
            cc=[0]*2
            dfs(i,j)
            ans+= cc[1]*cc[0]

print(ans)

Measured memory_bytes: 148212
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0567
AC
"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
item = namedtuple('item', ['cal', 'pri'])


def Cond(x, n, items, pizza):
    # y = [0] * n
    # for i in range(n):
    #     y[i] = items[i].cal - x * items[i].pri 
    y = [(items[i].cal - x * items[i].pri) for i in range(n)] #  ?????????????????°???1??????????????????????????????????????¢??????
    y.sort(reverse=True)
    
    total = pizza.cal - x * pizza.pri #  ?????¶?????°????????????????????????????????????
    #  ?????¶?????°??¨??¢??????????????????????????????????¨??????????????????¶(????????????1??????????????????????????????)?????????????????????
    for c in y:
        if c > 0:
            total += c
        else:
            break
    return total >= 0


def main(args):
    # ?????¬ p132 ???????????§???
    N = int(input())
    A, B = map(int, input().split())
    C = int(input())
    toppings = []
    for i in range(N):
        toppings.append(item(int(input()), B))
    pizza = item(C, A)

    lb = 0
    ub = 1e5
    for i in range(100):
        mid = (lb + ub) / 2
        if Cond(mid, N, toppings, pizza):
            lb = mid
        else:
            ub = mid
    print(int(ub))


if __name__ == '__main__':
    main(sys.argv[1:])

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

#include <math.h>
#include <stdlib.h>


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

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 int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;

    for(int i = 1; i < 50010; i++){
        int nc = int(1.08 * i);
        if(nc == n) {
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

ll comb[5001][5001];


int main(){
	int n;
	vector<int> v1,v2;
	cin >> n;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		v1.push_back(a);
		v2.push_back(a);
	}

	sort(v2.begin(),v2.end());
	int d = 0;
	for(int i=0;i<n;i++){
		if(v1[i]!=v2[i]) d++;
	}
	if(d>2){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}

	return 0;
}


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

int main (){
    long long N, K;
    cin>>N>>K;
    vector<long long> V(N), VV(N);
    vector<long long> Hand(0);
    for(long long i=0; i<N; i++){
        cin>>V.at(i);
        VV.at(i)=V.at(i);
    }
    long long Size=V.size();
    long long Max=0;
    long long Sum=0;
    long long NK=min(N, K);
    for(long long a=0; a<=NK; a++){
      //cout<<endl;
        for(long long b=0; b<=NK-a; b++){
          	Sum=0;
            Hand.erase(Hand.begin(), Hand.end());
            for(long long i=0; i<a; i++){
                Hand.push_back(V.at(i));
                Sum += V.at(i);
            }
            for(long long i=0; i<b; i++){
                Hand.push_back(V.at(Size-1-i));
                Sum += V.at(Size-1-i);
            }
            sort(Hand.begin(), Hand.end());
            long long c=a+b;
            while(c<K){
                if(Hand.empty()||Hand.at(0)>-1){
                    break;
                }
                else{
                    Sum -= Hand.at(0);
                    Hand.erase(Hand.begin());
                }
                c ++;

            }
            Max=max(Max, Sum);
          	//cout<<Sum<<endl;

        }
    }
    cout<<Max<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var a, b, c byte
	fmt.Fscanf(r, "%c%c%c", &a, &b, &c)

	count := 0

	arr := []byte{a, b, c}

	for i := 0; i < 3; i++ {
		if arr[i] == 'R' {
			if i == 0 {
				count++
			} else if i == 1 {
				if count == 0 {
					count++
				} else if arr[i-1] == 'R' {
					count++
				}
			} else if i == 2 {
				if count == 0 {
					count++
				} else if count == 1 && arr[i-1] == 'R' {
					count++
				} else if count == 2 {
					count++
				}
			}
		}
	}

	fmt.Fprintf(w, "%d\n", count)

}


Measured memory_bytes: 1844
# 3 3 1 1

# 100
# 010
# 001

# 3 3 1 0

# 100
# 100
# 100

# 4 4 2 1
# 1100
# 1100
# 1100
# 0011

# 4 3 1 1

# 1000
# 1000
# 0111

# ……あ。全部0→左側A列を逆転させる→下側B列を逆転させる　で構成可能だ。

h, w, a, b = list(map(int, input().split()))

for _ in range(h-b):
    print('1'*a + '0'*(w-a))
for _ in range(b):
    print('0'*a + '1'*(w-a))


Measured memory_bytes: 3956
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
    var n = readL()
    var x = mutableListOf<Char>()
    while (0 < n) {
        x.add('a' + (--n % 26).toInt())
        n /= 26
    }
    println(x.reversed().joinToString(""))
}


Measured memory_bytes: 36492
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n;
	cin>>n;
	int h[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>h[i][j];		
		}
	}
	int dp[n][3];
	dp[0][0]=h[0][0];
	dp[0][1]=h[0][1];
	dp[0][2]=h[0][2];
	for(int i=1;i<n;i++){
		dp[i][0]=h[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=h[i][1]+max(dp[i-1][2],dp[i-1][0]);
		dp[i][2]=h[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);


}


Measured memory_bytes: 5500
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if(t.startsWith(s)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
	}
}

Measured memory_bytes: 35688
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(li, x):
    n = len(li)
    ok = -1
    ng = n
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if li[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

def main():
    a,b,q = inpm()
    s = inplm(a)
    t = inplm(b)
    x = inplm(q)
    s = tuple(s)
    t = tuple(t)
    x = tuple(x)
    for i in range(q):
        start = x[i]
        n = len(s)
        ok = -1
        ng = n
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if s[mid] < start:
                ok = mid
            else:
                ng = mid
        index_s = ok
        n = len(t)
        ok = -1
        ng = n
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if t[mid] < start:
                ok = mid
            else:
                ng = mid
        index_t = ok
        a1 = 10**11
        b1 = 10**11
        c1 = 10**11
        d1 = 10**11
        if index_t+1 < b and index_s+1 < a:
            d1 = abs(max(s[index_s+1],t[index_t+1]) - start)
        if index_s >= 0 and index_t+1 < b:
            a1 = min(abs(start - s[index_s]) + abs(s[index_s] - t[index_t+1]), abs(start - t[index_t+1]) + abs(s[index_s] - t[index_t+1]) )  
        if index_t >= 0 and index_s+1 < a:
            b1 = min(abs(start - t[index_t]) + abs(s[index_s+1] - t[index_t]),abs(start - s[index_s+1]) + abs(s[index_s+1] - t[index_t]))
        if index_s >= 0 and index_t >= 0:
            c1 = abs(start - min(s[index_s],t[index_t]))
        print(min(a1,b1,c1,d1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 145240
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BContestWithDrinksEasy {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    vector<int> t(n);
	    int tsum = 0;
	    for(int i=0; i<n; i++){
	        in >> t[i];
	        tsum += t[i];
	    }
	    int m, p, x;
	    in >> m;
	    vector<pair<int, int>> mp(m);
	    for(int i=0; i<m; i++){
	        in >> p >> x;
	        p--;
	        mp[i] = make_pair(p, x);
	    }

	    int res = 0;
	    for(int i=0; i<m; i++){
	        out << tsum - t[mp[i].first] + mp[i].second << endl;
	    }
	}
};


int main() {
	BContestWithDrinksEasy solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        long N = scanner.nextLong();

        long answer = Long.MAX_VALUE;
        for (long i = 1 ; i * i <= N ; i++) {
            if (N % i == 0) {
                long j = N / i;
                answer = Math.min(answer, i + j - 2);
            }
        }

        System.out.println(answer);
    }
}


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

int main() {
    int N;
    cin >> N;

    long long T=0,A=0;
    long long t,a;
    for(int i=0;i<N;i++){
        cin >> t >> a;
        if(i==0){
            T=t;
            A=a;
        }
        else{
            long long numa=A/a;
            if(A%a)numa++;
            long long numt=T/t;
            if(T%t) numt++;
            long long num=max(numt,numa);
            A=a*num;
            T=t*num;
        }
    }
    cout << T+A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    if ((S.at(2) == S.at(3)) && (S.at(4) == S.at(5)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256