akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int vecfind(vector<int> v, int x) {
    for (int i = 0; i < x; i++) {
        if (v[i] == x) {
            return i;
        }
    }
    return -1;
}

vector<int> sorted(vector<int> original) {
    sort(original.begin(), original.end());
    return original;
}

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> y2p;
    vector<int> prefectures(m);
    vector<int> years(m);
    rep(i,m) {
        cin >> prefectures[i] >> years[i];
        y2p[years[i]] = prefectures[i];
    }
    vector<int> sorted_years = sorted(years);
    int id_count[n+1] = {};
    map<int, int> y2id;
    rep(i,m) {
        int sy = sorted_years[i];
        id_count[y2p[sy]]++;
        int id = id_count[y2p[sy]];
        y2id[sy] = id;
    }
    rep(i,m) {
        int id_1 = prefectures[i];
        int y = years[i];
        int id_2 = y2id[y];
        cout << setfill('0') << right << setw(6) << id_1;
        cout << setfill('0') << right << setw(6) << id_2 << endl;
    }
}

Measured memory_bytes: 12416
#include <stdio.h>
#include <math.h>
int main(){
    int i, j, n, k, count=0;
    scanf("%d",&n);

    for(j=0;j<n;j++){
        scanf("%d",&k);
        if(k==2){ continue;}
        if((k&1)==0){ count++; continue; }
        for(i=3;i<=sqrt(k);i+=2) {
            if (k % i == 0) {
                count++;
                break;
            }
        }
    }
    printf("%d\n",n - count);
    return 0;
}



Measured memory_bytes: 2052
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
int a[200004];
int b[200004];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		b[i]=a[i];
	}
	sort(a+1,a+1+n);
	int m=n/2;
	for(int i=1;i<=n;i++)
	{
		if(b[i]<=a[m])
		printf("%d\n",a[m+1]);
		else
		printf("%d\n",a[m]);
	}
	return 0;
}
//const int maxm=100+10; 
//bool   f[maxm],   //f[i]表示切割在j位置时1~j是否存在i字符  
//q[maxm];   //q[i]表示切割在j位置时j+1~n是否存在i字符 
//int main(){
//    int n, //字符串长度 
//        now,  //当前不同字符数 
//        ans;  //已知最大不同字符数(初始值为0) 
//    register int i,j;
//    char s[maxm]; 
//    scanf("%d",&n);    //读入字符串的长度 
//    scanf("%s",s);     //读入的字符串 
//    for(i=0;i<n;i++){  //枚举切割点 
//        f[s[i]-'a']=true;     
//        //当前i位置的字符在f中标记为存在 
//        memset(q,false,sizeof(q));    //初始化q数组 
//        for(j=i+1;j<n;j++){   
//            //当前j位置的字符在q中标记为存在 
//            q[s[j]-'a']=true;  
//        }
//        now=0;    //初始化now 
//        for(j=0;j<26;j++){
//            if(f[j] && q[j]){    
//                //如果两串中拥有相同字符那么记入到now中 
//                now++; 
//            } 
//        } 
//        ans=max(ans,now); 
//        //若当前不同字符数大于已知不同字符则更新答案 
//    }
//    printf("%d",ans);  //打印答案 
//    return 0; 
//}

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    ll n;
    ll h[20];

    cin >> n;

    REP(i, n){
        cin >> h[i];
    }

    ll ans = n;
    REP(i, n){
        if (i == 0){
            continue;
        }

        REP(j, i){
            if (h[j] > h[i]){
                ans--;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{ 
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in); 
		for(int count = 0; count<7; count++){
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sa = a - b;
		System.out.println(sa);
		}
		
	}
	}	

Measured memory_bytes: 17316
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
#define INF (1e18)+1
 
int nChoosek( int n, int k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i; 
    }
    return result;
}

int choose2(int n){
	
	return n*(n-1)/2;
}
 
int arr[200001]; 
 
int32_t main() {
 
 	
 	int N;
 	cin >> N;
 	
 	int maxi = INT_MAX;
 	int	cnt =0;
 	for(int i=0; i<N; i++){
 		
 		cin >> arr[i];
 		if(arr[i] <= maxi){
 			maxi = arr[i];
 			cnt++;
		 }
	 }
  	cout << cnt << endl;
   
}

Measured memory_bytes: 4740
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
    long long N,h,n,t1,t2;int s=0;
    scanf("%lld",&N);
    for(h=1;h<=3500;h++)
    {
        for(n=1;n<=N;n++)
        {
            t1=N*h*n;
            t2=4*h*n-N*n-N*h;
            if(t2>0&&t1%t2==0)
            {
                printf("%lld %lld %lld\n",h,n,t1/t2);
                s=1;break;
            }
        }
        if(s)break;
    }
}


