akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;
const int SIZE = 100001;
vector<int> adj[SIZE];
vector<int> path;
int mid, p;
int N;

void dfs(int here, int parent)
{
	path.push_back(here);
	if (here == N) {
		p = path[(path.size() - 1) / 2];
		mid = path[(path.size() + 1) / 2];
	}
	for (int i = 0; i < adj[here].size(); i++) {
		int next = adj[here][i];
		if (next == parent)
			continue;
		dfs(next, here);
	}
	path.pop_back();
}

int dfs2(int here, int parent)
{
	int ret = 1;
	for (int i = 0; i < adj[here].size(); i++) {
		int next = adj[here][i];
		if (next == parent)
			continue;
		ret += dfs2(next, here);
	}
	return ret;
}

int main()
{
	int a, b;
	scanf("%d", &N);
	for (int i = 0; i < N - 1; i++) {
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1, 0);
	if (2 * dfs2(mid, p) >= N)
		printf("Snuke\n");
	else
		printf("Fennec\n");
}

Measured memory_bytes: 10872
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

# 数値→アルファベット
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

def main():
    N = I()
    print(num2alpha(N).lower())


if __name__ == '__main__':
    main()



Measured memory_bytes: 10952
import numpy as np
i8 = np.int64
i4 = np.int32

def main():
    stdin = open('/dev/stdin')
    H, W, K = map(int, stdin.readline().split())
    a = np.empty((H, W), dtype=i8)
    line = 0
    count = 1
    for i in range(H):
        s = stdin.readline()
        list = []
        for j, c in enumerate(s):
            if c == '#':
                list.append(j)
        if len(list) > 0:
            list.append(W)
            prev = 0
            for l in list[1:]:
                for x in range(prev, l):
                    for y in range(line, i + 1):
                        a[y, x] = count
                prev = l
                count += 1
            line = i + 1
    for y in range(line, H):
        a[y] = a[line - 1]

    for i in range(H):
        print(' '.join(map(str, a[i].tolist())))
        
main()

Measured memory_bytes: 14464
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#define ll long long
using namespace std;
const int maxn=200005;

int n,a[maxn],lef[maxn];
ll ans=0;

