akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int N,M,p[MAX+2],x[MAX+2],y[MAX+2];

//------------Union find---------------
class UnionFind{
    int par[MAX+2],rank[MAX+2];
public:
    //n要素で初期化
    UnionFind(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    //木の根を求める
    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

    //xとyの属する集合を併合
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return ;
    
        if(rank[x]<rank[y]) par[x]=y;
        else{
            par[y]=x;
            if(rank[x]) rank[x]++;
        }
    }

    //xとyが同じ集合に属するか
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

void solve(){
    UnionFind un(N);
    for(int i=0;i<M;i++) un.unite(x[i],y[i]);
    int cunt=0;
    for(int i=1;i<=N;i++){
        if(un.same(i,p[i-1])) cunt++;
    }
    cout<<cunt<<"\n";
}


int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N>>M;
    for(int i=0;i<N;i++) cin>>p[i];
    for(int i=0;i<M;i++) cin>>x[i]>>y[i];
    
    solve();
    
    
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;


int main(void)
{
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> sorted(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
        
        sorted[i] = X[i];
    }


    sort(sorted.begin(), sorted.end());

    int mid = sorted[N/2];
    int pre = sorted[N/2 - 1];

    for(int i = 0; i < N; i++){
        int x = X[i];
        int pos = lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin();
        if(pos < N/2){
            cout << mid << endl;
        } else {
            cout << pre << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 4840
n=int(input())
import sys
num2alpha = lambda c: chr(c+65).lower()

ans=[]

while True:
  n-=1
  ans.append(num2alpha(n%26))
  n=n//26
  if n<26:
    if n==0:
      break
    n-=1
    ans.append(num2alpha(n%26))
    break

for i in range(len(ans)):
  print(ans[-1-i], end='')


print()

# N=int(input())
# ans=''
# for i in range(1,99):
#   if N<=26**i:
#     N-=1
#     for j in range(i):
#       ans+=chr(ord('a')+N%26)
#       N//=26
#     break
#   else:
#     N-=26**i
# print(ans[::-1])

Measured memory_bytes: 9136
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<stack>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
//#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long


using namespace std;

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


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

const int MOD = 1e9 + 7;

long long gcd(long long x, long long y) {
	long long m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

int cumS[100010], cumT[100010];
int a[100010], b[100010], c[100010], d[100010];
signed main() {
	string S,T; cin >> S>>T;
	int Q; cin >> Q;
	REP(i, Q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	m0(cumS); m0(cumT);
	REP(i, S.length()) {
		if (S[i] == 'A') {
			cumS[i + 1] = 1;
		}
		else cumS[i + 1] = 2;
	}
	REP(i, S.length()) {
		cumS[i + 1] += cumS[i];
	}
	REP(i, T.length()) {
		if (T[i] == 'A') {
			cumT[i + 1] = 1;
		}
		else cumT[i + 1] = 2;
	}
	REP(i, T.length()) {
		cumT[i + 1] += cumT[i];
	}
	REP(i, Q) {
		int cntS = cumS[b[i]] - cumS[a[i] - 1];
		int cntT = cumT[d[i]] - cumT[c[i] - 1];
		if (cntS % 3 == cntT % 3)print("YES")
		else print("NO");
	}
}




Measured memory_bytes: 5632
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, h[100010], dp[100010];
const ll INF = 10000000000;
int main(void){
    // Your code here!
    cin >> n >> k;
    for (ll i = 0; i < n; i++) cin >> h[i];
    for (ll i = 1; i < n; i++) dp[i] = INF;
    for (ll i = 1; i < k; i++)
    {
        for (ll j = 0; j < i; j++)
        {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    for (ll i = k; i < n; i++)
    {
        for (ll j = i - k; j < i; j++)
        {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n - 1] << endl;
}


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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}


class DSU
{
public:
    vector<int>rt,sz;
    int components;
    DSU( int n )
    {
        rt.resize(n+5);
        sz.resize(n+5);
        components = n;
        for(int i=0;i<n;i++)
        {
            rt[i] = i;
            sz[i] = 1;
        }
    }
    int get_components()
    {
        return components;
    }
    int root( int x )
    {
        while( x != rt[x] )
        {
            rt[x] = rt[rt[x]];
            x = rt[x];
        }
        return x;
    }
    void connect( int x, int y )
    {
        int r1 = root(x);
        int r2 = root(y);
        if( r1 == r2 )
            return;
        if( sz[r1] < sz[r2] )
            swap(r1,r2);
        sz[r1] += sz[r2];
        rt[r2] = r1;
        components--;
    }
};


int main() 
{
    #ifdef gupta_samarth
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    int n,m;
    cin>>n>>m;
    DSU d(n);
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--,v--;
        d.connect(u,v);
    }
    cout<<d.components-1,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

int main() {
  int ok = 0;
  int n, m, c;
  cin >> n >> m >> c;
  int b[m], a[n][m];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      sum += a[i][j] * b[j];
    }
    if (sum + c > 0) {
      ok++;
    }
  }
  cout << ok << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,AZ ="abcdefghijklmnopqrstuvwxyz";
  cin >> S;
  
  vector<int> N(26);
  
  for(int i=0; i<S.size(); i++) {
    for(int j=0; j<26; j++) {
       if(S.at(i)== AZ.at(j)) N.at(j)++;
    }
  }
  
  string res = "None";
  for(int i=0; i<26; i++) {
    if(N.at(i) == 0) {
      res = {AZ.at(i)};
      break;
    }
  }
  cout << res << endl;
  
}

Measured memory_bytes: 512
let () =
    let s = read_line () in
    let rec loop i acc =
        if i < 0 then acc else loop (i - 1) ((int_of_char s.[i] - int_of_char '0') :: acc)
    in
    let (just, over) =
        loop (String.length s - 1) [] |>
        List.fold_left (fun (just, over) d ->
            min (just + d) (over + d + 1), min (just + 10 - d) (over + 9 - d)) (0, 1) 
    in
    Printf.printf "%d\n" (min just (over + 1))

Measured memory_bytes: 26372
import sys, math
sys.setrecursionlimit(10**5 + 10)

def input():
    return sys.stdin.readline()[:-1]

def main():
    S = input()
    Q = int(input())
    f = 1
    m = ""
    u = ""
    for k in range(Q):
        q = list(input().split())
        if q[0] == "1":
            f *= -1
        else:
            if f == 1:
                if q[1] == "1":
                    m = q[2] + m
                else:
                    u = u + q[2]
            else:
                if q[1] == "1":
                    u = u + q[2]
                else:
                    m = q[2] + m
    if f == 1:
        print(m+S+u)
    else:
        print(u[::-1]+S[::-1]+m[::-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 4540
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<n;i++)
using namespace std;


int main(){
	int n,l;
	cin>>n>>l;
	vector<int> a(n);
	rep(i,n){
		a[i]=l+i+1-1;
	}
	int sum=0;
	int min=abs(a[0]);
	bool flag;
	if(a[0]>=0){
		flag=true;
	}
	else{
		flag=false;
	}
	rep(i,n){
		sum+=a[i];
		if(min>abs(a[i])){
			min=abs(a[i]);
			if(a[i]>=0){
				flag=true;
			}
			else{
				flag=false;
			}
		}
	}
	int ans;
	if(flag){
		ans=sum-min;
	}
	else{
		ans=sum+min;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# GCD -- START --
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
# GCD --- END ---

# LCM -- START --
def lcm(x,y):
  return x*y//gcd(x,y)
# LCM --- END ---

def main():
  n=I()
  ans=I()

  for _ in range(n-1):
    ans=lcm(ans,I())

  return ans

# main()
print(main())


Measured memory_bytes: 6484
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for _ in range(m)]
a.sort()
b = sorted(b,key = lambda  x: x[1],reverse=True)
d = []
j = 0
while (n<=len(a) or j<m) :
    C = b[j][1]
    B = b[j][0]
    for i in range(B) :
        d.append(C)
    j += 1
    if j>=m or len(d) > len(a) :
        break

for i in range(min(len(d),len(a))) :
    if a[i] < d[i] :
        a[i] = d[i]

print(sum(a))

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> A(N);
    int maxA = 0;
    rep(i, N) {
        cin >> A[i];
        maxA = max(maxA, A[i]);
    }

    vector<int> dp(1e5 + 10);
    dp[0] = 3;
    ll ans = 1;

    rep(i, N) {
        int a = A[i];
        ans *= dp[a];
        ans %= MOD;
        dp[a]--;
        dp[a + 1]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll inf = 1LL<<59;

int N;
vector<vector<ll>> d(334, vector<ll>(334, inf));

void floyd(){
    for(int k=0; k<N; ++k){
        for(int i=0; i<N; ++i){
            if(d[i][k] == inf) continue;
            for(int j=0; j<N; ++j){
                if(d[j][k] == inf) continue;

                chmin(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    cin >> N;
    ll a[334][334];
    ll ans = 0;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            cin >> a[i][j];
            d[i][j] = a[i][j];
            ans += a[i][j];
        }
    }
    ans /= 2;

    floyd();
    bool flg = true;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(a[i][j] != d[i][j]) flg = false;
        }
    }
    if(!flg){
        cout << -1 << endl;
        return 0;
    }

    for(int i=0; i<N; ++i){
        for(int j=i+1; j<N; ++j){
            for(int w=0; w<N; w++){
                if(w == i || w == j) continue;

                if(d[i][j] == d[i][w]+d[j][w]){
                    ans -= a[i][j];
                    break;
                }
            }
        }
    }

    cout << ans << endl;
    
}


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

int main(){
    int N;
    cin >> N;
    ll L[N];
    rep(i, N) cin >> L[i];
    
    ll ans = 0;

    if (N <= 2){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0; i < N-2; i++){
        for(int j = i + 1; j < N-1; j++){
            for(int k = j + 1; k < N; k++){
                if ( (L[i] != L[j]) && (L[j] != L[k]) && (L[k] != L[i]) ){
                    if ( (L[i] + L[j] > L[k]) && (L[j] + L[k] > L[i]) && (L[k] + L[i] > L[j]) ){
                        ans++;
                    }
                }
            }
        }
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N,X,num=0;
        N =sc.nextInt();
        X = sc.nextInt();
        int [] list = new int[N];
        for(int a=0;a<N;a++){
            list[a] = sc.nextInt();
        }
        Arrays.sort(list);
        for(int a=0;a<N;a++){
            X-= list[a];
            num++;
            if(X<0) break;
            }
        for(;;){
            if(X-list[0]>=0) {
                X -= list[0];
                num++;
            }
            else break;
        }
        System.out.println(num);
    }
}

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

int main(){
    int K,A,B;
    cin >> K >> A >> B;
    if(B-A>=K-1){
        cout << "OK" << endl;
    }else{
        for(int i=A;i<=B;i++){
            if(i%K==0){
                cout << "OK" << endl;
                return 0;
            }
        }
        cout << "NG" << endl;
    }
}

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

void out(int *a, int n)
{
	for(int i = 0; i < n; ++i)
	{
		if(i != 0)
		{
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;
}

int main()
{
    int N, a[100];
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >>a[i];
	}
	
	out(a, N);
	for(int i = 1; i < N; ++i)
	{
		int key = a[i], j = i - 1;
		while(j >= 0 && a[j] >= key)
		{
			a[j + 1] = a[j];
			--j;
		}
		
		a[j + 1] = key;
		out(a, N);
	}

    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int num[5];
string s;
void solve(int idx,int curNum,vector<char> a)
{
    if(idx == 4)
    {
        if(curNum == 7)
        {
            for(int i = 0;i < a.size();i++)
                cout << a[i];
            cout << "=7";
            exit(0);
        }
        return;
    }
    a.push_back('+');
    a.push_back(s[idx]);
    solve(idx + 1,curNum + num[idx],a);
    a.pop_back();
    a.pop_back();
    a.push_back('-');
    a.push_back(s[idx]);
    solve(idx + 1,curNum - num[idx],a);
    a.pop_back();
    a.pop_back();
}
int main()
{

    cin >> s;
    for(int i = 0;i < s.length();i++)
        num[i] = (s[i] - '0');
    vector<char> temp;
    temp.push_back(s[0]);
    solve(1,num[0],temp);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5,mod=998244353;
typedef long long ll;
int n,f[1<<3];
char s[N];
int main()
{
    scanf("%d",&n);
    f[0]=n;
    scanf("%s",s+1);
    ll ans=1;
    for(int l=1;l<=n*3;l++)
    {
        int t=0;
        if(s[l]=='R') t=1;
        if(s[l]=='G') t=2;
        bool flag=true;
        for(int j=2;j>=0&&flag;j--)
        {
            for(int i=(1<<3)-1;i>=0;i--)
                if((!(1<<t&i))&&f[i]&&__builtin_popcount(i)==j)
            {
                ans=ans*f[i]%mod;
                f[i]--;
                f[i^(1<<t)]++;
                flag=false;
                break;
            }
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<math.h>
int main(){
    long long a,b,c,d, eq1=0, eq2=0, eq3=0, eq4=0;
    scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
    eq1= a*c;
    eq2= a*d;
    eq3= b*c;
    eq4= b*d;
    if(eq1>= eq2 && eq1>= eq3 && eq1>= eq4)
        printf("%lld", eq1);
    else if(eq2>= eq1 && eq2>= eq3 && eq2>= eq4)
        printf("%lld", eq2);
    else if(eq3>= eq1 && eq3>= eq2 && eq3>= eq4)
        printf("%lld", eq3);
    else if(eq4>= eq1 && eq4>= eq3 && eq4>= eq2)
        printf("%lld", eq4);
    printf("\n");
    return 0;
}

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


int main()
{
    ll n, m;
    cin>>n>>m;
    ll ans =0;
    if( n*2 < m)
    {
        ans += n;
        m = m-2*n;
        ans += m/4;
    } else
    {
        ans = m/2;
    }
    cout<<ans;
}



Measured memory_bytes: 3636
a,b,c,d=map(int,input().split())
if a%c==0:
  countc1=(a//c)-1
else:
  countc1=a//c
countc2=b//c
if a%d==0:
  countd1=(a//d)-1
else:
  countd1=a//d
countd2=b//d
def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a
e=c*d//gcd(c,d)
if a%e==0:
  counte1=(a//e)-1
else:
  counte1=a//e
counte2=b//e
print(b-a+1+countc1+countd1-counte1-countc2-countd2+counte2)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;
constexpr ll MAX = (ll)1e9;
ll s;
ll x1 = 0, x2 = MAX, y2 = 1;
ll x3, y3;

int main(void) {
	cin >> s;
	x3 = s % MAX;
	if (x3 != 0) x3 = MAX - x3;
	y3 = (s + x3) / MAX;
	cout << 0 << " " << 0 << " ";
	cout << x2 << " " << y2 << " ";
	cout << x3 << " " << y3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  size_t N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N);
  for(auto& i : A) cin >> i;
  vector<ll> F(N);
  for(auto& i : F) cin >> i;

  boost::sort(A, std::greater<ll>());
  boost::sort(F);

  using Pair = pair<ll, ll>;
  vector<Pair> cost(N);
  for (size_t i = 0; i < N; ++i) {
    cost[i].first = A[i] * F[i];
    cost[i].second = F[i];
  }

  ll min = -1;
  ll max = boost::max_element(cost)->first;
  ll itr{};
  while ((max - min) != 1) {
    itr = (min + max) / 2;
    ll cnt{};
    for (size_t i = 0; i < N; ++i) {
      ll res = (cost[i].first - itr + (cost[i].second - 1)) / cost[i].second;
      cnt += std::max((ll)0, res);
    }
    if (cnt <= K)
      max = itr;
    else
      min = itr;
  }

  auto ans = max;
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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






int main(){

  
  int n,k;
  cin>>n>>k;
  
  vector<int> height(n);
  
  for (int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    height.at(i)=tmp;
  }
  
  sort(height.begin(),height.end());
  
  int dis=-1;
  
  for (int i=0;i<=n-k;i++){
    int tmp;
    tmp=height.at(i+k-1)-height.at(i);
    
    if (dis==-1){
      dis=tmp;
    }
    else {
      dis=min(dis,tmp);
    }
  }
  
  cout<<dis<<endl;
  

        
}

Measured memory_bytes: 640
N,M = map(int,input().split())

import math
G=[]
for i in range(1,int(math.sqrt(M))+2+1):
    if M%i == 0:
        cd = M//i
        G.append(cd)
        G.append(i)

G.sort(reverse=True)
for g in G:
    n = M//g
    if n>=N:
        print(g)
        exit()









Measured memory_bytes: 9068
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int K = s.nextInt();
		int d = 0;
		boolean[] have = new boolean[N];
		for(int i = 0; i < K;i++) {
			d = s.nextInt();
			for(int j = 0; j < d; j++) {
				have[s.nextInt() - 1] = true;
			}
		}
		
		int counter = 0;
		for(boolean b : have) {
			if(b)
				continue;
			counter++;
		}
		
		System.out.println(counter);
    }
}

Measured memory_bytes: 46312
#include <iostream>
#include <string>

int main(int argc, char *argv[]) {
  long a;
  std::string b;
  std::cin >> a >> b;
  b.replace(1, 1, "");
  long bb = std::stoi(b);
  std::cout << (a * bb) / 100 << std::endl;
}


Measured memory_bytes: 3228
s = int(input())
lis = [s]
 
while len(lis) == len(set(lis)):
  if lis[-1] % 2 == 0:
    lis.append(lis[-1] / 2)
  else:
    lis.append(3 * lis[-1] + 1)
    
print(len(lis))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

    int X = scanner.nextInt();

    if ( X == 1 ) {
      System.out.println(1);
      System.exit(0);
    }

    int max = 0;
    for (int i = 2; i <= X; i++) {
      for ( int j = 2; j <= 1000; j++ ) {
          int b = (int)Math.pow((int)i, (int)j);
          if ( b > X) {
            break;
          }
          if ( b > max ) {
            max = b;
          }
      }
    }
    System.out.println(max);
  }

}


Measured memory_bytes: 23764
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner Input = new Scanner(System.in);
        int N = Input.nextInt();
        ArrayList<Integer> A = new ArrayList();
        for (int I = 0; I < N; I++) {
            A.add(Input.nextInt());
        }
        Collections.sort(A, Collections.reverseOrder());
        int Sum = 0;
        for (int I = 0; I < A.size(); I++) {
            if (I % 2 == 0) {
                Sum += A.get(I);
            } else {
                Sum -= A.get(I);
            }
        }
        System.out.println(Sum);
    }

}


Measured memory_bytes: 21972
h,w = map(int,input().split())

a1 = ["#"]*(w+2)
x = [0]*h
for i in range(0,h):
  x[i] = input().split()

a1 = ''.join(a1)

print(a1)
for i in range(0,h):
  x[i] = ''.join(x[i])
  print("#"+x[i]+"#")
print(a1)

Measured memory_bytes: 38256
#include<stdio.h>
int main()
{
	int n,s,m;
	scanf("%d%d",&n,&s);
	if(n>=10)
	{
		printf("%d\n",s);
	}
	else
	{
		printf("%d\n",s+(100*(10-n)));
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {
        int n = sc.nextInt();
        int k = sc.nextInt();

        System.out.println((n-1)*(k-1));



    }

}

Measured memory_bytes: 20560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int N,M;
bool visited[100100];
int dp[100100]={0};
vector<int> G[100100],v;

void dfs(int s){
  visited[s]=1;
  for(int i=0;i<G[s].size();i++){
    if(!visited[G[s][i]]){
      dfs(G[s][i]);
    }
  }
  v.push_back(s);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  int x,y;
  for(int i=0;i<M;i++){
    cin >> x >>y;
    x--;
    y--;
    G[x].push_back(y);
  }

  for(int i=0;i<N;i++){
    if(!visited[i]){
      dfs(i);
    }
  }
  reverse(v.begin(),v.end());

 int ans=0;
 for(int i=0;i<N;i++){
   for(int j=0;j<G[v[i]].size();j++){
     dp[G[v[i]][j]]=max(dp[G[v[i]][j]],dp[v[i]]+1);
   }
   ans=max(ans,dp[v[i]]);
 }
 cout << ans << endl;
 return 0;
}


Measured memory_bytes: 8056
n,k=map(int,input().split())
s,p,r=map(int,input().split()) #筐体の手に対する勝利ポイント
t=list(input())
ans=0
for i in range(n):
    if t[i]=="s":
        tmp=s
    elif t[i]=="p":
        tmp=p
    else:
        tmp=r
    if i>=k:
        if t[i]==t[i-k]:
            tmp=0
            t[i]=None
    ans+=tmp
print(ans)

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

bool is_prime(ll n){
	if(n==1)return false;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return true;
}
vector<ll>divisor(ll n){
	vector<ll>res;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i)res.push_back(n/i);
		}
	}
	return res;
}
map<ll,int>prime_factor(ll n){
	map<ll,int>res;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n/=i;
		}
	}
	if(n!=1)res[n]++;
	return res;
}
vector<ll>prime_enum(int n){
	vector<bool>is_prime(n+1,true);
	is_prime[0]=is_prime[1]=false;
	vector<ll>res;
	for(int i=2;i<=n;i++){
		if(!is_prime[i])continue;
		res.push_back(i);
		for(int j=2*i;j<=n;j+=i){
			is_prime[j]=false;
		}
	}
	return res;
}
set<ll>se;

void solve(ll N,ll n){
	auto v=divisor(N);
	for(ll k:v){
		if(k==1)continue;
		ll d=n;
		while(d>=k){
			if(d%k==0)d/=k;
			else break;
		}
		d%=k;
		if(d==1){
			se.insert(k);
		}
	}
}

int main(){
	ll n;cin>>n;
	solve(n,n);
	solve(n-1,n);
	cout<<se.size()<<endl;
	//~ for(ll n=1;n<=10000;n++){
		//~ cout<<"-----------  "<<n<<"  -----"<<endl;
		//~ int cnt=0;
		//~ for(ll k=2;k<=n;k++){
			//~ ll d=n;
			//~ while(d>=k){
				//~ if(d%k==0)d/=k;
				//~ else d-=k;
			//~ }
			//~ if(d==1){
				//~ if(n%k!=0&&(n-1)%k!=0){
					//~ abort();
				//~ }
				//~ cout<<k<<endl;
			//~ }
			//~ cout<<k<<' '<<d<<endl;
		//~ }
		//~ cout<<cnt<<",";
	//~ }
}

Measured memory_bytes: 384
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node *link;
typedef struct process proc;
typedef proc Item;
struct process {
    char name[11];
    int time;
};
struct node {
    Item item;
    link next;
};
static link head, tail;

void Queueinit (int maxN) { head = NULL; }
int Queueenpty (void) { return head == NULL; }
Item Queueget (void) {
    Item item = head->item;
    link t = head->next;
    free(head);
    head = t;
    return item;
}
link NEW(Item item, link next) {
    link x = malloc(sizeof * x);
    x->item = item;
    x->next = next;
    return x;
}
void Queueput (Item item) {
    if (head == NULL) {
        head = (tail = NEW(item, head));
        return;
    }
    tail->next = NEW(item, tail->next);
    tail = tail->next;
}

int main(void) {
    int n, q, time, i, clock = 0;
    char name[11];
    Item pr;
    Queueinit(1000);
    scanf("%d %d[^\n]", &n, &q);
    if (n < 1 || n > 100000) return -1;
    if (q < 1 || q > 1000) return -1;
    i = 0;
    while (i < n) {
        scanf("%10s %d[^\n]", name, &time);
        pr.time = time;
        strcpy(pr.name, name);
        Queueput(pr);
        i++;
    }
    while (!Queueenpty()) {
        pr = Queueget();
        if (pr.time > q) {
            clock += q;
            pr.time = pr.time - q;
            Queueput(pr);
        } else {
            clock += pr.time;
            printf("%s %d\n", pr.name, clock);
        }
    }
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> d(n);
  REP(i,n)cin >> d[i];
  sort(ALL(d));
  ANS(max<int32>(0,d[n/2] - d[n/2-1]));
  return 0;
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7
INF = float('inf')

def main():
    S = input()
    T = input()
    L = len(S)
    bl = False
    for i in range(L):
        s = S[-i:] + S[:-i]
        if T == s:
            bl = True
    print('Yes' if bl else 'No')





if __name__ == '__main__':
    main()

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

int main(){
  int N;
  cin>>N;
  vector<int> s(N);
  for(int i=0;i<N;i++){
    cin>>s.at(i);
  }
  sort(s.begin(),s.end());
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=s.at(i);
  }
  if(sum%10==0){
    for(int i=0;i<N;i++){
      if(s.at(i)%10!=0){
        sum-=s.at(i);
        break;
      }
      if(i==N-1){
        sum=0;
        break;
      }
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <cstring>
#include <queue>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

template <typename T>
struct LazzySegTreeSum
{
  private:
    ll N = 1;
    vector<T> node,lazy;

  public:
    LazzySegTreeSum(vector<T> vec)
    {
        ll size = vec.size();

        while (N < size)
        {
            N *= 2;
        }

        node.resize(2 * N - 1, -iINF);
        lazy.resize(2 * N - 1, 0);

        REP(i, size)
        {
            node[i + N - 1] = vec[i];
        }

        for (int i = N - 2; 0 <= i; i--)
        {
            node[i] = node[2 * i + 1] + node[2 * i + 2];
        }
    }

    void eval(int k, int l, int r)
    {
        if(lazy[k] != 0)
        {
            node[k] += lazy[k];

            if(r - l > 1)
            {
                lazy[2 * k + 1] += lazy[k] / 2;
                lazy[2 * k + 2] += lazy[k] / 2;
            }
        }

        lazy[k] = 0;
    }

    void add(int a, int b, T value, int k = 0, int l = 0, int r = -1)
    {
        if(r < 0) r = N;

        eval(k, l, r);

        if(b <= l || r <= a) return;

        if(a <= l && r <= b) 
        {
            lazy[k] += (r - l) * value;
            eval(k, l, r);
        }
        else
        {
            add(a, b, value, 2 * k + 1, l, (l + r) / 2);
            add(a, b, value, 2 * k + 2, (l + r) / 2, r);

            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

   T getSum(int a, int b, int k = 0, int l = 0, int r = -1)
   {
       if(r < 0) r = N;

       eval(k, l, r);

       if(b <= l || r <= a) return 0;
       if(a <= l && r <= b) return node[k];

       ll vl = getSum(a, b, 2 * k + 1, l, (l + r) / 2);
       ll vr = getSum(a, b, 2 * k + 2, (l + r) / 2, r);

       return vl + vr;
   }
};

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

    int N, Q;
    cin >> N >> Q;

    LazzySegTreeSum<ll> seg(vector<ll> (N, 0));

    REP(i, Q)
    {
        int com, s, t;
        cin >> com >> s >> t;

        if(com == 0)
        {
            int x;
            cin >> x;

            seg.add(s - 1, t, x);
        }
        else
        {
            Cout(seg.getSum(s - 1, t));
        }
    }
    

    return 0;
}


Measured memory_bytes: 7840
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

pub struct UnionFind {
    pub parents: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> Self {
        let parents = (0..n).collect();
        UnionFind { parents }
    }
    pub fn root(&mut self, x: usize) -> usize {
        if self.parents[x] == x {
            return x;
        }
        let par = self.parents[x];
        self.parents[x] = self.root(par);
        self.parents[x]
    }
    pub fn union(&mut self, x: usize, y: usize) {
        let rx = self.root(x);
        let ry = self.root(y);
        if rx == ry {
            return;
        }
        self.parents[rx] = ry;
    }
    pub fn is_same(&mut self, x: usize, y: usize) -> bool {
        let rx = self.root(x);
        let ry = self.root(y);
        rx == ry
    }
}

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize);
    let mut uf = UnionFind::new(n);
    for _ in 0..m {
        parse!(it, a: u1, b: u1);
        uf.union(a, b)
    }
    let mut s = HashMap::new();
    for i in 0..n {
        *s.entry(uf.root(i)).or_insert(0usize) += 1;
    }
    let mut ret = 0;
    for (k, v) in &s {
        ret.chmax(*v);
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 12336
#include <stdio.h>


void sort1(int data[], int n){
    int i, j, x, y;
    for(i = 1; i < n; i++){
        x = data[i];
        for(j = i - 1; j >= 0; j--){
            y = data[j];
            if(y > x)
                data[j+1] = y;
            else {
                data[j+1] = x;
                break;
            }
        }
        if(j == -1) data[0] = x;
    }
}


int main(void) {
    int n, count = 0;
    scanf("%d", &n);
    int d[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &d[i]);
    }
    sort1(d, n);
    for(int i = d[n/2-1]+1; i <= d[n/2]; i++) {
        count++;
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文
int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	ansYes(a[0] + a[1] == a[2]);
}

Measured memory_bytes: 256
# include <iostream>
# include <iomanip>
using namespace std;
int N;
double ans = 0.0, A;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    ans += 1.0 / A;
  }
  
  ans = 1.0 / ans;
  
  cout << setprecision(16) << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    
    string s;
    cin >> s;
    ll g = 0, p = 0, ans = 0;
    rep(i, s.size()){
        if(s[i] == 'g'){
            if(p < g){
                ans++;
                p++;
            }
            else g++;
        }
        else{
            if(p < g)p++;
            else{
                g++;
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <chrono>
#include <set>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;
typedef long long int64;
typedef unsigned long long ll;
#define fi first
#define se second

#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vec vector<int> 
#define lvec vector<ll>
#define dvec vector<double>
#define Mem(x) memset(x,0,sizeof(x));

#define rFor(i,a,b) for(int i=(a);i>(b);--i)
#define For(...)  GET_MACRO(_0,##__VA_ARGS__,For3,For2,For1,For0)(__VA_ARGS__)
#define foronce for(static int __ = 0; __ < 1;++__)
#define forall(i, s) foreach(i,begin(s),end(s))
#define foreach(i, a, b) for(auto i = (a);i!=(b) ;++i)
#define foreachn(i, a, n) for(auto i = (a),_=next(a,n);i!=_;++i)
#define For3(i,a,b) for(int i=(a);i<(b);++i)
#define For2(i,a) for(int i=0;i<(a);++i)
#define For1(a) For2(_,a)
#define For0()	

#define in(x) scanf("%d",&(x));
#define put(x) cout<<(x)<<endl;
#define GET_MACRO(_0,_1,_2,_3,_NAME,...) _NAME
#ifndef ONLINE_JUDGE
	#define out0()
	#define out1(x) {cout<<" ";cout.width(5);cout<<(x);}
	#define out2(x,y) {out1(x)out1(y)}
	#define out3(x,y,z) {out2(x,y)out1(z)}
	#define outset(x) for(auto i : x) out1(i) //std::size()
	#define outarr1(x,fir) foreachn(_iter,begin(x),fir) out1(*_iter)
	#define outarr2(x,fir,sec) for(auto iter2=begin(x);iter2!=begin(x)+fir;++iter2){ outarr1((*iter2),sec)out()}
	#define out(...) {cout<<#__VA_ARGS__<<" ";GET_MACRO(_0,##__VA_ARGS__,out3,out2,out1,out0)(__VA_ARGS__);cout<<endl;}
	#define outa(...)  {cout<<#__VA_ARGS__;out()GET_MACRO(""##__VA_ARGS__,UNUSED,outarr2,outarr1,outset)(__VA_ARGS__)out()}
#endif // ONLINE_JUDGE

const double eps = 1e9;
int mod = 222;

template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
#define lcm(a,b) ((ll)(a)/gcd(a,b)*(b))
inline ll powmod(ll a,ll b) {ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

#include<unordered_set>

int R;

int main(){
    string s;
    cin>>s;
    int flag=0,chance =0;
    if(s[0]=='A'){
        For(i,1,s.size()){
            if(isupper(s[i])&&s[i]!='C'){
                flag=1;
            }
            if(s[i]=='C'){
                chance++;
                if(i==1||i==s.size()-1) flag=1;
            }
        }
    }else{
        flag=1;
    }
    if(chance!=1) flag=1;
    if(flag==1) puts("WA");else puts("AC");

}


Measured memory_bytes: 256
#include<stdio.h>
char a[1000000];
int main()
{
	int n,i;
	scanf("%d",&n);
	scanf("%s",&a);
	int sum=0;
	for(i=0;i<n-1;i++)
	{
	if(a[i]!=a[i+1]) sum++;
	}
	printf("%d",sum+1);
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BYYMMOrMMYY {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            if (Integer.parseInt(x.substring(0, 2)) <= 12 && Integer.parseInt(x.substring(2)) > 0 && Integer.parseInt(x.substring(2)) <= 12 && Integer.parseInt(x.substring(0, 2)) > 0) {
                out.println("AMBIGUOUS");
            } else if (Integer.parseInt(x.substring(0, 2)) <= 12 && Integer.parseInt(x.substring(0, 2)) > 0) {
                out.println("MMYY");
            } else if (Integer.parseInt(x.substring(2)) <= 12 && Integer.parseInt(x.substring(2)) > 0) {
                out.println("YYMM");
            } else {
                out.println("NA");
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21460
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char s[10], t[10];
  int ans = 0;
  scanf("%s%s", s, t);
  for (int i = 0; i < strlen(s); i++)
  {
    if (s[i] == t[i])
      ans++;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128