akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n, k = [int(x) for x in input().split()]
    p = [int(x) for x in input().split()]
    s = 0
    for i in range(k):
        s += p[i]
    max_sum = s
    for i in range(n-k):
        s += p[k+i] - p[i]
        max_sum = max(s, max_sum)
    return (max_sum + k) / 2


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 25304
#include <stdio.h>
int main(){

  int a,b,c,x;

  x=0;
  
  scanf("%d %d %d",&a,&b,&c);

  for (a; a <= b; a++){

    if (c%a == 0){

      x++;

    }

  }

  printf("%d\n",x);

  return 0;

}

Measured memory_bytes: 596
s = input()
for i in range(len(s)-1):
    if s[i] == s[i+1] :
        print(i+1, i+2)
        break
    elif i+2 < len(s) and s[i] == s[i+2]:
        print(i+1, i+3)
        break
else:
    print(-1, -1)


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/


const int MAX_N = 1 << 17;

// [1,n]
int bit[MAX_N+1], n;

int sum(int i){
    int s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & -i;   // iの最後の1ビットを引いている
    }
    return s;
}

void add(int i, int x){
    while(i<=n){
        bit[i] += x;
        i += i & -i;
    }
}

int main()
{
    cin >> n;
    int q; cin >> q;
    rep(_,q){
        int com; cin >> com;
        if(com == 0){
            int x, y; cin >> x >> y;
            add(x, y);
        }else if(com == 1){
            int x, y; cin >> x >> y;
            cout << sum(y) - sum(x-1) << endl;
        }
    }
}


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