Measured memory_bytes: 128
import sys


def input(): return sys.stdin.readline().strip()


N, M = (list)(map(int, input().split()))
edge = []

for _ in range(M):
    edge.append((list)(map(int, input().split())))


inf = 10**15

d = [inf]*(N+1)
d[1] = 0
ans = inf
for i in range(N):
    update = False
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            update = True

    if not update:
        break

neg = [False]*(N+1)
for i in range(N):
    for a, b, c in edge:
        c = -c
        new_d = d[a]+c
        if d[a] != inf and d[b] > new_d:
            d[b] = new_d
            neg[b] = True
        if neg[a]:
            neg[b] = True

if neg[-1]:
    print('inf')
else:
    print(-d[-1])


Measured memory_bytes: 3572
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        d[input()] += 1
    M = int(input())
    for _ in range(M):
        d[input()] -= 1
    print(max(0,max(d.values())))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import heapq

N = int(input())

red = []
for i in range(N):
    x,y = map(int, input().split())
    heapq.heappush(red, (-y, x))

blue = []
for i in range(N):
    x,y = map(int, input().split())
    heapq.heappush(blue, (x,y))

ans = 0
for i in range(N):
    tmp = []
    bx,by = heapq.heappop(blue)
    flag = True
    while flag:
        mry, rx = heapq.heappop(red)
        if bx > rx and by > -mry:
            ans += 1
            flag = False
            if len(tmp) > 0:
                for mry,rx in tmp:
                    heapq.heappush(red, (mry, rx))
        else:
            tmp.append((mry, rx))

        if len(red) == 0:
            if len(tmp) > 0:
                for mry,rx in tmp:
                    heapq.heappush(red, (mry, rx))
            break
            
print(ans)


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solver();
	}

	double EPS = 1e-11;

	void solver() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			double w = sc.nextDouble(), h = sc.nextDouble();
			int n = sc.nextInt();
			if (w == 0 && h == 0 && n == 0)
				break;
			n *= 2;
			double[] x = new double[n + 2];
			double[] y = new double[n + 2];
			for (int i = 0; i < n; i++) {
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
			}
			x[n] = w;
			y[n] = 0;
			x[n + 1] = w;
			y[n + 1] = h;
			ArrayList<Double> y1 = new ArrayList<>();
			for (int i = 0; i < n + 2; i++) {
				for (int j = i + 1; j < n + 2; j++) {
					if (x[i] != x[j]) {
						double tmp = (y[i] - y[j]) / (x[i] - x[j]) * (-x[j]) + y[j];
						if (0 < tmp && tmp < h)
							y1.add(tmp);
					}
				}
			}
			y1.add(0.0);
			y1.add(h);
			y1.sort(null);
			for (int i = 0; i < y1.size() - 1; i++) {
				while (i < y1.size() - 1 && y1.get(i) == y1.get(i + 1)) {
					y1.remove(i);
				}
			}

			double ans = 0;

			for (int i = 0; i < y1.size() - 1; i++) {
				double[] y2 = new double[n];
				if (Math.abs(y1.get(i) - y1.get(i + 1)) < EPS)
					continue;
				double y_mid = (y1.get(i) + y1.get(i + 1)) / 2;
				for (int j = 0; j < n; j++) {
					double tmp;
					if (x[j] == 0 && y[j] >y_mid)
						tmp = h;
					else if(x[j]==0&&y[j]<y_mid)
						tmp=0;
					else
						tmp = (y[j] - y_mid) / ((x[j] + EPS) - 0) * w + y_mid;
					if (tmp < 0)
						tmp = 0;
					if (tmp > h)
						tmp = h;
					y2[j] = tmp;
				}
				Arrays.sort(y2);
				ans += (y2[n / 2] - y2[n / 2 - 1]) * (y1.get(i + 1) - y1.get(i));
				// System.out.println(ans / (h * h));
			}
			System.out.println(ans / (h * h));
		}
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 164956
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
int main() {
    int N,K;
    cin>>N>>K;

    vector<int> h(N);
    int ans=0;

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

   cout<<ans<<endl;

    return 0;
}

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

vector<vector<int>> moves;
int memo[100001];

