akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=6010;
int n,s[maxn],tot;
char t[maxn],ans[maxn],res[maxn];
struct node { int l,r,flag; } d[maxn];
bool cmp(char *a,char *b) {
	int t1=strlen(a+1),t2=strlen(b+1);
	for (int i=1;i<=max(t1,t2);i++) {
		if (i>t1) a[i]=0;
		if (i>t2) b[i]=0;
		if (a[i]!=b[i]) return a[i]<b[i];
	}
	return 1;
}
bool cmp2(char *a,char *b) {
	int t1=strlen(a+1),t2=strlen(b+1);
	for (int i=1;i<=t2;i++) {
		if (i>t1) a[i]=0;
		if (a[i]!=b[i]) return a[i]<b[i];
	}
	return 1;
}
char tmp[maxn];
int id[maxn];
void eq(char *a,char *b) {
	int len=strlen(b+1);
	for (int i=1;i<=len;i++) a[i]=b[i];
	a[len+1]=0;
}
void solve(int l,int r) {
	// [l,r] has more 'b' than 'a' in every prefix
	int t1=0,t2=0,len;
	res[1]='a'-1; res[2]=0;
	for (int i=l;i<=r;i++) {
		if (t[i]=='a') id[i]=++t1;
		else id[i]=++t2;
	}
	for (int i=1;i<=t1;i++) {
		len=0;
		for (int j=l;j<=r;j++)
			if (id[j]>=i) tmp[++len]=t[j];
		tmp[len+1]=0;
		//printf("%s\n",tmp+1);
		if (cmp(res,tmp)) eq(res,tmp);
	}
}
bool mk[maxn];
int dy[maxn];
void solve2(int l,int r) {
	int t1=0,t2=0;
	for (int i=l;i<=r;i++) {
		if (t[i]=='a') id[i]=++t1;
		else id[i]=++t2,dy[t2]=i;
	}
	int pos;
	for (int i=l;i<=r;i++) {
		if (!mk[i]&&t[i]=='a') {
			pos=dy[id[i]];
			for (int j=i;j<=pos;j++) mk[j]=1;
			i=pos;
			printf("ab");
		}
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); n*=2;
	scanf("%s",t+1);
	int flag=0,sum=0;
	for (int i=1;i<=n;i++) {
		if (t[i]=='a') sum++;
		else sum--;
		s[i]=sum;
		if (!flag) {
			if (sum<0) flag=-1;
			else if (sum>0) flag=1;
		}
		if (sum==0) {
			tot++;
			d[tot]=(node){d[tot-1].r+1,i,flag};
			flag=0;
		}
	}
	//for (int i=1;i<=tot;i++)
		//printf("%d %d %d\n",d[i].l,d[i].r,d[i].flag);
	int pos=0,len;
	for (int i=tot;i>=1;i--) {
		if (d[i].flag==1) continue;
		if (!pos) pos=i;
		solve(d[i].l,d[i].r);
	//	printf("res=%s\n",res+1);
		if (cmp2(ans,res)) {
			len=strlen(ans+1);
			reverse(ans+1,ans+len+1);
			for (int j=strlen(res+1);j>=1;j--)
				ans[++len]=res[j];
			//printf("ans=%s\n",ans+1);
			ans[len+1]=0;
			reverse(ans+1,ans+len+1);
		}
	}
	printf("%s",ans+1);
	for (int i=pos+1;i<=tot;i++) {
		solve2(d[i].l,d[i].r);
	}
	printf("\n");
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    vector<int> x1;
    vector<int> y1;
    vector<int> x2;
    vector<int> y2;
    rep(i, h) rep(j, w-1) {
        if ( a[i][j]&1 ) {
            x1.push_back(j), y1.push_back(i), x2.push_back(j+1), y2.push_back(i);
            ++a[i][j+1];
        }
    }
    rep(i, h-1) {
        if ( a[i][w-1]&1 ) {
            x1.push_back(w-1), y1.push_back(i), x2.push_back(w-1), y2.push_back(i+1);
            ++a[i+1][w-1];
        }
    }
    cout << x1.size() << endl;
    rep(i, x1.size()) {
        cout << y1[i]+1 << " " << x1[i]+1 << " " << y2[i]+1 << " " << x2[i]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5352
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  string s;
  cin >> s;
  int l,st,cnt1 = 0, cnt2 = 0;

  l = s.length();
  if(l % 2 == 0) st = l / 2;
  else st = l / 2 + 1;
  for(int i=0; i<l/2; i++) if(s[i] != s[l-i-1]) cnt1++;
  for(int i=st; i<l; i++) if(s[i] != s[l-i-1]) cnt2++;
  cout << min(cnt1,cnt2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(void) {
	
	int a[5], k, num = 0;

	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}

	cin >> k;

	if (a[4] - a[0] > k)num++;

	if (num == 0)cout << "Yay!\n";
	else cout << ":(\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool pal(string s, int l, int r){
    while(l<r){
        if(s[l]!=s[r]) return false;
        l++;
        r--;
    }
    return true;
}
int main(){
    string s;
    cin>> s;
    int n=s.length();
    if(pal(s, 0, n-1) && pal(s, 0, (n-1)/2-1) && pal(s, (n+3)/2-1, n-1)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


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

        for(int i=0;i<w;i++){

            num[i]=i+1;

        }
        sc.useDelimiter(",|\n");
        for(int i=0;i<n;i++){

           String str=sc.nextLine();
           int a = sc.nextInt();
			int b = sc.nextInt();
           int temp = num[a-1];
           num[a-1] = num[b-1];
           num[b-1] = temp;
            
        }



        for(int i=0;i<w;i++){

            System.out.println(num[i]);
        }

        sc.close();
    }
}


Measured memory_bytes: 26136
x1 = input()
x2 = [int(i) for i in input().split(" ")]

result = 0
if 0 in x2:
  None 
else:
  result = 1
  for xv in x2:
     result = xv * result
  
     if 10**18 < result : 
        result = -1
        break


print(result) 


Measured memory_bytes: 21556
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] v = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int[] c = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int tmp = v.Zip(c, (a, b) => a - b).Where(a => a > 0).Sum();
            Console.WriteLine(tmp);
        }
    }
}

