akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline
mod = 10**9+7
 
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
NNN = 2*10**5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
 
for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def ff(N, M):
    R = 0
    for i in range(1, M+1):
        R += (-1 if (M-i)%2 else 1) * cmb(M, i) * pow(i, N, mod) % mod
    R = R*cmb(N, M)%mod
    return R
 
N, = map(int, input().split())
R = 0
for i in range(1, N):
    M=N-2*i
    if N < M:
        break
    R += cmb(M-1,i-1)
    R %= mod

print(R)


Measured memory_bytes: 109620
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  pair<int,int>students[n];
  for(int i=0;i<n;i++)
  {
    cin>>students[i].first;
    students[i].second=i+1;
  }
  sort(students,students+n);
  for(int i=0;i<n;i++)
  {
    cout<<students[i].second<<" ";
  }
  
 return 0; 
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int N, M;
vector<int> query[MAX_N];

int main()
{
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        query[a].push_back(b);
        query[b].push_back(a);
    }
    REP(i, N+3) {
        if(query[i].size() % 2 != 0) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,-1,0,1 };
const int LIT = 1000000007;
int n, m;
long long sum = 0;

void solve() {
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        sum += arr[i];
        sum %= LIT;
    }

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        sum -= arr[i];
        if (sum < 0) sum += LIT;
        
        ans += sum * arr[i];
        ans %= LIT;
    }
    cout << ans;
}

int main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3940
# 2019/07/11

import sys
from heapq import heappop,heappush

input=sys.stdin.readline

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,c=map(int,input().split())
    u-=1
    v-=1
    edge[u].append((c,v))
    edge[v].append((c,u))


def dijkstra(s):
    d=[float('inf')]*n
    visited=[False]*n
    d[s]=0
    visited[s]=True
    que=[]
    for e in edge[s]:
        heappush(que,e)
    while que:
        c,v=heappop(que)
        if visited[v]:continue
        d[v]=c
        visited[v]=True
        for cost,vtx in edge[v]:
            if visited[vtx]:continue
            hq=(cost+d[v],vtx)
            heappush(que,hq)

    return d

q,k=map(int,input().split())
k-=1

res=dijkstra(k)
for _ in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(res[x]+res[y])



Measured memory_bytes: 46656
# coding: utf-8
# Your code here!

N = int(input())

dp = [[0] * 3 for _ in range(N)]

a, b, c = map(int, input().rstrip().split(' '))
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c

for i in range(1, N):
    a, b, c = map(int, input().rstrip().split(' '))
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
    
print(max(dp[-1]))


Measured memory_bytes: 22776
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>w>>a>>b;
    tmp=a;tmpp=b;
    a=min(tmp,tmpp);
    b=max(tmp,tmpp);
    ans=b-(a+w);
    ans=max(ans,0LL);
    Cout(ans);
    return 0;
}


Measured memory_bytes: 768
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
//const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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 check(ll target) {
	int res = 0;
	while (target) {
		target /= 10;
		res++;
	}
	return res;
}

int main() {
	
	ll n;
	cin >> n;
	vector<int> ans;
	for (ll i = 1; i*i <= n; ++i) {
		if (n % i == 0) {
			int a = check(i);
			int b = check(n / i);
			ans.push_back(max(a, b));
		}
	}
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
	return 0;
}


Measured memory_bytes: 256
import collections
def slove(n, a):

    count = collections.Counter()
    a_list = [int(i) for i in a.split()]
    for i in a_list:
        count[i] += 1

    tmp = sorted([item for item in count.items() if item[1] >= 2])

    if len(tmp) == 0:
        return 0
    else:
        x = tmp.pop()
        if x[1] >= 4:
            return x[0] ** 2
        else:
            y = tmp.pop()[0]
            return x[0] * y

if __name__ == "__main__":
    n = int(input())
    a_list = input()
    print(slove(n, a_list))


