akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;
int a[4];
int main() {
    char b[4];
    cin >> b[0] >> b[1] >> b[2] >> b[3];
    rep(i, 4) a[i] = b[i] - '0';
    for (int bit = 0; bit < (1 << 3); bit++) {
        int sum = a[0];
        rep(i, 3) {
            if ((bit >> i) & 1) {
                sum += a[i + 1];
            } else {
                sum -= a[i + 1];
            }
        }
        if (sum == 7) {
            cout << a[0];
            rep(i, 3) { cout << (((bit >> i) & 1) ? '+' : '-') << a[i + 1]; }
            cout << "=7" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
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() {
	i64 n; scanf("%lld", &n);

	int ans = 0;
	__int128_t now = 100;
	while(now < n) {
		now = now * 101L / 100L;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3760
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=1e5+11;
const ll INF=1e16+11;
struct Edge{int to,nxt;ll w;}edge[N<<1];
queue<int> Q;
int head[N],num_edge,n,q,k;
ll dist[N];
bool vis[N];
void add_edge(int from,int to,ll w){
	edge[++num_edge].nxt=head[from];
	edge[num_edge].to=to;
	edge[num_edge].w=w;
	head[from]=num_edge;
}
void spfa(){
	for(int i=1;i<=n;++i) dist[i]=INF;
	Q.push(k);vis[k]=1;dist[k]=0;
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;vis[v]=0;
			if(dist[v]>dist[u]+edge[i].w){
				dist[v]=dist[u]+edge[i].w;
				if(!vis[v]) Q.push(v),vis[v]=1;
			}
		}
	}
}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int x,y;ll z;
		scanf("%d%d%lld",&x,&y,&z);
		add_edge(x,y,z);add_edge(y,x,z);
	}
	scanf("%d%d",&q,&k);
	spfa();
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		printf("%lld\n",dist[x]+dist[y]);
	}
	return 0;
}

Measured memory_bytes: 6144
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		
		double a = (y2 - y1) / (x2 - x1);
		double b = y1 - a * x1;
		
		int q = sc.nextInt();
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<q; i++) {
			double xp = sc.nextDouble();
			double yp = sc.nextDouble();
			
			double x = 0;
			double y = 0;
			if(y1 == y2) {
				x = xp;
				y = y1;
			} else if(x1 == x2) {
				x = x1;
				y = yp;
			} else {
				x = (yp + xp / a - b) / (a + 1 / a);
				y = yp + xp / a - x / a;
			}
			
			ans.append(x);
			ans.append(" ");
			ans.append(y);
			ans.append("\n");
		}
		
		System.out.print(ans);
	}

	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;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); 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() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 28340
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  for (;;) {
    auto rd = readln.split.map!(to!int);
    auto m = rd[0], f = rd[1], r = rd[2];
    if (m == -1 && f == -1 && r == -1) break;

    if (m == -1 || f == -1)
      writeln("F");
    else if (m + f >= 80)
      writeln("A");
    else if (m + f >= 65 && m + f < 80)
      writeln("B");
    else if (m + f >= 50 && m + f < 65)
      writeln("C");
    else if (m + f >= 30 && m + f < 50) {
      if (r >= 50)
        writeln("C");
      else
        writeln("D");
    }
    else
      writeln("F");
  }
}

Measured memory_bytes: 2484
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    a, b, c, d = (int(x) for x in sys.stdin.read().split())
    left = a + b
    right = c + d
    if left > right: ans = "Left"
    elif right > left: ans = 'Right'
    else: ans = 'Balanced'
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
//Score: /200

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int left_fee = 0, right_fee = 0;
	for(int i=0; i<M; ++i){
		int A;
		cin >> A;
		if(A<X){
			++left_fee;
		}else if(A>X){
			++right_fee;
		}
	}
	cout << min(left_fee, right_fee);
}


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