int main(){
	scanf("%d",&n);
	for(int i=1,las=0;i<=n;i++){
		scanf("%d",a+i),lef[i]=las;
		if(a[i]) las=i;
	}
	
	for(int i=1,now,j;i<=n;i++){
		now=a[i];
		
		for(j=lef[i];j;now^=a[j],j=lef[j]) if(now&a[j]) break;
		
		ans+=(ll)(i-j);
		
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


s = S()
n = len(s)

ans = 0

for bit in range(1 << (n - 1)):

    f = s[0]

    for i in range(n - 1):
        if (bit >> i) & 1:

            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)


Measured memory_bytes: 74452
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> order(n);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		order[a - 1] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cout << order[i] << " ";
	}
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    cout << N/3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int sx, sy, tx, ty;
int main() {
	cin >> sx >> sy >> tx >> ty;
	int ex = tx - sx, ey = ty - sy;
	for (int i = 0; i < ex; i++) cout << 'R';
	for (int i = 0; i < ey; i++) cout << 'U';
	for (int i = 0; i < ex; i++) cout << 'L';
	for (int i = 0; i < ey; i++) cout << 'D';
	cout << 'D';
	for (int i = 0; i < ex + 1; i++) cout << 'R';
	for (int i = 0; i < ey + 1; i++) cout << 'U';
	cout << 'L';
	cout << 'U';
	for (int i = 0; i < ex + 1; i++) cout << 'L';
	for (int i = 0; i < ey + 1; i++) cout << 'D';
	cout << 'R';
	cout << endl;
	return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=550;
//ここまでテンプレ
int main(){
	ll N,M,Q;
	cin>>N>>M>>Q;
	ll B[SIZE][SIZE]={};
	for(int i=0;i<M;i++){
		ll l,r;
		cin>>l>>r;
		B[l][r]+=1;
	}
	for(int i=0;i<SIZE;i++)
		for(int j=1;j<SIZE;j++)
			B[i][j]+=B[i][j-1];
	for(int i=1;i<SIZE;i++)
		for(int j=0;j<SIZE;j++)
			B[i][j]+=B[i-1][j];
	while(Q--){
		int p,q;
		cin>>p>>q;
		cout<<B[N+1][q]-B[p-1][q]<<endl;
	}
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

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

ll yen[111111];
ll snuke[111111];

vector<vector<pair<ll,pair<ll,ll>>>> v(111111);

int main(){
	
	int n,m,s,t;cin >> n >> m >> s >> t;
	s--;t--;
	
	for(int i = 0;i < m;i++){
		ll a,b,c,d;cin >> a >> b >> c >> d;
		a--;b--;
		v[a].push_back(make_pair(b,make_pair(c,d)));
		v[b].push_back(make_pair(a,make_pair(c,d)));
	}
	
	for(int i = 0;i < 111111;i++){
		yen[i] = snuke[i] = LLINF;
	}
	
	yen[s] = 0;
	snuke[t] = 0;
	
	priority_queue<P,vector<P>,greater<P>> pq;
	
	pq.push(make_pair(0,s));
	
	while(!pq.empty()){
		
		P now = pq.top();pq.pop();
		ll node = now.second;
		ll d = now.first;
		
		if(yen[node] < d)continue;
		
		for(int i = 0;i < v[node].size();i++){
			int aite = v[node][i].first;
			if(yen[aite] > d + v[node][i].second.first){
				yen[aite] = d + v[node][i].second.first;
				pq.push(make_pair(yen[aite],aite));
			}
		}
	}
	
	pq.push(make_pair(0,t));
	
	while(!pq.empty()){
		
		P now = pq.top();pq.pop();
		
		ll node = now.second;
		ll d = now.first;
		
		if(d > snuke[node])continue;
		
		for(int i = 0;i < v[node].size();i++){
			int aite = v[node][i].first;
			if(snuke[aite] > d + v[node][i].second.second){
				snuke[aite] = d + v[node][i].second.second;
				pq.push(make_pair(snuke[aite],aite));
			}
		}
	}
	
	vector<pair<ll,ll>> ans;
	
	for(int i = 0;i < n;i++){
		ans.push_back(make_pair(yen[i] + snuke[i],i));
	}
	
	sort(ALL(ans));
	
	
	int cou = 0;
	for(int i = 0;i < n;i++){
		while(ans[cou].second < i)cou++;
		cout << (1000000000000000 - ans[cou].first) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 14836
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

int main()
{
    int a;
    scanf("%d",&a);
    if(a<1200)
        printf("ABC\n");
    else
        printf("ARC\n");
    return 0;
}

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

int n, maxn = 1000000;

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		string S = to_string(i);
		string T = to_string(n - i);
		int sum = 0;
		for (int j = 0; j < S.size(); j++) sum += (S[j] - '0');
		for (int j = 0; j < T.size(); j++) sum += (T[j] - '0');
		maxn = min(maxn, sum);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const int inf=2147483647;
const long long Mod=1000000007;
struct ball
{
	int c,w;
}a[200010];
int n,b[200010],s[200010],cnt;
bool used[200010],can[200010];
long long fac[200010],inv[200010];
bool cmp(ball x,ball y)
{
	return x.w<y.w;
}
long long pw(long long x,long long y)
{
	long long res=1;
	while (y)
	{
		if (y&1)
		{
			res=res*x%Mod;
		}
		x=x*x%Mod;
		y>>=1;
	}
	return res;
}
int main()
{
	int x,y;
	scanf("%d%d%d",&n,&x,&y);
	fac[0]=1;
	for (int i=1;i<=n;i++)
	{
		fac[i]=fac[i-1]*i%Mod;
	}
	inv[n]=pw(fac[n],Mod-2);
	for (int i=n-1;i>=0;i--)
	{
		inv[i]=inv[i+1]*(i+1)%Mod;
	}
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].c,&a[i].w);
	}
	sort(a,a+n,cmp);
	int mn,mn2,k;
	mn=mn2=inf;
	for (int i=0;i<n;i++)
	{
		if (!used[a[i].c])
		{
			used[a[i].c]=true;
			b[a[i].c]=a[i].w;
			if (mn>a[i].w)
			{
				mn2=mn;
				mn=a[i].w;
				k=a[i].c;
			}
			else if (mn2>a[i].w)
			{
				mn2=a[i].w;
			}
		}
	}
	//cout<<mn<<" "<<k<<" "<<mn2<<endl;
	for (int i=1;i<=n;i++)
	{
		if (!used[i])
		{
			continue;
		}
		if (i==k)
		{
			//cout<<b[i]<<" "<<mn2<<" "<<b[i]+mn2<<endl;
			if (b[i]+mn2<=y)
			{
				//cout<<i<<endl;
				can[i]=true;
			}
		}
		else
		{
			//cout<<b[i]<<" "<<mn<<" "<<b[i]+mn<<endl;
			if (b[i]+mn<=y)
			{
				//cout<<i<<endl;
				can[i]=true;
			}
		}
	}
	for (int i=0;i<n;i++)
	{
		if (!can[a[i].c])
		{
			continue;
		}
		if (a[i].c==k)
		{
			if (a[i].w+mn2<=y)
			{
				s[a[i].c]++;
				cnt++;
				continue;
			}
		}
		else
		{
			if (a[i].w+mn<=y)
			{
				s[a[i].c]++;
				cnt++;
				continue;
			}
		}
		if (a[i].w+b[a[i].c]<=x)
		{
			s[a[i].c]++;
			cnt++;
		}
	}
	long long ans=fac[cnt];
	for (int i=1;i<=n;i++)
	{
		if (!can[i])
		{
			continue;
		}
		//cout<<i<<" "<<s[i]<<endl;
		ans=ans*inv[s[i]]%Mod;
		//cout<<ans<<endl;
	}
	printf("%lld\n",ans);
    return 0;
}
//绿蚁新醅酒，红泥小火炉。
//晚来天欲雪，能饮一杯无？
//——白居易《问刘十九》

Measured memory_bytes: 6912
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
#１行に数値一つならparseInt(readline())
#１行に数値複数ならparseMap(split(readline()))を行数分。
# 例：n,k = readline() |> split |> parseMap
#      a = readline() |> split |> parseMap
function main()
  #a = parseInt(readline())
  X,Y = parseMap(split(readline()))
  #println("$X,$Y")
  if X == 0 && Y == 0
      println("Yes")
      exit()
  end
  if Y < 2*X || Y > 4*X
      println("No")
      exit()
  end
  if Y % 2 != 0
      println("No")
      exit()
  end
  if (Y-2*X) % 2 == 0 && (4*X-Y) % 2 == 0
    y0 = (Y-2*X)/2
    x0 = (4*X-Y)/2
    if x0 > 0 && y0 > 0
      println("Yes")
    else
      if x0==0 && y0 > 0
        println("Yes")
      elseif y0==0 && x0 > 0
        println("Yes")

      else
        println("No")
      end
    end
  end
end
main()


Measured memory_bytes: 162624
fn main() {
    let (mut n, k) = read_tuple::<i64>();

    let mut ans = 1;
    while n / k != 0 {
        ans += 1;
        n /= k;
    }

    println!("{:?}", ans);
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
const long long INF = 1LL << 60;
ll mod = 1e9 + 7;

int n;
ll h[100100];
ll dp[100100];

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

int main()
{
    cin >> n;
    rep(i, n) cin >> h[i];
    rep(i, 100100) dp[i] = INF;
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        chamin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1)
            chamin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;

    return 0;
}

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

#define ll long long int

using namespace std;

ll n=0,a=0,b=0, *o;

ll eval(ll x){
  ll temp=0, ct=0;
  for(size_t i=0; i<n; ++i){
    temp = o[i] - b*x;

    if(!(temp <= 0)){
      //cout<<"temp = "<<ceil(temp/a);
      ct+= ceil(double(temp)/double(a));
    }
  }
  //cout<<"**-*-*-*-*****-*-*----------***"<<ct<<endl;
  return ct;
}

bool check(ll x) {
  return(eval(x) <= x);
}

ll b_search(ll l, ll r){
  ll mid =0;
  //cout<<l<<r<<"============================="<<endl;
  while(l<r){
    mid = l+(r-l)/2;
    //cout<<mid<<"))))))))))))))))))"<<endl;
    if(check(mid)){
      //cout<<"midmidmidmidmidmidmid"<<mid<<endl;
      r = mid;
    }
    else{
      l = mid+1;
    }
  }
  return r;
}

int main() {
    cin>>n>>a>>b;
    a-=b;
    o = new ll[n];
    for (size_t i = 0; i < n; ++i) {
      cin>>o[i];
    }

    cout<<b_search(1, 1e9+10);
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
  int n,m,c;
  scanf("%d%d%d",&n,&m,&c);
  int i;
  int j;
  int ans = 0;
  int sum = 0;
  int a[n][m];
  int b[m];
  i = 0;
  while (i < m)
  {
    scanf("%d",&b[i]);
    i++;
  }
  i = 0;
  while (i < n)
  {
    j = 0;
    while (j < m)
    {
      scanf("%d",&a[i][j]);
      j++;
    }
    i++;
  }
  i = 0;
  j = 0;
  while (i < n)
  {
    j = 0;
    sum = 0;
    while (j < m)
    {
      sum += a[i][j] * b[j];
      j++;
    }
    if (sum + c > 0)
    {
      ans += 1;
    }
    i++;
  }
  printf("%d",ans);
}

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

#define int long long

int ans;
string s;

int get(int msk) {
	int res = 0, u = 0, last = 0;
	for (int i = 0; i < s.size(); i++) {
		last = 10 * last + (s[i] - '0');
		if (msk & (1LL << i))
			res += last, last = 0;
	}
	return res + last;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	for (int msk = 0; msk < (1LL << ((int)s.size() - 1)); msk++)
		ans += get(msk);
	cout << ans << endl;
}

Measured memory_bytes: 256
N=input()
N=int(N)
S=[0]*N
for i in range(N):
    S[i]=input()

M=input()
M=int(M)
T=[0]*M
for i in range(M):
    T[i]=input()

A=[]
for i in S:
    A.append(S.count(i)-T.count(i))

print(max(0,max(A)))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;

int n;
char buf[100000];
vector<string> ans;

int main() {
  fgets(buf, sizeof(buf), stdin);
  char *p = strchr(buf, '\n');
  if (p) *p = '\0';

  n = strlen(buf);
  string word;
  for (int i=0; i<n; i++) {
    char c = buf[i];
    if (c == ' ' || c == ',' || c == '.') {
      if (3 <= word.size() && word.size() <= 6) {
        ans.push_back(word);
      }
      word = "";
    } else word += c;
  }

  if (3 <= word.size() && word.size() <= 6) {
    ans.push_back(word);
  }

  
  if (!ans.empty()) {
    printf("%s", ans[0].c_str());
    for (int i=1; i<ans.size(); i++) {
      printf(" %s", ans[i].c_str());
    }
  }
  puts("");
}

Measured memory_bytes: 2780
#include<cstdio>
#include<cmath>

int main()
{
  long long n;
  int ans=0;
  scanf("%lld",&n);
  if(n==1){
    printf("0");
    return 0;
  }
  for(int i=2;i<sqrt(n)+2;i++){
    int c=0;
    int d=0;
    int e=0;
    while(1){
      if(n%i)break;
      ++c;
      n/=i;
      //printf("%lld\n",n);
    }
    //if(c)printf("%d^%d\n",i,c);
    while(c>d){
      c-=++d;
      ++e;
    }
    ans+=e;
  }
  ans+=(n!=1);
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 2152
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var rd = bufio.NewReader(os.Stdin)

// 標準入力から1行読み込む。
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := rd.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// 渡された文字列(空白区切りの整数の並び)をintのスライスにする。
func intsFromLine(line string) []int {
	slice := make([]int, 0, 1000)
	for _, str := range strings.Split(line, " ") {
		num, err := strconv.Atoi(str)
		if err != nil {
			panic(err)
		}
		slice = append(slice, num)
	}
	return slice
}

func main() {
	total := 0

	line := readLine()
	nums := intsFromLine(line)

	_, k := nums[0], nums[1]

	line = readLine()
	nums = intsFromLine(line)
	sort.Ints(nums)

	for i := 0; i < k; i++ {
		total += nums[i]
	}

	fmt.Println(total)
}

Measured memory_bytes: 1804
import itertools
H,W = map(int,input().split())
S = [input() for _ in range(H)]
a = [[0 if cell=='.' else '#' for cell in row] for row in S]

for i in range(H):
  for j in range(W):
    if S[i][j] != '#':
      continue
    for dx,dy in itertools.product([-1,0,1],repeat=2):
      x = i+dx
      y = j+dy
      if x < 0 or x >= H:
        continue
      if y < 0 or y >= W:
        continue
      if S[x][y] == '#':
        continue
      a[x][y] += 1

      
for row in a:
  print(*row,sep='')


Measured memory_bytes: 3444
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(input())
    A, B = [int(x) for x in input().split()]

    for i in range(A, B + 1):
        if i % K == 0:
            print("OK")
            return
    print("NG")

    

if __name__ == '__main__':
    main()



Measured memory_bytes: 9096
#include <vector>
//#include <boost/optional.hpp>
//using boost::optional;
//auto const none = boost::none;

struct None {} none;
template<class T> struct optional {
  bool b; T t;
  optional() : b(false), t() {}
  optional(None rhs) : b(false), t() { (void)rhs; }
  optional(T t) : b(true), t(t) {}
  operator bool() const { return b; }
  T& operator*() { return t; }
  auto& operator=(None rhs) { (void)rhs; b=false; return *this; }
  auto& operator=(T const& rhs) { b=true; t = rhs; return *this; }
};


template <class T, class Op> struct OptionalSegmentTree { // (M, op) : monoid
  using size_t = std::size_t;
  Op o; size_t n; std::vector<optional<T>> dat;
  OptionalSegmentTree() {}
  OptionalSegmentTree(Op o, size_t n_=0) : o(o), n(0), dat() { init(n_); }
  void init(size_t const& n_) { n=1; while(n<n_) n<<=1; dat.assign(2*n, none); }
  void build(std::vector<T> const& v) {
    size_t n_ = v.size(); init(n_);
    for(size_t i=0;i<n_;++i) dat[n+i] = v[i];
    for(size_t i=n;i-->0;) dat[i] = op(dat[i<<1], dat[i<<1|1]);
  }
  auto op(optional<T> x, optional<T> y) {
    optional<T> r;
    if(x) if(y) r = o(*x, *y); else r = x; else r = y;
    return r;
  }
  auto operator[](size_t const& i) const { return dat[n+i]; }
  void update(size_t k) { while(k>>=1) dat[k] = op(dat[k<<1], dat[k<<1|1]); }
  void set(size_t k, T const& v) { dat[k+=n] = v; update(k); }
  auto get(size_t a, size_t b) { // [a. b)
    optional<T> l, r;
    for(a+=n, b+=n; a<b; a>>=1, b>>=1) {
      if(a & 1) l = op(l, dat[a++]);
      if(b & 1) r = op(dat[--b], r);
    }
    return op(l, r);
  }
};
template <class T, class Op> auto make_optseg(Op op, std::size_t n=0) { return OptionalSegmentTree<T, Op>(op, n); }



#include <iostream>
#include <limits>

void dsl_2_a() { // RmQ
  std::cin.tie(nullptr); std::cout.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  using namespace std;
  constexpr int inf = numeric_limits<int>::max();
  int n, q; cin >> n >> q;
  vector<int> c(q), x(q), y(q);
  for(int i=0;i<q;++i) cin >> c[i] >> x[i] >> y[i];
  auto seg = make_optseg<int>([](int a, int b) { return min(a,b); }, n);
  for(int i=0;i<q;++i) {
      if(c[i] == 0) seg.set(x[i], y[i]);
      else {
        auto m = seg.get(x[i], y[i]+1);
        cout << (m?*m:inf) << '\n';
      }
  }
}

signed main() {

  dsl_2_a();

  return 0;
}


Measured memory_bytes: 6000
using System;

namespace A___HEX
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var x = char.Parse(input[0]);
            var y = char.Parse(input[1]);
            if (x < y)
            {
                Console.WriteLine("<");
            }
            else if (x > y)
            {
                Console.WriteLine(">");
            }
            else
            {
                Console.WriteLine("=");
            }
        }
    }
}

