akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 811111

#define TASK "1"

using namespace std;

int b[N], h[N], hh[N], s[N][2];
int n;
int k;
pair<int, int> q[N];

int mi[N];


void add(int x, int v, int o) {
	if (o) x = (n - 1 - x);
	if (x < 0) return;
	
	while (x < n) {
		s[x][o] = min(s[x][o], v);
		x |= x + 1;
	}
}

int get(int x, int o) {
	if (o) x = (n - 1 - x);

	int r = 1e9 + 1;
	while (x >= 0) {
		r = min(r, s[x][o]);
		x = (x & (x + 1)) - 1;
	}
	return r;
}

int get2(int pos ,int l, int r, int x) {
	if (x < l || x > r) return 1e9 + 1;
	if (l == r) return mi[pos];

	return min(mi[pos], min(get2(pos + pos, l, (l + r) / 2, x), get2(pos + pos + 1, (l + r) / 2 + 1, r, x)));
}

void add2(int pos, int l, int r, int ll, int rr, int v) {
	ll = max(ll, l);
	rr = min(rr, r);
	if (ll > rr) return;
	if (l == ll && r == rr) {
		mi[pos] = min(mi[pos], v);
		return;
	}
	add2(pos + pos, l, (l + r) / 2, ll ,rr, v);
	add2(pos + pos + 1, (l + r) / 2 + 1, r, ll, rr, v);
}




int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	cin >> n;
	int ii = 0;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		ii += (b[i] != 0);

		if (b[i] == 1) h[i] = -1; else h[i] = 1;
	}
	hh[0] = 0;
	for (int i = 0; i < n; i++) hh[i + 1] = hh[i] + h[i];

	cin >> k;
	for (int i = 0; i < k; i++) {
		cin >> q[i].S >> q[i].F;
		q[i].F--;
		q[i].S--;
	}
	sort(q, q + k);

	for (int i = 0; i <= n * 4; i++) s[i][0] = s[i][1] = mi[i] = 1e9 + 1;

	add(0, ii, 0);


	int change = 0;
	int u = 0;

	int ans = ii;

	for (int i = 0; i < k; i++) {
		int l = q[i].S;
		int r = q[i].F;
		while (u <= r) {
			change += h[u];
			u++;
		}
		{
			int t = get(l, 0) + (hh[r + 1] - hh[l]);
			ans = min(ans, t );
			add(r + 1, t, 0);


			add2(1, 0, n - 1, l + 1, r, t - change);
		}
		{
			int t = get2(1, 0, n - 1, l) + change;
			ans = min(ans, t );

			add(r + 1, t, 0);


			add2(1, 0, n - 1, l + 1, r, t - change);
		}
	}
	cout << ans << endl;

	return 0;
}






Measured memory_bytes: 22784
package main

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

func main() {
	In := ReadLineInt()
	TakahashiHP, TakahashiAttack := In[0], In[1]
	AokiHP, AokiAttack := In[2], In[3]

	for {
		AokiHP -= TakahashiAttack

		if AokiHP <= 0 {
			fmt.Println("Yes")
			return
		}

		TakahashiHP -= AokiAttack

		if TakahashiHP <= 0 {
			fmt.Println("No")
			return
		}
	}
}

/////////////////////////////////////////

func fln(format string, elements ...interface{}) {
	fmt.Printf(format+"\n", elements...)
}

var BufReader = bufio.NewReaderSize(os.Stdin, 1e6)

func ReadLine() string {
	a, _, _ := BufReader.ReadLine()
	return string(a)
}