int check(int v) {
    if (memo[v] != -1) {
        return memo[v];
    }
    if (moves[v].size() == 0) {
        return memo[v] = 0;
    }
    int m = 0;
    for (int to : moves[v]) {
        int tmp = check(to);
        if (tmp > m)
            m = tmp;
    }
    return memo[v] = m + 1;
}

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, N) memo[i] = -1;
    moves.assign(N, vector<int>());

    rep(i, M) {
        int from,to;
        cin >> from >> to;
        moves[from - 1].push_back(to - 1);
    }

    int m = 0;
    for (int i = 0; i < N; i++) {
        if (memo[i] == -1)
            check(i);
        if (memo[i] > m)
            m = memo[i];
    }
    cout << m << endl;
}

Measured memory_bytes: 10932
#include<stdio.h>

int main(void){
	int K,A,B,comp;
	
	scanf("%d",&K);
	scanf("%d %d",&A,&B);
	
	int worst = A/K;
	int best = B/K;
	
	while(1){
		comp = K*worst;
		if(A <= comp && comp <= B){
			printf("OK\n");
			break;
		}else if(comp < A){
			worst++;
		}else{
			printf("NG\n");
			break;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1644
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int ret = 0;
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      if ((i + 1) % 2 != 0 && a % 2 != 0) {
        ret++;
      }
    }
    System.out.println(ret);
  }
}

Measured memory_bytes: 35760
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  cout << b*2-a <<endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

bool isprime(int n){
  for(int i = 2;i*i <= n;i++)if(!(n%i))return false;
  return true;
}