Measured memory_bytes: 11220
N, Q = list(map(int, input().split()))
s = input()
lr = [list(map(int, input().split())) for i in range(Q)]

L = [0] * (N + 1)

for i in range(N - 1):
  if s[i] == "A" and s[i + 1] == "C":
      L[i + 1] = 1 + L[i]
  else:
      L[i + 1] = L[i]


for i in range(Q):
    print(L[lr[i][1] - 1] - L[lr[i][0] - 1])



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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	ll N, M; cin >> N >> M;

	vector<pair<ll, ll>> AB(N);
	REP(i,N){
		ll A, B; cin >> A >> B;
		AB[i] = make_pair(A, B);
	}

	SORT(AB);

	ll cnt = 0;
	ll ans = 0;
	int idx = 0;
	while(cnt != M){
		ll num = min((ll)AB[idx].second, M-cnt);
		ans += AB[idx].first * num;
		cnt += num;
		idx++;

	}

	cout << ans << endl;




	return 0;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

    vector<ll> A(N);
    vector<tuple<ll,ll,ll>> tmp(N);
    vector<long double> hi(N);
    rep(i,N){
        cin>>A[i];
    }
    
    sort(all(A));
    long double sum = 0.0;
    rep(i,N){
        hi[i] = (long double)A[i]/(long double)(A[0]);
        
        sum += hi[i];
    }
    ll cnt = 0;
    rep(i,N){
        //cout<<"OK"<<endl;
        //cout<<hi[i]<<" "<<sum<<endl;
        ll a,b,c;
        if((ll)(K*hi[i]/sum)!=0){
            
            a= (ll)A[i]/((ll)(K*(hi[i]/sum)+1));
            cnt+=(ll)(K*hi[i]/sum);
            b= (ll)(K*hi[i]/sum)+1;
            c = A[i];
        }else{
            a = (ll)A[i];
            
            b= 1;
            c = A[i];
        }
        tmp[i] = make_tuple(a,b,c);
        
    }

    sort(all(tmp));
    reverse(all(tmp));
    rep(i,K-cnt){

        get<0>(tmp[i]) = get<2>(tmp[i])/(get<1>(tmp[i])+1);
        get<1>(tmp[i]) ++;
    }
 
  

    rep(i,N){
        if(get<2>(tmp[i])%get<1>(tmp[i])== 0){
            get<0>(tmp[i]) = get<0>(tmp[i]);

        }else{
            get<0>(tmp[i]) = get<0>(tmp[i])+1;
        }
    }

    sort(all(tmp));
    reverse(all(tmp));

    cout << get<0>(tmp[0]) << endl;



    return 0;
    

}

