akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 4

typedef struct{
  int P[N][N];
}Papa;

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

int dfs (int x,int y,int max,int count,int n){
  int i,temp;
  int x0,y0,ans=-1,h;

  h=Heu(Q);

  if(h==0)return count;
  if((count+h) > max)return -1;

  for(i=0;i<4;i++){
    x0=x+dx[i];
    y0=y+dy[i];

    if(((i == (n+2)%4 )&& (n!=-1))||!((0<=x0 )&&( x0<N) && (0<=y0) && (y0<N)))continue;
    temp=Q.P[y][x];
    Q.P[y][x]=Q.P[y0][x0];
    Q.P[y0][x0]=temp;

    ans= dfs(x0,y0,max,count+1,i);

    if(ans!=-1)return ans;
    temp=Q.P[y][x];
    Q.P[y][x]=Q.P[y0][x0];
    Q.P[y0][x0]=temp;
  }

  return -1;

}
int Heu(Papa Q){
  int i ,j;
  int hx,hy,sum=0;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Q.P[i][j]==0)continue;

      hx=(Q.P[i][j]-1)%N-j;
      hy=(Q.P[i][j]-1)/N-i;

      if(hx<0)sum-=hx;
      else sum+=hx;

      if(hy<0)sum-=hy;
      else sum+=hy;
    }
  }
  return sum;
}