Measured memory_bytes: 19488
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;

  bool ng = false;
  ll x = 0;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);

    int cnt = 0;
    while(a%2==0){
      cnt++;
      a/=2;
    }
    if(x == 0){
      x = cnt;
    }else{
      if(x != cnt){
        ng = true;
      }
    }
  }

  if(ng){
    cout << 0 << endl;
    return 0;
  }

  ll p = 1;
  rep(i,x-1) p *= 2;
  

  rep(i,N){
    v[i] /= p;
  }
  
  ll l = 1;
  rep(i,N){
    ll a = v[i]/2;
    
    l = lcm(l, a);
    if(l > M){
      cout << 0 << endl;
      return 0;
    }
  }

  if(p > M){
    cout << 0 << endl;
    return 0;
  }
  if(p*l > M){
    cout << 0 << endl;
    return 0;
  }
  
  ll lb = 0, ub = 1e10;
  while(ub-lb>1){
    ll mid = (ub-lb)/2 + lb;
    if(2*p*l*mid-p*l <= M) lb = mid;
    else ub = mid;
  }
  
  cout << lb << endl;

  return 0;
}



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

int main(){
	int N,K;
	cin>>N>>K;
	char S[N];
	char tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		if(i==K-1){
			if(tmp == 'A') tmp = 'a';
			if(tmp == 'B') tmp = 'b';
			if(tmp == 'C') tmp = 'c';
		}
		S[i] = tmp;
	}
	for(int i=0;i<N;++i) cout<<S[i];
	cout<<endl;
}


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

int main(){
    int i, f, s, t, h;
    f = -1;
    s = -1;
    t = -1;
    for (i = 0; i < 10; i++) {
        scanf("%d", &h);
        if (h > f) {
        	t = s;
        	s = f;
        	f = h;
        }
        else if (h > s) {
        	t = s;
        	s = h;
        }
        else if (h > t) {
        	t = h;
        }
    }
    printf("%d\n%d\n%d\n", f, s, t);
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll dp[2001][2001];
int main(void){
    ll n;
    cin>>n;
    vector<pair<ll,ll>>p(n);
    rep(0,i,n){
        cin>>p[i].first;
        p[i].second=i;
    }
    sort(p.rbegin(),p.rend());
    rep(0,i,n+1)rep(0,j,n+1)dp[i][j]=0;
    rep(0,i,n){
        ll k=p[i].first;
        ll r=p[i].second;
        rep(0,x,i+1){
            ll y=i-x;
            dp[x+1][y]=max(dp[x+1][y],dp[x][y]+k*abs(r-x));
            dp[x][y+1]=max(dp[x][y+1],dp[x][y]+k*abs(n-1-y-r));
        }
    }
    ll ans=0;
    rep(0,i,n)ans=max(dp[i][n-i],ans);
    cout<<ans;
}


Measured memory_bytes: 34944
package main

import "fmt"

type music struct {
	Name string
	Time int
}

func (m music) Is(s string) bool {
	return s == m.Name
}

func main() {
	var (
		playlist []music
	)
	var n int
	fmt.Scan(&n)
	playlist = make([]music, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&playlist[i].Name)
		fmt.Scan(&playlist[i].Time)
	}
	var x string
	fmt.Scan(&x)
	var flag bool
	all := 0
	for i := 0; i < n; i++ {
		if flag {
			all += playlist[i].Time
			continue
		}
		flag = playlist[i].Is(x)
	}
	fmt.Println(all)
}


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

#define INFTY (1 << 30);
typedef long long ll;

int main(void) {
  int N;
  vector<int> H;
  cin >> N;
  int H_input;
  for (int i = 0; i < N; i++) {
    cin >> H_input;
    H.push_back(H_input);
  }
  int counter = 1;
  reverse(H.begin(), H.end());
  bool possible = true;
  for (int i = 0; i < N - 1; i++) {
    possible = true;
    for (int j = i+1; j < N; j++) {
      if (H[i] >= H[j]) {
      } else {
        possible = false;
        break;
      }
    }
    if (possible == true) {
      counter++;
    }
  }

  cout << counter << endl;

  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS() std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define me(a,b) memset(a,b,sizeof(a))
int main(){
	int n;
	string s1,s2;
	cin>>n>>s1>>s2;
	for(int i=0;i<n;i++){
		cout<<s1[i]<<s2[i]; 
	}
	cout<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

signed main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int i = 0, j = n - 1;
    while (i < j)
    {
        while (i < j && s[i] != 'W') i++;
        while (j > i && s[j] != 'R') j--;
        if (i == j)
        {
            cout << ans;
            return 0;
        }
        ans++;
        swap(s[i], s[j]);
    }
}


Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (((a <= c) && (c <= b)) ? "Yes" : "No" ) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=1;i<=(n);++i)
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
int n;
int ind[501][501];
char str[1002];
#define B 0
#define W 1
bool colexistb[501];
int main()
{
	scanf("%d",&n);
	bool existb=false;
	rep(i,n)
	{
		scanf("%s",&str[1]);
		rep(j,n)
		{
			ind[i][j]=(str[j]=='#'?B:W);
			if(ind[i][j]==B)existb=true;
		}
	}
	if(!existb)
	{
		cout<<-1;
		return 0;
	}
	int res=0;
	rep(j,n)
	{
		colexistb[j]=false;
		rep(i,n)
		{
			if(ind[i][j]==B)colexistb[j]=true;
		}
	}
	int minwcount=99999999;
	rep(i,n)
	{
		int wcount=0;
		rep(j,n)
		{
			if(ind[i][j]==W)
			{
				++wcount;
			}
			
		}
		if(!colexistb[i])++wcount;
		//cout<<"wCount:"<<wcount<<endl;
		minwcount=min(minwcount,wcount);
	}
	res+=minwcount;
	rep(j,n)
	{
		bool existw=false;
		rep(i,n)
		{
			if(ind[i][j]==W)existw=true;
		}
		if(existw)++res;
	}
	cout<<res;
}

