akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MX = 305;
int n,m,a[MX][MX],ans = MX;
bool ex[MX];
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) rep(j,m) scanf("%d", a[i]+j);
	rep(i,m){
		int cnt[MX] = {}, v = 0;
		rep(i,n){
			rep(j,m) if(!ex[a[i][j]]){
				cnt[a[i][j]]++;
				break;
			}
		}
		for(int i=1; i<=m; i++) if(cnt[v] < cnt[i]) v = i;
		ex[v] = true;
		ans = min(ans, cnt[v]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

int main() {
    string o, e;
    cin >> o >> e;
    int n = o.size(), m = e.size();
    for (int i = 0; i < n; i++) {
        cout << o[i];
        if (i < m) cout << e[i];
    }
    cout << '\n';
}

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

using namespace std;

int main(){
    long long N, K;
    cin >> N >> K;

    long long div = N/K;

    long long K_dash;
    long long N_dash; 
    if(div >0){
        K_dash = div*K;
        N_dash = abs(N - K_dash);
    }else{
        N_dash = N;
    }

    while(true){
        long long tmp = abs(N_dash - K);
        if(tmp < N_dash){
            N_dash = tmp;
        }else{
            break;
        }
    }

    cout << N_dash << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    // UURDDLLUUURRDRDDDLLU
    int sx = in(), sy = in(), tx = in(), ty = in();
    REP(i, ty - sy) cout << 'U';
    REP(i, tx - sx) cout << 'R';
    REP(i, ty - sy) cout << 'D';
    REP(i, tx - sx) cout << 'L';
    cout << 'L';
    REP(i, ty - sy + 1) cout << 'U';
    REP(i, tx - sx + 1) cout << 'R';
    cout << "DR";
    REP(i, ty - sy + 1) cout << 'D';
    REP(i, tx - sx + 1) cout << 'L';
    cout << 'U' << endl;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

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


n = II()
src = [SI() for _ in range(3)]

ans = 0
for abc in zip(*src):
    ans += len(set(abc)) - 1

print(ans)

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

using namespace std;

typedef unsigned long long ll;
int main()
{
    ll n;
    cin >> n;

    vector<ll> ans(n+1, 1);

    for (ll i = 2; i <= n; i++)
    {
        ll j = i;
        while (j <= n)
        {
            ans[j]++;
            j += i;
        }
    }

    ll result = 0;
    for (ll i = 1; i <= n; i++)
    {
        result += (i) * ans[i];
    }

    cout << result;
    return 0;
}


Measured memory_bytes: 81400
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(K);
    string S;
    cin>>S;
    if(S.length()<=K)
    {
        cout<<S<<endl;
    }
    else
    {
        FORI(i,0,K)
        {
            cout<<S[i];
        }
        cout<<"..."<<endl;
    }
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

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

int main(){
  int i, j, num, rank, n, stc[4][13] = { 0 };
  char card[2];

  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    scanf("%s %d",card ,&num);
	if(strcmp(card, "S") == 0) rank = 0;
	else if(strcmp(card, "H") == 0) rank = 1;
	else if(strcmp(card, "C") == 0) rank = 2;
	else if(strcmp(card, "D") == 0) rank = 3;
	
	stc[rank][num - 1] = 1;
  }

  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      if(stc[i][j] == 0){
	    if(i == 0) rank = 'S';
		else if(i == 1) rank = 'H';
		else if(i == 2) rank = 'C';
		else if(i == 3) rank = 'D';

		printf("%c %d\n", rank, j + 1);
	  }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
void tree(vector<set<int>> &g,vector<vector<int>> &t,int p){
  while(!g.at(p).empty()){
    int cp=*begin(g.at(p));
    t.at(p).push_back(cp);
    g.at(p).erase(cp);
    g.at(cp).erase(p);
    tree(g,t,cp);
  }
}
void depth(vector<vector<int>> &t,vector<vector<int>> &d,int p,int c){
  d.at(c).push_back(p);
  for(int cp:t.at(p))
    depth(t,d,cp,c+1);
  return;
}
int main(){
  int n;
  cin>>n;
  int p=1000000007;
  vector<set<int>> g(n);
  for(int i=0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    g.at(x-1).insert(y-1);
    g.at(y-1).insert(x-1);
  }
  vector<vector<int>> t(n);
  tree(g,t,0);
  vector<vector<int>> d(n);
  depth(t,d,0,0);
  vector<int64_t> dp(n);
  for(int x=n-1;x>=0;x--){
    for(int i:d.at(x)){
      int64_t w=1;
      int64_t b=1;
      for(int ci:t.at(i)){
        w=w*dp[ci]%p;
        for(int cci:t.at(ci))
          b=b*dp[cci]%p;
      }
      dp[i]=(w+b)%p;
    }
  }
  cout<<dp[0]<<endl;
}

Measured memory_bytes: 25472
#include<stdio.h>
#include<math.h>

int main(void)
{
	int n,a;
	double x[1000], y[1000], sum=0, sum2=0, sum3=0, sum4=0;
	scanf("%d", &n);
	for (a = 0; a < n; a++)
	{
		scanf("%lf", &x[a]);
	}
	for (a = 0; a < n; a++)
	{
		scanf("%lf", &y[a]);
		if (x[a] < y[a])
		{
			x[a] = -1 * x[a];
			y[a] = -1 * y[a];
			sum4 = x[a] - y[a];
		}

	}
	for (a = 0; a < n; a++)
	{
		sum =1.0*( sum + (x[a] - y[a]));
		sum2 = 1.0*(sum2 + ((x[a] - y[a])*(x[a] - y[a])));
		sum3 = 1.0*(sum3 + ((x[a] - y[a])*(x[a] - y[a])*(x[a] - y[a])));
		if ((x[a] - y[a]) > sum4)
		{
			sum4 = x[a] - y[a];
		}
	}
	printf("%f\n%f\n%f\n%f\n", sum, sqrt(sum2), pow(sum3, 1.0 / 3.0),sum4);
	
	return 0;
}


Measured memory_bytes: 2116
K, N = map(int, input().split())

house_list = list(map(int, input().split()))
#print(house_list)

dist_list = [K - house_list[-1] + house_list[0]]
#print(dist_list)

for n in range(1, N):
    dist_list.append(house_list[n] - house_list[n-1])
print(K - max(dist_list))

Measured memory_bytes: 25840
import java.util.*;

public class Main {

    private static class SP {
        int id;
        String S;
        int P;

        SP(int id, String S, int P) {
            this.id = id;
            this.S = S;
            this.P = P;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<SP> SPs = new ArrayList<>();
        for (int n = 0; n < N; n += 1) {
            String S = sc.next();
            int P = sc.nextInt();
            SPs.add(new SP(n + 1, S, P));
        }

        SPs.sort(new Comparator<SP>() {
            @Override
            public int compare(SP o1, SP o2) {
                int dictOrder = o1.S.compareTo(o2.S);
                if (dictOrder != 0) {
                    return dictOrder;
                } else {
                    return Integer.compare(o2.P, o1.P);
                }
            }
        });

        for (SP sp : SPs) {
            System.out.println(sp.id);
        }
    }

}


Measured memory_bytes: 19540
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

void add_self(int &a, int b, int m){
    a%=m;
    b%=m;
    a+=b;
    if(a>=m)a-=m;
}

signed main() {
   tezz
   
   int n;
   cin >> n;
   cout << (int)pow(n,2) << endl;
   
  
   return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int count = 1;
    while (true) {
      if ((x * count) % 360 == 0) break;
      count++;
    }
    System.out.println(count);
  }
}


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

int main(){
    int a,b,c;cin >> a >> b >> c;
    if ((b - a) == (c - b)){
        cout << "YES" << endl;
        return 0;
    }
    
    cout << "NO" << endl;
	return 0;
}

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

int main(){
    ll n, m; cin >> n >> m;
    ll a = (n-m)*100, b = 1900*m, c = pow(2, m), d = (a+b)*c;
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 256
mod = 1000000007
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())


def cmb(n, r):
    if n<0 or r<0 or r>n:
        return None
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n
    numerator = [0]*r
    denominator = [0]*r
    for k in range(r):
        numerator[k] = n-r+k+1
        denominator[k] = k+1
    for p in range(2, r+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (n-r) % p
            for k in range(p-1, r, p):
                numerator[k-offset] //= pivot
                denominator[k] //= pivot
    res = 1
    for n in numerator:
        if n > 1:
            res *= n
    return res

N2 = N**2
M2 = M**2
Xpattern = [(x * (N-x)) % mod for x in range(N)]
Ypattern = [(y * (M-y)) % mod for y in range(M)]
coef = cmb(N*M-2, K-2)

print(((sum(Xpattern)*M2+sum(Ypattern)*N2)*coef)%mod)

Measured memory_bytes: 53232
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define all(x)              (x).begin(), (x).end()
#define inf                 1e18

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	ll a;
	ld b;
	cin >> a >> b;
	cout << (ll)floor((ld)a * b);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	ifstream cin("input.txt");
//	ofstream cout("output.txt");
	int q = 1; // cin >> q;
	while (q--) {
		solve();
	}
}

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

int main() {
  ll N; cin >> N;
  vector<ll> A(N),B(N),C(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  
  vector<ll> D(N);
  for (int i = 0; i < N; i++) {
    ll k = upper_bound(C.begin(), C.end(), B[N-1-i]) - C.begin();
    if (i == 0) D[N-1-i] = max(N - k,ll(0));
    else D[N-1-i] = D[N-i] + max(N - k,ll(0));
  }
  
  ll ans  = 0;
  for (int i = 0; i < N; i++) {
    ll j = upper_bound(B.begin(), B.end(), A[i]) - B.begin();
    ans += D[j];
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		String a = "#";
		String b = ".";
		Boolean c = true;
		while (true) {
			Integer h = sc.nextInt();
			Integer w = sc.nextInt();
			
			if(h == 0 && w == 0) {
				return;
			}
			
			for(Integer i = 0; i < h; i++) {
				if (i % 2 != 0) {
					c = false;
				} else {
					c = true;
				}
				
				for (Integer j = 0;j < w;j++) {
					if (c) {
						System.out.print(a);
						c = false;
					}else {
						System.out.print(b);
						c = true;
					}
				}
				System.out.println();
			}
			System.out.println();
			c = true;
		}
	}
}


Measured memory_bytes: 37268
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	char d;
	int a,b;
	int t[102]={0};
	while(cin>>a>>d>>b,a||b)t[a]=b;
	int rank[102]={0};
	int no=0;
	int mat=1e4;
	while(mat){
		int ma=0;
		no++;
		rep(i,102)if(mat>t[i])ma=max(ma,t[i]);
		rep(i,102)if(ma==t[i])rank[i]=no;
		mat=ma;
	}
	while(cin>>a)cout<<rank[a]<<endl;
}

Measured memory_bytes: 1160
import sys

while 1:
	arr = list(map(int, input().split()))
	H = arr[0]
	W = arr[1]
	
	if H == 0 and W == 0:
		break

	for i in range(H):
		for j in range(W):
			if i == 0 or i == H - 1 or j == 0 or j == W - 1:
				sys.stdout.write('#')
				if j == W - 1: print()
			else:
				sys.stdout.write('.')
	print()



Measured memory_bytes: 6304
#132a
S = str(input())

if (S[0]==S[1] and S[2]==S[3] and S[1]!=S[2]) or (S[0]==S[2] and S[1]==S[3] and S[1]!=S[2]) or (S[0]==S[3] and S[1]==S[2] and S[1]!=S[3]):
    print("Yes")
else:
    print("No")

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

typedef long long ll;

ll M(ll x) { return x % 998244353; }

ll mpow(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1) res = M(res * base);
		base = M(base * base);
		exp /= 2;
	}
	return res;
}

ll fact[300005], ifact[300005];

int N;
ll A, B, K;

ll tot;

int main() {
	scanf("%d%lld%lld", &N, &A, &B);
	scanf("%lld", &K);

	fact[0] = 1;
	for (int i = 1; i < 300005; ++i) fact[i] = M(fact[i-1] * i);
	for (int i = 0; i < 300005; ++i) ifact[i] = mpow(fact[i], 998244353 - 2);

	for (int i = 0; i <= N; ++i) {
		ll rem = (K - A * i);
		if (rem < 0 || (rem % B)) continue;
		int j = rem / B;
		if (j > N) continue;
		tot = M(tot + M(M(M(M(M(fact[N] * ifact[i]) * ifact[N-i]) * fact[N]) * ifact[j]) * ifact[N-j]));
	}

	printf("%lld\n", tot);
}

Measured memory_bytes: 4992
#include <stdio.h>

int main() {
  
  char nama[55] ;
  scanf("%s",&nama) ;

  

  nama[0] = '2';
  nama[1] = '0';
  nama[2] = '1';
  nama[3] = '8';
  
  
  printf("%s", nama);
  return 0;
}

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

ll a[10001];

void solve()
{
	ll n;
	scanf("%lld", &n);
	for (int i = 1; i <= n; ++i)
	{
		printf("%lld\n", a[i]);
	}		
}

int main()
{
	ll t = 1;
	for (ll i = 1; i < 101; ++i)
	{
		for(ll j = 1; j< 101; j++)
		{
			for(ll k = 1; k<101; k++)
			{
				ll e = (i+j)*(i+j) + (j+k)*(j+k) + (k+i)*(k+i);
				if(e%2==0)
				{
					if(e/2<10001)
					{
						a[e/2]++;
					}
				}
			}
		}
	}
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(3*n);
	rep(i,3*n) scanf("%d",&a[i]);

	sort(a.rbegin(),a.rend());

	lint ans=0;
	rep(i,n) ans+=a[2*i+1];
	printf("%lld\n",ans);

	return 0;
}


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

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

  int a,b;cin>>a>>b;
  if(b%a==0){
    cout<<b+a<<endl;
  }else{
    cout<<b-a<<endl;

  }

  return 0;
}