int main(){

  int n;
  cin >> n;
  vector<int> v(100,0);
  for(int i = 2;i <= n;i++){
    if(!isprime(i))continue;
    int cnt = 0;
    int l = i;
    while(l <= n){
      cnt += n/l;
      l *= i;
    }
    if(cnt < 2)v[0]++;
    else if(cnt < 4)v[3]++;
    else if(cnt < 14)v[5]++;
    else if(cnt < 24)v[15]++;
    else if(cnt < 74)v[25]++;
    else v[75]++;
  }
  ll res = 0;
  res += v[75];
  res += (v[3]+v[5]+v[15])*(v[25]+v[75])+(v[25]+v[75])*(v[25]+v[75]-1);
  res += v[5]*(v[15]+v[25]+v[75])+(v[15]+v[25]+v[75])*(v[15]+v[25]+v[75]-1);
  res += v[3]*(v[5]+v[15]+v[25]+v[75])*(v[5]+v[15]+v[25]+v[75]-1)/2+(v[5]+v[15]+v[25]+v[75])*(v[5]+v[15]+v[25]+v[75]-1)*(v[5]+v[15]+v[25]+v[75]-2)/2;
  cout << res << endl;

  



  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX_N 100001


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;			// スライム個数
int L[MAX_N];	// スライムの色配列

int main () {

	int cnt = 0;

	// 個数と長さの読込み
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", L + i);

	// ソート
	std::sort(L, L + N);

	// 
	for(int i = 0; i < N; i++) {
		for(int  j = i + 1; j < N; j++) {
			// 2辺の和を超える最小の添え字を2分探索
			cnt += std::lower_bound(L, L+N, L[i]+L[j]) - &L[j] - 1;
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
N = int(input())
tree = [[] for _ in range(N+1)]
for i in range(N-1):
    u,v,w = map(int, input().split())
    tree[u].append([v,w])
    tree[v].append([u,w])

d = [-1 for _ in range(N+1)]
d[1] = 0
q = [1]

while q:
    cur = q.pop()
    for n,l in tree[cur]:
        if d[n] == -1:
            d[n] = d[cur] + l
            q.append(n)

for l in d[1:]:
    print(l%2)


Measured memory_bytes: 49728
#include<stdio.h>

typedef struct{
  char pic;
  int num;
}Trump;

void change(Trump *, Trump *);
void BubbleSort(Trump *, int);
void SelectionSort(Trump *, int);
void Print(Trump *, int);
int Compare(Trump *, Trump *, int);


int main(){
  int n,i,com;
  Trump T1[100];
  Trump T2[100];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf(" %c%d",&T1[i].pic,&T1[i].num);
    T2[i] = T1[i];
  }

  BubbleSort(T1,n);
  SelectionSort(T2,n);

  com = Compare(T1,T2,n);

  Print(T1,n);
  printf("Stable\n");
  Print(T2,n);
  if(com == 1) printf("Stable\n");
  else printf("Not stable\n");

 return 0;
}

void change(Trump *x, Trump *y){
  Trump z;

  z = *x;
  *x = *y;
  *y = z;
}

void BubbleSort(Trump A[], int x){
  int i,j;
  Trump a;
  for(i = 0 ; i < x ; i++){
    for(j = x - 1 ; j >= i + 1 ; j--){
      if(A[j].num < A[j-1].num) change(&A[j],&A[j-1]);
    }
  }
}

void SelectionSort(Trump A[], int x){
  int i,j,minj;
  Trump a;

  for(i = 0 ; i < x ; i++){
    minj = i;
    for(j = i ; j < x ; j++){
      if(A[j].num < A[minj].num) minj = j;
    }
    change(&A[i],&A[minj]);
  }
}

void Print(Trump A[], int x){
  int i;

  for(i = 0 ; i < x ; i++){
    if(i > 0) printf(" ");
    printf("%c%d",A[i].pic, A[i].num);
  }
  printf("\n");
}

int Compare(Trump A1[], Trump A2[], int x){
  int i;

  for(i = 0 ; i < x ; i++){
    if(A1[i].pic != A2[i].pic) return 0;
  }
  return 1;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

int H, W;
char A[10][10];


bool check_area(int x, int y){
    // x--;
    y++;
    reps(i,y,H) rep(j,x) {
        if (A[j][i] == '#') return true;
    }
    return false;
}

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

    rep(i,H) rep(j,W) {cin >> A[j][i];}

    int flag = 1;

    rep(i,H){
        reps(j,1,W){
            if (A[j][i] == '#'){
                if (check_area(j,i)) {flag = 0;}
            }
        }
    }

    if(flag){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
int main()
{
 ll x;
 cin>>x;
 ll p=100;
 int c=0;
 while(p<x)
 {
     p+=p/100;
     c++;
 }
 cout<<c<<"\n";
  return 0;
}


Measured memory_bytes: 3604
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool ihmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n; ll d; read(n, d);
  vector<ll> x(n), y(n);
  int ans = 0;
  rep(i, 0, n) {
    read(x[i], y[i]);
    if (x[i] * x[i] + y[i] * y[i] <= d * d)
      ans++;
  }

  write(ans);
}



Measured memory_bytes: 6360
n,k = map(int,input().split())
p = list(map(int,input().split()))

a = []
for e in p:
    a.append((1+e)/2.0)

tmp = 0
for i in range(k):
    tmp += a[i]

res = []
res.append(tmp)
for i in range(k,n):
    tmp += a[i] - a[i-k]
    res.append(tmp)

print(max(res))

Measured memory_bytes: 75912
import unittest
import collections


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(['...', '...', '...']), 4)

    def test_2(self):
        self.assertEqual(think(['...#.', '.#.#.', '.#...']), 10)


def solve():
    maze = read()
    result = think(maze)
    write(result)


def read():
    h, w = read_int(2)
    maze = []
    for _ in range(h):
        maze.append(read_line(n=w))
    return maze


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(maze):
    wall = '#'
    h, w = get_height_and_width_of(maze)
    longest_path_length = 0

    for y in range(h):
        for x in range(w):
            if maze[y][x] == wall:
                continue
            longest_path_length = max(longest_path_length, search(maze, x, y, wall))

    return longest_path_length


def write(result):
    print(result)


def get_height_and_width_of(maze):
    return len(maze), len(maze[0])


def search(maze, x, y, wall):
    h, w = get_height_and_width_of(maze)
    inf = h * w + 1

    dp = prepare_dp_table(h, w, inf)

    return bfs(maze, dp, w, h, x, y, wall)


def prepare_dp_table(h, w, inf):
    return [[inf for _ in range(w)] for _ in range(h)]


def bfs(maze, dp, w, h, x, y, wall):
    queue = collections.deque([])
    queue.append((x, y, 0))

    max_distance = 0

    diff_xy = [
        (-1, 0), (1, 0), (0, -1), (0, 1)
    ]

    while queue:
        xx, yy, distance = queue.popleft()
        if dp[yy][xx] <= distance:
            continue
        dp[yy][xx] = distance
        max_distance = max(max_distance, distance)

        for dx, dy in diff_xy:
            nx, ny = xx + dx, yy + dy
            if not in_range(w, h, nx, ny):
                continue
            if maze[ny][nx] == wall:
                continue
            if dp[ny][nx] <= distance + 1:
                continue
            queue.append((nx, ny, distance + 1))

    return max_distance


def in_range(w, h, x, y):
    return 0 <= x < w and 0 <= y < h


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 61164
#include"bits/stdc++.h"
using namespace std;
int main(){
	set<int> x{1,3,5,7,8,10,12},y{4,6,9,11},z{2};
	int a,b;
	cin>>a>>b;
	if((x.find(a)!=x.end()&&x.find(b)!=x.end())||(y.find(a)!=y.end()&&y.find(b)!=y.end())||(z.find(a)!=z.end()&&z.find(b)!=z.end()))
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
struct Edge
{
	int to,next;
}w[1005];
int t,n,d[55],d2[55],pre[55],sum,rd[55],h[55],cnt,prt[55];
bool flags=1;
bool ma[55][55],ma2[55][55];
bool vis[55],vst[55];
void add(int x,int y)
{
	w[++cnt]=(Edge){y,h[x]};
	h[x]=cnt;rd[y]++;
}
void dfs(int x,int fa)
{
	vis[x]=1;prt[x]=fa;
	for(int i=1;i<=n;i++) if(ma2[x][i]&&!vis[i]) dfs(i,x);
}
void dfs2(int x,int fa)
{
	vis[x]=1;
	if(prt[x]!=fa) vst[x]=1,sum++;
	else vst[x]=0;
	if(fa) add(fa,x);
	int s=1;
	for(int i=1;i<=n;i++) if(ma[x][i]&&!vis[i]) dfs2(i,x),s&=vst[i];
	if(vst[x]&&!s) flags=0;
}
void dfs3(int x,int fa)
{
	vis[x]=1;
	if(vst[x]&&vst[fa]) add(x,fa);
	for(int i=1;i<=n;i++) if(ma2[x][i]&&!vis[i]) dfs3(i,x);
}
bool solve(int x)
{
	memset(rd,0,sizeof(rd));
	memset(vis,0,sizeof(vis));memset(h,0,sizeof(h));cnt=0;
	dfs(x,0);
	memset(vis,0,sizeof(vis));
	flags=1;
	dfs2(x,0);
	memset(vis,0,sizeof(vis));
	dfs3(x,0);
	if(!flags) return 0;
	queue<int> q;
	for(int i=1;i<=n;i++) if(!rd[i]) q.push(i);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=h[u];i;i=w[i].next)
		{
			int y=w[i].to;
			if(!(--rd[y])) q.push(y);
		}
	}
	
	for(int i=1;i<=n;i++) if(rd[i]) return 0;
	return 1;
}
int main()
{
	t=read();
	while(t--)
	{
		memset(ma,0,sizeof(ma));memset(ma2,0,sizeof(ma2));
		memset(d,0,sizeof(d));
		n=read();
		for(int i=1;i<n;i++)
		{
			int x,y;
			x=read(),y=read();
			d[x]++,d[y]++;
			pre[x]=y;pre[y]=x;
			ma[x][y]=ma[y][x]=1;
		}
		for(int i=1;i<n;i++)
		{
			int x,y;
			x=read(),y=read();
			ma2[x][y]=ma2[y][x]=1;
		}
		bool flag=1;
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) if(ma[i][j]^ma2[i][j]) flag=0;
		if(flag)
		{
			puts("0");
			continue;
		}
		int ans=1e9;
		for(int u=1;u<=n;u++)
		{
			sum=0;
			if(solve(u)) ans=min(ans,sum);
			if(d[u]>1) continue;
			for(int v=1;v<=n;v++)
			{
				if(u==v) continue;
				if(v==pre[u]) continue;
				sum=1;
				ma[u][pre[u]]=ma[pre[u]][u]=0;
				ma[u][v]=ma[v][u]=1;
				if(solve(u)) ans=min(ans,sum);
				ma[u][v]=ma[v][u]=0;
				ma[u][pre[u]]=ma[pre[u]][u]=1;
			}
		}
		if(ans==1e9) puts("-1");
		else printf("%d\n",ans);
	}
}

Measured memory_bytes: 3736
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

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

  int n, c, k;
  cin >> n >> c >> k;
  vi t(n);
  REP(i, n) { cin >> t[i]; }
  sort(ALL(t));

  int ans = 0;
  int itr = 0;
  while (itr < n) {
    int next = upper_bound(ALL(t), t[itr] + k) - t.begin();
    if (next == itr) {
      itr++;
    } else {
      itr = next - itr > c ? itr + c : next;
    }
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
	int n[6],i;
	for(i=0;i<6;i++) cin>>n[i];
	sort(n,n+4);
	if(n[5]<=n[4]) cout<<n[1]+n[2]+n[3]+n[4]<<endl;
	else cout<<n[1]+n[2]+n[3]+n[5]<<endl;
	return 0;
}


Measured memory_bytes: 3032
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <math.h>

#define NumPlusIter(start,end) for(int start = 0; start < end; start++)

using namespace std;

int main() {
	vector<int> result(91,0);
	string s;
	cin >> s;
	NumPlusIter(i, s.size())
		result[s[i]] = 1;
	if (result['N'] != result['S']) {
		cout << "No" << endl;
		return 0;
	}
	if (result['E'] != result['W']) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	v32 curr(3, 0);
	vector<v32> next(3, v32());
	curr[0] = a, curr[1] = b, curr[2] = c;
	vector<string> arr(n);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		for (char c : arr[i])
			next[c - 'A'].push_back(i);
	}
	vector<char> ans;
	for (int i = 0; i < n; i++)
	{
		int idx1 = arr[i][0] - 'A', idx2 = arr[i][1] - 'A';
		if (curr[idx1] < curr[idx2])
		{
			curr[idx1]++;
			curr[idx2]--;
			ans.push_back(arr[i][0]);
		}
		else if (curr[idx1] > curr[idx2])
		{
			curr[idx1]--;
			curr[idx2]++;
			ans.push_back(arr[i][1]);
		}
		else
		{
			int temp1 = lower_bound(next[idx1].begin(), next[idx1].end(), i + 1) - next[idx1].begin();
			int temp2 = lower_bound(next[idx2].begin(), next[idx2].end(), i + 1) - next[idx2].begin();
			if (temp1 == sz(next[idx1]))
				temp1 = 1e9;
			else
				temp1 = next[idx1][temp1];
			if (temp2 == sz(next[idx2]))
				temp2 = 1e9;
			else
				temp2 = next[idx2][temp2];
			if (temp1 < temp2)
			{
				curr[idx1]++;
				curr[idx2]--;
				ans.push_back(idx1 + 'A');
			}
			else
			{
				curr[idx1]--;
				curr[idx2]++;
				ans.push_back(idx2 + 'A');
			}
		}
		for (int x : curr)
		{
			if (x < 0)
			{
				cout << "No" << ln;
				return;
			}
		}
		db(curr);
	}
	cout << "Yes" << ln;
	for (char c : ans)
		cout << c << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 7796
#include<iostream>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x+r>w||x-r<0||y+r>h||y-r<0)cout<<"No\n";
	else{
		cout<<"Yes\n";
	}
	return 0;
}


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

