akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	string s[10];
	for (int i = 1; i <= 8; i++) {
		cin >> s[i];
		s[i] = 'A' + s[i] + 'A';
	}
	for (int i = 0; i < 10; i++) {
		s[0] += 'A';
		s[9] += 'A';
	}
	int field[10][10] = {};
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (s[i][j] == '.')field[i][j] = 0;
			else if (s[i][j] == 'o')field[i][j] = 1;
			else if (s[i][j] == 'x')field[i][j] = 2;
			else field[i][j] = 3;
		}
	}
	int dx[8] = { -1,0,1,1,1,0,-1,-1 };
	int dy[8] = { -1,-1,-1,0,1,1,1,0 };
	int player = 1;
	bool pass = false;
	while (1) {
		bool pas = true;
		int rev[10][10] = {};
		for (int i = 1; i <= 8; i++) {
			for (int j = 1; j <= 8; j++) {
				if (!field[i][j]) {
					for (int k = 0; k < 8; k++) {
						bool cnt = false;
						int loop = 1;
						while (1) {
							if (field[i + dy[k] * loop][j + dx[k] * loop] != (player ^ 3)) {
								if (field[i + dy[k] * loop][j + dx[k] * loop] == player)cnt = true;
								break;
							}
							else loop++;
						}
						if(cnt)rev[i][j] += loop - 1;
						if (rev[i][j])pas = false;
					}
				}
			}
		}
		//cout << "hi";
		if (pas) {
			//cout << "hi";
			if (pass)break;
			pass = true;
			player ^= 3;
			continue;
		}
		pass = false;
		set<pair<int, pair<int, int>>>se;
		for (int i = 1; i <= 8; i++) {
			for (int j = 1; j <= 8; j++) {
				if(player==2)se.insert({ rev[i][j], { i,j } });
				else se.insert({ 100 - rev[i][j], { i,j } });
			}
		}
		int cx, cy;
		if (player == 2) {
		//	cout << (*se.rbegin()).first << endl;
			cx = (*se.rbegin()).second.second;
			cy = (*se.rbegin()).second.first;
		}
		else {
			cx = (*se.begin()).second.second;
			cy = (*se.begin()).second.first;
		}
		for (int k = 0; k < 8; k++) {
			bool cnt = false;
			int loop = 1;
			while (1) {
				if (field[cy + dy[k] * loop][cx + dx[k] * loop] != (player ^ 3)) {
					if (field[cy + dy[k] * loop][cx + dx[k] * loop] == player)cnt = true;
					break;
				}
				loop++;
			}
			if (cnt) {
				while (loop) {
					loop--;
					field[cy + dy[k] * loop][cx + dx[k] * loop] = player;
				}
			}
		}
		player ^= 3;
	}
	for (int i = 1; i <= 8; i++) {
		for (int j = 1; j <= 8; j++) {
			if (field[i][j] == 0)cout << '.';
			else if (field[i][j] == 1)cout << 'o';
			else cout << "x";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
using System;
namespace std
{
    class Test {
        static void Main(string[] args) {
       double circle, area;
        var r = double.Parse(Console.ReadLine()); 
        area = r * r * Math.PI;
        circle = 2 * r * Math.PI;
       
        string ans1 = area.ToString("F6"); // 小数点以下を6桁表示する指示
        string ans2 = circle.ToString("F6"); // 小数点以下を6桁表示する指示

        Console.WriteLine(ans1 + " " + ans2);
        }  
    }
}


Measured memory_bytes: 15912
m = int(input())

l, r = {}, {}

def insertnode(num, x):
    """xには毎回rootを設定（rootから順に比較してし、適した場所に追加）"""
    if num < x:
        if x in l:
            if l[x] != 3000000000:
                insertnode(num, l[x])
            else:
                l[x] = num
                return
        else:
            l[x] = num
            return
    else:
        if x in r:
            if r[x] != 3000000000:
                insertnode(num, r[x])
            else:
                r[x] = num
                return
        else:
            r[x] = num
            return

def inorder(num):
    if num == 3000000000:
        return
    if num in l:
        inorder(l[num])
    else:
        l[num] = 3000000000
        inorder(l[num])
    print(' ' + str(num), end='')
    if num in r:
        inorder(r[num])
    else:
        r[num] = 3000000000
        inorder(r[num])

def preorder(num):
    if num == 3000000000:
        return
    print(' ' + str(num), end='')
    if num in l:
        preorder(l[num])
    else:
        l[num] = 3000000000
        preorder(l[num])
    if num in r:
        preorder(r[num])
    else:
        r[num] = 3000000000
        preorder(r[num])

for i in range(m):
    order = input()
    if i == 0:
        global root
        root = int(order[7:])
        continue
    if order[0] == 'i':
        num = int(order[7:])
        insertnode(num, root)
    else:
        inorder(root)
        print()
        preorder(root)
        print()


Measured memory_bytes: 72852
N = int(input())


def digit(N):
    return len(str(N))


f = []
i = 1
while i * i <= N:
    if N % i == 0:
        d1 = digit(i)
        d2 = digit(int(N/i))
        f.append(max(d1, d2))
    i += 1

print(min(f))


Measured memory_bytes: 9120
#include <iostream>
#include <climits>
#include <vector>

using namespace std;

typedef vector< int > VI;
typedef vector< VI > VVI;
typedef vector< VVI > VVVI;

const int INF = INT_MAX / 2;

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

	while ( true )
	{
		int n, m;
		cin >> n >> m;

		if ( !( n | m ) )
		{
			break;
		}

		VVVI G( m, VVI( m, VI( 2, INF ) ) );

		for ( int i = 0; i < m; i++ )
		{
			G[i][i][0] = G[i][i][1] = 0;
		}

		// 入力処理とグラフの構築
		for ( int i = 0; i < n; i++ )
		{
			int a, b, cost, time;
			cin >> a >> b >> cost >> time;

			a--;
			b--;

			G[a][b][0] = G[b][a][0] = cost;
			G[a][b][1] = G[b][a][1] = time;
		}

		// Warshall-Froyd
		for ( int k = 0; k < m; k++ )
		{
			for ( int i = 0; i < m; i++ )
			{
				for ( int j = 0; j < m; j++ )
				{
					G[i][j][0] = min( G[i][j][0], G[i][k][0] + G[k][j][0] );
					G[i][j][1] = min( G[i][j][1], G[i][k][1] + G[k][j][1] );
				}
			}
		}

		int k;
		cin >> k;

		for ( int i = 0; i < k; i++ )
		{
			int p, q, r;
			cin >> p >> q >> r;

			p--;
			q--;

			cout << G[p][q][r] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1784
//21th centry Copyright by libra9z
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define reunique(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
using ll=long long;
template<class T>ostream&operator,(ostream&os,const T&object){return os<<' '<<object;}
template<class T>istream&operator,(istream&os,T&object){return os>>object;}
const int inf=1e9;
const ll lnf=1e18;
const int mod=1e9+7;
long long s[200005],a[200005],p[200005],ans,n;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		s[i]=s[i-1]+x;
		p[i]=p[i-1]^x;
	}
	for (int l=1,r=1;r<=n;r++)
	{
		while ((s[r]-s[l-1])!=(p[r]^p[l-1])) l++;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4480
from sys import stdin


n, m, x, y = [int(x) for x in stdin.readline().rstrip().split()]

xList = [int(x) for x in stdin.readline().rstrip().split()]
yList = [int(x) for x in stdin.readline().rstrip().split()]


isOk = True

xMax = max(xList)
yMin = min(yList)

ret = [int(z) for z in range(xMax+1, yMin+1) if (x < z) and (z <= y)]

if len(ret) > 0:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3064
// Problem : A - We Love Golf
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#define XOX
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define ll          long long
#define ld          long double
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
#define vvd(a,b,name)    vector<vector<double>> name(a,vector<double>(b,-1))
//const ld pi=3.14159265359;
inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}
inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

void solve(){
	int k,a,b;cin>>k>>a>>b;
	int j=(a+k-1)/k;	
	j*=k;
	if(j>=a && j<=b)cout<<"OK"<<endl;
	else cout<<"NG"<<endl;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int a, b, c, d;
    int ans = 0;

    cin >> a >> b >> c >> d;

    if (a <= b) {
        ans += a;
    } else {
        ans += b;
    }

    if (c <= d) {
        ans += c;
    } else {
        ans += d;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define MOD 100000
int dp[101][101][3][2];
int w,h;
int dfs(int x,int y,int l,int dir)
{
	if(x>w-1||y>h-1)return 0;
	if(x==w-1&&y==h-1)return 1;
	if(dp[x][y][l][dir]>=0)return dp[x][y][l][dir];
	int res=0;
	if(l==2)res=dfs(x,y+1,0,0)+dfs(x+1,y,0,1);
	else if(l==0&&dir==0)res=dfs(x,y+1,0,0)+dfs(x+1,y,1,1);
	else if(l==0&&dir==1)res=dfs(x+1,y,0,1)+dfs(x,y+1,1,0);
	else if(l==1&&dir==0)res=dfs(x,y+1,0,0);
	else if(l==1&&dir==1)res=dfs(x+1,y,0,1);
	return dp[x][y][l][dir]=res%MOD;
}
int main()
{
	while(1)
	{
		cin >> w >> h;
		if(w==0&&h==0)break;
		memset(dp,-1,sizeof(dp));
		cout << dfs(0,0,2,0) << endl;
	}
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s.at(0) == s.at(1) && s.at(1) == s.at(2)){
        cout << "No" << endl;
    }else {
        cout << "Yes" << endl;
    }
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

int n , m , s , t;
vector<int> adj[N];

int bfs()
{
    queue< pair<int,int> > q;
    int d[n+2][4];
    for(int i=1; i<=n; i++)
    {
        d[i][0]=1e8 , d[i][1] =1e8 , d[i][2] = 1e8;
    }
    q.push({s , 0});
    d[s][0] = 0;

    while(q.size())
    {
        int node = q.front().f , mod = q.front().s;
        q.pop();

        for(auto ch : adj[node])
        {
            int m = (mod+1)%3;
            if (d[ch][m] == 1e8)
            {
                d[ch][m] = d[node][mod]+1;
                q.push({ch,m});
            }
        }
    }

    if (d[t][0] == 1e8) return -1;
    else return d[t][0]/3;
}

int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin >> x >> y;
        adj[x].push_back(y);
    }

    cin >> s >> t;
    cout << bfs() << '\n';

    return 0;
}

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

bool betemp(string sleft, string sright, int left, int right) {
    if (sleft == sright) return (right - left) % 2 == 1;
    else return (right - left) % 2 == 0;
}

void solve(int N) {
    string vac = "Vacant";
    string sleft, sright, str;
    int left = 0, right = N/2;
    cout << left << endl;
    cin >> sleft;
    if (sleft == vac) return;
    cout << right << endl;
    cin >> sright;
    if (sright == vac) return;

    if (!betemp(sleft, sright, left, right)) {
        swap(sleft, sright), left = right, right = N;
    }
    while (right - left > 1) {
        int mid = (left + right) / 2;
        cout << mid << endl;
        cin >> str;
        if (str == vac) return;
        if (betemp(sleft, str, left, mid)) sright = str, right = mid;
        else sleft = str, left = mid;
    }
}

int main() {
    int N;
    while (cin >> N) solve(N);
}

Measured memory_bytes: 3856
n=int(input())
h=list(map(int,input().split()))
ans=0
if n==1:
    print(h[0])
    exit()
while any(h)==True:
    flag=0
    for i in range(n-1):
        if h[i]>0:
            h[i]-=1
            flag=1
        else:
            if flag==1:
                ans+=1
                flag=0
        if i==n-2:
            if h[n-1]>0:
                h[n-1]-=1
                ans+=1
            else:
                if flag==1:
                    ans+=1
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

using namespace std;
// 7:14

bool binsearch(int l, int r, int a, vector<int>& v) {
	if(l >= r-1) {
		return (v[l] == a) ? true : false;
	}
	int mid = (r + l) / 2;
	if(a < v[mid]) {
		return binsearch(l, mid, a, v);
	} else {
		return binsearch(mid, r, a, v);
	}
}

int main() {
	int n, q;
	cin >> n;
	vector<int> s(n);
	for (size_t i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	cin >> q;
	vector<int> t(q);
	for (size_t i = 0; i < q; i++)
	{
		cin >> t[i];
	}
	int c = 0;
	for (size_t i = 0; i < q; i++)
	{
		if(binsearch(0, n, t[i], s)) {
			c++;
		}
	}
	cout << c << endl;
}



Measured memory_bytes: 3264
<?php
fscanf(STDIN, "%d %d", $H, $W);


$list = array();
for ($i = 0; $i < $H; $i++) {   
  $list[$i]=str_split(trim(fgets(STDIN)));
}


$resultList = array();
for ($i = 0; $i < $H; $i++) { 
  for ($j = 0; $j < $W; $j++) {
    $resultList[$i][$j] = 0;
  }
}



for ($i = 0; $i < $H; $i++) { 
  for ($j = 0; $j < $W; $j++) {
    // 爆弾
    if( strcmp($list[$i][$j],"#") == 0 )
    {
      if(isset($list[$i-1][$j-1])){
        $resultList[$i-1][$j-1]++;
      }
      if(isset($list[$i][$j-1])){
        $resultList[$i][$j-1]++;
      }
      if(isset($list[$i+1][$j-1])){
        $resultList[$i+1][$j-1]++;
      }
    
      if(isset($list[$i-1][$j])){
        $resultList[$i-1][$j]++;
      }
      if(isset($list[$i+1][$j])){
        $resultList[$i+1][$j]++;
      }

      if(isset($list[$i-1][$j+1])){
        $resultList[$i-1][$j+1]++;
      }
      if(isset($list[$i][$j+1])){
        $resultList[$i][$j+1]++;
      }
      if(isset($list[$i+1][$j+1])){
        $resultList[$i+1][$j+1]++;
      }
    }
  }
}


for ($i = 0; $i < $H; $i++) { 
  for ($j = 0; $j < $W; $j++) {
    
    if( strcmp($list[$i][$j],".") == 0 )
    {
      $list[$i][$j] = $resultList[$i][$j];
    }
  }
}




for ($i = 0; $i < $H; $i++) { 
  for ($j = 0; $j < $W; $j++) {   
    echo $list[$i][$j];
  }
  echo "\n";
}


// $result = 1;
// $total = 0;
// for ($i = 1; $i <= $N; $i++) {    
//   $result *= $i;
//   $result = $result%1000000007;
// }

// echo ($result);


?>

Measured memory_bytes: 4468
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())

	min := 1001
	for i := 0; i < n; i++ {
		sc.Scan()
		c, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		tt, _ := strconv.Atoi(sc.Text())

		if tt <= t && c < min {
			min = c
		}
	}

	if min == 1001 {
		fmt.Println("TLE")
	} else {
		fmt.Println(min)
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans1=0,ans2=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-'0'!=i%2)
			ans1++;
		if(s[i]-'0'!=((i%2)+1)%2)
			ans2++;
	}
	cout<<min(ans1,ans2);
}

Measured memory_bytes: 512
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i+1):
        price = 10000*i + 5000*j + 1000*(n-i-j)
        if price == y:
            print(i, j, (n-i-j))
            exit()
        
print(-1, -1, -1)

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

int main() {
  int N,n;
  cin>>N;
  n=0;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    if(S=="Y"){
    n++;
      break;
   }
    else{
    }
  }
    if (n==1){
    cout<<"Four"<<endl;
    }
    else{
      cout<<"Three"<<endl;
    }

    }


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

