akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int min,n,a[5],t,min2;
    int i,mini,mini2,mm,fu;
    min=1000000000000000;mini=0;
    scanf("%lld",&n);
    for(i=0;i<5;i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]<min)
        {
            min=a[i];
            mini=i;
        }
    }
    if(n%min!=0)
        fu=1;
    else fu=0;
    t=(4-mini)+n/min+fu;
    mini2=mini;min=1000000000000000;
    while(mini2!=0){
        for(mini2=0,i=0,min=1000000000000000;i<mini;i++)
        {
            if(a[i]<min)
            {
                min=a[i];
                mini2=i;
            }
        }
        if(n%min!=0)
            fu=1;
        else fu=0;
        t+=(mini-mini2);
        mini=mini2;
    }
    printf("%lld",t);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
struct TeamData {
	int number;
	int score;
	int rank;
};

int main(void) {
	struct TeamData team[30], *p,temp;
	int n = 0, i, j, inquiry;

	p = team;
	while (1) {
		scanf("%d,%d", &team[n].number, &team[n].score);
		if (team[n].number == 0 && team[n].score == 0)break;
		n++;
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if ((p + i)->score < (p + j)->score) {
				temp = *(p + i);
				*(p + i) = *(p + j);
				*(p + j) = temp;
			}
		}
	}
	while (scanf("%d", &inquiry) != EOF) {

		p->rank = 1;
		for (i = 1; i <n; i++) {
			if ((p + i)->score == (p + i - 1)->score)
				(p + i)->rank = (p + i - 1)->rank;
			else
				(p + i)->rank = (p + i - 1)->rank + 1;
		}
		for (i = 0; i < n; i++) {
			if ((p + i)->number == inquiry) {
				printf("%d\n", (p + i)->rank);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b)
{
    if (a.F < b.F) return true;
    return false;
}

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

    vector<pair<int, int>> vp;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        vp.push_back(make_pair(a, i + 1));
    }
    sort(vp.begin(), vp.end(), cmp);

    for (int i = 0; i + 1 < vp.size(); i++) {
        cout << vp[i].S << " ";
    }
    cout << vp[n - 1].S << "\n";
}