int main() {
    
  int N;
  cin >> N;
  int count=0;
  for(int i=0;i<N;i++){
    int A;
    cin >> A;
    int coun=0,n=0;
    if(A%2==0){
    while(n==0){
      A/=2;
      n=A%2;
      coun++;
    }
      if(i>0&&coun<count){
        count=coun;
      }
      else if(i>0&&coun>count){
        continue;
      }
      else{
        count=coun;
      }
    }
    else{
      break;
    }
  }
  cout<<count<<endl;
        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int t = n * 360 / gcd(n, 360);
    cout << t / n << endl;
    return 0;
}

Measured memory_bytes: 3612
A = list(map(int,input().split()))
cnt_5 = 0
cnt_7 = 0
for i in range(3):
	if A[i] == 5:
		cnt_5+=1
	if A[i] == 7:
		cnt_7 +=1
if cnt_5 == 2 and cnt_7 == 1:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll n, m, d;
	cin >> n >> m >> d;

	ll x = n - d;
	if (d > 0) { x *= 2; }

	double ans = (double)(x * (m - 1)) / double(n * n);

	cout << fixed << setprecision(12);
	cout << ans << endl;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll i,j,k,l,m,n;
	string str;
	cin>>str;
	set <char> a;
	for(i=0;i<str.length();i++)
	{
		a.insert(str[i]);
	}
	set<char>::iterator itr;
	itr=a.end();
	k=0;
	for(i=97;i<=122;i++)
	{
		if(a.count((char)i)==0)
		{
			k=1;
			break;
		}
	}
	if(k==0)
		cout<<"None"<<"\n";
	else
		cout<<(char)i<<"\n";

	return 0;
}
	

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
int main(){
    int a,b;
    cin >> a >> b;
//    int ans[5];
    vector<int> ans(5); 
    int val;
    string str,rev;
    int count = 0;
    for(int i = a; i <= b; i++) {
        val = i;
        ans[0] = val % 10; val /= 10;
        ans[1] = val % 10; val /= 10;
        ans[2] = val % 10; val /= 10;
        ans[3] = val % 10; val /= 10;
        ans[4] = val % 10; val /= 10;
        str = to_string(i);
//        reverse(ans.begin(),ans.end());
        rev = "";
        for(int i = 0; i <5; i++){
            rev += to_string(ans[i]);
        }
//        cout << "str :" << str << endl;
//        cout << "rev :" << rev << endl;
        if(str == rev){
            count += 1;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int ,int> P;
int N,K;
signed main(){
  cin >> N >> K;
  int mx=(N-1)*(N-2)/2;
  if(mx<K){
    puts("-1");
    return 0;
  }
  vector<P> ans;
  for(int i=0;i<N-1;i++){
    ans.push_back(P(i+1,N));
  }
  int add=mx-K;
  vector<P> edge;
  for(int i=0;i<N-1;i++){
    for(int j=0;j<i;j++){
      edge.push_back(P(i+1,j+1));
    }
  }
  for(int i=0;i<add;i++) ans.push_back(edge[i]);
  cout << ans.size() << endl;
  for(int i=0;i<ans.size();i++){
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
bool exprime(int x){
  if(x<=1) return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)
      return false;
  }
  return true;
}
int main()	{
  int a;
  cin>>a;
  int i=a;
  for(int i=a;;i++){
    bool ex;
    ex=exprime(i);
    if(ex==true){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
num =input()


for i in range(num):
    x = map(float, raw_input().split(' '))

    if x[1]-x[3] == 0 or x[5]-x[7] == 0:
        if x[1]-x[3] == 0 and x[5]-x[7] == 0:
            print 'YES'
        else:
            print 'NO'
        
    elif (x[0]-x[2])/(x[1]-x[3]) == (x[4]-x[6])/(x[5]-x[7]):
        print 'YES'
    else:
        print 'NO'

Measured memory_bytes: 5648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		int n = Integer.parseInt(input);
		
		int m = n;
		int pow = 0;
		do {
			m /= 2;
			pow++;
		}while(m > 1);
		
		int result = 1;
		if(m == 1) {
			for(int i = 0; i < pow; i++) {
				result *= 2;
			}
		} else {
			result = n;
		}
		System.out.println(result);		
		
	}

}


Measured memory_bytes: 21972
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

int dp[105][4][2];

void Main() {
    string s; int k; 
    cin >> s >> k;
    int n = s.size();
    
    // dp[i][j][full] 
    // 上から i 桁目まで決定, 0 <= i <= n
    // 非ゼロをいくつ使ったか ０ <= j <= k <= 3 
    // full = 0, if 上から i 桁目が s のそれと一致
    // full = 1, otherwise

    dp[0][0][0] = 1;
    dp[0][0][1] = 0;
    
    rep(i, n) rep(j, 4) rep(full, 2){
        int nd = s[i] - '0';
        rep(d, 10){
            int ni = i+1;
            int nj = j;
            int nfull = full;
            if(d != 0) nj++;
            if(nj > k) continue;
            if(full == 0){
                if(d > nd) continue;
                if(d < nd) nfull = 1;
            }  
            dp[ni][nj][nfull] += dp[i][j][full];
        }
    }
    
	cout << dp[n][k][0] + dp[n][k][1] << endl;
	return;
}

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


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] d = new int[N];
		int i = 0;
		while (true) {
			d[i] = sc.nextInt();
			i++;
			if (i >= N) {
				break;
			}
		}
		int sum = 0;
		for (i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				sum += d[i] * d[j];
			}
		}
		System.out.println(sum);
	}

}


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