int main() {
  int an,bn,m;
  cin >> an >> bn >> m;
  vector<int> A(an), B(bn);
  for (int i = 0; i < an; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < bn; i++) {
    cin >> B.at(i);
  }
  int amin=A.at(0),bmin=B.at(0);
  for (int i = 0; i < an-1; i++){
    if(A.at(i)>A.at(i+1)){amin=A.at(i+1);}
  }
  for (int i = 0; i < bn-1; i++){
    if(B.at(i)>B.at(i+1)){bmin=B.at(i+1);}
  }
  int min=amin+bmin;
  //わりびきなしの最小金額
  int x,y,c;
  for (int i = 0; i < m; i++){
    cin >> x >> y >> c;
    if(min>A.at(x-1)+B.at(y-1)-c){
      min=A.at(x-1)+B.at(y-1)-c;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n-1);
    rp(i,n) cin>> a.at(i);
    rp(i,n) cin >> b.at(i);
    rp(i,n-1) cin >> c.at(i);
    int sum=0;
    rp(i,n){
        a[i]--;
        sum+=b[a[i]];
        if(i>=1&&a[i]==a[i-1]+1) sum+=c[a[i-1]];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
nums = [int(s) for s in input().split()]
k = nums[0]
x = nums[1]

box = [s + x - k + 1 for s in range(k * 2 - 1)]

note = str(box[0])
for i in range(len(box) - 1):
  note += " " + str(box[i + 1])
print(note)

Measured memory_bytes: 3064
from sys import stdin
def S(): return stdin.readline().rstrip()
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()
n,k = [tmp.pop(0) for _ in range(2)]
s = list(S())
k -= 1
l = {'A':'a', 'B':'b', 'C':'c'}

s[k] = l[s[k]]

ans = ''

for i in range(n):
    ans += s[i]

print(ans)

Measured memory_bytes: 3064
import sys
import numpy as np

input = sys.stdin.readline

# N 品物の数、 W 合計の重さ
n, w = map(int, input().split())

# (W V) W : 品物の重さ V：品物の価値
lst = [list(map(int, input().split())) for ii in range(n)]

# 価値 v を最大にするので、0に初期化
# １次元は品物（インデックス0には ALL0）、２次元は重さの合計
dp = np.zeros([n+1, w+1])

for i, ln in enumerate(lst):
    # 自分の重さが入るまでは１つ前の
    dp[i+1, :ln[0]] = dp[i, :ln[0]]
    # 自分を加えられる。選ばない時と価値の高いほうをセット
    dp[i+1, ln[0]:] = np.max([dp[i, ln[0]:], dp[i, :w-ln[0]+1]+ln[1]], axis=0)

print(int(dp[n, w]))

Measured memory_bytes: 93580
#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define xx exit(0)
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#define ct continue
#define br break
#define rt return
using namespace std;
struct st{
	
};
bool cmp(){
	return 1;
}
void recur(){
	
}
void solve(){
	int d,t,s;
	cin>>d>>t>>s;
	if (t*s>=d) yy;
	else nn;
	
	
	
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while (t--) solve();
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (int i = (int)b; i < (int)e; i++)
#define forr(i, b, e)    for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    double L;
    cin>>L;
    printf("%.7lf",(L*L*L)/27.0);
}
// PLUS ULTRA!


Measured memory_bytes: 256
import java.util.Scanner;

 class Main {

    public static void main(String[] args) {


        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        String s = in.next();
        char[] str = s.toCharArray();
        str[k-1]+=32;
        //for(int i=0;i<n;i++){

            System.out.print(str);
        //}
    }

}


Measured memory_bytes: 21460
import math

A, B, H, M = map(int, input().split())

rad_H = (H+(M/60)) / 6 * math.pi
rad_M = M / 30 * math.pi

rad = abs(rad_H - rad_M)
print(math.sqrt(A**2 + B **2 - 2 * A * B * math.cos(rad)))


Measured memory_bytes: 9496
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n],b[n];
	bool isprime = true;
	int count = 0;
	for(int i=0;i<n;i++){
		isprime = true;
		cin >> a[i];
		b[i] = sqrt(a[i]);
		for(int j=2;j<b[i]+1;j++){
			if(a[i]%j==0){
				isprime = false;
				break;
			}
		}
		if(isprime==true) count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
using namespace std;
int gcd(int a, int b) { return b?gcd(b, a%b):a; }

int main()
{
  int N, X, D, ans=0;
  cin >> N >> X;
  vector<int> x(N);
  for(int n=0; n<N; ++n)
  {
    cin >> x[n];
    x[n] = abs(X-x[n]);
  }
  for(int n=0; n<N; ++n)
  {
    ans = gcd(ans, x[n]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
def main():
    from collections import deque
    s = deque(list(input()))
    q = int(input())
    query = [input().split() for _ in [0]*q]

    cnt = 0
    for i in range(q):
        if query[i][0] == "1":
            cnt += 1
        else:
            if (cnt+int(query[i][1])) % 2 == 1:
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
    if cnt % 2 == 0:
        print("".join(s))
    else:
        print("".join(list(reversed(s))))


main()

Measured memory_bytes: 44616
# include <iostream>
using namespace std;
const int N=4005;
char s[4005];
long long ans;
int main(void)
{
	int n,a[3]={};
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='R') a[0]++;
		else if(s[i]=='G') a[1]++;
		else a[2]++;
	} 
	ans=(long long )a[0]*a[1]*a[2];
	for(int i=1;i<n;i++)
	{
		for(int d=1;i+d+d<=n;d++)
		{
			if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B')) --ans;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main() {
  int n,m;cin>>n>>m;vector<int> s,g;
  rep(i,m){
    int a,b;cin>>a>>b;
    if(a == 1)s.push_back(b);
    if(b == n)g.push_back(a);
  }
  sort(g.begin(), g.end());
  rep(i,s.size()){
    if(binary_search(g.begin(), g.end(), s[i])){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}



Measured memory_bytes: 1276
X,N=map(int,input().split())
p=list(map(int,input().split()))

if p==[]: print(X); exit()

p.sort()
l,r=p[0]-1,p[-1]+1
p=set(p)
sa=float('inf')
ans=float('inf')
for i in range(l,r+1):
    if (i not in p) and (abs(X-i)<sa):
        ans=i
        sa=abs(X-i)

print(ans)



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

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int>S(N);
    vector<int>T(N);
    vector<int>X(N);
    for (int i = 0; i < N; ++i) {
      cin >> S[i] >> T[i] >> X[i];
    }
    vector<int>D(Q);
    for (int i = 0; i < Q; ++i) {
      cin >> D[i];
    }

    // S-X, T-X, XをXの降順にソートする
    vector<tuple<int, int, int>> xst(N);
    for (int i = 0; i < N; ++i) {
        xst[i] = make_tuple(X[i], S[i] - X[i], T[i] - X[i]);
    }
    sort(xst.begin(), xst.end(), greater<tuple<int, int, int>>());
    for (int i = 0; i < N; ++i) {
        X[i] = get<0>(xst[i]);
        S[i] = get<1>(xst[i]);
        T[i] = get<2>(xst[i]);
    }


    // 時刻[S_i, T_i)に出発するとiにぶち当たる
    // 複数の工事があるならiの大きい工事が優先される
    // 時刻t以降次に更新されるまでの進む距離(t, x)をpairで持つ
    vector<pair<int, int>> dist;
    dist.reserve(2*N);
    dist.push_back(make_pair(0, -1));

    vector<pair<int, int>> timeline;
    timeline.reserve(2*N);
    for (int i = 0; i < N; ++i) {
        timeline.push_back(make_pair(S[i], i));
        timeline.push_back(make_pair(T[i], -1)); // 同時刻ならこっちが先
    }
    sort(timeline.begin(), timeline.end());

    // 工事中のものを入れるヒープ
    priority_queue<int, vector<int>> que;

    for (int i = 0; i < timeline.size(); ++i) {
        int t = timeline[i].first;
        int k = timeline[i].second;

        if(k == -1 && ! que.empty() && T[que.top()] <= t){
            int flag = 0;
            while (T[que.top()] <= t){
                que.pop();
                if(que.empty()){
                    flag = 1;
                    dist.push_back(make_pair(t, -1));
                    break;
                }
            }
            if(flag == 0){
                dist.push_back(make_pair(t, X[que.top()]));
            }
        } else if(k != -1){
            if(que.empty()){
                que.push(k);
                dist.push_back(make_pair(t, X[k]));
            } else{
                if(que.top() < k){
                    dist.push_back(make_pair(t, X[k]));
                }
                que.push(k);
            }
        }
    }

    vector<ll> ans(Q);
    // tが同じものがいっぱいあるなら最後のものを取る
    for (int i = 0; i < Q; ++i) {
        auto iter = lower_bound(dist.begin(), dist.end(), make_pair(D[i]+1, -1));
        iter--;
        auto p = *iter;
        ans[i] = p.second;
    }

    for (int i = 0; i < Q; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 14976
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut map = HashMap::new();
    let mut ans = 0;

    for ai in a {
        *map.entry(ai).or_insert(0) += 1;
    }

    for (key, val) in map.iter() {
        ans += if val >= key { val - key } else { *val };
    }
    println!("{}", ans);
}

Measured memory_bytes: 7072
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N - 1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      int tmp;
      cin >> tmp;
      tmp--;
      A[i][j] = tmp;
    }
  }

  int ans = 0;
  int done = 0;
  vector<int> cur(N, 0);
  unordered_map<int, int> mp;
  while (done != N) {
    bool proceed = false;
    for (int i = 0; i < N; i++) {
      if (mp[i] == (ans + 1) || cur[i] == (N - 1)) {
        continue;
      }
      int a = A[i][cur[i]];
      if (mp[a] == (ans + 1) || cur[a] == (N - 1)) {
        continue;
      }
      int b = A[a][cur[a]];
      if (b == i) {
        proceed = true;
        cur[i]++;
        cur[a]++;
        mp[i] = (ans + 1);
        mp[a] = (ans + 1);
        if (cur[i] == (N - 1)) {
          done++;
        }
        if (cur[a] == (N - 1)) {
          done++;
        }
      }
    }
    if (!proceed) {
      cout << -1 << endl;
      return 0;
    }
    ans++;
    if (ans > 50000) {
      cout << 499500 << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	int a,b;
	scanf("%d %d",&a,&b);
	if(a%3==0 || b%3==0 || (a+b)%3==0)printf("Possible");
	else printf("Impossible");
	return 0;
}

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

const int N = 1e5 + 10;

int n, a[N], val[N], s[N];

int bit[N * 2 + 10];

void modify(int x) {
	x += n + 2;
	for( ; x <= 2 * n + 10; x += x & -x) ++ bit[x];
}

int query(int x) {
	x += n + 2;
	int res = 0;
	for( ; x ; x -= x & -x) res += bit[x];
	return res;
}

int check(int val) {
	// puts("go 1");
	for(int i = 0 ; i <= 2 * n + 10 ; ++ i) bit[i] = 0;
	for(int i = 1 ; i <= n ; ++ i) {
		if(a[i] <= val) s[i] = 1;
		else s[i] = -1;
		s[i] += s[i - 1];
	}
	long long res = 0, len = 1ll * n * (n + 1) / 2;
	modify(0);
	for(int i = 1 ; i <= n ; ++ i) {
		res += query(s[i] - 1);
		modify(s[i]);
	}
	return res >= len / 2 + 1;
}

int main() {
	scanf("%d", &n);
	for(int i = 1 ; i <= n ; ++ i) {
		scanf("%d", &a[i]);
		val[i] = a[i];
	}
	sort(val + 1, val + 1 + n);
	int k = unique(val + 1, val + 1 + n) - val - 1;
	int l = 1, r = k, ans = 0;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(check(val[mid])) {
			ans = val[mid];
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	printf("%d\n", ans);
}


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

using namespace std;

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

int dp[1000005];

void solve() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  for(int i = 1; i < s.size(); i++) {
    if(s[i-1] == 'A' && s[i] == 'C') dp[i]++;
  }
  for(int i = 2; i <= s.size(); i++) dp[i] += dp[i-1];
  while(q--) {
    int a, b;
    cin >> a >> b;
    cout << dp[--b] - dp[--a] << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Measured memory_bytes: 1488
from math import sqrt

N = int(input())

ans = float('inf')

for a in range(1, int(sqrt(N)) + 1):
  if N % a == 0:
    A = str(a)
    B = str(N // a)
    F = max(len(A), len(B))
    ans = min(ans, F)

print(ans)

Measured memory_bytes: 3060
n = int(input())
t = [int(input()) for _ in range(n)]

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

l = t[0]
for i in range(1, n):
    g = gcd(l, t[i])
    l = l*t[i] // g
    
print(l)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

string s;

int main(){
    cin>>s;
    bool flag=true;
    rep(i,0,s.size()){
        if(i%2==0){
            if(s[i]=='L') flag=false;
        }
        else{
            if(s[i]=='R') flag=false;
        }
    }
    if(flag) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  int mx = *max_element(a.begin(), a.end());
  for (int i = 0; i < n; i++) if (a[i] == mx) {
    cout << a[i] + b[i] << '\n';
    break;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  string X , Y;
  cin >> X >> Y;

  if(X == Y)
    cout << "=" << endl;
  else if(X > Y)
    cout << ">" << endl;
  else
    cout << "<" << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
flag = True
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 5 == 0 or a[i] % 3 == 0:
            pass
        else:
            flag = False
if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a = list(map(lambda x:x-1,a))

#閉路を検知する

visitted = [-1] * n
cur_town = 0
town_cnt = 0
visitted[0]=town_cnt
town_cnt+=1
while True:
    next_town = a[cur_town]
    if visitted[next_town]==-1:
        visitted[next_town]=town_cnt
        town_cnt+=1
        cur_town=next_town
    else:
        break

last_move = (k-town_cnt)%(town_cnt-visitted[next_town])
if k < town_cnt:
    print(visitted.index(k)+1)
else:
    cur_town=next_town
    for _ in range(last_move):
        next_town = a[cur_town]
        cur_town=next_town
    print(cur_town+1)

Measured memory_bytes: 32380
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n;
    int h[100010];
    int graph[101][101] = {0};
    int mh = 0;
    int ans = 0;
    bool flg = false;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> h[i];
        for (int j = 0; j < h[i]; j++) {
            graph[i][j] = 1;
        }
        if (mh < h[i]) mh = h[i];
    }

    for (int i = 0; i < mh; i++) {
        for (int j = 0; j < n; j++) {
            if (graph[j][i] == 1) flg = true;

            if (graph[j][i] == 0 && flg == true) {
                flg = false;
                ans++;
            }
        }
        if (flg == true) {
            flg = false;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int hill[10];
	int i, j, n, x, max = 0;

	for(i = 0; i < 10; i++) {
		scanf("%d", &n);
		hill[i] = n;
	}

	for(i = 0; i < 3; i++) {
		for(j = 0; j < 10; j++) {
			if(hill[j] > max) {
				max = hill[j];
				x = j;
			}
		}
		printf("%d\n", max);
		hill[x] = 0;
		max = 0;
	}

	return 0;
}

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

using namespace std;

int main(){

	int n;

	cin>>n;
	cout<<n<<":";
	for(int i=2;i<=sqrt((double)n);){
		if(n%i==0){
			cout<<" "<<i;
			n/=i;
		}
		else i++;
	}
	if(n!=0) cout<<" "<<n;
	cout<<endl;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;


int fibonacci(int n)
{
	int preFib = 1;
	int prepreFib = 1;
	int fib;

	if (n <= 1) {
		return 1;
	}

	for (int i = 2; i <= n; i++) {
		fib = preFib + prepreFib;
		prepreFib = preFib;
		preFib = fib;
	}

	return fib;

}

int main(void)
{
	int n;
	cin >> n;
	cout << fibonacci(n) << endl;

	return 0;
}

Measured memory_bytes: 3064
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 2e5 + 10;

ll a[N];

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	set<ll> s;
	s.insert(0);
	ll offset = 1, ans = 0;
	for (int i = n; i >= 1; --i) {
		--offset;
		if (*s.rbegin() + offset > a[i]) {
			cout << -1;
			return 0;
		}
		s.insert(a[i] - offset);
		s.insert(0 - offset);
		s.erase(-1 - offset);
		ans += s.size() - 1;
	}
	if (*s.rbegin() + offset > 0) {
		cout << -1;
	} else {
		cout << ans;
	}
}

Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 絶対値を求める
UInt Abs(const Int a) {
    return a > 0 ? a : -a;
}

void PermutationLoop(Int n, vector<Int>& p, vector<Int>& q) {
    vector<Int> v(n);  
    for (Int i = 0; i < n; ++i) {
        v[i] = i;
    }
    Int cnt = 0;
    Int pPermuPosi = -1;
    Int qPermuPosi = -1;
    do {
        bool isSameAsP = true;
        bool isSameAsQ = true;
        for (Int i = 0; i < n; ++i) {
            if (v[i] != p[i]) {
                isSameAsP = false;
            }
            if (v[i] != q[i]) {
                isSameAsQ = false;
            }
        }
        if (isSameAsP == true) {
            pPermuPosi = cnt;
        }
        if (isSameAsQ == true) {
            qPermuPosi = cnt;
        }
        ++cnt;
    } while (std::next_permutation(v.begin(), v.end()));
    cout << Abs(pPermuPosi - qPermuPosi) << endl;
    return;
}

int main(void) {
    // 入出力処理
    Int n; // ループする回数 n! を決めるパラメータ
    cin >> n;
    vector<Int> p(n);
    vector<Int> q(n);
    for (Int i = 0; i < n; ++i) {
        cin >> p[i];
        --p[i];
    }
    for (Int i = 0; i < n; ++i) {
        cin >> q[i];
        --q[i];
    }
    PermutationLoop(n, p, q);
    return 0;
}



Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=1000000007;

int main(){
	string s;
	cin>>s;
	string str=s.substr(0,3);
	puts(str);
}

Measured memory_bytes: 3628
MAX = 1000000007

m, n = [int(x) for x in input().split(' ')]
bi_n = bin(n)

ans = 1
dig = m
for i in range(len(bi_n)-1, 1, -1):
    if bi_n[i] == '1': ans *= dig
    if ans >= MAX: ans %= MAX
    dig *= dig
    if dig >= MAX: dig %= MAX

print(ans)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n, k;
  in2(n, k);
  vector<ll> c(n), d(n - k + 1);
  rep(i, n)
    in(c[i]);
  a = 9999999999999;
  rep(i, n - k + 1){
    b = c[i + k - 1] - c[i];
    d[i] = min(abs(c[i]) + b, abs(c[i + k - 1]) + b);
    a = min(a, d[i]);
  }
  out(a);
  memi;
}

Measured memory_bytes: 1408
n = int(input())
c = [0] * (n - 1)
s = [0] * (n - 1)
f = [0] * (n - 1)
for i in range(n - 1):
    c[i], s[i], f[i] = map(int, input().split())
for i in range(n - 1):
    a = 0
    for j in range(i, n - 1):
        if a <= s[j]:
            a = s[j]
        else:
            b = a - s[j]
            if b % f[j] > 0:
                a -= b
                a += (b // f[j]) * f[j]
                a += f[j]
        a += c[j]
    print(a)
print(0)

Measured memory_bytes: 3188
import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())

    a_dict = collections.Counter(a)
    a_dict = {key: key*value for key, value in a_dict.items()}
    answer = sum(a_dict.values())
    for _ in range(q):
        b, c = map(int, input().split())
        diff = 0
        if b in a_dict:
            b_sum = a_dict.pop(b)
            c_add = b_sum//b * c
            diff = c_add - b_sum
            if c in a_dict:
                a_dict[c] += c_add
            else:
                a_dict[c] = c_add
        answer += diff
        print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22624
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    for(int i=0; i<k; i++) c *= 2;
    for(int i=0; i<k; i++) {
        if(a < b && b < c) {
            cout << "Yes" << endl;
            return 0;
        }
        c /= 2;
        b *= 2;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3600
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let a: usize = sc.read();
    let mut b: String = sc.read::<String>();
    b.retain(|x| x != '.');

    let ans = a * b.parse::<usize>().unwrap() / 100;
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
if (a<c && c<b) {
  cout << "Yes" << endl;
return 0;
}
if (b<c && c<a) {
  cout << "Yes" << endl;
return 0;
}
  cout << "No" << endl;
}
  

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

using ll = long long;
const int INF = 1e9+7;

void solve(){
	int n;cin >> n;
	ll ans = 0;
	vector<int> hash(n);
	for(auto &x:hash) cin >> x;
	for(int i = 0;i<n;++i){
		for(int j = i+1;j<n;++j){
			ans += hash[i]*hash[j];
		}
	}
	cout << ans << '\n';}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int t=1;
//	int t;cin >> t;
	while(t--) solve();
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int f[10]={0};
  for(int i=0; i<4; ++i){
    int x;
    cin >> x;
    if(x<10)f[x]=1;
  }
  if(f[1] && f[9] && f[7] && f[4])cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy3

import collections
import itertools


DELTAS = [(1, 0), (-1, 0), (0, 1), (0, -1)]


class UnitDict(dict):

    def __init__(self, iterable=None, wrapper=lambda x: x):
        super().__init__(self)
        self.wrapper = wrapper
        if iterable is not None:
            self.update(iterable)

    def __missing__(self, key):
        self[key] = self.wrapper(key)
        return self[key]


class DisjointSetDataStructure(object):

    def __init__(self, nodes=None):
        self.par = UnitDict(wrapper=lambda x: x)
        self.rank = collections.defaultdict(int)
        self.groups = UnitDict(wrapper=lambda x: {x})
        if nodes is not None:
            for node in nodes:
                _, _, _ = self.par[node], self.rank[node], self.groups[node]
        
    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r
    
    def in_the_same_set(self, node1, node2):
        return self.root(node1) == self.root(node2)
    
    def elements_of_group(self, node):
        return self.groups[self.root(node)]
 
    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            self.par[y] = x
            self.groups[x].update(self.groups[y])
            self.groups[y].clear()
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def solve(h, w, stage):
    dds = DisjointSetDataStructure()
    for r0, c0 in itertools.product(range(h), range(w)):
        cell0 = stage[r0][c0]
        for dr, dc in DELTAS:
            r, c = r0 + dr, c0 + dc
            if 0 <= r < h and 0 <= c < w and cell0 != stage[r][c]:
                dds.unite((r0, c0), (r, c))
    res = 0
    for nodes in dds.groups.values():
        num_total = len(nodes)
        num_black = sum(stage[r][c] for r, c in nodes)
        res += num_black * (num_total - num_black)
    return res


def main():
    h, w = (int(z) for z in input().split())
    stage = [[c == "#" for c in input()] for _ in range(h)]
    res = solve(h, w, stage)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 123224
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <map>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<string, int> dic;
	string str;
	int n;
	cin >> n;
	int ans=0;
	rep(i, n) {
		cin >> str;
		dic[str]++;
		ans = max(ans,dic[str]);
	}

	for (auto e : dic) {
		if (e.second == ans)
			cout << e.first<<endl;
	}
}

Measured memory_bytes: 19276
#include<bits/stdc++.h>
using namespace std;
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m,d,a[200]={},b[200]={},c[200]={},e=0;
  cin>>m>>d;
  for(int i=1;i<=m;i++){
    a[i]=i;
  }
  for(int j=1;j<=d;j++){
    b[j]=j;
    c[j]=b[j]%10;
    b[j]=b[j]/10;
  }
  for(int i=1;i<=m;i++){
    for(int j=1;j<=d;j++){
      if(a[i]==b[j]*c[j] && b[j]!=1 && c[j]!=1){
	e++;
      }
    }
  }
  cout<<e<<"\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
//#include<string>
//#include<sstream>
using namespace std;
int main()
{
    int n,i,min=0;
    double b[1000],c[1000],t,a;
    scanf("%d",&n);
    scanf("%lf%lf",&t,&a);
    for(i=0;i<n;i++)
    {
    	scanf("%lf",&b[i]);
    	c[i]=abs(t-b[i]*0.006-a);
    	if(c[i]<c[min])
    		min=i;
	}
	printf("%d\n",min+1);
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>

#include <cstdio>

template<typename T, size_t MAX_N>
class BIT
{
	public:
		BIT(size_t n) : _bit(), _n(n) {}

		T sum(size_t i)
		{
			T r = 0;
			while (i > 0)
			{
				r += _bit[i];
				i &= (i - 1);
			}
			return r;
		}

		void add(size_t i, T x)
		{
			while (i <= _n)
			{
				_bit[i] += x;
				i += i & -i;
			}
		}

	protected:
		T _bit[MAX_N + 1];
		size_t _n;
};

int main()
{
	int n;
	long long d, a;
	scanf("%d%lld%lld", &n, &d, &a);
	using pair = std::pair<long long, long long>;
	pair enemy[200000];
	for (int i = 0; i < n; ++i)
	{
		long long x, h;
		scanf("%lld%lld", &x, &h);
		enemy[i].first = x;
		enemy[i].second = h;
	}
	std::sort(enemy, enemy + n);
	BIT<long long, 200000> bit0(n);
	BIT<long long, 200000> bit1(n);
	auto pquery = [&](int x)
	{
		return (bit1.sum(x) * x + bit0.sum(x)) - (bit1.sum(x - 1) * (x - 1) + bit0.sum(x - 1));
	};
	long long ans = 0;
	for (int i = 0; i < n; ++i)
	{
		long long left = enemy[i].second - pquery(i + 1);
		if (left <= 0) continue;
		long long l = enemy[i].first;
		long long r = l + 2 * d;
		int ub = std::upper_bound(enemy, enemy + n, pair{r, 0}, [](auto& a, auto& b){ return a.first < b.first; }) - enemy;
		long long times = (left + a - 1) / a;
		ans += times;
		long long bomb = times * a;
		bit0.add(i + 1, -bomb * i);
		bit1.add(i + 1, bomb);
		bit0.add(ub + 1, bomb * ub);
		bit1.add(ub + 1, -bomb);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6400
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int a;
    vector<int> v;
    while(cin >> a) v.push_back(a);
    sort(v.begin(), v.end(), greater<int>());
    printf("%d\n%d\n%d\n", v[0], v[1], v[2]);
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=ll(1e18)+1;
ll n,k;
bool ok(ll x,vector<ll> a){
    ll total=0;
    for(int i=0; i<n; i++){
        if(a[i]<0){
            int l=-1,r=n;
            while(r-l>1){
                int mid=(r+l)/2;
                if(a[mid]*a[i]<x) r=mid; else l=mid;
            }
            total+=n-r;
        }
        else{
            int l=-1,r=n;
            while(r-l>1){
                int mid=(r+l)/2;
                if(a[mid]*a[i]<x) l=mid; else r=mid;
            }
            total+=l+1;
        }
        if(a[i]*a[i]<x) total--;
    }
    total/=2;
    return total<k;
}
int main(){
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll l=-LINF,r=LINF;
    while(r-l>1){
        ll x=(r+l)/2;
        if(ok(x,a)) l=x;
        else r=x;
    }
    cout << l << endl;
    return 0;
}

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

const int mxn = 262150;
const int mxl = 1e5 + 1;
int n, q, v[mxn], w[mxn], dp[513][mxn];
	
int main() {
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i=1; i<=min(511, n); i++) {
		int p = i / 2;
		for (int j=0; j<mxl; j++) {
			dp[i][j] = dp[p][j];
			if (j - w[i] >= 0) {
				dp[i][j] = max(dp[i][j], dp[p][j - w[i]] + v[i]);
			}
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	cin >> q;
	while (q--) {
		int u, l;
		cin >> u >> l;
		vector<int> path;
		while (u > min(511, n)) {
			path.push_back(u);
			u /= 2;
		}
		int sz = path.size();
		int ans = 0;
		for (int i = 0; i < (1 << sz); i++) {
			int tw = 0, tv = 0;
			for (int j = 0; j < sz; j++) {
				if (i & (1 << j)) {
					tw += w[path[j]];
					tv += v[path[j]];
				}
			}
			if (l - tw >= 0) {
				ans = max(ans, dp[u][l - tw] + tv);
			}
		}
		cout << ans << '\n';
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;

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

    int n;
    cin >> n;

    vector<ld> x(n), y(n);
    vector<char> d(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i] >> d[i];

    auto f = [&](const ld t) {
        pair<ld, ld> dx, dy;
        for (int i = 0; i < n; ++i) {
            ld vx = x[i], vy = y[i];

            if (d[i] == 'R') vx += t;
            else if (d[i] == 'L') vx -= t;
            else if (d[i] == 'U') vy += t;
            else if (d[i] == 'D') vy -= t;

            if (i == 0) {
                dx = make_pair(vx, vx);
                dy = make_pair(vy, vy);
            }
            else {
                dx.first = min(dx.first, vx);
                dx.second = max(dx.second, vx);
                dy.first = min(dy.first, vy);
                dy.second = max(dy.second, vy);
            }
        }
        return (dx.second - dx.first) * (dy.second - dy.first);
    };

    ld v = f(0), lb = 0, ub = 2 * 1e9;
    for (int i = 0; i < 200; ++i) {
        const ld t1 = (2.0 * lb + ub) / 3.0;
        const ld t2 = (lb + 2.0 * ub) / 3.0;

        v = min(v, f(t1));
        v = min(v, f(t2));

        if (f(t1) > f(t2)) lb = t1;
        else ub = t2;
    }

    // cout << f(lb) << endl;
    cout << v << endl;

    return 0;
}


Measured memory_bytes: 3584
N,K = map(int,input().split())

A = list(map(int,input().split()))


for loop in range(K):

    if min(A) == N:
        break

    end = [0] * N
    now = 0
    nA = [0] * N

    for i in range(N):

        if i+A[i] < N:
            end[i+A[i]] += 1
        now += 1

        nA[i] += now

        now -= end[i]

    end = [0] * N
    now = 0

    for i in range(N-1,-1,-1):

        nA[i] += now

        if i-A[i] >= 0:
            end[i-A[i]] += 1
        now += 1
        
        now -= end[i]

    A = nA

#print (cnt)
print (*A)


Measured memory_bytes: 170380
n=int(input())
s=list(input())
sw=[0]
se=[0]
swc=0
sec=0
for i in range(n):
    if s[i]=='W':
        swc+=1
    else:
        sec+=1
    sw.append(swc)
    se.append(sec)
m=n
for i in range(n+1):
    m=min(m,sw[i]+se[-1]-se[i])
print(m)

Measured memory_bytes: 25492
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e17;
ll mod = 1000000007;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  ll arr[n + 5];
  ll flag = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] != i)
      flag = 1;
  }
  if (flag == 0) {
    cout << "YES" << en;
    return 0;
  }
  ll cnt = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      swap(arr[i], arr[j]);
      ll flag = 0;
      for (ll i = 1; i <= n; i++) {
        if (arr[i] != i)
          flag = 1;
      }
      if (flag == 0) {
        cout << "YES" << en;
        return 0;
      }
      swap(arr[i], arr[j]);
    }
  }

  cout << "NO" << en;

  return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

const ll P = 1e9+7;

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

    string S;
    cin >> S;

    map<char,int> Alpha;
    for(int i=0;i<N;i++)
    {
        Alpha[S[i]]++;
    }

    ll ans = 1;

    for(auto x : Alpha)
    {
        ans *= (x.second+1);
        ans %= P;
    }

    cout << ans-1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i;
	int a[100005];
	for (i = 0;i < n;i++)
		scanf("%d", &a[i]);
	int x;
	for (i = 0;i < n;i++)
		if (a[i] == 1)
			x = i;
	int ans = 0;
	k--;
	ans += (x + k - 1) / k;
	n -= x + 1;
	if (x%k > 0)
		n -= k - (x%k);
	if (n > 0)
		ans += (n + k - 1) / k;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define N 100

int main(){
  int i,j,n,u,k,v;
  int G[N][N];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      G[i][j]=0;

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      G[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",G[i][j]);
      if(j!=n-1)
	printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
 
N, Q = map(int,input().split())
S = input()
nums = [0] * (N + 1)
for i in range(N):
  nums[i+1] = nums[i] + (1 if S[i:i+2]=='AC' else 0)
    
for j in range(Q):
  l, r = map(int,input().split())
  print(nums[r-1] - nums[l-1])

Measured memory_bytes: 7916
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int D [] = new int[N];
        Arrays.fill(D,0);
        for(int i=1;i<N;i++){
            for(int j=i+1;j<=N;j++){
                int num = Math.min(Math.abs(j-i),Math.abs(X-i)+1+Math.abs(Y-j));
                num = Math.min(num,Math.abs(Y-i)+1+Math.abs(X-j));
                D[num]++;
            }
        }
        for(int i=1;i<N;i++) System.out.println(D[i]);
    }
}

Measured memory_bytes: 22100