akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
// #define int long long


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

    int n,m; cin >> n;
    vector<int> a(n+1),b(n+1);

    for(int i = 1;i < n+1;i ++){
        cin >> a.at(i);
    }

    for(int i = n;i > 0;i --){
        int sum = 0;
        int j = i * 2;
        while(j <= n){
            sum += b.at(j);
            j += i;
        }

        if(sum % 2 != a.at(i)) b.at(i) =  1;
    }

    for(int i = 1;i < n+1;i ++){
        m += b.at(i);
    }

    cout << m << endl;

    for(int i = 1;i < n+1;i ++){
        if(b.at(i)) cout << i << " ";
    }

    cout << endl;

}

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

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

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

int main()
{

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = 1001001001001001001;
    for (int i = 0; i <= 2 * max(x, y); i += 2)
    {
        ll cnt = a * max(x - i / 2, 0) + b * max(y - i / 2, 0) + c * i;
        if (cnt > 0)
        {
            ans = min(ans, cnt);
        }
    }

    cout << ans << '\n';
    return (0);
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;

  ll d = 10, p = 0;
  REP(i, 8){
    if(n == d) p++;
    d *= 10;
  }
  if(p) cout << 10 << endl;
  else{
    ll tmp = n, ans = 0;
    while(tmp){
      ans += tmp % 10;
      tmp /= 10;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum_a = sum(a)

for i in range(n):
    if a[-1-i] - b[-1-i] >= 0:
        left = a[-1-i] - b[-1-i]
        a[-1-i] = left
        b[-1-i] = 0
    else:
        b[-1-i] = abs(a[-1-i] - b[-1-i])
        a[-1-i] = 0

    if a[-2-i] - b[-1-i] >= 0:
        a[-2-i] = a[-2-i] - b[-1-i]
    else:
        a[-2-i] = 0

print(sum_a - sum(a))

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

int S[300009], A[300009], C[22], B[300009], X[300009];
vector<int> que[22];

int main() {
    set<int> st;
    int N; scanf("%d",&N);
    for(int i=0; i<(1<<N); i++) {
        scanf("%d", &S[i]);
        ++C[__builtin_popcount(i)];
        B[i] = -1;
        if(i) st.insert(i);
    }
    sort(S, S+(1<<N)); reverse(S, S+(1<<N));
    vector<int> T;
    for(int i=0; i<(1<<N); i++) {
        if(i) {
            if(S[i-1] == S[i]) A[i] = A[i-1] + 1;
            else {
                A[i] = 1;
                T.push_back(A[i-1]);
            }
        }
        else A[i] = 1;
    }
    T.push_back(A[(1<<N) - 1]);
    for(int i=0, j=0, s=0; i<T.size(); i++) {
        s += T[i];
        while(j < s) X[j++] = s;
    }
    //for(int i=0; i<(1<<N); i++) printf("X: %d\n", X[i]);
    que[0].push_back(0);
    for(int i=0; i<N; i++) {
        for(auto& it: que[i]) {
            auto tmp = st.lower_bound(X[it]);
            if(tmp == st.end()) return !printf("No");
            que[i+1].push_back(*tmp);
            que[i+1].push_back(it);
            st.erase(tmp);
        }
    }
    if(st.size()) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 18040
x = list(map(int, input().split()))
count = 0
l = []
for i in range(1, x[0]+1):
  tmp = x[1] + i - 1
  l.append(tmp)
if (0 in l) == True:
  for i in l:
    count += i
else:
  if l[0] > 0:
    for i in l[1:]:
      count += i
  else:
    for i in l[:-1]:
      count += i
print(count)

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

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		long A = nextLong();
		long B = nextLong();
		long N = nextLong();


		long ans = 0;
		long x=Math.min(N, B-1);
		ans=(long)(A*x/B)-A*(long)(x/B);


		System.out.println(ans);
	}


	public static long gcd(long a, long b) {
		long x, y;
		if (a < b) {
			x = b;
			y = a;
		} else {
			x = a;
			y = b;
		}
		long r;
		while ((r = a % b) != 0) {
			a = b;
			b = r;
		}
		return b;
	}

	public static void test(int N,int M,int n,int c,long cnt,int[] x){
		if(c==N){
			return;
		}


	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

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

int cnt[200010];
int N, K;
int ret;

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

	rep(i, N) {
		int x;
		cin >> x;
		++cnt[x];
	}

	vi vec;
	rep(i, 200010) if (cnt[i] > 0) {
		vec.pb(cnt[i]);
	}

	sort(ALL(vec));
	reverse(ALL(vec));

	int now = 0;
	rep(i, vec.size()) {
		if (now < K) {
			++now;
			ret += vec[i];
		}
	}

	cout << N - ret << endl;

	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;


// 1-indexed
class FenwickTree {
    long long n;
    vector<long long> a;
public:
    FenwickTree(long long n) : n(n), a(n+1, 0) {}
    long long get(long long i) {
        long long sm = 0;
        for(; i > 0; i -= i&-i) sm += a[i];
        return sm;
    }
    void set(long long i, long long x) {
        for(; i <= n; i += i&-i) a[i] += x;
    }
    long long at(long long i){return get(i) - get(i-1);}
};


// 順序を保存したまま圧縮する
// ex) 1,5,8,8,2,4 -> 1,4,5,6,2,3 
void compress(vector<long long> &a){
    auto b = a;
    sort(b.begin(), b.end());
    map<long long, long long> mp;
    long long num = 1;
    for(auto x : b){
        if(mp[x] == 0)
            mp[x] = num;
        num++;
    }
    for(auto &x : a)
        x = mp[x]++;
}

// バブルソートの交換回数 (反転数、転倒数、inversion)
// 1~n からなる vector を与えて 1,2,...,n にソートする交換回数
// <=> i < j, a[i] > a[j] となる組の数
// 今までに出現した数以下に1を足しながら左から順に見ていけば良い
long long inversion(const vector<long long> &a){
    long long N = a.size();
    long long ans = 0;
    FenwickTree ft(N);
    for(long long i=0; i<N; i++){
        ans += i - ft.get(a[i]);
        ft.set(a[i], 1);
    }
    return ans;
}

bool judge(vector<long long> &a, long long x){
    long long N = a.size();
    vector<long long> b(N), c(N+1, 0);

    for(long long i=0; i<N; i++)
        b[i] = (a[i] <= x) ? 1 : -1;

    for(long long i=1; i<=N; i++)
        c[i] = c[i-1] + b[i-1];

    for(long long i=1; i<=N; i++)
        c[i] = -c[i];


    compress(c);

    long long inv = inversion(c);

    return inv >= N*(N+1)/4+1;
}

int main(){
    long long N;
    cin >> N;
    vector<long long> a(N);
    for(long long i=0; i<N; i++) cin >> a[i];

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

    vector<long long> b = a;
    b.push_back(-1);
    sort(b.begin(), b.end());

    long long lb = 0, ub = N;
    while(ub - lb > 1){
        long long mid = (lb + ub) / 2;
        if(judge(a, b[mid])) ub = mid;
        else lb = mid;
    }
    cout << b[ub] << endl;

    return 0;
}

Measured memory_bytes: 10464
#include<stdio.h>
int Block[30][6];
int score=0,n;
void Jo();
int main()
{
  int i,j,score1[1000],m=0;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<20;i++){
      for(j=0;j<6;j++){
	Block[i][j]=0;
      }
    }
    for(i=10;i<n+10;i++){
      for(j=0;j<5;j++){
        scanf("%d",&Block[i][j]);
      }
    }
    Jo();
    score1[m]=score;
    score=0;
    m++;
  }
  for(i=0;i<m;i++){
    printf("%d\n",score1[i]);
  }
  return 0;
}

void Jo()
{
  int i,j,m,s,score1=0,k,l;
  while(1){
    for(i=10;i<n+10;i++){
      for(j=0;j<3;j++){
	if(Block[i][j]!=0 &&Block[i][j]==Block[i][j+1]&&Block[i][j]==Block[i][j+2]){
	  score1+=3*Block[i][j];
	  if(j==0&&Block[i][j]==Block[i][j+3]){
            score1+=Block[i][j];
            if(Block[i][j]==Block[i][j+4])score1+=Block[i][j];
	  }
	  if(j==1 && Block[i][j]==Block[i][j+3])score1+=Block[i][j];
	  j+=2;
}
      }
    }
    if(score1==0)return;
    score+=score1;
    score1=0;
    for(i=10;i<n+10;i++){
      if(Block[i][0]!=0){
        s=Block[i][0];
        m=1;
      }
      for(j=1;j<6;j++){
	if(Block[i][j-1]==0 &&Block[i][j]!=0){
	  s=Block[i][j];
	  m=0;
	}
	if(s==Block[i][j])m++;
	if(m>=3 && s!=Block[i][j]){
	  for(k=j-1;m>0;k--){
            for(l=i;l>0;l--){
	      Block[l][k]=Block[l-1][k];
	    }
            m--;
	  } 
	}
	if(s!=Block[i][j]){
	  s=Block[i][j];
	  m=1;
	}
      }
    }
  }
}

Measured memory_bytes: 600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    P = int(1e9)+7
    s = 0
    for k in range(60):
        cnt = 0
        for num in A:
            if (num>>k) & 1:
                cnt += 1
        s += cnt*(N-cnt) * 2**k
        s %= P
    print(s)
if __name__ == '__main__':
    main()


Measured memory_bytes: 35852
#include <stdio.h>
#include <math.h>

int main(){
  int v,n,i,j,k,l,flag,tmp,count = 0;
  scanf("%d", &n);
  int A[n];
  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
  }

  flag = 1;
  while(flag == 1){
    flag = 0;
    for(j=n-1;j>=1;j--){
      if(A[j]<A[j-1]){
        flag = 1;
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        count++;
      }
    }

  }

  for(l=0;l<n;l++){
    printf("%d", A[l]);
    if(l != n-1){
      printf(" ");
    }
  }
    printf("\n");
    printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 1992
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n){
		int i,j,count=0,count1;
		for(i=1;i<=n;i+=2){
			count1=0;
			for(j=1;j<=n;j++){
				if(i%j==0){
					count1++;
				}
			}
			if(count1==8){
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

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

int main(){
	string s;
	cin >> s;
	if(s[s.size() - 1] == '2' ||s[s.size() - 1] == '4' ||s[s.size() - 1] == '5' ||s[s.size() - 1] == '7' ||s[s.size() - 1] == '9'){
		cout << "hon";
	}
	else if(s[s.size() - 1] == '0' ||s[s.size() - 1] == '1' ||s[s.size() - 1] == '6'||s[s.size() - 1] == '8'){
		cout << "pon";
	}
	else if(s[s.size() - 1] == '3'){
		cout << "bon";
	}
	return 0;
} 

Measured memory_bytes: 3624
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline


N, M = map(int, input().split())
H = list(map(int, input().split()))

path = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    path[a - 1].append(b - 1)
    path[b - 1].append(a - 1)

# print(path)

counter = 0
for i, obs in enumerate(path):
    flag = True
    own_height = H[i]
    for other in obs:
        if own_height > H[other]:
            pass
        elif own_height <= H[other]:
            flag = False
            break

    if flag:
        counter += 1

print(counter)


Measured memory_bytes: 29552
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 5007;
int n, A, B;
int a[N];
LL f[N], ans = 1e18;
int main() {
#ifdef fwat
#endif
	n = gi(), A = gi(), B = gi();//A:r B:l
	rep(i, 1, n) a[i] = gi();
	rep(i, 1, n) {
		f[i] = 1e18;
		LL tot = 0;
		for(int j = i - 1; ~j; --j) {
			if(a[i] > a[j]) Min(f[i], f[j] + tot);
			if(a[j] > a[i]) tot += A;
			else tot += B;
		}
		Min(ans, f[i] + (LL) (n - i) * B);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y)
{
	return y?gcd(y,x%y):x;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		long long a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(a<b||d<b)printf("No\n");
		else if(c>=b)printf("Yes\n");
		else
		{
			long long l=a-b,r=a-c-1;
			long long t=gcd(b,d);
			if(l/t==r/t)printf("Yes\n");
			else printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[[0]*n for _ in range(n)]
u=0
k=0
for i in range(n):
    ukv=list(map(int,input().split()))
    for j in range(2,2+ukv[1]):
        a[ukv[0]-1][ukv[j]-1]=1
for i in range(n):
    print(" ".join(map(str,a[i])))



Measured memory_bytes: 5668
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

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

  int m = 0;
  int d = INT_MIN;
  int x;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (i == 0) {
      m = x;
      continue;
    }
    d = max(d, x - m);
    if (x < m) {
      m = x;
    }
  }

  cout << d << endl;
  return 0;
}

Measured memory_bytes: 1164
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int n,t;
pair<int,int> dish[3010];
int DP[3010][3010];

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>t;
	
	for(int i=0;i<n;i++)cin>>dish[i].first>>dish[i].second;
	
	sort(dish,dish+n);
	
	int ans=0;
	
	for(int i=0;i<n;ans=max(DP[i][t-1]+dish[i].second,ans),i++)for(int j=0;j<t;j++)
	{
		DP[i+1][j]=max(DP[i][j],DP[i+1][j]);
		
		if(j+dish[i].first<t)DP[i+1][j+dish[i].first]=max(DP[i+1][j+dish[i].first],DP[i][j]+dish[i].second);
	}
	
	cout<<ans;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin >> a;
	int n=0,s=0,w=0,e=0,b=a.size();
	for(int i=0;i<b;i++){
		if(a[i]=='N'){
			n++;
		}else if(a[i]=='S'){
			s++;
		}else if(a[i]=='W'){
			w++;
		}else if(a[i]=='E'){
			e++;
		}
	}
	if(((n==0&&s==0)||(n!=0&&s!=0))&&((w==0&&e==0)||(w!=0&&e!=0))){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
s=input()
l=len(s)
ans=0
for i in range( 1<< (l-1)):
    temp=int(s[0])
    value=0
    for j in range(l-1):
        if i>>j &1:
            value+=temp
            temp=int(s[j+1])
        else :
            temp=10*temp+int(s[j+1])
    value+=temp
    ans+=value
    
    
print(ans)
    




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int INF = 999999;
int main(){
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  int ma = INF;
  for (int i = 0; i < A; i++){
    cin >> a[i];
    ma = min(ma, a[i]);
  }
  vector<int> b(B);
  int mb = INF;
  for (int i = 0; i < B; i++){
    cin >> b[i];
    mb = min(mb, b[i]);
  }
  vector<int> x(M), y(M), c(M);
  int m = INF;
  for (int i = 0; i < M; i++){
    cin >> x[i] >> y[i] >> c[i];
    m = min(m, a[x[i] - 1] + b[y[i] - 1] - c[i]);
  }
  cout << min(ma + mb, m);
}

Measured memory_bytes: 2176
card = [list(map(int, input().split())) for _ in range(3)]
used = [[False for _ in range(3)] for _ in range(3)]
n = int(input())
for _ in range(n):
	b = int(input())
	for i in range(3):
		for j in range(3):
			if card[i][j] == b:
				used[i][j] = True

ok = False
for i in range(3):
	if used[i][0] and used[i][1] and used[i][2]:
		ok = True
	if used[0][i] and used[1][i] and used[2][i]:
		ok = True
	if used[0][0] and used[1][1] and used[2][2]:
		ok = True
	if used[0][2] and used[1][1] and used[2][0]:
		ok = True
if ok:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
#define MAX 1500000

bool prime[MAX];

void is_prime(){
    fill(prime,prime+MAX,true);
    prime[0] = prime[1] = false;
    
    for(int i = 2 ; i*i < MAX ; i++)
        if(prime[i])
            for(int j = 2*i ; j < MAX ; j += i)
                prime[j] = false;
}

int main(){
    int n;
    is_prime();
    
    while(cin >> n,n){
        int a,i;
        
        if(prime[n]) cout << '0' << endl;
        else{
            for(i = n ; prime[i] != true ; i++);
            a = i;
            for(i = n ; prime[i] != true ; i--);
            cout << a-i << endl;
        }
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const ll MAXN = 50 + 5;
const ll MAXK = 1e5 + 10;

int main() {
    ll H, W;
    cin >> H >> W;
    vector<vector<char>> grid(H, vector<char>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> grid[i][j];
        }
    }
    vector<vector<ll>> dp(H, vector<ll>(W, 0));
    dp[0][0] = 1;
    for (int i = 1; i < H; ++i) {
        if (grid[i][0] == '#') break;
        dp[i][0] = dp[i - 1][0];
    }
    for (int j = 1; j < W; ++j) {
        if (grid[0][j] == '#') break;
        dp[0][j] = dp[0][j - 1];
    }
    for (int i = 1; i < H; ++i) {
        for (int j = 1; j < W; ++j) {
            if (grid[i][j] == '#') continue;
            dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N, K;
  cin >> N >> K;
  vll H(N);
  rep(i, N) {
    cin >> H[i];
  }
  SORT(H);

  ll ans = INF;
  rep(i, N) {
    if (i + K - 1 >= N) {
      continue;
    }
    ll sa = abs(H[i + K - 1] - H[i]);
    ans = min(ans, sa);
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 1024
def main():
    h, w = list(map(int, input().split()))
    n = int(input())
    A = list(map(int, input().split()))
    ans = [str(i + 1) for i, a in enumerate(A) for _ in range(a)]
    for i in range(h):
        if i % 2 == 0:
            print(' '.join(ans[i * w:i * w + w]))
        else:
            print(' '.join(ans[i * w + w - 1:i * w - 1:-1]))
if __name__ == '__main__':
    main()


Measured memory_bytes: 9556
a, b, k = map(int, input().split())

aend = a + k - 1
bstart = b - k + 1
if aend >= bstart:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, aend+1):
        print(i)
    for i in range(bstart, b+1):
        print(i)


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

import sys

n = int(raw_input().split()[0])
tl = []
for i in range(n):
    e = [int(e) for e in raw_input().split()]
    tl.append(e)
#print tl

t = 0
x = 0
y = 0
ans = 'Yes'
for i in tl:
    ti, xi, yi = i
    dt = ti - t
    dx = abs(xi - x)
    dy = abs(yi - y)
    # print [t,x,y], i, [dt,dx,dy],
    if (dx + dy) > dt:
        # print '!',
        ans = 'No'
        break
    if (dt - (dx + dy)) & 1:
        # print '!!',
        ans = 'No'
        break
    # print
    t = ti
    x = xi
    y = yi
    
# print
sys.stdout.write('%s\n' % (ans))
sys.stdout.flush()


Measured memory_bytes: 23044
#include <iostream>
#include <string.h>
using namespace std;

long long n, m = 1;
long long a[100002];
const long long M = 1000000007;

int main()
{
	memset(a, 0, sizeof(a));

	cin >> n;

	for (int i = 0; i < n; i++) {
		int b;

		cin >> b;
		a[b]++;

		if (b == 0)
				m = m * (4 - a[0]) % M;
		else
			m = m * (a[b - 1] - a[b] + 1) % M;
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()

const int N = 45;
const int mod = 1e9+7;
const int maxn = 1<<16;
int dp[maxn][N];
//0 is for nothing is yet started
//1 is for first X is making
//2 is for second Y is making
//...



int add(int a , int b){
  a += b;
  if(a >= mod) a -= mod;
  return a;
}
void inc(int &a , int b){
  a += b;
  if(a >= mod) a -= mod;
}
int mul(int a , int b){
  return a*1ll*b%mod;
}
int n , x , y , z;
void printBinary(int mask){
  for(int i = 15 ;i >= 0 ; --i)
    cout << ((mask&(1<<i)) != 0) ;
  cout << endl;
}

bool check(int mask , int now){
  if(now > z) return false;
  vector<int> val;
  for(int i = 15 ; i >= 0 ; --i){
    if(mask&(1<<i)){
      int cnt = 1;
      int j = i-1;
      while(j >= 0 && !(mask&(1<<j))){
        --j;
        ++cnt;
      }
      val.push_back(cnt);
      i = j+1;
    }
  }
  int curr = now;
  int stage = 0;
  if(curr == z){
    curr = 0;
    stage = 1;
  }
  for(int j = val.size()-1;j >= 0 ; --j){
    curr += val[j];
    if(curr > z && stage == 0) return false;
    if(curr > y && stage == 1) return false;
    if(curr > x && stage == 2) return false;
    if(curr == z && stage == 0){
      curr = 0 , stage = 1;
    }
    else if(curr == y && stage == 1){
      curr = 0 , stage = 2;
    }
    else if(curr == x && stage == 2){
      return true;
    }
  }
  return false;
}
int getMask(int mask , int nw){
  //cout << nw << ' ';
  //printBinary(mask);
  
  vector<int> val;
  int tot = 0;
  for(int i = 15 ;i >= 0 ; --i){
    if(mask&(1<<i)){
      int cnt = 1;
      int j = i-1;
      while(j >= 0 && !(mask&(1<<j))){
        --j;
        ++cnt;
      }
      tot += cnt;
      if(cnt)
        val.push_back(cnt);
      i = j+1;
    }
  }
  tot += nw;
  val.push_back(nw);
  reverse(all(val));
  while(tot > 16){
    tot -= val.back();
    val.pop_back();
  }
  int idx = 0;
  for(auto it : val){
    assert(it != 0);
    for(int j = 0; j < it-1 ; ++j){
      if(mask&(1<<idx))
        mask ^= (1<<idx);
      ++idx;
    }
    if(!(mask&(1<<idx)))
    mask ^= (1<<idx); 
    ++idx;
  }
  while(idx <= 15){
    if((mask&(1<<idx)))
      mask ^= (1<<idx);
    ++idx;
  }
  assert(idx == 16);
  //printBinary(mask);
  return mask;
}

int solve(int mask , int i){
 if(i == n) return 1;
 if(dp[mask][i] != -1) return dp[mask][i];
 int ans = 0;
 int curr = mask;
 for(int last = 1 ; last <= 10 ; ++last){
    if(!check(mask, last))
      ans = add(ans , solve( ((mask<<last)^(1<<(last-1)))&(maxn-1)  , i+1));
 }
 dp[mask][i] = ans;
 return ans;
}

int main(){
  cin >> n >> x >> y >> z;
  memset(dp , -1 , sizeof(dp));
  int tot = 1;
  for(int i = 1 ;i <= n ; ++i)
    tot = mul(tot , 10);
  cout << (mod + tot - solve(0 , 0))%mod << endl;
  return 0;
}

Measured memory_bytes: 11776
let a = readLine()!.characters.split{$0 == " "}.map{ Int(String($0))! }
let n = a[0]
let k = a[1]
let q = a[2]

var answers = [Int]()

for counter in 0..<q {
  answers.append(Int(readLine()!)!)
}

if q < k {
  for index in 0..<n {
    print("Yes")
  }
} else {
  var ret = Array(count: n, repeatedValue: "No")
  var dict = [Int:Int]()

  for ans in answers {
    if dict[ans] == nil {
      dict[ans] = 1
    } else {
      dict[ans] = dict[ans]! + 1
    }
  }
  
  for (key,v) in dict {
    //print(key,v,q-v,k)
    if q - v < k {
      ret[key - 1] = "Yes"
    }
  }
  
  for score in ret {
    print(score)
  }
}

Measured memory_bytes: 9200
#include<stdio.h>

int main(){
	int n,m,x,card[4][13]={0};
    int i,j;
	char mark,ent;
	scanf("%d\n",&n);
	
	for(i=0;i<n;i++){
		scanf("%c %d",&mark,&x);
		scanf("%c",&ent);
		if(mark=='S') card[0][x-1]=1;
		else if(mark=='H') card[1][x-1]=1;
		else if(mark=='C') 	card[2][x-1]=1;
		else if(mark=='D') 	card[3][x-1]=1;
		
	}
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(card[i][j]==0){
				if(i==0) printf("S %d\n",j+1);
				else if(i==1) printf("H %d\n",j+1);
				else if(i==2) printf("C %d\n",j+1);
				else if(i==3) printf("D %d\n",j+1);
			}
		}
	}
    return 0;
}


Measured memory_bytes: 2112
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define N_MAX 201
#define INF 1000000

int N;
int edge[N_MAX][N_MAX],d[N_MAX][N_MAX],visit[N_MAX];

bool dfs(int index)
{
	for (int i = 0; i < N; i++){
		if (1 == edge[index][i] && -1 == visit[i]){
			visit[i] = (visit[index] + 1) % 2;
			if (!dfs(i)){
				return false;
			}
		}
		else if (1 == edge[index][i]){
			if (visit[index] == visit[i]){
				return false;
			}
		}
	}
	return true;
}

void solv()
{
	
	scanf("%d", &N);
	for (int i = 0; i < N; i++){
		scanf("%*c");
		for (int j = 0; j < N; j++){
			char ch; scanf("%c", &ch);
			if ('0' == ch){
				edge[i][j] = 0;
				d[i][j] = INF;
			}
			else{
				edge[i][j] = 1;
				d[i][j] = 1;
			}
		}
	}

	for (int i = 0; i < N; i++){
		d[i][i] = 0;
	}
	for (int k = 0; k < N; k++){
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N; j++){
				if (d[i][j] > d[i][k] + d[k][j]){
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}

	fill(visit, visit + N, -1);
	visit[0] = 0;
	if (!dfs(0)){
		printf("-1");
		return;
	}

	int ret = 0;
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			ret = max(ret, d[i][j]);
		}
	}
	printf("%d", ret+1);


	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 640
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);
  const K = Number(input[1][0]);
  const X = Number(input[2][0]);
  const Y = Number(input[3][0]);

  return Math.min(N, K) * X + Math.max(0, N - K) * Y;
};

console.log(main(read()));


Measured memory_bytes: 29812
#include<bits/stdc++.h>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<pii> vii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline in(){
	int x=0,c;
	for(;(unsigned int)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((unsigned int)((c=getchar())-'0')<10);
	return x;
}
int main(){
    ios::sync_with_stdio(false);
	int n,a,b;
	cin>>n>>a>>b;
	a*=n;
	cout<<min(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    N %= 10;
    if(N == 3) cout << "bon\n";
    else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon\n";
    else cout << "hon\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    int num;
    vector<int> par;

    UnionFind(int n) : num(n), par(n, -1){};

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        num--;
        return true;
    }

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

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, 0, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        if (!uf.same(x, y)) uf.unite(x, y);
    }

    cout << uf.num << endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class e{
    public static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int k = int.Parse(str[1]);
        int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int left = 1, right = (int)Math.Pow(10,9)+1;
        while(left < right){
            int mid = (left + right) / 2;
            if(k < count(a, mid)){
                left = mid + 1;
            }
            else{
                right = mid;
            }
        }
        Console.WriteLine(left);
    }
    public static int count(int[] arr, int len){
        int ret = 0;
        foreach(int n in arr){
            ret += (int)Math.Ceiling((double)n/len) - 1;
        }
        return ret;
    }
}


Measured memory_bytes: 39364
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int x[105];
vi sums;
 
int32_t main()
{
    fast;
    int n, ans = INT_MAX, sum, j; cin >> n; 
    Rep(i, 1, n) cin >> x[i];
    int hi = *max_element(x+1, x+1+n);
    
    Rep(i, 1, hi) {
        sum = 0;
        Rep(j, 1, n) {
            sum += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, sum);
    }

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

Measured memory_bytes: 3672
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;
int N, M, K, T, Q, H, W;
bool check(vector< int > &A, int m) {
	map< int, int > mp;
	for (int i = 1; i < N; i++) {
		if (A[i] > A[i - 1])
			continue;
		if (m == 1)
			return false;
		auto it = mp.upper_bound(A[i]);
		mp.erase(it, mp.end());
		int j = A[i];
		while (1) {
			if (j == 0)
				return false;
			mp[j]++;
			if (mp[j] < m) {
				break;
			}
			mp[j] = 0;
			--j;
		}
	}
	return true;
}

signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int l = 0, r = N + 10;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(A, m)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def factors(n):
    d = []
    a = 2
    while n >= a ** 2:
        if n % a == 0:
            n //= a
            d.append(a)
        else:
            a += 1
    d.append(n)
    return d

def main():
    N = I()

    i = math.ceil(math.sqrt(N))
    while N % i != 0:
        i -= 1

    print(i + N//i - 2)



if __name__ == '__main__':
    main()

Measured memory_bytes: 77324
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
  input! {
    k: usize,
  };

  let mut res = 0_usize;
  for a in 1..k + 1 {
    for b in 1..k + 1 {
      for c in 1..k + 1 {
        res += a.gcd(&b).gcd(&c);
      }
    }
  }
  println!("{}", res);
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    in(n);
    vector<int> vec(n);
    in(vec);
    reverse(all(vec));
    out(vec);
}


Measured memory_bytes: 3216
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
static inline void fast_io()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
using namespace std;
using ll = long long;
using ld = long double;

int main()
{
    fast_io();

    int n;
    cin >> n;
    int tmp = max(1, (int)ceil(sqrt(n - 2)) + 1);
    map<int, int> m;
    for (int x = 1; x <= tmp; x++) {
        for (int y = 1; y <= tmp; y++) {
            for (int z = 1; z <= tmp; z++) {
                int cal =
                    pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x;
                m[cal]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << m[i] << '\n';
    }
}


Measured memory_bytes: 5064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
typedef long long ll;
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b),swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}

Measured memory_bytes: 256
// AOJ 2161 Defend the Bases
// 2018.3.9 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MAX 210
int  to[MAX][MAX]; char hi[MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u);
int bipartiteMatching(int m, int n, int V)
{
	int u, max;

	memset(match, -1, V*sizeof(int));
	max = 0;
	for (u = 0; u < m; u++) {
		memset(seen, 0, V);
		if (bpm(u)) max++;
	}
	return max;
}

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (match[v] < 0 || bpm(match[v])) {
			match[u] = v, match[v] = u;
			return 1;
		}
	}
	return 0;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define LIM 60
#define EPS 1e-8

typedef struct { int from, to; double tm; } EDGE;
EDGE edge[10010], *tail;
typedef struct { int x, y, v; } TROOP;
TROOP troop[102];
typedef struct { int x, y; } BASE;
BASE  base[102];
int   N, M, V;

double dist(int t, int b) { return hypot(troop[t].x-base[b].x, troop[t].y-base[b].y); }

int check(double tm)
{
	EDGE *e;

	memset(hi, 0, V);
	for (e = edge; e < tail && e->tm < tm+EPS; e++) to[e->from][hi[e->from]++] = e->to;
	return bipartiteMatching(N, M, V) == M;
}

int cmp(EDGE *a, EDGE *b) {
	if (fabs(a->tm - b->tm) < EPS) return 0;
	if (a->tm <= b->tm) return -1;
	return 1;
}

int main()
{
	int i, j, lim;
	double lb, ub, md;
	EDGE *e;

	while (N = in()) {
		M = in(), V = N+M;
		for (i = 0; i < N; i++) troop[i].x = in(), troop[i].y = in(), troop[i].v = in();
		for (i = 0; i < M; i++) base[i].x = in(), base[i].y = in();

		e = edge; for (i = 0; i < N; i++) for (j = 0; j < M; j++) {
			e->from = i, e->to = N+j, e->tm = dist(i, j) / troop[i].v, e++;
		}
		tail = e, lim = e - edge;
		qsort(edge, lim, sizeof(EDGE), cmp);

		lb = 0, ub = edge[lim-1].tm + 10;
		lim = LIM; while (lim--) {
			md = 0.5*(lb+ub);
			if (check(md)) ub = md; else lb = md;
		}
		printf("%.20lf\n", ub);
	}
	return 0;
}


Measured memory_bytes: 2168
/*  -*- coding: utf-8 -*-
 *
 * g.cc: G - SCC
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 500000;
const int MAX_M = 500000;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef stack<int> si;

/* global variables */

vi nbrs[MAX_N], gnbrs[MAX_N];
pii es[MAX_N];
int gids[MAX_N], pns[MAX_N], vs[MAX_N];

/* subroutines */

void scc_visit(const vi *nbrs, int v, vvi& scc,
	       si& S, vb &inS, vi& low, vi& num, int& time) {
  low[v] = num[v] = ++time;
  S.push(v);
  inS[v] = true;

  const vi& nbrv = nbrs[v];
  for (vi::const_iterator vit = nbrv.begin(); vit != nbrv.end(); vit++) {
    const int& w = *vit;
    if (num[w] == 0) {
      scc_visit(nbrs, w, scc, S, inS, low, num, time);
      low[v] = min(low[v], low[w]);
    }
    else if (inS[w])
      low[v] = min(low[v], num[w]);
  }

  if (low[v] == num[v]) {
    scc.push_back(vi());
    for (;;) {
      int w = S.top(); S.pop();
      inS[w] = false;
      scc.back().push_back(w);
      if (v == w) break;
    }
  }
}

void calc_scc(const int n, const vi *nbrs, vvi& scc) {
  vi num(n), low(n);
  si S;
  vb inS(n);
  int time = 0;

  for (int u = 0; u < n; u++)
    if (num[u] == 0)
      scc_visit(nbrs, u, scc, S, inS, low, num, time);
}

/* main */

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

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    nbrs[a].push_back(b);
    es[i] = pii(a, b);
  }

  vvi scc;
  calc_scc(n, nbrs, scc);
  int k = scc.size();

  for (int i = 0; i < k; i++)
    for (int j = 0; j < scc[i].size(); j++)
      gids[scc[i][j]] = i;

  for (int i = 0; i < m; i++) {
    int ga = gids[es[i].first], gb = gids[es[i].second];
    if (ga != gb)
      gnbrs[ga].push_back(gb), pns[gb]++;
  }

  qi q;
  for (int u = 0; u < k; u++)
    if (pns[u] == 0) q.push(u);

  int l = 0;
  while (! q.empty()) {
    int u = q.front(); q.pop();
    vs[l++] = u;

    vi &gnbru = gnbrs[u];
    for (vi::iterator vit = gnbru.begin(); vit != gnbru.end(); vit++) {
      int v = *vit;
      if (--pns[v] == 0) q.push(v);
    }
  }
  
  printf("%d\n", k);
  for (int i = 0; i < k; i++) {
    vi &sci = scc[vs[i]];
    printf("%lu", sci.size());
    for (int j = 0; j < sci.size(); j++) printf(" %d", sci[j]);
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 86144