func ReadLineInt() (result []int) {
	in := strings.Split(ReadLine(), " ")
	result = make([]int, 0, 2)
	for _, v := range in {
		t, _ := strconv.Atoi(v)
		result = append(result, t)
	}
	return
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc129/tasks/abc129_a
import sys

#n= int(input())
#s= input()
tmp = input().split()
p,q,r = list(map(lambda a: int(a), tmp))

sum = p+q+r-max(p,max(q,r))
print(sum)

Measured memory_bytes: 2940
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}
	for (int i = 0; i < n; i++)
	{
		cin >> b.at(i);
	}
	int ans = 0;
	
	for (int i = 0; i < n; i++)
	{
		int w = 0;
		for (int j = 0; j < i+1; j++)
		{
			w += a.at(j);
		}
		for (int k = i; k < n; k++)
		{
			w += b.at(k);
		}
		if (ans < w)
		{
			ans = w;
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <string>

int N, M;
std::map<std::string, int> word_benefit;
int max_benefit = 0;

int main() {
  std::cin >> N;
  std::string linebuf;
  for (int i = 0; i < N; ++i) {
    std::cin >> linebuf;
    ++word_benefit[linebuf];
  }
  std::cin >> M;
  for (int i = 0; i < M; ++i) {
    std::cin >> linebuf;
    --word_benefit[linebuf];
  }
  for (auto& j: word_benefit) {
    max_benefit = std::max(max_benefit, j.second);
  }
  std::cout << max_benefit << std::endl;
}

Measured memory_bytes: 256
// / #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <stack>
#include <sstream>
#include <regex>
 
#define prev asasddlsa
#define rank aljds
 
using namespace std;
 
typedef long long ll;
typedef long double dbl;

// mt19937 mrand(random_device{} ());
// int rnd(int x = INT_MAX) {
//     return mrand() % x;
// }

template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << ' ';
    cout << endl;
}
 
template<class T>
void print(const T* s, int n){
    for (int i = 0; i < n; i++){
        cout << s[i] << ' ';
    }
    cout << endl;
}
 
template<class T>
void print(vector<vector<T>> s){
    for (int i = 0; i < s.size(); i++)
        print(s[i]);
}

const int mod = 1e9 + 7;

ll power(ll a, ll n){
    ll res = 1;
    while (n){
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll inv(ll a){
    return power(a, mod - 2);
}

const int maxn = 1e3 + 7;

ll fact[maxn], inv_fact[maxn];

ll cnk(int n, int k){
    if (k > n)
        return 0;
    return fact[n] * inv_fact[k] % mod * inv_fact[n - k] % mod;
}

ll inv_cnk(int n, int k){
    assert(n >= k);
    return fact[k] * fact[n - k] % mod * inv_fact[n] % mod;
}

ll dp[maxn];

int main(){
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i <= n; i++){
        fact[i] = fact[i - 1] * i % mod;
        inv_fact[i] = inv_fact[i - 1] * inv(i) % mod;
    }
    dp[0] = 1;
    ll mult = 1;
    for (int i = 0; i < k; i++){
        int a;
        cin >> a;
        // print(dp, n + 1);
        for (int j = n; j > 0; j--){
            for (int l = 1; l <= min(j, a); l++){
                ll coef = cnk(n - l, a - l) * cnk(j, l) % mod * inv_cnk(n, a) % mod;
                // if (i == 1 && j == n){
                //     cout << "coef: " << l << " " << coef << ' ' << dp[j - l] << endl;
                //     cout << cnk(n - l, a - l) << ' ' << cnk(j, l) << ' ' << inv_cnk(n, a) << endl;
                // }
                dp[j] = (dp[j] + dp[j - l] * coef) % mod;
                // if (i == 1 && j == n)
                    // cout << dp[n] << endl;
            }
            // print(dp, n + 1);
        }
        // print(dp, n + 1);
        mult = mult * cnk(n, a) % mod;
    }
    cout << dp[n] * mult % mod << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

ll MOD;
vector<vector<int> > adj;

vector<ll> dp0;
ll dfs0(const int u = 0, const int p = -1) {
    dp0[u] = 1;
    for (const int v : adj[u]) {
        if (v != p) (dp0[u] *= 1 + dfs0(v, u)) %= MOD;
    }
    return dp0[u];
}

vector<ll> dp;
void dfs(const int u = 0, const int p = -1, const ll cur = 1LL) {
    (dp[u] *= cur) %= MOD;
    vector<ll> suf;
    for (const int v : adj[u]) {
        if (v == p) continue;
        suf.push_back(1 + dp0[v]);
    }
    suf.push_back(1);
    for (int i = suf.size() - 2; i >= 0; i--) {
        (suf[i] *= suf[i + 1]) %= MOD;
    }
    ll left = 1;
    int i = 0;
    for (const int v : adj[u]) {
        if (v == p) continue;
        const ll val = (left * suf[i + 1]) % MOD;
        dfs(v, u, (1 + cur * val) % MOD);
        (left *= 1 + dp0[v]) %= MOD;
        i++;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n >> MOD;

    adj.resize(n);
    dp0.resize(n);

    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs0();

    dp = dp0;

    dfs();

    for (const ll e : dp) cout << e << '\n';
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  constexpr ModInt() : v(0) {}
  constexpr ModInt(unsigned _v, int) : v(_v) {}
  template<class Z> ModInt(const Z& a) : v((a < 0 ? P - -a % P : a) % P) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  friend M operator*(M l, M r) { return M(l) *= r; }
  friend M operator/(M l, M r) { return M(l) /= r; }
  friend M operator+(M l, M r) { return M(l) += r; }
  friend M operator-(M l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
  friend bool operator!=(M l, M r) { return !(l == r); }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Z> M pow(Z n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
};
using Mint = ModInt<998244353>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> d(n), c(n);
  for (auto&& e : d) {
    cin >> e;
    ++c[e];
  }
  if (d[0] or c[0] != 1) {
    return cout << 0 << '\n', 0;
  }
  for (int i = 0; i < n - 1; ++i) if (c[i] == 0 and c[i + 1]) {
    return cout << 0 << '\n', 0;
  }
  Mint res = 1;
  for (int i = 1; i < n; ++i) {
    if (c[i] == 0) break;
    res *= Mint(c[i - 1]).pow(c[i]);
  }
  cout << res << '\n';
}

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


class Dice:
    """
    0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
    """

    def __init__(self, surfaces):
        self.init_surface = surfaces
        self.surface = surfaces

    def roll(self, direction: str):
        if direction == "E":
            self.surface = [self.surface[3], self.surface[1], self.surface[0],
                            self.surface[5], self.surface[4], self.surface[2]]

        elif direction == "N":
            self.surface = [self.surface[1], self.surface[5], self.surface[2],
                            self.surface[3], self.surface[0], self.surface[4]]

        elif direction == "S":
            self.surface = [self.surface[4], self.surface[0], self.surface[2],
                            self.surface[3], self.surface[5], self.surface[1]]

        elif direction == "W":
            self.surface = [self.surface[2], self.surface[1], self.surface[5],
                            self.surface[0], self.surface[4], self.surface[3]]

        return

    def spin(self):
        self.surface = [self.surface[0], self.surface[3], self.surface[1],
                        self.surface[4], self.surface[2], self.surface[5]]
        return

    def get_surface(self, num):
        return self.surface.index(num)

    def get_top(self):
        return self.surface[0]

    def get_south(self):
        return self.surface[1]

    def get_east(self):
        return self.surface[2]


def main():
    surface = [int(i) for i in input().strip().split()]
    cases = int(input().strip())
    dice = Dice(surface)

    for _ in range(cases):
        top, south = [int(i) for i in input().strip().split()]
        # get current surface
        cur = dice.get_surface(top)
        if cur == 0:
            pass
        elif cur == 1:
            dice.roll("N")
        elif cur == 2:
            dice.roll("W")
        elif cur == 3:
            dice.roll("E")
        elif cur == 4:
            dice.roll("S")
        elif cur == 5:
            dice.roll("S")
            dice.roll("S")
        for _ in range(4):
            dice.spin()
            if dice.get_south() == south:
                print(dice.get_east())


if __name__ == "__main__":
    main()



Measured memory_bytes: 5648
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
ex=0
for test in range(K):
    ex+=1
    D=[0 for i in range(N+1)]
    for i in range(N):
        D[max(0,i-A[i])]+=1
        D[min(N,i+A[i]+1)]-=1
    A[0]=D[0]
    for i in range(1,N):
        A[i]=A[i-1]+D[i]
    if set(A)=={N}:
        break
print(*A)


Measured memory_bytes: 170164
n,w=map(int,input().split())
x1,y1=map(int,input().split())
d={x1:[y1],x1+1:[],x1+2:[],x1+3:[]}
for _ in range(n-1):
    x,y=map(int,input().split())
    d[x].append(y)
d={k:[0]+sorted(d[k],reverse=True) for k in d}
vm=0
v1,w1=0,0
for e in d[x1]:
    v1+=e
    w1+=0 if e==0 else x1
    v2,w2=0,0
    for f in d[x1+1]:
        v2+=f
        w2+=0 if f==0 else x1+1
        v3,w3=0,0
        for g in d[x1+2]:
            v3+=g
            w3+=0 if g==0 else x1+2
            v4,w4=0,0
            for h in d[x1+3]:
                v4+=h
                w4+=0 if h==0 else x1+3
                ws=w1+w2+w3+w4
                vs=v1+v2+v3+v4
                if ws<=w:
                    vm=max(vm,vs)
print(vm)


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> S(N,0);
  vector<int> H(N);
  for(int i=0;i<N;i++) cin>>H.at(i);
  for(int i=0;i<M; i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    if(H.at(a)<=H.at(b)) S.at(a)++;
    if(H.at(a)>=H.at(b)) S.at(b)++;
  }
  int count=0;
  for(int i=0; i<N; i++){
    if(S.at(i)==0) count++;
  }
  cout<< count;
    
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int H, W, N; cin >> H >> W >> N;
	int sr, sc; cin >> sr >> sc; --sr; --sc;
	string S, T;
	cin >> S >> T;

	int minr = 0, maxr = H-1, minc = 0, maxc = W-1;

	dump(mp(mp(minr, maxr), mp(minc, maxc)));

	for (int i = N - 1; i >= 0; --i) {
		if (T[i] == 'L') {
			++maxc;
		} else if (T[i] == 'R') {
			--minc;
		} else if (T[i] == 'U') {
			++maxr;
		} else if (T[i] == 'D') {
			--minr;
		}


		chmax(minr, 0);
		chmin(maxr, H-1);
		chmax(minc, 0);
		chmin(maxc, W-1);

		if (minc > maxc || minr > maxr) {
			puts("NO");
			return 0;
		}

		dump(mp(mp(minr, maxr), mp(minc, maxc)));

		if (S[i] == 'L') {
			++minc;
		} else if (S[i] == 'R') {
			--maxc;
		} else if (S[i] == 'U') {
			++minr;
		} else if (S[i] == 'D') {
			--maxr;
		}

		chmax(minr, 0);
		chmin(maxr, H-1);
		chmax(minc, 0);
		chmin(maxc, W-1);	

		if (minc > maxc || minr > maxr) {
			puts("NO");
			return 0;
		}

		dump(mp(mp(minr, maxr), mp(minc, maxc)));	
	}

	if (minr <= sr && sr <= maxr && minc <= sc && sc <= maxc) {
		puts("YES");
	} else {
		puts("NO");
	}

	return 0;
}

Measured memory_bytes: 776
N = int(input())

t_b = x_b = y_b = 0 # 直前の時刻と位置保存用

def dist(x, x_b, y, y_b):
    return abs(x-x_b) + abs(y-y_b)

miss_flg = 0

for i in range(N):
    t, x, y = map(int, input().split())
    if dist(x, x_b, y, y_b) > t - t_b or ((t - t_b) + dist(x, x_b, y, y_b))% 2 == 1: # 到達不能もしくは距離と残り時間の偶奇が不一致
        miss_flg = 1
    t_b, x_b, y_b = t, x, y

print("Yes" if miss_flg == 0 else "No")

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

int main(){
    long long n;
    cin >> n;

    vector<long long> a(n);
    for(long long i = 0; i < n; i++) cin >> a[i];

    long long ans = 0;
    for(long long i = 0; i < n; i++){
        long long r = a[i]/2;
        ans += r;
        a[i] -= 2*r;
        if(i+1 < n){
            r = (a[i] + a[i+1]) / 2;
            ans += r;
            if(r > 0){
                a[i+1] -= 2 * r - a[i];
            }

        }
    }

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

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,w,w0,v0;vector<int> a[4];

signed main(){
  cin>>n>>w>>w0>>v0;
  a[0].push_back(v0);
  repd(i,1,n){
    int ww,vv;cin>>ww>>vv;
    a[ww-w0].push_back(vv);
  }
  rep(i,4){
    sort(a[i].begin(), a[i].end(), greater<int>());
    repd(j,1,a[i].size()){
      a[i][j] += a[i][j-1];
    }
  }
  int ans = -1;
  int p = w0, q = p+1, r = q+1, s = r+1;
  rep(i,n+1){
    int pw = i*p;
    if(pw > w || i > a[0].size())break;
    rep(j,n+1){
      int qw = pw + j*q;
      if(qw > w || j > a[1].size())break;
      rep(k,n+1){
        int rw = qw + k*r;
        if(rw > w || k > a[2].size())break;
        rep(l,n+1){
          int sw = rw + l*s;
          if(sw > w || l > a[3].size())break;
          int value = (i > 0 ? a[0][i-1] : 0) + (j > 0 ? a[1][j-1] : 0) + (k > 0 ? a[2][k-1] : 0) + (l > 0 ? a[3][l-1] : 0);
          chmax(ans, value);
        }
      }
    }
  }
  cout << ans << endl;
}




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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int n, m;
int s[400], l[400], p[400];
int w[400];

int dp[400][401];

int main() {
    cin >> n;
    rep(i, n) {
        cin >> s[i] >> l[i] >> p[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 400; ++j) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            for (int k=s[i]; k<=l[i]; ++k) {
                if (j >= k) {
                    dp[i+1][j]=max({dp[i][j], dp[i+1][j], dp[i+1][j-k]+p[i]});
                }
                else dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
            }
        }
    }
    cin >> m;
    bool ok = true;
    rep(i, m) {
        cin >> w[i];
        if (dp[n][w[i]] == 0) {
            ok = false;
        }
    }
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, m) {
        cout << dp[n][w[i]] << endl;
    }
    return 0;
}



Measured memory_bytes: 3728
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    ll a, b, n;
    cin >> a >> b >> n;

    cout << a * min(b - 1, n) / b << endl;

    return 0;
}

Measured memory_bytes: 3656
h,n=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]

dp = [123456789012] * (10**8 + 10)

dp[0] = 0
for i in range(h+1):
    if dp[i] == 123456789012:
        continue
    for j in range(n):
        dp[i+ab[j][0]] = min(dp[i+ab[j][0]],dp[i] + ab[j][1])
ans = 123456789012
for i in range(h,h+10000+2):
    ans = min(ans,dp[i])
print(ans)

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

int g[3][3],n,x;

int main()
{
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			cin >> g[i][j];
			
	cin >> n;
	
	for(int k=0; k<n; k++)
	{
		cin >> x;
		for(int i=0;i<3; i++)
			for(int j=0; j<3; j++)
			{
				if(g[i][j] == x)
					g[i][j] = -1;
			}
	}
	
	/*for(int i=0; i<3; i++)
	{
		for(int j=0; j<3; j++)
			cout << g[i][j] << ' ';
	
		cout << '\n';		
	}
	
	cout << '\n';*/
	
	bool l,c,dp,ds;
	
	for(int i=0; i<3; i++)
	{
		int auxl=0;
		
		for(int j=0; j<3; j++)
			auxl+=g[i][j];
		
		if(auxl == -3)
		{
			l = true;
			break;
		}
		else
			l = false;
	}
	
	for(int j=0; j<3; j++)
	{
		int auxc = 0;
	
		for(int i=0; i<3; i++)
			auxc += g[i][j];
			
		if(auxc == -3)
		{
			c = true;
			break;
		}
		else
			c = false;
			
		//cout << auxc << '\n';
	}
	
	int auxds = 0;
	for(int i=0; i<3; i++)		
		for(int j=0; j<3; j++)
		{
			if(i+j == 2)
				auxds += g[i][j];
		}
		
	if(auxds == -3)
		ds = true;
	else
		ds = false;
	
	int auxdp = 0;
	for(int i=0; i<3; i++)
		auxdp += g[i][i];
	
	if(auxdp == -3)
		dp = true;
	else
		dp = false;
	
	//cout << l << ' ' << c << ' ' << dp << ' ' << ds << '\n';
	
	if(l or c or dp or ds)
		cout << "Yes\n";
	else
		cout << "No\n";
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  string s;
  cin >> s;

  vector<int> ox(N);
  for(int i = 0; i < N; i++){
    if(s[i] == 'o'){
      ox[i] = 0;
    }else{
      ox[i] = 1;
    }
  }

  bool ok = false;
  vector<int> ans(N);

  // 0, 1がS, S
  vector<int> test1(N);
  test1[0] = 0;
  test1[1] = 0;
  if(ox[0] == 0){
    test1[N-1] = 0;
  }else{
    test1[N-1] = 1;
  }

  for(int i = 2; i < N-1; i++){
    test1[i] = test1[i-1] ^ ox[i-1] ^ test1[i-2];
  }

  if(test1[N-1] == test1[N-2] ^ ox[N-2] ^ test1[N-3] &&
  test1[0] == test1[N-1] ^ ox[N-1] ^ test1[N-2]){
    ok = true;
    ans = test1;
  }

  // 0, 1がS, W;
  vector<int> test2(N);
  test2[0] = 0;
  test2[1] = 1;
  if(ox[0] == 0){
    test2[N-1] = 1;
  }else{
    test2[N-1] = 0;
  }

  for(int i = 2; i < N-1; i++){
    test2[i] = test2[i-1] ^ ox[i-1] ^ test2[i-2];
  }

  if(test2[N-1] == test2[N-2] ^ ox[N-2] ^ test2[N-3] &&
  test2[0] == test2[N-1] ^ ox[N-1] ^ test2[N-2]){
    ok = true;
    ans = test2;
  }

  // 0, 1がW, S;

  vector<int> test3(N);
  test3[0] = 1;
  test3[1] = 0;
  if(ox[0] == 0){
    test3[N-1] = 1;
  }else{
    test3[N-1] = 0;
  }

  for(int i = 2; i < N-1; i++){
    test3[i] = test3[i-1] ^ ox[i-1] ^ test3[i-2];
  }

  if(test3[N-1] == test3[N-2] ^ ox[N-2] ^ test3[N-3] &&
  test3[0] == test3[N-1] ^ ox[N-1] ^ test3[N-2]){
    ok = true;
    ans = test3;
  }
  // 0, 1がW, W;

  vector<int> test4(N);
  test4[0] = 1;
  test4[1] = 1;
  if(ox[0] == 0){
    test4[N-1] = 0;
  }else{
    test4[N-1] = 1;
  }

  for(int i = 2; i < N-1; i++){
    test4[i] = test4[i-1] ^ ox[i-1] ^ test4[i-2];
  }

  if(test4[N-1] == test4[N-2] ^ ox[N-2] ^ test4[N-3] &&
  test4[0] == test4[N-1] ^ ox[N-1] ^ test4[N-2]){
    ok = true;
    ans = test4;
  }

  if(ok){
    for(int i = 0; i < N; i++){
      if(ans[i] == 0){
        cout << 'S';
      }else{
        cout << 'W';
      }
    }
    cout << endl;
  }else{
    cout << -1 << endl;
  }


  return 0;
}


Measured memory_bytes: 2896
#include<bits/stdc++.h>
using namespace std;
#define debug 1

struct JOB{
	int day;
	int reward;
	
	friend bool operator<(const JOB a,const JOB b) {
		if(a.reward!=b.reward)
			return a.reward<b.reward;
		return 0;
	}
};

bool cmp(JOB a,JOB b) {
	return a.day>b.day;
} 

int main(int argc,char **argv) {
	int n,m;
	cin>>n>>m;
	JOB job[n];
	
	int a,b;
	for(int i=0;i<n;i++) {
		scanf("%d%d",&a,&b);
		job[i].day=m-a;
		job[i].reward=b;
	}
	
	sort(job,job+n,cmp);
	
	priority_queue<JOB> q;
	int ans=0;
	int now=0;
	for(int i=m-1;i>=0;i--) {
		while(now<n && job[now].day>=i)
			q.push(job[now++]);
		if(!q.empty()) {
			ans+=q.top().reward;
			q.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
	int N;
	vector<int> A;
	int inputA;

	int maxA = 0;
	int minA = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> inputA;
		A.push_back(inputA);
	}

	maxA = *max_element(A.begin(), A.end());
	minA = *min_element(A.begin(), A.end());

	cout << maxA - minA << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
I = [int(_) for _ in open(0).read().split()]
H, W, D = I[:3]
A = I[3:3 + H * W]
Q = I[3 + H * W]
LR = I[4 + H * W:]

a_i = [0] * (H * W + 1)
for i, a in enumerate(A):
    a_i[a] = i


def calc(a1):
    a2 = a1 + D
    hw1 = a_i[a1]
    h1, w1 = divmod(hw1, W)
    hw2 = a_i[a2]
    h2, w2 = divmod(hw2, W)
    return abs(h2 - h1) + abs(w2 - w1)


score = [0] + [calc(i) for i in range(1, H * W + 1 - D)]
cum = [[0] + list(itertools.accumulate(score[i::D])) for i in range(D)]
ans = []
for l, r in zip(LR[::2], LR[1::2]):
    ans += [cum[r % D][r // D] - cum[l % D][l // D]]
print(*ans, sep='\n')


Measured memory_bytes: 42792
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <int> a(n),b(n),c(n-1);
    generate(all(a),nxt);
    generate(all(b),nxt);
    generate(all(c),nxt);
    int test=0;
    for(int i=0;i<n;i++)
    {
        test+=b[a[i]-1];
        if(i>=1&&a[i]==a[i-1]+1)
            test+=c[a[i-1]-1];
    }
    cout<<test<<endl;
    
    
    return 0;   
}


 
 


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    char s;
    cin >> s;
    printf("%c", s+1);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define Q int t,q; cin>>t ;for(q=1;q<=t;q++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    ll n,i,a,mx=0;
    vector<ll>v(100001);
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        v[a]++;
    }
    for(i=0;i<100000;i++)
    {
        mx=max(mx,v[i]+v[i+1]+v[i+2]);
    }
    cout<<mx;
}


Measured memory_bytes: 3848
n=int(input())
answer=0
for i in range(6):
  if n/(10**i)>=1:
    if i%2==1:
      answer+=10**i-(10**(i-1))
  else:
    if i%2==1:
      answer+=(n-(10**(i-1))+1)
    break
print(answer)

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

const int MAX = 200000;

int main(){
    int n, k;
    int H[MAX];
    cin >> n >> k;
    rep(i,n) cin >> H[i];
    sort(H, H + n);

    long long  ans = 0;
    for(int i = 0; i < n - k; i++){
        ans += H[i];
    }

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

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  long long a,b,k;
  cin>>a>>b>>k;
  if(k>a && k<=a+b){
    b=b-(k-a);
    a=0;
  }
  else if(k>a){
    a=0;
    b=0;
  }
  else{
    a=a-k;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b;
  cin>>a>>b;
  string ans = "No";
  for(int i=0;i<=a;i++){
    int j = a - i;
    	if(2*i+4*j == b){
          ans ="Yes";
          break;
        }
    
  }
  cout<<ans;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	int n,ans=0,ke=1;
	string s;
	cin>>n;
	s=to_string(n);
	for(int i=0;i<s.size();i++){
		ans+=(s[i]-'0');
		ke*=10;
	}
    ke/=10;
	if(n==ke)ans=10;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        double ans = 0;
        for(int i = 0; i < a; i++){
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        ans = list.get(0);
        list.remove(0);
        while(list.size() > 0){
            ans = (ans + list.get(0)) / 2;
            list.remove(0);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

#include <queue>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif

int H, N;
vi A, B;
int dp[10001][1000];
int dfs(int H, int i) {
  if (H <= 0)
    return 0;
  if (i >= N)
    return INF;
  if (dp[H][i] != INF)
    return dp[H][i];
  return dp[H][i] = min(B[i] + dfs(H - A[i], i), dfs(H, i+1));
}
int main() {
  cin >> H >> N;

  rep(i, 10001) rep(j, 1000) dp[i][j] = INF;
  A.resize(N);
  B.resize(N);
  rep(i, N) {
    cin >> A[i] >> B[i];
  }
  cout << dfs(H, 0) << endl;
  return 0;
}


Measured memory_bytes: 40064
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    int n = (int)s.size();
    for (int i = n - 2; i >= 0; i -= 2) {
        string t1 = s.substr(0, i / 2);
        string t2 = s.substr(i / 2, i / 2);
        if (t1 == t2) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
/*IT'S A VERY LONG ROAD BUT IT WILL BE WORTH IT*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int
signed main() 
{ 
    fast;
    string s,t;
    cin>>s>>t;
    cout<<t<<s;
} 

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

int main() {
  int ans;
  string s;
  cin>>s;
  if(s[0]=='1')ans++;
  if(s[1]=='1')ans++;
  if(s[2]=='1')ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
LL gcd(LL a,LL b)
{
	return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
	return x>y;
}
const int N=2e5+100;
const LL mod=1e9+7;
LL f[N],n,m,A,B;
LL powmod(LL x,LL n)
{
	LL s=1;
	while(n)
	{
		if(n&1)
			s=(s*x)%mod;
		x=(x*x)%mod;
		n>>=1;
	}
	return s;
}
LL C(LL n,LL m)
{
	LL a=f[n];
	LL b=(f[m]*f[n-m])%mod;
	return (a*powmod(b,mod-2))%mod;
}
int main()
{
	io;
	f[0]=1;
	for(LL i=1; i<N; i++)
		f[i]=(f[i-1]*i)%mod;
	while(cin>>n>>m>>A>>B)
	{
		LL res=0;
		for(LL i=B+1; i<=m; i++)
		{
			LL tmp=(C(i-1+n-A-1,n-A-1)*C(m-i+A-1,m-i))%mod;
			res=(res+tmp)%mod;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main(){
    
    int n;
    cin >> n;
    int* a;
    int* b;
    int* c;
    a = new int [n];
    b = new int [n];
    c = new int [n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    for(int i=0;i<n-1;i++){
        cin >> c[i];
    }
    
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=b[a[i]-1];
        if(a[i+1]==a[i]+1){
            ans+=c[a[i]-1];
        }
        else continue;
    }
    cout << ans << endl;
    
    delete a;
    delete b;
    delete c;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<long long int, long long int> P;
#define F first
#define S second
#define MAX_N 100000
#define INF 1e18
P house[2][2 * MAX_N + 1];
long long int ruiseki[2][2 * MAX_N + 1] = {};
int main() {
	long long int w, h, n, sum = 0, time = INF, ma = 0, mid, x = 0, y = 0, ansx = INF, ansy = INF, p, mid2, sum2;

	P save, save2, search;
	cin >> w >> h >> n;
	for (int i = 0; i <2 * n; i += 2) {
		long long int a, b;
		scanf("%lld%lld", &a, &b);
		house[0][i] = make_pair(a, b);
		house[0][i + 1] = house[0][i];
		house[1][i] = make_pair(b, a);
		house[1][i + 1] = house[1][i];
	}
	sort(house[0], house[0] + 2 * n);
	sort(house[1], house[1] + 2 * n);
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 0; j < 2; j++) {
			ruiseki[j][i] += house[j][i].F;
			if (i)
				ruiseki[j][i] += ruiseki[j][i - 1];
		}
	}
	mid = mid2 = n - 1;
	for (int j = 0; j < 2 * n; j += 2) {
		sum2 = 0;
		if (j < mid)
			mid++;
		search = make_pair(house[0][j].S, house[0][j].F);
		p = lower_bound(house[1], house[1] + n * 2, search) - house[1];
		if (p < mid2)
			mid2++;
		x = house[0][mid].F;
		y = house[1][mid2].F;
		sum2 += (mid + 1) * x + (mid2 + 1) * y - ruiseki[0][mid] - ruiseki[1][mid2];
		sum2 += ruiseki[0][2 * n - 1] + ruiseki[1][2 * n - 1] - ruiseki[0][mid] - ruiseki[1][mid2] - (2 * n - mid - 1) * x - (2 * n - mid2 - 1) * y;
		sum2 -= abs(house[0][j].F - x) + abs(house[0][j].S - y);
		if (time == sum2) {
			time = sum2;
			if (ansx > x) {
				ansx = x;
				ansy = y;
			}
			if (ansx == x) {
				if (ansy > y) {
					ansy = y;
				}
			}
		}
		if (time > sum2) {
			time = sum2;
			ansx = x;
			ansy = y;
		}
		if (j < mid)
			mid--;
		if (p < mid2)
			mid2--;
	}
	cout << time << endl;
	cout << ansx << ' ' << ansy << endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

int main()
{
    char c;
    for (size_t i = 0; i < 3; i++) {
        cin >> c;
        if (c == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#define ll long long
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)

//library----------------------------------------------


int main(){
  int n,a,b; cin>>n>>a>>b;
  if(n==1){
    printf("Hello World\n");
  }else{
    printf("%d\n",a+b);
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

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

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

int main( void ) {
    int n, m;
    while( cin >> n >> m && n + m != 0 ) {
        int ans = 0;
        for( int i = 1; i <= n; ++i ) {
            for( int j = i + 1; j <= n; ++j ) {
                int x = m - i - j;
                if( x > j && x <= n ) ++ans;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
int arr[N];
char str[N];
int s1[N],s2[N];

/*
><<>>
*/
signed main(){
	scanf("%s",str+1);
	int len=strlen(str+1)+1;

	for(int i=1;i<=len;i++){
		if(str[i-1]=='<') s1[i]=s1[i-1]+1;
		else s1[i]=0;
	}
	

	for(int i=len;i>=0;i--){
		if(str[i]=='>') s2[i]=s2[i+1]+1;
		else s2[i]=0;
	}
	int ans=0;
	for(int i=1;i<=len;i++) ans+=max(s1[i],s2[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 12544
#include<iostream>
using namespace std;
string str;
int cnt;
int main(){
  while(cin>>str){
    for(int i=0;i<(int)str.size();i++){
      if(str[i]=='@'){
	cnt=str[i+1]-'0';
      }else if(i-1>=0&&str[i-1]=='@'){
	continue;
      }else{
	if(i-2>=0&&str[i-2]=='@'){
	  for(int j=0;j<cnt;j++)cout<<str[i];
	}else{
	  cout<<str[i];
	}
      }
    }
    cout<<endl;
  }
  return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<pair<int,int>> adj[100000];
vector<int> tree[100000];
vector<tuple<int,int,int>> E;
bool used[100000];
string ans;
int V[100000], res[200000], color[100000];

int find_(int a)
{
	return color[a]=color[a]==a ? a:find_(color[a]);
}

void union_(int a, int b)
{
	color[find_(a)]=find_(b);
}

void dfs(int c, int v)
{
	used[c]=false;
	ans[c]=v ? 'B':'W';
	for(auto n: tree[c]) if(used[n]) dfs(n,!v);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, M, tot=0;
	queue<int> Q;
	cin>>N>>M;
	for(int i=0;i<N;i++) {
		cin>>V[i];
		color[i]=i;
	}
	for(int i=0;i<M;i++) {
		int a, b;
		cin>>a>>b;
		adj[--a].emplace_back(--b,i);
		adj[b].emplace_back(a,i);
		if(V[a]==V[b]) {
			res[i]=V[a];
			if(!used[a]) {
				used[a]=true;
				Q.push(a);
			}
			if(!used[b]) {
				used[b]=true;
				Q.push(b);
			}
			if(find_(a)!=find_(b)) {
				union_(a,b);
				tree[a].push_back(b);
				tree[b].push_back(a);
			}
		}
		else res[i]=1e9;
	}
	ans.resize(N);
	while(!Q.empty()) {
		int c=Q.front();
		Q.pop();
		tot++;
		for(auto n: adj[c]) if(V[n.first]>=V[c] && !used[n.first]) {
			if(find_(c)!=find_(n.first)) {
				union_(c,n.first);
				tree[c].push_back(n.first);
				tree[n.first].push_back(c);
			}
			used[n.first]=true;
			res[n.second]=V[n.first];
			Q.push(n.first);
		}
	}
	if(tot<N) {
		cout<<"-1\n";
		return 0;
	}
	for(int i=0;i<N;i++) if(used[i]) dfs(i,0);
	cout<<ans<<'\n';
	for(int i=0;i<M;i++) cout<<res[i]<<'\n';
	return 0;
}

Measured memory_bytes: 17792
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n)+out
        X_dumy = int(X_dumy/n)
    return out


def main():
    N, K = MI()
    print(len(Base_10_to_n(N, K)))


if __name__ == '__main__':
    main()


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> ans;
    int p = n;
    while (p > 0) {
        if (p <= m) {
            ans.push_back(p);
            p = 0;
            break;
        }
        for (int i = m; i > 0; --i) {
            if (s[p - i] == '0') {
                ans.push_back(i);
                p -= i;
                goto A;
            }
        }
        cout << -1 << '\n';
        return 0;
        A: continue;
    }
    reverse(ans.begin(), ans.end());
    for (auto& i : ans) {
        cout << i << ' ';
    }
    cout << '\n';
    return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int k, q;
    cin >> k >> q;
    Vl d(k);
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    Vl dm(k);
    Vl coeffs(k);
    for (int i = 0; i < q; i++) {
        ll n, x, m;
        cin >> n >> x >> m;
        ll out = 0;
        ll a_last = x % m;
        for (int j = 0; j < k; j++) {
            dm[j] = d[j] % m;
        }
        for (int j = 0; j < k; j++) {
            if (j <= (n - 1) % k - 1)
                coeffs[j] = (n - 1) / k + 1;
            else
                coeffs[j] = (n - 1) / k;
        }
        for (int j = 0; j < k; j++) {
            a_last += dm[j] * coeffs[j];
            if (dm[j] == 0) out += coeffs[j];
        }
        out += a_last / m;
        cout << n - 1 - out << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		int min = Math.min(A, B);
		int count = 0;
		int val = 0;
		for(int i=min; i>=1; i--) {
			if(A%i==0 && B%i==0) {
				count++;
				val = i;
				if(count==K) {
					break;
				}
			}
		}
		System.out.println(val);
	}

}

Measured memory_bytes: 35768