Measured memory_bytes: 12704
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

struct state {

  bool operator<(const state& other) const {
    if (add >= 0 && other.add >= 0) {
      return mn_bal > other.mn_bal;
    }
    if (add < 0 && other.add < 0) {
      int r1 = add == mn_bal;
      int r2 = other.add == other.mn_bal;
      if (r1 != r2) {
        return r2;
      }
      return mn_bal < other.mn_bal;
    }
    return add > other.add;
  }

  void init() {
    for (char c : s) {
      if (c == '(') {
        ++add;
      } else {
        --add;
      }
      mn_bal = min(mn_bal, add);
    }
  }

  string s;
  int mn_bal = 0;
  int add = 0;
};

void solve(int) {
  cin >> n;
  vector<state> a(n);
  vector<int> ord(n);
  int bal = 0;
  for (auto& s : a) {
    cin >> s.s;
    s.init();
    bal += s.add;
  }
  if (bal) {
    cout << "No\n";
    return;
  }
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&] (int l, int r) {
    return a[l] < a[r];
  });
  //for (int i = 0; i < n; ++i) {
  //  cout << a[ord[i]].s << ' ' << a[ord[i]].add << ' ' << a[ord[i]].mn_bal << '\n';
  //}
  for (int i = 0; i < n; ++i) {
    auto& s = a[ord[i]];
    if (s.mn_bal + bal < 0) {
      cout << "No\n";
      return;
    }
    bal += s.add;
  }
  cout << "Yes\n";
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}