Measured memory_bytes: 1280
import std.stdio, std.conv, std.algorithm, std.string;
alias L = long;
L M = 998244353;
L[] X, D;
L q(L m, L[] U){
	foreach(i, u; U) if(i / m & 1 ^ U[i % m] ^ u) return u;
	return 1;
}
L t(L[] U){
	L f;
	foreach(u; U) f = (f * 2 + u) % M;
	return f;
}
void main(){
	L n = readln.chomp.to!L, b = n * 2;
	foreach(c; readln.chomp) X ~= c - '0';
	foreach_reverse(d; 3 .. n + 1) if(d % 2 && !(n % d)) D ~= d;
	
	L[L] C;
	foreach(d; D){
		C[d] = t(X[0 .. n / d]) + q(n / d, X);
		foreach(e; D) if(e > d && !(e % d)) C[d] += M - C[e];
		C[d] %= M;
	}
	
	n = (t(X) + 1) * b % M;
	foreach(d; D) n += M - C[d] * (b - b / d) % M;
	writeln(n % M);
}


Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
using namespace std;
long long a[100000],f[1000][1000],sum[100000];
int n;
long long qhd(int i,int j){
    if (f[i][j]!=10e13) return f[i][j];
    else {
        for (int z=i;z<j;++z){
            f[i][j]=min(f[i][j],qhd(i,z)+qhd(z+1,j)-sum[i-1]+sum[j]);
        }
        return f[i][j];
    }
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;++i) {cin>>a[i]; sum[i]=sum[i-1]+a[i];}
    for (int i=1;i<=n;++i){
        for (int j=1;j<=n;++j) f[i][j]=10e13;
    }
    for (int i=1;i<=n;++i) f[i][i]=0;
    cout<<qhd(1,n);
}


Measured memory_bytes: 3456
K = int(input())

cnt = 1
num = 7 % K

flag = False

if num == 0:
    flag = True

remainderList = {num}

while not flag:
    cnt += 1
    
    num = ((num * 10) % K + 7) % K
    if num == 0:
        flag = True
        break
    if num in remainderList:
        break
    remainderList.add(num)

if flag:
    print(cnt)
else:
    print("-1")

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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

int main() {
	FREOPEN();
	int n, m;
	cin >> n >> m;
	int ans = (1 << m) - 1;
	for (int i = 1; i <= n; i++) {
		int mask = 0;
		int k;
		scanf("%d ", &k);
		for (int j = 0; j < k; j++) {
			int x;
			scanf("%d ", &x);
			x--;
			mask |= (1 << x);
		}
		ans &= mask;
	}
	cout << __builtin_popcount(ans);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    sum = 0
    for i in range(1,n-1):
        a = p[i-1]
        b = p[i]
        c = p[i+1]
        if (a < b and b < c) or (a > b and b > c):
            sum += 1
    print(sum) 
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll k;
	cin >> k;
	ll n;
	cin >> n;
	ll a[200010];
	FOR(i,n){
		cin >> a[i];
	}
	ll maxi=-100;
	FOR(i,n-1){
		chmax(maxi,a[i+1]-a[i]);
	}
	chmax(maxi,k+a[0]-a[n-1]);
	cout << k-maxi << endl;
}

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

const int MAX_N = (int)100 + 5;

int n;
vector<int> d;

int t;