Measured memory_bytes: 256
import math
A,B,H,M = map(int, input().split())
elapsed = H*60+M
ma = (elapsed%60)*6
ha = elapsed*0.5
theta = abs(ha-ma)
dist = math.sqrt(A*A+B*B-2*A*B*math.cos(theta*(math.pi)/180))
print(dist)

Measured memory_bytes: 62268
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n;

	cin >> n;

	int A[n];
	int q, b, e, k;
	int count;

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

	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> b >> e >> k;
		count = 0;

		for (int j = b; j < e; j++) {
			if (A[j] == k) count++;
		}
		cout << count << endl;
	}
}




Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    string a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    //Sunny, Cloudy, Rainy
    //*
    if( a == "Sunny" ){
        cout << "Cloudy" << endl;
    } else if (a == "Cloudy" ){
        cout << "Rainy" << endl;
    } else if (a == "Rainy" ){
        cout << "Sunny" << endl;
    } else {
        cout << "Snowy" << endl;
    }
    //*/
    
    //cout << ((floor(a / 2) + fmod(a, 2)) / a) << endl;
    
    return 0; 
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;


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

int N; cin >> N;
vector<int> H(N); rep(i,0,N) cin >> H[i];


for (int i = N-1; i >= 1; --i) { 
    int diff = H[i-1] - H[i];
    if (diff >= 2) {cout << "No" << "\n"; return 0;}
    if (diff == 1) --H[i-1];
}
cout << "Yes" << "\n";