int main() {
    ll x, y;
    cin >> x >> y;

    if (x % y == 0)
        cout << -1 << endl;
    else
        cout << x << endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


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

    if((N/10)%111==0 || (N-(N/1000)*1000)%111==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3556
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n; cin >> n;
	int a[114514];
	int ans = 0;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		int j = i;
		while (a[j + 1] == a[i] && j <= n)j++;
		int k = j - i + 1;
		if (k != a[i]) {
			if (k > a[i])ans += k - a[i];
			else ans += k;
		}
		i = j;
	}
	cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

inline void init() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
}

int main() {
  init();
  int n, k, idx = 0;

  cin >> n >> k;
  std::vector<int> a(n, 0);

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

  int ans = 0;
  
  if (k == n) {
    cout << 1 << endl;
    return 0;
  }
  
  int d = 0;
  
  while (d < n - 1) {
    ans++;
    d += (k - 1);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};

int main(){

	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ma=max(a*c,b*d);
	ma=max(ma,a*d);
	cout<<max(ma,b*c)<<endl;

	return 0;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  int na[n];
  rep(i,n){
    cin >> a[i];
    na[i] = 0;
  }
  int pm[n];
  rep(i,n)pm[i] = 0;
  int flag = 1;
  rep(iii,k){
    flag = 1;
    int tmp = 0;
    rep(i,n){
      na[i] = 1+tmp;
      if(i+a[i]<n)pm[i+a[i]] += 1;
      tmp++;
      tmp -= pm[i];
      pm[i] = 0;
    }
    tmp = 0;
    for(int i=n-1;i>=0;i--){
      na[i] += tmp;
      if(i-a[i]>=0)pm[i-a[i]] += 1;
      tmp++;
      tmp -= pm[i];
      pm[i] = 0;
      if(a[i]!=na[i]){
        a[i] = na[i];
        flag = 0;
      }
    }
    if(flag)break;
  }
  rep(i,n)cout << na[i] << " ";
  return 0;
}

Measured memory_bytes: 5932
#include <stdio.h>

int main(){
	int a,b,c;
	int temp;
	int min,med,max;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	min = a; med = b; max = c;
	
	if(c < a){               //set a
		temp = c;
		c = a;
		a = temp;
	}else if (b < a){
		temp = b;
		b = a;
		a = temp;
	}
	
	if (b < a){
		temp = b;
		b = a;
		a = temp;
	}
	
	if(c < b){
		temp = c;
		c = b;
		b = temp;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

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

int main(){
    long H, W;
    cin >> H >> W;
    long ans;
    if(H == 1 or W == 1){
        ans = 1;
    }
    else if(W%2 == 0){
        ans = H * W / 2;
    }
    else if(H%2 == 0){
        ans = W / 2 * H + H / 2;
    }
    else{
        ans = W / 2 * H + H / 2 + 1;
    }

    cout << ans << endl;
}

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

int n;
vector<int> a;
int x, y;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		int t;
		cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end(), greater<int>() );
	for(int i=1; i<n; ++i){
		if(a[i] == a[i-1]){
			if(x == 0){
				x = a[i];
				++i;
			}else if(y == 0){
				y = a[i];
				break;
			}
		}
	}
	cout << (long long)x * y << "\n";
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[200],dp[200009][209],W,w[200],k;

ll f(ll brt, ll idx){
	if(idx>n)return 0;
	if(dp[brt][idx]!=-1)return dp[brt][idx];
	if(brt+w[idx]<=W){
		dp[brt][idx]=max(f(brt+w[idx],idx+1)+a[idx],f(brt,idx+1));
	}
	else dp[brt][idx]=f(brt,idx+1);
	return dp[brt][idx];
}

int main(){
	cin >> n >> W;
	for(int i=1; i<=n; i++)cin >> w[i] >> a[i];
	memset(dp,-1,sizeof dp);
	cout << f(0,1) << endl;
}//1+1=2

Measured memory_bytes: 326784
from math import sqrt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in x:
    for j in x:
        ans = 0
        for k in range(d):
            ans += (i[k] - j[k]) ** 2
        if ans != 0 and sqrt(ans) % 1 == 0:
            cnt += 1
print(cnt // 2)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MOD 998244353
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 1000005
#define ll long long
using namespace std;
int main()
{
	ll n,m;
	cin>>n>>m;
	if((n+m)%2==0)
	cout<<(n+m)/2;
	else
	cout<<"IMPOSSIBLE";
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// sort(cut.begin(),cut.end());

int main ()
{
    vector<int> v(5);
    int A,B,C,D,E;cin>>v[0]>>v[1]>>v[2]>>v[3]>>v[4];

    int last = 10;
    int last_id;
    for(int i=0; i<5; i++){
      int r = v[i]%10;
      if((last > r) && (r != 0)){
        last_id = i;
        last = r;
      }
    }

    int sum=0;
    for(int i=0; i<5; i++){
      int r = v[i]%10;
      if(i != last_id){

        if(r != 0){
          sum += (v[i] - v[i]%10) + 10;
        }else{
          sum += v[i];
        }

      }
    }

    cout<<sum + v[last_id]<<endl;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d %d', $n, $m);
$point = array_map('intVal', explode(' ', trim(fgets(STDIN))));

$a = explode(' ', fgets(STDIN));
sort($a);

rsort($point);
$distance = [];
for ($i = 0; $i < $m - 1; ++$i) {
  $distance[] = $point[$i] - $point[$i + 1];
}
rsort($distance);
array_splice($distance, 0, $n - 1);

echo array_sum($distance);


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

int main(){
int P,Q,R;
  cin >> P>> Q>>R;
  int a1 = P+Q;
  int a2 = Q+R;
  int a3 = R+P;
  cout << min(a1,min(a2,a3)) << endl;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

parent = [None] * N
parent[0] = 0

score = [0] * N
for pi, xi in px:
    score[pi - 1] += xi

ans = [None] * N

from collections import deque

q = deque([(0, 0)])
while len(q) > 0:
    src, score_tmp = q.popleft()
    score_tmp += score[src]
    ans[src] = score_tmp
    for dst in graph[src]:
        if ans[dst] != None: continue
        q.append((dst, score_tmp))

print(' '.join(map(str, ans)))

Measured memory_bytes: 162668
/*
Come on, come on
Put your hands into the fire
Explain, explain
As I turn, I meet the power

This time, this time
Turning white and senses dying
Pull up, pull up
From one extreme to another

From the summer to the spring
From the mountain to the air
From samaritan to sin
And it's waiting on the air

Come on, come on
Put your hands into the fire
Explain, explain
As I turn, I meet the power

This time, this time
Turning white and senses dying
Pull up, pull up
From one extreme to another

From the summer to the spring
From the mountain to the air
From samaritan to sin
And it's waiting on the air

Now I'm low, I'm looking out, I'm looking in
Way down, the lights are dimmer
Now I'm low, I'm looking out, I'm looking in
Way down, the lights are dimmer

Come on, come on
Put your hands into the fire
Come on, come on
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define inf 0x3f3f3f3f
#define LINF  0x3f3f3f3f3f3f3f3fll
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 
 
const ll mod = 999983;
#define mx 1000005
const ll mxi = 105;

int main()
{
    fast_as_levi;
    ll n;
    cin>>n;
    ll ar[n];
    ll sm = 0;
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        sm += ar[i];
    }
    sm/=n;
    ll sm1 = sm;
    ll sm2 = sm;
    sm1++;
    sm2--;
    ll ans = 0,ans1 = 0,ans2 = 0;
    for(int i=0;i<n;i++)
    {
        ans += (ar[i]-sm)*(ar[i]-sm);
        ans1 += (ar[i]-sm1)*(ar[i]-sm1);
        ans2 += (ar[i]-sm2)*(ar[i]-sm2);
    }
    cout<<min(ans,min(ans1,ans2));
    
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int A, B, K;
    //iが偶数なら高橋のターン
    
    cin >> A;
    cin >> B;
    cin >> K;
    for (int i = 0; i < K; i++) {
        if (i % 2 == 0) {   //奇数なら
            if (A % 2 == 1) {
            A -= 1;
            }
        }
        else if (i % 2 == 1) {
            if (B % 2 == 1) {
                B -= 1;
                }
        }
        if (i % 2 == 0) {
            B += A / 2;
            A -= A / 2;
        }
        else if (i % 2 == 1) {
            A += B / 2;
            B -= B / 2;
        }
    }
    cout << A << " "<< B << endl;
    return 0;
}


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

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

  if(N<=1000){
  x=1000-N;
  } 
  if(1000<N && N<=2000){
  x=2000-N;
  } 
  if(2000<N && N<=3000){
  x=3000-N;
  } 
  if(3000<N && N<=4000){
  x=4000-N;
  } 
  if(4000<N && N<=5000){
  x=5000-N;
  } 
  if(5000<N && N<=6000){
  x=6000-N;
  } 
  if(6000<N && N<=7000){
  x=7000-N;
  } 
  if(7000<N && N<=8000){
  x=8000-N;
  } 
  if(8000<N && N<=9000){
  x=9000-N;
  } 
  if(9000<N && N<=10000){
  x=10000-N;
  } 
  
  cout << x << endl;
}



Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>

using namespace std;

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

const ll MOD = 1000000007;
const ll inf = (ll) 1e18;

vector<vector<ll> > warshallFloyd(vector<set<Pii> > edge) {
  int n = edge.size();
  vector<vector<ll> > d(n, vector<ll>(n, inf));
  for (int i = 0; i < n; i++) {
    d[i][i] = 0;
    for (Pii x : edge[i]) {
      d[i][x.first] = x.second;
    }
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  return d;
}

vector<ll> dijkstraDistOnly(const vector<set<Pii> > &edge, int start) {
  vector<ll> length(edge.size(), inf);
  vector<bool> visited(edge.size(), false);
  priority_queue<pair<ll, int> > que;
  que.push(pair<ll, int>(0, start)); // negative distance
  length[start] = 0;
  while (!que.empty()) {
    auto now = que.top();
    que.pop();
    if (visited[now.second]) continue;
    visited[now.second] = true;
    for (auto x : edge[now.second]) {
      if (visited[x.first]) continue;
      ll d = -now.first + x.second;
      if (d < length[x.first]) {
        length[x.first] = d;
        que.push(pair<ll, int>(-d, x.first));
      }
    }
  }
  return length;
}

vector<vector<ll> > dijkstraAll(vector<set<Pii> > edge) {
  int n = edge.size();
  vector<vector<ll> > d;
  for (int i = 0; i < n; i++) {
    d.push_back(dijkstraDistOnly(edge, i));
  }
  return d;
}

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

  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r;
  for (int i = 0; i < R; i++) {
    int buf;
    cin >> buf;
    r.push_back(buf-1); // zero index
  }
  vector<set<Pii> > edge;
  for (int i = 0; i < N; i++) edge.push_back(set<Pii>());
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[a-1].insert(Pii(b-1, c)); // zero index
    edge[b-1].insert(Pii(a-1, c)); // zero index
  }

  //vector<vector<ll> > distanceMatrix = warshallFloyd(edge);
  vector<vector<ll> > distanceMatrix = dijkstraAll(edge);
  ll shortest = inf;
  stack<vector<int> > st;
  st.push(vector<int>());
  while (!st.empty()) {
    vector<int> now = st.top();
    st.pop();
    if (now.size() == R) {
      ll dist = 0;
      for (int i = 0; i < R-1; i++) dist += distanceMatrix[now[i]][now[i+1]];
      if (dist < shortest) shortest = dist;
      continue;
    }
    set<int> contain;
    for (int x : now) contain.insert(x);
    for (int x : r) {
      auto it = contain.find(x);
      if (it == contain.end()) {
        vector<int> next = now;
        next.push_back(x);
        st.push(next);
      }
    }
  }

  cout << shortest << endl;
  return 0;
}


Measured memory_bytes: 4352
S = input()
N = len(S)
flag = 1

for i in range(N):
	if S[i] != S[N-1-i]:
		flag = 0

N = N//2
for i in range(N):
	if S[i] != S[N-1-i]:
		flag = 0

if flag == 0:
	print('No')
else:
	print('Yes')

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define fr(dt,i,a,b) for(dt i=a;i<b;i++)
#define f0(a,b) for(int i=a;i<b;i++)
#define fn(b,a) for(int i=b;i>a;i--)
#define dbg(x); cout<<"\n"<<#x<<": "<<x;
#define ret return
#define pb push_back
#define pf push_front
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define UL9 1000000007
#define UL5 100007
#define INF 1e9+7
#define PI 3.1415926
#define SQ(a) (a)*(a)
#define fst first
#define scd second
typedef vector<long long int> vlli;
typedef vector<int> vi;
typedef long long int lli;  //  e-18 to e18
int main(){
    fastIO();
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe\n";
    else cout<<"safe\n";
    ret 0; 
}                                                             

Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long H, W;
    cin >> H >> W;

    if(H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
    } else {
        long long mini = LLONG_MAX;
        for(long long i=1; i<H; i++){
            long long a = i * W;
            long long b = (H-i)*(W/2);
            long long c = H * W - a - b;
            if(max({a, b, c}) - min({a, b, c}) < mini){
                mini = max({a, b, c}) - min({a, b, c});
            }

            a = i * W;
            b = (H-i)/2*W;
            c = H * W - a - b;
            if(max({a, b, c}) - min({a, b, c}) < mini){
                mini = max({a, b, c}) - min({a, b, c});
            }

        }

        for(long long i=1; i<W; i++){
            long long a = i * H;
            long long b = (W-i)*(H/2);
            long long c = H * W - a - b;
            if(max({a, b, c}) - min({a, b, c}) < mini){
                mini = max({a, b, c}) - min({a, b, c});
            }

            a = i * H;
            b = (W-i)/2*H;
            c = H * W - a - b;
            if(max({a, b, c}) - min({a, b, c}) < mini){
                mini = max({a, b, c}) - min({a, b, c});
            }
        }

        cout << mini << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g,h,j,i;
	scanf("%d %d %d",&a,&s,&d);
	if(a==1&&s==1||d==1) printf("Open\n");
	else printf("Close\n");
	return 0;
}

Measured memory_bytes: 2600
using System;
using System.Collections.Generic;
public class Hello{
 
    public static void Main(){
        // Your code here!
        var line = Console.ReadLine().Split(' ');
        int N = int.Parse(line[0]);
        int K = int.Parse(line[1]);
        line = Console.ReadLine().Split(' ');
        List<long> A = new List<long>();
        for (int i = 0; i < N; i++)
        {
            A.Add(long.Parse(line[i]));
        }
        long Ai = 0;
        long preAi = A[0];
        for (int i = 1; i < N - K + 1; i++)
        {
            Ai = A[i + K - 1];

            if (Ai > preAi)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            preAi = A[i];
        }
    }
}


Measured memory_bytes: 48572
#include <bits/stdc++.h>
using namespace std;
int N, u, v;
vector<vector<int>> G;

void dfs(vector<int> &D, int c) {
    for(int to : G[c]) {
        if(D[to] == -1) {
            D[to] = D[c] + 1;
            dfs(D, to);
        }
    }
}

int main() {
    cin >> N >> u >> v;
    --u; --v;
    G.assign(N, vector<int>());
    for(int i=1; i<N; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> T(N, -1), A(N, -1);
    T[u] = 0; A[v] = 0;
    dfs(T, u);
    dfs(A, v);

    int res = 0;
    for(int i=0; i<N; ++i) {
        if(T[i] <= A[i]) res = max(res, A[i] - 1);
    }
    cout << res << endl;
}

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

int main(){
    string s,t;
    cin>>s>>t;

    int n=s.length(), ans=0;

    for(int i=0; i<n; i++){
        if(s[i] != t[i]) ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3916
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

string makeCommand(string s, int a, int b)
{
    ostringstream oss;
    oss << s << ' ' << a << ' ' << b;
    return oss.str();
}

bool solve(string s, vector<string>& ans)
{
    int n = s.size();
    ans.clear();

    int oNum = count(s.begin(), s.end(), 'o');
    int xNum = s.size() - oNum;
    if(oNum < xNum){
        return false;
    }
    else if(oNum == xNum){
        bool ng = false;
        for(int i=0; i<n; i+=2){
            if(s[i] == s[i+1])
                ng = true;
        }
        if(ng)
            return false;
    }

    int index = 0;
    while(n > 2){
        if(s.find('x') == string::npos){
            ans.push_back(makeCommand("split", index, 1));
            index += 2;
            s = s.substr(2);
            n -= 2;
        }
        else if(s[0] != s[1]){
            ans.push_back(makeCommand("split", index, 1));
            index += 2;
            s = s.substr(2);
            n -= 2;
        }
        else if(s[n-2] != s[n-1]){
            ans.push_back(makeCommand("split", index, n - 3));
            index += 2;
            s = s.substr(0, n - 2);
            n -= 2;
        }
        else{
            int cnt1 = 0;
            int cnt2 = n - count(s.begin(), s.end(), 'x') * 2;
            for(int i=0; ; ++i){
                if(s[i] == 'o'){
                    ++ cnt1;
                    -- cnt2;
                }
                else{
                    -- cnt1;
                    ++ cnt2;
                }
                if(cnt1 >= 0 && cnt2 >= 0){
                    ans.push_back(makeCommand("split", index, i));
                    ans.push_back(makeCommand("join", index + 2, index + 1));
                    s = s.substr(i+1) + s.substr(0, i+1);
                    break;
                }
            }
            index += 3;
        }
    }

    return true;
}

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

    while(--q >= 0){
        string s;
        cin >> s;

        vector<string> ans;
        if(solve(s, ans)){
            cout << ans.size() << endl;
            for(const string& t : ans)
                cout << t << endl;
        }
        else{
            cout << -1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <cstdio>
#include <utility>
using namespace std;

int main(void){
    int min,max,divisor,count=0;
    scanf("%d %d %d",&min,&max,&divisor);
    for(int i=min;i <= max;i++){
        if( !(divisor % i) )
        count++;
    }
    cout << count << endl;
}


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

int main(){
	int a[4], b[4];
	while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
        int hit = 0, blow = 0;
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                if(a[i] == b[j]){
                    if(i == j){
                        hit++;
                    }else{
                        blow++;
                    }
                }
            }
        }
        cout << hit << " " << blow << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int counter = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1'){
      counter++;
    } 
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Info{

	Info(){
		left = right = 'X';
		index = 0;
	}

	Info(char arg_left,char arg_right,int arg_index){
		left = arg_left;
		right = arg_right;
		index = arg_index;
	}
	char left,right;
	int index;
};

bool check[10000];
vector<Info> V[26];

void dfs(char left){
	for(int i = 0; i < V[left - 'a'].size(); i++){
		if(check[V[left - 'a'][i].index] == false){
			check[V[left - 'a'][i].index] = true;
			dfs(V[left - 'a'][i].right);
		}
	}
}

int main(){

	int N,num_left[26],num_right[26];

	bool FLG;

	char buf[33],last,final_start;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		FLG = true;

		for(int i = 0; i < 26; i++){
			V[i].clear();
			num_left[i] = 0;
			num_right[i] = 0;
		}
		for(int i = 0; i < N; i++)check[i] = false;

		for(int i = 0; i < N; i++){
			scanf("%s",buf);
			num_left[buf[0] - 'a']++;
			for(int k = 0; buf[k] != '\0'; k++)last = buf[k];
			num_right[last - 'a']++;
			V[buf[0]-'a'].push_back(Info(buf[0],last,i));
			final_start = buf[0];
		}

		for(int i = 0; i < 26; i++){
			if(num_left[i] != num_right[i]){
				printf("NG\n");
				FLG = false;
				break;
			}
		}

		if(!FLG)continue;

		check[V[final_start - 'a'][0].index] = true;
		dfs(V[final_start - 'a'][0].right);

		for(int i = 0; i < N; i++){
			if(check[i] == false){
				printf("NG\n");
				FLG = false;
				break;
			}
		}

		if(!FLG)continue;

		printf("OK\n");

	}

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;
typedef pair<ll, pill> pllpill;
typedef pair<pii, pii> pipii;

void solve() {
  int n; cin >> n;
  vector<pii> red, blue;
  red.resize(n);
  blue.resize(n);
  vector<bool> used;
  used.resize(n);
  for(int i = 0; i < n; i++) cin >> red[i].first >> red[i].second;
  for(int i = 0; i < n; i++) cin >> blue[i].first >> blue[i].second;
  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());
  int ret = 0;
  for(int i = n-1; i >= 0; i--) {
    int can = -1;
    for(int j = 0; j < n; j++) {
      if(used[j]) continue;
      if(blue[j].first < red[i].first || blue[j].second < red[i].second) continue;
      if(can == -1 || blue[j].second < blue[can].second) can = j;
    }
    if(can >= 0) {
      ret++;
      used[can] = true;
    }
  }
  cout << ret << endl;
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h" // {{{
using namespace std;
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define X           first
#define Y           second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U) template<class T, class U>
#ifdef DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t= " << (x) << '\n'
#define line()      fputs("\n--------------------------------\n", stderr)
#else
#define debug(...)
#define show(x)
#define LN()
#endif
using ll  = long long;
using pii = pair<int,int>;
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y) { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
inline bool inner(int val, int min, int max){ return min <= val && val < max; }
constexpr int INF   = 0x3f3f3f3f;
constexpr ll LINF   = 0x3f3f3f3f'3f3f3f3fLL;

namespace ydk{ // }}}

constexpr int LIM = (int)100 + 10;

int $(int n)
{
    if (n < 400)    return 0;
    if (n < 800)    return 1;
    if (n < 1200)   return 2;
    if (n < 1600)   return 3;
    if (n < 2000)   return 4;
    if (n < 2400)   return 5;
    if (n < 2800)   return 6;
    if (n < 3200)   return 7;
    return -1;
}

#define P 8

signed _vim_is_god_()
{
    int N;
    int a[LIM];
    int cnt[10]{};

    int pro = 0;

    cin >> N;
    rep(i, N) {
        int a; cin >> a;
        a = $(a);
        if (a < 0) ++pro;
        cnt[a] = 1;
    }

    int base = 0;

    rep(i, P) {
        base += cnt[i];
    }

    int x = max(base, 1);
    int y = base + pro;

    cout << x << ' ' << y << '\n';

    return 0;
}

} // {{{

signed main(){ydk::_vim_is_god_(); return 0;} // }}}



Measured memory_bytes: 256
import heapq as hq

def f():
    # N = int(input())
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    H = []
    for m in range(M):
        B, C = map(int, input().split())
        hq.heappush(H, (-C, B))

    index = 0
    res = sum(A)
    for n in range(M):
        c, b = hq.heappop(H)
        c *= -1

        for _ in range(b):
            if A[index] < c:
                res += (c - A[index])
                index += 1
                if index == N:
                    return res
            else:
                return res
    return res

print(f())


Measured memory_bytes: 21120
import bisect

N,Q =  map(int, input().split())
S = input()

start = []
end = []

for i in range(N-1):
	if S[i] == "A" and S[i+1] == "C":
		start.append(i)
		end.append(i+1)

length = len(start)
for _ in range(Q):
	left, right = map(int, input().split())
	left -= 1
	right -= 1

	if length == 0:
		print(0)
	else:
		# startの中で、left以上であるものの最小インデックス

		l1 = bisect.bisect_left(start, left)
		r1 = bisect.bisect_right(end, right) - 1

		print (r1-l1+1)


Measured memory_bytes: 7752
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

b = [b[j] for j in range(n) if b[j] > amax]
sumb = sum(b)
if sumb >= h:
  s = 0
  b = sorted(b)
  c = 0
  while s < h:
    s += b[-1]
    b.pop(-1)
    c += 1
  print(c)
else:
  print((h-sumb)//amax+((h-sumb)%amax!=0) + len(b))



Measured memory_bytes: 11992
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define LL long long



int main() {
	int a, b, c;
	cin >> a;
	cout << (a < 1000 ? "ABC" : "ABD") << endl;

	return 0;
}

Measured memory_bytes: 256