Measured memory_bytes: 1780
while True:
    a = list(map(lambda x : int(x), input().split(" ")))
    if a[0] == 0 and a[1] == 0:
        break

    for i,i_ in enumerate(range(a[0])):
        for j,j_ in enumerate(range(a[1])):
            if (j-i%2)% 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()

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

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

        public static void Solve()
        {
            var NK = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var pi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(pi);
            var answer = 0;
            for (var i = 0; i < K; i++)
            {
                answer += pi[i];
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28652
# include <iostream>
using namespace std;
int main(){
  long long int n, d,temp,p,count,x,y; 
  cin>>n>>d; 
  temp=d*d;
  count=0;
  while(n--){
    cin>>x>>y; 
    p=x*x+(y*y);
    if(p<=temp){
      count++;
    }
  }
  cout<<count; 
  return 0;
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  ll N, M;
  cin >> N >> M;
  ll MOD = 1e9 + 7;

  vector<ll> S(N + 1);
  vector<ll> T(M + 1);
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
  vector<vector<ll>> su(N + 1, vector<ll>(M + 1, 0));

  for (int s = 1; s <= N; s++) { cin >> S[s]; }
  for (int t = 1; t <= M; t++) { cin >> T[t]; }

  for (ll i = 1; i <= N + M; i++) {
    for (ll j = 1; j <= M; j++) {
      ll s = i - j + 1, t = j;
      if (s < 1 || s > N) continue;

      if (S[s] == T[t]) {
        dp[s][t] = su[s - 1][t - 1] + 1;
      }
        su[s][t] = (su[s - 1][t] + su[s][t - 1] - su[s - 1][t - 1] + dp[s][t]) % MOD;
    }
    // SHOW2(dp);
  }
  cout << (su[N][M] + 1 + MOD) % MOD << BR;

  return 0;
}

Measured memory_bytes: 62976
N, K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

map = Hash.new(0)
a.each do |d|
  map[d] += 1
end

md = map.sort_by { |_k, v| v }

count = 0
0.upto(md.size - K - 1) do |i|
  count += md[i][1]
end
p count

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

using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
typedef pair<ll, ll> pll;
pll piles[N];
ll res[N];
ll min_suff[N];
const int INF = 2e9;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> piles[i].first;
        piles[i].second = i;
    }
    sort(piles, piles + n);
    fill(res, res + n, 0);
    min_suff[n] = INF;
    for (int i = n - 1; i >= 0; i--) {
        min_suff[i] = min(min_suff[i + 1], piles[i].second);
    }
    ll cur = 0;
    ll last = 0;
    ll id = 0;
    for (int i = 0; i < n; i++) {
        cur += piles[i].first - last;
        if (id == piles[i].second) {
            res[id] = cur + (ll)(n - 1 - i) * (piles[i].first - last);
            cur = 0;
            last = piles[i].first;
            id = min_suff[i + 1];
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
}


Measured memory_bytes: 4224
n = int(input())
A = list(map(int, input().split()))
dp = [[None] * 2000 for i in range(n + 1)]


def solve(i, m):
    if dp[i][m] is not None:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i + 1, m) or solve(i + 1, m - A[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]


q = int(input())
M = list(map(int, input().split()))

for i in range(q):
    if solve(0, M[i]):
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5960
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let () = Scanf.scanf "%d %d\n%s" @@ fun n p s ->
  if p = 2 || p = 5 then begin
    Printf.printf "%d\n" @@
    Array.fold_left ( + ) 0 @@
    Array.init n @@ fun i ->
      if 0 < (Char.code s.[i] - Char.code '0') mod p
      then 0
      else i + 1
  end else begin
    let ( +^ ) x y = (x + y) mod p in
    let ( *^ ) x y = (x * y) mod p in
    let inv x = power ( *^ ) 1 x (p - 2) in
    let acc = Array.make (n + 1) 0 in
    let radix = Array.make (n + 1) 1 in
    for i = 0 to n - 1 do
      radix.(i + 1) <- 10 *^ radix.(i);
      acc.(i + 1) <- 10 *^ acc.(i) +^ (Char.code s.[i] - Char.code '0');
    done;
    let ms = Array.make (n + 2) IntMap.empty in
    for i = n downto 0 do
      let x = acc.(i) *^ inv radix.(i) in
      ms.(i) <- IntMap.add x (1 + try IntMap.find x ms.(i + 1) with Not_found -> 0) ms.(i + 1)
    done;
    Printf.printf "%d\n" @@
    Array.fold_left ( + ) 0 @@
    Array.init (n + 1) @@ fun i ->
      let x = acc.(i) *^ inv radix.(i) in
      try IntMap.find x ms.(i + 1) with Not_found -> 0
  end

Measured memory_bytes: 130104
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    cnt=Dict{Int,Int}()
    for i in a
        if haskey(cnt,i)
            cnt[i]+=1
        else
            cnt[i]=1
        end
    end
    ans="No"
    if haskey(cnt,0)
        if length(cnt)==1
            ans="Yes"
        elseif length(cnt)==2 && cnt[0]==n÷3
            ans="Yes"
        end
    end
    if length(cnt)==3
        k=collect(keys(cnt))
        if(k[1]$k[2]$k[3]==0 && cnt[k[1]]==cnt[k[2]]==cnt[k[3]])
            ans="Yes"
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 124312
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n,k = MI()
print((min(n%k, abs(n%k-k))))

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a != c) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);

  Problem::Solver sol;
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

long long gcd(long long a,long long b){
	return b==0?a:gcd(b,a%b);
}

int main(){
	long long x,y;
	scanf("%lld %lld",&x,&y);
	printf("%lld\n",gcd(x,y));
	return 0;
}



Measured memory_bytes: 2112
#include <iostream>
using namespace std;
const int inf = 100000;
int main()
{
  int N, T;
  cin>>N>>T;
  int n, t, ans = inf;
  for(int i=0;i<N;i++)
  {
    cin>>n>>t;
    if(t<=T && ans>n) ans = n;
  }
  if(ans==inf) cout<<"TLE\n";
  else
  	cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int x,y;
	scanf("%d %d",&x,&y);
	while(x>0 || y>0){
		if(x<=y) printf("%d %d\n",x,y);
		if(x>y) printf("%d %d\n",y,x); 
		scanf("%d %d",&x,&y);
	}
	return 0;
}

Measured memory_bytes: 600
from operator import itemgetter

N = int(input())
S = []
for i in range(N):
  tmp = list(input().split())
  S.append([i+1, tmp[0], int(tmp[1])])