int main(){
  int i,j;
  int kx,ky,ans,a;
  Papa tP;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&a);
      Q.P[i][j]=a;
      if(a==0){
        kx=j;
        ky=i;
      }
    }
  }

  tP=Q;
  for(i=1;i<46;i++){
    Q=tP;
    ans=dfs(kx,ky,i,0,-1);
    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 2144
import math

ans = []
n = int(input())
xn = list(map(float,input().split()))
yn = list(map(float,input().split()))

def man(xx):
    sum = 0
    for i in range(n):
        sum += (abs(xn[i] - yn[i]))**xx
    return sum**(1/xx)

def che():
    sum = 0
    for i in range(n):
        tmp = (abs(xn[i] - yn[i]))
        if tmp > sum:
            sum = tmp
    return sum


for i in range(1,4):
    print(man(i))
print(che())


Measured memory_bytes: 5716
#include<iostream>
using namespace std;
 
int main(){
  int N,Y;
  cin >> N >> Y;
  int X,a=-1,b=-1,c=-1;
  for(int i=0;i<=N;i++){
    for(int j=0;i+j<=N;j++){
      X=10000*i+5000*j+1000*(N-i-j);
      if(X==Y){
        a=i;b=j;c=N-i-j;
      }
    }
  }
  cout << a << " " << b << " " << c;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		Queue<Integer> minQueue = new PriorityQueue<Integer>();
		int n = sc.nextInt(), s = 0, k = 0;
		while (n-->0) {
			int a = sc.nextInt();
			minQueue.add(a);
			s+=a;
		}
		if (s%10==0) {
			while (!minQueue.isEmpty()) {
				int o = minQueue.poll();
				if ((s-o)%10!=0) {
					System.out.println(s-o); System.exit(0);
				}
			}
		}
		System.out.println(s%10==0 ? 0 : s);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35816
#include <cstdio>
#include <algorithm>
#define maxn 200010
#define LL long long
using namespace std;
int a[maxn],b[maxn],c[maxn],cnt,cnta,cntb;
LL sum;
struct node{
	int flag;
	int v;
}e[maxn<<1];
int cmp(node a,node b){
	return a.v==b.v?a.flag<b.flag:a.v<b.v;
}
int main(){
	int n,i,good;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)b[i]=a[i]+i,c[i]=i-a[i];
	for(i=1;i<=n;i++)
		if(b[i]==c[i])sum--;
	for(i=1;i<=n;i++)
		e[++cnt].flag=0,e[cnt].v=b[i];
	for(i=1;i<=n;i++)
		e[++cnt].flag=1,e[cnt].v=c[i];
	sort(e+1,e+1+cnt,cmp);
	e[0].v=2e9,cnta=0,cntb=0,good=0;
	for(i=1;i<=cnt;i++)
		if(e[i-1].v==e[i].v){
			if(e[i-1].flag==0&&e[i].flag==1)good=1;
			if(e[i].flag==0)cnta++;
			else cntb++;
		}else{
			if(good)sum+=(LL)cntb*(cnta+1);
			cnta=0,cntb=0,good=0;
		}
	if(good)sum+=(LL)cntb*(cnta+1);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;


ll fib(int n){
  if(n<0){return 0;}
  if(n==0||n==1){return 1;}
  else{return (fib(n-2)+fib(n-1))%MOD;}
}

int main(){
  int H,W,K;cin>>H>>W>>K;

  ll dp[H+1][W];
  memset(dp, 0, sizeof(dp));
  
  dp[0][0]=1;
  for (int i=0;i<H;++i){
    for (int j=0;j<W;++j){
      dp[i+1][j]=(fib(j-1)*fib(W-1-j)*dp[i][j-1])%MOD;
      (dp[i+1][j]+=fib(j)*fib(W-j-1)*dp[i][j])%=MOD;
      (dp[i+1][j]+=fib(j)*fib(W-j-2)*dp[i][j+1])%=MOD;
    }
  }

  cout << dp[H][K-1]<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans=max({a*c,a*d,b*c,b*d});
  pr(ans);
}

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


Measured memory_bytes: 3660
/*
Till the roof comes off, till the lights go out
Till my legs give out, canâ��t shut my mouth.
Till the smoke clears out. Am I high? Perhaps
I'ma rip this shit till my bones collapse.
*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#include <stack>
#include <complex>


#define ll long long
#define X real()
#define Y imag()
#define f first
#define s second
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define lngth(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)

using namespace std;

const int N=100005;
typedef pair<int,int>ii;
typedef pair<ii,int>event;
typedef complex<double>point;
const double EPS = 1e-9;
const int INF=100000;

const double PI = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int n,arr[N];
int main()
{
   // freopen("test.in","r",stdin);
   //freopen("output.txt","w",stdout);
    scanf("%d",&n);
    memset(arr,0,sizeof(arr));
    for(int i=0;i<n;i++){
            int a;
            scanf("%d",&a);
            arr[a]++;
    }
    int even=0,odd=0;
    for(int i=0;i<N;i++){
        if(arr[i]==0)continue;
        if(arr[i]%2)odd++;
        else even++;
    }
    if(even%2)even--;
    cout<< even+odd;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//editorial AC
// The theme is understandable but installation is much more difficult than my ability
int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<ll> vec;
  
  ll res = -1;
  for(ll i = 0; i < n; i++){ 
    if( res < a[i] ){ res = a[i]; vec.push_back(i);}
  }
  
  
  map<ll,ll> mp;
  
  for(ll i = 0; i < n; i++){
    mp[a[i]]++;
  }
  
  vector<ll> ans(n,0LL);

  for(ll i = (ll)vec.size()-1; i >= 1; i--){ //index == 0 は別途調べる
    // index-vec[i] is the largest element in the current array A
    
    while( mp.rbegin()->first > a[vec[i-1]] ){
      
       auto v = *mp.rbegin();
       ans[vec[i]] += (v.first-a[vec[i-1]])*v.second;
       mp[a[vec[i-1]]] += v.second;
         
       mp.erase(v.first);
         
          }
  }
  
  for(auto v : mp ){
    ans[0] += v.first*v.second;
  }

  for(auto ne : ans ){ cout << ne << endl;}
  
 
  return 0;
}
          
          
          
          
    
        

    
    
    
  

Measured memory_bytes: 9716
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(1)][0]
A = [-1*x for x in A]

import heapq
heapq.heapify(A)

while M != 0:
    x = heapq.heappop(A)
    y = -x // 2
    heapq.heappush(A, -y)
    M -= 1

A = [-1*x for x in A]
print(sum(A))


Measured memory_bytes: 14252
N = int(input())
ls = [input() for _ in range(N)]
ans_ls = []
from collections import Counter
c = Counter(ls)
m = sorted(c.values())[-1]
for k,v in c.items():
    if v == m:
        ans_ls.append(k)
ans_ls.sort()
print(*ans_ls,sep="\n")

Measured memory_bytes: 35968
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N;
    ll x;
    cin >> N >> x;

    vector<ll> a(N);
    rep(i, 0, N) cin >> a[i];

    sort(all(a));
    ll oka = 0ll;
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        if (oka + a[i] <= x) {
            oka += a[i];
            ans++;
        }
    }
    if (x != oka) {
        if (ans == N) {
            ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX_PRIME	(32768)


int prime[MAX_PRIME + 1];

void make_prime(void)
{
    int i;
    int j;
    int n;
    int c;
    
    for (i = 2; i * i <= MAX_PRIME; i++){
        if (prime[i] == 0){
            for (j = i * 2; j <= MAX_PRIME; j += i){
				prime[j] = 1;
            }
        }
    }
}
	


int main(void)
{
	int n;
    int i;
	int count;
	
	make_prime();

    while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		count = 0;
		for (i = 2; i <= n / 2; i++){
			if (prime[i] == 0 && prime[n - i] == 0){
				count++;
			}
		}
		printf("%d\n", count);
    }
    
    return (0);
}

Measured memory_bytes: 728
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 3e3 + 123;
const int PLS = 3e5 + 123;
const int mod = 1e9 + 7;
const ll inf = 1e16;


ll n;
ld a[N], dp[N][N];


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= n; j++) {
            if (j != 0)
                dp[i][j] = a[i] * dp[i - 1][j - 1] + (1 - a[i]) * dp[i - 1][j];
            else
                dp[i][j] = (1 - a[i]) * dp[i - 1][j];
        }
    ld ans = 0.0;
    for (int i = 1; i <= n; i++)
        if (2 * i > n)
            ans += dp[n][i];
    cout.precision(20);
    cout << ans;
}

Measured memory_bytes: 147840
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue>
#include <set>
#include <map>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  int n,y;
  cin >> n >> y;
  
  REP(i,n+1){
    REP(j,n+1-i){
      if(y == 10000*i + 5000*j + 1000*(n-i-j)){
        cout << i << " " << j << " " << n-i-j << endl;
        return 0;
      }
    }
  }
  
        cout << -1 << " " << -1 << " " << -1 << endl;


 return 0;
}

Measured memory_bytes: 256
from itertools import combinations

def build(X, Y):
    A = []
    for x in X:
        res = 1
        for xi in X:
            if x == xi:
                continue
            res *= x - xi
        A.append(Y[x] / res)
    return A

def calc(X, A, x):
    base = 1
    for xi in X:
        base *= i - xi
    return sum(base / (i - x) * a for x, a in zip(X, A))


while 1:
    d = int(input())
    if d == 0:
        break
    N = d+3
    Y = [float(input()) for i in range(N)]

    cnts = [0]*N
    for X in combinations(range(N), d+1):
        U = [0]*N
        for x in X:
            U[x] = 1
        A = build(X, Y)

        for i in range(N):
            if U[i]:
                continue
            res = calc(X, A, i)

            if abs(Y[i] - res) > 0.5:
                cnts[i] += 1
    print(cnts.index(max(cnts)))



Measured memory_bytes: 5680
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int a, b;
    while(scanf("%d %d", &a, &b)!= EOF){
        int res = a > 10?b:100 * (10 - a) + b;
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
char s[110000];
bool c[300];
int l;
int main(){
	scanf("%s",s+1);
	l=strlen(s+1);
	fo(i,1,l) c[s[i]]=1;
	fo(i,'a','z') if (!c[i]){
		putchar(i);
		return 0;
	}
	printf("None\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <algorithm>

using namespace std;

typedef long long ll;
int main() {
    int a;
    ll a1=0,b1=0;
    ll n;
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    map<int,int> mi;
    map<int,int>::iterator it;
    cin>>a;
    while(a--) {
        cin>>n;
        it = mi.find(n);
        if(it != mi.end()) {
            if( (it->second)==1 ) {
                if(n>=a1) {
                    if(a1==0) a1 = n;
                    else {
                        b1=a1;
                        a1=n;
                    }
                } else if (n>b1) {
                    b1 = n;
                }
                mi[n] = 0;
            } else {
                mi[n] = 1;
            }

        } else {
            mi[n] = 1;
        }
    }
    cout<<a1*b1<<'\n';
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <type_traits>
#include <vector>

enum class NotMovableFrom {
	NONE,
	LEFT,
	TOP,
	BOTH,
};

constexpr size_t get_index(size_t x, size_t y, size_t gx) {
	return x + (gx + 1) * y;
}

const NotMovableFrom& operator|=(NotMovableFrom& lhs, NotMovableFrom rhs) {
	using EC = std::underlying_type<NotMovableFrom>::type;
	lhs = static_cast<NotMovableFrom>(static_cast<EC>(lhs) | static_cast<EC>(rhs));
	return lhs;
}

bool operator&(NotMovableFrom lhs, NotMovableFrom rhs) {
	using EC = std::underlying_type<NotMovableFrom>::type;
	return static_cast<bool>(static_cast<EC>(lhs) & static_cast<EC>(rhs));
}


void walk() {
	size_t gx, gy;
	std::cin >> gx >> gy;

	size_t p;
	std::cin >> p;

	// ?§??????§???????????? [0,gx] * [0,gy]
	std::vector<NotMovableFrom> not_movables((gx + 1) * (gy + 1), NotMovableFrom::NONE);

	for (size_t i = 0; i < p; ++i) {
		size_t ax, ay, bx, by;
		std::cin >> ax >> ay >> bx >> by;
		if (ax == bx) {
			not_movables[get_index(ax, std::max(ay, by), gx)] |= NotMovableFrom::TOP;
		} else /*if(ay == by)*/ {
			not_movables[get_index(std::max(ax, bx), ay, gx)] |= NotMovableFrom::LEFT;
		}
	}

#ifdef _DEBUG
	for (size_t y = 0; y <= gy; ++y) {
		for (size_t x = 0; x <= gx; ++x) {
			std::cerr << std::underlying_type<NotMovableFrom>::type(not_movables[get_index(x, y, gx)]) << ' ';
		}
		std::cerr << std::endl;
	}
	std::cerr << std::endl;
#endif

	size_t processing_index = 0;
	std::vector<size_t> line(gx + 1, 0);
	line[0] = 1;
	for (size_t y = 0; y <= gy; ++y) {
		for (size_t x = 0; x <= gx; ++x) {
			int ways = 0;
			NotMovableFrom restriction = not_movables[get_index(x, y, gx)];
			if (x != 0 && false == (restriction & NotMovableFrom::LEFT)) {
				ways += line[x - 1];
			}
			if ((processing_index == 0 || y != 0) && false == (restriction & NotMovableFrom::TOP)) {
				ways += line[x];
			}
			line[x] = ways;
#ifdef _DEBUG
			std::cerr << ways << ' ';
#endif

			++processing_index;
		}
#ifdef _DEBUG
		std::cerr << std::endl;
#endif
	}

	size_t count = line.back();
	if (count) {
		std::cout << line.back() << std::endl;
	} else {
		std::cout << "Miserable Hokusai!" << std::endl;
	}
}

