akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm> //sort
#include <stdio.h>   //printf

using namespace std;

static const int MAX_ELEMENT = 20;

/*
int rec(int idx, int n, int *A){
  int i;
  if (idx >= n) {
    printf("{%d", A[0]);
    for (i = 1; i < n; i++)
      printf(", %d", A[i]);
    printf("}\n");
    return;
  }

  A[idx] = 0;
  rec(idx+1, n, A);

  A[idx] = 1;
  rec(idx+1, n, A);
}

void makeConbination(int n) {
  int i, *S;
  S = new int[n];

  S[0] = 0;
  rec(1, n, S);

  S[0] = 1;
  rec(1, n, S);

  delete[] S;
}
*/

int solve(int *A, int idx, int n, int m) {
  int res;

  if (m == 0) return 1;
  if (idx >= n) return 0;

  res = solve(A, idx+1, n, m) || solve(A, idx+1, n, m - A[idx]);

  return res;
}

int main(){
  int i, j, n, q, m, A[MAX_ELEMENT] = {0};

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> A[i];
  }
  //??????????????????
  sort(A, A+n);

  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> m;

    //A?????´???????????¨?????????
    for (j = 0; j < n; j++) {
      if (A[j] > m)
        break;
    }
    //A[0] ~ A[j]???????´??????¨????????????????????????????????????
    if ( solve(A, 0, j, m) )
      printf("yes\n");
    else
      printf("no\n");
  }

  return 0;
}

Measured memory_bytes: 3164
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  lint A,B;
  cin >> A >> B;
  if(llabs(A-B)>=2) cout << "Alice" << endl;
  else cout << "Brown" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010];
int main() {
	ll n,l;
	cin>>n>>l;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans1=inf;
	for(int i=0;i<n-1;i++){
		if(a[i]+a[i+1]>=l){
			ans1=i;
			break;
		}
	}
	if(ans1==inf){
		cout << "Impossible";
		return 0;
	}
	else{
		cout << "Possible"<<endl;
	}
	vector<ll> b;
	for(int i=ans1;i<n-1;i++){
		b.push_back(i+1);
	}
	for(int i=ans1-1;i>=0;i--){
		b.push_back(i+1);
	}
	for(int i=n-2;i>=0;i--){
		cout << b[i]<<endl;
	}
	return 0;
}

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

int main () {
    int N, K;
    cin >> N >> K;
    int h[N];
    for (int i=0; i<N; i++){
        cin >> h[i];
    }

    int times =0;
    for (int i=0; i<N; i++){
        if (h[i] >= K){
            times += 1;
        }
    }

    cout << times;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%i%i", &A,&B);
    if(A > 9|| A < 1||B > 9||B < 1)
    {
        printf("-1\n");
    }
    else
    {
        printf("%i", (A * B));
    }
}

Measured memory_bytes: 128
from collections import Counter
n=int(input())
L=[]
for _ in range(n):
   x,y=map(int,input().split())
   L.append((x,y))
D=[]
if n==1:print(1)
else:
   for i in range(n):
      for j in range(i+1,n):
          D.append((L[i][0]-L[j][0],L[i][1]-L[j][1]))
          D.append((L[j][0]-L[i][0],L[j][1]-L[i][1]))
   C=Counter(D)
   print(n-C.most_common()[0][1])

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define itn int
#define gI gi
 
using namespace std;
 
typedef long long ll;
 
inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}
 
inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}
 
int n, m, a[100003];
char s[100003];
 
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi(), m = gi();
	if (n == m) puts("Yes");
	else puts("No");
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  if (a > b) {
    cout << "a > b";
  } else if (a < b) {
    cout << "a < b";
  } else {
    cout << "a == b";
  }
  cout << endl;
}

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

using namespace std;

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

	int n,t,a;
	cin >> n >> t >> a;
	vector<double> temperatures;
	for(int i=0; i<n; i++){
		int height;
		cin >> height;
		temperatures.push_back(abs(t-height*0.006-a));
	}
	int minElementIndex = min_element(temperatures.begin(),temperatures.end()) - temperatures.begin();
	cout << minElementIndex+1;
	return 0;
}

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

using namespace std;

int dp[105][10005];
int v[105],w[105];

int N,W;

