akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
	int l,r,largest;
	l=2*i;
	r=2*i+1;
	if(l<=H&&A[l]>A[i])largest=l;
	else largest=i;
	if(r<=H&&A[r]>A[largest])largest=r;
	if(largest!=i){
		swap(A[i],A[largest]);
		maxHeapify(largest);
	}
}

int main(){
cin>>H;
for (int i = 1; i <= H; ++i) {cin>>A[i];}
for (int i = H/2; i >= 1; i--) {maxHeapify(i);}
for (int i = 1; i <= H; ++i) {cout<<" "<<A[i];}
cout<<endl;
return 0;
}

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr
    
fact = factorization(N)

import math

ans = 0

if N!= 1:
    
    for f in fact:
        X = f[1]
        n = math.ceil(math.sqrt(2*X)-1)
        if n * (n+1) > 2* X:
            n = n-1
            
        ans += n
        
print(ans)

Measured memory_bytes: 9496
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int trash;
    int n;
    trash = scanf("%d", &n);

    int a[n];
    int oneDiff[n];
    int diffCount = 0;
    trash = scanf("%d", &a[0]);
    for (int i = 1; i < n; i++)
    {
        trash = scanf("%d", &a[i]);
        if (a[i] - a[i - 1] == 1)
        {
            oneDiff[diffCount] = a[i - 1] - 1;
            diffCount++;
        }
    }
    sort(oneDiff, oneDiff + diffCount);

    int b;
    int v = 0;
    for (int i = 0; i < n; i++)
    {
        trash = scanf("%d", &b);
        v += b;
    }
    int c;
    int diffUp = 0;
    for (int i = 0; i < n - 1; i++)
    {
        trash = scanf("%d", &c);
        if (diffCount > 0 && i == oneDiff[diffUp])
        {
            v += c;
            diffUp++;
        }
    }

    printf("%d\n", v);
    return 0;
}


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