Measured memory_bytes: 13396
n = int(input())
start = 0
end = 1

a = []
for _ in range(n):
    a.append(int(input()) - 1)

pushed = {}
l = 0
cnt = 0
while True:
    pushed[l] = True
    l = a[l]
    cnt += 1
    if l in pushed:
        print(-1)
        exit()
    if l == end:
        break
print(cnt)


Measured memory_bytes: 59480
#include<iostream>
#include<vector>
using namespace std;
#define MAX 2000

int n,m,h,k;
int t[MAX][MAX];
int change[MAX];
int u[MAX];
vector<int> G[MAX],A,B;

int check(int x,int y,int sum){
  if(x<k&&y<k)return sum;
  if(x>=k&&y>=k)return sum;
  
  if(x<k)sum-=u[x];
  else sum+=u[x];

  if(y<k)sum-=u[y];
  else sum+=u[y];
  return sum;
}

void compute(){
  for(int i=0;i<n;i++)t[h][i]=i;

  for(int i=h-1;i>=0;i--){
    for(int j=0;j<n;j++)t[i][j]=t[i+1][j];
    for(int j=0;j<(int)G[i].size();j++){
      int w=G[i][j];
      swap(t[i][w-1],t[i][w]);
    }
  }
  for(int i=1;i<h;i++){
    for(int j=0;j<(int)G[i].size();j++){
      int w=G[i][j];
      A.push_back(t[i][w]);
      B.push_back(t[i][w-1]);
    }
  }
  //for(int i=0;i<=h;i++){    for(int j=0;j<n;j++){
  //  cout<<t[i][j]<<" ";    }    cout<<endl;  } cout<<endl;
  
}

void solve(){  
  compute();
  int mini=0;
  for(int i=0;i<k;i++)mini+=u[t[0][i]];
  for(int i=0;i<(int)A.size();i++){
    swap(u[A[i]],u[B[i]]);
    int sum=0;
    for(int j=0;j<k;j++) sum+=u[t[0][j]];
    mini=min(mini,sum);
    swap(u[A[i]],u[B[i]]);
  }
  cout<<mini<<endl;
}

void init(){
  A.clear();
  B.clear();
  for(int i=0;i<MAX;i++){
    G[i].clear();
  }
}

int main(){
  while(1){
    cin>>n>>m>>h>>k;
    if(n==0&&m==0&&h==0&&k==0)break;
    init();
    for(int i=0;i<n;i++)cin>>u[i];
    for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      G[b].push_back(a);
    }
    solve();
  }
  return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[N] ;
vector<int>ans ;

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

  for(int i = 0 ;i<n ;i++)
    scanf("%d", &a[i]) ;

  sort(a, a+n , greater<int>()) ;
  

  for(int i = 0; i<n-1 ; i++){
    if(a[i] == a[i+1]){
      ans.pb(a[i]) ;
      i++ ;
    }
  }

  if(ans.size()<2) puts("0") ;
  else {
    printf("%lld\n", 1LL*ans[0]*ans[1]) ;
  }	
  return 0 ;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<queue<ll>> A(N);
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < M; j++)
    {
      ll a;
      cin >> a;
      a--;
      A.at(i).push(a);
    }
  }

  vector<bool> used(M, false);
  ll ans = INF;
  for (ll i = 0; i < M; i++)
  {
    map<ll, ll> mp;
    for (ll j = 0; j < N; j++)
    {
      while (!A.at(j).empty() && used.at(A.at(j).front()))
      {
        A.at(j).pop();
      }

      if (!A.at(j).empty())
        mp[A.at(j).front()]++;
    }

    ll Mxk = -1, Mxv = -INF;
    for (auto x : mp)
    {
      if (chmax(Mxv, x.second))
        Mxk = x.first;
    }

    used.at(Mxk) = true;
    chmin(ans, Mxv);
    //cerr << Mxk << " " << Mxv << endl;
  }
  cout << ans << endl;
}

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

