akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd, sqrt
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m, k = LI()
A = LI()
B = LI()
a_acc = [0] + list(accumulate(A))
b_acc = [0] + list(accumulate(B))
ans = 0
for i in range(n + 1):
    if a_acc[i] > k:
        continue
    idx = bisect_right(b_acc, k - a_acc[i])
    ans = max(ans, i + idx - 1)

print(ans)



Measured memory_bytes: 135212
#include <cstdio>

int main()
{
    int a, b, c, d, e, k;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    scanf("%d", &k);

    if(e-a > k)
        printf(":(\n");
    else
        printf("Yay!\n");
    return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string t;
bool n, s, w, e;

int main() {
    cin >> t;
    n = s = w = e = false;
    for (char c : t) if (c == 'N') n = true;
    else if (c == 'S') s = true;
    else if (c == 'W') w = true;
    else if (c == 'E') e = true;
    if ((n + s) == 1 || (w + e) == 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int N; cin >> N;
    VI n(4,0);

    REP(i,N){
        string s; cin >> s;
        if(s=="AC") n[0]++;
        else if(s=="WA") n[1]++;
        else if(s=="TLE") n[2]++;
        else n[3]++;
    }

    cout << "AC x " << n[0] << en;
    cout << "WA x " << n[1] << en;
    cout << "TLE x " << n[2] << en;
    cout << "RE x " << n[3] << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3656
import collections

n = int(input())
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
a_t = collections.Counter(sorted(a_t))
ans = 0
for i in a_t.values():
    ans += i * (i - 1) // 2
print(ans)

Measured memory_bytes: 43244
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;

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;
}


int main() {
  ll X, Y; cin >> X >> Y;
  int ans = 0;
  while (true){
    if(X > Y) break; 
    ans++;
    X = 2*X;
  }
  cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	inline char getc(){
		char c=getchar();
		while(c!='0' && c!='1') c=getchar();
		return c;
	}

	const int N=5009;
	int s[N],t[N],n,a[N],b[N],top1,top2;
	int main(){
		n=read<int>();
		for(int i=1;i<=n;i++) s[i]=getc()-'0';
		for(int i=1;i<=n;i++) t[i]=getc()-'0';
		for(int i=1;i<n;i++) if(s[i]^s[i+1]) a[++top1]=i;
		for(int i=1;i<n;i++) if(t[i]^t[i+1]) b[++top2]=i;

		int ans=n*n;
		for(int i=-top1-1;i<=top2+1;i++) if(s[1]^t[1]^(~i&1)){
			int ret=0;
			for(int j=min(1,1-i);j<=max(top1,top2-i);j++)
				ret+=abs(((j<0)?0:((j>top1)?n:a[j]))-((j+i<0)?0:((j+i>top2)?n:b[j+i])));
			ans=min(ans,ret);
		}
		printf("%d\n",ans);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 3836
# -*- coding: utf-8 -*-

################ DANGER ################
test = ""
test = \
"""

"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
        
n = int(input2())

def primes(n):
    ps = [2]
    for odd in range(3, n + 1, 2):
        for p in ps:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                ps.append(odd)
                break
    return ps


def isprime(n):
    last = int(n**.5)
    for m in primes(last):
        if n % m == 0:
            return False
    return True


def nextprime(n):
    if n in primes(n):
        return n
    elif n == 1:
        return 2
    else:
        i = n
        while not isprime(i):
            i += 1
        return i


print(nextprime(n))

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

bool is_even(int n) {
  return (n % 2 == 0);
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  ll sum;

  // 第1項を正とする場合
  ll p1_ans = 0;
  sum = 0;
  for (int i = 0; i < n; i++) {
    ll n = a.at(i);
    sum += n;

    // 添字が偶数番号の場合、和が正の数であることを期待する
    // 和が負の数の場合、正の数の最小値 +1 になるまで操作を繰り返す
    if (is_even(i)) {
      if (sum <= 0) {
        ll diff = 1 - sum;
        p1_ans += diff;
        sum += diff;
      }
    // 添字が奇数番号の場合、和が負の数であることを期待する
    // 和が正の数の場合、負の数の最小値 -1 になるまで操作を繰り返す
    } else {
      if (sum >= 0) {
        ll diff = sum - (-1);
        p1_ans += diff;
        sum -= diff;
      }
    }
  }

  // 第1項を負とする場合
  ll p2_ans = 0;
  sum = 0;
  for (int i = 0; i < n; i++) {
    ll n = a.at(i);
    sum += n;

    // 添字が偶数番号の場合、和が負の数であることを期待する
    // 和が正の数の場合、負の数の最小値 -1 になるまで操作を繰り返す
    if (is_even(i)) {
      if (sum >= 0) {
        ll diff = sum - (-1);
        p2_ans += diff;
        sum -= diff;
      }
    // 添字が奇数番号の場合、和が正の数であることを期待する
    // 和が負の数の場合、正の数の最小値 +1 になるまで操作を繰り返す
    } else {
      if (sum <= 0) {
        ll diff = 1 - sum;
        p2_ans += diff;
        sum += diff;
      }
    }
  }

  cout << min(p1_ans, p2_ans) << endl;
  return 0;
}


Measured memory_bytes: 1024
S = input()
Answer = 0
for i in range(len(S)):
    counter = 0
    for j in range(len(S)-i):
        if S[j] in ['A','C', 'G','T']:
            counter += 1
            if Answer < counter:
                Answer = counter
            j = i + 1
        else:
            counter = 0
print(Answer)

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

using namespace std;

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

	int answer = 1;
	for (int i = 0; i < N; i++) {
		if (answer <= K) {
			answer *= 2;
		} else {
			answer += K;
		}
	}

	cout << answer << endl;
	return 0;
}


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

typedef long long int int64;
static const int64 mod = 998244353LL;
int64 exgcd(int64 a,int64 b,int64 &c,int64 &d)
{
	if(b == 0) {
		c = 1, d = 0;
		return a;
	}
	int64 k = exgcd(b,a%b,d,c);
	d -= c * (a / b);
	return k;
}
int64 finv(int64 x)
{
	int64 a,b;
	exgcd(x,mod,a,b);
	if(a < 0) a += mod;
	return a;
}
int64 dp[2][403][403];

int n;
int a[403],b[403];
int64 p[403];
int64 fac[403],inv[403],invfac[403];
int main()
{
	fac[0] = fac[1] = inv[1] = invfac[0] = invfac[1] = 1;
	for(int i = 2;i <= 400;++i) {
		fac[i] = (fac[i-1] * i) % mod;
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		invfac[i] = (invfac[i-1] * inv[i]) % mod;
	}
	scanf("%d",&n);
	int s = 0;
	for(int i = 0;i < n;++i) {
		scanf("%d%d",&a[i],&b[i]);
		s += a[i];
	}
	int64 invs = finv(s);
	for(int i = 0;i < n;++i) {
		p[i] = invs * a[i] % mod;
	}
	int cnt = 0,cnt2 = 0;
	int f = 0;
	dp[f][0][0] = 1;
	for(int i = 0;i < n;++i) {
		memcpy(dp[f^1],dp[f],sizeof(dp[0]));
		int64 val = 1;
		for(int j = 0;j < b[i];++j) {
			for(int k = 0;k <= cnt;++k) {
				for(int l = 0;l <= cnt2;++l) {
					dp[f^1][k+j][l+a[i]] = (dp[f^1][k+j][l+a[i]] - dp[f][k][l] * invfac[j] % mod * val) % mod;
				}
			}
			val = val * a[i] % mod;
		}
		cnt += b[i] - 1;
		cnt2 += a[i];
		f ^= 1;
	}
	int64 ans = 0;
	for(int k = 0;k <= cnt2;++k) {
		int64 val = 1;
		for(int j = 0;j <= cnt;++j) {
			if(j == 0 && k == 0) continue;
			ans += dp[f][j][k] * fac[j] % mod * inv[k] % mod * s % mod * val % mod;
			val = val * inv[k] % mod;
		}
	}
	ans = -ans % mod;
	if(ans < 0) ans += mod;
	printf("%lld\n", ans % mod);
}


Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    char c;
    cin >> c;
    int a = c-'0';
    a += 1;
    char b = a + '0'; 
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
using namespace std;
int n,nw,sl,fh;
LL S;
struct node
{
	int a,b;
	bool operator <(const node &x)const {return b<x.b;}
}s[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i) s[i].a=rd(),s[i].b=rd();
	sort(s+1,s+n+1);
	for(int i=1;i<=n;++i)
	{
		if(S+s[i].a>s[i].b) {puts("No"); return 0;}
		S+=s[i].a;
	}	
	puts("Yes");
	return 0;
}

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

#define int long long
#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 all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sgn(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, K;
signed main() {
    cin >> N >> K;
    if (N - 2 * K + 1 < 0) { fin(-1); }
    if (N == 1) { fin("1 2 3"); }
    int a = N / 2 - 1, b = 1, c = 0;
    rep(i, N) {
        cout << K + a << " " << K + N + b << " " << K + 2 * N + c << endl;
        (a += N - 1) %= N, (b += 2) %= N, c++;
        if (b == 1) { b = 0; }
    }
}

Measured memory_bytes: 3592
use proconio::marker::Usize1;
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        ab: [(Usize1,Usize1);m],
    }
    let mut uf=vec![-1;n];
    for (a,b) in ab {
        unite(&mut uf, a, b);
    }
    println!("{}",(0..n).map(|i|count(&mut uf,i)).max().unwrap());
}
fn find(uf: &mut Vec<i32>, i: usize) -> usize {
    if uf[i]<0 {
        i
    }
    else {
        uf[i]=find(uf, uf[i]as usize)as i32;
        uf[i]as usize
    }
}
fn unite(uf: &mut Vec<i32>, i: usize, j: usize) {
    let mut i=find(uf, i);
    let mut j=find(uf, j);
    if i==j {
        return;
    }
    if uf[i]>uf[j] {
        std::mem::swap(&mut i, &mut j);
    }
    uf[i]+=uf[j];
    uf[j]=i as i32;
}
fn count(uf: &mut Vec<i32>, i: usize) -> usize {
    let i=find(uf, i);
    (-uf[i])as usize
}

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

int main(){
  int N;cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  sort(A.begin(),A.end());
  cout<<A.at(N-1)-A.at(0)<<endl;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        long result = 0L;
        for(int a=1; a<=K; a++) {
            for(int b=1; b<=K; b++) {
                int gcd_ab = gcd(a, b);
                for(int c=1; c<=K; c++) {
                    int gcd_abc = gcd(gcd_ab, c);
                    result+=gcd_abc;
                }
            }
        }
        System.out.println(String.format("%d", result));
    }
    static int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}


Measured memory_bytes: 35920
import java.math.BigInteger;
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[] A = new int[N];

        Map<Integer, Integer> m = new HashMap<>();
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(scanner.next());
            for(Map.Entry<Integer, Integer> e: factorize(A[i]).entrySet()) {
                int max = Math.max(m.getOrDefault(e.getKey(), 0), e.getValue());
                m.put(e.getKey(), max);
            }
        }

        long lcm = 1;
        for(Map.Entry<Integer, Integer> e: m.entrySet()) {
            for (int i = 0; i < e.getValue(); i++) {
                lcm *= e.getKey();
                lcm %= MOD;
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            long inv = pow(A[i], MOD - 2, MOD);
            ans += lcm * inv % MOD;
            ans %= MOD;
        }

        System.out.println(ans);
    }

    // Tested on AOJ
    static TreeMap<Integer, Integer> factorize(int n) {
        TreeMap<Integer, Integer> primes = new TreeMap<>();
        for (int i = 2; i * i <= n; i++) {
            while (n % i == 0) {
                primes.put(i, primes.getOrDefault(i, 0) + 1);
                n /= i;
            }
        }
        if (n != 1) {
            primes.put(n, 1);
        }
        return primes;
    }

    static long pow(long x, long n, long mod) {
        long res = 1;
        while (n > 0) {
            if ((n & 1) > 0) {
                res = res * x % mod;
            }
            x = x * x % mod;
            n >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 35524
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll n,b;
	cin>>n;
	double a=sqrt(n);
	for(int i=1;i<=a;i++){
		b=i;
	}
	cout << b*b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-a)>abs(x-b)) {
    cout << "B" << endl;
  }
  else {
    cout << "A" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int n;	
	int c[1001][1001];
	string str1, str2;

	cin >> n;

	for (int k = 0; k < n; k++) {
		int Max = 0;
		cin >> str1 >> str2;
		
		int m = str1.size();
		int n = str2.size();


		str1 = ' ' + str1;
		str2 = ' ' + str2;

		//cout << str1 << str2 << endl;


		for (int i = 0; i <= m; i++) {
			for (int j = 0; j <= n; j++) {
				if (i == 0 || j == 0) c[i][j] = 0;
				else if (str1[i] == str2[j]) c[i][j] = c[i - 1][j - 1] + 1;
				else c[i][j] = max(c[i][j - 1], c[i - 1][j]);

				Max = max(Max, c[i][j]);

				//cout << c[i][j] << " ";

			}

			//cout << endl;

		}

		cout << Max << endl;
	}

	return 0;

}


Measured memory_bytes: 7128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
  
  int nyu;
  
  int sums=0;
  int& sum=sums;
  
  cin>>nyu;
  for(int i=1;i<=nyu;i++)
  sum= sum+i;
  
  cout<<sum<<endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int MAX_K = 1<<9;
const int MAX_L = 100010;

struct P{int v,w;};
P operator+(const P &a, const P &b){return {a.v+b.v,a.w+b.w};}

int dp[MAX_K][MAX_L];

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vector<P> nodes(N);
    rep(i,N){
        int v,w; cin>>v>>w;
        nodes[i] = {v,w};
    }
    int K = min(MAX_K,N+1);
    FOR(i,1,K-1){
        int p = i/2;
        rep(j,MAX_L){
            if (j>=nodes[i-1].w)
                dp[i][j] = max(dp[p][j],dp[p][j-nodes[i-1].w]+nodes[i-1].v);
            else
                dp[i][j] = dp[p][j];
        }
    }

    int Q; cin>>Q;
    while(Q--){
        int v,L; cin>>v>>L;
        vector<P> ps;
        ps.pb({0,0});
        while(v>=K){
            int M = ps.size();
            rep(i,M){
                ps.pb(ps[i]+nodes[v-1]);
            }
            v>>=1;
        }
        int ans=0;
        for(P e:ps){
            if (e.w>L) continue;
            chmax(ans,dp[v][L-e.w]+e.v);
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 205016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
const int N=1e9+7;
int main()
{
   int n;
   cin>>n;
   int arr[n][3];
   forl(i,0,n)forl(j,0,3) cin>>arr[i][j];

   int dp[n][3];
   forl(i,0,n) forl(j,0,3) dp[i][j]=0;
    forl(i,0,3) dp[0][i]=arr[0][i];

    
    forl(i,1,n)
    {
        forl(j,0,3)
        {
            forl(k,0,3)
            {
                if(k!=j)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+arr[i][j]);
                }
            }
        }
    }

    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    u32 X, Y;
    cin >> X >> Y;
    bool exists = false;
    for (u32 i = 0; i <= X; i++) {
        if (2 * i + 4 * (X - i) == Y) exists = true;
    }
    if (exists) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
int main(void) {
	int K;
	char S[101];
	scanf("%d\n", &K);
	scanf("%s\n", S);
	
	if (strlen(S) <= K) {
		printf("%s\n", S);
	} else {
		S[K] = 0x00;
		printf("%s...\n", S);
	}
	return(0);
}


Measured memory_bytes: 1724
s=input()
def solve(decided, left, idx):
    if idx==len(s):
        return decided+left
    # 手前に+を入れる
    ret1 = solve(decided+left,int(s[idx]),idx+1)
    # 入れない
    ret2 = solve(decided, left*10+int(s[idx]), idx+1)
    return ret1+ret2
# 最初の文字の左側には+は入れる必要が無いので1から
print(solve(0,int(s[0]),1))

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

using lint = int64_t;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
        cerr << fixed << setprecision(12);
    }
} iosetup;

int main() {
    int n, l;
    cin >> n >> l;
    int sum = 0, eat = INF;
    for (int i = 0; i < n; i++) {
        int aji = l + i;
        sum += aji;
        if (abs(aji) < abs(eat)) {
            eat = aji;
        }
    }

    cout << sum - eat << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin

a = int(stdin.readline().rstrip())
b = int(stdin.readline().rstrip())
c = int(stdin.readline().rstrip())
x = int(stdin.readline().rstrip())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x: count = count + 1

print (count)



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

inline int num (const std::string& S, int idx){ return S.at(idx) - '0'; }
inline unsigned int bitMask(int i){ return (1 << i); }
inline bool isTrue(unsigned int bit, int i){ return bit & bitMask(i); }
inline bool isEven(int num) { return !num%2; }
inline bool isOdd(int num) { return num%2; }

int main(){
	unsigned long long h, w;
	cin >> h >> w;
	if(h==1 || w==1) {
		cout << 1 << endl;
		return 0;
	}
	if(h%2) {
		if(w%2){
			cout << h*w/2 + 1 << endl;
		}else{
			cout << h*w/2 << endl;
		}
	}else{
		if(w%2){
			cout << h*w/2 << endl;
		}else{
			cout << h*w/2 << endl;
		}
	}
	return 0;
}


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

int main() {
    int s, w;
    cin >> s >> w;

    if(s <=  w)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    
}



Measured memory_bytes: 3592
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16096
#include<iostream>
#include<string>
#include<cstring>

int main(){
	int n;
	char c;
	std::string str,Del;
	std::cin>>n;
	std::getline(std::cin,str);
	while( --n ,std::getline(std::cin,str) , n+1 ){
		int Result;
		while( (Result = str.find("Hoshino") ) != std::string::npos )str.replace(Result,strlen("Hoshino"),"Hoshina");
		std::cout<<str<<std::endl;
	}
}

Measured memory_bytes: 1208
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
x = gets.chomp.to_i

if x == 1
  puts 1
  exit
end

ans = 0
2.upto(100).each do |i|
  cur = i * i
  next unless cur <= x
  while cur <= x
    cur *= i
  end
  cur /= i
  ans = cur if ans < cur
end

puts ans

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  
  double Theta1, Theta2, Theta3, ans;
  const double pi = acos(-1);
  
  Theta2 = H*30 + M*0.5;
  Theta3 = M*6;
  Theta1 = Theta2 - Theta3;
  Theta1 *= pi/180;
  
  ans = sqrt(pow(A,2) + pow(B,2) - (2*A*B*(cos(Theta1))));
  cout << fixed << setprecision(10) << ans << endl;
}


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

int main(){
    char card[201];
    char sub[201]; //後ろに連結するための文字列
    char target[201];//残りの文字列
    char h[201];
    int m,i,j,k,x;

    while(1){
        scanf("%s", card);
        if(card[0] == '-'){
            break;
        }
        scanf("%d", &m);

        for(i = 0; i < m; i++){
            scanf("%s", &h[i]);
            if(h[i] == '-'){
                break;
            }
            x = atoi(&h[i]);
            memset(target, '\0', sizeof(target));
            memset(sub, '\0', sizeof(sub));
            //前からxばんめまでをsubに入れる
            for(j = 0; j < x; j++){
                sub[j] = card[j];
            }
            //xから終わりまでtargetに入れる
            for(j = x, k = 0; j < strlen(card); j++ , k++){
                target[k] = card[j];
            }
            memset(card, '\0', sizeof(card));
            for(k = 0; k < strlen(target); k++){
                card[k] = target[k];
            }
            strcat(card,sub);//文字列を連結
            //printf("sub:%s\n", sub);//確認用
            //printf("target:%s\n",target);//確認用

        }
        printf("%s\n",card);
    }

    //printf("Length: %d\n", length);
    return 0;
}



Measured memory_bytes: 2044
s = input()
y, m, d = s.split('/')


def heisei(y, m, d):
    if int(y) < 2019:
        return 'Heisei'
    elif int(y) > 2019:
        return 'TBD'
    elif int(y) == 2019:
        if int(m) > 4:
            return 'TBD'
        elif int(m) < 4:
            return 'Heisei'
        elif int(m) == 4:
            if int(d) == 30:
                return 'Heisei'
            elif int(d) > 30:
                return 'TBD'
            else:
                return 'Heisei'


print(heisei(y, m, d))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  long long ans = 0;
  long long tmp = 0;
  for (int mask = 0; mask < (1 << (n-1)); mask++) {
    tmp = s.at(0) - '0';
    for (int i = 0; i < n-1; i++) {
      if(mask & (1 << i)) {
        ans += tmp;
        tmp = 0;
      }
      tmp = tmp * 10 + (s.at(i+1) - '0');
    }
    ans += tmp;
  }
  cout << ans << endl;

  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

// [---]
//  [-]
//   [--]
// 123321
//
//
// 101101
// [[[]]]
//
//
// [-]
//  [-]
//     []
//
// 100111
// [[]][]

const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	string a; cin >> a;
	
	ll res = 1, open = 0, close = 0;
	for (char c: a) {
		ll depth = open-close;
		if (depth%2 == (c == 'W')) {
			open++;
		} else {
			close++;
			res = res * depth % MOD;
		}
		if (open < close) res = 0;
	}
	if (open != close) res = 0;
	FOR(i,1,n+1) res = res*i % MOD;
	cout << res << endl;
}



Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

class UnionFind {
public:
  	vector<int> parents, ranks;
    UnionFind(int n) {
      	parents.resize(n);
      	ranks.resize(n);
        for (int i = 0; i < n; ++i)
            parents[i] = i;
    }
    
    int find(int x) {
        if (x != parents[x])
            parents[x] = find(parents[x]);
        return parents[x];
    }
    
    void unite(int x, int y) {
        int px = find(x);
        int py = find(y);
        if (px == py) return;
      
        if (ranks[px] > ranks[py])
            parents[py] = px;
        else if (ranks[px] < ranks[py])
            parents[px] = py;
        else {
            parents[py] = px;
            ranks[px]++;
        }
    }
};

int main() {
  int n, m, k, a, b;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<int> friendships(n), blockships(n);
  
  while(m--) {
    cin >> a >> b;
    friendships[a-1]++;
    friendships[b-1]++;
    uf.unite(a-1, b-1);
  }
  
  while(k--) {
    cin >> a >> b;
    if (uf.find(a-1) == uf.find(b-1)) {
      blockships[a-1]++;
      blockships[b-1]++;
    }
  }
  
  unordered_map<int, int> infos;
  for (int i = 0; i < n; ++i) infos[uf.find(i)]++;
  for (int i = 0; i < n; ++i)
    cout << infos[uf.parents[i]] - friendships[i] - blockships[i] - 1 << ' ';
  cout << '\n';
  
  return 0;
}


Measured memory_bytes: 6052
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
#define ll long long
#define fo(i,v,e) for(v=i;v<e;v++)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define deb(x...)
#endif
vector<ll> sieveOfErthnosis(ll n)
{
    vector<bool>flag(n+5,false);
    vector<ll>primes;
    for(int i=2;i*i<=n;i++)
    {
        if(!flag[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {flag[j]=true;}
        }
    }
    for (int  i = 2; i < n+1; i++)
    {
        if(!flag[i])primes.pb(i);
    }
    return primes;
}
void init()
{
    
}
void solve()
{
   ll n,i,j;cin>>n;
   set<string>v;
   string s;
   fo(0,i,n){cin>>s;v.insert(s);}
   cout<<v.size()<<endl;

}
int main()
{
    init();
    #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    #endif
    auto start = high_resolution_clock::now(); 
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start); 
    #ifndef ONLINE_JUDGE
    // cout << "time taken : "<<duration.count()<<" ms" << endl;
     #endif
}


Measured memory_bytes: 19232
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int dp[n+1];
	rep(i,n+1)dp[i]=i;
	rep(i,n){
		int t=6;
		while(i+t<n+1){
			dp[i+t]=min(dp[i+t],dp[i]+1);
			t*=6;
		}
		t=9;
		while(i+t<n+1){
			dp[i+t]=min(dp[i+t],dp[i]+1);
			t*=9;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

int main(){
  int i,N,M,a=0;
  long b,x;
  unsigned long long ans=0;
  scanf("%d",&N);
  scanf("%d",&M);
  vector<long> v(N,0);
  vector<pair<long,long>> change(M);
  for(i=0;i<N;i++){
    scanf("%ld",&x);
    v[i]=x;
  }
  sort(v.begin(),v.end(),greater<long>());
  for(i=0;i<M;i++){
    scanf("%ld",&b);
    scanf("%ld",&x);
    change[i]=pair<long,long>(x,b);
  }
  sort(change.begin(),change.end(),greater<pair<long,long>>());

  b=0;
  for(i=0;i<N;i++){
    if(v[a]>change[b].first){
      ans=ans+(long long)v[a];
      a++;
    }else{
      if(i+change[b].second<N){
        ans=ans+(long long)change[b].first*(long long)change[b].second;
        i+=change[b].second-1;
        b++;
      }else{
        ans=ans+(long long)change[b].first*(long long)(N-i);
        break;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 2560
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        p: i32,
        q: i32,
        r: i32,
    }
    println!("{}", cmp::min(p + q, cmp::min(q + r, r + p)));
}

Measured memory_bytes: 4352
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, K;
    string S;
    cin >> N >> K >> S;
    if (S[K - 1] == 'A') S[K - 1] = 'a';
    else if (S[K - 1] == 'B') S[K - 1] = 'b';
    else if (S[K - 1] == 'C') S[K - 1] = 'c';

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
void scan();
void cal();
void Sort();

int n,m;
int date[1000][1000]={0};
int sum[10000000]={0};

int main(){

  while(1){
  scanf("%d",&n);
  scanf("%d",&m);

  if(n==m && n==0){
    break;
  }

  scan();

  cal();

  Sort();

  }

  return 0;
}

void scan(){

  int i,j;

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

}

void cal(){

  int i,j;

  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      sum[i]+=date[j][i];
    }
  }

}

void Sort(){

  int i,j,max;
  int point;
  int kekka[100000]={0};

  for(i=0;i<m;i++){
  max=0;
  point=0;
    for(j=0;j<m;j++){
      if(max<sum[j]){
	max=sum[j];
	point=j;
      }
    }
    sum[point]=0;
    kekka[i]=point+1;
  }
  for(i=0;i<m;i++){
    printf("%d",kekka[i]);
    if(i!=m-1){
      printf(" ");
    }

  }
  printf("\n");

}

Measured memory_bytes: 5652
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int main(){
//  cout<<fixed<<setprecision(1)<<1<<endl;
//system("cls");
	int n;
	cin>>n;
	int a=0,w=0,t=0,r=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC")a++;
		if(s=="WA")w++;
		if(s=="TLE")t++;
		if(s=="RE")r++; 
	}
	cout<<"AC"<<" x "<<a<<endl;
	cout<<"WA"<<" x "<<w<<endl;
	cout<<"TLE"<<" x "<<t<<endl;
	cout<<"RE"<<" x "<<r<<endl;
	return 0;
}

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

int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if(a[0] == a[2])cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>=b;i--)
#define FILL(a,b,c) for(ll i=0;i<c;i++) a[i]=b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\n"
#define setpri(x) setprecision(x)
#define vp(x) cout<<#x<<" : "<< (x)<<" | "
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define forf(i,a,b) for(int i=a;i<b;i++)

#define INF 1e17+4
#define MINF 
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) { n %= MOD; if (n < 0) return n + MOD; else return n;}
// vector<int> adj[1000002];
// int vis[1000002],dep[1000002],siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }    
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b) 
// { 
//     return ;


void solve()
{
    int n,m,x;
    cin>>n>>m>>x;
    int data[n][m+1];
    forf(i,0,n)
        forf(j,0,m+1)
            cin>>data[i][j];
            
    int ans=MOD;
    
    // cout<<n<<" "<<m<<" "<<x<<endl;
    // forf(i,0,n)
    //     forf(j,0,m+1)
    //         cout<<data[i][j]<<" ";
    
    
    
    for(int i=0;i<pow(2,n);i++)
    {
        vector<int> a(m+1,0);
        int tmp=0;
        bool fg=true;
        
        for(int j=0;j<n;j++)
        {
            // cout<<(i>>j)<<" "<<(j)<<endl;
            if(((i>>j)&1) != 0 )
            {
                for(int k=1;k<=m;k++)
                    a[k]=a[k]+data[j][k];
                tmp+=data[j][0];
            }
        }
        for(int j=1;j<=m;j++)
        {
            // cout<<a[j]<<" ";
            if(a[j]<x)
                fg=false;
        }
        // cout<<endl<<ans<<endl<<endl;    
        if(tmp!=0 && fg==true)
            ans=min(ans,tmp);
        
    }
    if(ans==MOD)
        cout<<-1;
    else
        cout<<ans;
}


signed main()
{
    FAST;
    
    // ll t;cin>>t;while(t--)
        solve();
 
    return 0;
}

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

using ll=long long;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vvvvvi=vector<vvvvi>;
using vvvvvvi=vector<vvvvvi>;
const ll INF=1e15;

int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];
    vvvvvvi dp(2,vvvvvi(2,vvvvi(n+1,vvvi(m+1,vvi(n+1,vi(m+1,INF))))));
    vector<int> sumva(n+1);
    for(int i=0;i<n;i++){
        sumva[i+1]=sumva[i]+max(0LL,a[i]);
    }
    vector<int> sumvb(m+1);
    for(int i=0;i<m;i++){
        sumvb[i+1]=sumvb[i]+max(0LL,b[i]);
    }
    auto sumA=[&](int l,int r){return sumva[r]-sumva[l];};
    auto sumB=[&](int l,int r){return sumvb[r]-sumvb[l];};
    //cerr<<"#"<<endl;
    function<ll(int,int,int,int,int,int)> dfs=[&](int pass,int turn,int ap,int bp,int ar,int br){
        if(abs(dp[pass][turn][ap][bp][ar][br])!=INF) return dp[pass][turn][ap][bp][ar][br];
        ll res=(turn ? INF : -INF);
        if(pass) res=0;
        if(turn==0){
            if(ap<n){
                if(a[ap]==-1) res=max(res,dfs(0,1,ap+1,bp,ar,bp));
                else res=max(res,dfs(0,1,ap+1,bp,ar,br));
            }
            if(ap!=ar || bp!=br) res=max(res,dfs(0,1,ap,bp,ap,bp)+sumA(ar,ap)-sumB(br,bp));
            else if(pass==0) res=max(res,dfs(1,1,ap,bp,ap,bp));
        }
        else{
            if(bp<m){
                if(b[bp]==-1) res=min(res,dfs(0,0,ap,bp+1,ap,br));
                else res=min(res,dfs(0,0,ap,bp+1,ar,br));
            }
            if(ap!=ar || bp!=br) res=min(res,dfs(0,0,ap,bp,ap,bp)+sumA(ar,ap)-sumB(br,bp));
            else if(pass==0) res=min(res,dfs(1,0,ap,bp,ap,bp));
        }
        //cerr<<turn<<" "<<ap<<" "<<bp<<" "<<ar<<" "<<br<<" "<<res<<endl;
        return dp[pass][turn][ap][bp][ar][br]=res;
    };
    cout<<dfs(0,0,0,0,0,0)<<endl;
    return 0;
}


Measured memory_bytes: 403588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin>>a;
  vector<int> b(a);
    for(int i=0;i<a;i++)
      cin>>b.at(i);
  sort(b.begin(), b.end());
    if(b.at(a/2-1)==b.at(a/2))
       cout<<0;
      else
       cout<<b.at(a/2)-b.at(a/2-1);
  }

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+50,inf=1e9;
int n,m,a[N],b[N];
int calc(int s){
    for (int i=1; i<=m; ++i)
	b[i]=(a[i]>=s);
    int ans=0,sum=inf;
    for (int l=1,r; l<=m; l=r+1){
	r=l;
	while(r<m&&b[r+1]==b[l]) ++r;
	if (r>l)
	    for (int j=l; j<=r; ++j)
		if (abs(j-n)<sum)
		    sum=abs(j-n),ans=j;
    }
    if (!ans) return b[n]^(n&1)^1;
    return b[ans];
}
int main(){
    cin>>n,m=2*n-1;
    for (int i=1; i<=m; ++i) scanf("%d",&a[i]);
    int l=1,r=m,mid,ans;
    while(l<=r){
	mid=(l+r)>>1;
	if (calc(mid)) l=mid+1,ans=mid;
	else r=mid-1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792