return 0;
}

// 境界，出力文字列 チェック



Measured memory_bytes: 640
#include <cstdio>
#include <queue>
const int N = 200005;
int n, m, cnt[2][N], head[N], tot, vis[N];
char buf[N];
std::queue<int> q;
struct edge { int to, nxt;} e[ N << 1];
void addedge(int x, int y) {
	e[++tot] = (edge) { y, head[x] }; head[x] = tot;
}
int main() {
	std::scanf("%d%d", &n, &m);
	std::scanf("%s", buf + 1);
	for (int i = 1; i <= m; i++) {
		int x, y;
		std::scanf("%d%d", &x, &y);
		if (x == y) cnt[buf[x] - 'A'][x] = 0x3f3f3f3f;
		else addedge(x, y), addedge(y, x), ++cnt[buf[x] - 'A'][y], ++cnt[buf[y] - 'A'][x];
	}
	for (int i = 1; i <= n; i++) if (!(cnt[0][i] && cnt[1][i])) vis[i] = 1, q.push(i);
	while (!q.empty()) {
		int tmp = q.front(); q.pop();
		for (int i = head[tmp]; i; i = e[i].nxt) if (!vis[e[i].to]) {
			--cnt[buf[tmp] - 'A'][e[i].to];
			if (!(cnt[0][e[i].to] && cnt[1][e[i].to])) vis[e[i].to] = 1, q.push(e[i].to);
		}
	}
	int ans = 1;
	for (int i = 1; i <= n; i++) ans &= vis[i];
	std::puts(ans ? "No" : "Yes");
	return 0;
} 

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;