int main(){
    cin>>N>>W;
    for(int i=1;i<=N;i++)
        cin>>v[i]>>w[i];
    int ans=0;
    for(int i=1;i<=N;i++){
        for(int j=0;j<=W;j++){
            if(j<w[i]) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    #ifdef debug
    for(int i=1;i<=N;i++){
        for(int j=0;j<=W;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    #endif
    cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int H, W;
    cin >> H >> W;
    long long int count = 0;
    bool flag = false;
    long long int add = W;
    if(W == 1 || H == 1) {
        cout << 1 << endl;
        return 0;
    }
    if(W % 2 == 1) {
        add++;
    }
    if(H % 2 == 1) {
        flag = true;
    }
    for(long long int i = 0; i < H/2; i++) {
        count += add / 2 +  W / 2;
    }
    if(flag) {
        count += add / 2;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
	long long n,k,ans=0;
	long long list[100001];
	long long a,b,m=0;
	scanf("%lld %lld",&n,&k);
	int i;
    for(i=0;i<100001;i++){
        list[i] = 0;
    }
	for(i=0;i<n;i++){
		scanf("%lld %lld",&a,&b);
		list[a] += b;
	}
	for(i=1;i<100001;i++){
		m = m + list[i];
		if(m>=k){
			ans = i;
			break;
		}
	}
	printf("%d\n",ans);
}

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

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

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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> B(N);
  for(ll i=0;i<N;i++){
    ll a;
    cin >> a;
    if(a%2==1){
      cout << 0 << endl;
      return 0;
    }
    B[i]=a/2;
  }
  ll count=0;
  ll b=B[0];
  while(b%2==0){
    b=b/2;
    count++;
  }
  for(ll i=1;i<N;i++){
    ll c=0;
    ll d=B[i];
    while(d%2==0){
      d=d/2;
      c++;
    }
    if(count!=c){
      cout << 0 << endl;
      return 0;
    }
  }
  ll T=1;
  for(ll i=0;i<N;i++){
    T=lcm(T,B[i]);
  }
  ll kaisuu=M/T;
  if(kaisuu%2==0){
    cout << kaisuu/2 << endl;
  }
  else{
    cout << (kaisuu+1)/2 << endl;
  }
}

Measured memory_bytes: 3988
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long int ll;

void chmin(ll &a, ll b){
  if (a > b) a = b;
}
ll INF = 1LL << 60;
ll dp[100010]; //DPテーブル
int h[100010];
int K;

ll rec(int N){
  
  ll res = INF;
  //ベースケース
  if (N == 0){
    return 0;
  }

  //計算済みであればその値を返す
  if (dp[N] < INF){
    return dp[N];
  }

  //各ジャンプ毎にmin値を計算する（再帰）
  for (int i = 1; i <= K; i++){
    if(N-i >= 0) chmin(res, rec(N-i) + abs(h[N] - h[N-i]));
  }

  return dp[N] = res; //DPテーブルに記録しながらリターン
}


int main(){
  int N; cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    cin >> h[i];
  }
  
  for (int i = 0; i < 100010; i++){
    dp[i] = INF;
  }  
  
  cout << rec(N-1);
  return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//単価高くて日にち間に合うのからとってく？
//5日
//5 8
//4 10
//3 5
//3 6
//3 7
//3 4
//1 8
//1 9
//1 10
//DP的な。4日目にいくら、みたいな
//長期のミドルバイトを後半に残すと最大とれなくなりそう
//1 8
//2 7
//3 6
//最終日から逆算すればいいか
int main(){
  ll N,M; cin>>N>>M;
  vector<vector<ll>> T(100010,vector<ll>(0,0));
  for(int i=0; i<N; i++){
    ll A,B; cin>>A>>B;
    T[A].emplace_back(B);
  }
  priority_queue<ll> pq;
  ll ans=0;
  for(int i=1; i<=M; i++){
    ll tsz=T[i].size();
    for(int j=0; j<tsz; j++){
      pq.push(T[i][j]);
    }
    if(!pq.empty()){
      ans+=pq.top();
      pq.pop();
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
vector<int> g[4][4][4];
int f[101][4][4][4];
const int mod=1000000000+7;
bool check(vector<int> v){
	for(int i=0;i<2;i++){//A 0 G 2  C 1
		if(v[i]==0&&v[i+1]==2&&v[i+2]==1){
			return false;
		}
	}
	for(int j=0;j<3;j++){
		swap(v[j],v[j+1]);
		for(int i=0;i<2;i++){
		  if(v[i]==0&&v[i+1]==2&&v[i+2]==1){
				return false;
		   }
		}
		swap(v[j],v[j+1]);
	}
	return true;
}

void init(){
	for(int x=0;x<4;x++){
		for(int y=0;y<4;y++){
			for(int z=0;z<4;z++){
				for(int c=0;c<4;c++){
					vector<int> v;
					v.push_back(x);
					v.push_back(y);
					v.push_back(z);
					v.push_back(c);
					if(check(v)) g[x][y][z].push_back(c);
			}
			}
		}
	}
}

int main(){
	int n;
	cin>>n;
	init();
	if(n==3) cout<<61<<endl;
	else {
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				for(int q=0;q<4;q++){
					f[3][i][j][q]=1;
				}
			}
		}
		f[3][0][2][1]=0;
		f[3][2][0][1]=0;
		f[3][0][1][2]=0;
		for(int i=3;i<n;i++){
			for(int x=0;x<4;x++){
				for(int y=0;y<4;y++){
					for(int z=0;z<4;z++){
						for(int c=0;c<g[x][y][z].size();c++){
							int c1=g[x][y][z][c];
								f[i+1][y][z][c1]=(f[i+1][y][z][c1]+f[i][x][y][z])%mod;
						}
						
					}
				}
			}
		}
		int ret=0;
		for(int x=0;x<4;x++){
			for(int y=0;y<4;y++){
				for(int z=0;z<4;z++){
					ret=(ret+f[n][x][y][z])%mod;
				}
			}
		}
		cout<<ret<<endl;
	}
}


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

using namespace std;
long long mod = 1000000007,dp[100010][20];
int main(){
	string s;
	cin >> s;
	int i,j,k,n = s.size();
	dp[0][0] = 1;
	for(i=0;i<n;i++){
		for(j=0;j<13;j++){
			if(s[i]=='?'){
				for(k=0;k<10;k++){
					(dp[i + 1][(j*10 + k)%13] += dp[i][j]) %= mod;
				}
			}else{
				(dp[i + 1][(j*10 + s[i] - '0')%13] += dp[i][j]) %= mod;
			}
		}
	}
	cout << dp[n][5] << endl;
}

Measured memory_bytes: 16128
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°??????????????°?????????
		int n = sc.nextInt();
		//??°?????????	0?????¨?????????????????? ??\???????????°????????§??¨????????????
		for(int i = 1; i<= n; i++){
		//?????¶??? 3???????????°??????????????¨??? contains??????????????????????????????????????§?????????????????????String????????´???????????¨??????????????????toString????????´
			if(i % 3 ==0 || Integer.toString(i).contains("3")){
				//???????????°??????????????¨?????????????????´?????????
				if(0 < i){
					//?????????????¬?
					System.out.print(" " + i);
				}else{
					//?????????????¬???????
					System.out.print(i);
				}
			}
		}
		//??????
		System.out.println();
	}
}

Measured memory_bytes: 29112
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int fact(int n){
	if(n<=1)
		return 1;
	return n*fact(n-1);
}

double ecludean_dis(double x1,double y1,double x2,double y2)
{
	double x = x1 - x2; //calculating number to square in next step
	double y = y1 - y2;
	double dist;

	dist = (x*x) + (y*y);       //calculating Euclidean distance
	dist = sqrt(dist);   
	return dist;
}

double get_dist(vector<pair<double,double>> points)
{
	double dis=0;
	for(int i=1;i<points.size();i++){
		dis+=ecludean_dis(points[i-1].fi,points[i-1].se,points[i].fi,points[i].se);
	}
	return dis;
}

int main()
{      
  fastio();
  int n,i;
  cin>>n;
  vector<pair<double,double>> points;
  for(i=0;i<n;i++){
  	pair<double,double> p;
  	cin>>p.fi>>p.se;
  	points.pb(p);
  }
  sort(points.begin(),points.end());
  double total=0;
  double div=fact((int)n);
  do{
  	double dis=get_dist(points);
    total+=dis;
  } while (next_permutation(points.begin(),points.end()));
  cout<<fixed<<setprecision(10);
  cout<<(total/div); 
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  int size = S.size();
  int half = size/2;
  string front = S.substr(0,half);
  reverse(front.begin(),front.end());
  string end = S.substr(half);
  if(size%2==1)end = S.substr(half+1);
  int min_count=0;
  for(int i=0; i<front.size(); i++){
    if(front[i]!=end[i])min_count++;
  }
  cout << min_count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[110];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	printf("%c%d%c\n",in[0],n-2,in[n-1]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    ll n,temp;
    ll sum=0;
    cin >> n;
    vector<ll> a(n+1),b(n);
    rep0(i,n+1)
        cin >> a[i];
    rep0(i,n)
        cin >> b[i];
    rep0(i,n){

        if(a[i]<b[i]){
            sum+=a[i];
            b[i]-=a[i];
            temp=min(a[i+1],b[i]);
            sum+=temp;
            a[i+1]-=temp;
        }else sum+=b[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4840
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	if(A%3==0 || B%3==0 || (A+B)%3 == 0) "Possible".writeln;
	else "Impossible".writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

long long int N;
int Q, v[100005], L[100005];
long long int V[300005], W[300005];

set<long long int > S;

long long int dp[2060][100005];

int max_level;

int node[40];

void visit(int k, int level) {

	if (level > max_level / 2) { return ; }

	int p = k / 2;

	for (int j = 1; j <= 100000; j++) {
		dp[k][j] = dp[k][j - 1];
		dp[k][j] = max(dp[k][j], dp[p][j]);
		if (j - W[k] >= 0) { dp[k][j] = max(dp[k][j], dp[p][j - W[k]] + V[k]); }
	}

	visit(k * 2, level + 1);
	visit(k * 2 + 1, level + 1);
}
int calc_level(long long int v) {
	int cnt = 0;
	while (v > 0) {
		cnt++; v /= 2;
	}
	return cnt;
}
int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> V[i] >> W[i];
	}

	cin >> Q;

	for (int i = 1; i <= Q; i++) {
		cin >> v[i] >> L[i];
	}


	for (int i = 1; i <= N; i++) {
		int tmp = v[i]; int cnt = 0;
		while (tmp > 0) {
			cnt++; tmp /= 2;
		}
		max_level = max(max_level, cnt);
	}

	
	visit(1, 1);

	for (int i = 1; i <= Q; i++) {
		int lv = calc_level(v[i]);
		if (lv<= max_level / 2) {
			cout << dp[v[i]][L[i]] << endl;
		}
		else {
			long long int ans = 0;
			int H = lv - max_level / 2;
			int tmp = v[i];
			for (int i = 1; i <= H; i++) {
				node[i] = tmp;
				tmp /= 2;
			}

			for (long long int k = 0; k < (1LL << H); k++) {
				long long int sum_v = 0;
				long long int sum_w = 0;

				for (int j = 1; j <= H; j++) {
					if ((k >> (j - 1)) & 1) { sum_v += V[node[j]]; sum_w += W[node[j]]; }
				}
				
				if (sum_w > L[i]) { continue; }

				ans = max(ans, dp[tmp][L[i] - sum_w] + sum_v);

			}
			cout << ans << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 407312
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_N=50;
int n;
string l[MAX_N];
int p[MAX_N];
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N];
int e[MAX_N];
int f[MAX_N];
int s[MAX_N];
int m[MAX_N];

void solve(){
  map<double,set<string>,greater<double> > seeds;
  REP(i,n){
    double time=a[i]+b[i]+c[i]+(d[i]+e[i])*m[i];
    double profit=s[i]*f[i]*m[i]-p[i];
    double efficient=profit/time;
    seeds[efficient].insert(l[i]);
  }
  for(auto seed_eff:seeds)
    for(auto seed:seed_eff.second)
      cout<<seed<<endl;
  cout<<"#"<<endl;
}

int main(){ _;
  while(cin>>n,n!=0){
    REP(i,n)cin>>l[i]>>p[i]>>a[i]>>b[i]>>c[i]>>d[i]>>e[i]>>f[i]>>s[i]>>m[i];
    solve();
  }
}

Measured memory_bytes: 1224
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main()
{
  int n,m;
  cin>>n>>m;
  vector<P> a(n);
  vector<P> b(m);
  for(int i=0;i<n;i++)
    cin>>a[i].first>>a[i].second;
  for(int i=0;i<m;i++)
    cin>>b[i].first>>b[i].second;
  for(int i=0;i<n;i++){
    int c=1000000000;
    int d=1;
    for(int j=0;j<m;j++){
      int x=abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second);
      if(c>x){
	c=x;
	d=j+1;
      }
    }
    cout<<d<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,count=0;
  string s;
  cin>>n;
  cin>>s;
  for(int i=0; i<n; i++)
  {
     if(s[i]!=s[i+1])
     count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  if(a==b && b==c){
    cout << "No" << endl;
  } else if(a!=b && b!=c && c!=a){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

	return 0;
}

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

using namespace std;

int main()
{
    int n ;
    cin>>n ;
    int arr[n] ;
    int ans = 0 ;
    int MAX = 0 ;
    for(int i = 0 ; i < n ; ++i)
    {
        cin>>arr[i] ;
        if(arr[i] & 1)
            continue;
        int x = arr[i] ;
        while(x % 2 == 0)
            x /= 2 , MAX++;
        ans = max(ans , MAX);
    }
    cout<<ans;
    return 0 ;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
r = []
s = 0

for i in range(1, n):
    if h[i-1] >= h[i]:
        s = s + 1
    else:
        r.append(s)
        s = 0
        
r.append(s)

print(max(r))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
const int N=3e4+5;
char s[N];
int nex[N][10],la[10],n;
bool check(int x) {
	int pos=0;
	if(nex[pos][x/100]==-1) return false;
	pos=nex[pos][x/100];
	if(nex[pos][(x%100)/10]==-1) return false;
	pos=nex[pos][(x%100)/10];
	if(nex[pos][x%10]==-1) return false;
	return true;
}
int main() {
	scanf("%d%s",&n,s+1);
	for(int i=0;i<10;i++) nex[n][i]=-1,la[i]=-1;
	la[s[n]-'0']=n;
	for(int i=n-1;i>=1;i--) {
		for(int j=0;j<10;j++) nex[i][j]=la[j];
		la[s[i]-'0']=i;
	}
	for(int i=0;i<10;i++) nex[0][i]=la[i];
	int ans=0;
	for(int i=0;i<1000;i++) {
		if(check(i)) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
n,p,m = list(map(int,input().split()))

seen = {}
ans = p%m
seen[p%m]=1
T = {}
T[1] = ans
T[0] = 0
last_p = p%m

r = 0

if n==1:
  print(p%m)
  exit()
else:
  for i in range(2,m+1000):
    p = p ** 2
    p = p % m
    
    if p not in seen:
      seen[p]=i
    else:
      r = i-seen[p]
      last_p = p
      break
    
    ans += p
    T[i] = ans
    
    if i==n:
      print(ans)
      exit()
    
    
temp = T[seen[p]-1]
ans -= temp
n -= seen[p]

k = n//r
ans *= k
ans += temp

n = n % r

if n==0:
  print(ans+last_p)
  exit()

for i in range(1,m+1000):
  p = p ** 2
  p = p % m
  ans += p
  if i==n:
    print(ans+last_p)
    exit()
      
      
    

Measured memory_bytes: 82176
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val h = IntArray(n) { scanner.nextInt() }

    var ret = 0
    var stroke = 0
    var cur = 1
    while (cur < h.size) {
        if (h[cur - 1] >= h[cur]) {
            stroke++
            ret = Math.max(ret, stroke)
        } else {
            stroke = 0
        }
        cur++
    }

    println(ret)
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll l, r;
  cin >> l >> r;
  r = min(r, l + 2019);
  ll ans = 2018;
  rep(i, l, r + 1)rep(j, i + 1, r + 1) chmin(ans, i * j % 2019);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 

 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

LL modinv(LL a, LL m) {
  LL b = m, u = 1, v = 0;
  while (b) {
    LL t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0){
     u += m;
  }
  return u;
}

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}

void func() {
  LL N;
  cin >> N;
  VLL A(N,5);
  VVLL B(10,VLL(5,5));
  //chmax(N,10LL);
  //PRINTSP(A);
  cout << N*N; 
  return;
}


int main()
{
  func();
  return 0;
}
 

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    string S,T;
    cin >> S >> T;
    int ans = 0;
    rep(i,S.size()){
      if(S.at(i)!=T.at(i)){
        ans++;
      }
    }
    printl(ans);
}


Measured memory_bytes: 3908
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int x = 0;
  for (int i = 9; i > 0; i--) {
    if (N % i == 0) {
      x = N / i;
      break;
    }
  }
  if (x == 0 || x > 9) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

// PMAMP :)
// INL , IIWOIL

int solve(ll n,ll k)
{
    int count=0;
    while(n)
    {
        n=n/k;
        count++;
    }
    return count;
}
int main()
{
    jaldi
    int n;
    cin>>n;
    vector<int> v(n);
    for(int &x:v) cin>>x;
    ll fans=INT_MAX;
    for(int i=0;i<=110;i++)
    {
        ll ans=0;
        for(int j=0;j<n;j++)
        {
            ans+=(v[j]-i)*(v[j]-i);
        }
        fans=min(ans,fans);
    }
    cout<<fans;
    return 0;
}

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

using namespace std;


int main(int argc, char *argv[])
{

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, town[8];
    long long x[8], y[8];
    double dist = 0.0;
    
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    
    iota(town, town + N, 0);
    
    long long factorial[9] = {1};
    for (int i = 1; i <= N; i++) factorial[i] = factorial[i - 1] * i;
    
    do {
        for (int i = 1; i < N; i++) {
            int i1 = town[i], i0 = town[i-1];
            dist += sqrt(pow(x[i1] - x[i0], 2) + pow(y[i1] - y[i0], 2));
        }
    } while (next_permutation(town, town + N));
    
    dist /= factorial[N];
    
    cout << fixed << setprecision(10) << dist << endl;
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Solution
{
    public static void Main()
    {
      int N = int.Parse(Console.ReadLine());
      int[] A = new int[N];
      for (int i = 0; i < N; i++)
      {
        A[i] = int.Parse(Console.ReadLine());
      }
      // LINQでソート
      var dst = A.OrderBy(a => -a).ToList();

      int[] ans = new int[N];
      // 最大の数を持つ要素が１つの場合、２番目に大きい数を求めて、
      // 最大の数が入っているiのときだけ２番目に大きい数を出力する。
      // 最大の数が重複する場合、全て最大の数を出す。
      for (int i = 0; i < N; i++)
      {
        ans[i] = dst[0] != dst[1] ? 
          A[i] == dst[0] ? dst[1] : dst[0] : dst[0];
      }
      for (int i = 0; i < N; i++)
      {
        Console.WriteLine(ans[i]);
      }
      //Console.WriteLine($"{ans}");
    }
}

Measured memory_bytes: 22484
#include <iostream>
#include <stdlib.h>

using namespace std;

#define MAX 500000
#define INF 1500000000

int cnt = 0;

void merge(int _array[],int _left,int _mid,int _right){

  int i;
  int j;
  int k;
  int n1;
  int n2;
  int *L;
  int *R;
  n1 = _mid-_left;
  n2 = _right-_mid;

  L = (int *)malloc(sizeof(int)*n1+1);
  R = (int *)malloc(sizeof(int)*n2+1);

  for(i = 0;i < n1;i++){
    L[i] = _array[_left+i];
  }
  for(i = 0;i < n2;i++){
    R[i] = _array[_mid+i];
  }

  L[n1] = INF;
  R[n2] = INF;

  for(i = 0,j =0,k = _left;k < _right;k++,cnt++){
    if(L[i] <= R[j]){
      _array[k] = L[i];
      i++;
    }
    else {
      _array[k] = R[j];
      j++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int _array[],int _left,int _right){

  int mid;

  if(_left+1 < _right){
    mid = (_left+_right)/2;
    mergeSort(_array,_left,mid);
    mergeSort(_array,mid,_right);
    merge(_array,_left,mid,_right);
  }

}

int main(){

  int i;
  int n;
  int A[MAX];

  cin >> n;

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

  mergeSort(A,0,n);

  for(i = 0;i < n-1;i++){
    cout << A[i] << ' ';
  }
  cout << A[n-1] << endl;

  cout << cnt << endl;

  return 0;

}

Measured memory_bytes: 5056
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int main() {
	int w, h;
	while (cin >> w >> h) {
		if (w == 0 && h == 0) {
			break;
		}
		vector< vector<char> > hyou(h, vector<char>(w));
		vector< vector<char> > hyou2(h, vector<char>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> hyou[i][j];
				hyou2[i][j] = hyou[i][j];
			}
		}
		queue<P> q;
		queue<P> q2;
		queue<P> q3;
		queue<P> q4;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (hyou[i][j] == 'B') {
					P p;
					p.first = i;
					p.second = j;
					q.push(p);
					q4.push(p);
				}
				if (hyou[i][j] == 'W') {
					P p;
					p.first = i;
					p.second = j;
					q2.push(p);
					q3.push(p);
				}
			}
		}
		int di[] = {1, 0, -1, 0};
		int dj[] = {0, 1, 0, -1};
		while (!q.empty()) {
			P pp = q.front();
			q.pop();
			for (int i = 0; i < 4; i++) {
				if (pp.first+di[i] >= 0 && pp.first+di[i] < h && pp.second+dj[i] >= 0 && pp.second+dj[i] < w && hyou[pp.first+di[i]][pp.second+dj[i]] == '.') {
					hyou[pp.first+di[i]][pp.second+dj[i]] = 'B';
					P ppp;
					ppp.first = pp.first+di[i];
					ppp.second = pp.second+dj[i];
					q.push(ppp);
				}
			}
		}
		while (!q2.empty()) {
			P pp = q2.front();
			q2.pop();
			for (int i = 0; i < 4; i++) {
				if (pp.first+di[i] >= 0 && pp.first+di[i] < h && pp.second+dj[i] >= 0 && pp.second+dj[i] < w && hyou2[pp.first+di[i]][pp.second+dj[i]] == '.') {
					hyou2[pp.first+di[i]][pp.second+dj[i]] = 'W';
					P ppp;
					ppp.first = pp.first+di[i];
					ppp.second = pp.second+dj[i];
					q2.push(ppp);
				}
			}
		}
		int counter = 0;
		while (!q3.empty()) {
			P pp = q3.front();
			q3.pop();
			for (int i = 0; i < 4; i++) {
				if (pp.first+di[i] >= 0 && pp.first+di[i] < h && pp.second+dj[i] >= 0 && pp.second+dj[i] < w && hyou[pp.first+di[i]][pp.second+dj[i]] == '.') {
					hyou[pp.first+di[i]][pp.second+dj[i]] = 'W';
					P ppp;
					ppp.first = pp.first+di[i];
					ppp.second = pp.second+dj[i];
					counter++;
					q3.push(ppp);
				}
			}
		}
		int counter2 = 0;
		while (!q4.empty()) {
			P pp = q4.front();
			q4.pop();
			for (int i = 0; i < 4; i++) {
				if (pp.first+di[i] >= 0 && pp.first+di[i] < h && pp.second+dj[i] >= 0 && pp.second+dj[i] < w && hyou2[pp.first+di[i]][pp.second+dj[i]] == '.') {
					hyou2[pp.first+di[i]][pp.second+dj[i]] = 'B';
					P ppp;
					ppp.first = pp.first+di[i];
					ppp.second = pp.second+dj[i];
					counter2++;
					q4.push(ppp);
				}
			}
		}
		cout << counter2 << ' ' << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
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;

int main() {
  int A, B;
  cin >> A >> B;
  cout << 6 - A - B << endl;
}


Measured memory_bytes: 256
//简单模拟  KMP优化？ 
#include <iostream>
#include <cstring>
using namespace std;
char s[100+5];
char t[100+5];
int main()
{
	cin>>s;
	cin>>t;
	int len = strlen(s);
	//cout << len << endl;
	int flag  = 0;
	for(int i = 0; i < len; ++i){
		int ttt = 0;
		for(int j = 0; j < len; ++j){
			if(s[i] == t[j]){
		    	for(int k = 1; k<len; ++k){
		    		if(s[(i+k)%len]!= t[(j+k)%len]){
						ttt = 1;	
		    			break;
					}
				}
				if(ttt == 0){
					flag = 1;
				}
			}	
		}
	
}
if(flag)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}
	

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

int main(){
    int h, w;

    while(1){
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++ ){
            for (int j = 0; j < w; j++){
                if ((i+j)%2 == 0){
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

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


int n;
int p[102], m[102][102]={0};
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> p[i-1] >> p[i];
	}
	for( int l = 2; l <= n; l++) {
		for (int i = 1; i<= n - l + 1;i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k<= j - 1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}



Measured memory_bytes: 3128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int main(){
	int n,m;
	cin>>n>>m;
	vector<pii> ab(m);
	REP(i,m){
		cin>>ab[i].first>>ab[i].second;
	}

	int prev=0;
	int cnt=0;
	while(prev<n){
		int best=-1;
		REP(i,m){
			if(ab[i].first<=prev+1&&(best==-1||ab[best].second<ab[i].second)){
				best=i;
			}
		}
		if(best==-1||prev==ab[best].second){
			cout<<"Impossible"<<endl;
			exit(0);
		}
		prev=ab[best].second;
		cnt++;
	}
	if(prev==n){
		cout<<cnt<<endl;
	}else{
		cout<<"Impossible"<<endl;
	}
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b + c <= 21) puts("win");
    if(a + b + c >= 22) puts("bust");

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

static const char RGB[]={'R','G','B'};
int w,h;

class Data{
public:
	char stage[10][10];
	int count;
	Data() : count(0), stage(){}
	Data(char _stage[10][10],int _count){
		memcpy(this->stage,_stage,sizeof(char)*10*10);
		this->count = _count;
	}
	bool operator>(const Data& d) const{
		return this->count > d.count;
	}

	bool operator<(const Data& d) const{
		return this->count < d.count;
	}
};

void dfs(char stage[10][10],int x,int y,int from,int to,bool visited[10][10]){
	stage[y][x] = to;
	visited[y][x] = true;

	for(int i=0;i<4;i++){
		int dx = x + tx[i];
		int dy = y + ty[i];
		if(dx < 0 || dx >= w || dy < 0 || dy >= h) continue;
		if(stage[dy][dx] != from ) continue;
		if(visited[dy][dx]) continue;

		dfs(stage,dx,dy,from,to,visited);
	}
}

string stg2str(char stage[10][10]){
	string res = "";
	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			res += stage[y][x];
		}
	}

	return res;
}

int main()
{
	while(~scanf("%d %d",&w,&h)){
		if(h==w && w==0) break;

		char stage[10][10];
		memset(stage,'\0',sizeof(stage));
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				char ch;
				cin >> ch;
				stage[y][x] = ch;
			}
		}

		int minv = numeric_limits<int>::max();
		string init = stg2str(stage);
		

		priority_queue<Data,vector<Data>,greater<Data> > que;
		que.push(Data(stage,0));

		map<string,int> cost;

		cost[init] = 0;

		while(!que.empty()){
			Data d = que.top();
			que.pop();

			for(int i=0;i<3;i++){
				char next[10][10];
				memcpy(next,d.stage,sizeof(char)*10*10);

				bool visited[10][10];
				memset(visited,0,sizeof(visited));
				dfs(next,0,0,d.stage[0][0],RGB[i],visited);


				string str = stg2str(next);
				if(cost.find(str) != cost.end() && cost[str] <= d.count + 1) continue;

				cost[str] = d.count + 1;

				que.push(Data(next,d.count+1));
			}
		}

		for(int i=0;i<3;i++){
			string ans="";
			while(ans.size() < w*h) ans.push_back(RGB[i]);
			if(cost.find(ans) != cost.end()) minv = min(cost[ans],minv);
		}

		printf("%d\n",minv);

	}
}

Measured memory_bytes: 2676
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[110000];
struct wolf{
	int t;
	int ch[2];
	wolf(){t=0;ch[0]=ch[1]=-1;}
};
wolf pool[110000];
long long ret;
int ind=1;
void dfs(int a,long long b){
	if(pool[a].t){
		return;
	}
	if(pool[a].ch[0]==-1){
		long long tmp=1;
		long long v=b;
		while(v%2==0){
			v/=2;tmp*=2;
		}
		ret^=tmp;
	}else dfs(pool[a].ch[0],b-1);
	if(pool[a].ch[1]==-1){
		long long tmp=1;
		long long v=b;
		while(v%2==0){
			v/=2;tmp*=2;
		}
		ret^=tmp;
	}else dfs(pool[a].ch[1],b-1);
	
}
int main(){
	int a;
	long long b;
	scanf("%d%lld",&a,&b);

	for(int i=0;i<a;i++){
		scanf("%s",in);
		int n=strlen(in);
		int at=0;
		for(int j=0;j<n;j++){
			if(in[j]=='0'){
				if(pool[at].ch[0]!=-1){
					at=pool[at].ch[0];
				}else{
					pool[at].ch[0]=ind;
					at=ind;
					ind++;
				}
			}else{
				if(pool[at].ch[1]!=-1){
					at=pool[at].ch[1];
				}else{
					pool[at].ch[1]=ind;
					at=ind;
					ind++;
				}
			}
		}
		pool[at].t=1;
	}

	dfs(0,b);
	if(ret)printf("Alice\n");else printf("Bob\n");
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int n,m,k,now=0;cin>>n>>m>>k;
  vector<ll> a(n+1,0),b(m+1,0);
  ll sum=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
	sum+=a[i];
  }
  for(int i=1;i<=m;i++){
    cin>>b[i];
  }
  int mx=0;
  for(int i=n;i>=0;i--){
      while(now<=m&&sum+b[now]<=k){
        sum+=b[now];
        now++;
      }
    if(sum<=k)mx=max(mx,i+now-1);
    sum-=a[i];
  }
  cout<<mx;
}

Measured memory_bytes: 6424
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(long i = 0; i < (long)n; i++)
using namespace std;

int main(){
  int n,c;
  cin >> n >> c;
  int d[c][c];
  REP(i,c){
    REP(j,c){
      cin >> d[i][j];
    }
  }
  long long col_cnt[3][c];
  REP(i,3){
    REP(j,c){
      col_cnt[i][j] = 0;
    }
  }
  REP(i,n){
    REP(j,n){
      int c_ij;
      cin >> c_ij;
      col_cnt[((i+1)+(j+1))%3][c_ij-1]++;
    }
  }

  long long col_d[3][c] = {0};
  REP(i,3){
    REP(j,c){
      col_d[i][j] = 0;
    }
  }
  REP(i,3){
    REP(j,c){
      REP(k,c){
        col_d[i][j] += col_cnt[i][k]*d[k][j];
      }
    }
  }

  long long min = col_d[0][0]+col_d[1][1]+col_d[2][2];
  REP(c0,c){
    REP(c1,c){
      if(c1==c0) continue;
      REP(c2,c){
        if(c2==c1||c2==c0) continue;
        if(min > col_d[0][c0]+col_d[1][c1]+col_d[2][c2]){
          min = col_d[0][c0]+col_d[1][c1]+col_d[2][c2];
        }
      }
    }
  }
  cout << min << endl;
  return 0;
}


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

const int maxn = 200010;
int n, p[maxn], q[maxn], tmp[maxn], ans[maxn], fa[maxn], sz[maxn];

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    fa[x] = y, sz[y] += sz[x];
}

int main() {
    scanf("%d", &n);
    for (int i = 1, x, y; i <= n; i++) {
        scanf("%d %d", &x, &y);
        p[x] = y, tmp[i] = x, q[y] = x;
        fa[i] = i, sz[i] = 1;
    }
    int cur = n;
    for (int i = 1; i <= n; i++) {
        if (q[i] > cur) continue;
        if (q[i] == cur) { cur--; continue; }
        int mx = 0, from = q[i];
        for (int j = from; j <= cur; j++) {
            mx = max(mx, p[j]), q[p[j]] = n + 1;
            if (j > from) unite(j, j - 1);
        }
        p[from] = mx, cur = from, q[mx] = from;
    }
    for (int i = 1; i <= n; i++) {
        printf("%d\n", sz[find(tmp[i])]);
    }
    return 0;
}

Measured memory_bytes: 7724
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
As = sorted(A)
A1 = As[-1]
A2 = As[-2]
if A1 != A2:
    for j in range(N):
        if A[j]==A1:
            print(A2)
        else:
            print(A1)
else:
    for j in range(N):
        print(A1)

Measured memory_bytes: 14112
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

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

int main() {
	ll x;
	cin >> x;
	cout << 360 / gcd(x, 360) << endl;

	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;
ll num[ten52];
ll path[ten52];

int main(void)
{
    long long int m,n,i;
    long long int a,v,b,w,t;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    if(b>a)
    {
        a+=t*v;
        b+=w*t;
        if(a>=b) cout<<"YES";
        else cout<<"NO";
    }
    else if(a>b)
    {
        a-=t*v;
        b-=w*t;
        if(a<=b) cout<<"YES";
        else cout<<"NO";

    }

    return 0;
}





Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;


int main() {
    
    long n,m;
    cin >> n >> m;
    const long N = n;
    const long M = m;
    long mat[N][M] = {};
    long vec[M] = {};
    long ans[N] = {};
    for (int i=0;i<N;i++){
        for (int j=0;j<M;j++){
            int p;
            cin >> p;
            mat[i][j] = p;
        }
    }
    for (int i=0;i<M;i++){
        int p;
        cin >> p;
        vec[i] = p;
    }

    for (int i=0;i<N;i++){
        for (int j=0;j<M;j++){
            ans[i] += mat[i][j] * vec[j];
        }
    }
    for (int i=0;i<N;i++){
        cout << ans[i] << endl;
    }


}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
struct o
{
	int a,b;
	inline bool operator<(const o &x)const
	{
		return a<x.a;
	}
}	x[100005];
priority_queue<int>q;

int main()
{
	ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,m,s=0,j=1;
	cin>>n>>m;
	for (int i=1; i<=n; i++)
	{
		cin>>x[i].a>>x[i].b;
	}
	sort (x+1,x+n+1);
	for(int i=1; i<=m; ++i)
	{
		for(; x[j].a==i&&j<=n; ++j)
		{
			q.push(x[j].b);
		}
		if(!q.empty())
		{
			s+=q.top();
			q.pop();
		}

	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 1660
N=int(input())
h=[int(i) for i in input().split()]
dp=[0]
for i in range(1,N):
    dp.append(1000000000)
for i in range(0,N):
    for j in [i+1,i+2]:
        if(j<N):
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
#print(dp)
print(dp[N-1])

Measured memory_bytes: 13924