int main() {
	int count;
	std::cin >> count;
	for (int i = 0; i < count; ++i) {
		walk();
	}
}

Measured memory_bytes: 3068
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] arr = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				arr[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isSqrt(getDistance(arr[i], arr[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static int getDistance(int[] arr1, int[] arr2) {
		int ans = 0;
		for (int i = 0; i < arr1.length; i++) {
			ans += (arr1[i] - arr2[i]) * (arr1[i] - arr2[i]);
		}
		return ans;
	}
	
	static boolean isSqrt(int  x) {
		for (int i = 0; i * i <= x; i++) {
			if (i * i == x) {
				return true;
			}
		}
		return false;
	}
}


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

typedef struct{
	int w;
	int h;
} P;
char A[1000][1000];
int a[1000][1000] = {0};
int H, W, K;

int g(int w, int h)
{
	int ret = 1000;
	if(A[h][w] != 'T') return ret;
	if(h < ret) ret = h;
	if(w < ret) ret = w;
	if(H - h - 1 < ret) ret = H - h - 1;
	if(W - w - 1 < ret) ret = W - w - 1;
	return (ret + K - 1) / K;
}

int f(int w, int h)
{
	if(w <  0) return 0;
	if(w >= W) return 0;
	if(h <  0) return 0;
	if(h >= H) return 0;
	if(A[h][w] == '.'){
		A[h][w] = 'T';
		return 1;
	}
	return 0;
}

int main(void)
{
	cin >> H >> W >> K;
	P p;
	Rep(h, H){
		cin >> A[h];
		Rep(w, W){
			if(A[h][w] == 'S'){
				p.w = w;
				p.h = h;
				a[h][w] = 0;
				A[h][w] = 'T';
			}
		}
	}

	queue<P> qu;
	qu.push(p);
	while(!qu.empty()){
		p = qu.front();
		qu.pop();
		int w = p.w;
		int h = p.h;
		if(a[h][w] == K) continue;
		if(f(w-1, h)){a[h][w-1] = a[h][w] + 1; p.w = w-1; p.h = h; qu.push(p);}
		if(f(w+1, h)){a[h][w+1] = a[h][w] + 1; p.w = w+1; p.h = h; qu.push(p);}
		if(f(w, h-1)){a[h-1][w] = a[h][w] + 1; p.w = w; p.h = h-1; qu.push(p);}
		if(f(w, h+1)){a[h+1][w] = a[h][w] + 1; p.w = w; p.h = h+1; qu.push(p);}
	}

	int ans = 1000;
	Rep(h, H){
		Rep(w, W){
			int score = g(w, h);
			if(score < ans) ans = score;
		}
	}
	PrintLn(ans + 1);
	return 0;
}


Measured memory_bytes: 4992
N=int(input())
d={}
cnt=0
for i in range(N):
  s=input()
  if s not in d:
    d[s]=1
  else:
    d[s]+=1
  if cnt<d[s]:
    cnt=d[s]
ans=[]
for k in d:
  if d[k]==cnt:
    ans.append(k)
ans=sorted(ans)
for i in ans:
  print(i)
  

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int X;
    cin>>X;
    long A, B;
    REP(i, 0, 4000){
        A = i-2000;
        REP(j, 0, 4000){
            B = j-2000;
            if(A*A*A*A*A -B*B*B*B*B == X){
                break;
            }
        }    
        if(A*A*A*A*A -B*B*B*B*B == X){
            break;
        }
    }
    cout << A << " " << B << endl;
} 

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  int H,W,M;
  cin >> H >> W >> M;
  vector<P> A(M);
  REP(i,M){
    cin >> A[i].first >> A[i].second;
    A[i].fi--;
    A[i].se--;
  }

  vector<int> vec1(H,0);
  vector<int> vec2(W,0);

  REP(i,M){
    vec1[A[i].fi]++;
    vec2[A[i].se]++;
  }

  int maxh=0;
  int maxw=0;
  REP(i,H){
    maxh=max(maxh,vec1[i]);
  }
  int cnth=0;
  int cntw=0;
  REP(i,H){
    if(vec1[i]==maxh){
      cnth++;
    }
  }
  REP(i,W){
    maxw=max(maxw,vec2[i]);
  }
  REP(i,W){
    if(vec2[i]==maxw){
      cntw++;
    }
  }

  int flag = 1;
  int cnt = 0;
  REP(i,M){
    if(vec1[A[i].fi]==maxh&&vec2[A[i].se]==maxw){
      cnt++;
    }
  }

  if(cntw*cnth==cnt){
    flag=1;
  }else{
    flag=0;
  }
  
  cout << maxh+maxw-flag << endl;
}

Measured memory_bytes: 10392
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  string s;
  unordered_map<string, int> s_map;
  ll ans = 0;
  REP(i,n){
      cin >> s;
      sort(ALL(s));
      ans += s_map[s];
      s_map[s]++;
  }
  
  cout << ans << endl;
  return 0;
}

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

