akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;
ll expo(ll a, ll b){
    if(b == 0) 
		return 1;
    ll x = expo(a, b/2);
    return (b & 1 ? ((x*x)%mod*a)%mod : (x*x) % mod);
}

int main() {
	int n;
	cin >> n;
	pii xd[n+5];
	for(int i = 0; i < n; i++) {
		cin >> xd[i].f;
		xd[i].s = i+1;
	}
	sort(xd, xd+n);
	for(int i = 0; i < n; i++)
		cout << xd[i].s << " ";

	cout << endl;
}


Measured memory_bytes: 1664
K, A, B = map(int,input().split())
ans = 0
if B - A < 2:
    ans = K+1
else:
    n = K - A + 1 #A個を達成する最初のindex
    if n % 2 == 1:
        ans = A + n // 2 * (B-A) + 1
    else:
        ans = A  + n // 2 * (B-A)
print(ans)

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void solve() {
	int n; cin >> n;
	int k; cin >> k;
	LL a[100000]; rep(i, n) cin >> a[i];
	LL as[100001]; as[0] = 0;
	LL as2[100001]; as[0] = 0;
	rep(i, n) as[i + 1] = as[i] + a[i];
	rep(i, n) as2[i + 1] = as2[i] + max(0ll, a[i]);

	LL ans = 0;
	for (int i = k; i <= n; i++) {
		LL l = as2[n] - as2[i] + as2[i - k];
		LL B = as[i] - as[i - k];
		ans = max(ans, l + B);
		ans = max(ans, l);
	}

	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 2560
n, p = map(int, input().split())
A = list(map(int, input().split()))
even = len(list(filter(lambda x: x%2==0, A)))
odd = len(list(filter(lambda x: x%2==1, A)))
even_ans = 2 ** even
if odd == 0:
    if p == 0:
        odd_ans = 1
    else:
        odd_ans = 0
else:
    odd_ans = 2 ** odd // 2
print(even_ans * odd_ans)


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

std::vector<std::vector<std::array<int, 3>>> edges;

int dfs(int, int, int);

int main()
{
	int N;
	scanf("%d", &N);
	edges.resize(N);
	for (int i{}; i < N - 1; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		edges[a].push_back({b, -1, i});
		edges[b].push_back({a, -1, i});
	}
	int max{dfs(0, -1, -1)};
	std::vector<int> ans(N - 1);
	for (auto& e: edges)
		for (auto& f: e)
			if (f[1] >= 0)
				ans[f[2]] = f[1];
	printf("%d\n", max);
	for (auto& e: ans)
		printf("%d\n", e + 1);

	return 0;
}

int dfs(int index, int prev, int from)
{
	int color{}, max{(int)edges[index].size()};
	for (auto& e: edges[index])
	{
		if (e[0] == from) continue;
		if (color == prev)
			color++;
		e[1] = color;
		max = std::max(max, dfs(e[0], e[1], index));
		color++;
	}
	return max;
}

Measured memory_bytes: 8320
#include <iostream>
using namespace std;
int main()
{
	string S;
	cin>> S ;
	int n = 700;
	for (int i = 0; i < 3; ++i)
	{
		if(S[i] == 'o')n = n + 100;
		else;
	}
	cout << n << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0)
    cout<<"1";
  else if(x2==0)
    cout<<"2";
  else if(x3==0)
    cout<<"3";
  else if(x4==0)
    cout<<"4";
  else
    cout<<"5";
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

ll solve(ll n, ll x) {
    if(n == -1) {
        return 0;
    } else {
        return n/x+1;    
    }
}
int main(void)
{
    ll a, b, x;
    
    cin >> a >> b >> x;

    ll ans = solve(b, x) - solve(a-1, x);
    
    cout << ans << endl;

    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

long long powerMod(long long x, long long n, long long mod) {
    long long ret = 1LL;
    while (n > 0) {
        if (n & 1) (ret *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}
int main() {
    long long m, n;
    cin >> m >> n;
    cout << powerMod(m, n, MOD) << endl;
    return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>

typedef struct {int id, par, dep, child, sib;}Node;

Node node[200000];

void dfs(int pos, int dep){
  node[pos].dep = dep;
  if(node[pos].child != -1) dfs(node[pos].child, dep + 1);
  if(node[pos].sib != -1) dfs(node[pos].sib, dep);
}

void prChilds(int pos, int init){
  if(pos == -1) return;
  if(init) printf("%d", pos);
  else printf(", %d", pos);
  if(node[pos].sib != -1) prChilds(node[pos].sib, 0);
}

int main(){
  int i, j, k;
  int N;
  int id, sib, child;
  int root = 0;
  scanf("%d", &N);
  for(int i=0;i<N;i++) node[i].par = node[i].child = node[i].sib = -1;
  
  for(i=0;i<N;i++){
    scanf("%d %d", &id, &k);
    node[id].id = id;
    for(j=0;j<k;j++){
      scanf("%d", &child);
      node[child].par = id;
      if(j == 0) node[id].child = child, sib = child;
      else node[sib].sib = child;
      sib = child;
    }
  }


  for(i=0;i<N;i++) if(node[i].par == -1) root = i;
  dfs(root, 0);

  for(i=0;i<N;i++){
    printf("node %d: parent = %d, depth = %d, ", node[i].id, node[i].par, node[i].dep);
    if(node[i].par == -1) printf("root, ");
    else if(node[i].child == -1) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    prChilds(node[i].child, 1);
    printf("]\n");
  }
  

  return 0;
}




Measured memory_bytes: 4632
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
int n;
int cnt=0;
cin>>n;
vector<int>d(n);
for(int i=0;i<n;i++){
    cin>>d.at(i);
}
vector<int>backet(100);
for(int i=0;i<n;i++){
    backet.at(d.at(i)-1)++;
}
for(int i=0;i<backet.size();i++){
    if(backet.at(i)>0){
        cnt++;
    }
}
cout<<cnt<<endl;
}








Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 try{

			 int S = Integer.parseInt(br.readLine());

			 System.out.printf("%d:%d:%d\n",S/3600,(S%3600)/60,S%60);

		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}
}


Measured memory_bytes: 24664
n=int(input())
a=[]
b=[0]*n

for i in range(n):
    a.append(int(input()))
c=0
v=0
while v!=1:
    b[v]+=1
    if b[v]==2:
        print(-1)
        exit()
    c+=1
    v=a[v]-1
print(c)
        
    

Measured memory_bytes: 7888
# coding: utf-8
import sys

def gcd(a, b):
    m = a % b
    if m == 0:
        return b
    return gcd(b, m)

for l in sys.stdin:
  x, y = map(int, l.split())
  g = gcd(x, y)
  l = x * y / g
  print g, l

Measured memory_bytes: 6360
K,N=list(map(int,input().split()))
num_list = list(map(int, input().split()))
x_list=[]
for i in range(N):
  x_list.append(num_list[i]-num_list[i-1])
x_list[0]=K-num_list[-1]+num_list[0]
print(K-max(x_list)) 

Measured memory_bytes: 26548
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())
data = getInputListInt()

onedic = {0:0}
twodic = {0:0}

for i in range(n):
    if i % 2 ==0:
        onedic[data[i]]=0
    else:
        twodic[data[i]]=0

for i in range(n):
    if i % 2 ==0:
        onedic[data[i]]+=1
    else:
        twodic[data[i]]+=1

onemax = max(onedic, key=onedic.get)
twomax = max(twodic, key=twodic.get)

onemax = sorted(onedic.items(), key = lambda x:x[1], reverse=True)
twomax = sorted(twodic.items(), key = lambda x:x[1], reverse=True)

ans = 0
if onemax[0][0] != twomax[0][0]:
    ans = n - onemax[0][1] - twomax[0][1]
else:
    ans = min(n - onemax[0][1] - twomax[1][1], n - onemax[1][1] - twomax[0][1])

print(ans)



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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b) {
        if (b < c) {
            cout << a << ' ' << b << ' ' << c << endl;
        } else {
            if (a < c) {
                cout << a << ' ' << c << ' ' << b << endl;
            } else {
                cout << c << ' ' << a << ' ' << b << endl;
            }
        }
    } else {
        if (a < c) {
            cout << b << ' ' << a << ' ' << c << endl;
        } else {
            if (b < c) {
                cout << b << ' ' << c << ' ' << a << endl;
            } else {
                cout << c << ' ' << b << ' ' << a << endl;
            }
        }
    }
    return 0;
}


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