Measured memory_bytes: 46216
package main

import (
	"fmt"
	"math"
)

func main() {
	A := 0
	B := 1
	C := 2
	var n, a, b, c int
	fmt.Scan(&n)
	var dp [][]int
	for i := 0; i < n; i++ {
		dp = append(dp, make([]int, 3))
		fmt.Scan(&a, &b, &c)
		if i == 0 {
			dp[i][A] = a
			dp[i][B] = b
			dp[i][C] = c
			continue
		}
		dp[i][A] = int(math.Max(float64(dp[i-1][B]), float64(dp[i-1][C]))) + a
		dp[i][B] = int(math.Max(float64(dp[i-1][A]), float64(dp[i-1][C]))) + b
		dp[i][C] = int(math.Max(float64(dp[i-1][A]), float64(dp[i-1][B]))) + c

	}
	max := 0
	for i := 0; i < 3; i++ {
		if max < dp[n-1][i] {
			max = dp[n-1][i]
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 11520
S = input()
MOD = 10 ** 9 + 7

A = 0
AB = 0
ABC = 0
cnt = 1

for s in S:
    if s == "A":
        A = (A + cnt) % MOD
    elif s == "B":
        AB = (A + AB) % MOD
    elif s == "C":
        ABC = (AB + ABC) % MOD
    else:
        A, AB, ABC = (A * 3 + cnt) % MOD, (AB * 3 + A) % MOD, (ABC * 3 + AB) % MOD
        cnt = (cnt * 3) % MOD
    # print(A, AB, ABC, cnt)
    
print(ABC)

Measured memory_bytes: 40048
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll dp[110][4][2];

int main() {
    string N;
    int K;
    cin >> N >> K;
    dp[0][0][1] = 1;
    for(int i = 0; i < N.size(); i++) {
        for(int k = 0; k < 4; k++) {
            for(int j = 0; j < 2; j++) {
                if(j) { // smallが確定していない
                    int n = N[i] - '0';
                    if(n == 0) {
                        dp[i + 1][k][j] += dp[i][k][j];
                    } else {
                        if(k < 3)
                            dp[i + 1][k + 1][j] += dp[i][k][j];
                    }
                    if(k < 3)
                        dp[i + 1][k + 1][!j] += dp[i][k][j] * max(0, (n - 1));
                    if(n != 0)
                        dp[i + 1][k][!j] += dp[i][k][j];
                } else { // smallが確定している
                    if(k < 3)
                        dp[i + 1][k + 1][j] += dp[i][k][j] * 9;
                    dp[i + 1][k][j] += dp[i][k][j];
                }
            }
        }
    }
    cout << dp[N.size()][K][0] + dp[N.size()][K][1] << endl;
    return 0;
}

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

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int, bool>> tp(N);
  tp[0].second = true;
  for (int i = 0; i < N; i++) {
    int A; cin >> A; tp[i].first = A;
  }
 
  vector<int> roop(N, -1);
  int count = 1, stop = 0;
  int now = tp[0].first; tp[0].second = true;
  roop[0] = 1;
  while (!(tp[now-1].second)) {
    roop[count] = now;
    tp[now-1].second = true;
    now = stop = tp[now-1].first; 
    count++;
  }
  
  long long broop = 0;
  for (int i = 0; i < count; i++) {
    if (stop == roop[i]) broop = i;
  }
  
  int ans;
  if (K <= broop) ans = K % count;
  else ans = (K-broop) % (count-broop) + broop;
  
  cout << roop[ans] << endl; 
}

Measured memory_bytes: 5600
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

vector<int> ans;

int solve(int N) {
    vector<int> a(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ave = sum / N;
    int ret = 0;
    for (int i = 0; i < N; i++) {
        if (ave >= a[i]) ret++;
    }
    return ret;
}

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

    while (1) {
        int N; cin >> N;
        if (N == 0) break;
        ans.push_back(solve(N));
    }
    for (auto i: ans) {
        cout << i << endl;
    }
}




Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
       ios_base::sync_with_stdio(false);
       cin.tie(0);
  int n ,k;
  string s;
  cin>>n>>k>>s;
  if(s.at(k - 1) == 'A')
  	 s.at(k - 1) ='a'; 
  	 if(s.at(k - 1) == 'B')
  	 	 s.at(k - 1) = 'b';
  	 	 if(s.at(k - 1) == 'C')
  	 	 	 s.at(k - 1) = 'c';
  	 	 	cout<<s<<endl;
  	 	 	return 0;
  	 	 }    

Measured memory_bytes: 3612
n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]
 