int main()
{
    int A, B;
    cin >> A >> B;

    int card[] = {
        0, 13, 1, 2, 3,
        4, 5, 6, 7, 8,
        9, 10, 11, 12};
    if (card[A] > card[B])
    {
        cout << "Alice" << endl;
    }
    else if (card[A] < card[B])
    {
        cout << "Bob" << endl;
    }
    else
    {
        cout << "Draw" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;

int countPrimeNumbers(int nums[], int n);

int main(void)
{
	int n, nums[10000];
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	
	int count = countPrimeNumbers(nums, n);
	
	cout << count << endl;
	
	return 0;
}

int countPrimeNumbers(int nums[], int n)
{
	int count = 0;
	
	for (int i = 0; i < n; i++) {
		int j;
		for (j = 2; j * j <= nums[i]; j++) {
			if (nums[i] % j == 0) break;
		}
		if (j * j > nums[i]) count++;
	}
	
	return count;
}

Measured memory_bytes: 3124
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        Set<Integer> s = new HashSet<>();
        s.add(a);
        int idx = 1;
        while(true) {
            idx++;
            int t = a % 2 == 0 ? (a / 2) : (3 * a + 1);
            if(s.contains(t)) {
                System.out.println(idx);
                break;
            } 
            s.add(t);
            a = t;
        }
    }
}



Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int X = in.nextInt();
            int Y = in.nextInt();
            out.println(N <= K ? X * N : X * K + Y * (N - K));
        }

    }
}



Measured memory_bytes: 20692
N,M=map(int,input().split())
T=[]
frag=[0 for y in range(N)]
p=[0 for y in range(N)]
a=0
for i in range(M):
  s=list(map(str,input().split()))
  T.append(s)
for i in range(M):
  if T[i][1]=='WA' and frag[int(T[i][0])-1]==0:
    p[int(T[i][0])-1]=p[int(T[i][0])-1]+1
  elif T[i][1]=='AC' and frag[int(T[i][0])-1]==0:
    a=a+1
    frag[int(T[i][0])-1]=1
for i in range(N):
  if frag[i]==0:
    p[i]=0
print(a,sum(p))

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
  char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
  vector<char*> v({token});
  while(token = strtok(NULL,", ")) v.push_back(token);
  return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
  debug() << " [" << args.back() << ": " << H << "] ";
  args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    int x;
    cin>>x;
    int cnt=1;
    while(1){
    	if(cnt*x%360==0) break;
    	cnt++;
    }
    cout<<cnt;
    return 0;   
}




Measured memory_bytes: 3632
from collections import defaultdict


