akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;

typedef pair <int, int> pii;
typedef long long LL;
const int N = 2e5 + 5;

int n;
priority_queue <pii> tp;
priority_queue <int, vector <int>, greater <int> > le, del;

int main() {
  int D = 1e9, R = -1e9;
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i ++) {
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    tp.push(make_pair(y, x));
    le.push(x);
    R = max(R, x);
    D = min(D, y);
  }
  LL ans = 1LL * (R - le.top()) * (tp.top().first - D);
  pii cur;
  while (tp.top().first > tp.top().second) {
    cur = tp.top();
    tp.pop();
    del.push(cur.second);
    le.push(cur.first);
    tp.push(make_pair(cur.second, cur.first));
    D = min(D, cur.second);
    R = max(R, cur.first);
    while (!del.empty() && del.top() == le.top()) {
      del.pop(); le.pop();
    }
    ans = min(ans, 1LL * (R - le.top()) * (tp.top().first - D));
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

ll n, k;
string s;
 
vector<ll> a;

ll score(vector<ll> x){
  ll n = x.size();
  ll ans = 0;
  rep(i,n){
    ans += abs(x[i]) - 1;
  }
  return ans;
}

ll num(ll size, ll x){
  if(x == 0) return 0;
  if(size == 1) return 0;
  if(size == 2) return (x>0?1:0);
  if(size >= 3) return 2 + num(size-2,x-1); 
}

 
int main(){
  cin >> n >> k;
  cin >> s;
  ll count = 1;
  rep(i,n-1){
    if(s[i] == s[i + 1]){
      count++;
    }else{
      if(s[i] == 'R') count *= -1;
      a.push_back(count);
      count = 1;
    }
    if(i == n-2){
      if(s[n-1] == 'R') count *= -1;
      a.push_back(count);
    }
  }
  
  ll size = a.size();
  
    cout << score(a) +  num(size, k) << endl;
 
  
  
}

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

lint power(lint x, lint n){
    lint res = 1;
    while(n > 0){
        if(n & 1){
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

lint nCr(lint n, lint r){
    r = min(r, n-r);
    if(r < 0){
        return 0;
    }
    lint multiple = 1, divide = 1;
    rep(i, r){
        multiple *= (n - i);
        multiple %= MOD;
        divide *= (i + 1);
        divide %= MOD;
    }
    lint res = multiple * power(divide, MOD-2);
    res %= MOD;
    return res;
}

int main(){
    lint n, m;
    cin >> n >> m;
    lint ans = 1;
    for(lint i = 2 ; i * i <= m ; ++i){
        lint cnt = 0;
        while(m % i == 0){
            m /= i;
            ++cnt;
        }
        ans *= nCr(n - 1 + cnt, cnt);
        ans %= MOD;
    }
    if(m > 1){
        ans *= n;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long

using namespace std;

string s, t;
int dp[10001][10001];
string ans;


void path(int i, int j){
   // cout << i << " " << j << endl;
    if(i == 0 || j == 0){
        return;
    }
    if(dp[i][j] == dp[i - 1][j]){
        path(i - 1, j);
    }
    else if(dp[i][j] == dp[i][j - 1]){
        path(i, j - 1);
    }
    else{
        ans += s[i - 1];
        path(i - 1, j - 1);
    }
}

signed main() {
    ios::sync_with_stdio(false);

    cin >> s >> t;
    int n = s.size(), m = t.size();
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            dp[i][j] = 0;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    path(n, m);
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 85968
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vll> vl2d;
typedef vector <vi> vi2d;
typedef vector <char> vc;
typedef vector <bool> vb;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <long,long> ml;
typedef map <string,string> mss;
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define foreach(x,arr) for(auto& x:arr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000LL
#define MOD 1000000007
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<"\n"; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define forch(ch,str) for(char& c : str)
#define FILL(a,b) memset(a,b,sizeof(a))
//Swift related stuff
#define append push_back
#define nil nullptr
#define guard(_condition) if (bool(_condition)){}
#define count size()
#define let const auto
#define var auto
#define startsWith(str) rfind(str, 0)
#define prq priority_queue
#define tostr(argument) to_string(argument)
#define alphabet "abcdefghijklmnopqrstuvwxyz"

ll n, last;
vl2d arr;
ll cnt = 0;

void dfs(ll mask, ll cur, vll& series, double& res, double pr) {
    if(last == mask) {
        cnt += 1;
        res += pr;
        return;
    }
    rep(i,0,n) {
        ll j = 1<<i;
        if(j&mask) {
            continue;
        }
        j = j|mask;
        long double dist = 0.0;
        ll x1 = cur>=0 ? arr[cur][0] : 0, y1 = cur>=0 ? arr[cur][1] : 0;
        if(cur != -1) {
            dist = sqrt(
                        pow(-(long double)arr[i][0]+(long double)x1,2.0) +
                        pow(-(long double)arr[i][1]+(long double)y1,2.0)
                        );
        }
        series.append(i);
        dfs(j, i, series, res, pr + dist);
        series.erase(series.end()-1);
    }
}

int main() {
    cin>>n;
    arr.resize(n, vll(2));
    last = (1<<n)-1;
    
    rep(i,0,n) {
        cin>>arr[i][0]>>arr[i][1];
    }
    
    vll series;
    double res = 0;
    dfs(0, -1, series,res, 0);
    res/=cnt;
    printf("%.10f", res);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3748
dummy = list(map(int, input().split(" ")))
N = dummy[0]
M = dummy[1]

s = []
c = []
for i in range (M):
    dummy = list(map(int, input().split(" ")))
    s.append(dummy[0])
    c.append(dummy[1])



for i in range (0, 1000):
    if(len(str(i)) == N):
        if(M == 0):
            print(i)
            exit()
        for j in range(M):
            if not (str(i)[s[j] - 1] == str(c[j])):
                break
            if (j == M - 1):
                print(i)
                exit()
print(-1)
        

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

using namespace std;

int n, sol, nr, t;

int main ()
{
  cin >> n;
  sol = INT_MAX;
  for (int i = 0; i <= n; i++) {
    nr = 0;
    t = i;
    while (t >0) {
      nr += t % 6;
      t /= 6;
    }
    t = n - i;
    while (t > 0) {
      nr += t % 9;
      t /= 9;
    }
    if ( sol > nr )
      sol = nr;
  }
  cout << sol;
  return 0;
}


Measured memory_bytes: 256
let solve s n =
  let t = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    t.(i+1) <- if String.get s i = 'A' && (i + 1) < n then 
                 if String.get s (i + 1) = 'C' then t.(i) + 1 else t.(i)
               else t.(i)
  done;
  fun (i, j) -> t.(j-1) - t.(i-1)

let _ =
  let n, q = Scanf.scanf "%d %d\n" (fun n q -> n, q) in
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  let queries = ref [] in
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d\n" (fun l r -> queries := (l, r)::!queries)
  done;
  let solver = solve s n in
  List.fold_left (fun acc query -> (solver query)::acc) [] !queries
  |> List.iter (fun n -> print_int n; print_endline "")

Measured memory_bytes: 12800
import java.util.Scanner;

/**
 * B - ... (Triple Dots)
 * 英小文字からなる文字列 S があります。
 * S の長さが K 以下であれば、S をそのまま出力してください。
 * S の長さが K を上回っているならば、先頭 K 文字だけを切り出し、末尾に ... を付加して出力してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // Sを取得する長さ K
        int k = sc.nextInt();
        // 英小文字からなる文字列 S
        String s = sc.next();

        System.out.println( s.length() <= k ? s : s.substring( 0, k) + "..." );

        sc.close();
    }
}

Measured memory_bytes: 38520
#include <stdio.h>
int main(void){
    int a,b,i;
    scanf("%d%d",&a,&b);
    for(i=1;i<1100;i++){
        if(i*8/100 == a && i*10/100 == b){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[200], n, l, ans, i;
  scanf("%d", &n);
  for(l=0;l<2*n;l++){
    scanf("%d", &a[l]);
  }
  sort(a, a+2*n);
  ans = 0;
  for(i=0;i<2*n;i+=2){
    ans = ans + a[i];
  }
  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
    
    int N,K;
    cin >> N >>K;
    
    int x=1;
    int sum = x;
    for (int i=0 ; i<N ; i++){
        if(x<K){
            sum += x;
            x *= 2;
        }
        else{
            sum += K;
        }
    }
  
    cout << sum <<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

int main(){
    ll N, K;
    cin >> N >> K;
    if(N==1){
        if(K==0){
            cout << "0 0 1 1" << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    if(N==0){
        if(K==0){
            cout << "0 0" << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    if(K>=(1<<N)){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0; i<(1<<N); i++){
        if(i==K) continue;
        cout << i << " ";
    }
    cout << K << " ";
    for(int i=(1<<N)-1; i>=0; i--){
        if(i==K) continue;
        cout << i << " ";
    }
    cout << K << endl;
    return 0;
}

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

class Main
{
    static class Len
    {	
	int a[]; //= new int[2000010];
	int b[]; //= new int[2000010];
	
	Len(int n)
	{
	    a = new int[n+1];
	    b = new int[n+1];
	}
	

    }

    public static void main(String args[])
    {
	int n;
	int i, j, k;

	String line = new String();
	BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
	//PrintStream out = new PrintStream(System.out);

	//Read ----------------
	//Read n
	try{
	    line=line=bin.readLine();
	}	
	catch(IOException e){
	    System.out.println("Error");
	}

	n=Integer.parseInt(line);
	Len len = new Len(n);
	j=0;
	//Read A[]
	try{
	    line=bin.readLine();
	    //System.out.println(line);
	    StringTokenizer str = new StringTokenizer(line);   
	    for(i=0; i<n; i++)
		{
		    len.a[i]=Integer.parseInt(str.nextToken());
		    if(j<len.a[i])j=len.a[i];
		}
	}
	catch(IOException e){
	    System.out.println("Error");
	}

	bin=null;

	//Read end------------


	//sort
	countingSort(len, j, n);

	//print
	StringBuffer s = new StringBuffer(100);
	for(i=1; i<=n; i++)
	    {
		s.append(len.b[i]);
		if(i!=n)s.append(" ");
	    }
	System.out.println(s);
	//	out.print(len.b[i]+" ");
	//out.println(len.b[n]);

	/*
	for(i=1; i<n; i++)System.out.print(len.b[i]+" ");
	System.out.println(len.b[n]);*/

    }

    static void countingSort(Len len, int max, int n)
    {
	int i, j, k;
	int[] c = new int[max+1];

	//for(i=0; i<=max; i++)c[i]=0;
	for(i=0; i<n; i++)c[len.a[i]]++;

	for(i=0; i<=max; i++)
	    {
		if(i!=0)c[i]+=c[i-1];
	    }

	for(i=n-1; i>=0; i--)
	    {
		len.b[c[len.a[i]]]=len.a[i];
		c[len.a[i]]--;
	    }
    }
}

Measured memory_bytes: 102000
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

B = [i - a for i, a in enumerate(A)]
C = [i + a for i, a in enumerate(A)]
#print(B)
#print(C)

B_cnt = defaultdict(int)
C_cnt = defaultdict(int)
for b in B:
    B_cnt[b] += 1
for c in C:
    C_cnt[c] += 1

answer = 0
B_lst = list(B_cnt.items())
#print(B_lst)
for n, c in B_lst:
    answer += c * C_cnt[n]
#print(answer)

for i in range(N):
    if B[i] == C[i]:
        print(i)
        answer -= 1

print(answer)

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

int main(){
	string s;
	cin>>s;
	string cf = "CODEFESTIVAL2016";
	int res = 0;
	for(int i=0;i<16;i++){
		if(s[i] != cf[i]) res++;
	}
	cout<<res<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    vector<int> c(n + 1, 0);
    c.at(0) = 3;

    long long answer = 1LL;
    rep(i, n)
    {
        if (c.at(a.at(i)) == 0)
        {
            answer = 0LL;
        }
        else
        {
            answer = (answer * (long long)c.at(a.at(i))) % 1000000007ll;
            c.at(a.at(i)) -= 1;
            c.at(a.at(i) + 1) += 1;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin, n, k;
    vector<ll> P(n), C(n);
    REP(i, 0, n) {
        cin, P[i];
        P[i]--;
    }
    REP(i, 0, n) {
        cin, C[i];
    }
    const ll inf = 1LL << 60;
    ll ans = -inf;
    REP(i, 0, n) {
        int kk = k;
        int pos = i;
        ll score = 0;
        REP(j, 0, n) {
            pos = P[pos];
            score += C[pos];
            kk--;
            chmax(ans, score);
            if (kk == 0 || pos == i) break;
        }
        if (kk > 0) {
            int loop = (k - kk);
            if (kk >= 2 * loop) {
                score += max(kk / loop - 2, 0) * score;
                kk = 2 * loop + kk % loop;
            }

            REP(j, 0, kk) {
                pos = P[pos];
                score += C[pos];
                chmax(ans, score);
            }
        }
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

string n;

int main()
{
  cin >> n;
  bool check = false;
  if(n[0] == '7' || n[1] == '7' || n[2] == '7') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int abc(int a,int b) {
	int x = 0;
	for (int i = b; i <= a; i++) {
		for (int j = b; j <= a; j++) {
			if (j % i >= b)x++;
		}

	}
	return x;
}

int main() {
	int a,b=0;
	char s[100];
	cin >> a;
	rep(i, a) {
		cin >> s[i];
		if (s[i] == 'Y')b++;
	}
	if (b == 0)cout << "Three" << endl;
	else cout << "Four" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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; }

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

    int N; cin >> N;
    int K; cin >> K;
    int h[N]; for (int i=0; i<N; ++i) cin >> h[i];
    sort(h, h+N);

    int min = INF32;
    for (int i=0; i<N-K+1; ++i) {
        chmin(min, h[i+K-1]-h[i]);
    }
    cout << min << '\n';

    return 0;
}



Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        String s = scan.next();
        char[] data = s.toCharArray();
        data[K-1] = (char) ((int) data[K-1]+32);
        System.out.println(new String(data));
    }
}


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

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    private void solve(){
        int n = in.nextInt();
        long a = 1;
        long mod = (long)1e9+7;

        for(int i=1;i<=n;i++){
            a= (a*i)%mod;
        }
        out.print(a);
    }

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

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 21460
// atcoder/arc064/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int a, b, c, d, n;
  while (cin >> a >> b >> c >> d >> n) {
    const int N = 1000 + 5;

    int x[N], y[N], r[N];
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i] >> r[i];
    }
    x[n] = a;
    y[n] = b;
    r[n] = 0;
    ++n;
    x[n] = c;
    y[n] = d;
    r[n] = 0;
    ++n;

    double g[N][N];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        double p = abs(x[i] - x[j]);
        double q = abs(y[i] - y[j]);
        double d = sqrt(p * p + q * q);
        g[i][j] = max(0.0, d - r[i] - r[j]);
      }
    }

    double cost[N];
    fill(cost, cost + N, 1e128);
    priority_queue<pair<double, int>> q;
    cost[n - 2] = 0;
    q.push(make_pair(0, n - 2));

    while (q.size()) {
      auto p = q.top();
      q.pop();
      int curr = p.second;
      double w = -p.first;
      if (cost[curr] != w) continue;
      for (int next = 0; next < n; ++next) {
        double c = w + g[curr][next];
        if (c < cost[next]) {
          cost[next] = c;
          q.push(make_pair(-c, next));
        }
      }
    }

    cout << cost[n - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 14320
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll a;
    long double b;
    cin >> a >> b;
    cout << ll(a * b);
}

Measured memory_bytes: 3740
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int main()
{
	int n, m;
	cin>>n>>m;
	vector<P> v[100010];
	for(int i=0; i<m; i++){
		int l, r;
		ll c;
		cin>>l>>r>>c;
		l--; r--;
		v[r].push_back({l, c});
	}
	const ll INF=1e18;
	vector<ll> dp(n, INF);
	dp[0]=0;
	SegmentTree<ll> seg(n, [](ll x, ll y){ return min(x, y);}, INF, dp);
	for(int i=1; i<n; i++){
		for(auto p:v[i]){
			dp[i]=min(dp[i], seg.query(p.first, i)+p.second);
		}
		seg.update(i, dp[i]);
	}
	if(dp[n-1]<=INF/2) cout<<dp[n-1]<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 9216
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    auto r =  b + c - a;
    if (r < 0) r = 0;
    cout << r << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
#define N 200010

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int n,q,x,y;
vector<int> a[N];
ll added[N],total[N];
int chk[N];
void dfs(int x){
    chk[x] = 1;
    for(int i=0;i<a[x].size();i++){
        int nxt = a[x][i];
        if(!chk[nxt]){
            total[nxt] += total[x];
            dfs(nxt);
        }
    }
    chk[x] = 0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(int i=1;i<n;i++){
        cin>>x>>y;
        a[x].pb(y); a[y].pb(x);
    }
    for(int i=0;i<q;i++){
        cin>>x>>y;
        added[x] += (ll)y;
    }
    for(int i=1;i<=n;i++) total[i] = added[i];
    dfs(1);
    for(int i=1;i<=n;i++) printf("%lld ",total[i]);
    return 0;
}


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



int main(){
int n,i,N;
double x;

scanf("%d",&n);
N=n;
x=sqrt(n);

printf("%d:",n);

i=2;
while(i<=x){

   while(n%i==0){
    printf(" %d",i);
    n=n/i;
   }
 
 i++;
}

if(n!=1)printf(" %d",n);

printf("\n");

return 0;
}


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

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

const main = (input: string[][]) => {
  const [A, B, C] = input[0].map(Number);

  for (let i = A; i < B * 100; i += A) {
    if (i % B === C) {
      return "YES";
    }
  }

  return "NO";
};

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


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

//int solve(string s, string t, int s1, int s2){
//	if(s1==0 || s2==0)
//		return 0;
//		
//	int ans=0;
//	if(s[s1-1]==t[s2-1])
//		ans = 1 + solve(s, t, s1-1, s2-1);
//	else 
//		ans = max( solve(s, t, s1-1, s2), solve(s, t, s1, s2-1));	
//	return ans;
//}

void bottomup(string s, string t, int s1, int s2){
	int dp[s1+1][s2+1];
	memset(dp, 0, sizeof(dp));
	
	for(int i=1; i<=s1; i++) {
		for(int j=1; j<=s2; j++) {
			if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
		}
	}
//	cout << dp[s1][s2] << "\n";
	
	int i=s1, j=s2;
	char ans[dp[s1][s2]+1];	
	ans[dp[s1][s2]]='\0';
	
	int index = dp[s1][s2];
	
	while(i>0 && j>0){
		
		if(s[i-1]==t[j-1]) {
			ans[index-1]=s[i-1];
			i--, j--;
			index--;
		}
		else if(dp[i-1][j] > dp[i][j-1]){
			i--;
		} else {
			j--;
		}

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

void solve(){
	string s, t;
	cin >> s >> t;
	
	int s1 = s.size();
	int s2 = t.size();
	
	bottomup(s, t, s1, s2);
}

int main(){
	solve();
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main(int argc, char const *argv[])
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans += (n / (a + b)) * a;
    n %= (a + b);
    ans += min(n, a);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int solve(int,int);
int A[2000],n;
int main(){
int i,j,q,m[2000],flag;
 
scanf("%d",&n);

 for(i=0;i<n;i++){
   scanf("%d",&A[i]);
 }
 
 scanf("%d",&q);

 for(i=0;i<q;i++){
   scanf("%d",&m[i]);
 }
 
 for(i=0;i<q;i++){
   flag=solve(0,m[i]);
   if(flag==TRUE){
     printf("yes\n");
   }
   else if(flag==FALSE){
     printf("no\n");
   }
 }
 return 0;  
}

int solve(int i,int m){
  int res;
  if (m == 0){
    return TRUE;
  }
  if (i >= n){
    return FALSE;
  }
  if(res = solve(i + 1, m) || solve(i + 1, m - A[i])){
    return res;
  }

}

Measured memory_bytes: 588
#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];
int ind[MAXN];

bool cmp(int i, int j){ return A[i]<A[j];}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++){
		cin>>A[i];
		ind[i]=i;
	}
	sort(ind+1, ind+n+1, cmp);
	for (int i=1; i<=n; i+=2) ans+=(ind[i]%2==0);
	cout<<ans<<'\n';
	
	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


Measured memory_bytes: 1024
N = int(input())
al=[chr(ord('a') + i) for i in range(26)]
out = [1000]*26
for i in range(N):
    S = list(input())
    LS = len(S)
    tmp = [0]*26
    for j in range(LS):
        tmp[ord(S[j])-ord("a")]+=1
    for j in range(26):
        out[j]=min(out[j],tmp[j])
S = ""
for i in range(26):
    S += out[i]*chr(ord("a")+i)
print(S)


Measured memory_bytes: 65112
#pragma GCC optimize("O2")
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
#include <iomanip>
#include <bitset>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

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

#define int long long

int getAns(int n){

	int val = sqrt(1 + 8*n) - 1;
	val/=2;

	return val;

}

void solve(){

	int n;
	cin>>n;

	int ans = 0;

	int x = n;
	for(int i = 2 ; i*i <= n ; ++i){

		if(x%i==0){

			int cnt = 0;
			while(x%i==0){

				++cnt;
				x/=i;
			}
			//debug(cnt);
			ans += getAns(cnt);
		}
	}
	if(x > 1)
		++ans;
	cout<<ans<<endl;
}

signed main(){

	int t = 1;
	//cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3676
#include <stdio.h>

#define LEFT   0
#define BOTTOM 1
#define RIGHT  2
#define TOP    3

typedef struct {
  int n, d;
  int x, y;
} s_square;

int main() {
  int n, x_min, y_min, x_max, y_max;
  s_square square[200] = {0};
  // square[0] = {0, 0, 0, 0};  //´_ðú»

  int i;
  while(1) {
    scanf("%d", &n);
    if(n == 0) { break; }

    for(i = 1; i < n; i ++) {
      scanf("%d %d", &square[i].n, &square[i].d);
    }

    x_min = y_min = x_max = y_max = 0;

    for(i = 1; i < n; i ++) {
      switch(square[i].d) {
      case(LEFT):
	square[i].x = square[square[i].n].x - 1;
	square[i].y = square[square[i].n].y;
	break;
	
      case(BOTTOM):
	square[i].x = square[square[i].n].x;
	square[i].y = square[square[i].n].y - 1;
	break;
	
      case(RIGHT):
	square[i].x = square[square[i].n].x + 1;
	square[i].y = square[square[i].n].y;
	break;
	
      case(TOP):
	square[i].x = square[square[i].n].x;
	square[i].y = square[square[i].n].y + 1;
	break;
      }

	//ÀW[ÌXV
	     if(square[i].x < x_min) { x_min = square[i].x; }
	else if(x_max < square[i].x) { x_max = square[i].x; }

	     if(square[i].y < y_min) { y_min = square[i].y; }
	else if(y_max < square[i].y) { y_max = square[i].y; }
    }

    printf("%d %d\n", x_max - x_min + 1, y_max - y_min + 1);
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main{

    public Main(){
        int N;
        String S;
        HashMap<String, Integer> HM = new HashMap<String, Integer>();

        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        for(int i=0;i<N;i++){
            S = scanner.next();
            if(HM.containsKey(S)){
                HM.put(S, HM.get(S)+1);
            } else {
                HM.put(S, 1);
            }
        }

        int max=0;
        for(int v : HM.values()){
            if(v > max) max = v;
        }

        ArrayList<String> R = new ArrayList<String>();
        for(Map.Entry<String, Integer> entry : HM.entrySet()) {
            if(entry.getValue() == max)
                R.add(entry.getKey());
        }

		Collections.sort(R);

		for(String str : R){
			System.out.println(str);
		}

    }

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }
}


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

int A1,A2,A3,sum;

scanf("%d %d %d",&A1,&A2,&A3);

sum=A1+A2+A3;

if(sum>=22){ printf("bust\n");}

else{ printf("win\n");}


    return 0;
}

Measured memory_bytes: 1628
import sys
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(2*10**5)
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v = map(int, input().split())
        repn[u - 1].append(v - 1)
        repn[v - 1].append(u - 1)
    
    length = [0] * (N + 1)
    dp = [-1]

    """
    やはり各頂点でLIS配列を取ると配列コピーの時間がかかってTLEするので、
    配列は唯一つを扱って、DFSからバックするときに配列も元に戻す操作を行いたい
    （ここの実装の仕方がわからなかった）

    これはdfsを再帰で書いた後に復元操作を追記すれば異常に楽に書ける。。。
    """

    def dfs(v, p=N):
        if A[v] > dp[-1]:
            dp.append(A[v])
            length[v] = length[p] + 1
            for u in repn[v]:
                if u == p: continue
                dfs(u, v)
            dp.pop()
        else:
            length[v] = length[p]
            idx = bisect_left(dp, A[v]) # bisect_rightだとdpに重複する値を書き込んでしまうのでダメ
            old = dp[idx]
            dp[idx] = A[v]
            for u in repn[v]:
                if u == p: continue
                dfs(u, v)
            dp[idx] = old
        #print("v={}, len={}, dp={}".format(v, length[v], dp))

    dfs(0)
    length.pop()
    for ans in length:
        print(ans)
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 264024
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main () {
    long n;

    scanf("%ld", &n);

    long m = 1 + n;
    int cl = ceil(sqrt(n));
    ldiv_t divmod;
    long tmp;
    for (int i = 1; i <= cl; ++i) {
        divmod = ldiv(n,i);
        tmp = i + divmod.quot;
        if (divmod.rem == 0 && m > tmp) {
            m = tmp;
        }
    }

    printf("%ld\n", m - 2);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

int a[100000 + 1];
int b[100000 + 1];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n / 2; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		a[tmp1]++;
		b[tmp2]++;
	}

	int most_frequence1 = 0, most_frequence2 = 0;
	int num1, num2;

	for (int i = 1; i <= 100000; i++) {
		if (most_frequence1 < a[i]) {
			most_frequence1 = a[i];
			num1 = i;
		}

		if (most_frequence2 < b[i]) {
			most_frequence2 = b[i];
			num2 = i;
		}
	}

	if (num1 != num2) cout << n - most_frequence1 - most_frequence2 << endl; // 最頻値を取る値(i)が異なるとき、それぞれの数字に合わせる
	else {// 同じ値で最頻
		int next_frequence1 = 0, next_frequence2 = 0;

		for (int i = 0; i <= 100000; i++) {
			if (i != num1) {
				if (next_frequence1 < a[i]) {
					next_frequence1 = a[i];
				}
			}
			if (i != num2) {
				if (next_frequence2 < b[i]) {
					next_frequence2 = b[i];
				}
			}
		}

		cout << n - max(most_frequence1 + next_frequence2, most_frequence2 + next_frequence1);

	}


	return 0;
}

Measured memory_bytes: 1024
import itertools
N,M,Q = map(int,input().split())
cc = [list(map(int,input().split())) for i in range(Q)]
a = [i for i in range(1,M+1)]
max_count = -float('inf')
for i in itertools.combinations_with_replacement(a,N):
  count = 0
  for j in cc:
    if i[j[1]-1] - i[j[0]-1] == j[2]:
      count += j[3]
  max_count = max(max_count,count)
print(max_count)

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

int main() {
	int n,s=0;
	cin >> n;
	int a[n], even[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
		even[i] = 0;
		while(a[i]%2 ==0){
			a[i] /= 2;
			even[i]++;
		}
		s+=even[i];
	}
	printf("%d",s);

}

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

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

    int ans = 1;

    rep(i,n-1){
        if(s[i]!=s[i+1])ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
chomp($_=<>);
($n, $t) = split(' ');
chomp($_=<>);
@t = split(' ');

shift(@t);
$prev = 0;
for (@t) {
    if ($_ - $prev < $t) {
        $sum += $_ - $prev;
    } else {
        $sum += $t;
    }
    $prev = $_;
}
$sum += $t;
print "$sum\n";

Measured memory_bytes: 33868
program sumitrust2019B
	integer(8)::N,i
	integer(8)::flg=0
	read(5,*)N
	
	do i=1,N
		if(int(real(i)*1.08)==N)then
			flg=i
			exit
		end if
	end do

	if(flg==0)then
		print'(A)',":("
	else
		print'(i0)',flg
	end if
end program sumitrust2019B


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
map<string,int>mp;
string s;
int main()
{
        IO;
        ll i, j, n, m, k=0, l, r,t, q,sum,mod, lcm,mn1,mn2;
        cin>>n;
        for(i=1; i<=n; i++){
        cin>>s;
        mp[s]++;
        if(mp[s]==1) k++;
       }
       cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 19244
from fractions import gcd
import sys

input = sys.stdin.readline

x = int(input())

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

def get_prim(x):
    i = x
    while True:
        if is_prime(i):
            return i

        i += 1


print(get_prim(x))

Measured memory_bytes: 66156
import collections
N = int(input())
D = [0]*100001
A = list(map(int, input().split()))
a = sum(A)
for j in A:
    D[j] += 1
Q = int(input())
start = sum(A)
for i in range(Q):
    x,y=[int(i) for i in input().split()]
    a += D[x]*(y-x)
    print(a)
    D[y] +=D[x]
    D[x] = 0
            


Measured memory_bytes: 22240
#include<iostream>
#include<cstring>
#include<vector>

using namespace std;

bool  slove(int tmp[])
{
  for(int i=1;i<10;i++)
    {
      while(tmp[i]!=0)
	{
	  if(tmp[i]>=3)
	    {
	      tmp[i]-=3;
//	      cout<<i<<":3set"<<endl;
	    }
	  else if(i<8&&tmp[i]>0&&tmp[i+1]>0&&tmp[i+2]>0)
	    {
	      tmp[i]--;
	      tmp[i+1]--;
	      tmp[i+2]--;
//	      cout<<i<<":3zyun"<<endl;
	    }
	  else
	    {
	      return false;
	    }
	}
    }
  return true;
}


int main()
{
  string str;
  for(;cin>>str;)
    {
      int data[10];
      memset(data,0,sizeof(data));
      for(int i=0;i<str.size();i++)
	{
	  data[str[i]-'0']++;
	}
      for(int i=0;i<10;i++)
	{
	}

      vector<int> ans;
      //      int tmp1[10];
      //      memcpy(tmp1, data, sizeof(data));
      for(int i=1;i<10;i++)
	{
	  if(data[i]>3)
	    continue;
//	  cout<<i<<":add"<<endl;
	  for(int j=1;j<10;j++)
	    {
	      int tmp[10];
	      memcpy(tmp, data, sizeof(tmp));
	      tmp[i]++;
	      if(tmp[j]>1)
		{
		  /*
		  for(int xx=1;xx<10;xx++)
		    for(int yy=tmp[xx];yy>0;yy--)
		      cout<<xx;		  
		  cout<<endl;
		  */
		  tmp[j]-=2;
	//	  cout<<j<<":head"<<endl;		  
		  if(slove(tmp))
		    {
		      ans.push_back(i);
		      j=10;
		    }		  
		}
	    }
	 	  
	}

       for(int i=0;i<ans.size();i++)
	    {
	      cout<<ans[i];
	      if(i==ans.size()-1)
		cout<<endl;
	      else
		cout<<" ";
	    }
if(ans.size()<1)
  cout<<0<<endl;      
       
    }
}

Measured memory_bytes: 1204
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

int N,ans[300],cnt[300];
string s;

int main(){
    cin >> N;

    int i,j;
    for (i='a'; i<='z'; i++)
        ans[i]=100;

    while (N--){
        cin >> s;
        memset(cnt,0,sizeof(cnt));
        for (i=0; i<s.length(); i++)
            cnt[s[i]]++;

        for (i='a'; i<='z'; i++)
            ans[i]=min(ans[i],cnt[i]);
    }

    for (i='a'; i<='z'; i++)
        for (j=1; j<=ans[i]; j++)
            cout << (char)(i);

    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0; i<N; i++) cin >> l.at(i);
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int ans=0;
  for(int i=0; i<K; i++){
    ans+=l.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std ;
int main() { 
  int n; 
  cin >> n; 
  for ( int i = 0; i < 20; i++){ 
    if (n < (1<<(i +1))){ 
      cout << (1<<i ) << endl ; 
      break ; 
    } 
  } return 0; 
}


Measured memory_bytes: 256