S.sort(key=itemgetter(2),reverse=True)
S.sort(key=itemgetter(1))

for i in range(N):
  print(S[i][0])

Measured memory_bytes: 3064
n, d = [int(x) for x in input().split()]
x = []
for _ in range(n):
    x.append([int(x) for x in input().split()])

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k] - x[j][k]) ** 2
        if (dis ** 0.5).is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstring>
using namespace std;

int x[1000];
int n, w, k, maxn, maxx;
double point;

int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n >> w; maxn = 0; maxx = 0; point = 0.01;
		if (n == 0 && w == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> k;
			x[k / w]++;
			maxn = max(maxn, k / w);
		}
		for (int i = 0; i <= maxn; i++) {
			maxx = max(maxx, x[i]);
		}
		for (int i = 0; i <= maxn; i++) {
			point += (1.0*(maxn - i) / maxn)*(1.0*x[i] / maxx);
		}
		cout << fixed << setprecision(15) << point << endl;
	}
}

Measured memory_bytes: 1236
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        ArrayList<String> sList = new ArrayList<>();
        for(int i = 0; i < n; i++) {
          sList.add(sc.next());
        }
      
		int m = sc.nextInt();
        ArrayList<String> tList = new ArrayList<>();
        for(int i = 0; i < m; i++) {
          tList.add(sc.next());
        }
      
        int ans = 0;
        while(sList.size() != 0) {
          String target = sList.get(0);
          int count = 1;
          sList.remove(0);
          while(sList.indexOf(target) != -1) {
            count++;
            sList.remove(sList.indexOf(target));
          }
          while(tList.indexOf(target) != -1) {
            count--;
            tList.remove(tList.indexOf(target));
          }
          if (count > ans) {
            ans = count;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll n, k, a[N];

bool tmam(ll x){
    ll c = 0;
    if(x == 0){
        for(int i = 0; i < n; i++){
            if(a[i] > 0) break;
            int idx = lower_bound(a + i + 1, a + n, 0) - a;
            c += n - idx;
        }
        return c >= k;
    }
    for(int i = 0; i < n; i++){
        if(x > 0){
           if(a[i] == 0) c += n - 1 - i;
           else if(a[i] > 0){
            int idx = upper_bound(a + i + 1, a + n, x / a[i]) - a;
            c += idx - i - 1;
           }
           else{
            int idx = lower_bound(a + i + 1, a + n, x / a[i]) - a;
            c += n - idx;
           }
        }
        else{
            if(a[i] >= 0) break;
            int idx = lower_bound(a + i + 1, a + n, x / a[i] + (x % a[i] != 0)) - a;
            c += n - idx;
        }
    }
    return c >= k;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll low = -1e18, high = 1e18, mid, ans;
    while(high >= low){
        mid = low + high >> 1;
        if(tmam(mid)){
            ans = mid;
            high = mid - 1;
        }
        else low = mid + 1;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 5184
#include <iostream>

using namespace std;

void takahasi(){
	int a, b;
	cin >> a;
	cin >> b;
	if(a==b){
		cout << a << endl;
	}
	else if (a < b){
		cout << a << endl;
	}
	else if (a > b){
		cout << a - 1 << endl;
	}
}

int main(){
	takahasi();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
double pi = 3.141592653589793;
ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    int back;
    int next;
    cin >> next;
    bool ok = true;
    if (next != 0) {
        ok = false;
    }
    ll ans = 0;
    for (int i = 0; i < N - 1; i++) {
        back = next;
        cin >> next;
        if (next >= back + 2) {
            ok = false;
        } else {
            if (next == back + 1) {
                ans++;
            } else {
                ans += next;
            }
        }
    }
    if (!ok) {
        ans = -1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;
    int answer;
    if (A<=5){
        answer = 0;
    }
    else if (A<=12) {
        answer =  B / 2;
    }else{
        answer = B;
    }
    cout<<answer<<endl;
    return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int index = -1;
  for (int i = 0; i <= (int) s.size() - (int) t.size(); i++) {
    bool check = true;
    for (int j = 0; j < t.size(); j++) {
      if (s.at(i + j) != t.at(j) && s.at(i + j) != '?') check = false;
    }
    if (check) index = i;
  }
  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < s.size(); i++) {
    if (index <= i && i < index + t.size()) {
      cout << t.at(i - index);
    } else if (s.at(i) == '?') {
      cout << 'a';
    } else {
      cout << s.at(i);
    }
  }
  cout << endl;
}


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

int main(){
    vector<int> a(3);
    cin>>a.at(0)>>a.at(1)>>a.at(2);
    cout<<a.at(0) + a.at(1) + a.at(2) - *max_element(a.begin(),a.end())<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define inf 1e9+10
#define eps 1e-7
using namespace std;
inline int read(){
	int x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,i;
int main(){
	n=read();i=read();
	printf("%d\n",n-i+1);
	return 0;
} 

Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = []

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

for s in range(x):
    for t in range(y):
        for u in range(z):
            if (s+1) * (t+1) * (u+1) > k:
                break
            ans.append(a[s] + b[t] + c[u])

ans.sort(reverse=True)

for i in range(k):
    print(ans[i])

Measured memory_bytes: 48540
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

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

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

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

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {
	ll K, X;
	cin >> K;
	cin >> X;

	if (500 * K >= X) {
		Yes();
	}
	else {
		No();
	}

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
using namespace std;

const int MAXN = 123456;
int N, L[MAXN], R[MAXN], is_child[MAXN], root;

void preorder_traverse(int root) {
	stack<int> st;
	for(int i=root; ; ) {
		if(i != -1) {
			printf(" %d", i);
			st.push(i);
			i = L[i];
		} else {
			if(st.empty()) break;
			i = R[st.top()];
			st.pop();
		}
	}
}

void inorder_traverse(int root) {
	stack<int> st;
	for(int i=root; ; ) {
		if(i != -1) {
			st.push(i);
			i = L[i];
		} else {
			if(st.empty()) break;
			printf(" %d", st.top());
			i = R[st.top()];
			st.pop();
		}
	}
}

void postorder_traverse_2(int root) {
	stack<int> st;
	int prev = -1;
	for(int i=root; ; ) {
		if(i != -1) {
			st.push(i);
			i = L[i];
		} else {
			if(st.empty()) break;
			i = st.top();
			st.pop();
			if(R[i] == -1 || R[i] == prev) {
				printf(" %d", i);
				prev = i;
				i = -1;
			} else {
				st.push(i);
				i = R[i];
			}
		}
	}
}
 
int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	
	scanf("%d", &N);
	memset(is_child, 0, sizeof(is_child));
	for(int i=0; i<N; ++i) {
		int j;
		scanf("%d", &j);
		scanf("%d%d", &L[j], &R[j]);
		if(L[j] != -1) is_child[L[j]] = 1;
		if(R[j] != -1) is_child[R[j]] = 1;
	}
	
	for(int i=0; i<N; ++i) {
		if(!is_child[i]) {
			root = i;
			break;
		}
	}
	
	puts("Preorder");
	preorder_traverse(root);
	puts("");
	
	puts("Inorder");
	inorder_traverse(root);
	puts("");
	
	puts("Postorder");
	postorder_traverse_2(root);
	puts("");
	
	return 0;
}

Measured memory_bytes: 3212
#include<stdio.h>
int main(){
	int n,m,a,b,i,a1[220000],b1[220000];
  	scanf("%d%d",&n,&m);
  	for(i=0;i<m;i++){
      scanf("%d%d",&a,&b);
      if(a==1)b1[b]++;
      if(b==n)a1[a]++;
	}
	for(i=2;i<=n;i++){
        if(a1[i]>0&&b1[i]>0){
          puts("POSSIBLE");
          return 0;
        }
    }
  puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------
 
 
 
int main(){
  int n,x;
  cin >> n >> x;
  int m[n];
  for(int i=0;i<n;++i){
    cin >> m[i];
  }
  int mini=m[0],total=0;
  for(int i=0;i<n;++i){
    total += m[i];
    mini=min(mini,m[i]);
  }
  int count = n;
  int Temp=x-total;
  do{
    if(Temp>0){
      ++count;
    }
    Temp=Temp-mini;
  }while(Temp>=mini);
  cout << count;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        int[] n = new int[3];
        for (int i = 0; i < 3; i++) {
            n[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(n);

        int a = n[2] - n[0];
        int b = n[2] - n[1];

        int cnt = 0;
        if ((a - b) % 2 > 0) {
            b++;
            cnt++;
        }
        cnt += b;
        a -= b;
        cnt += a / 2;

        System.out.println(cnt);
    }
}


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

void chmin(int& a, int b) {
  if (a > b) a = b;
}

int main() {
  int N, K;
  cin >> N >> K;
  
  int h[N];
  for (int i = 0;i < N; i++) cin >> h[i];
  
  sort(h, h+N);
  
  int ans = h[K-1] - h[0];
  for (int i = 1; i < N-K+1; i++) {
    chmin(ans, h[i+K-1]-h[i]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,s;
  
  cin >> a >> b;
  
  c=a*b;
  
  s = c%2;
  
  if(s == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b,a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	ll N; cin >> N;
	vector<ll> T(N);  rep(i, N) cin >> T[i];

	if (N == 1) {
		cout << T[0] << endl;
		return 0;
	}

	ll ans;
	rep(i, N - 1) {
		if (i == 0) ans = lcm(T[i], T[i + 1]);
		else ans = lcm(ans, T[i + 1]);
	}

	cout << ans << endl;
}

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

using namespace std;

int v[200010],v1[200010],vaz[200010];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n,k,sol=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) {scanf("%d",&v[i]);vaz[v[i]]++;}
    int l=0;
    for(int i=1;i<=n;i++)
        if(vaz[i]>0) {v1[++l]=vaz[i];}
    sort(v1+1,v1+l+1);
    if(l<=k) {printf("0");return 0;}
    for(int i=1;i<=l-k;i++)
        sol+=v1[i];
    printf("%d",sol);
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
typedef long long LL;
const int N = 2e3+5;
const LL mod = 1e9+7;
int a[N];

LL pow(LL a,LL b){
    LL res = 1;
    while(b){
        if(b&1) res = (res*a)%mod;
        a = (a*a)%mod;
        b /= 2;
    }
    return res;
}


int main(){
    int n; LL k;
    scanf("%d%lld",&n,&k);
    for(int i = 1; i <= n; i++){
        scanf("%d",&a[i]);
    }
    LL ans = 0; LL inv = pow(2,mod-2);
    for(int i = 1; i <= n; i++){
        LL cnt = 0, total = 0;
        for(int j = 1; j <= n; j++){
            if(a[j]>a[i]){
                total++;
                if(j<i) cnt++;
            }
        }
        LL plus = (2*cnt+(k-1)*total%mod)*(k)%mod*inv%mod;
        //printf("i = %d: %lld\n",i,plus);
        ans = (ans+plus)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }




    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        int[] s = sc.intarr;
        int N = s[0];
        var A = sc.intarr;
        wr.wri(Math.Abs(A.Min() - A.Max()));
    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;cin>>n>>m;
    if(n > m){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}


/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))

//ll ncr(ll n,ll r,ll p){if(r==0){return 1;}return ((((fact[n]* inv[r]) % p) * inv[n-r]) % p);}
ll dp[100001];
int main()
{
	for(ll i=1;i<=100000;i++)
	{
		dp[i]=1e18;
	}
	ll n,w;
	in2(n,w)
	for(ll i=0;i<n;i++)
	{
		ll we,val;
		in2(we,val);
		for(ll j=100000;j>=val;j--)
		{
			dp[j]=min(dp[j-val]+we,dp[j]);
		}
		

	}
	ll ans=0;
	for(ll i=1;i<=100000;i++)
	{
		if(dp[i]<=w)
		{
			ans=i;
		}
	}
	out(ans)
}
	



	

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

typedef pair<int, int> ii;
const int N = 200005;

struct Edge {
	long long w; int u, v;

	bool operator < (const Edge& to) const {
		return w < to.w;
	}
};

int n;
int a[N];
int sz[N];
int par[N];
int mn;
long long f[N];
bool visit[N];
vector<ii> G[N];
vector<Edge> E;
vector<int> go;

void dfs(int u, int p) {
	sz[u] = 1;
	for (auto v : G[u]) {
		if (v.first == p || visit[v.first]) continue;
		dfs(v.first, u), sz[u] += sz[v.first];
	}
} 

int find(int u, int p, int r) {
	for (auto v : G[u]) {
		if (v.first == p || visit[v.first]) continue;
		if (2 * sz[v.first] >= sz[r]) return find(v.first, u, r);
	}
	return u;
}

void cal(int u, int p) {
	if (f[mn] + a[mn] > f[u] + a[u]) mn = u;
	go.push_back(u);
	for (auto v : G[u]) {
		if (v.first == p || visit[v.first]) continue;
		f[v.first] = f[u] + v.second, cal(v.first, u);
	}
}

void solve(int u) {
	dfs(u, u), u = find(u, u, u), visit[u] = 1;
	go.clear(), mn = u, f[u] = 0, cal(u, u); 
	for (auto i : go) if (i != mn)
		E.push_back({f[i] + f[mn] + a[i] + a[mn], i, mn});
	for (auto v : G[u]) if (!visit[v.first]) solve(v.first);
}

int find(int u) {
	return (u == par[u]) ? u : par[u] = find(par[u]);
}

bool join(int u, int v) {
	u = find(u), v = find(v), par[u] = v; return u != v;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i < n; ++i) {
		int u, v, w; cin >> u >> v >> w;
		G[u].push_back(ii(v, w)), G[v].push_back(ii(u, w));
	}
	solve(1);
	for (int i = 1; i <= n; ++i) par[i] = i;
	sort(E.begin(), E.end());
	long long res = 0;
	for (auto i : E) {
		if (join(i.u, i.v)) res += i.w;
	}
	cout << res;
}

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

using namespace std;

int main() {

	int a = 0, b = 0;
	priority_queue <int> A;
	cin >> a >> b;
	A.push(a + b);
	A.push(a - b);
	A.push(a * b);
	cout << A.top() << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

ll n;

ll dfs(ll m, bool s, bool f, bool t, ll k) {
    if (k == 0) {
        if (m <= n && s && f && t) {
            return 1ll;
        }
        else return 0ll;
    }

    ll res = 0;
    res += dfs(m * 10 + 3, s, f, true, k - 1);
    res += dfs(m * 10 + 5, s, true, t, k - 1);
    res += dfs(m * 10 + 7, true, f, t, k - 1);
    if (!s && !f && !t) res += dfs(0ll, false, false, false, k - 1);
    return res;
}

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

    cin>>n;
    ll temp = n;
    ll k = 0;
    while (temp > 0) {
        temp /= 10;
        k++;
    }
    ll ans = dfs(0ll, false, false, false, k);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
S=input()
S_reverse =S[::-1]

N=len(S)
#1.回文の判定
# for i in range()
flg1 = 0
for i in range(N//2):
    if S[i] != S_reverse[i]:
        flg1+=1

# 2.前半部分は回文
S_pre =S[:N//2]
S_pre_reverse=S_pre[::-1]


flg2=0
if S_pre != S_pre_reverse:
    flg2+=1

# 3.後半部分は回文
S_last = S[int((N+3)/2)-1:]
S_last_reverse = S_last[::-1]

flg3 = 0
if S_last != S_last_reverse:
    flg3 +=1

if flg1 ==0 and flg2 ==0 and flg3==0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<cstdio>

int main(){
    unsigned K, seven = 7, mod = 0, answer = 1;
    scanf("%u", &K);
    while(answer <= K){
        mod = (mod + seven)%K;
        if(!(mod%K)){
            printf("%u\n", answer);
            return 0;
        }
        answer++;
        seven = seven*10%K;
    }
    printf("-1\n");
	return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int main(){
    string S;
    cin>>S;
    for(int i=0;i<S.size();i++){
        if(S.substr(i,10)=="dreamerase"){//dream+rease
            i+=4;
        }else if(S.substr(i,7)=="dreamer"){
            i+=6;
        }else if(S.substr(i,5)=="dream"){
            i+=4;
        }else if(S.substr(i,6)=="eraser"){
            i+=5;
        }else if(S.substr(i,5)=="erase"){
            i+=4;
        }else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 760
(n,m,x),*t=[[*map(int,t.split())]for t in open(0)]
m=9**9
for i in range(1,2**n):
    c,*a=map(sum,zip(*[t[j]for j in range(n)if 1<<j&i]))
    if min(a)>=x:m=min(m,c+1)
print(m%9**9-1)

Measured memory_bytes: 68824
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string S;
int N, K, ret;

int main() {
	cin >> N >> K >> S;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') {
			if (i >= 1 && S[i - 1] == S[i]) ret++;
		}
		if (S[i] == 'R') {
			if (i < N - 1 && S[i + 1] == S[i]) ret++;
		}
	}
	ret = min(ret + 2 * K, N - 1);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

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

    int n, a, b, c, x;
    while (cin >> n >> a >> b >> c >> x, n) {
        vector<int> y(n);
        rep(i, n) cin >> y[i];

        int pos = 0;
        rep(ans, 10000 + 1) {
            if (y[pos] == x) {
                pos++;
            }
            if (pos == n) {
                cout << ans << endl;
                break;
            }
            if (ans == 10000) {
                cout << -1 << endl;
                break;
            }
            x = (a * x + b) % c;
        }
    }
}

Measured memory_bytes: 3112
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long ans = n;
        boolean con = true;

        if(n%k==0){
            System.out.println(0);
            return;
        }

        if(n>=k && n%k != 0){
            n %= k;
        }

        while(con){
            long hikaku = Math.abs(n-k);
            n = hikaku;
            if(ans <=  hikaku){
                break;
            }
            ans = hikaku;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		ArrayList<Integer> array = new ArrayList<Integer>();
		Integer sum = 0;
		int x = 0;
		
		while(sc.hasNext()) {
			Integer a = sc.nextInt();
			sum += a;
			array.add(a);
		}

		if(sum > n) {
			System.out.println(-1);
		} else {
			System.out.println(n - sum);
		}

		sc.close();

	}

}

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

int main() {
	int datas[3000][2];
	int count = 0;
	while (true) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) {
			break;
		}
		datas[count][0] = x;
		datas[count][1] = y;
		count++;
	}
	for (int i = 0; i < count; i++) {
		if (datas[i][0] < datas[i][1]) {
			cout << datas[i][0] << " " << datas[i][1] << endl;
		} else {
			cout << datas[i][1] << " " << datas[i][0] << endl;
		}
	}
}


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

using namespace std;


int main(int argc, char *argv[])
{

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long N;
    cin >> N;
    
    int min_value = 10;
    
    for (long a = 1; a * a <= N; a++) {
        if (N % a != 0) {
            continue;
        }
        long b = N/a;
        min_value = min(min_value,(int) max(to_string(a).length(), to_string(b).length()));
    }
    
    cout << min_value << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define mod 1000000007



int main()
{
 //O_O ;
   ll s,w;
   cin>>s>>w;
   if(s>w)
    cout<<"safe"<<nn;
   else
    cout<<"unsafe"<<nn;


    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const long N=2e5+5,M=1e9+7;
long h,w,a,b,fac[N],ifac[N],ans,up,i;
inline long C(long n,long m){return fac[n]*ifac[m]%M*ifac[n-m]%M;}
int main(){
	cin>>h>>w>>a>>b,up=max(w,h),fac[0]=fac[1]=ifac[0]=ifac[1]=1;
	for(i=2;i<=up<<1;++i)fac[i]=fac[i-1]*i%M,ifac[i]=ifac[M%i]*(M-M/i)%M;
	for(i=2;i<=up<<1;++i)ifac[i]=ifac[i]*ifac[i-1]%M;
	for(i=1;i<=h-a;++i)(ans+=C(b+i-2,b-1)*C(h+w-b-i-1,w-b-1)%M)%=M;
	cout<<ans;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

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

int main()
{
  int tn;
  cin >> tn;
  for (int test = 0; test < tn; ++test) {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    if (D < B || A - B < 0) {
      cout << "No\n";
    } else if (C >= B) {
      cout << "Yes\n";
    } else {
      A %= B;
      ll g = GCD(B, D);
      ll k = (B - A) / g;
      if ((B - A) % g == 0) k--;
      if (A + k * g > C) {
        cout << "No\n";
      } else {
        cout << "Yes\n";
      }
    }
  }
  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int dp[41][1001][1001];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    VI a, b, c;
    REP(i, n){
        int ta,tb,tc;
        cin >> ta >> tb >> tc;
        a.PB(ta);
        b.PB(tb);
        c.PB(tc);
    }

    REP(i, 41) REP(j, 1001) REP(k, 1001) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    REP(i, n){
        REP(j, 1000){
            REP(k, 1000){
                if(dp[i][j][k] != INF){
                    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                    int next_a = j + a[i];
                    int next_b = k + b[i];
                    int cost = dp[i][j][k] + c[i];
                    if(next_a <= 1000 && next_b <= 1000 && cost < dp[i+1][next_a][next_b]){
                        dp[i+1][next_a][next_b] = cost;
                    }
                }
            }
        }
    }

    int res = INF;
    REP1(i, 1001) REP1(j, 1001){
        if(mb * i == j * ma){
            res = min(res, dp[n][i][j]);
        }
    }

    if(res == INF) cout << -1 << endl;
    else cout << res << endl;
}


Measured memory_bytes: 160768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	ll n;
	cin >> n;
	vector<ll> d(n);
	for(int i = 0; i < n; i++)
		cin >> d[i];

	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			ans += d[i]*d[j];
		}
	}

	cout << ans << endl;

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int div_left(int a, int b){
    if(a % b == 0){
        return a/b;
    }else{
        return a/b + 1;
    }
}

int div_right(int a, int b){
    if(a % b == 0){
        return a/b - 1;
    }else{
        return a/b;
    }
}

int main(){
    int n;
    scanf("%d", &n);
    int left = div_left(100*n, 108);
    int right = div_right(100*(n+1), 108);
    if(left <= right){
        printf("%d\n", left);
    }else{
        printf(":(\n");
    }
}

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

int main()
{
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int count = 0;

    for(int i = 0; i <= A; i++)
    {
        for(int j = 0; j <= B; j++)
        {
            for(int k = 0; k <= C; k++)
            {
                if(500*i+100*j+50*k == X)count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string S; cin >> S;
	int ans = 0;
	for (int i = 0; i < S.size()-1; i++)
	{
		if (S[i] != S[i + 1]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
/**
 * @author torith
 * @date 2018-09-30
 */

#include <bits/stdc++.h>

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int D,G;
    cin >> D >> G;
    vector<int> num_q,scores;
    for (int i = 0; i < D; ++i) {
        int a,b;
        cin >> a >> b;
        num_q.emplace_back(a);
        scores.emplace_back(b);
    }

    int tmp = 1;
    int dgt = 1;

    int ans = 1e9;
    for (int mask = 0; mask < (1<<D); ++mask) {
        int sum = 0;
        int tmp_ans = 0;
        int par_max = 0;

        // 全回答を加算 & 部分回答をする問題の種類を選ぶ
        int tmp_mask = mask;
        for (int i = 0; i < D; ++i) {
            if (tmp_mask & 1) {
                sum += 100 * (i + 1) * num_q[i] + scores[i];
                tmp_ans += num_q[i];
            }else{
                par_max = i;
            }
            tmp_mask = tmp_mask >> 1;
        }

        if (sum >= G) {
            ans = min(ans,tmp_ans);
        }else{
            // 部分回答を加算
            for (int j = 1; j < num_q[par_max]; ++j) {
                if (sum + 100 *(par_max + 1)  * j >= G){
                    tmp_ans += j;
                    ans = min(ans,tmp_ans);
                    break;
                }
            }
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 256
@$_=(1e9)x@@for@@=0..<>;/ (.*) /,${$`}[$1]=${$1}[$`]=$' for@M=<>;for$i(@@){//,map$$_[$']-=$-=$$_[$']-$$_[$i]-$$i[$'],@@for@@}print~~grep/ .* /*${$`}[$&]<$',@M

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
string s;
cin>>s;
if(s=="RRS" || s=="SRR") cout<<"2\n";
else if(s=="RRR") cout<<"3\n";
else if(s=="RSS" || s=="SRS" || s=="SSR" || s=="RSR") cout<<"1\n";
else cout<<"0\n";
return(0);
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b ? "true" : "false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vector<bool> v) {
	string res;
	for(int i = 0; i < (int) v.size(); i++)
		res += char('0' + v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template<class T> string to_string(T v) {
    bool f = 1;
    string res;
    for(auto& x : v) {
		if(!f)
			res += ' ';
		f = 0;
		res += to_string(x);
	}
    return res;
}
 
void DBG() {
	cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

void solve() {
	string s, t;
	cin >> s >> t;
	int ans = 1e9;
	int sz = s.size();
	int tz = t.size();
	for(int i = 0; i < sz - tz + 1; i++){
		int cnt = 0;
		for(int j = 0; j < t.size(); j++){
			if(s[i + j] != t[j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << '\n';
}	
 
int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  long long sum = 0;
  int a;
  rep(i, M) {
    cin >> a;
    sum += a;
  }

  if (sum > N) {
    cout << -1 << endl;
  } else {
    cout << N - sum << endl;
  }

  return 0;
}


Measured memory_bytes: 3636