int main(void){
  // Here your code !
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    d.push_back(t);
  }

  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());

  printf("%d\n", d.size());

}


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

int main(void)
{
  int m,n,i,j,k;
  int a[101][101]={},b[101]={},c[101]={};

  cin >> m >> n;
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++)
      cin >> a[i][j];
  }
    for(j=1;j<=n;j++)
      cin >> b[j];

  for(i=1;i<=m;i++) {
    for(j=1;j<=n;j++)
      c[i]=c[i]+a[i][j]*b[j];
    cout << c[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

// union-find
struct union_find {
    vector<int> data;

    union_find(int size) {data.resize(size,-1);}

    int find(int x) {
        if (data[x] < 0) {return x;}
        return data[x] = find(data[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) {return false;}
        if (data[x] > data[y]) swap(x,y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int size(int x) {return -data[find(x)];}
};

int main() {
    int n, m; cin >> n >> m;
    union_find uf(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = -1;
    rep(i,n) if (uf.data[i] < 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cstdio>
#define N 50
using namespace std;

int main(){

  int n,r,ans;
  int operate[N][2];

  while(true)
    {
      cin >> n >> r;
      if(n == 0 && r == 0)break;

      for(int i=0;i<r;i++)cin >> operate[i][0] >> operate[i][1];
      ans = n;
      int da = n;
     
      for(int i=r-1;i>=0;i--){

	if(n - ans  +1<= operate[i][1]){
	  ans -= operate[i][0] -1;
	}else if(n-ans+1< operate[i][0]+operate[i][1]) 
	  {
	    ans += operate[i][1];
	  }


	//	da = n;
	/*	if(n-operate[i][1] <= ans && ans <= n)
	  {
	    if(n == operate[i][1])continue;
	    ans = ans-operate[i][0]+1;
	  
	  }
	else{
	  da = da-operate[i][0]+1;
	  if(da <= ans)ans+=operate[i][1];
	  //else if(da > ans)ans-=operate[i][1];

	}
	*/
	//cout << "da ~ " << da << endl;
	//cout << "ans = " << ans << endl;

      }

      cout << ans << endl;



    }

}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  REP(i, N) cin >> s[i];

  REP(i, N) sort(ALL(s[i]));
  sort(ALL(s));

  ll ret = 0;
  REP(i, N) {
    int pos = i;
    while((i < N) && (s[i] == s[pos])) ++i;
    ret += (ll)(i - pos) * (ll)(i - pos - 1) / 2;
    i--;
  }

  cout << ret << endl;
  return 0;
}



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

int main() {
    string n; cin >> n;
    int abcd[4];
    for(int i= 0; i < 4; i ++) abcd[i] = n[i]-48;
    char op[3];
    for(int i = 0; i < 2; i ++) {
        int ans = abcd[0];
        if(i%2==0) {
            op[0] = '+';
            ans += abcd[1];
        }
        else {
            op[0] = '-';
            ans -= abcd[1];
        }
        for(int j = 0; j < 2; j ++) {
            int anss = ans;
            if(j%2==0) {
                op[1] = '+';
                anss += abcd[2];
            }
            else {
                op[1] = '-';
                anss -= abcd[2];
            }
            for(int k = 0; k < 2; k ++) {
                int ansss = anss;
                if(k%2==0) {
                    op[2] = '+';
                    ansss += abcd[3];
                }
                else {
                    op[2] = '-';
                    ansss -= abcd[3];
                }
                if(ansss==7) {
                    cout << abcd[0] << op[0] << abcd[1] << op[1] << abcd[2] << op[2] <<abcd[3] << '=' << 7 << endl;
                    return 0;
                }
            }
        }
    }
}

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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll> > prime_factorize(ll n) {
  vector<pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
  ll x = 1, y = 1;
  for (ll i = 0; i < a; i++) {
    x = x * (n - i) % MOD;
    y = y * (i + 1) % MOD;
  }
  return x * repeat_square(y, MOD - 2) % MOD;
}

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

  int count_1 = 0, count_2 = 0;
  rep(i, N) {
    ll a;
    cin >> a;

    if (a % 4 == 0) count_1++;
    if (a % 2 == 0) count_2++;
  }

  count_2 -= count_1;

  if (count_1 >= (N/2)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    int leave = N/2 - count_1;
    if (count_2 >= (leave*2)) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3596
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = input()

    cnt_init = X.count("1")
    x_init = int(X, 2)
    a = x_init % (cnt_init + 1)
    if cnt_init - 1 != 0:
        b = x_init % (cnt_init - 1)

    for i in range(n):
        if X[i] == "0":
            cnt = cnt_init + 1
            x = (a + pow(2, (n - i - 1), cnt)) % cnt
            res = 1
        else:
            cnt = cnt_init - 1
            if cnt != 0:
                x = (b - pow(2, (n - i - 1), cnt)) % cnt
                res = 1
            else:
                x = 0
                res = 0

        while x:
            cnt = bin(x).count("1")
            x %= cnt
            res += 1
        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9408
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = sc.nextInt();
		int k = sc.nextInt();

		if((n + 1) / 2 >= k) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(const vector<ll>& v, ll m){
  m *= 2;
  int N = v.size();
  
  ll base = m;
  rep(i,N){
    base = 2 * (v[i%N] - base/2);
  }

  if(base>=m) return true;
  return false;
}

int main(){
  int N;
  vector<ll> v;
  cin >> N;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll lb = 0, ub = 10000000005LL;
  while(ub-lb>1){
    ll mid = (lb+ub)/2;
    if(check(v, mid)) lb = mid;
    else ub = mid;
  }

  ll base = 2*lb;
  rep(i,v.size()){
    if(i>0) cout << " ";
    cout << base;
    base = 2*(v[i] - base/2);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2164
//author: zekigurbuz (Zeki Gurbuz) 2019
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, vi> mvi;
typedef map<int, vpii> mvpii;
typedef priority_queue<int> pqi;
typedef set<int> si;

#define int ll
#define double ld
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rsz resize
#define forn(a,b) for(int a=0;a<b;++a)
#define rep(a,b,c) for(int a=b;a<c;++a)
#define all(x) begin(x),end(x)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);

const ld PI=4*atan((ld)1);
const int MOD=1000000007;//998244353
const ll INF=0x3FFFFFFFFFFFFFFFLL;
const int N=200005;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}
template<class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

string Eval(bool b){return(b?"Yes":"No");}
string eval(bool b){return(b?"yes":"no");}
string EVAL(bool b){return(b?"YES":"NO");}

void precomp() {
	
}

void solve(int testCaseNumber) {
	int n; cin >> n;
	bool b = 0;
	rep(i, 1, 10) rep(j, 1, 10) if (i * j == n) {
		b = 1;	
	}
	cout << Eval(b) << endl;	
}
signed main(){fastio//freopen("replace.in", "r", stdin);freopen("replace.out", "w", stdout);
	
	precomp();
	int t = 1;
//	cin >> t;
	rep(i, 1, t + 1) solve(i);
	
return 0;}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())

struct P {
  int x, y, t;
};

int main() {
  int N;
  cin >> N;
  vector<P> points(N + 1);

  points.at(0) = P{0, 0, 0};  // start point

  for (int i = 1; i <= N; i++) {
    int x, y, t;
    cin >> t >> x >> y;
    points.at(i) = P{x, y, t};
  }

  bool canTravel = true;
  for (int i = 0; i < N; i++) {
    int d = abs(points.at(i).x - points.at(i + 1).x) +
            abs(points.at(i).y - points.at(i + 1).y);

    int dt = points.at(i + 1).t - points.at(i).t;
    if (d > dt) {
      canTravel = false;
      break;
    }
    if (d % 2 != dt % 2) {
      canTravel = false;
      break;
    }
  }

  cout << (canTravel ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  map<char, int> cnt;
  int g1, g2, g4;
  if (H % 2 && W % 2) {g1 = 1; g2 = H/2 + W/2; g4 = (H/2)*(W/2);}
  else if (H % 2 == 0 && W % 2 == 0) {g1 = 0; g2 = 0; g4 = (H*W)/4;}
  else if (H % 2 && W % 2 == 0) {g1 = 0; g2 = W/2; g4 = W/2 * H/2;}
  else if (H % 2 == 0 && W % 2) {g1 = 0; g2 = H/2; g4 = H/2 * W/2;}
  VC alp;
  REP(i, H) REP(j, W)
  {
    char a;
    cin >> a;
    cnt[a]++;
    alp.push_back(a);
  }
  UNIQUE(alp);

  priority_queue<int> que;
  REPx(x, alp) que.push(cnt.at(x));

  while(que.size())
  {
    int x = que.top(); que.pop();
    if (g4 > 0 && x >= 4)
    {
      x -= 4;
      g4--;
    }
    else if (g2 > 0 && x >= 2)
    {
      x -= 2;
      g2--;
    }
    else if (g1 > 0 && x >= 1)
    {
      x--;
      g1--;
    }
    else
    {
      que.push(x);
      break;
    }
    if (x != 0) que.push(x);
  }

  if (que.size()) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    mp[d]++;
  }
  cout << mp.size() << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

result = -1
flag = True
while flag:
    result += 1
    for i in range(len(A)):
        if A[i] % 2 == 0:
            A[i] /= 2
        else:
            flag = False
            break

print(result)

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

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

    if (N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    } else if (N == 4) {
        cout << "2 5 20 63" << endl;
        return 0;
    } else if (N == 5) {
        cout << "2 5 20 30 63" << endl;
        return 0;
    }

    vector<ll> cand;
    for (ll i = 1; i <= 30000; i++) {
        if (i % 6 == 0 || i % 6 == 2 || i % 6 == 3 || i % 6 == 4) {
            cand.push_back(i);
        }
    }

    vector<ll> ans(N);
    for (int i = 0; i < N; i++) {
        ans[i] = cand[i];
    }

    ll sum = accumulate(ans.begin(), ans.end(), 0ll);
    if (sum % 6 == 2) {
        ans.erase(find(ans.begin(), ans.end(), 8));
        ans.push_back(30000);
    } else if (sum % 6 == 3) {
        ans.erase(find(ans.begin(), ans.end(), 9));
        ans.push_back(30000);
    } else if (sum % 6 == 5) {
        ans.erase(find(ans.begin(), ans.end(), 9));
        ans.push_back(29998);
    }

    for (ll a : ans) {
        cout << a << " ";
    }
    cout << endl;
}


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

int main() {
    
    char b; cin >> b;

    if(b=='A'){
        cout << 'T' << endl;
        return 0;
    }

    if(b=='T'){
        cout << 'A' << endl;
        return 0;
    }

    if(b=='C'){
        cout << 'G' << endl;
        return 0;
    }

    if(b=='G'){
        cout << 'C' << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <set>
using namespace std;

int main(int argc, char const *argv[]) {
  int n,m;cin>>n>>m;
  vector<string> ss(n);
  int num = 0;
  for(int i=0;i<n;++i){
    cin>>ss[i];
    for(int j=0;j<m;++j)num+=(ss[i][j]=='#');
  }
  for(int i=0;i<n*m;++i){
    int x = i/m,y=i%m;
    if(ss[x][y]!='#')continue;
    int tmp = 1;
    while(true){
      int b1=0;
      if(x+1<n&&ss[x+1][y]=='#')b1=1;
      int b2=0;
      if(y+1<m&&ss[x][y+1]=='#')b2=1;
      if(b1+b2!=1)break;
      tmp++;
      if(b1>b2)x++;
      if(b2>b1)y++;
    }
    if(tmp==num){
      std::cout << "Possible" << '\n';
      return 0;
    }
  }
  std::cout << "Impossible" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>
#include <cstring>

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

int main() {
    int x;
    cin >> x;
    if (x >= 400 && x <= 599) {
        cout << 8 << endl;
    }
    else if (x <= 799) {
        cout << 7 << endl;
    }
    else if (x <= 999) {
        cout << 6 << endl;
    }
    else if (x <= 1199) {
        cout << 5 << endl;
    }
    else if (x <= 1399) {
        cout << 4 << endl;
    }
    else if (x <= 1599) {
        cout << 3 << endl;
    }
    else if (x <= 1799) {
        cout << 2 << endl;
    }
    else {
        cout << 1  << endl;
    }
    return 0;
}


Measured memory_bytes: 3524
a,b,k=map(int,input().split())
for i in range(k):
  if i%2:
    if b%2:b-=1
    a+=(b//2)
    b//=2
  else:
    if a%2:a-=1
    b+=(a//2)
    a//=2
print(a,b)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,k; cin >> n >> k;
  int keta = 0;
  while(n>0){
    n/=k;
    keta++;
  }
  cout << keta;
  return 0;
}

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

int main() {
    vector<int> nums(10, 0);
    rep(i,3){
        int a;
        cin >> a;
        nums[a]++;
    }
    for(int i = 0; i < 10; i++){
        if(nums[i] == 2){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
            return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  int largest = (B / K) * K;

  if (A <= largest) {
    cout << "OK" << endl;
  }
  else  {
      cout << "NG" << endl;
  }
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int n;
typedef struct {
	char name;
	int num;
}Card;
void fswap(Card *x, Card *y) {
	Card tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}
bool solve(Card bubble[], Card com[]) {
	for (int i = 0; i<n; ++i)
		if (bubble[i].name != com[i].name || bubble[i].num != com[i].num) return false;
	return true;
}
void output(Card bubble[], Card com[]) {
	for (int i = 0; i<n; ++i) {
		if (i) cout << " ";
		cout << com[i].name << com[i].num;
	}
	cout << endl;
	if (solve(bubble, com)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
}
int main() {
	cin >> n;
	Card card[36], cp[36];
	for (int i = 0; i<n; ++i) {
		cin >> card[i].name >> card[i].num;
		cp[i].name = card[i].name;
		cp[i].num = card[i].num;
	}
	for (int i = 0; i<n - 1; ++i)
		for (int j = n - 2; j >= i; --j)
			if (card[j].num>card[j + 1].num) fswap(&card[j], &card[j + 1]);
	output(card, card);
	for (int i = 0; i<n - 1; ++i) {
		int minj = i;
		for (int j = i + 1; j<n; ++j)
			if (cp[j].num<cp[minj].num) minj = j;
		fswap(&cp[i], &cp[minj]);
	}
	output(card, cp);
	return 0;
}


Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] pattern =
			{
				"1100000011",
				"1000000010000000100000001",
				"1111",
				"1000000110000001",
				"11000000011",
				"100000001100000001",
				"110000011"
			};
			while (true)
			{
				var str = Console.ReadLine();
				if (str == null) break;
				for (int i = 0; i < 7; i++)
					str += Console.ReadLine();
				Console.ReadLine();
				for (int i = 0; i < pattern.Length; i++)
				{
					if (str.Contains(pattern[i]))
						Console.WriteLine((char)('A' + i));
				}
			}
		}
	}
}

Measured memory_bytes: 6196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {
    int N;
    cin >> N;
    double ans = 0;
    double m;
    string s;
    REP(i, N){
        cin >> m >> s;
        if (s[0] == 'J') ans += m;
        else ans += m * 380000.0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int i,l,a,x,b,r,num;
  for(i = 0; i <1000; i++){
      scanf("%d %d", &a, &b);
      if(a == 0 && b == 0) break;
      if(a < b){
      x = b;
      b = a;
      a = x;
      }
   num = 0;
  for(l = 0; b != 0; l++){
      r = a%b;
      a = b;
      b = r;
      num++;
  }
  printf("%d %d\n", a, num);
  }
  return 0; 
}


Measured memory_bytes: 1972
//https://atcoder.jp/contests/abc127/tasks/abc127_a
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int A, B;
    cin >> A >> B;
    cout << ( A >= 6 && A <= 12 ? B/2 : A <= 5 ? 0 : B ) << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
4 3 2
*/
#include <bits/stdc++.h>
using namespace std;
int r, b, g;
int main(){
	scanf("%d %d %d", &r, &b, &g);
	puts((100 * r + 10 * b + g) % 4 == 0 ? "YES" : "NO");
}

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

int main() {
        int n;
        cin >> n;
        vector<int> a(n);
        rep(i, n) {
                scanf("%d", &a[i]);
        }
        vector<int> ans(n);
        rep(i, n) if (i) ans[0] ^= a[i];
        rep(i, n) if (i) {
                ans[i] = ans[0] ^ a[0] ^ a[i];
        }
        rep(i, n) printf("%d ", ans[i]);
        printf("\n");
        return 0;
}


Measured memory_bytes: 4876
#include<bits/stdc++.h>
using namespace std;
int point[100][100],n,d;
int main()
{
    cin>>n>>d;
    for(int i=0;i<n;i++)
        for(int j=0;j<d;j++)
            cin>>point[i][j];
    int ans=0;
    int record=0;
    for(int i=0;i<n;i++)
    {
        // int sum=0;
        for(int j=i+1;j<n;j++)
        {
            int sum=0;
            for(int k=0;k<d;k++)
            {
                sum+=(point[i][k]-point[j][k])*(point[i][k]-point[j][k]);
            }
            if(sum==(int)sqrt(sum)*(int)sqrt(sum)) ans++;
            // cout<<sum<<" "<<(int)sqrt(sum)*(int)sqrt(sum)<<endl;
        }
    }
    // cout<<record<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define mod 1000000007 
using namespace std;
typedef long long ll;
const int N=100000+10;
ll n,m,x,y,k,a,b,c,d,s,t,ans,q,r;  
ll sum,arr[N]; 
const int nax = 1001;

void solve()
{ ll n,w,sumval=0;
   cin>>n>>w;
   ll weight[n],val[n];
   for(int i=0;i<n;i++)
   {  cin>>weight[i]>>val[i];
      sumval+=val[i];
   } 
   vector<ll> dp(sumval+1,1e18); // dp [val] = weight 
   dp[0] = 0;                         
   for(int i=0;i<n;i++)
   { for(int j=sumval;j>=val[i];j--)
      { dp[j] = min(dp[j],dp[j-val[i]]+weight[i]);
	  }
   } 
   ans = 0;
   for(int i=0;i<=sumval;i++) 
   { if(dp[i]<=w) 
     ans = max(ans,1LL*i);
   } 
   cout<<ans;
}
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
	freopen("fi.txt", "r", stdin);
	freopen("fo.txt", "w", stdout);
	#endif 
	
	int t=1;
	
 	//cin>>t; 
 
	int  a=0;
	while(t--)
	{ // cout<<"Case #"<<++a<<": ";
	   solve();
	   cout<<"\n"; 
	}    
	
    return 0;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
int n;
char s[N];
void add(int x,int y){
	printf("%d %d\n",x,y);
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if (s[1]=='0'){
		puts("-1");
		return 0;
	}
	if (s[n]=='1'){
		puts("-1");
		return 0;
	}
	for (int i=1;i<=n-1;i++)
	if (s[i]!=s[n-i]){
		puts("-1");
		return 0;
	}
	int last=1; s[n]='1';
	for (int i=2;i<=n;i++){
		if (s[i]=='0') continue;
		add(i,last);
		for (int j=last+1;j<i;j++) add(i,j);
		last=i;
	}
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = Console.ReadLine()
            .Split(' ')
            .Select(txt => int.Parse((txt)))
            .ToList()
            .First();

        var x = N % 10;


        switch (x)
        {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                Console.WriteLine("hon");
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                Console.WriteLine("pon");
                break;
            case 3:
                Console.WriteLine("bon");
                break;
        }
    }
}

Measured memory_bytes: 28256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int index_check(int cur, int n) {
    if (cur == n) return 0;
    else if (cur == n+1) return 1;
    else return cur;
}

int main(int argc, char const *argv[]) {
    int n;
    string s;
    cin >> n >> s;
    vector<string> dp(4);
    dp[0] = "SS";
    dp[1] = "SW";
    dp[2] = "WS";
    dp[3] = "WW";
    REP(i,4) {
        for (int j = 1; j <= n; ++j) {
            int s_ind = index_check(j, n);
            if (dp[i][j-1] == 'S') {
                if (dp[i][j] == 'S') {
                    if (s[s_ind] == 'o') dp[i].push_back('S');
                    else dp[i].push_back('W');
                }
                else {
                    if (s[s_ind] == 'o') dp[i].push_back('W');
                    else dp[i].push_back('S');
                }
            }
            else {
                if (dp[i][j] == 'S') {
                    if (s[s_ind] == 'o') dp[i].push_back('W');
                    else dp[i].push_back('S');
                }
                else {
                    if (s[s_ind] == 'o') dp[i].push_back('S');
                    else dp[i].push_back('W');
                }
            }
        }
    }
    REP(i,4) {
        string ZO = dp[i].substr(0, 2);
        string NN = dp[i].substr(n, 2);
        //cout << "ZO = " << ZO << " NN = " << NN << endl;
        if (ZO == NN) {
            dp[i].erase(dp[i].begin()+n, dp[i].end());
            cout << dp[i] << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  string str;
  cin>>str;
  int K;
  cin>>K;
  for (int i = 0; i < N; i++) {
  if(str.at(i)==str.at(K-1)){
    cout<<str.at(i);}
      else{
        cout<<"*";
}
  }
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]) {  
	unsigned long long Lucas[123];
	Lucas[0] = 2;
	Lucas[1] = 1;
	for(int i = 2; i < 88; i++) {
		Lucas[i] = Lucas[i-1] + Lucas[i-2];
	}
	int N;
	std::cin >> N;
	std::cout << Lucas[N] << '\n';
	return 0;
}

Measured memory_bytes: 256