signed main()
{
	int n;cin>>n;
	n%=10;
	if(n==2||n==4||n==5||n==7||n==9)cout<<"hon"<<endl;
	else if(n==0||n==1||n==6||n==8)cout<<"pon"<<endl;
	else cout<<"bon"<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#define For(i, n) for(int i = 0; i < (n); i ++)

using namespace std;

int main(void){
    int n, q;
    cin >> n >> q;

    vector<int> dp(n+1);
    int pos = 1;
    dp[2] = 1;

    For(i, q){
        int a, b;
        cin >> a >> b;
        
        if(pos == a) pos = b;
        else if(pos == b) pos = a;
        swap(dp[a], dp[b]);
        
        if(pos-1 >= 1) dp[pos-1] = 1;
        if(pos+1 <= n) dp[pos+1] = 1;
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++) if(dp[i] || i == pos) ans ++;
    cout << ans << "\n";
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define int long long

signed main() {
	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	h = min(h, q*2);
	s = min(s, h*2);
	d = min(d, s*2);
	cout << (d*(n/2))+(s*(n%2)) << endl;
	
	return 0;
}

Measured memory_bytes: 256
dish = []
for i in range(5):
    dish.append( int( input() ) )

min_r = 10
min_dish = 0
for i in range(5):
    if dish[i] % 10 != 0 and min_r > dish[i] % 10:
        min_r = dish[i] % 10
        min_dish = i

ans = 0
for i in range(5):
    if i == min_dish or dish[i] % 10 == 0:
        ans += dish[i]
    else:
        ans += (dish[i]//10+1)*10

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  for(int i=0;i<=(n/7);i++){
    int n7=n-(7*i);
    if(n7==0){
      cout<<"Yes"<<endl;
      return 0;
    }else{
      for(int j=1;j<=(n7/4);j++){
        int n4=n7-(4*j);
        if(n4==0){
          cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())

res = 0
for i in range(a+1):
  if i * 500 > d:
    break
  for ii in range(b+1):
    if i * 500 + ii * 100 <= d:
      if (d - (i * 500 + ii * 100)) // 50 <= c:
        res+=1

print(res)


Measured memory_bytes: 3060
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//データ数
      	String[] result=new String[n];
      	int count_Ac=0;
      	int count_Wa=0;
      	int count_Tle=0;
      	int count_Re=0;
      	
    	for(int i=0;i<n;i++){
			result[i]=sc.next();
          
            if(result[i].equals("AC")){
            	count_Ac+=1;
            }
         	if(result[i].equals("WA")){
            	count_Wa+=1;
            }
            if(result[i].equals("TLE")){
            	count_Tle+=1;
            }
         	if(result[i].equals("RE")){
            	count_Re+=1;
            }          
    
      	}
     	

      
      	
        System.out.println("AC x "+count_Ac); 
        System.out.println("WA x "+count_Wa); 
        System.out.println("TLE x "+count_Tle); 
        System.out.println("RE x "+count_Re);       
    } 
}















Measured memory_bytes: 64740
/*
  consider maximum divisor
  can think this question when you have only two numbers :)
*/
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  if (a < b) swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}

int main()
{ 
  int N, K;
  cin >> N >> K;
  int x, M = -1;
  vector<int> a;

  for (int i = 0; i < N; ++ i) {
    cin >> x;
    if (x > M) M = x;
    a.push_back(x);
  }
  
  bool ok = true;
  if (K > M) ok = false;
  else {
    int g = a[0];
    for (int i = 1; i < N; ++ i) {
      g = gcd(g, a[i]);
    }
    if (K % g) ok = false;
  }
                           
  if (ok) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s; cin >> s;
	if(s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) cout << "Bad" << endl;
	else cout << "Good" << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

void solve(long long X, long long Y, long long Z, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    sort(all(A), gr);
    sort(all(B), gr);
    sort(all(C), gr);
    vector<LL> total;
    rep(i, X){
        if((i+1)>K)break;
        rep(j, Y){
            if((i+1)*(j+1)>K)break;
            rep(k, Z){
                if((i+1)*(j+1)*(k+1)>K)break;
                total.emplace_back(A[i]+B[j]+C[k]);
            }
        }
    }
    sort(all(total),gr);
    rep(i, K){
        cout << total[i] << endl;
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(X);
    for(int i = 0 ; i < X ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(Y);
    for(int i = 0 ; i < Y ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(Z);
    for(int i = 0 ; i < Z ; i++){
        scanf("%lld",&C[i]);
    }
    solve(X, Y, Z, K, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string T;
  cin>>T;
  for(int i=0;i<T.size();i++){
    if(T.at(i)=='?'){
      T.at(i)='D';
    }
  }

  cout<<T<<endl;
}

Measured memory_bytes: 3756
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())
As = list(map(int, input().split()))
c = Counter(As)

ans = 0
for i in range(100000):
    ans = max(ans, c[i-1] + c[i] + c[i+1])
print(ans)



Measured memory_bytes: 16068
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

const int C_MAX = 2 * 100000 + 5;

signed main() {
    int N;
    cin >> N;
    int C[N];
    for (int i = 0; i < N; i++) cin >> C[i];

    vector<vector<int>> table(N);
    for (int i = 0; i < N - 1; i++) {
        if (C[i] == C[i+1]) continue; // のちのステップではるエッジ
        table[i].push_back(i+1);
    }

    vector<int> last_idx(C_MAX, -1);

    for (int i = 0; i < N; i++) {
        if (last_idx[C[i]] == -1) { // はじめて出てきた数字
            last_idx[C[i]] = i;
        } else {
            table[last_idx[C[i]]].push_back(i);
            last_idx[C[i]] = i;
        }
    }

    vector<int> dp(N, 0);
    dp[0] = 1;
    for (int i = 0; i < N; i++) {
        for (int next : table[i]) {
            dp[next] += dp[i];
            dp[next] %= MOD;
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] costs = new int[n];
		int[][] degrees = new int[n][m];
		for (int i = 0; i < n; i++) {
		    costs[i] = sc.nextInt();
		    for (int j = 0; j < m; j++) {
		        degrees[i][j] = sc.nextInt();
		    }
		}
		int min = Integer.MAX_VALUE;
		for (int i = 1; i < (1 << n); i++) {
		    int[] current = new int[m];
		    int sum = 0;
		    for (int j = 0; j < n; j++) {
		        if ((i & (1 << j)) == 0) {
		            continue;
		        }
		        sum += costs[j];
		        for (int k = 0; k < m; k++) {
		            current[k] += degrees[j][k];
		        }
		    }
		    boolean flag = true;
		    for (int j = 0; j < m; j++) {
		        if (current[j] < x) {
		            flag = false;
		            break;
		        }
		    }
		    if (flag) {
		        min = Math.min(min, sum);
		    }
		}
		if (min == Integer.MAX_VALUE) {
		    System.out.println(-1);
		} else {
		    System.out.println(min);
		}
	}
}


Measured memory_bytes: 37496
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    rep(i, N)cin >> A[i];
    rep(i, 1000000) {
        rep(j, N) {
            if (A[j] % 2 == 1) {
                cout << i << endl;
                return 0;
            }
            A[j] /= 2;
        }
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
	ll a, b, c, ans;
	scanf("%lld%lld%lld", &a, &b, &c);
	ans=min(min(a*b, b*c), c*a);
	if((a&b&c&1)==0) ans=0;
	printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n; cin >> n;
  int maxa=0,b=0;
  for(int i = 0; i < n; ++i){
    int x,y; cin >> x >> y;
    if(x > maxa){
      maxa = x;
      b = y;
    }
  }
  cout << maxa + b << endl;
}

Measured memory_bytes: 3632
n = gets.to_i
s = gets.chars
v = s.uniq.size

if n == v
  puts 0
elsif v == 1
  puts 1
else
  max = 0
  (0...n).each do |i|
    before = s[0..i]
    after = s[(i+1)...n]
    count = 0

    before.uniq.each do |c|
      count +=1 if after.include?(c)
    end
    max = count if max < count
  end
  puts max
end

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll h,w,d;
  cin >> h >> w >> d;

  vector<pll> a(h*w);
  ll x;
  REP(i, h){
    REP(j, w){
      cin >> x;
      x--;
      a[x] = make_pair(i, j);
    }
  }    

  ll q;
  cin >> q;
  vector<pll> lr(q);
  ll l,r;
  REP(i, q){
    cin >> l >> r;
    l--;
    r--;
    lr[i].FI = l;
    lr[i].SE = r;    
  }
  vll dpx(h*w), dpy(h*w);
  REP(i, h*w){
    if(i-d < 0){
      dpx[i] = 0;
      dpy[i] = 0;
      continue;
    }
    dpx[i] = dpx[i-d] + abs(a[i].SE - a[i-d].SE);
    dpy[i] = dpy[i-d] + abs(a[i].FI - a[i-d].FI);
  }
  
  REP(i, q){
    l = lr[i].FI;
    r = lr[i].SE;
    cout << abs(dpx[l]-dpx[r])+abs(dpy[l]-dpy[r]) << endl;
  }
  
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

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

const int mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> a(n, 0);

    for (int const_m = 2; const_m <= n; const_m++) {
        int m = const_m;
        for (int i = 2; i <= const_m * const_m; i++) {
            while (m % i == 0) {
                m /= i;
                a[i-1] += 1;
            }
        }
        if (m > 1) a[m-1] += 1;
    }

    ll ans = 1;
    for (int ai: a) {
        ans *= (ll(ai) + 1);
        ans %= mod;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n=int(input())
S=[input() for i in range(n)]
data=[inf]*26
for s in S:
    tmp=[0]*26
    for si in s:
        tmp[ord(si)-ord("a")]+=1
    for i in range(26):
        data[i]=min(data[i],tmp[i])
ans=""
# print(data)
for i in range(26):
    # print(ans)
    ans+=chr(ord("a")+i)*data[i]
print(ans)



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

using namespace std;


int main()
{
	string S, T;
	int count = 0;
	cin >> S >> T;


	for (int i = 0; i < 3; i++)
	{
		if (S.at(i) == T.at(i))
		{
			count++;
		}
	}

	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
// AOJ 2773: Periodic Sequence
// 2017.10.9 bal4u@uu
// 2017.11.24

#include <stdio.h>

int s[200005];
int a[200005];

char buf[1400000], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, i, j;

//	scanf("%d", &n);
	fgets(p=buf, 10, stdin), n = getint();

//	for (i = 0; i < n; i++) scanf("%d", s+i);
	fgets(p=buf, sizeof(buf), stdin);
	for (i = 0; i < n; i++) s[i] = getint(), p++;
	
	a[0] = -1, j = -1;
	for (i = 0; i < n; i++) {
		while (j >= 0 && s[i] != s[j]) j = a[j];
		a[i+1] = ++j;
	}
	j = n - a[n];
	if (n % j != 0) puts("1");
	else printf("%d\n", n / j);
	return 0;
}

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

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= (N-i); j++) {
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        cout << i << " " << j << " " << N - i - j << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,i,c=1,d=0,n,m,t,k;
string s,v,w;
cin>>s>>v>>w;
cout<<char(int(s[0])-32)<<char(int(v[0])-32)<<char(int(w[0])-32);
return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}

	int ans = 1, f = 0, max = h[0];
	for(int i = 1; i < n; ++i)
	{
		if(h[i] >= max)
		{
			ans++;
			max = h[i];
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin >> n;
    vector<long long> a(n, 0);
    for(int i = 0; i < n; ++i) cin >> a.at(i);

    list<long long> b;
    int init = n-1;

    if(init % 2 != 0) {
        for(int i = 0; i < n; ++i) {
            if(i % 2 == 0) {
                b.push_back(a.at(i));
            }else {
                b.push_front(a.at(i));
            }
        }
    }else {
        b.push_back(a.at(0));
        for(int i = 1; i < n; ++i) {
            if(i % 2 != 0) {
                b.push_back(a.at(i));
            }else {
                b.push_front(a.at(i));
            }
        }
    }

    for(int i = 0; i < n; ++i) {
        cout << b.front() << " ";
        b.pop_front();
    }
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int a[100010][3];
int dp[100010][3];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> a[i][0] >> a[i][1] >> a[i][2];

    rep(i, 0, N) rep(j, 0, 3) rep(k, 0, 3){
        if(j != k) chmax(dp[i+1][k], dp[i][j]+a[i][j]);
    }

    cout << max({ dp[N][0], dp[N][1], dp[N][2] }) << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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



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


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

	vector<ll> H(N);
	rep(i, N) { cin >> H[i]; }

	sort(H.begin(),H.end());

	ll ans=0;
	rep(i, N - K) { ans += H[i]; }

	cout << ans;
	
	
}


Measured memory_bytes: 1792
from math import sqrt


def f(x):
    ret = []
    for i in range(1, int(sqrt(x)) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)

    return ret


n = int(input())

ans = 1
for k in range(2, int(sqrt(n)) + 1):
    r = n
    while r % k == 0:
        r //= k

    if r % k == 1:
        ans += 1

li = f(n - 1)
for e in li:
    if e > int(sqrt(n)):
        ans += 1

print(ans)


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

    map<string, ll> m;
    NREP() {
        string s;
        cin >> s;
        if (m.find(s) == m.end()) {
            m[s] = 1;
        } else {
            m[s]++;
        }
    }

    ll maximum = -1;
    for (auto &it : m) {
        maximum = max(maximum, it.second);
    }

    for (auto &it : m) {
        if (it.second == maximum) MSG(it.first)
    }
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

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

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	ll n;
	cin >> n;
	if (n%2 == 1) {
		puts("0");
		return 0;
	}

	ll ans = n/10;
	ll m = n;
	/*
	while (m > 0) {
		m /= 10;
		ans += m;
	}
	*/

	for (m = 50; m <= n; m *= 5) {
		ans += n / m;
	}
	cout << ans << endl;
}


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

int main()
{
  int i;
  while (cin >> i) {
    if (i == 0)
      break;

    vector<int> a(i);
    for (int j = 0; j < i; ++j)
      cin >> a[j];

    int num = 32, cnt = 0;
    while (num != 0) {
      num = num - (num-1)%5;
      cout << num << endl;

      num = num - min(num, a[cnt++%i]);
      cout << num << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    if (A % D == 0)
    {
        cout << (C * D <= A * B ? "Yes" : "No");
    }
    else
    {
        cout << (C - A / D * B <= B ? "Yes" : "No");
    }
}


Measured memory_bytes: 3624
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

count = 0
for ai in a:
    count += ans//ai
print(count%1000000007)

Measured memory_bytes: 6072
import Data.Array.IO

rInt = read :: String -> Int

type Ary = IOUArray Int Int

increment :: Ary -> Int -> IO ()
increment ary x = do
    v <- readArray ary x
    writeArray ary x (v + 1)

main = do
    n <- rInt <$> getLine
    a <- ((map rInt) . words) <$> getLine
    ary <- newArray (-1,100001) 0 :: IO Ary
    mapM_ (increment ary) $ (map (+) [-1..1]) <*> a
    (maximum <$> getElems ary) >>= print
    

Measured memory_bytes: 29052
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

//????????????
//test?????£???wrong answer????????£??????

int n,s;
int c;

void search(int a,int sum,int before){
  FOR(i,before,10){
	if(sum+i>s) continue;
	if(a<n) search(a+1,sum+i,i+1);
	else if(sum+i==s) {
	  //	  	  cout << i <<" " << sum << " " << before-1 << endl;
	  c++;
	}
  }
}

 
int main(){
  while(1){
	cin >> n >> s;
	c = 0;
	if(n==0&&s==0) break;
	search(1,0,0);

	cout << c << endl;

  }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char S[100001];
    int N, bstart=0, wstart=0; //black start, white start
    scanf("%s",S);
    N = strlen(S);
    for(int i = 0; i < N; i++)
    {
        if(i%2 == 1)
        {
            if(S[i] == '1')
                wstart++;
            else
                bstart++;
        }
        else if(i%2 == 0)
        {
            if(S[i] == '1')
                bstart++;
            else
                wstart++;
        }
    }
    printf("%d\n",(bstart<wstart)? bstart:wstart);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,m,i,j=0,a,b=100;
	scanf("%d %d",&n,&m);
	if(m==100) n=n*1000+m;
	else if(m>=10) n=n*100+m;
	else n=n*10+m;
	for(i=1;i<n/2;i++){
		if(i*i==n) j=1;
	}
	//printf("%d\n",n);
	if(j==1) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
console.log((args=>{
  const [[N,K],A] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  let p = [];
  for ( let i = 0; i < N-K; i++ ) {
    p.push( (A[i] < A[i+K])?'Yes':'No' );
  }
  return p.join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


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

int main(){
    int N;
    int box[3] = {0};
    cin >> N;
    for(int i = 0; i < N; ++i){
        int a;
        scanf("%d", &a);
        if(a % 4 == 0){
            box[2]++;   
        }else if(a % 2 == 0){
            box[1]++;
        }else{
            box[0]++;
        }
    }
    if((box[1] >= 1 && box[0] <= box[2]) || (box[1] == 0 && box[0] - 1 <= box[2])){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    

    return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static Reader;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var n = NextInt;
        var m = NextInt;

        Console.WriteLine(n == m ? "Yes" : "No");
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = BUF_SIZE - 1;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }


    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (int)(Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


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

int main(){
	int M,N;
    cin >> N >> M;
    
    char a[100][100],b[100][100];
    
    for(int i = 0;i < N;i++){
    	for(int j = 0;j < N;j++){
        	cin >> a[i][j];
        }
    }
    for(int i = 0;i < M;i++){
    	for(int j = 0;j < M;j++){
        	cin >> b[i][j];
        }
    }
   
    
    for(int i = 0;i < N - M + 1;i++){
    	for(int j = 0;j < N - M + 1;j++){
        	bool flag = true;
            for(int k = 0;k < M;k++){
            	for(int l = 0;l < M;l++){
                	if(a[k+i][l+j] != b[k][l]){
                    	flag = false;
                    }
                }
            }
            if(flag){
           		cout << "Yes" << endl;
				return 0;
			}
        }
    }
    
    cout << "No" << endl;
    
    
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include <iomanip>
#include <stack>
using namespace std;

#define rep(p,q) for(int i = p;i < q;i++)

#define LL long long int

#define inf 10000000000

//1_3_A

int main(void) {
	string str;
	stack<int> st = stack<int>();
	while (cin >> str) {
		int a, b;
		if (str == "+") {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(a + b);
		}
		else if (str == "-") {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(b - a);
		}
		else if (str == "*") {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(a * b);
		}
		else {
			st.push(stoi(str));
		}
	}
	cout << st.top() << endl;
}


Measured memory_bytes: 3164
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

constexpr intmax_t MOD = 1e9+7;

intmax_t f(const std::vector<intmax_t>& a) {
  size_t n = a.size();
  std::vector<intmax_t> b(n-1);
  for (size_t i = 1; i < n; ++i)
    b[i-1] = a[i] - a[i-1];

  intmax_t res = 0;
  intmax_t sum = 0;
  for (size_t i = 0; i+1 < n; ++i) {
    intmax_t j = i+1;
    sum += j * b[i] % MOD;
    (res += sum) %= MOD;
  }
  return res;
}

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  std::vector<intmax_t> x(n), y(m);
  for (auto& xi: x) scanf("%jd", &xi);
  for (auto& yj: y) scanf("%jd", &yj);

  intmax_t xs = f(x);
  intmax_t ys = f(y);
  printf("%jd\n", xs*ys % MOD);
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <ctype.h>
#include <set>
#include <map>
#include <list>
#include <stack>

using namespace std;
int p[20500];
int n;
int a[20500];
int b[20500];
int paixu[20500];
bool compare(int a,int b)
{
	return p[a]<p[b];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
	}
	for(int i=1;i<=n;i++)
	{
		a[i]=i*20000;
		b[i]=(n+1-i)*20000;
	}
	for(int i=1;i<=n;i++)
	{
		paixu[i]=i;
	}
	sort(paixu+1,paixu+1+n,compare);
	for(int i=1;i<=n;i++)
	{
		b[i]+=paixu[i]-1;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d",a[i]);
		if(i!=n) printf(" ");
		else printf("\n");
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d",b[i]);
		if(i!=n) printf(" ");
		else printf("\n");
	}
	return 0;
}

Measured memory_bytes: 896
// @prefix atcoder
// @description atcoder template

#include <bits/stdc++.h>
using namespace std;
#define int long long

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

int a, b, n;

signed main() {
    cin >> a >> b >> n;

    int res = 0;

    if (b > n) {
        cout << (a * n) / b - a * (n / b) << endl;
        return 0;
    }
    if (b != 1) {
        int i = n / (b - 1);
        res = max((a * (i * (b - 1))) / b - a * ((b * i - 1) / b), res);
        i--;
        res = max((a * (i * (b - 1))) / b - a * ((b * i - 1) / b), res);
    } else {
        res = 0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define UNIQUE(X) X.erase( unique( X.begin(), X.end() ), X.end() )


typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef vector<int> VI;
typedef vector<LL> VL;


// Order Statistic Tree

/* Special functions:

        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
PII,
null_type,
less<PII>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

/*end of header*/

int n,a[100009],b[100009];
int par[100009];

int findpar(int u)
{
    if(par[u]==u)return u;
    return par[u]=findpar(par[u]);
}

int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
    scanf("%d",&n);
    REP(i,1,n)scanf("%d",&a[i]);
    REP(i,1,n)scanf("%d",&b[i]);
    REP(i,1,n)a[0]^=a[i];
    map<int,int>mp;
    REP(i,0,n)mp[a[i]]++;
    REP(i,1,n)
    {
        if(!mp[b[i]])
        {
            print("-1\n");
            return 0;
        }
        mp[b[i]]--;
    }
    int cntr=0;
    itrALL(mp,it)
    {
        if(it->second)b[0]=it->first;
        mp[it->first]=++cntr;
    }
    int ans=0;
    REP(i,0,cntr)par[i]=i;
    REP(i,0,n)
    {
        if(a[i]==b[i])continue;
        ans++;
        if(findpar(mp[a[i]])!=findpar(mp[b[i]]))par[findpar(mp[a[i]])]=findpar(mp[b[i]]);

    }
    set<int>s;
    bool flag=0;
    REP(i,0,n)
    {
        if(a[i]==b[i])continue;
        s.insert(findpar(mp[a[i]]));
        if(a[i]==a[0])flag=1;
    }
    ans+=s.size();
    if(a[0]!=b[0])ans-=2;
    else ans-=flag;
    print(ans);
    return 0;
}



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

int A, B;
bool b[105][105];

int main() {
	scanf("%d%d", &A, &B);

	printf("100 100\n");

	for (int i = 0; i < 50; ++i) fill(b[i], b[i]+100, 1);

	int x = 0, y = 0;
	while (--A) {
		b[y][x] = 0;
		x += 2; if (x == 100) x = 0, y += 2;
	}

	x = 0, y = 99;
	while (--B) {
		b[y][x] = 1;
		x += 2; if (x == 100) x = 0, y -= 2;
	}

	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			if (b[i][j]) printf("#");
			else printf(".");
		}
		printf("\n");
	}
}

Measured memory_bytes: 256
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
b=[int(input()) for i in range(N)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if A[j][k]==b[i]:
                A[j][k]=0

if (A[0][0]==A[0][1]==A[0][2]==0) or (A[1][0]==A[1][1]==A[1][2]==0) or (A[2][0]==A[2][1]==A[2][2]==0) or (A[0][0]==A[1][0]==A[2][0]==0) or (A[0][1]==A[1][1]==A[2][1]==0)  or (A[0][2]==A[1][2]==A[2][2]==0) or (A[0][0] == A[1][1] == A[2][2] == 0) or (A[2][0]==A[1][1]==A[0][2]==0):
    print('Yes')
else:
    print('No')

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

using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;//<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



int main() {
	int q;
	cin >> q;
	vl a(q), b(q);
	rep(i, q) {
		cin >> a[i] >> b[i];
		if (a[i] < b[i]) {
			swap(a[i], b[i]);
		}
		if (a[i] == b[i]) {
			cout << 2*(a[i] - 1)<< endl;
		}
		else {
			ll res = 0;
			res += 2 * (b[i] - 1);
			ll ok = 0, ng = a[i] - b[i] + 1;
			while (ok + 1 < ng) {
				ll mid = (ok + ng) / 2;
				ll b0 = b[i], a0 = b[i] + mid;
				bool flag = true;
				for (int j = max(0LL, mid / 2 - 100); j < min(mid, mid / 2 + 100); j++) {
					if ((b0 + j)*(a0 - j) >= a[i] * b[i]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					ok = mid;
				}
				else {
					ng = mid;
				}
			}
			cout << res + ok << endl;
		}
	}
}

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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define bad gooood

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 3e3 + 10;
const int M = (int) 1e6 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int ALPHA = 26;
const int mod = INF + 2;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

const int nx[4] = {0, 0, -1, 1};
const int ny[4] = {1, -1, 0, 0};

int n, lim, d;
vec v[N];
int p[N], m[N], sz[N], pos[N];
ll sum[N];

void dfs(int x) {
  sum[x] = m[x];
  sz[x] = 1;
  for (auto it : v[x]) {
    dfs(it);
    sum[x] += sum[it];
    sz[x] += sz[it];
  }
}

bool cmp(int x, int y) {
  return sum[x] * sz[y] < sum[y] * sz[x];
}

int cnt[N];

int get(ll clim) {
  int ans = 0;
  for (int it = 1; it <= n; it++) {
    int i = pos[it];
    ll take = clim / sum[i];
    if (i > 1) take = min(take, 1ll * d - cnt[it]);
    ans += take * sz[i];
    clim -= take * sum[i];
  }
  return ans;
}

ll dp[55][55 * 55 * 55];

int main() {
  #define fn "saddle"
  #ifdef witch
      freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> n >> lim >> d;
  for (int i = 1; i <= n; i++) {
    cin >> m[i];
    if (i > 1) {
      cin >> p[i];
      v[p[i]].pb(i);
    }
  }
  dfs(1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    pos[i] = i;
  }
  sort(pos + 1, pos + n + 1, cmp);
  for (int it = 0; it <= n; it++) {
    for (int j = 0; j <= 50 * 50 * 50; j++) {
      dp[it][j] = LINF;
    }
  }
  dp[0][0] = 0;
  for (int it = 1; it <= n; it++) {
    int i = pos[it];
    for (int j = 0; j <= 50 * 50 * 50; j++) {
      for (int take = 0; take <= (i == 1 ? 50 : min(50, d)); take++) {
        if (j - take * sz[i] < 0) continue;
        dp[it][j] = min(dp[it][j], dp[it - 1][j - take * sz[i]] + take * sum[i]);
      }
    }
  }
  for (int j = 0; j <= n * 50 * 50; j++) {
    if (lim - dp[n][j] >= 0) {
      int cur_ans = j;
      ll clim = lim - dp[n][j];
      for (int it = 1; it <= n; it++) {
        int i = pos[it];
        ll take = clim / sum[i];
        if (i > 1) take = min(take, 1ll * d - 50);
        if (take <= 0) continue;
        cur_ans += take * sz[i];
        clim -= take * sum[i];
      }
      ans = max(ans, cur_ans);
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 67584
n, s = map(int, input().split())
a = sorted(list(map(int, input().split())))
mod = 998244353

dp = [[0] * (s+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(1, n+1):
    for j in range(s+1):
        dp[i][j] += 2 * dp[i-1][j]
        dp[i][j] %= mod

        if j + a[i-1] <= s:
            dp[i][j+a[i-1]] += dp[i-1][j]
            dp[i][j+a[i-1]] %= mod

print(dp[-1][-1])


Measured memory_bytes: 139256
s=input()
s2=input()

s_len=len(s)

res='No'

s_mod=s

if s_mod==s2:
  res='Yes'
else:
	for i in range(1,s_len+1):
		s_mod=s_mod[-1]+s_mod[:-1]
		if s_mod==s2:
			res='Yes'
			break

print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll MOD=1000000007;
const double PI = acos(-1);

int main(){
  int a,p; cin>>a>>p;
  int piece = a*3 + p;
  cout << piece/2 << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
#define M 1000000
using namespace std;

int isprime(ll n){
    if(n==1) return 0;
    if(n==2 || n==3) return 1;
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}

void answer(){
    ll n,ans=0,m,p=0,x;
    cin>>n>>m;
    //ll a[n];

    cout<<ceil(n*1.0/m);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

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

    double d=(((n+1)/2)*1.0)/n;

    cout<<d<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
using pll = pair<long long, long long>;

int main() {
    int N, M; cin >> N >> M;
    vector<long long> A(N), B(M), C(M);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());
    B.resize(M);
    C.resize(M);
    for (int i = 0; i < M; ++i) cin >> B[i] >> C[i];

    // C をソート (B をまとめて)
    vector<int> id(M);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int i, int j) {
            return C[i] > C[j];});

    // A (小さい順) と C (大きい順) とを比べて大きい方を足していく
    long long sum = 0;
    long long K = 0;
    for (auto i : id) {
        for (int j = 0; j < B[i]; ++j) {
            if (K >= N) break;
            sum += max(A[K++], C[i]);  
        }
    }
    for (int i = K; i < N; ++i) sum += A[i];        
    cout << sum << endl;
}

Measured memory_bytes: 5888
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;

    int x=1,i=0;
    for(;x<b;i++){
        x+=a-1;
    }

    cout<<i<<endl;

	return 0;
}


Measured memory_bytes: 256
s = input()
alp = "abcdefghijklmnopqrstuvwxyz"
if len(s) == 26:
    bck = []
    for i in range(25):
        bck.append(s[25-i])
        if s[25-i] > s[24-i]:
            for j in range(alp.find(s[24-i]),26):
                if alp[j] in bck:
                    sn = alp[j]
                    break
            print(s[0:24-i]+sn)
            exit()
    print(-1)
else:
    for i in alp:
        if i in s:
            continue
        else:
            print(s+i)
            exit()


Measured memory_bytes: 3064
local function reada(n,m)m=m or 1 r={}for i=1,m do r[i]={}end for i=1,n do for j=1,m do r[j][i]=io.read"*n"end end return unpack(r)end
N=io.read"*n"
M=io.read"*n"
H=reada(N)

t={}
for i=1,N do t[i]={}end

for i=1,M do
	a=io.read"*n"
	b=io.read"*n"
	table.insert(t[a],b)
	table.insert(t[b],a)
end
s=0
for i=1,N do
	b=true
	for j=1,#t[i]do
		if(H[t[i][j]]>=H[i])then b=false break end
	end
	if(b)then s=s+1 end
end
print(s)

Measured memory_bytes: 12112