int euclidean_gcd(int a, int b) {
	while(a > 0 && b > 0) {
		if(a > b) a %= b;
		else b %= a;
	}
	int ret = (a == 0 ? b : a);
	return ret;
}

int main(void) {
	// in
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for(int i = 0; i < n; ++i) std::cin >> a[i];

	// gcd
	int gcd = 0;
	for(int i = 0; i < n; ++i) {
		gcd = euclidean_gcd(gcd, a[i]);
	}

	std::cout << gcd << std::endl;

	return 0;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for(int i=0; i<N; i++) cin >> d[i];
	sort(d.begin(), d.end());

	int m = INT_MAX;
	int M = INT_MIN;
	for(int i=0; i<N; i++){
		if(lower_bound(d.begin(), d.end(), d[i]-1)-d.begin() == N/2){
			m = min(m, d[i]-1);
			M = max(M, d[i]-1);
		}
		if(lower_bound(d.begin(), d.end(), d[i])-d.begin() == N/2){
			m = min(m, d[i]);
			M = max(M, d[i]);
		}
		if(lower_bound(d.begin(), d.end(), d[i]+1)-d.begin() == N/2){
			m = min(m, d[i]+1);
			M = max(M, d[i]+1);
		}
	}
	if(m == INT_MAX){
		cout << 0 << endl;
		return 0;
	}
	cout << M-m+1 << endl;
}