int main() {
	int n,k;
  cin>>n>>k;
  vector<int> a(n,1);
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
   for(int j=0;j<d;j++){
     int A;
     cin>>A;
     a[A-1]=0;
   }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void){
    ll n;
    cin >> n;
    ll a[5];
    for(ll i = 0; i < 5; i++){
        ll b;
        cin >> b;
        a[i] = b;
    }
    sort(a, a+5);
    ll ans = n/a[0]+4;
    if(n%a[0]!=0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

gcd = lambda *numbers: reduce(math.gcd, numbers)

K = int(input())

answer = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            answer += gcd(a, b, c)

print(answer)


Measured memory_bytes: 74924
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
ll dp[3005][3005][2];
ll a[3005];
ll solve(ll l,ll r,ll p)
{	

	ll &res = dp[l][r][p];
	if(res!=-1)
		return res;
	if(l==r)
		if(p==1)
			return res=a[l];
		else
			return res=-a[l];

	if(p==1)
	{
		res=max(solve(l+1,r,!p)+a[l],solve(l,r-1,!p)+a[r]);
	}
	else
	{
		res=min(solve(l+1,r,!p)-a[l],solve(l,r-1,!p)-a[r]);
	}

	return res; 

}	

int main()
{	
	IOS
	ll n;
	cin>>n;
	
	memset(dp,-1,sizeof(dp));
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(n==1)
	{
		cout<<a[0];
		return 0;
	}

	ll ans=solve(0,n-1,1);

	cout<<ans<<endl;
}
    
 
    
    


Measured memory_bytes: 141568
n=int(input())
otosidama=0
for i in range(n):
  m = list(input().split())
  okane=float(m[0])
  if(m[1]=="BTC"):
    okane=okane*380000.0
  otosidama=otosidama+okane
print(otosidama)  
    

Measured memory_bytes: 2940
object Main extends App {
  val N = io.StdIn.readLine().toInt
  val Ls = io.StdIn.readLine().split(" ").map(_.toInt)
  var ans = 0
 
  for (ai <- Ls.indices){
    for (bi <- ai until Ls.length) {
      for (ci <- bi until Ls.length){
        if ((ai != bi) && (bi != ci) && (ai != ci)) {
          val a = Ls(ai)
          val b = Ls(bi)
          val c = Ls(ci)
          if (a != b && b != c && a != c) {
            if ((a + b > c) && (b + c > a) && (a + c > b)) {
              ans += 1
            }
          }
        }
      }
    }
  }
 
  println(ans)
}

Measured memory_bytes: 54812
from collections import deque

N, M = map(int, input().split())
l =[[] for _ in range(N)]

q=deque([0])

TFl=[0]*N
TFl[0]=1
ml=[-1]*N

for i in range(M):
  A,B=map(int,input().split())
  l[B-1].append(A-1)
  l[A-1].append(B-1)

while q:
  p = q.popleft()
  for i in l[p]: #普通に1行ずつ回してるイメージ
    if TFl[i]==1:
      continue
    TFl[i]=1
    ml[i]=p
    q.append(i)

if all([i==1 for i in TFl]):
  print('Yes')
  for i in range(1, N):
    print(ml[i]+1)

else:
  print('No')


Measured memory_bytes: 35312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int mod = 1000000007;
const int N = 210;
int rec[N][N];
int R[N];
int main() 
{
   // freopen("in.txt", "r", stdin);
    int n, m, r;
    while (~scanf("%d%d%d", &n, &m, &r))
    {
        int h[N];
        memset(h, 0, sizeof(h));
        memset(rec, INF, sizeof(rec));
        for (int i = 0; i < r; i++)
        {
            scanf("%d", R + i);
            h[R[i]] = 1;
        }

        for (int i = 0; i < m; i++)
        {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            rec[u][v] = min(rec[u][v], w);
            rec[v][u] = min(rec[v][u], w);
        }
        for (int k = 1; k <= n; k++)
        {
            if (h[k])
                continue;
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                {
                    if (rec[i][j] > (rec[i][k] + rec[k][j]))
                        rec[i][j] = rec[i][k] + rec[k][j];
                }
        }
        sort(R, R + r);
        int ans = INF;
        do
        {
            int tmp = 0;
            for (int i = 1; i < r; i++)
            {
                int u = R[i-1], v = R[i];
                tmp += rec[u][v]; 
            }
            ans = min(ans, tmp);
        }while (next_permutation(R, R + r));
        printf("%d\n", ans);
    }
   
    return 0;
}


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

int main(){
  string N;
  cin>>N;
  if(N=="A") cout<<"T";
  if(N=="T") cout<<"A";
  if(N=="G") cout<<"C";
  if(N=="C") cout<<"G";
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int c(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int main(){
 int n,k[100000];
 scanf("%d", &n);
 for(int i = 0; i < n; i++) {
  scanf("%d", &k[i]);
 }
 qsort(k, n, sizeof(int), c);
 printf("%d", k[n/2 -1] == k[n/2] ? 0: k[n/2]-k[n/2 -1]);
}

Measured memory_bytes: 892
#include<stdio.h>
main(){
  int i,n,m;
  for(i=1;;i++){
    scanf("%d %d",&n,&m);
    if(n==0 && m==0)break;
    if(n>m)printf("%d %d\n",m,n);
    else printf("%d %d\n",n,m);
  }
  return 0;
}



Measured memory_bytes: 2032
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

d = [(1,0),(-1,0),(0,1),(0,-1)]
def solve(h,w):
    s = LIR(2*h-1)
    bfs = [[0]*w for i in range(h)]
    bfs[0][0] = 1
    q = deque([(0,0)])
    g = (h-1,w-1)
    while q:
        y,x = q.popleft()
        if (y,x) == g:
            print(bfs[y][x])
            return
        nb = bfs[y][x]+1
        for dy,dx in d:
            ny,nx = y+dy,x+dx
            if 0 <= ny < h and 0 <= nx < w:
                if dy and not s[2*min(y,ny)+1][nx]:
                    if not bfs[ny][nx]:
                        bfs[ny][nx] = nb
                        q.append((ny,nx))
                elif dx and not s[2*ny][min(x,nx)]:
                    if not bfs[ny][nx]:
                        bfs[ny][nx] = nb
                        q.append((ny,nx))
    print(0)
    return

#Solve
if __name__ == "__main__":
    while 1:
        w,h = LI()
        if w == h == 0:
            break
        solve(h,w)



Measured memory_bytes: 6096
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
H = [int(_) for _ in stdin.readline().rstrip().split()]
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
ans = [1]*N
for a, b in AB:
    if H[a-1] >= H[b-1]:
        ans[b-1] = 0
    if H[b-1] >= H[a-1]:
        ans[a-1] = 0
print(sum(ans))

Measured memory_bytes: 32016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
int par[100010];
int rank1[100010];

void init(int n)
{
    for(int i = 0; i < n; i++){
        par[i] = i;
        rank1[i] = 0;
    }
}

int find(int x)
{
    if(par[x] == x){
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y){
        return ;
    }
    if(rank1[x] , rank1[y]){
        par[x] = y;
    } else {
        par[y] = x;
        if(rank1[x] == rank1[y]){
            rank1[x]++;
        }
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

bool comp(pair<int, pair<int, int> > in1, pair<int, pair<int, int> > in2)
{
    return in1.first > in2.first;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    init(n);
    vector<pair<int, int> > y(n);
    vector<pair<int, int> > x(n);
    for(int i = 1; i <= n; i++){
        cin >> x[i - 1].first;
        cin >> y[i - 1].first;
        x[i - 1].second = i;
        y[i - 1].second = i;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<pair<int, pair<int, int> > > distance;
    for(int i = 0; i < n - 1; i++){
        pair<int, pair<int, int> > in;
        in.second.first = x[i].second;
        in.second.second = x[i + 1].second;
        in.first = x[i + 1].first - x[i].first;
        distance.push_back(in);
        in.second.first = y[i].second;
        in.second.second = y[i + 1].second;
        in.first = y[i + 1].first - y[i].first;
        distance.push_back(in);
    }
    long long ans = 0;
    sort(distance.begin(), distance.end(), comp);
    for(int i = 1; i < n; i++){
        while(same(distance.back().second.first, distance.back().second.second)){
            distance.pop_back();
        }
        ans += (long long)distance.back().first;
        unite(distance.back().second.first, distance.back().second.second);
        distance.pop_back();
    }
    cout << ans << endl;
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  map<int, bool> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m.find(a) == m.end()) {
      m.emplace(a, true);
    } else {
      m.erase(a);
    }
  }
  int count = 0;
  for (auto x : m) {
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 4864
/*Bismillahir Rahmanir Rahim*/


#include<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#define ll long long int
#define dd double
using namespace std;

int main()
{
   ll a,b,c;
   cin>>a>>b>>c;
   ll t=min(a,c),ak=0;
   c-=t;
   a-=t;
   if(c>0)
   {
     ak=min(c,b);
   }
   b-=ak;
   cout<<a<<" "<<b<<endl;

    

}
//Apna Time Aayega :)

Measured memory_bytes: 3576
n = int(input())
data1 = [[0 for _ in range(10)] for _ in range(3)] # data[i][j] = i+1階、j+1番目の部屋
data2 = [[0 for _ in range(10)] for _ in range(3)]
data3 = [[0 for _ in range(10)] for _ in range(3)]
data4 = [[0 for _ in range(10)] for _ in range(3)]
data_index = [data1, data2, data3, data4]
for _ in range(n):
    b, f, r, v = map(int, input().split())
    data_index[b-1][f-1][r-1] = data_index[b-1][f-1][r-1] + v
for i in range(3):
    for j in range(10):
        print(f' {data1[i][j]}', end='')
    print()
print('####################')
for i in range(3):
    for j in range(10):
        print(f' {data2[i][j]}', end='')
    print()
print('####################')
for i in range(3):
    for j in range(10):
        print(f' {data3[i][j]}', end='')
    print()
print('####################')
for i in range(3):
    for j in range(10):
        print(f' {data4[i][j]}', end='')
    print()



Measured memory_bytes: 5644
while n = gets.chomp.to_i
  break if n == 0
      tmp = Hash.new(0)
      tmp2 = Hash.new(false)
  n.times do |i|
    line = gets
    e,p,q = line.split.map(&:to_i)
    tmp[e] += p * q
    if p * q >= 1000000
      puts e
      tmp2[e] = true
    end
    if  tmp[e] >= 1000000 && tmp2[e] == false
      puts e
    end
    if  i == n-1 && (tmp.max{|a,b| a[1]<=>b[1]})[1] < 1000000
      puts "NA" 
    end
  end
end


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

int main(void)
{
	char pat[256];
	char str[256];
	int ans;
	int n;
	char s[256];
	
	scanf("%s", pat);
	
	scanf("%d", &n);
	
	ans = 0;
	for (int i = 0; i < n; i++){
		scanf("%s", s);
		
		sprintf(str, "%s%s", s, s);
		if (strstr(str, pat) != NULL){
			ans++;
		}
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int A, B;
    cin >> A >> B;
    int ans;
    if(A > 9 || B > 9){
        ans = -1;
    } else {
        ans = A * B;
    }
    cout << ans << endl;
    
    return 0;
}


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

int main(){
  string str;

  getline(cin,str);

  for(int i=0;i<(int)str.size();i++)
    {
      if( islower(str[i]) )
	{
	  str[i]=toupper(str[i]);
	}
      else if( isupper(str[i]))
	{
	  str[i]=tolower(str[i]);
	}
    }
  cout << str << endl;
}
	  



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

int main()
{
	string a, b;
	cin >> a >> b;
	b.erase(b.size() - 1);
	if(a == b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
string s; int K;
 
int main(){
  
  cin>>s>>K;
  
  for(int i=0; i<s.size(); i++){
    int p='z'-s[i]+1;
     if(p<=K&&s[i]!='a'&&i!=s.size()-1){
       K-=p;
       s[i]='a';
     }
     if(i==s.size()-1&&K>0){
       if(K>=p){
         K-=p; K%=26; s[i]='a';
         s[i]+=K;
       }else s[i]+=K;
     }
     if(K==0) break;
   }
   
   cout<<s<<endl;
  
   return 0;
 
}

Measured memory_bytes: 512
/* code by AbhiTaker
         ____
        /    \
       /  __  \              _______      __       _   _    _____    _____
      /  /  \  \            |__   __|    /  \     | | / /  |  ___|  |  _  \
     /  /____\  \     ___      | |      / /\ \    | |/ /   | |__    | |_)  )
    /  /______\  \   |___|     | |     / /__\ \   |   /    |  __|   |    _/
   /  /        \  \            | |    / /----\ \  | |\ \   | |___   | |\ \
  /__/          \__\           |_|   /_/      \_\ |_| \_\  |_____|  |_| \_\
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define M 1000000007
#define N 1000016
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define inf 9000000000000000000
string str[N];

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    string s,s2;
    cin>>n;
    cout<<"0\n";
    fflush(stdout);
    cin>>s;
    if(s=="Vacant")
        return 0;
    cout<<n-1<<"\n";
    fflush(stdout);
    cin>>s2;

    if(s2=="Vacant")
        return 0;

    for(ll i=0; i<n-1; i++)
    {
        if(i%2==0)
            str[i] = s;
        else
            str[i] = s2;
    }

    ll l = 1, r = n-2;
    while(1)
    {
        ll mid = l + (r-l)/2;
        cout<<mid<<"\n";
        fflush(stdout);
        cin>>s;
        if(s=="Vacant")
            return 0;

        if(s==str[mid])
            l = mid+1;
        else
            r = mid-1;
    }



    return 0;
}


Measured memory_bytes: 8660
import sys

nil = -1

class Node:
    def __init__(self):
        self.parent = nil
        self.sibling = nil
        self.degree = 0
        self.left = nil
        self.right = nil
        self.depth = nil
        self.height = nil
        self.ntype = 'leaf'

def set_depth(v, depth):
    bitree[v].depth = depth

    if bitree[v].left != nil:
        set_depth(bitree[v].left, depth + 1)

    if bitree[v].right != nil:
        set_depth(bitree[v].right, depth + 1)

def get_height(v):
    h1 = 0
    h2 = 0

    if bitree[v].left != nil:
        h1 = get_height(bitree[v].left) + 1
    if bitree[v].right != nil:
        h2 = get_height(bitree[v].right) + 1

    bitree[v].height = max(h1, h2)

    return bitree[v].height

n = int(input())
bitree = [Node() for i in range(n)]
leaves = set()

for i in range(n):
    line = [int(j) for j in input().split()]
    t_id = line[0]
    bitree[t_id].left = line[1]
    bitree[t_id].right = line[2]
    bitree[t_id].degree = (line[1] != nil) + (line[2] != nil)

    if bitree[t_id].degree > 0:
        bitree[t_id].ntype = 'internal node'

        if bitree[t_id].left != nil:
            bitree[bitree[t_id].left].parent = t_id

        if bitree[t_id].right != nil:
            bitree[bitree[t_id].right].parent = t_id

        if bitree[t_id].degree == 2:
            bitree[bitree[t_id].left].sibling = bitree[t_id].right
            bitree[bitree[t_id].right].sibling = bitree[t_id].left
    else:
        leaves.add(t_id)

for t_id in range(n):
    if bitree[t_id].parent == nil:
        bitree[t_id].ntype = 'root'
        r = t_id
        break

set_depth(r, 0)

get_height(r)

for t_id in range(n):

    print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(
            t_id, bitree[t_id].parent, bitree[t_id].sibling, bitree[t_id].degree,
            bitree[t_id].depth, bitree[t_id].height, bitree[t_id].ntype))

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll k, a, b; cin >> k >> a >> b;
  if(k + 1 <= a||b - a <= 2)
  {
    fin(k + 1);
  }
  else
  {
    ll ans = a;
    k -= (a - 1);
    if(k % 2 == 1) { ans++; k--;}
    ans += ((b - a) * (k / 2));
    fin(ans);
  }
}

//前処理
int main()
{
  ifstream in("text.txt");
  cin.rdbuf(in.rdbuf());
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 256
from itertools import groupby, accumulate, product, permutations, combinations

def solve():
    ans = 0
    S = list(map(int,list(input())))
    for p in product([0,1],repeat=len(S)-1):
        total = S[0]
        for i in range(len(S)-1):
            if p[i]==1:
                ans += total
                total = S[i+1]
            else:
                total *= 10
                total += S[i+1]
        ans += total
    return ans
print(solve())

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N) for (int i = (init); i < (int)(N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

struct T{
    string s;
    VI childs;
};

void dfs(vector<T> &ts, int x, int deep) {
    if (x != 0) {
        rep(i, deep - 1) {
            cout << ".";
        }
        cout << ts[x].s << endl;
    }

    for (auto c : ts[x].childs) {
        dfs(ts, c, deep + 1);
    }
}

int main(void) {
    int n;
    cin >> n;
    vector<T> ts(n + 1);
    rep(i, n) {
        string s;
        int parent;
        cin >> parent >> s;
        ts[i + 1].s = s;
        ts[parent].childs.PB(i + 1);
    }

    dfs(ts, 0, 0);

	return 0;
}

Measured memory_bytes: 1428
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=2005,mod=1e9+7;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int n,m;
LL x;
struct Edge{
	int x,y,z;
	LL v;
}e[N];
bool cmp(Edge a,Edge b){
	return a.z<b.z;
}
int fa[N];
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
bool cmp2(Edge a,Edge b){
	return a.v<b.v;
}
int main(){
	n=read(),m=read(),x=read();
	For(i,1,m)
		e[i].x=read(),e[i].y=read(),e[i].z=read();
	sort(e+1,e+m+1,cmp);
	For(i,1,m){
		For(i,1,n)
			fa[i]=i;
		e[i].v=e[i].z;
		fa[getf(e[i].y)]=getf(e[i].x);
		For(j,1,m){
			if (i==j)
				continue;
			int x=e[j].x,y=e[j].y,z=e[j].z;
			x=getf(x),y=getf(y);
			if (x!=y){
				fa[y]=x;
				e[i].v+=z;
			}
		}
	}
	sort(e+1,e+m+1,cmp2);
	if (m<=1)
		return puts("0"),0;
	LL mst=e[1].v;
//	For(i,1,m)
//		printf("%d %d %d %lld\n",e[i].x,e[i].y,e[i].z,e[i].v);
	if (x==mst){
		int ans=Del(Pow(2,m)-2);
		For(i,1,m)
			if (e[i].v!=mst)
				Del(ans,Pow(2,m-i+1));
		cout<<ans<<endl;
	}
	else {
		int ans=0;
		For(i,1,m)
			if (e[i].v==x)
				Add(ans,Pow(2,m-i+1));
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll h[n];
	rep(i,0,n) cin >> h[i];

	for(ll i=n-2; i>=0; i--){
		if(h[i]<=h[i+1]) continue;
		else{
			if(h[i]-h[i+1]>1){
				cout << "No";
				return 0;
			}
			else{
				if(h[i]=h[i+1]+1) h[i]--;
				else continue;
			}
		}
	}
	cout << "Yes";
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

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


#define ll long long
#define MOD 1000000007

int main() {
	// your code goes here
	ll n, m; cin>>n>>m;
	
	ll dp[n][m];
	char mp[n][m];
	
	for(int i = 0; i < n; i++) {
	    for(int j = 0; j < m; j++){
	        cin>>mp[i][j];
	    }
	}
	
	
	
	dp[0][0] = 1;
	
	for(int i = 1; i < n ; i++) {
	    if(mp[i][0] == '#') {
	        dp[i][0] = 0;
	        continue;
	    }
	    
	    
	    dp[i][0] = dp[i-1][0];
	}
	
	
	for(int i = 1; i < m ; i++) {
	    if(mp[0][i] == '#') {
	        dp[0][i] = 0;
	        continue;
	    }
	    
	    
	    dp[0][i] = dp[0][i-1];
	}
	
	
	for(int i = 1; i < n; i++) {
	    for(int j = 1; j < m; j++) {
	        
	        if(mp[i][j] == '#') {
	            dp[i][j] = 0;
	            continue;
	        }
	        
	        dp[i][j] = ((dp[i-1][j]%MOD) + (dp[i][j-1]%MOD))%MOD;
	        
	    }
	}
	
	
	cout<<dp[n-1][m-1]<<endl;
	
	
	return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,W;cin>>n>>W;
    vl w(n),v(n);rep(i,n)cin>>w[i]>>v[i];

    ll w1=w[0];
    rep(i,n)w[i]-=w1;

    ll ans=0;
    repe(i,1,n){
        if(i*w1>W)continue;
        ll ww=W-i*w1;
        chmin(ww,500LL);

        vvl dp(i+1,vl(ww+1));
        rep(j,n){
            for(ll l=i;l>=0;l--){
                for(ll k=ww;k>=0;k--){
                    if(k+w[j]<=ww&&l<i){
                        chmax(dp[l+1][k+w[j]],dp[l][k]+v[j]);
                        chmax(ans,dp[l+1][k+w[j]]);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

char c[55][55]; int H, W, cnt;

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#'){
              cnt++;
              break;
            }
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<double> p(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
    }
    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
    dp[0][0] = 1;

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (j > 0) {
                dp[i][j] += dp[i - 1][j - 1] * p[i];
            }
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
        }
    }
    double ans = 0;
    for (int i = (N + 2 - 1) / 2; i <= N; i++) {
        ans += dp[N][i];
    }
    cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    long double rate = 1.0 / N;
    long double rate_sum = 0;
    int point = 0;
    int count = 0;
    for(int i = 1; i <= N; i++) {
        point = i;
        while(point <  K) {
            point *= 2;
            rate *= 0.5;
        }
        rate_sum += rate;
        rate = 1.0 / N;
    }
    cout << std::setprecision(13) << rate_sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char t, s[1001], com[8], rep[1001];
  int p, a, b;
  scanf("%s\n%d", s, &p);

  for (int i = 0; i < p; i++) {
	  scanf("%s%d%d", com, &a, &b);
  	  if(com[0] == 'p'){
	    for (int i = a; i <= b; i++) printf("%c", s[i]);
		printf("\n");
	  }
	  else if (com[2] == 'p'){
		scanf("%s", rep);
	  	for (int i = a, j = 0; i <= b; i++, j++) s[i] = rep[j];
	  }
	  else
	  {
		  for ( ; a < b; a++, b--) {
		  t = s[a]; s[a] = s[b]; s[b] = t;
		  }
	  }
  }
  return 0;
}



Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>X(N);
	rep(i, 0, N)cin >> X[i];
	int ans = INF;
	rep(i, 0, 101) {
		int cnt = 0;
		rep(j, 0, N) {
			int x = X[j] - i;
			cnt += x * x;
		}
		chmin(ans, cnt);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [x for x in map(int, input().split())]
#n, m = map(int, input().split())
#print("sp", n, q, file=sys.stderr)

# 改行区切りの整数の入力
#a = []
#for x in range(m):
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]

# 文字列の入力
s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()


def doit(s):
  ok = True
  for x in range(m):
    res = 0
    for y in range(a[x][0]):
      if s[a[x][y+1]-1] == 1:
        res = res + 1
    #print("res", res, file=sys.stderr)
    if res % 2 != p[x]:
      ok = False
      break
  #print("ok", ok, file=sys.stderr)
  return ok

def createSw(n):
  if n <= 1:
    return [[0,], [1,]]

  ret = []
  for x in createSw(n-1):
    #print("sw0", x, file=sys.stderr)
    ret.append(x + [0])
    ret.append(x + [1])
    #print("ret", ret, file=sys.stderr)
  #print("ret", ret, file=sys.stderr)
  return ret

#print(doit([0] * 4))
try:
  res = 0
#  for x in createSw(n):
#  for x in itertools.product(range(2), repeat=n):
#    print("x", x, file=sys.stderr)
#    if doit(x):
#      res = res + 1
#  print((n-3)*180)
  l = len(s)
  for x in s:
    if x == 'x':
      res += 1
  print(15 - l, 8 - res, file=sys.stderr)
  if l - res >= 8: 
    print("YES")
  elif res >= 8 or 15 - l < 8 - res:
    print("NO")
  else:
    print("YES")
except Exception as e:
  print("e", e, file=sys.stderr)


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

int main() {
  ll n, m, a;
  cin >> n >> m;

  priority_queue<double> q;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    q.push(a);
  }
  
  for (ll i = 0; i < m; i++) {
    // cout << q.top() << endl;
    a = q.top() / 2;
    q.pop();
    q.push(a);
  }

  ll total = 0;
  for (ll i = 0; i < n; i++) {
    total += (int) q.top();
    q.pop();
  }

  cout << total << endl;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    int A, B, C, D, E, F;
    std::cin >> A >> B >> C >> D >> E >> F;

    double percent = 100.0 * double(E) / double(100 + E); 
    int water, sugar;
    int ans1, ans2;
    double max = 0.0;
    for (int i = 0; i <= F; i += 100*A) {
        for (int j = 0; j <= F; j += 100*B) {
            for (int k = 0; k <= F - (i+j); k += C) {
                for (int l = 0; l <= F - (i+j+k); l += D) {
                    if (i == 0 && j == 0) {
                        break;
                    }
                    water = i+j+k+l;
                    sugar = k+l;
                    double conc = 100.0 * double(sugar) / double(water);
                    if (conc <= percent) {
                        if (max <= conc) {
                            max = conc;
                            ans1 = water;
                            ans2 = sugar;
                        }
                    }
                }
            }
        }
    }

    std::cout << ans1 << " " << ans2 << std::endl;

    return 0;
}

Measured memory_bytes: 256
///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull unsigned long long
///////////////////////////////////////////////////////////
template <class T>
T absolute(const T& n);
template <class T>
void input(vector<T>& vec);
template <class T>
void output(const vector<T>& vec);
template <class T>
T sum(const vector<T>& vec);
template <class T>
void upsort(vector<T>& vec);
template <class T>
void downsort(vector<T>& vec);
template <class T>
T max(const vector<T>& vec);
template <class T>
T min(const vector<T>& vec);
template <class T>
vector<bool> isPrime(T max);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main()
{
    ull n;
    cin >> n;

    for (ull i = sqrt(n); i > 0; --i) {
        if (n % i == 0) {
            cout << i + n / i - 2 << endl;
            return 0;
            ;
        }
    }
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
template <class T>
T absolute(const T& n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

template <class T>
void input(vector<T>& vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cin >> vec.at(i);
    }
}

template <class T>
void output(const vector<T>& vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

template <class T>
T sum(const vector<T>& vec)
{
    T initial = 0.0;
    T s = accumulate(vec.begin(), vec.end(), initial);
    return s;
}

template <class T>
void upsort(vector<T>& vec)
{
    sort(vec.begin(), vec.end());
}

template <class T>
void downsort(vector<T>& vec)
{
    sort(vec.begin(), vec.end(), greater<T>());
}

template <class T>
T max(const vector<T>& vec)
{
    T m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = max(m, vec.at(i));
    }
    return m;
}

template <class T>
T min(const vector<T>& vec)
{
    T m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = min(m, vec.at(i));
    }
    return m;
}

template <class T>
vector<bool> isPrime(T max)
{
    vector<bool> isPrime(max + 1, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for (size_t i = 2; i * i <= max; ++i) {
        if (isPrime[i]) {
            for (size_t j = 2; i * j <= max; ++j) {
                isPrime[i * j] = false;
            }
        }
    }
    return isPrime;
}
///////////////////////////////////////////////////////////

Measured memory_bytes: 256
def f(d, name1, name2)
    return f(d, name2, name1) if name1.size < name2.size
    return name1 == name2 if d == 0
    return false if name1.size > name2.size + d

    if name1.size == name2.size + d
        return name2 =~ (/^#{name1.split("").join(??)}?$/)
    end

    return true if name2 == ""

    if name1[0] == name2[0]
        return f(d, name1[1..-1], name2[1..-1])
    else
        b = f(d-1, name1[1..-1], name2)
        return true if b
        if name1.size == name2.size
            b = f(d-1, name2[1..-1], name1)
            return true if b
        end
        b = f(d-1, name1[1..-1], name2[1..-1])
        return true if b
        if name1.size >= 2
            b = f(d-1, name1[0..1].reverse + name1[2..-1], name2)
            return true if b
        end
        if name2.size >= 2
            b = f(d-1, name1, name2[0..1].reverse + name2[2..-1])
            return true if b
        end
    end
    
    return false
end

loop do
    n = gets.to_i
    break if n == 0
    d = gets.to_i
    
    names = (1..n).map { gets.chomp }

    ans = []
    names.combination(2) do |name1, name2|
        ans << [name1, name2].sort if f(d, name1, name2)
    end
    puts ans.sort.map {|n1, n2| "#{n1},#{n2}"}
    puts ans.size
end

Measured memory_bytes: 9616
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>P(N);
  vector<int>Q(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  for(int i=0;i<N;i++){
    cin>>Q.at(i);
  }
  vector<int>R(N);
  vector<vector<int>>W;
  for(int i=0;i<N;i++){
    R.at(i)=i+1;
  }
  do{
    W.push_back(R);
  }while (next_permutation(R.begin(), R.end()));
  int a,b;
  for(int i=0;i<W.size();i++){
    if(W.at(i)==P){
      a=i;
    }
    if(W.at(i)==Q){
      b=i;
    }
  }
  cout<<abs(a-b)<<endl;
}
    
  

Measured memory_bytes: 3256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2000
#define MO 1000000007
using namespace std;
int dp[MAXN+5][MAXN+5];
int fact[MAXN*MAXN+5],inv[MAXN*MAXN+5];
int PowMod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
void prepare()
{
	fact[0]=1;
	for(int i=1;i<=MAXN*MAXN;i++)
		fact[i]=1LL*fact[i-1]*i%MO;
	inv[MAXN*MAXN]=PowMod(fact[MAXN*MAXN],MO-2);
	for(int i=MAXN*MAXN-1;i>=0;i--)
		inv[i]=1LL*inv[i+1]*(1LL*i+1LL)%MO;
}
int C(int n,int m)
{
	if(n<m)
		return 0;
	return 1LL*fact[n]*inv[m]%MO*inv[n-m]%MO;
}
int main()
{
//	freopen("ball.in","r",stdin);
//	freopen("ball.out","w",stdout);
	int N,K;
	scanf("%d %d",&N,&K);
	if(K==1)
	{
		printf("1\n");
		return 0;
	}
	dp[0][0]=1;
	prepare();
	for(int i=0;i<=N;i++)
		for(int j=0;j<=i;j++)
		{
			if(i-1>=0)
				dp[i][j]=(1LL*dp[i][j]+1LL*dp[i-1][j])%MO;
			if(j-1>=0)
			dp[i][j]=(1LL*dp[i][j]+1LL*dp[i][j-1]*C(N*K-(K-1)*(j-1)-i-1,K-2)%MO)%MO;
		}
	int ans=1LL*dp[N][N]*fact[N]%MO;
	printf("%d\n",ans);
	return 0;
}

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

int main (){
    int h, w, k ;
    cin >> h >> w >> k ;
    vector<vector<char>> nyuu (h, vector<char> (w)) ;
    rep(i, h){
        rep(j, w){
            cin >> nyuu[i][j] ;
        }
    }
    int ans = 0 ;
    rep(i, 1<<h){
        rep(j, 1<<w){
            vector<vector<char>> masu = nyuu ;
            int num = 0;
            rep(k, h){
                if(i>>k & 1){
                    rep(p, w) {
                    masu[k][p] = '!' ;}                
                }
            }
            rep(k, w){
                if(j>>k & 1){
                    rep(p, h){
                        masu[p][k] = '!' ;
                    }

                }
            }
            rep(ll , h){
                rep(lll, w){
                    if(masu[ll][lll] == '#'){
                        num++ ;
                    }
                }
            }
            if(num == k){
                ans++ ;
            }
        }
    }
    cout << ans << endl ;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
vector<ll> V;
int pre[maxn];
int main() {
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>pre[i];    
    sort(pre+1,pre+1+n);
	ll sum=0;
	for(int i=1;i<=k;i++) sum+=pre[i];
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	int answer = 0;
	int smallest_so_far = n + 1;
	for(int i = 0; i < n; ++i) {
		if(smallest_so_far > p[i]) {
			answer++;
			smallest_so_far = p[i];
		}
	}
	cout << answer;
}

//4 3
//444 3333


Measured memory_bytes: 1024
n = int(input())
li = [int(i) for i in input().split()]

if len(li) == 2:
    for i in range(1, max(li) + 1):
        if li[0] % i == 0 and li[1] % i == 0:
            print(i)
else:
    for i in range(1, max(li) + 1):
        if li[0] % i == 0 and li[1] % i == 0 and li[2] % i == 0:
            print(i)


Measured memory_bytes: 5604
#include <iostream>

#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <cmath>
#include <algorithm>

#include <fstream>

using namespace std;

#define M_PI 3.14159265358979323846264338327950288

int main()
{
  srand(179179);

  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  cout.setf(ios_base::fixed);
  cout.precision(28);

  long long n, t;
  cin >> n >> t;
  vector<int> v(n);
  for (auto& x : v) {
    cin >> x;
  }

  vector<int> v2(2 * n);
  for (int i = 0; i < 2 * n; ++i) {
    v2[i] = v[i % n];
  }
  vector<vector<int> > mn(2 * n, vector<int>(2 * n, 2e9));
  for (int i = 0; i < 2 * n; ++i) {
    for (int j = i; j < 2 * n; ++j) {
      if (j > i) {
        mn[i][j] = mn[i][j - 1];
      }
      mn[i][j] = min(mn[i][j], v2[j]);
    }
  }

  long long ans = 1e18;
  for (int i = 0; i <= n; ++i) {
    long long c = 0;
    for (int j = 0; j < n; ++j) {
      c += mn[n + j - i][j + n];
    }
    ans = min(ans, c + i * t);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 62976