akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


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



int main() {
	
	int n;
	cin >> n;
	REP(i, n) {
		char c;
		cin >> c;
		if (c == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}

	cout << "Three" << endl;


	return 0;
}



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

using namespace std;
int mod=1e9+7;
map<int,int> fre;
void cal(int s)
{
    for (int i = 2; i*i <=s ; ++i) {
        while (s%i==0)
        {
            fre[i]++;
            s/=i;
        }
    }
    if(s!=1)
        fre[s]++;

}

int fac(int a)
{
    int z=1;
    for (int i = 1; i <=a ; ++i) {
        z=(z*i)%mod;
    }
    return z;
}

int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        // q is quotient
        int q = a / m;
        int t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

int comb(int a,int b)
{
    if(a<b)
        return 0;
    else
    {
        int z=fac(a);
        int z2=(fac(a-b)*fac(b))%mod;
        z2=modInverse(z2,mod);
        z=(z*z2)%mod;
        return z;
    }

}


signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,m;
    cin>>n>>m;

    cal(m);
    int ans=1;
    for(auto i:fre)
    {
        ans=(ans*comb(i.second+n-1,i.second))%mod;
    }

    cout<<ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
#define INF 1e10

using namespace std;
 
struct Item{
    ll w, v;
};
 
int main() {
    ios
    string a, b;
    cin>>a>>b;
    ll m=a.size(), n=b.size();
    vector <vector<ll>> dp(m+1, vector<ll>(n+1));
    repi(i, m+1){
        repi(j, n+1){
            if(i==0 || j==0) dp[i][j] = 0;
            else if(a[i-1]==b[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string ans = "";
    ll i, j;
    i = m;
    j = n;
    while(i>0 and j>0){
        if(a[i-1]==b[j-1]) {
            ans = a[i-1] + ans;
            i--; j--;
        }
        else{
            if(dp[i-1][j] >= dp[i][j-1]) i--;
            else j--;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 74136
#include <stdio.h>

int solve(int,int);
int n;
int A[21];

int main(void){
  int q,i,j;
  int M[201];
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&M[i]);
  }
  for(i = 0 ; i < q ; i++){  
    if(solve(0,M[i])){
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
  }
  return 0;
}

int solve(int p,int t)
{
  int r,s;

  if(t < 0) return 0;
  if(t == 0) return 1; 
  if(p == n)return 0;
  r=solve(p+1,t);
  s=solve(p+1,t-A[p]);
  if(r==1 || s==1) return 1;
  else return 0;
}

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

int main()
{
  int n, k; cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  
  vector<ll> at(n+1); at[0] = 0;
  for (int i = 1; i < n+1; ++i) at[i] = at[i-1] + a[i-1];
  
  int m = n*(n+1)/2;
  vector<ll> b(m);
  int idx = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i+1; j < n+1; ++j)
      b[idx++] = at[j] - at[i];
  
  vector<bool> cand(m, true);
  ll dig = 1ll << 39;
  ll max_a = 0;
  while (dig)
  {
    int count = 0;
    for (int i = 0; i < m; ++i)
      if (cand[i] && dig & b[i]) ++count;
    if (count >= k)
    {
      max_a |= dig;
      for (int i = 0; i < m; ++i)
        if (!(dig & b[i])) cand[i] = false;
    }
    
    dig >>= 1;
  }
  
  cout << max_a << endl;
}

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

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

	for(int i = 0; i <s.size();i++){
		if(s[i] == '0') res.push_back('0');
		if(s[i] == '1') res.push_back('1'); 
		if(s[i] == 'B' && res.size() != 0) res.pop_back();  
	}

	cout<<res<<"\n";
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()
const ll INF=1e18;
const double PI=4*atan(1);

#define SpeedForce                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base,ll exp);
void solve();
ll POW(ll base,ll exp);
ll gcd(ll a,ll b);

ll modInverse(ll n) { 
    return mpow(n, mod-2); 
}
 
ll nCr(ll n, ll r){ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%mod; 
    return ((fac[r]%mod)*(fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod)*(fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod) % mod)%mod; 
}

int32_t main(){
    SpeedForce
    ll i = 0,j = 0;

    int t;
    t=1;
    //cin >> t;
    while (t--){
        //cout << fixed << setprecision(10);
        solve();
    }
}



void solve(){
    ll n;
    cin >> n;
    ll a[n];
    map<ll,ll> mp;
    ll s=0;
    loop(i,0,n){
        cin >> a[i];
        s+=a[i];
        mp[a[i]]++;
    }

    ll q;
    cin >> q;
    while(q--){
        ll b,c;
        cin >> b >> c;

        ll cur=mp[b];
        mp[c]+=cur;
        mp[b]=0;
        s+=(cur*c-cur*b);
        cout<< s << endl;

    }

}

ll POW(ll base,ll exp){
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base);
        base = ((ll)base * base);
        exp >>= 1;
    }
    return result;
}

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

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

Measured memory_bytes: 10284
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n, m;
  std::cin >> n;
  std::map<std::string, int> st;
  rep(i,n) {
    std::string s;
    std::cin >> s;
    ++st[s];
  }

  std::cin >> m;
  rep(i,m){
    std::string t;
    std::cin >> t;
    --st[t];
  }

  int max = 0;
  for(auto& x : st) {
    if(x.second > max)
      max = x.second;
  }

  std::cout << max << '\n';
  return 0;
}


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

typedef int in;
#define int long long
int MAX=1e9;
int MAXEST=1e18;
int MOD=1e9+7;

int n,k;
int a[105];
int dp[105][100005];

in main()
{
    int tc=1;
//    cin>>tc>>st;
    while(tc--)
    {
        cin>>n>>k;
        for(int i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        dp[0][0]=1;
        for(int i=1; i<=n; i++)
        {
            for(int j=0; j<=k; j++)
            {
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=MOD;
                if(j)
                {
                    dp[i][j]+=dp[i][j-1];
                    dp[i][j]%=MOD;
                }
                if(j-a[i]-1>=0){
                    dp[i][j]+=MOD;
                    dp[i][j]-=dp[i-1][j-a[i]-1];
                    dp[i][j]%=MOD;
                }
            }
        }
        cout<<dp[n][k]<<endl;
    }
    return 0;
}


Measured memory_bytes: 81676
x = int(input())
if x <= 599:
    print(8)
elif x <= 799:
    print(7)
elif x <= 999:
    print(6)
elif x <= 1199:
    print(5)
elif x <= 1399:
    print(4)
elif x <= 1599:
    print(3)
elif x <= 1799:
    print(2)
else:
    print(1)


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

using namespace std;

int main() {
	int h,w;

	cin >> h >> w;

	int xpos = 0;

	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < xpos; j++) {
			if (s.at(j) == '#') {
				cout << "Impossible" << endl;
				return 0;
			}
		}
		if (s.at(xpos) == '.') {
			cout << "Impossible" << endl;
			return 0;
		}
		while(xpos + 1 < w && s.at(xpos+1) == '#') {
			xpos++;
		}
		for (int j = xpos + 1; j < w; j++) {
			if (s.at(j) == '#') {
				cout << "Impossible" << endl;
				return 0;
			}
		}

	}
	if (xpos != w - 1) {
		cout << "Impossible" << endl;
		return 0;
	} 
	cout << "Possible" << endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include <iostream>
#include<stdlib.h>
//#include <algorithm>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
struct DSU{
  int num;
  ll size;
};
DSU *par;//親の番号
//n要素で初期化
void init(int n){
  rep(i,n){
    par[i].num=i;
    par[i].size=1;
  }
  return;
}
//木の根を求める
ll root(ll x){
  if(par[x].num==x){
    return x;
  }else{
    ll r = root(par[x].num);
    par[x].num=r;
    return r;//経路圧縮
  }
}

//x,yが同じ集合に属するか否か
bool same(ll x,ll y){
  if(root(x)==root(y)){
    return true;
  }else{
    return false;
  }
}
//x,yの属する集合を併合
void unite(ll x,ll y){
  if(same(x,y)==true){
    return;
  }
  par[root(x)].size+=par[root(y)].size;
  par[root(y)].size=par[root(x)].size;
  par[root(y)].num=root(x);
  return;
}
ll size(ll x){
  ll sum = par[root(x)].size;
  return sum;
}
int main(void){
	ll N,M;
  cin >> N >> M;
  par = (DSU*)malloc(sizeof(DSU)*N);
  init(N);
  ll ans[M+1];
  ll Na=1;
  ll Nb=1;
  ll a[M],b[M];
  rep(i,M){
    cin >> a[i] >> b[i];
    a[i]-=1;
    b[i]-=1;
  }
  ans[M]=(N*(N-1))/2;
  for(int i=M-1;i>=1;i--){
    if(same(a[i],b[i])==true){
      Na=0;Nb=0;
      //cout << "same";
      ans[i]=ans[i+1];
      continue;
    }
    Na=size(a[i]);
    Nb=size(b[i]);
      //cout << size(a[i],N) << " " << size(b[i],N) << endl;
      unite(a[i],b[i]);
    ans[i]=ans[i+1]-(ll)(Na*Nb);
  }
  for(int i=0;i<M;i++){
    cout << ans[i+1] << endl;
  }
	return 0;
}

Measured memory_bytes: 5248
x,y=map(int,input().split())
a=(2*y-x)/3
b=(2*x-y)/3
c=(x+y)/3
mod=10**9+7
MOD=10**9+7
def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD        
        ret = ret * pow(i, MOD - 2, MOD) % MOD
        
    return ret


  
if (x+y)%3!=0:
  print(0)
elif a<0 or b<0:
  print(0)
else:
  print(int(comb(int(c), int(a))))

Measured memory_bytes: 3064
//Author : Gaara

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

#define ll long long
#define pb push_back
#define endl "\n"
#define fo(i,n) for(ll i=0;i<n;i++)
#define ro(i,n) for(ll j=n-1;i>=0;i--)
#define vll vector<long long>
#define MAX 200000

vector<vector<int>> adj(MAX+1);
bool visited[MAX+1] = {false};
int cnt=0;

void dfs(int s){
	cnt++;
	visited[s] = true;
	for(auto u:adj[s]){
		if(visited[u]) continue;
		dfs(u);
	}
	return;
}

int main(){
    int t=1;
    //cin>>t;
    while(t--){
		int n,m; cin>>n>>m;
		int x,y;
		fo(i,m){
			cin>>x>>y;
			adj[x].pb(y);
			adj[y].pb(x);
		}
		
		int ans = 0, prev=0;
		for(int i=1;i<=n;i++){
			if(visited[i]) continue;
			
			cnt=0;
			dfs(i); 
			ans = max(ans,cnt);
		}
		cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 20588
#include <cstdio>
#include <cstring>
using namespace std;
int a[120];
int cost[240];
int main()
{
	int n;
	while ( ~scanf ( "%d", &n ) )
	{
		memset ( cost, 0, sizeof ( cost ) );
		int maxa = 120, mina = -120;
		for ( int i = 0; i < n; i++ )
		{
			scanf ( "%d", a + i );
			if ( a[i] > maxa )
				maxa = a[i];
			if ( a[i] < mina )
				mina = a[i];
		}
		int p = maxa - mina;
		for ( int i = 0; i < p; i++ )
		{
			for ( int j = 0; j < n; j++ )
				cost[i] += ( a[j] - i - mina ) * ( a[j] - i - mina );
		}
		int ans = cost[0];
		for ( int i = 0; i < p; i++ )
		{
			if ( cost[i] < ans )
				ans = cost[i];
		}
		printf ( "%d\n", ans );
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

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

  for (int _ = 0; _ < M; _++) {
    int s, c;
    cin >> s >> c;
    if (ss[s - 1] != -1 && ss[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    ss[s - 1] = c;
  }

  if (N > 1) {
    if (ss[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << (ss[0] == -1 ? 1 : ss[0]);
    for (int i = 1; i < N; i++) { cout << (ss[i] == -1 ? 0 : ss[i]); }
  } else {
    cout << (ss[0] == -1 ? 0 : ss[0]);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
/*
 *  Author: sleepify
 */
#include <bits/stdc++.h>
// #include "prettyprint.h"
using namespace std;

#define LOG(x) cerr << "*** " << x << " ***" << endl;
#define wi(x) what_is(x, '\n')
#define wisp(x) what_is(x, ", ")
#define what_is(x, terminator) cerr << #x << " = " << x << terminator;

#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define REV_ALL(x) x.rbegin(), x.rend()
#define SZ(x) (int)x.size()
#define CONTAINS(cont, val) (cont.find(val) != cont.end())
#define endl '\n'
#define IO_SPEED_UP ios::sync_with_stdio(false);cin.tie(NULL)
#define FOR(i, s, e) for(ll i = s; i < e; i++)
#define leftmost_set(x) __builtin_clzll(x)
#define TWO_POWER(n) (1LL << (n))

// When root of a binary tree is 1
#define PARENT(n) ((n) >> 1LL)
#define LCHILD(n) ((n) << 1LL)
#define RCHILD(n) (((n) << 1LL) + 1LL)

typedef long long ll;typedef pair<ll, ll> ii;
typedef vector<ll> vi;typedef vector<bool> vb;
typedef vector<ii> vii;typedef vector<vi> vvi;

const int INF32 = 1E9;
const long long INF64 = 4E18;
const ll M = 1E9 + 7;
const double EPS = 1E-9;
const double PI = 2 * acos(0);

template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}

int main() {
	IO_SPEED_UP; // Turn Off for Interactive Problems
	if(fopen("tupni.txt", "r")) {
		freopen("tupni.txt", "r", stdin);
		freopen("tuptuo.txt", "w", stdout);
	}
	int n, a, b; cin >> n >> a >> b;
	if(abs(b - a - 1) % 2 == 1) {
		cout << "Alice";
	} else {
		cout << "Borys";
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 2e5+10;

int n,c[N],f[N],top,head[N],ans[N];
struct zjz{
	int next,to;
}a[N << 1];

inline void add(int fr,int t){
	a[++top].to = t;
	a[top].next = head[fr];
	head[fr] = top;
	a[++top].to = fr;
	a[top].next = head[t];
	head[t] = top;
}

inline void dfs(int x,int fa){
	int *t = lower_bound(f,f+n+1,c[x]) , v = *t;
	*t = c[x] , ans[x] = lower_bound(f,f+n+1,0x7f7f7f7f)-f;
	for(int i=head[x];i != -1;i = a[i].next)
		if(a[i].to != fa)
			dfs(a[i].to,x);
	*t = v;
}

int main()
{
	memset(head,-1,sizeof(head));
	memset(f,0x7f,sizeof(f));
	int fr,t;
	scanf("%d",&n);
	for(int i=1;i <= n;i++) scanf("%d",&c[i]);
	for(int i=1;i < n;i++) scanf("%d%d",&fr,&t) , add(fr,t);
	dfs(1,0);
	for(int i=1;i <= n;i++) printf("%d\n",ans[i]);
	return 0;
} 

Measured memory_bytes: 21520
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;
    string s;
    cin >> s;
    int cur=0,ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'A' or s[i] == 'G' or s[i] == 'C' or s[i] == 'T')
            cur++;
        else{
            ans = max(ans,cur);
            cur = 0;
        }
    }
    ans = max(ans,cur);

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		int loo = inputs.nextInt();
		int k = inputs.nextInt();
		int[] f = new int[loo];
		for(int i=0;i<loo;i++) {
			f[i] = inputs.nextInt();
		}
		Arrays.sort(f);
		int ans = 0;
		for(int i=0;i<k;i++) {
			ans+=f[i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 38728
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

uf = UnionFind(N+1)
for ab in AB:
    uf.union(ab[0], ab[1])

print(uf.group_count() - 1 - 1) # [0]を除いたグループの数 - 1

Measured memory_bytes: 28536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

int main(){
    ll n;cin>>n;
    ll a[n][n];rep(i,0,n-1)rep(j,0,n-1)cin>>a[i][j];
    ll dp[1<<n];
    rep(i,0,(1<<n)-1){
        ll v[n];ll s=0;
        rep(j,0,n-1)if((i>>j)&1){v[s]=j;s++;}
        ll sum=0;
        rep(j,0,s-1){
            rep(k,j,s-1){
                sum+=a[v[j]][v[k]];
            }
        }
        dp[i]=sum;
    }
    rep(i,0,(1<<n)-1){
        ll v[n];ll c=0;
        rep(j,0,n-1)if((i>>j)&1){v[c]=j;c++;}
        rep(j,1,(1<<c)-2){
            ll sx=0,sy=0;
            rep(k,0,c-1){
                if((j>>k)&1){
                    sx+=1<<v[k];
                }else{
                    sy+=1<<v[k];
                }
            }
            ll sum=dp[sx]+dp[sy];
            Max(&dp[i],sum);
        }
    }
    //rep(i,0,(1<<n)-1)cout<<dp[i]<<" ";cout<<endl;
    cout<<dp[(1<<n)-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 768
from collections import Counter

class Union_Find:

    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.height = [0 for i in range(n)]
        self.size = [1 for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def getsize(self, x):
        return self.size[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.height[x] < self.height[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = self.par[x]
            self.size[x] += self.size[y]
            if self.height[x] == self.height[x]:
                self.height[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, K, L = map(int, input().split())
uf0 = Union_Find(N+1)
for i in range(K):
    x, y = map(int, input().split())
    uf0.union(x, y)
uf1 = Union_Find(N+1)
for i in range(L):
    x, y = map(int, input().split())
    uf1.union(x, y)
types = [None] * (N+1)
for i in range(1, N+1):
    types[i] = (uf0.find(i), uf1.find(i))
C = Counter(types)
ans = [None] * (N+1)
for i in range(1, N+1):
    ans[i] = C[types[i]]
print(*ans[1:])


Measured memory_bytes: 62068
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  rep(i, n+1)rep(j, m+1){
    int ans = i*m;
    ans += j*n;
    ans -= 2*i*j;
    if(ans == k){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3548
import math
K=int(input())
dp=[[0][0]]*K
sum_gcd=0
c=1
for a in range(1,K+1):
    for b in  range(1,K+1):
            for c in  range(1,K+1):
                sum_gcd+=math.gcd(c,math.gcd(a,b))
print(sum_gcd)

Measured memory_bytes: 81020
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int N;
    cin >> N;
    ll a[N], b[N], c[N];
    rep(i, 0, N) cin >> a[i] >> b[i] >> c[i];
    ll dp[N + 1][3];
    rep(i, 0, N + 1) rep(j, 0, 3) dp[i][j] = 0ll;
    rep(j, 0, 3) dp[0][j] = 0;

    rep(i, 0, N) {
        rep(j, 0, 3) {
            if(j == 0) {
                dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][1] + a[i], dp[i][2] + a[i]));
            } else if(j == 1) {
                dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][0] + b[i], dp[i][2] + b[i]));
            } else if(j == 2) {
                dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][0] + c[i], dp[i][1] + c[i]));
            }
        }
    }

    ll rsl = 0;
    rep(j, 0, 3) rsl = max(rsl, dp[N][j]);
    cout << rsl << endl;
}


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

int main() {
    int N;
    int d[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    int num[110] = {0};
    for (int i = 0; i < N; ++i) {
        num[d[i]]++;
    }

    int res = 0;
    for (int i = 1; i <= 100; ++i) {
        if (num[i]) {
            ++res;
        }
    }
    cout << res << endl;
    // return 0;
}

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

bool judge() {
  int n, a[100000];
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int nmin = n, nmax = 0;
  for (int i = 0; i < n; ++i) {
    nmin = min(nmin, a[i]);
    nmax = max(nmax, a[i]);
  }

  if (nmax - nmin > 1) return false;
  if (nmin == nmax) {
    return (nmin == n - 1 || (nmin >= 1 && nmin * 2 <= n));
  }

  int alone = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == nmin) alone++;
  }
  return (alone < nmax && (nmax - alone) * 2 <= n - alone);
}

int main(int argc, char *argv[])
{
  cout << (judge()? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
int n,m,c,b[20],a,ans=0;
int main(){
  scanf("%d%d%d",&n,&m,&c);
  for(int i=0;i<m;i++)scanf("%d",&b[i]);
  for(int i=0;i<n;i++){
    int sum=c;
    for(int i=0;i<m;i++){
      scanf("%d",&a);
      sum+=a*b[i];
    }
    if(sum>0)ans++;
  }
  printf("%d",ans);
  return 0;
}
    

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int n,a,mini,ans=-(1<<30);
  scanf("%d %d",&n,&mini);
  for(int i=0;i<n-1;i++){
    scanf("%d",&a);
    if(a-mini>ans)ans=a-mini;
    if(mini>a)mini=a;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int i,o,b=0,f;
    while(cin>>i>>o){
        f=i+o;
        for(int j=1;j<=1000000;j=j*10){
            if(f>=j){
                b++;
            }else{
                break;
            }
        }
        cout<<b<<endl;
        b=0;
    }
    return 0;
}

Measured memory_bytes: 3068
N,D = map(int, input().split())
"""
i-D i+D
2D+1個見ることができる

15 1 -> 5コずつ見られる

1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
"""
if N%(2*D+1)==0:
    print(N//(2*D+1))
else:
    print(N//(2*D+1)+1)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
using llong = long long;

const llong inf = 1ll << 60ll;
llong n, m, x;
llong cost[16];
llong add[16][16];
llong b[16];

llong rec(llong i, llong c) {
    if (i == n) {
        for (int j = 0; j < m; j++) {
            if (b[j] < x) {
                return inf;
            }
        }
        return c;
    }

    llong ret = inf;
    for (int j = 0; j < m; j++) b[j] += add[i][j];
    ret = min(ret, rec(i + 1, c + cost[i]));
    for (int j = 0; j < m; j++) b[j] -= add[i][j];
    ret = min(ret, rec(i + 1, c));

    return ret;
}

int main() {
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> cost[i];
        for (int j = 0; j < m; j++) {
            cin >> add[i][j];
        }
    }

    llong ans = rec(0, 0);

    if (ans == inf) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#A, B, K = map(int, input().split())
X = int(input())

if X == 2 :
  print (2)
  exit()

while True :
  for i in range(2, X) :
    if X%i == 0 :
      X += 1
      break
    if i == X-1 :
      print (X)
      exit()




Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;

double pi=3.141592653589;

void solve(){
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	int min = 60*h+m;
	double angh = 2*pi/720 *min;
	double angm = 2*pi/60 *m;
	double ans=a*a + b*b - 2*a*b * cos(angh-angm);
	cout<<setprecision(17);
	cout<<fixed;
	cout<<sqrt(ans);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 4208
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	int n,q;
	int k;
	cin >> n >> k >> q;

	vector<int>part(n, k);

	REP(i, q) {
		int a;
		cin >> a;
		--a;
		part[a]++;
	}

	REP(i, n) {
		if (part[i] - q > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;

}

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

int n, k, c;
string s;

vector<int> greed(){
  vector<int> res(n, -10);
  
  int cnt = 1;
  for(int i = 0; i < n || cnt <= k; ++i){
    if(s.at(i) == 'x') continue;
    res.at(i) = cnt++;
    i += c;
  }
  
  return res;
}

int main(){
  cin >> n >> k >> c >> s;
  
  vector<int> l, r;
  l = greed();
  reverse(s.begin(), s.end());
  r = greed();
  reverse(r.begin(), r.end());
  
  for(int i = 0; i < n; ++i){
    if(l.at(i) < 0) continue;
    if(l.at(i) == k - r.at(i) + 1) cout << i + 1 << endl;
  }
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) {
        cin >> A.at(i);
    }
    
    int count = 0;
    for(int i = 0; i < n-1; i++) {
        int min = 101;
        int minj = i;
    for(int j = i; j < n; j++) {
        
        if(A.at(j) < min) {
            min = A.at(j);
            minj = j;
        }
    }
    if(minj != i) {
        swap(A.at(i),A.at(minj));
        count++;
    }
    }
    for(int i = 0; i < n; i++) {
        cout << A.at(i);
        if(i == n-1) {
            cout << endl;
        }
        else cout << " ";
    }
    cout << count << endl;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	ANS(max(a*b, c*d));
	return 0;
}


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

using namespace std;

const int mx = 1e9;

int n, m, dp[1 << 12];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i = 1; i < (1 << n); i++) dp[i] = mx;
    for(int i = 1; i <= m; i++){
        int a, b, sum = 0;
        cin >> a >> b;
        for(int j = 1; j <= b; j++){
            int x;
            cin >> x;
            sum += (1 << (x - 1));
        }
        dp[sum] = min(dp[sum], a);
    }

    for(int i = 1; i < (1 << n); i++){
        if(dp[i] < mx){
            for(int j = 1; j < i; j++){
                dp[i | j] = min(dp[i | j], dp[i] + dp[j]);
            }
        }
    }

    if(dp[(1 << n) - 1] == mx) cout << "-1\n";
    else cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dnt(ll x)
{
    int nt=0;
    while(x){
        nt++;
        x/=10;
    }
    return nt;
}
int main()
{
    int nn=1e9,xx;
    ll g,q,z,x;
    scanf("%lld",&q);
    for(g=1;g*g<=q;g++)if(q%g==0){
        z=g, x=q/g;
        xx=max(dnt(z),dnt(x));
        nn=min(nn,xx);
    }
    printf("%d\n",nn);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

class Unionfind {
  public:
    vector<int> par; // 節点
    vector<int> rank; // 木の高さ
    vector<int> size; // 節点が属する木の節点数
    int treeNum; // 木の数
    Unionfind(int N) : par(N), rank(N, 0), size(N, 1) {
      for (int i = 0; i < N; i++) {
        par[i] = i;
      }
      treeNum = N;
    }
    // 節点追加
    void addNode(int x) {
      par[x] = x;
      rank[x] = 0;
      size[x] = 1;
    }
    // 根を探すと同時に経路上にある節点の親が根になるように代入
    int root(int x) {
      return par[x] == x ? x : par[x] = root(par[x]);
    }
    // 同じ木に属しているか
    bool same(int x, int y) {
      return root(x) == root(y);
    }
    // rankが低い方の木をrankが高い方の木の根に結びつける(結びつけた後の新しい木の高さが高くなることがないため)
    void unite(int x, int y) {
      x = root(x);
      y = root(y);
      treeNum--;
      if (x == y) {
        return;
      }
      if (rank[x] < rank[y]) {
        par[x] = y;
        size[y] += size[x];
      } else {
        par[y] = x;
        size[x] += size[y];
        if (rank[x] == rank[y]) {
          rank[x] += 1;
        }
      }
    }
};

int main() {
  int N, M;
  cin >> N >> M;
  int x, y, z;

  Unionfind uf(N);

  rep(i, 0, M) {
    cin >> x >> y >> z;
    x--; y--;
    if (!uf.same(x, y)) {
      uf.unite(x, y);
    }
  }

  cout << uf.treeNum << endl;
};


Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using usize = std::size_t;

bool visit[1000000];

auto main() -> i32 {
	i32 k;
	scanf("%d", &k);
	i32 x = 0;
	i32 last = -1;
	i32 ans = -1;
	i32 i = 0;
	while (true) {
		x = (x * 10 + 7) % k;
		i += 1;
		if (x == 0) {
			ans = i;
			break;
		}
		if (visit[x]) {
			break;
		}
		visit[x] = true;
	}
	printf("%d\n", ans);
	return 0;
}


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

int main(void) {
    int N,M; cin >> N >> M;
    const int INF = 1e9;
    ll height[N+10];
    vector<ll> matrix(N+10,-1);
    for(int i=1; i<=N; i++) cin >> height[i];
    for(int i=1; i<=M; i++) {
        int a,b; cin >> a >> b;
        int c; //低いほうの番号
        if(height[a]>=height[b]) {
            c = b;
            matrix[c] = INF;
        }
        if(height[a]<=height[b]) {
            c = a;
            matrix[c] = INF;
        }
    }
    int ans = 0;
    for(int i=1; i<=N; i++) {
        if(matrix[i] == -1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4848
string = "{0}KIH{1}B{2}R{3}"
OK = []
for i in range(2**4):
    ins_a = [""]*4
    for j in range(4):
        if ((i >> j) & 1):
            ins_a[j] = "A"
    OK.append(string.format(*ins_a))
if input() in OK:
    print("YES")
else:
    print("NO")

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

int N,K;
vector<int> A;
vector<int> c;

signed main()
{
  cin >> N >> K;
  A.resize(N);
  c.resize(N+1);

  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) c[i+1] = (c[i] + A[i] - 1) % K;

  int count=0;
  unordered_map<int, int> m;
  m[0]=1;
  for(int i=1; i<=N; i++)
  {
    if( i - K >= 0 ) m[c[i-K]]--;
    count += m[c[i]];
    m[c[i]]++;
  }
  cout << count << endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;cin >> a >> b >> c >> d;
	a*=b;
	c*=d;
	cout << max(a,c) << endl;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int A,B,C,D,E;
int X[10001],Y[10001];
int main() {
	cin>>A>>B>>C>>D>>E;

	if(A==0)cout<<D+B*E<<endl;
	if(A<0)cout<<((0-A)*C)+D+(B*E)<<endl;
	if(A>0)cout<<(B-A)*E<<endl;


	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    int count = 0;
    
    if(s=="RRR"){
        cout << 3 << endl;
    }else if(s=="SRR"||s=="RRS"){
        cout << 2 << endl;
    }else if(s=="RSR"||s=="SSR"||s=="RSS"||s=="SRS"){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    
    
}

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

struct Card{
  char suit, value;
};

void bubble(struct Card A[], int N){
  for(int i = 0; i < N; i++){
    for(int j = N - 1; j >= i + 1; j--){
      if(A[j].value < A[j - 1].value){
	Card t = A[j];
	A[j] = A[j - 1];
	A[j - 1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N){
  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N){
  for(int i = 0; i < N; i++){
    if(i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
  for(int i = 0; i < N; i++){
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(){
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i = 0; i < N; i++){
    C2[i] = C1[i];
  }

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);

  cout << "Stable" << endl;
  print(C2, N);
  if(isStable(C1, C2, N)){
    cout << "Stable" << endl;
  }
  else {
    cout << "Not stable" << endl;
  }

  return 0;
}



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

int main(){
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int b=(2*C*X+B*(Y-X));
  int c=(2*C*Y+A*(X-Y));
  int d=2*C*Y;
  int e=2*C*X;
  if(A+B<=2*C){
    cout<<(A*X+B*Y)<<endl;
  }
  else{
    if(X<Y){
      if(b<d)
        cout<<b<<endl;
      else
        cout<<d<<endl;
    }else{
      if(c<e)
        cout<<c<<endl;
      else
        cout<<e<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

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

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define s_cin(X) scanf("%s",&X)


#define  i_cout(X) printf("%d\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

int i_cins(int n, int* A);

int main(void) {
	int   N, A[101],i,cnt=0;
	i_cin(N);
	i_cins(N, A);
	for (i = 0;i < N-1;i++)
	{
		if (A[i] == A[i + 1]) {
			cnt++; A[i + 1] = 10001;
		}
	}
	i_cout(cnt);
	return 0;
}

int i_cins(int n, int* A) {
	int i;
	for (i = 0; i < n; i++) 
		i_cin(*(A + i));
	return 0;
}


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

int main()
{
  char a[3];
  for(int i = 0; i < 3; i++){
    cin >> a[i];
    if(a[i] == '1'){
      a[i] = '9';
    }
    else{
      a[i] = '1';
    }
  }
  cout << a[0] << a[1] << a[2] << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 50
#define MAX_A 50
#define MAX_S 2500
i64 dp[MAX_N + 1][MAX_N + 1][MAX_S + 1];

int main() {
    i64 N, A; cin >> N >> A;
    vector<i64> x(N);
    REP(i, N) cin >> x[i];

    dp[0][0][0] = 1;
    REP(i, N) {
        for (i64 j = 0; j <= i; j++) {
            REP(k, MAX_S + 1) {
                dp[i + 1][j][k] += dp[i][j][k];
                if (k + x[i] <= MAX_S) {
                    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                }
            }
        }
    }
    i64 cnt = 0;
    REPS(i, N) {
        cnt += dp[N][i][i * A];
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 49152
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

struct edge{
  int to, cost;
};

vector<edge> G[100001];
bool visited[100001];
int color[100001];

void dfs(int n){
  //cout << n << endl;
  visited[n] = true;
  //cout << " b" << endl;
  for(int i = 0; i < G[n].size(); i++){
    int nxt = G[n][i].to;
    int cst = G[n][i].cost;
    if(!visited[nxt]){
      if(cst % 2 == 0){
        color[nxt] = color[n];
      } else {
        if(color[n] == 0) color[nxt] = 1;
        else color[nxt] = 0;
      }
      //cout << " a" << endl;
      dfs(nxt);
    }
  }
  return;
}

int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N - 1; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    G[u].push_back(edge{v, w});
    G[v].push_back(edge{u, w});
  }

  fill(visited, visited + 100001, false);
  color[0] = 0;
  dfs(0);

  for(int i = 0; i < N; i++){
    cout << color[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define int long long int 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vii vector<int>
#define mii map<int,int>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
using namespace std;
int32_t main()
{
    IOS;
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==5 && a[1]==5 && a[2]==7)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


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

void shuf(vector<int> &v,int p,int c){
    p-=1;
    vector<int> tmp1(p,0),tmp2(c,0);
    rep(i,p){
        tmp1[i]=v[i];
    }
    rep(i,c){
        tmp2[i]=v[p+i];
    }
    rep(i,c){
        v[i]=tmp2[i];
    }
    rep(i,p){
        v[c+i]=tmp1[i];
    }

}

int main(){
    while (true){
        int n,r;
        cin>>n>>r;
        if (n==0)
            break;
        vector<int> deck(n,0);
        rep(i,n){
            deck[n-i-1]=i+1;
        }
        rep(i,r){
            int p,c;
            cin>>p>>c;
            shuf(deck,p,c);
        }
        cout<<deck[0]<<endl;
    }

}




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

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

    static class ACoffee {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.nextLine();
            boolean result = s.charAt(3) == s.charAt(2) && s.charAt(5) == s.charAt(4);
            out.println(result ? "Yes" : "No");
        }

    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる


int main(){
    int N,K; cin >> N >> K;
    int keta=1;
    int tmp=N;
    while(1){
        if (tmp<K) break;
        tmp/=K;
        keta++;
    }
    cout << keta << endl;
    return 0;
}

Measured memory_bytes: 256