int main() {
	vector<ll> a;
	ll n, m, l, r, i, j;

	cin >> n >> m;
	SIZE(a, n + 1);

	rep(i, m) {
		cin >> l >> r;
		l--;
		r--;
		a[l]++;
		a[r + 1]--;
	}
	j = 0;
	if (a[0] == m)j++;
	repj(i,1, n) {
		a[i] += a[i - 1];
		if (a[i] == m)j++;
	}

	cout << j << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!
    val k = readInteger()

    // dp[i][smaller][k] 上位桁からi桁目に0がK個あるときの場合の数
    val dp = Array(s.length + 1) { Array(2) { LongArray(k + 2) } }
    dp[0][0][0] = 1
// 桁dpのお気持ち
//    for (i in s.indices) {
//        val n = s[i] - '0'
//        for (d in 0..9) {
//            dp[i + 1][1] = dp[i][1]
//        }
//
//        for (d in 0 until n) {
//            dp[i + 1][1] = dp[i][0]
//        }
//
//        dp[i + 1][0] = dp[i][0]
//    }

    for (i in s.indices) {
        val n = s[i] - '0'
        for (j in 0..k) {
            for (d in 0..9) {
                if (d == 0) {
                    dp[i + 1][1][j] += dp[i][1][j]
                } else {
                    dp[i + 1][1][j + 1] += dp[i][1][j]
                }
            }

            for (d in 0 until n) {
                if (d == 0) {
                    dp[i + 1][1][j] += dp[i][0][j]
                } else {
                    dp[i + 1][1][j + 1] += dp[i][0][j]
                }
            }

            if (n == 0) {
                dp[i + 1][0][j] += dp[i][0][j]
            } else {
                dp[i + 1][0][j + 1] += dp[i][0][j]
            }
        }
    }
    out.println(dp[s.length][1][k] + dp[s.length][0][k])
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 34208
#include<bits/stdc++.h>
#define pb push_back
#define FAST ios::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);
typedef long long ll;
using namespace std;

int main()
{
    FAST
    int n,a;
    cin>>n;
    map<int,int>m;
    map<int,int>::iterator it;
    for(int i=1;i<n;i++)
    {
        cin>>a;
        m[a]++;
    }
    for(int i=1;i<=n;i++)
        cout<<m[i]<<endl;
    return 0;
}



Measured memory_bytes: 13036
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    double N;
    cin >> N;
    double vol = (N / 3) * (N / 3) * (N / 3);
    cout << fixed << setprecision(10) << vol << endl;
    return 0;
};