int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  string s;
  char old;
  bool flag = true;
  for(int i = 0;i < n;i++){
    cin >> s;
    if(i != 0){
      if(s[0] != old){
        flag = false;
      }
    }
    if(mp[s] != 0){
      flag = false;
    }
    mp[s]++;
    old = s[s.size()-1];
  }

  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];

    deque<P> que;
    que.push_front({0, 0});
    ll dy[2] = {0, 1};
    ll dx[2] = {1, 0};

    vector<vector<ll>> dist(H, vector<ll>(W, INF));
    if (s[0][0] == '.')
        dist[0][0] = 0;
    else
        dist[0][0] = 1;
    while (que.size()) {
        P now = que.front();
        que.pop_front();

        if (s[now.fi][now.se] == '.') {
            rep(i, 2) {
                ll ny = now.fi + dy[i], nx = now.se + dx[i];
                if (H <= ny || W <= nx) continue;
                if (s[ny][nx] == '#') {
                    if (dist[ny][nx] > dist[now.fi][now.se] + 1) {
                        dist[ny][nx] = dist[now.fi][now.se] + 1;
                        que.push_back({ny, nx});
                    }
                } else {
                    if (dist[ny][nx] > dist[now.fi][now.se]) {
                        dist[ny][nx] = dist[now.fi][now.se];
                        que.push_front({ny, nx});
                    }
                }
            }
        } else {
            rep(i, 2) {
                ll ny = now.fi + dy[i], nx = now.se + dx[i];
                if (H <= ny || W <= nx) continue;
                if (s[ny][nx] == '#') {
                    if (dist[ny][nx] > dist[now.fi][now.se]) {
                        dist[ny][nx] = dist[now.fi][now.se];
                        que.push_back({ny, nx});
                    }

                } else {
                    if (dist[ny][nx] > dist[now.fi][now.se]) {
                        dist[ny][nx] = dist[now.fi][now.se];
                        que.push_front({ny, nx});
                    }
                }
            }
        }
        /*rep(i, H) {
            rep(j, W) {
                if (dist[i][j] != INF)
                    cout << dist[i][j] << " ";
                else
                    cout << -1 << " ";
            }

            cout << "\n";
        }
        cout << "\n";*/
    }

    cout << dist[H - 1][W - 1] << "\n";
    return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N, Q, A, B, M, K;