def main():
    n = int(input())
    d = defaultdict(list)
    for i in range(n):
        k, v = input().split()
        d[k].append((int(v), i+1))
    for k in sorted(d.keys()):
        for v in sorted(d[k], key=lambda x: x[0], reverse=True):
            print(v[1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
function f(x, y, z){ return Math.abs(y - x) + Math.abs(y - z); }
function main(input){
	input = input.split(' ').map(Number);
	a = input[0], b = input[1], c = input[2], d = 1000001;
	if (f(a, b, c) < d) d = f(a, b, c);
	if (f(a, c, b) < d) d = f(a, c, b);
	if (f(b, a, c) < d) d = f(b, a, c);
	if (f(b, c, a) < d) d = f(b, c, a);
	if (f(c, a, b) < d) d = f(c, a, b);
	if (f(c, b, a) < d) d = f(c, b, a);
	console.log(d);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include <iostream>
#include <vector>

using namespace std;

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }

    return false;
}

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

int main()
{
    string s, t;
    cin >> s >> t;

    vector<vector<int>> dp(MAX_STR + 1, vector<int>(MAX_STR + 1, 0));

    for (int i = 1; i < s.size() + 1; i++)
    {
        for (int j = 1; j < t.size() + 1; j++)
        {
            if (s[i - 1] == t[j - 1])
            {
                chmax(dp[i][j], dp[i - 1][j - 1] + 1);
            }
            else
            {
                chmax(dp[i][j], dp[i - 1][j]);
                chmax(dp[i][j], dp[i][j - 1]);
            }
        }
    }

    string res = "";
    int i = s.size();
    int j = t.size();
    while (i > 0 && j > 0)
    {
        if (dp[i][j] == dp[i - 1][j])
        {
            --i;
        }
        else if (dp[i][j] == dp[i][j - 1])
        {
            --j;
        }
        else
        {
            res = s[i - 1] + res;
            --i, --j;
        }
    }

    cout << res << endl;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;



template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main(){
    int N;
    cin >> N;
    vector<ll> count(65);
    ll res = 0;
    rp(i, 0, N) {
        ll a;
        cin >> a;
        for(int i = 0; i < 60; i++) {
            if(a & (1ll<<i)) count[i]++;
        }
    }
    rp(i, 0, 60) {
        res += (1ll<<i) % MOD * count[i] % MOD * (N - count[i]) % MOD;
        res %= MOD;
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 3728
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    
    string s;

    cin >> s;

    int ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='+'){
            ans++;
        }
        if(s[i]=='-'){
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
       
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x; cin >> x;
    vector<ll> p;
    for(ll i=1;i*i<=x;i++){
        if(x%i==0){
            p.push_back(x/i);
            p.push_back(i);
           // p.push_back(-(x/i));
            //p.push_back(-i);
        }
    }
    sort(p.begin(), p.end());
    for(ll q:p){
        ll xx=x/q;
        for(ll a=1;a<1e5;a++){
            ll b=a-q;
            ll y=a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b;
            if(xx==y){
                printf("%lld %lld\n",a,b);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3716
from functools import reduce

N = int(input())
T = [int(input()) for i in range(N)]


def gcd_base(a, b):
    while b:
        a, b = b, a % b
    return a


def gcd(numbers):  # "numbers" is list
    return reduce(gcd_base, numbers)


def lcm_base(a, b):
    return (a * b) // gcd_base(a, b)


def lcm(numbers):  # "numbers" is list
    return reduce(lcm_base, numbers)  # [third argument] return 1 if "numbers" is empty


print(lcm(T))

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string s;cin >> s;
    int n = s.size();
    int l;
    for(l=0;l<n;l++){
        if(s[l] == 'C') break;
    }
    int r;
    for(r=n-1;r>=0;r--){
        if(s[r] == 'F') break;
    }

    cout << (l<r ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-04 13:02:15
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    cout << n - i + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int max = 0;
        int sum = 0;
        for(int i=0;i<N;i++)
        {
            int num = sc.nextInt();
            if(max<num)
            {
                sum += num;
                max = num;
            }
            else
            {
                sum += num;
            }
        }
        sum = sum - max;
        if(max<sum)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    k = II()
    ans = 1
    for i in range(n):
        if ans < k:
            ans *= 2
        else:
            ans += k
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int ans=INF;
int dp[12];

int main(){
    int n,m,x;
    cin >> n>>m>>x;
    int c[n];
    int a[n][m];
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    rep(i,1<<n){
        rep(j,m){
            dp[j]=0;
        }
        int temp=0;
        rep(j,n){
            if(i>>j&1==1){
                temp+=c[j];
                rep(k,m){
                    dp[k]+=a[j][k];
                }
            }
        }
        bool ok=1;
        rep(j,m){
            if(dp[j]<x){
                ok=0;
            }
        }
        if(ok){
            ans=min(ans,temp);
        }
    }
    if(ans==INF){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Math.min(sc.nextInt(), sc.nextInt());
        int m = Math.min(sc.nextInt(), sc.nextInt());
        System.out.println(n + m);
    }
}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int q;cin>>q;
  vector<int> res(q);
  map<int,int> memo;
  int sm=0;
  rep(i,n){
    memo[a[i]]+=1;
    sm+=a[i];
  }
  rep(i,q){
    int b,c;cin>>b>>c;
    int buf=memo[b];
    sm+=c*buf-b*buf;
    memo.erase(b);
    memo[c]+=buf;
    res[i]=sm;
  }
  for(auto& val:res){
    cout<<val<<"\n";
  }
  return 0;
}


Measured memory_bytes: 8672
#include<iostream>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
ll s[maxn];
int main(){
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll lcm=1;
    for(int i=1;i<=n;i++){
        scanf("%lld",&s[i]);
        if(s[i]%2==0){
            s[i]=s[i]/2;
        }
        lcm=lcm*s[i]/__gcd(lcm,s[i]);
    }
    ll c=0,a,b;
    for(int i=1;i<=n;i++){
        int a=lcm/s[i];
        if(a%2==0){
            c=1;
            break;
        }
    }
    if(c&1){
        cout<<"0"<<endl;
    }
    else
    {
    b=m/lcm;
    if(b&1){
        b=b/2+1;
    }
    else{
        b=b/2;
    }
    printf("%lld\n",b);	
	}
    return 0;
}

Measured memory_bytes: 4600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const int MAX = 2020;
bool a[MAX][MAX]={};
bool dpL[MAX][MAX]={};
bool dpR[MAX][MAX]={};

signed main(){
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<i;j++){
      a[i][j]=s[j]-'0';      
      a[j][i]=!a[i][j];
    }
  }
  
  for(int i=0;i<n;i++)
    dpL[i][i]=dpR[i][i]=1; 

  for(int w=2;w<=n;w++){
    {
      int l=0,r=w-1;
      for(int k=l;k<r;k++)
        dpR[l][r]|=dpR[l][k]&dpL[r-1][k]&a[r][k];    
    }    
    for(int i=1;i+w<=n+1;i++){
      int l=i,r=i+w-1;
      for(int k=l;k<r;k++){
        dpL[r-1][l-1]|=dpR[l][k]&dpL[r-1][k]&a[l-1][k];        
        dpR[l][r]|=dpR[l][k]&dpL[r-1][k]&a[r][k];
      }
    }
  }
  
  int ans=0;
  for(int i=0;i<n;i++)
    if(dpR[0][i]&dpL[n-1][i]) ans++;  
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 12160
package main

import "fmt"

func min(x, y int) int {
	if x <= y {
		return x
	} else {
		return y
	}

}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	fmt.Println(min(a, b) + min(c, d))
}


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

#define FOR(i, a, b) for (int i = a; (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmix(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<int>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;

vad Read(ll n) {
    auto      v = vad(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

class Dice {
  public:
    ll top_;
    ll bottom_;
    ll W_;
    ll S_;
    ll E_;
    ll N_;

    Dice() {
        top_    = 1;
        bottom_ = 6;
        W_      = 4;
        S_      = 2;
        E_      = 3;
        N_      = 5;
    }

    void RollW(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = E;
        bottom_ = W;
        W_      = top;
        S_      = S;
        E_      = bottom;
        N_      = N;
    }

    void RollS(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = N;
        bottom_ = S;
        W_      = W;
        S_      = top;
        E_      = E;
        N_      = bottom;
    }

    void RollE(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = W;
        bottom_ = E;
        W_      = bottom;
        S_      = S;
        E_      = top;
        N_      = N;
    }

    void RollN(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = S;
        bottom_ = N;
        W_      = W;
        S_      = bottom;
        E_      = E;
        N_      = top;
    }


    void Roll(char dist) {
        if (dist == 'W') RollW(top_, bottom_, W_, S_, E_, N_);
        else if (dist == 'S')RollS(top_, bottom_, W_, S_, E_, N_);
        else if (dist == 'E')RollE(top_, bottom_, W_, S_, E_, N_);
        else if (dist == 'N')RollN(top_, bottom_, W_, S_, E_, N_);
        //else cout << dist << " is not distance" << endl;

        //cout << "top : " << top_ << ", bottom : " << bottom_ << ", W : " << W_
        //<< ", S : " << S_ << ", E : " << E_ << ", N : " << N_ << endl;
    }
};

int main() {
    cout << setprecision(20) << fixed;
    auto num = vi(7);

    FOR(i, 1, 7) cin >> num[i];

    string dist;
    cin >> dist;

    const auto n = dist.size();

    Dice dice;
    REP(i, n) dice.Roll(dist[i]);

    cout << num[dice.top_] << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    sort(S.begin(), S.end());
    vector<pair<string,int> > count;
    string curr = S[0];
    count.push_back(make_pair(S[0], 1));
    repSE(i,1,N) {
        if (S[i] != curr) {
            curr = S[i];
            count.push_back(make_pair(curr, 1));
        } else {
            count.back().second += 1;
        }
    }
    // int max_count = 0;
    // rep(i, count.size()) {
    //     int cnt = count[i].second;
    //     if (cnt > max_count) max_count = cnt;
    // }
    // rep(i, count.size()) {
    //     if (count[i].second > max_count) cout << count[i].first << endl;
    // }
    sort(count.begin(), count.end(),
         [](pair<string,int> a, pair<string,int> b) {
             if (a.second == b.second)
                 return a.first < b.first;
             else
                 return a.second > b.second;
         }
         );
    rep(i,count.size()) {
        if (count[i].second == count[0].second)
            cout << count[i].first << endl;
        else
            break;
    }
    return 0;
}


Measured memory_bytes: 18676
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000000
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pi 3.14159
ll power(ll a,int n){
  if(n==0)
    return 1;
  if((n%2)==0)
    return power(a*a,n/2);
  else
    return a*power(a*a,n/2);    
}
vector<bool> mark;
void seive(ll N){
    mark.resize(N+1);
  for(ll i=2;i*i<=N;i++){
    if(!mark[i]){
       for(ll j=i*i;j<=N;j+=i){
         mark[j]=1;
       }
      }
  }
}
int main(){
FASTIO
ll a,b,n;
cin>>a>>b>>n;
if(n>=(b-1)){
  cout<<(a*(b-1))/b;
}
else{
  cout<<(a*n)/b;
}
return 0;
}


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

int main(void)
{
  int r,D,x;
  cin>>r>>D>>x;
  int y=x;
 
  for(int i=0;i<10;i++){
    y=r*y-D;
    cout<<y<<endl;
  }
  
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define TTF template<typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline void Out(T&x){cout<<x;}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline int ubnd(T&v,ET(T)&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T)&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF inline void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF inline void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
#undef TT
#undef TTF
#undef ET

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}

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

int dp[128][4][4][4] = {};
int decided[128] = {};

int main()
{
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++){
    int d = in();
    decided[d] = in();
  }

  dp[0][0][0][0] = 1;
  for (int d = 1; d <= n; d++){
    for (int u = 1; u < 4; u++){
      if (decided[d] && decided[d] != u) continue;
      for (int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++){
          if (u == i && u == j) continue;
          for (int k = 0; k < 4; k++){
            dp[d][u][i][j] = (dp[d][u][i][j] + dp[d - 1][i][j][k]) % Mod;
          }
        }
      }
    }
  }
  int tot = 0;
  for (int i = 0; i < 4; i++){
    for (int j = 0; j < 4; j++){
      for (int k = 0; k < 4; k++){
        tot = (tot + dp[n][i][j][k]) % Mod;
      }
    }
  }
  cout << tot << endl;
  return (0);
}

// priority_queue queue deque front stringstream max_element min_element insert count make_tuple

Measured memory_bytes: 1260
import java.util.*;

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int H = sc.nextInt();
		final int W = sc.nextInt();

		char[][] board = new char[H + 2][W + 2];
		sc.nextLine();

		final char WALL = 'x';

		for (int i = 0; i < H + 2; i++) {
			board[i][0] = board[i][W + 1] = WALL;
		}
		for (int j = 0; j < W + 2; j++) {
			board[0][j] = board[H + 1][j] = WALL;
		}

		for (int i = 0; i < H; i++) {
			String s = sc.nextLine();
			for (int j = 0; j < s.length(); j++) {
				board[i + 1][j + 1] = s.charAt(j);
			}
		}

		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if (board[i][j] == '#') {
					if (board[i - 1][j] != '#' && board[i][j - 1] != '#' && board[i + 1][j] != '#'
							&& board[i][j + 1] != '#') {	
						System.out.println("No");
						return;
					}

				}
			}
		}
		System.out.println("Yes");
		sc.close();

	}

}


Measured memory_bytes: 23380
#include<stdio.h>

#define SIZE 500000

int heap[SIZE];

void maxHeapify(int i, int n){
	int l = 2*i;
	int r = 2*i+1;
	int largest = i;
	if( l <= n && heap[l] > heap[i] ){
		largest = l;
	}
	if( r <= n && heap[r] > heap[largest] ){
		largest = r;
	}
	if( largest != i ){
		int temp = heap[i];
		heap[i] = heap[largest];
		heap[largest] = temp;
		maxHeapify(largest, n);
	}
	return;
}

void buildMaxHeap(int n){
	int i;
	for( i = SIZE/2; i >= 1; i-- ){
		maxHeapify(i, n);
	}
}

void output(int k, int n){
	printf("node %d: key = %d, ", k, heap[k]);
	if( k/2 > 0 ){ printf("parent key = %d, ", heap[k/2]); }
	if( k*2 <= n ){ printf("left key = %d, ", heap[k*2]); }
	if( k*2 + 1 <= n ){ printf("right key = %d, ", heap[k*2+1]); }
	printf("\n");
	return;
}

int main(){
	int n, i;
	scanf("%d", &n);
	for( i = 1; i <= n; i++ ){ scanf("%d", &heap[i]); }
	buildMaxHeap(n);
	for( i = 1; i <= n; i++ ){ printf(" %d", heap[i]); }
	printf("\n");
	return 0;
}

Measured memory_bytes: 2548
#include <iostream>

int main()
{
  int n;
  std::cin >> n;
  int b[101] = {};

  for ( int i = 0; i < n; i++ ) {
    int d;
    std::cin >> d;
    b[d]++;
  }
  int ans = 0;
  for ( int i = 1; i < 101; i++ ) {
    if ( b[i] != 0 ) ans++;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  string ans = "";

  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '0') {
      ans.push_back('0');
    }
    else if(s[i] == '1') {
      ans.push_back('1');
    }
    else if (s[i] == 'B' && ans.size() > 0) {
      ans.pop_back();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
<?php

class CalculateSum
{
    public function getAnswer()
    {
        $n = trim(fgets(STDIN));
        $count = 0;

        for ($i = 0; $i < $n; $i++) {
            $num = (int) fgets(STDIN);

            if ($this->isPrime($num)) {
                $count++;
            }
        }

        echo $count . PHP_EOL;
    }
}

class CheckPrimeNumbers extends CalculateSum
{
    public function isPrime($num)
    {
        if ($num == 2) {
            return true;
        } elseif ( $num < 2 or $num % 2 == 0) {
            return false;
        } else {
            $start = 3;
            while ($start <= sqrt($num)) {
                if ($num % $start == 0) {
                    return false;
                }
                $start += 2;
            }
            return true;
        }
    }
}

$rate = new CheckPrimeNumbers();
$rate->getAnswer();



Measured memory_bytes: 9316
h,w = gets.chomp.split(' ').map(&:to_i)
a = []
for i in 0..(h-1)
  a[i] = gets.chomp
end

a.map!{ |s| s = s.include?('#') ? s : nil }
for j in 0..(w-1)
  flag = true
  for i in 0..(h-1)
    unless a[i].nil?
      flag = false if a[i][j] == '#'
    end
  end
  if flag
    for i in 0..(h-1)
      a[i][j] = ' ' unless a[i].nil?
    end
  end
end
a.each do |a|
  puts a.delete(' ') unless a.nil?
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      if( N == i*j){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  
}

Measured memory_bytes: 3604
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

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


int main() {
    ll n;
    scanf("%lld", &n);
    vector<ll> x(n + 1);
    for (int i = 0; i <= n; ++i) scanf("%lld", x.begin() + i);
    sort(x.begin(), x.end());
    for (int i = n; i >= 1; --i) x.at(i) -= x.at(i - 1);
    for (int i = 2; i <= n; ++i) x.at(1) = gcd(x.at(1), x.at(i));
    printf("%lld\n", x.at(1));
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int primemap[1000000]={0},i,sum=0,j;
    primemap[0]=1;primemap[1]=1;
    for(i=2;i*i<999999;i++){
        j=2;
        while(i*j <= 999999){
            primemap[i*j]=1;
            j++;
        }
    }
    while(1){      
        scanf("%d",&j);
        if(j==0)
            break;
        for(i=2;i<=999999;i++){
                if(primemap[i] == 0){
                    sum+=i;
                    j--;
                    if(j == 0)
                        break;
                }
            }
            printf("%d\n",sum);
            sum=0;
    }
    return 0;
}

Measured memory_bytes: 4512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n;
  cin >> n;
  int m = 1000000;
  ll ans = 1000000000010;
  for (int i = 1; i <= m && i <= n; ++i) {
    if (n %i ==0) {
      ll tmp = i + n/i;
      ans = min(ans, tmp);
    }
  }
  cout << ans - 2 << endl;
  return 0;
}


Measured memory_bytes: 3144
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    x = next_int()

    if x == 3 or x == 5 or x == 7:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

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

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

int dp[40] = {0};

ll f(ll x)
{
    if (x <= 0)
        return 0;
    // 2^40 > 10^12
    ll acc[40] = {0};
    for (int i = 0; i < 40; i++) {
        ll mod = (1LL << (i + 1));

        acc[i] += x / mod * mod / 2;
        ll rem = x % mod - (mod / 2 - 1);
        if (rem > 0)
            acc[i] += rem;
    }

    ll ans = 0;
    for (int i = 0; i < 40; i++)
        if (acc[i] % 2 == 1)
            ans |= (1LL << i);
    return ans;
}

int main()
{
    ll a, b;
    scanf("%lld %lld", &a, &b);

    printf("%lld\n", f(b) ^ f(a - 1));

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()

signed main(){
	int N,K,X;
	X = 0;
	cin >> N >> K;
	vector<int> H(N);
	rep(i, N)
		cin >> H[i];
	sort(all(H));
	rep(i, N - K)
		X += H[i];
	cout << X;
}

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

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int>height(n);
  rep(i,n) cin >>height[i];
  int count = 0;
  rep(i,n){
      if(height[i] >= k){
          count ++;
      }
  }
  cout << count << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s, t;
lli q, sn, tn, sc[100001], tc[100001];

int main() {
  cin >> s >> t;
  sn = s.size(); tn = t.size();

  for (lli i=1; i<=sn; ++i) sc[i] = sc[i-1] + (s[i-1] == 'A' ? 1 : 2);
  for (lli i=1; i<=tn; ++i) tc[i] = tc[i-1] + (t[i-1] == 'A' ? 1 : 2);

  cin >> q;

  for (lli i=0; i<q; ++i) {
    lli a, b, c, d; cin >> a >> b >> c >> d;
    lli sp = sc[b] - sc[a-1], tp = tc[d] - tc[c-1];
    bool ans = sp % 3 == tp % 3;
    // cout << sp << ' ' << tp << endl;
    cout << (ans ? "YES" : "NO") << '\n';
  }
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#define max 100000
#define sen 2000000000
using namespace std;

struct card{
	char suit;
	int value;
};
struct card l[max/2+2],r[max/2+2];

void merge(struct card a[],int n,int left,int mid,int right)
{
	int i,j,k;
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++) l[i]=a[left+i];
	for(int i=0;i<n2;i++) r[i]=a[mid+i];
	l[n1].value=r[n2].value=sen;
	i=j=0;
	for(k=left;k<right;k++)
	{
		if(l[i].value<=r[j].value){
			a[k]=l[i++];
		}
		else{
			a[k]=r[j++];
		}
	}
}

void mergesort(struct card a[],int n,int left,int right)
{
	int mid;
	if(left+1<right)
	{
		mid=(left+right)/2;
		mergesort(a,n,left,mid);
		mergesort(a,n,mid,right);
		merge(a,n,left,mid,right);
	}
}

int partition(struct card a[],int n,int p,int r)
{
	int i,j;
	struct card t,x;
	x=a[r];
	i=p-1;
	for(j=p;j<r;j++)
	{
		if(a[j].value<=x.value)
		{
			i++;
			t=a[i];a[i]=a[j];a[j]=t;
		}
	}
	t=a[i+1];a[i+1]=a[r];a[r]=t;
	return i+1;
}

void quicksort(struct card a[],int n,int p,int r)
{
	int q;
	if(p<r)
	{
		q=partition(a,n,p,r);
		quicksort(a,n,p,q-1);
		quicksort(a,n,q+1,r);
	}
}

struct card a[max],b[max];
int main()
{
	int n,i,v;
	char s[10];
	int stable=1;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%s %d",s,&v);
		a[i].suit=b[i].suit=s[0];
		a[i].value=b[i].value=v;
	}
	
	mergesort(a,n,0,n);
	quicksort(b,n,0,n-1);
	
	for(int i=0;i<n;i++)
	{
		if(a[i].suit!=b[i].suit) stable=0;
	}
	if(stable==1) printf("Stable\n");
	else printf("Not stable\n");
	for(i=0;i<n;i++)
	{
		printf("%c %d\n",b[i].suit,b[i].value);
	}
	return 0;
}

Measured memory_bytes: 5552
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;


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

    int N, a, count = 0;
    cin >> N;

    for(int i = 0;i<N;i++){
        cin >> a;
        while(a % 2 == 0){
            a /= 2;
            count += 1;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
function main(input)
{
    const args = input.split('\n');
    const N = parseInt(args[0], 10);
    const numbers = args.slice(1, N + 1).map(x => parseInt(x, 10));
    const sorted_numbers = numbers.slice().sort((a, b) => a - b);
    const last_number = sorted_numbers[sorted_numbers.length - 1];
    const next_number = sorted_numbers[sorted_numbers.length - 2];

    for(var v of numbers) {
        console.log(last_number === v ? next_number : last_number);
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 41556
n = int(input())
x = [[int(i) for i in input().split()] for j in range(n)]

s = 0
for i in range(1, n):
    for j in range(i):
        s += ((x[i][0] - x[j][0]) ** 2 + (x[i][1] - x[j][1]) ** 2) ** 0.5
print(2 * s / n)


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

signed main(){
  lint N; cin >> N;
	vector<vector<lint> > a(N, vector<lint> (N));
	vector<vector<bool> > ok(N, vector<bool> (N, true));
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++) cin >> a[i][j];
	}
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(a[i][j] > a[i][k] + a[j][k]){
					cout << -1 << endl;
					return 0;
				}
				if(a[i][j] == a[i][k] + a[k][j] && a[i][k] * a[k][j] > 0) ok[i][j] = false;
			}
		}
	}
	lint ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= i; j++) if(ok[i][j]) ans += a[i][j];
	}
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=998244353;
using namespace std;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}





int32_t main(){
	
	//FIO();
	
	int n,mx;cin>>n>>mx;
	const int sum=100000;
	int w[n],v[n],dp[sum+1];
	for(int i=0; i<n; i++){
		cin>>w[i]>>v[i];
	}
	for(int i=0; i<=sum; i++){
		dp[i]=-1;
	}
	dp[0]=0;
	for(int i=0; i<n; i++){
		for(int j=sum; j>=0; j--){
			if(dp[j]!=-1 && dp[j]+w[i]<=mx){
				if(dp[j+v[i]]==-1)
					dp[j+v[i]]=dp[j]+w[i];
				else
					dp[j+v[i]]=min(dp[j]+w[i],dp[j+v[i]]);
			}
		}
	}
	
	int ret;
	for(int i=0; i<=sum; i++){
		if(dp[i]!=-1)
			ret=i;
	}	
	
	cout<<ret<<"\n";
	

	return 0;
		
	
		
		
}


Measured memory_bytes: 1024