Measured memory_bytes: 256
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-
a,b,c,d = LIST()

while 0 == 0:
    c -= b
    if c <= 0:
        print("Yes")
        break
    a -= d
    if a <= 0:
        print("No")
        break

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

int main() {
  int N, M;
  int A[200010], B[200010];

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

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

  int ans = 0;
  int cur = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] == B[cur]) {
      ++cur;
      if (cur == M) {
        ans = 1;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4592
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	
	vector<int> a(4);
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a);
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */
int main()
{
	int		a,ans = 0;
	
	scanf("%d", &a);

	printf("%d\n",a*a*a);


	return 0;
}



Measured memory_bytes: 2108
#include <string>
#include <cstring>
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;
string s;
int k;
set <string> T;
int main(){
	cin >> s >> k;
	int n = s.length();
	for (int i = 0;i < n;i++){
		for (int num = 1;num <= k;num++){
			T.insert(s.substr(i,num));
		}
	}
	n = 0;
	for (set <string>::iterator it = T.begin();it != T.end();it++){
		n++;
		if (n == k){
			cout << *it << endl;
			break;
		}
	}
	return 0;
} 

Measured memory_bytes: 1664
num = int(input())
values = list(map(int, input().split()))
count = 0
for index, value in enumerate(values):
    if value < 0:
        count += 1
    values[index] = abs(value)

if count % 2 == 0:
    print(sum(values))
else:
    print(sum(values) - 2*min(values))

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
#define ll long long int

int main(){
    double D,T,S;
    scanf("%lf%lf%lf",&D,&T,&S);
    double t = D/S;
    if(t <= T){
        printf("Yes\n");
    }else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int t[20][20] = {};
int dp[(1LL << 16) + 10];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin >> n, n){
        rep(i, 0, n){
            rep(j, 0, n + 1){
                cin >> t[i][j];
            }
        }
        rep(i, 0, (1LL << 16) + 10) dp[i] = INF;
        dp[0] = 0;
        for(int mask = 0; mask < (1LL << n); mask++){
            rep(i, 0, n){
                if(mask & (1LL << i)) continue;
                int MIN = t[i][0];
                rep(j, 0, n){
                    if(mask & (1LL << j)){
                        chmin(MIN, t[i][j + 1]);
                    }
                }
                chmin(dp[mask | (1LL << i)], dp[mask] + MIN);
            }
        }
        cout << dp[(1LL << n) - 1] << endl;
    }
}