r1 = 0
nl1.sort()

for i5 in range(2):
    c1 = 0
    for i2 in range(n1):
        if nl1[i2] % nl1[i5] != 0:
            c1 += 1
        if c1 >= 2:
             break
        if i2 == (n1 - 1):
            r1 = nl1[i5] 
 
i3 = nl1[1] // 2
 
while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1
 
print(str(r1))

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std ;
#define ll  long long 
#define dl long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);


int main ()
{
	
    FAST
    
   ll n ;
   cin>>n;
   if (n>=30)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

    

    
    return 0;

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x,y;
    cin >> x >> y;

    if (x == 4 || x==6 || x==9 || x==11)
    {
      x = 4;
    }
    else if (x==2)
    {
      x = 2;
    }
    else
    {
      x = 1;
    }
    if (y == 4 || y==6 || y==9 || y==11)
    {
      y = 4;
    }
    else if (y==2)
    {
      y = 2;
    }
    else
    {
      y = 1;
    }

    if (x==y)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }

}


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

void solve()
{

}

int32_t main()
{
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long  dp[107][1000007];
long long  weight[107],value[107];
vector <pair<int,int>> v;
pair<int,int> pp[107][1000007];
 ll n;
ll fn (int i ,ll w)
{
    if(i == n)
    {
        return 0;
    }
    if(w==0)
    {
        return 0 ;
    }
    if(dp[i][w]!=-1)
    {
        return dp[i][w];
    }
    ll leave = fn(i+1,w);
    ll take =0;
    if(weight[i]<=w)
    {
        take = value[i]+fn(i+1,w-weight[i]);
    }
    if (take>leave)
    {
    
    }
    return dp[i][w]= max(take,leave);

}

int main()
{
    cin>>n;
    ll w;
    cin>>w;
    memset (dp,-1,sizeof dp);
    for(int i =0;i<n;i++)
    {
        cin>>weight[i]>>value[i];
    }
    cout<<fn(0,w)<<endl;
  
    
    return 0;
}

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

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

   if(X == 3 || X == 5 || X == 7){
       cout << "YES" << endl;
   } else {
       cout << "NO" << endl;
   }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;
int t[100],h[100];

int main(){
  int _t,_h,ts,hs,i,j,x;
  loop:
    scanf("%d%d",&_t,&_h);
    if(!_t)return 0;
    ts=0;hs=0;
    for(i=0;i<_t;i++){
      scanf("%d",t+i);
      ts+=t[i];
    }
    for(i=0;i<_h;i++){
      scanf("%d",h+i);
      hs+=h[i];
    }
    x=ts-hs;
    if(x&1)goto fail;
    x/=2;
    sort(t,t+_t);
    sort(h,h+_h);

    for(i=0;i<_t;i++)
      for(j=0;j<_h;j++)
        if(x == t[i]-h[j]){
          printf("%d %d\n",t[i],h[j]);
          goto loop;
        }
  fail:
    printf("-1\n");
    goto loop;
}

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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  map<char,int> dx,dy;
  dx['E']=dy['N']=1;
  dx['W']= dy['S']=-1;
 
  while(true){
    int N;
    cin>>N;
    if(!N)return;
    vector<vector<int>> G(21,vector<int>(21,0));
    
    int x,y;
    rep(i,N){
      cin>>x>>y;
      G[y][x]=1;
    }
    int M;
    cin>>M;
    x=10;y=10;
    rep(i,M){
      char s;int len;
      cin>>s>>len;
      while(len--){
        x+=dx[s];y+=dy[s];
        G[y][x]=0;
      }
    }
   int ct=0;
   rep(i,21)
    rep(j,21)
      ct+=G[i][j];
    if(ct)
      cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
using namespace std;
#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  vector<bool> nums = vector<bool>(N, false);
  int cnt = 0;
  REP(i, N) {
    int A;
    cin >> A;
    A--;
    if(nums[A]) {
      cnt++;
    } else {
      nums[A] = true;
    }
  }
  if(cnt % 2 == 1) {
    cnt++;
  }
  cout << N - cnt << endl;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
    string S;
    cin >> S;
    string str1, str2;
    for (int i = 0; S.size() > 2; i++)
    {
        S.pop_back();
        if (S.size() % 2 != 0) continue;
        str1 = S.substr(0, S.size() / 2);
        str2 = S.substr(S.size() / 2, S.size() / 2);
        if (str1 == str2) break;
    }

    cout << str1.size() * 2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

using Weight = double;
using Data = pair<Weight,int>;

Weight INF = 1e18;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  using P = pair<Weight,int>;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  using C = tuple<ll,ll,ll>;
  vector<C> vc;
  ll xs,ys,xt,yt;
  cin>>xs>>ys>>xt>>yt;
  vc.emplace_back(xs,ys,0);
  vc.emplace_back(xt,yt,0);
  int n;
  cin>>n;
  REP(i,n) {
    ll x,y,r;
    cin>>x>>y>>r;
    vc.emplace_back(x,y,r);
  }
  n += 2;
  Graph g(n);
  REP(i,n)REP(j,n) {
    if (i == j) continue;
    ll x0,y0,r0,x1,y1,r1;
    tie(x0,y0,r0) = vc[i];
    tie(x1,y1,r1) = vc[j];
    double d = max(0., sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)) - r0 - r1);
    g[i].push_back(Edge{i,j,d});
  }
  Array dist;
  dijkstra(g, dist, 0);
  cout << fixed << setprecision(10) << dist[1] << endl;
  return 0;
}