string S;
vector<ll> vec;

void solve() {
	cin >> S;
	ll win = 0;
	rep(i, S.size()) {
		if (S[i] == 'o') win++;
	}
	if (win + 15 - S.size() >= 8) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	h, w := scanInt(), scanInt()
	ss := make([]string, h)
	for i := 0; i < h; i++ {
		ss[i] = scanString()
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if ss[i][j] == '.' {
				continue
			}
			f := false
			for k := 0; k < 4; k++ {
				if i+dy[k] >= 0 && i+dy[k] < h && j+dx[k] >= 0 && j+dx[k] < w {
					if ss[i+dy[k]][j+dx[k]] == '#' {
						f = true
					}
				}
			}
			if !f {
				fmt.Fprintln(wr, "No")
				return
			}
		}
	}
	fmt.Fprintln(wr, "Yes")
}

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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

vector<int> z_algo(string S){
    vector<int> ret(S.size());
    ret[0]=S.size();
    int i=1,j=0;
    while(i<S.size()){
        while(i+j<S.size()&&S[j]==S[i+j])++j;
        ret[i]=j;
        if(j==0){++i;continue;}
        int k=1;
        while(i+k<S.size()&&k+ret[k]<j)ret[i+k]=ret[k],k++;
        i+=k;j-=k;
    }
    return ret;
}

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

    int res = 0;
    rep(i,N){//最初のやつの初めの文字の位置を固定
        vector<int> Z = z_algo(S.substr(i,N-i));
        for(int j=0;j<Z.size();j++){//2つ目のやつの初めの文字の位置
            int cand = Z[j];
            res = max(res,min(j,Z[j]));
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n+1]={0};
    for(int i=1;i*i<=n;i++)
    {
        for(int j=1;j*j<=n;j++)
        {
            for(int k=1;k*k<=n;k++)
            {
                ll num=i*i+j*j+k*k+i*j+j*k+k*i;
                if(num>n)
                break;
                arr[num]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    cout<<arr[i]<<"\n";


    
    return 0;
}

Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main() {
        Scanner cin = new Scanner();
        int N = cin.Int();
        var F = new int[N, 10];
        var P = new int[N, 11];

        for (int i = 0; i < N; i++) {
            var tmp = cin.ArrayInt(10);
            for (int j = 0; j < 10; j++) {
                F[i, j] = tmp[j];
            }
        }
        for (int i = 0; i < N; i++) {
            var tmp = cin.ArrayInt(11);
            for (int j = 0; j < 11; j++) {
                P[i, j] = tmp[j];
            }
        }

        int ans = int.MinValue;
        for (int i = 1; i < (1 << 10); i++) {
            int tmp = 0;
            for (int j = 0; j < N; j++) {
                int cnt = 0;
                for (int k = 0; k < 10; k++) {
                    if ((i >> k & 1)==1 && F[j, k]==1) cnt++;
                }
                tmp += P[j, cnt];
            }
            ans = Math.Max(ans, tmp);
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


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

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

const long long MOD = 1000000007;

int main(){
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  if(k>=n){
    ans=min(n,k-n);
  }
  else{
    n=n%k;
    ans=min(n,k-n);
  }
  cout<<ans<<endl;
}


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

int main() {
    int N;
    cin >> N;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
    }


    ll ans = LINF;
    for (ll i = -100; i <= 100; i++) {
        ll tmp = 0;
        // iに書き換える
        rep(j, N) {
            ll x = (i - A[j]) * (i - A[j]);
            tmp += x;
        }

        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616