int main()
{
	while (true)
	{
		int m;
		cin >> m;
		if (m==0) break;
		
		int dp[8][7001];
		dp[0][0] = 1;
		for (int i=1; i<=7000; i++) dp[0][i]=0;
		
		for (int i=1; i<=m; i++)
		{
			int a, b;
			cin >> a >> b;
			
			for (int j=0; j<=7000; j++)
				dp[i][j] = dp[i-1][j];
			
			for (int j=0; j<=7000; j++)
				if (dp[i-1][j]!=0)
					for (int k=1; k<=b; k++)
						dp[i][j+a*k] += dp[i-1][j];
		}
		
		int g;
		cin >> g;
		for (int i=0; i<g; i++)
		{
			int n;
			cin >> n;
			cout << dp[m][n] << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

bool is_valid(const vector<int>& edges)
{
  for (auto e: edges) if (e % 2 == 1) return false;
  return true;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> edges(N, 0);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    ++edges[a-1];
    ++edges[b-1];
  }
  cout << (is_valid(edges) ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,k,a[100050];
LL F[100050][2];
int main() {
    scanf("%d%d",&n,&k);
    for (int _=1;_<=n;_++) scanf("%d",&a[_]);
    F[0][0] = 1LL;
    for (int _=1;_<=n;_++) {
        int t = a[_]&1;
        F[_][0] = F[_-1][0] + F[_-1][0^t];
        F[_][1] = F[_-1][1] + F[_-1][1^t];
    }
    cout << F[n][k] << endl;

    return 0;       
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long n,a,b[1000000],c,p;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",&a);if(b[0]==1 || c>a){printf("No\n");continue;}
		if(c==a && p!=a){printf("No\n");continue;}p++;
		if(a>=1000000){printf("Yes\n");continue;}
		b[a]++;while(b[a]>=2){b[a]-=2;b[a-1]++;a--;p--;}
		while(c<=999998 && b[c+1]==1)c++;
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 7152
import java.util.Scanner;

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

		int[] vc=new int[4];
		String a=sc.next();

		for(int i=0; i<4; i++) {
			vc[i]=0;
		}
		for(int i=0; i<a.length(); i++) {
			if(a.charAt(i)=='N') {
				vc[0]++;
			}
			else if(a.charAt(i)=='W') {
				vc[1]++;
			}
			else if(a.charAt(i)=='S') {
				vc[2]++;
			}
			else if(a.charAt(i)=='E') {
				vc[3]++;
			}
		}

		int zc=0;
		for(int i=0; i<4; i++) {
			if(vc[i]==0) {
				zc++;
			}
		}
		if(zc%2==1) {
			System.out.println("No");
		}
		else {
			if(vc[0]*vc[2]>0 || (vc[0]==0 && vc[2]==0)) {
				if(vc[1]*vc[3]>0 || (vc[1]==0 && vc[3]==0)) {
					System.out.println("Yes");
				}
				else {
					System.out.println("No");
				}
			}
			else {
				System.out.println("No");
			}
		}
	}
}

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

int main(){
  int N; cin>>N;
  vector<int> H;
  int ans=0; int mh=0;
  for(int i=0;i<N;i++){
    int h; cin>>h;
    if(mh<=h){ mh=h; ans++; }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
#define fi first
#define sec second
#define INF 1000000000
const int SIZE = 1<<20;
struct segtree{
	int seg[SIZE*2];
	segtree(){
		for(int i=0;i<SIZE*2;i++){
			seg[i] = INF;
		}
	}
	void update(int k,int x){
		k += SIZE-1;
		seg[k] = min(seg[k],x);
		while(k>0){
			k = (k-1)/2;
			seg[k] = min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return INF;
		if(a<=l&&r<=b)return seg[k];
		int mid = (l+r)/2;
		return min(query(a,b,k*2+1,l,mid),query(a,b,k*2+2,mid,r));
	}
}seg;
bool comp(P a,P b){
	if(a.sec!=b.sec)return a.sec < b.sec;
	else return a.fi < b.fi;
}
int N;
ll L;
vector<ll> zip;
vector<P> vec;
int dp[400100];
int rui[400100];
int main(){
	cin >> N >> L;
	zip.pb(L);
	vec.resize(N);
	for(int i=0;i<N;i++){
		cin >> vec[i].fi >> vec[i].sec;
		zip.pb(vec[i].fi);
		zip.pb(vec[i].sec);
	}
	zip.pb(0ll);
	sort(zip.begin(),zip.end());
	zip.erase(unique(zip.begin(),zip.end()),zip.end());
	for(int i=0;i<N;i++){
		vec[i].fi = lower_bound(zip.begin(),zip.end(),vec[i].fi)-zip.begin();
		vec[i].sec = lower_bound(zip.begin(),zip.end(),vec[i].sec)-zip.begin();
		rui[vec[i].fi]++;
		rui[vec[i].sec]--;
	}
	sort(vec.begin(),vec.end(),comp);
	// for(int i=0;i<vec.size();i++){
	// 	cout << vec[i].fi << ' ' << vec[i].sec << endl;
	// }
	for(int i=1;i<=zip.size();i++){
		dp[i] = INF;
	}
	dp[0] = 0ll;
	seg.update(0,dp[0]);
	for(int i=0;i<vec.size();i++){
		int l = vec[i].fi;
		int r = vec[i].sec;
		dp[r] = min(dp[r],seg.query(l,r,0,0,SIZE)+1);
		seg.update(r,dp[r]);
	}
	for(int i=1;i<zip.size();i++){
		rui[i] += rui[i-1];
	}
	int mi = INF;
	for(int i=0;i+1<zip.size();i++){
		mi = min(mi,rui[i]);
	}
	cout << dp[zip.size()-1] << ' ' << N-mi+1 << endl;
	return 0;
}




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

#define rep(i,s,t) for(int i = s; i <= t; ++ i)

const int MaxN = 105;

char str[MaxN];

int main()
{
	scanf("%s",str+1);
	int n = strlen(str+1);
	rep(i,1,n) rep(j,i+1,n) if(str[i] == 'C' && str[j] == 'F') {puts("Yes"); return 0;}
	puts("No");
} 

Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

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

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------

string target[4] = {"dream", "dreamer", "erase", "eraser"};
string S;

bool search(int& itr) {
  REP(i, 4) {
    string subword = target[i];
    int subsize = SZ(subword);
    if (itr >= subsize - 1) {
      if (S.substr(itr - subsize + 1, subsize) == subword) {
        itr -= subsize;
        return true;
      }
    }
  }
  return false;
}

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

  cin >> S;
  int itr = SZ(S) - 1;
  while (itr > 0) {
    if (!search(itr)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 512
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
int main(){
  int r,g,b;
  cin>>r>>g>>b;
  int a=g*10+b;
  cout<<((a%4==0)?"YES":"NO")<<endl;
  return 0;
}
      


Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897

#define INFI -(ll)1e12

vector<vector<ll>> A;
vector<ll> dp, store;
ll val = 0, n = 0;

ll solve(ll mask);

void solver(ll mask, ll i, vector<ll> &idx, ll group) {
    if(i==idx.size()) {
        if(group!=0)
            dp[mask] = max(dp[mask], store[group] + solve(group | mask));
        return;
    }

    solver(mask,i+1,idx,group);
    solver(mask,i+1,idx,group|(1<<idx[i]));
}

ll solve(ll mask) {
    // cout<<mask<<endl;
    if(mask==val)
        return 0;

    if(dp[mask]!=INFI)
        return dp[mask];

    vector<ll> idx;
    rep(i,n)
        if(!((1<<i)&mask))
            idx.pb(i);

    solver(mask, 0, idx, 0);

    // ll v = 1<<(ll)idx.size();
    // rep2(i,1,v) {
    //     ll mask2 = mask, mask3 = 0;
    //     rep(j,idx.size()) {
    //         if(i&(1<<j)) {
    //             mask2 |= (1<<idx[j]);
    //             mask3 |= (1<<idx[j]);
    //         }
    //     }

    //     // cout<<"mask1 "<<mask<<" mask2 "<<mask2<<" mask3 "<<mask3<<" "<<store[mask3]<<endl;
    //     res = max(res, store[mask3] + solve(mask2));
    // }

    // cout<<mask<<" "<<res<<endl;

    return dp[mask];
}

void precompute() {

    for(ll i=0;i<=val;i++) {
        rep(j,n) {
            if(i & (1<<j)) {
                rep2(k,j,n) {
                    if(i & (1<<k)) {
                        store[i] += A[j][k];
                    }
                }
            }
        }
    }
}



int main() {

    scanf("%lld",&n);
    A.assign(n, vector<ll>(n,0));

    rep(i,n)
        rep(j,n)
            scanf("%lld",&A[i][j]);

    val = (1<<n)-1;
    dp = vector<ll>(val+1,INFI);
    store = vector<ll>(val+1,0);

    precompute();

    // for(auto i:store)
    //     cout<<i<<endl;

    printf("%lld\n", solve(0));

    return 0;  
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)


// ------------debug用------------
#define FALSE cout<<"false"<<endl;
#define TRUE cout<<"true"<<endl;
// ------------debug用------------


// ------------計算用------------
#define ALL(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)
// ------------計算用------------


// ------------出力用------------
#define PRINT(x) cout<<x<<endl;
// ------------出力用------------


using namespace std;
typedef long long ll;

int main(){
  int N;
  cin>>N;
  vector<pair<ll,ll> > xy(N);

  for(int i = 0;i < N;++i){
    cin>>xy[i].first;
    cin>>xy[i].second;
  }
  sort(ALL(xy));
  
  vector<ll> allx(N * N * 2);
  vector<ll> ally(N * N * 2);
  int counter = 0;
  for(int i = 0;i < N;i++){
    for(int j = i + 1;j < N;j++){
      allx[counter] = xy[i].first - xy[j].first;
      ally[counter] = xy[i].second - xy[j].second;
      counter++;
    }
  }
  
  int maxx = 0;
  int maxy = 0;
  for(int i = 0;i < counter;i++){
    int cntx = 0;
    int cnty = 0;
    for(int j = i + 1;j < counter;j++){
      cntx += (allx[i] == allx[j] && ally[i] == ally[j]);
      //cnty += ally[i] == ally[j];
    }
    if(cntx > maxx)maxx = cntx;
    //if(cnty > maxy)maxy = cnty;
  }
  int tmp = maxx;//= min(maxx,maxy);
  int ans = N - tmp - 1;
  if(N == 1)ans = 1;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

char format[500001];
int start,end;
bool reversed;

int main(){
    scanf("%s",format+200000);

    //
    start=200000;
    end=start+strlen(format+200000);

    int Q;
    scanf("%d",&Q);

    // printf("Q=%d\n",Q);
    for(int i=0;i<Q;i++){
        // puts("loop");
        int T;
        scanf("%d",&T);
        if (T==1)
            reversed=!reversed;
        else {
            int F;
            scanf("%d",&F);
            char C;
            scanf(" %c",&C);
            // printf("C=%c\n",C);
            //front
            if (reversed&&F==2||(!reversed&&F==1))
                format[--start]=C;
            else 
                format[end++]=C;
        }

    }


    // printf("%d %d",start,end);
    if (!reversed){

        for (int i=start;i<end;i++)
            putchar(format[i]);

        putchar('\n');
    }else {
        for (int i=end-1;i>=start;i--)
            putchar(format[i]);

        putchar('\n');
    }

    return 0;
}

Measured memory_bytes: 768
n=int(input())
A=list(input())
w=0 ; r=A.count("R") ; ans=10**7
for i in range(n+1):
    ans=min(ans, max(w,r))
    if i==n:print(ans);exit()
    if A[i]=="R":
        r-=1
    else:
        w+=1


Measured memory_bytes: 81816
#include<bits/stdc++.h>
using namespace std;
int a[10009];
int ans[106][106];
bool vis[106][106];
int x = 0, y = 1 , way = 1;
int main()
{
	int H, W, N;
	scanf("%d%d%d", &H, &W, &N);
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			vis[i][j] = true;
		}
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		for (int j = 0; j < a[i]; j++) {
			if (x + way <= H&&x+way>=1) {
				ans[x + way][y] = i + 1;
				x += way;
			}
			else if (x == H|| x == 1) {
				ans[x][++y] = i + 1;
				way = -way;
			}
		}
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			printf("%d%c", ans[i][j], j == W ? '\n' : ' ');
		}
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N; cin >> N;
	int count = 0;
	while (N > 0) {
		if (N % 10 == 2) {
			count++;
		}
		N /= 10;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.

int main() {
	// #ifndef ONLINE_JUDGE
 //    freopen("../input.txt", "r", stdin);
 //    freopen("../output.txt", "w", stdout);
	// #endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	LL n,k;
	cin>>n>>k;
	VL arr(n);
	rep(i,0,n){
		cin>>arr[i];
	}
	sort(ALL(arr));
	LL sum = 0;
	rep(i,0,k){
		sum += arr[i];
	}
	cout<<sum;
  	return 0;
}

Measured memory_bytes: 3648
import sys
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():

	n=II()
	A=LI()

	if A[-1]!=2:
		print(-1)
		exit()

	l=2
	r=2

	for i in range(n-2,-1,-1):
		l=((l-1)//A[i]+1)*A[i]
		r=((r+A[i+1]-1)//A[i])*A[i]
		if l>r:
			print(-1)
			exit()

	print(l,r+A[0]-1)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 20452
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	for (int a = 1;a < 10;a++) {
		for (int b = 1;b < 10;b++) {
			int c = a*b;
			printf("%d", a);
			printf("x");
			printf("%d", b);
			printf("=");
			printf("%d", c);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 928
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, ta, ao, *AB = map(int, read().split())
    ta -= 1
    ao -= 1

    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    dist_ta = [-1] * N
    dist_ta[ta] = 0
    queue = deque([ta])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist_ta[nv] == -1:
                dist_ta[nv] = dist_ta[v] + 1
                queue.append(nv)

    dist_ao = [-1] * N
    dist_ao[ao] = 0
    queue = deque([ao])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist_ao[nv] == -1:
                dist_ao[nv] = dist_ao[v] + 1
                queue.append(nv)

    d_ao = 0
    for d1, d2 in zip(dist_ta, dist_ao):
        if d1 < d2 and d_ao < d2:
            d_ao = d2

    if d_ao == 0:
        if dist_ta[ao] == 1:
            print(0)
        else:
            print(1)

    print(d_ao - 1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 41912
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>


int main(void) {
	std::string s;

	std::cin >> s;

	int zero = std::count(s.begin(), s.end(), '0');
	int one = std::count(s.begin(), s.end(), '1');

	if (s.size() < 2) {
		std::cout << 0 << std::endl;
		return 0;
	}

	std::cout << std::min(zero, one) * 2 << std::endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
const int maxn=1000000+10;
int gcd[maxn],maxSum=0;
int GCD(int a,int b){
   if(b==0) return a;
   return GCD(b,a%b);
}
void slide(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
           gcd[i]++;
           while(x%i==0) x/=i;
        }
    }
    if(x>1) gcd[x]++;
}
int main()
{
    int n,m;
    cin>>n>>m;
    int gc=m;
    for(int i=2;i<=n;i++)
    {
        cin>>m;
        maxSum=max(maxSum,m);
        gc=GCD(gc,m);
        slide(m);
    }
    if(gc==1)
    {
        for(int i=2;i<=maxSum;i++)
        {
            if(gcd[i]>1)
            {
                cout<<"setwise coprime"<<endl;
                return 0;
            }
        }
        cout<<"pairwise coprime"<<endl;
                return 0;
    }
    cout<<"not coprime"<<endl;
    return 0;
}

Measured memory_bytes: 6996
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        int tmp=n%100;
        if((tmp+4)/5<=n/100){
            cout<<1<<endl;
        }
        else{
            cout<<0<<endl;
        }

    }
  return 0;
}




Measured memory_bytes: 256
S = input()
ans = 0
digit  = len(S)-1
for i in range(2**digit):
    bit = format(i,"0"+str(digit)+"b")
    temp = []
    num = S[0]
    for j in range(digit):
        if j == digit - 1:
            if bit[j] == "1":
                temp.append(int(num))
                temp.append(int(S[j+1]))
            else:
                temp.append(int(num+S[j+1:]))
        else:
            if bit[j] == "1":
                temp.append(int(num))
                num = S[j+1]     
            else:
                num += S[j+1]
    ans += sum(temp)
print(int(S) if digit == 0 else ans)
            

Measured memory_bytes: 3064
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [n, x] <- getInts
  ; if n == 0 && x == 0 then return ()
    else print (length (filter ((x ==) . sum) (comb [1 .. n] 3))) >> loop
  }

comb :: [Int] -> Int -> [[Int]]
comb ns 0 = [[]]
comb ns k = if length ns == k then [ns]
            else map (head ns :) (comb (tail ns) (k - 1)) ++ comb (tail ns) k
--
getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



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

#define fast_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define show(x) cout << #x << " = " << x << '\n'
#define ll long long
#define ull unsigned long long
#define PI 3.1415926535897932384626433832795
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("-ffloat-store")
#define modulo 998244353

clock_t time_p = clock();
void time()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (double)(time_p) / CLOCKS_PER_SEC << '\n';
}

int main()
{
    fast_IO
    ll n, mx = 0; cin >> n;
    vector<ll> a(n+1);
    a[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] && a[i-1])
        {
            mx++;
            a[i]--;
        }
        mx += a[i] / 2;
        a[i] = a[i] % 2;
    }
    cout << mx << '\n';
    //time();
    return 0;
}

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

int main(void){
    char s[11],t[11],u[11];
    int a,b;
    scanf("%s %s",s,t);
    scanf("%d %d",&a,&b);
    scanf("%s",u);
    if(!strcmp(s,u)){
        a--;
    }
    if(!strcmp(t,u)){
        b--;
    }
    printf("%d %d\n",a,b);
}


Measured memory_bytes: 128
a = gets.chomp

len = a.length
ans = "-1 -1"

i = 0
while ans == "-1 -1" && i <= len-2
  if a[i] == a[i+1]
    ans = "#{i+1} #{i+2}"
  end
  i = i+1
end

i = 0
while ans == "-1 -1" && i <= len-3
  if a[i] == a[i+2]
    ans = "#{i+1} #{i+3}"
  end
  i = i+1
end

print ans

Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define f(i,n) for(int i=0;i<n;i++)
#define f2(i,j,n) for(int i=j;i<n;i++)

using namespace std;
struct restaurant{
	string name;
	int value;
	int index;
};

bool restaurantSort(const restaurant& a, const restaurant& b){
	if(a.name == b.name) return a.value > b.value;
	else return a.name < b.name;
}


int main(){
	int N, P, tmp;
	string S,strTmp;
	vector<restaurant> r; 
	cin >> N;
	f(i,N){
		cin >> S >> P;
		restaurant rTmp = {S,P,i+1};
		r.push_back(rTmp);
	}
	sort(r.begin(), r.end(), restaurantSort);
	f(i,N) cout << r[i].index << endl;
	return 0;
}

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

using namespace std;
//FILE *fi = freopen("1.txt","r",stdin);
int n,m,K;
string s[11];
int a[11][1001];
typedef pair <int,int> ii;
int ans = 1e9;
int S[11];
int main()
{
    cin>>n>>m>>K;
    for(int i=1;i<=n;i++)
        cin>>s[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<m;j++)
        {
            a[i][j+1] = s[i][j]-'0';
        }
    }
    for(int mask = 0;mask < 1 << (n-1) ; mask++)
    {
        memset(S,0,sizeof S);
        vector <ii> c;
        int cur = 1;
        for(int i=1;i<=n;i++)
        {
            int t = i-1;
            if(mask&(1<<t))
            {
                c.push_back({cur,i});
                cur=i+1;
            }
        }
        c.push_back({cur,n});
        int cnt = __builtin_popcount(mask);
        bool ok=false;
        bool check = false;
        for(int i=1;i<=m;i++)
        {
            if(check)
                break;
            ok=false;
            for(int j = 0;j < c.size();j++)
            {
                int l = c[j].first;
                int r = c[j].second;
                for(int k = l;k <= r;k++)
                {
                    S[j] += a[k][i];
                    if(S[j]>K)
                    {
                        ok=true;
                        break;
                    }
                }
                if(ok)
                {
                    if(i==1)
                    {
                        check=true;
                        break;
                    }
                    i--;
                    cnt++;
                    for(int l=0;l<c.size();l++)
                    {
                        S[l] = 0;
                    }
                    break;
                }
            }
        }
        if(!check)
            ans=min(ans,cnt);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int Get(int x,int k)
{
	if(x==k-1) return 0;
	if(x==k-2) return 1;
	int r=x/k;if(r*k==x) return r;
	if((x-(r+1))/k!=r) return Get(x-r-1,k);
	int nxt=r*k;
	return Get(x-(x-nxt)/(r+1)*(r+1),k);	
}
int main()
{
	int n=read(),ans=0;
	for(int i=1;i<=n;++i) 
	{
		int x=read(),k=read();
		if(x>=k) ans^=Get(x,k);	
	}
	puts(ans?"Takahashi":"Aoki");
	return 0;
}



Measured memory_bytes: 384
n,b,i,t;long long k=1;L(x,y){!y?k*=n/x:L(y,x%y);}main(a){for(;scanf("%d%d",&a,&b,n=1)*a;L(n,k),k=++i%3<1?printf("%lld\n",k),1:k)for(t=a;t-1;t=t*a%b)++n;}

Measured memory_bytes: 0
# 169A
# A × B を整数として出力せよ

# 1. 入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())
# print(a, b)

# 2. 受け取った入力値を使って、適切に処理(計算)すること
answer = a * b

# 3. 計算した結果を出力すること
print(answer)



Measured memory_bytes: 9044
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 105;

int w[N], v[N], dp[N][100005], ready[N][100005];

int solve (int i, int j) {
	if (j == 0) return 0;
	if (j < 0) return inf;
	if (i == 0) return inf;
	if (ready[i][j])return dp[i][j];
	dp[i][j] = min(solve(i-1, j), w[i] + solve(i-1, j-v[i]));
	ready[i][j] = 1;
	return dp[i][j];
}


signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    	cin >> w[i] >> v[i];
    for (int i = 1; i < 100005; i++)
    	dp[0][i] = inf;
    int ans = 0;
    for (int i = 1; i < 100005; i++)
    {
    	if (solve(n, i) <= k) ans = i;
    }
    cout << ans;
    return 0;
}

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

int main()
{
    long long N,i,x,p,q,ans=1000000000000;

    cin>>N;

    x = sqrt(N);
    //cout<<x;

    for(i=x ; i>=1 ; i--){
        if(N%i==0){
            p = i;
            q = N/i;
            break;
        }
        if(i==1){
            p = N;
            q = 1;
            break;
        }
    }
    cout<<p+q-2;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int num[110] = {0};
int n;
int ans = 0;
void Fac(int m){
	if(m==1){
		return ;
	}
	int x = m;
	for(int i = 2; i <= x; i++){
		while(x%i == 0){
			num[i]++;
			x/=i;
		}
	}
	Fac(m-1);
}
void dfs(int p,int v){
	if(p>97){
		if(v == 75)
		ans++; 
		return;
	}
	if(75%v != 0)
		return ;
	for(int i=0;i<=num[p];i++){
		dfs(p+1,v*(i+1));
	}
}
int main() {
	cin >> n;
	Fac(n);
	dfs(2,1);
	cout << ans << endl;
    return 0;
}

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

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
}

int main(){
    fast();
    ll flag=0;
    string s;
    cin>>s;
    if(s.length()%2==1){
    	cout<<"No";
	}
	else{
		string t;
		for(ll i=0;i<(s.length())/2;i++)
		t+="hi";
		if(t==s)
		cout<<"Yes";
		else
		cout<<"No";
	}
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n;
    cin >> n;
    ll ans = pow_mod(10,n)-pow_mod(9,n)*2+pow_mod(8,n);
    cout << (ans+mod*2)%mod << newl;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> a(N);
    double average = 0;
    rep (i, N) {
        cin >> a[i];
        average += a[i];
    }

    average /= N;

    double tmp = INF;
    ll ans = -1;
    rep (i, N) {
        if (abs(a[i]-average) < tmp) {
            tmp = abs(a[i]-average);
            ans = i;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_M = 100000;

int dp[5005][5005];




int main(int argc, char *args[]) {
	int N;
	cin >> N;
	vector<int> L;
	for (int i = 0; i < N; i++) {
		int k; 
		cin >> k;
		L.push_back(k);
	}
	sort(L.begin(), L.end());
	/*
	for (int i = 0; i < N; i++) {
		cout << L[i];
	}
	*/
	
	int counter = 0;
	while (1) {
		bool reach_end = false;
		for (int i = 1; i < L.size() - 1; i++) {
			for (int j = i + 1; j < L.size(); j++) {
				if (i == L.size() - 2 && j == L.size() - 1) reach_end = true;

				if (L[0] + L[i] > L[j]) {
					counter++;
				}else {
					break;
				}
			}
		}
		if (reach_end) {
			L.erase(L.begin());
		}
		if (L.size() < 3)break;
	}
	cout << counter << endl;
	

}

Measured memory_bytes: 384
def calcPizza(k, mai):
    return k*mai

a,b,c,x,y = [int(i) for i in input().split(' ')]
mins = min(x,y)

asum = calcPizza(a, x)
bsum = calcPizza(b, y)
absum = calcPizza(c,mins*2)
if x > mins:
    atmp= calcPizza(a,x-mins)
    abtmp= calcPizza(c,(x-mins)*2)
    absum += min(atmp,abtmp)
elif y > mins:
    btmp = calcPizza(b,y-mins)
    abtmp = calcPizza(c,(y-mins)*2)
    absum += min(btmp,abtmp)
print(min(asum+bsum, absum))

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

bool is_included(int i, vector<int> x){
  bool ret=0;
  REP(k,x.size()) if(x.at(k)==i) ret=1;
  return ret;  
}

int keta(int i){
  int k=1;
  while(pow(10,k)<=i) k++;
  return k;
}

int main(){
  int i=0,n,tmp,k,flag;
  cin>>n>>k;
  vector<int> d(k), m(5);
  REP(i,k) cin>>d.at(i);
 
  while(1){
    flag=1;
    tmp=n;
    int kt=keta(tmp);
    REP(i,kt){
      m.at(i)=tmp%10;
      tmp/=10;
    }
    REP(i,kt) if(is_included(m.at(i),d)) flag=0;
    if(flag) break;
    n++;    
  }

  cout<<n;
}

Measured memory_bytes: 256
n, k, s = map(int,input().split())

if s != int(1e9):
    anslist = [int(1e9)] * n
    for i in range(k):
        anslist[i] = s
    for i in range(len(anslist)):
        print(anslist[i])
else:
    anslist = [1] * n
    for i in range(k):
        anslist[i] = s
    for i in range(len(anslist)):
        print(anslist[i]) 

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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

string s,t;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin>>s>>t;
	t+=s;
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    cout<<(1000-n%1000)%1000;
}


Measured memory_bytes: 3648
import sys

def solve():
    S = input()
    T = input()

    ss = [0] * (len(S) + 1)

    for i in range(len(S)):
        ss[i + 1] = ss[i]
        ss[i + 1] += 1 if S[i] == 'A' else 2

    ts = [0] * (len(T) + 1)

    for i in range(len(T)):
        ts[i + 1] = ts[i]
        ts[i + 1] += 1 if T[i] == 'A' else 2

    q = int(input())

    for qry in range(q):
        a, b, c, d = map(int, sys.stdin.readline().split())
        a, c = a-1, c-1

        sc = (ss[b] - ss[a]) % 3
        tc = (ts[d] - ts[c]) % 3

        if sc == tc:
            ans = 'YES'
        else:
            ans = 'NO'

        print(ans)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 12000