Measured memory_bytes: 22652
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int main(){
  ll N,K;  cin >> N >> K;
 if( K > (( N - 1) * ( N - 2 )) / 2){cout <<"-1" << endl ; return 0;}
  else{
    ll M = ( N * ( N - 1)) / 2 - K;
    cout << M << endl;
    for(ll i = 0; i < N - 1; i++){
      cout << 1 <<" " << i+2 << endl;}
  
    ll cnt = 0; bool flag = true; ll S = ((N-1)*(N-2))/2 - K;
    for(ll i = 2; i <= N-1; i++){
      for(ll j = i+1; j <= N; j++){
         cnt++;
      if( cnt >= S+1){ flag = false; break;} 
       cout << i << " " << j << " " << endl;  }
       if(!flag){ break;}}   return 0;}
}
         

Measured memory_bytes: 256
macro_rules! read {
	() => {{
		let mut buf = String::new();
		std::io::stdin().read_line(&mut buf).unwrap();
		buf
	}};
	( Vec<$t:ty> ) => {
		read!()
			.trim()
			.split_whitespace()
			.map(|x| x.parse::<$t>().unwrap())
			.collect::<Vec<_>>()
	};
	( $( $t:ty ),* ) => {{
		let buf = read!();
		let mut iter = buf.split_whitespace().collect::<Vec<_>>().into_iter();
		( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
	}};
}

fn main() {
    let mut v = vec![0; read!(usize)];
    for a in read!(Vec<usize>) {
        v[a - 1] += 1;
    }
    println!(
        "{}",
        v.iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    )
}


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


int main(){
    int n,d;
    cin>>n>>d;
    int x[n][d];
    int sum=0;
    int count=0;
    for(int i=0;i<n;i++)
    for(int j=0;j<d;j++)
        cin>>x[i][j];
    for(int h=0;h<n;h++){
        for(int i=h+1;i<n;i++){
            for(int j=0;j<d;j++){
                sum+=abs((x[h][j]-x[i][j])*(x[h][j]-x[i][j]));
            }
            
            if (ceil(sqrt(sum)) == floor(sqrt(sum)))
                count++;
            sum=0;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256