Measured memory_bytes: 640
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)       __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}

void solve()
{
	    string s;
	    cin>>s;
	    string t;
	    cin>>t;
	    int cnt=0;
	    for(int i=0;i<s.size();i++)
        {
            if(s[i]!=t[i])
            {
                cnt++;
            }
        }
        cout << cnt << endl;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
   // cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}

Measured memory_bytes: 3796
#include<stdio.h>
#define max 100000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
}Node;

Node T[max];
int D[max],H[max];
int n;

int Depth(int u){
  int d=0;
  while(1){
    u=T[u].p;
    if(u==NIL) break;
    d++;
  }
  return d;
}

int Sibling(int u){
  if(T[u].p==NIL) return NIL;
  if(T[T[u].p].l!=u&&T[T[u].p].l!=NIL) return T[T[u].p].l;
  if(T[T[u].p].r!=u&&T[T[u].p].r!=NIL) return T[T[u].p].r;
  return NIL;
}

int main(){
  int i,id,l,r,p,c,deg;
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    T[id].l=l;
    T[id].r=r;
    if(l!=NIL) T[l].p=id;
    if(r!=NIL) T[r].p=id;
  }

  for(i=0;i<n;i++){
    D[i]=Depth(i);
    H[i]=0;
  }

  for(i=0;i<n;i++){
    if(T[i].l==NIL&&T[i].r==NIL){
      H[i]=0;
      p=T[i].p;
      c=1;
      while(1){
	if(p==NIL) break;
	if(H[p]<c) H[p]=c;
	c++;
	p=T[p].p;
      }
    }
  }

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, ",i,T[i].p,Sibling(i));
    deg=0;
    if(T[i].l!=NIL) deg++;
    if(T[i].r!=NIL) deg++;
    printf("degree = %d, depth = %d, height = %d, ",deg,D[i],H[i]);

    if(T[i].p==NIL){
      printf("root\n");
    }
    else if(T[i].l==NIL&&T[i].r==NIL){
      printf("leaf\n");
    }
    else printf("internal node\n");
  }
  return 0;
}



Measured memory_bytes: 2104
def check(array, c):
    for i in array:
        if i != c:
            return False
    return True

def generate(s, c):
    ret = s[:-1]
    for i in range(len(s)-1):
        if s[i] == c or s[i+1] == c:
            ret[i] = c
    return ret

s = input()
# cで侵食
ans = float("inf")
for c in set(list(s)):
    use = list(s)
    ans_tmp = 0
    while not check(use, c):
        use = generate(use, c)
        # print("".join(use))
        ans_tmp += 1
    ans = min(ans, ans_tmp)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

string s1, s2, s3;