Measured memory_bytes: 3752
from collections import Counter
N = int(input())
cnt = sorted(Counter(list(map(int,input().split()))).items(), reverse=True)
ans = []
for k,v in cnt:
    if v >= 4 and ans==[]:
        print(k * k)
        exit()
    elif v >= 2:
        ans.append(k)
        if len(ans) >= 2:
            print(ans[0] * ans[1])
            exit()
print(0)

Measured memory_bytes: 21412
import itertools
s=input()
ans=0
rep=len(s)-1

for i in itertools.product(["+", ""], repeat=rep):
    temp=""
    #print(i)
    for j in range(rep):
        temp+=s[j]
        temp+=i[j]
    temp+=s[-1]
    ans+=eval(temp)
    #print(temp)

print(ans)


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

int main() {
    int N;
    cin >> N;
    int temp;
    while (N>=10) {
        N %= 10;
    }
    temp = N;
    string ans = "hon";
    if (temp==3) {
        ans = "bon";
    }
    else if (temp==0 or temp==1 or temp==6 or temp==8) {
        ans = "pon";
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N + 2];
  a[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  a[N + 1] = 0;

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

  for (int i = 1; i <= N; i++) {
    cout << sum - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]) << endl;
  }

  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

double n,m,d,ans;
signed main(){
	//(n-d)*2*(n^(m-2))*(m-1)　合計
	//n^m　割る数
	//(n-d)*2*(m-1)/n^2
	cin>>n>>m>>d;
	if(d==0)printf("%.15lf",(n-d)*(m-1.0)/(n*n));
	else printf("%.15lf",(n-d)*2.0*(m-1.0)/(n*n));
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int check(double a){
	int ad = a;
	if(a > ad) ad++;
	return ad;
}

int main(){
	int a, b;
	cin >> a >> b;
	double ar1 = 100.0/8.0;
	double br1 = 100.0/10.0;
	double a1 = a * ar1;
	int aa = check(a1);
	double a2 = a1 + ar1;
	int aaa = check(a2);
	double b1 = b * br1;
	int bb = check(b1);
	double b2 = b1 + br1;
	int bbb = check(b2);
	int mi = 1e8;
	for(int i = aa; i < aaa; i++){
		for(int j = bb; j < bbb; j++){
			if(i == j){
				mi = min(mi, i);
			}
		}
	}
	if(mi == 1e8) cout << -1 << endl;
	else cout << mi << endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }






int main() {
  cout<<fixed<<setprecision(10);


  ll N;cin>>N;
  vint A(N);rep(i,N)cin>>A[i];
  vint B(N);rep(i,N)cin>>B[i];

  ll sum = 0;
  vint diff(N);rep(i,N){diff[i] = A[i]-B[i];sum+=diff[i];}
  // 無理だったら抜ける
  if(sum<0){
    cout << -1 << endl;
    return 0;
  }
  vsort(diff);


  ll ans = 0;

  ll left=0;
  ll right=N-1;
  bool can = true;
  ll pool = 0;
  while(true){
    // if(diff[right]<=0){
    //   break;
    // }
    if(diff[left]>=0 && pool>=0){
      break;
    }
    if(pool<0){
      pool += diff[right];
      right--;
    }else{
      pool += diff[left];
      left++;
    }

  }

  ans = N-1-right + left;
  cout << ans << endl;
}

















//


Measured memory_bytes: 2560
#include <stdio.h>
 
int main(){
int a,b,c,x,y;
int ab = 0;
int i = 0;
scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
if(a + b> c * 2){
	if(x > y){
	for(i;i < y * 2;i++){
	ab += c;
}
	if(a > c * 2){
	ab += c * (x - y) * 2;
}else{
	ab += a * (x - y);
}
    }
	if(y > x){
	for(i;i < x * 2;i++){
	ab += c;
}
	if(b > c * 2){
	ab += c*(y - x) * 2;
}else{
	ab += b*(y - x);
}
    }if(x == y){
      for(i = 0;i < x;i++){
    ab += c * 2;
    }
    }
printf("%d",ab);
}
else{
	printf("%d\n",a * x + b * y);
}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define L class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<L T>void pr1(T a){cout<<a;ln;}
template<L T,L T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<L T,L T2,L T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<L T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

struct HL {
  static const int MD=20;
  int N,NE;
  vector<vector<int> > E,Cs;
  vector<int> D,S,B,C,Ci;
  vector<vector<int> > Q;
  void init(int N){this->N=N,NE=0,E.clear(),E.resize(N);Cs.clear(),Cs.resize(N);D=S=B=C=Ci=vector<int>(N,0);Q.clear();rep(i,MD+1)Q.pb(vector<int>(N,0));}
  void add_edge(int a,int b){E[a].pb(b),E[b].pb(a);NE++;}
  void dfs(int cur,int pre) {
    Q[0][cur]=pre;S[cur]=1;C[cur]=Ci[cur]=-1;B[cur]=cur;D[cur]=(pre==-1)?0:(D[pre]+1);
    rep(i,E[cur].size())if(E[cur][i]!=pre){int r=E[cur][i];dfs(r,cur);S[cur]+=S[r];if(C[cur]==-1||S[r]>S[C[cur]])C[cur]=r,Ci[cur]=i;}
  }
  void dfs2(int cur,int pre) {
    if(pre!=-1&&C[pre]==cur)B[cur]=B[pre];Cs[B[cur]].pb(cur);
    rep(i,E[cur].size())if(E[cur][i]!=pre)dfs2(E[cur][i],cur);
  }
  P lca(int a,int b) {
    int aa=a,bb=b;if(D[aa]>D[bb])swap(aa,bb);
    rrep(i,20)if(D[bb]-D[aa]>=1<<i)bb=Q[i][bb];
    rrep(i,20)if(Q[i][aa]!=Q[i][bb])aa=Q[i][aa],bb=Q[i][bb];
    return P((aa==bb)?aa:Q[0][aa],D[a]+D[b]-2*D[(aa==bb)?aa:Q[0][aa]]);
  }
  void decomp(int root=0){dfs(root,root);dfs2(root,root);rep(i,MD)rep(x,N)Q[i+1][x]=Q[i][Q[i][x]];}
};

void Main() {
  int n;
  R n;
  HL hl;
  hl.init(n);
  rep(i,n) {
    int k;
    R k;
    rep(j,k) {
      int x;
      R x;
      hl.add_edge(i,x);
    }
  }
  hl.decomp();
  int m;
  R m;
  while(m--) {
    int x,y;
    cin >> x >> y;
    pr(hl.lca(x,y).F);
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 25768
// Example program
#include <bits/stdc++.h>
using namespace std;
bool checked[3][3];
int main()
{
  int n;
  string s;
  cin>>n>>s;
  int cnt=0;
  for(int i=0;i<n-2;i++)
  {
      if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
n = gets.chomp("").to_i
x = []
y = []
n.times do |i|
  x[i],y[i] = gets.split.map(&:to_i)
end

ans = 0.0
(n-1).times do |i|
  (n-i-1).times do |t|
    yoko = (x[i] - x[i+1+t])*(x[i] - x[i+1+t])
    tate = (y[i] - y[i+1+t])*(y[i] - y[i+1+t])
    ans += (yoko+tate)**(1/2.0)
  end
end

puts (ans*2)/n

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  while (true) {
    int n, x;
    fscanf(stdin, "%d %d", &n, &x);
    if (n == 0 && x == 0) { break; }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = i + 1; j <= n; ++j) {
        int k = x - i - j;
        if (k > i && k > j && k <= n) {
          ++cnt;
        }
      }
    }
    fprintf(stdout, "%d\n", cnt);
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = 0;
	rep(i, n) {
		if (a[a[i] - 1] == i + 1) ans++;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,0,sizeof(p))
#define mp make_pair

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

int main(){
	string s;
	cin>>s;
	int temp=0;
	for (int i=0;i<s.size();i++){
		if (s[i]=='o')++temp;
	}
	if (temp+15-s.size()>=8) {
		cout<<"YES"<<endl;
	} else {
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int parent (int);
int left(int);
int right(int);
int main(void){
    int H,i,A[MAX+1];
    scanf("%d",&H);
    for(i=1;i<=H;i++){
        scanf("%d",&A[i]);
    }
    for(i=1;i<=H;i++){
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i)>=1)
            printf("parent key = %d, ",A[parent(i)]);
        if(left(i)<=H)
            printf("left key = %d, ",A[left(i)]);
        if(right(i)<=H)
            printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }
    return 0;
}
int parent (int i){
    return i/2;
}
int left(int i){
    return 2*i;
}
int right(int i){
    return 2*i+1;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int,int> pii;
const int mod = (int) 1000000007;
const int inf = (int) 2e18;
int par[200010], Rank[200010];

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

void merge(int a, int b){
  a = find(a);
  b = find(b);
  if(a == b) return;
  if(Rank[a] > Rank[b]){
    par[b] = a;
    Rank[a] += Rank[b];
  } else {
    par[a] = b;
    Rank[b] += Rank[a];
  }
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
  int n, m, x, y, r=0, mr;
  cin >> n >> m;
  for(int i=1; i<=n; i++)
  par[i] = -1 , Rank[i] = 1;
  vector<bool> flag(n+1, false);
  while(m--){
    cin >> x >> y;
    merge(x, y);
    flag[x] = true;
    flag[y] = true;
  }
  vector<int> v;
  for(int i=1; i<=n; i++){
      if(par[i] < 0 && flag[i]){
          v.push_back(Rank[i]);
      }
  }
  if(v.size() > 0){
      while(v.size()){
          sort(v.begin(), v.end());
          mr = v[0];
          for(int i=0; i<v.size(); i++){
              v[i] -= mr;
              if(v[i] == 0){
                  v.erase(v.begin() + i);
                  i--;
              }
          }
          r += mr;
      }
      cout << r << "\n";
  } else {
      cout << 1 << "\n";
  }
  return 0;
}


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

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

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

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

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

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

int main()
{
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] = abs(a[i] - x);
    }
    ll ans = a[0];
    for (int i = 1; i < n; i++)
    {
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,stack;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
   for(i=1;i<=n;i++){
    stack=A[i];
    j=i-1;
    while(j>=0 && A[j]>stack){
      A[j+1]=A[j];
      j--;
      A[j+1]=stack;
    }
    trace(A,n);
  }
  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
string s;
int t(char s){return s-'0';}
int main()
{
    cin>>s;
    int ans=1e9;
    for(int i=2;i<s.size();i++){
        int x=t(s[i-2])*100+t(s[i-1])*10+t(s[i]);
        ans=min(ans,abs(x-753));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256