int main() {
  cin >> s1 >> s2 >> s3;
  char c1 = s1.front() - 32;
  char c2 = s2.front() - 32;
  char c3 = s3.front() - 32;
  cout << c1 << c2 << c3;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (i + 1 == P[i]) {
      res++;
      i++;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
void Smax(ll &a,ll b){if(a<b) a=b;}
void Smin(ll &a,ll b){if(a>b) a=b;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

int fa[maxn],a[maxn],b[maxn],siz[maxn];

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

int Sheryang()
{

    int n=read,m=read;

    for(int i=1;i<=n;i++){
        fa[i]=i;
        siz[i]=1;
    }

    for(int i=0;i<m;i++){
        a[i]=read;
        b[i]=read;
    }

    ll ans=0;
    vector<ll>res;
    for(int i=m-1;i>=0;i--){
        res.push_back(1LL*n*(n-1)/2-ans);
        int fx=find(a[i]);
        int fy=find(b[i]);
        if(fx!=fy){
            ans+=1LL*siz[fx]*siz[fy];
            fa[fx]=fy;
            siz[fy]+=siz[fx];
        }
    }

    reverse(res.begin(),res.end());
    for(auto it:res){
        printf("%lld\n",it);
    }
    return 0;
}


Measured memory_bytes: 12916
#include<iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(void)
{
	vector<vector<int>> c(3, vector<int>(3));
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}
	int mina = min({ c[0][0], c[0][1], c[0][2] });
	int s1 = c[0][0] - mina, s2 = c[0][1] - mina, s3 = c[0][2] - mina;
	for (int i = 0; i < 3; i++){
		//cout << s1 << " " << s2 << " " << s3 << endl;
		int minss = min({ c[i][0], c[i][1], c[i][2] });
		int ss1 = c[i][0] - minss, ss2 = c[i][1] - minss, ss3 = c[i][2] - minss;
		if (s1 != ss1 || s2 != ss2 || s3 != ss3){
			cout << "No" << endl;
			return 0;
		}
	}

	mina = min({ c[0][0], c[1][0], c[1][0] });
	s1 = c[0][0] - mina, s2 = c[1][0] - mina, s3 = c[2][0] - mina;
	for (int i = 0; i < 3; i++){
		int minss = min({ c[0][i], c[1][i], c[2][i] });
		int ss1 = c[0][i] - minss, ss2 = c[1][i] - minss, ss3 = c[2][i] - minss;
		if (s1 != ss1 || s2 != ss2 || s3 != ss3){
			cout << "No" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 256
import sys
import math
#ta= map(int,input().split())
ta=int(input())
ans=0
sum=0
li= [int(x) for x in input().split()]
for i in range(ta):
  sum+=li[i]
sum=round(sum/ta)
for i in range(ta):
  ans+=pow((li[i]-sum),2)
print(ans)


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

int main()
{
    long long int a,b,c,d,tmp=0;
    
    while(cin >> a >> b){
        if (a<b) {
            swap(a,b);
        }
        
        c = a;
        d = b;
        
        while (b) {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        
        cout << a << " " << c*d/a << endl;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  /* code */
  int n ;
  int sum = 0;
  cin >> n;
  vector<int> d(n) ;

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

  for (int i = 0; i < n-1; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      sum += d[i] * d[j];
    }  
  }
  
  cout << sum << "\n" ;
  return 0;
}


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

int main() {
  for(int tci = 0; ; tci++) {
    int V, d;
    if(scanf("%d%d", &V, &d)<2) break;
    static int fbnt[2000];
    int x=1,y=2;
    for(int i = 0; i < V; i++) {
      fbnt[i] = y;
      int z = (x+y)%1001;
      x = y;
      y = z;
    }
    sort(fbnt,fbnt+V);
    int grp_cnt = 1;
    for(int i = 1; i < V; i++) {
      if(fbnt[i]-fbnt[i-1]>=d) grp_cnt++;
    }
    printf("%d\n", grp_cnt);
  }
  return 0;
}

Measured memory_bytes: 1044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int counter = 0;
		while (scanner.hasNext()) {

			counter = scanner.nextInt();
			if (counter == 0) {
				break;
			}


			int point = 0;

			boolean left = false;
			boolean right = false;
			boolean status = false;

			for (int i = 0; i < counter; i++) {

				String action = scanner.next();

				switch (action) {
				case "lu":
					left = true;
					break;
				case "ld":
					left = false;
					break;
				case "ru":
					right = true;
					break;
				case "rd":
					right = false;
					break;
				}

				if (left && right && !status) {
					point = point + 1;
					status = true;
				}
				if (!left && !right && status) {
					point = point + 1;
					status = false;
				}
			}

			System.out.println(point);
		}

		scanner.close();
	}
}



Measured memory_bytes: 37748
#B - Postal Code
A,B = map(int,input().split())
S = list(input())

is_A = S[:A]
is_B = S[A+1:A+B+1]
bar = S[A]

if ('-' in is_A) or ('-' in is_B) or bar != '-':
    print('No')
else :
    print('Yes')

Measured memory_bytes: 9196
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] s = scan.next().split("");
		if(s[2].equals(s[3]) && s[4].equals(s[5])) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23892
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		String a[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; 
		for(int i=0 ; i<7 ; i++ ) {
			if(S.equals(a[i])) {
				System.out.println(7-i);
			}
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  string s;
  cin>>s;
  if(s[4]==s[5] and s[2] == s[3]){
  	c("Yes");
  }
  else c("No");
  
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


Measured memory_bytes: 764
A, B, C = [int(i) for i in input().split()]
K = int(input())
cnt = 0

flag = False
while cnt < K:
    cnt += 1
    if A >= B:
        B *= 2
    elif B >= C:
        C *= 2
    
    if A < B and B < C:
        flag = True
        break
        
        
if flag:
    print('Yes')
else :
    print('No')


Measured memory_bytes: 9120
/**************
*	Shell Sort
*************/

#include <iostream>
#include <vector>	//??£?¨?
#include <algorithm>
using namespace std;
typedef vector<int> TList;

void insertionSort(TList& A, int g, int& cnt ){

	for(unsigned int i=g ; i<(A.size()); i++){
		int v = A[i];
		int j = i-g;
		while(j>=0 && A[j]>v){
			A[j+g] = A[j];
			j = j-g;
			cnt++;
		}
		A[j+g] =v;
	}
	return ;
}
//---------------------------------------------------------
void shellSort(TList& A, TList& G, int& cnt){

	for(unsigned int i=0; i<(G.size()); i++){
		insertionSort(A, G[i], cnt);
	}

	return;
}
//--<<???????????¢??°>>-------------------------------------------------------
int main(){

	//??????????¨????
	cin.tie(0);
	ios::sync_with_stdio(false);
	//??\???
	int n;
	cin >> n;
	vector<int> A;
	A.resize(n);
	for(unsigned int i=0; i< A.size(); i++){
		cin >> A[i];
	}
	
	//??????
	TList G;
//	G.reserve(100);//????????????????´???°???????????£??????????????¨????????????
	int sum = 1;
	while(sum <= n){
	    G.push_back(sum);
		sum = sum * 3 + 1;
	}
	reverse(G.begin(), G.end());

	int cnt = 0;
	shellSort(A, G, cnt);

	//??????
	cout << G.size() << endl;
	for(unsigned int i=0; i<(G.size()); i++){
		cout << G[i];
		if(i!=(G.size()-1)){
			 cout <<" " ;
		}
	}
	cout << endl;
	cout << cnt << endl;
	for(int i=0; i< n; i++){
		cout << A[i]<< endl;
	}

	return 0;
}
//-----------------------------------------------

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int3(x, y, n);
    vector<vector<tuple<int, int, int>>> input(4, 
        vector<tuple<int, int, int>>(0));
    rep(i, n) {
        int2(a, b); int2(c, d);
        if ((a == 0 || a == x || b == 0 || b == y) && 
                (c == 0 || c == x || d == 0 || d == y)) {
            if (a == 0) input[0].pb(tuple<int, int, int>(a, b, i));
            else if (b == y) input[1].pb(tuple<int, int, int>(a, b, i));
            else if (a == x) input[2].pb(tuple<int, int, int>(a, -b, i));
            else if (b == 0) input[3].pb(tuple<int, int, int>(-a, b, i));
            
            if (c == 0) input[0].pb(tuple<int, int, int>(c, d, i));
            else if (d == y) input[1].pb(tuple<int, int, int>(c, d, i));
            else if (c == x) input[2].pb(tuple<int, int, int>(c, -d, i));
            else if (d == 0) input[3].pb(tuple<int, int, int>(-c, d, i));
        }
    }

    rep(i, 4) sort(all(input[i]));
    
    stack<int> funami;
    rep(i, 4) {
        rep(j, input[i].size()) {
            if (funami.size()) {
                if (funami.top() == get<2>(input[i][j])) funami.pop();
                else funami.push(get<2>(input[i][j]));
            } else {
                funami.push(get<2>(input[i][j]));
            }
        }
    }

    if (funami.size()) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 8612
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int MAX = 701;
vi G[MAX];
bool adj[MAX][MAX];
int col[MAX];

void dfs(int u, int &a, int &b, int c = 0) {
    if (col[u] != -1) {
        if (col[u] != c) {
            cout << -1 << endl;
            exit(0);
        }
        return;
    }
    col[u] = c;
    if (c)a++;
    else b++;
    each(v, G[u]) {
        dfs(v, a, b, 1 - c);
    }
}

void solve() {
    MEM(col, -1);

    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u][v] = adj[v][u] = true;
    }

    rep(i, N)rep(j, i) {
        if (!adj[i][j]) {
            G[i].push_back(j);
            G[j].push_back(i);
        }
    }


    vector<bool> cu(N + 1), ne(N + 1);
    cu[0] = true;
    rep(i, N) {
        if (col[i] == -1) {
            int a = 0, b = 0;
            dfs(i, a, b);
            for (int j = N; j >= 0; --j) {
                if (cu[j]) {
                    ne[j + a] = true;
                    ne[j + b] = true;
                }
            }
            swap(ne, cu);
            fill(all(ne), false);
        }
    }

    int ans = INT_MAX;
    rep(i, N + 1) {
        int j = N - i;
        if (cu[i]) {
            smin(ans, i*(i - 1) / 2 + j * (j - 1) / 2);
        }
    }
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 3072
n=int(input())
a=[[] for _ in range(n)]
a[0]="a"
al=["a","b","c","d","e","f","g","h","i","j"]
b=[[] for _ in range(n)]
b[0]=[1]
for i in range(1,n):
    for j in range(len(a[i-1])):
        for k in range(b[i-1][j]+1):
            a[i].append(a[i-1][j]+al[k])
            if b[i-1][j]>=k+1:
                b[i].append(b[i-1][j])
            else:
                b[i].append(b[i-1][j]+1)
for i in range(len(a[n-1])):
    print(a[n-1][i])

Measured memory_bytes: 15640
#include<bits/stdc++.h>
#define endl "\n"
#pragma GCC optimize(3)
using namespace std;
string lists[16]={"KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA"};
string a;
signed main()
{
	ios::sync_with_stdio(false);
	cin>>a;
	for(int i=0;i<16;i++)
		if(a==lists[i])
		{
			cout<<"YES\n";
			return 0;
		}
	cout<<"NO\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,M;
    cin >>N >>M;
    vector<ll> num(N);
    ll wa = 0;
    rep(i,N){
        cin >> num[i];
        wa += num[i];
    }
    bool ans = true;
    sort(all(num));
    rep(i,M){
        if(num[N - i - 1] * 4 * M < wa)ans = false;
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>
#include <bitset>
#include <cassert>
#include <cstdint>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
//#define llint
#ifdef llint
#define int ll
static const int INF = LLONG_MAX;
#else
static const int INF = 1e9;
#endif // llint
static const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

signed main() {
	ios::sync_with_stdio(true);
	
	int d, g;
	cin >> d >> g;
	vector<int> p(15);
	vector<int> c(15);
	int ans = INF;
	rep(i, d) {
		cin >> p[i] >> c[i];
	}

	rep(bit, (1 << d)) {
		int sum = 0;
		int numSolve = 0;
		rep(i, d) {
			if (bit & (1 << i)) {
				numSolve += p[i];
				sum += c[i];
				auto x = p[i] * (i + 1) * 100;
				sum += x;
			}
		}
		if (sum >= g) {
			if (ans > numSolve)
				ans = numSolve;
		}else {
			int ld = d;
			vector<int> ns(15, 0);
			int unsolved = 0;
			rep(i,d){
				if (!(bit & (1 << i))) {
					unsolved = i;
				}
			}
			rep(i, p[unsolved] - 1) {
				sum += (unsolved + 1) * 100;
				numSolve++;
				if (sum >= g) {
					if (ans > numSolve)
						ans = numSolve;
					break;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}

ll n ;
ll m ;
ll ans ;
ll d[maxn] ;
ll dp[maxn]; 
ll x ;
ll y ;

vector<ll> adj[maxn] ; 
ll findpath(int v){
	if(dp[v] == -inf){
		for(auto u : adj[v]){
			if(findpath(u) + 1 > dp[v]){
				dp[v] = findpath(u) + 1 ; 
			}
		}
	}	
	return dp[v] ;
 
}
int main()
{
	migmig ;
	cin>>n>>m ; 
	for(int i = 1 ; i <= m ; i ++ ){ 
		cin>>x>>y; 
		adj[x].pb(y)  ;
		d[x]++; 
	}
	for(int i = 1 ; i <= n ; i ++ ){
		dp[i] = -1 * inf ; 
		if(d[i] == 0){ 
			dp[i] = 0 ; 
		}
	}
	
	for(int i = 1 ; i <= n ; i ++ )
	{
		ans = max(ans , findpath(i)) ;
	}
	cout<<ans ; 
}


Measured memory_bytes: 9344
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;

int main() {
  string S;
  cin >> S;
  string ans;  
  rep(i, S.size()) {
    if (S[i] == 'B') {
      if (!ans.empty()) ans = ans.substr(0, ans.size() -1);
    }
    else ans += S[i];
  }

  cout << ans << endl;
  return 0;
}

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

int main(){
    double a,b,c,d=0,e=0,z=0;
    cin>>b;
    a=b;
    a/=1000;
    z=ceil(a);
    z*=1000;
    z-=b;
    cout<<z;
}


Measured memory_bytes: 3692
#include <iostream>

using namespace std;

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

int main() {
	long long a, b, c, d; cin >> a >> b >> c >> d;
	long long cd = c * d / gcd(c, d);
	long long can = b / c - (a - 1) / c + b / d - (a - 1) / d - (b / cd - (a - 1) / cd);
	cout << b - a + 1 - can << endl;

	return 0;
}

Measured memory_bytes: 256