akhauriyash/Code-Regression huggingface dataset:
s = str(input())
ns = s.replace('x', '')
l = len(ns)
if l == 0:
    print(0)
elif l == 1:
    idx = s.find(ns)
    print(abs(idx - (len(s) - idx - 1)))
else:
    cnt = 0
    L = []
    for i in range(l // 2):
        if ns[i] != ns[-(i+1)]:
            print(-1)
            break
        else:
            L.append(ns[i])
    else:
        if l % 2:
            L.append(ns[i+1])
        pleft = 0
        pright = 0
        for c in L:
            if pleft == 0:
                left = s.find(c)
            else:
                left = s[pleft:].find(c)
            if pright == 0:
                right = len(s) - s.rfind(c) - 1
            else:
                right = len(s) - (s[:-pright].rfind(c) + pright + 1)
            pleft = left + pleft + 1
            pright = right + pright + 1
            cnt += abs(left - right)
        print(cnt)


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int now = 0;
	vector<bool> used(N, false);
	while (K > 0) {
		if (used[now]) {
			// 閉路検出
			int s = now;
			Int cnt = 0;
			bool flg = false;
			while (K > 0) {
				if (now == s && flg) { break; }
				if (now == s) { flg = true; }
				now = g[now];
				++cnt;
				--K;
			}
			if (K <= 0) { break; }
			
			K %= cnt;
			while (K > 0) {
				now = g[now];
				--K;
			}
			break;
		}
		used[now] = true;
		now = g[now];
		--K;
	}
	cout << now + 1 << endl;

	return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int x[n+1];
  int eve[1000000];
  fill(eve,eve+1000000,0);
  vector<pair<int,int>> v;
  for(int i=1;i<=n;i++){
    cin>>x[i];
    eve[x[i]]=i;
    v.push_back(make_pair(x[i],i));
  }
  sort(v.begin(),v.end());
  int now[n+1];
  fill(now,now+n+1,0);
  vector<int> ans;
  for(int i=0;i<v.size();i++){
    for(int j=0;j<v[i].second-1;j++)ans.push_back(v[i].second);
  }
  for(int i=0;i<v.size();i++){
    for(int j=0;j<n-v[i].second;j++)ans.push_back(v[i].second);
  }
  //for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
  for(int i=1;i<=n;i++){
    ans.insert(ans.begin()+v[i-1].first-1,v[i-1].second);
  }
  int cnt[n+1];
  fill(cnt,cnt+n+1,0);
  //for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
  for(int i=0;i<ans.size();i++){
    if(eve[i+1]==0){
      cnt[ans[i]]++;
    }
    else{
      int u=eve[i+1];
      if(cnt[u]!=u-1){
        cout<<"No"<<endl;
        return 0;
      }
      cnt[u]++;
    }
  }
  cout<<"Yes"<<endl;
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
  cout<<endl;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

bool is_kaibun(const string &str, i32 s, i32 e) {
    while (s <= e) {
        if (str[s] != str[e]) return false;
        s++, e--;
    }

    return true;
}

int main() {
    string s;
    cin >> s;
    i32 n = s.size();

    cout << (is_kaibun(s, 0, (n-3) / 2) && is_kaibun(s, 0, n-1) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long int sum = 0;
    int n, data, min, max;
    cin >> n;
    cin >> data;
    min = data;
    max = data;
    sum += data;
    for(int i = 1; i < n; i++){
        cin >> data;
        sum += data;
        if(max < data){
            max = data;
        }
        if(min > data){
            min = data;
        }
    }
    cout << min << " " << max << " " << sum << "\n";
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define double long double
#define N 10
using namespace std;
typedef pair<bool,double> P;

const double EPS = 1e-12;

double d, n, b, p[N], h[N];

P check(double s, double A, int cnt){
  
  double l = 0, r = 1000000000;
  
  while(l+EPS<r){
    
    double m = (l + r) / 2.0;
    double vx = m * cos(s);
    double vy = m * sin(s);
    double x = vx * 2 * vy;
    
    if(x<A) l=m;
    else r=m;

  }
  
  double vx = l * cos(s);
  double vy = l * sin(s);
  
  bool res = true;
  
  double x=0;
  
  for(int i=0;i<=cnt;i++){
    
    for(int j=0;j<n;j++)
      
      if(x-EPS<p[j]&&p[j]<x+A+EPS){
	
	if(abs(p[j]-x)<EPS||abs(p[j]-x)<EPS) res=false;
	
	double X=abs(p[j]-x);
	
	if(-X*X/(2*vx*vx)+X*vy/vx<=h[j]+EPS) res=false;
      }
    
    x+=A;
  }
  
  return P(res, l);
}

double sim(int cnt){
  
  double A=1.0*d/(cnt+1);
  
  double l = M_PI/4.0, r = M_PI/2.0;
  
  while(l+EPS<r){
    
    double m = (l + r) / 2.0;
    
    if(!check(m,A,cnt).first) l = m;
    else r=m;
  }
  
  return check(l,A,cnt).second;
}

int main(){
  
  cin>>d>>n>>b;

  for(int i=0;i<n;i++) cin>>p[i]>>h[i];
  
  double ans=(1e9);
  
  for(int i=0;i<=b;i++) ans=min(ans, sim(i));
  
  printf("%.8Lf\n", ans);
    
  return 0;
}

Measured memory_bytes: 3604
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, alice=0, bob=0;
    ll ans;
    cin >> N;
    vector <ll> a(N, 0);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end(),greater<ll>());
    for (ll j = 0; j < N; j += 2) {
        alice += a[j];
    }
    for (ll k = 1; k < N; k += 2) {
        bob += a[k];
    }
    ans = alice - bob;
    cout << ans << endl;


  

    return 0;
}


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

int main(void)
{
	int N, i, n, min;
	int P[200001];
	
	scanf("%d", &N);
	
	n=0; min=9999999;
	for(i=0; i<N; i++){
		scanf("%d", &P[i]);
		if(P[i]<=min){
			min = P[i];
			n++;
		}
	}
	
	printf("%d", n);
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

template <typename T>
T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	vector<int> dl(N, 0), dr(N, 0);
	dl[0] = A[0]; dr.back() = A.back();
	for (int i = 1; i < N; ++i) { dl[i] = gcd(dl[i - 1], A[i]); }
	for (int i = N - 2; i >= 0; --i) { dr[i] = gcd(dr[i + 1], A[i]); }

	int ans = max(dr[1], dl[N - 2]);
	for (int i = 1; i < N - 1; ++i) {
		ans = max(ans, gcd(dl[i - 1], dr[i + 1]));
	}
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 4496
N = int(input())
G = [[] for i in range(N)]
for nod in range(N):
    U = list(map(int, input().split()))[2:]
    G[nod] = zip(U[0::2], U[1::2])



import heapq


def dijkstra(x):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


distance = dijkstra(0)
#print(distance)
for i in range(N):
    print(i, distance[i])




Measured memory_bytes: 40352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class DCandyDistribution {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n, m;
    cin >> n >> m;
    vector<int64_t> A(n);
    for (auto &a: A) cin >> a;
    vector<int64_t> acc(n + 1);
    acc[0] = 0;
    partial_sum(A.begin(), A.end(), acc.begin() + 1);

    int64_t ans = 0;
    map<int64_t, int> C;

    for (const auto &a: acc)
        C[a % m]++;

    for (const auto& c: C)
        ans += c.second * (c.second - 1LL) / 2LL;

    cout << ans << endl;

}
};

int main() {
	DCandyDistribution solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5760
#include<stdio.h>
 
int main()
{
    int i,t,n,m=0,g,h,k,q,c[50]={},d[50]={};
     
    char s[200],p[200];
     
    scanf("%s %s",s,p);
     
    for(i=0;s[i]!='\0';i++)n=i+1;
    //printf("%d\n",n);
     
    for(t=0;t<i;t++){
         
        s[t+i]=s[t];
    }
    s[t+i]='\0';
    //printf("%s\n",s);     
    for(i=0;p[i]!='\0';i++);
     
    for(t=0;t<n;t++){
         
        //printf("%c %c %d\n",s[t],p[0],m);
        if(s[t]==p[0]){
            c[m]=t;
            m++;
        }
    }
    //printf("\n");
     
    for(g=0;g<m;g++){
        h=0;
        q=c[g];
        d[g]=1;
        for(k=0;k<i;k++){
             
            if(s[q+k]!=p[k]){
                h=h+1;
            }
            //printf("%c %c %d\n",s[q+k],p[k],h);
            if(d[g]!=0||h!=0){
                 
                d[g]=h;
            }
        }
        //printf("\n");
         
    }
    i=0;
    for(g=0;g<m;g++){
         
        //printf("%d\n",d[g]);
        if(d[g]==0){
             
            printf("Yes\n");
            i=1;
            break;
        }
    }
    if(i!=1){
        printf("No\n");
    }
     
    return 0;
}


Measured memory_bytes: 2112
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[0], A[1] = B[0], B[0]

for i in range(1, N - 1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i + 1] = B[i]

print(sum(A))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn = 210;
int n;
int f[maxn][maxn];
char a[maxn][maxn];
void solve() {
	scanf("%d", &n);
	memset(f, 0x3f, sizeof f);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", a[i] + 1);
		f[i][i] = 0;
		for (int j = 1; j <= n; ++j) {
			//scanf("%d",&a[i][j]);
			if (a[i][j] == '1')f[i][j] = 1; //a[i][j]-'0';
		}
	}
	/*puts("");
	for (int i = 1; i <= n; ++i, puts(""))
		for (int j = 1; j <= n; ++j)
			printf("%d", f[i][j] == f[0][0] ? 0 : f[i][j]);*/
	for (int k = 1; k <= n; ++k) {
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				if (f[i][j] >= f[i][k] + f[k][j]) {
					f[i][j] = f[i][k] + f[k][j];
				}
			}
		}
	}
	int mx = 0, ix, iy;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			if (mx < f[i][j]) {
				mx = f[i][j];
				ix = i;
				iy = j;
			}
		}
	if (mx == f[0][0]) {
		printf("-1\n");
		return;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (f[ix][i] == f[ix][j]) {
				if (a[i][j] == '1') {
					puts("-1");
					return;
				}
			}
		}
	}
	printf("%d\n", mx + 1);
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 512
from collections import defaultdict
dic = defaultdict(int)

N = int(input())
arr = list(map(int, input().split()))

j_arr =[]

ans = 0
for i in range(N):
    dic[i+arr[i]] += 1
    j_arr.append(-1*arr[i]+i)
    ans += dic[-1*arr[i]+i]

print(ans)

Measured memory_bytes: 152484
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, X, T = MI()
    if N%X == 0:
        ans = T*(N//X)
    else:
        ans = T*(N//X+1)

    
    print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
ll ans=0;
ll dp[0][0];

int main()
{
ll n;
cin >> n;
ll bi[20]={};
ll max,sum,coun=0;
rep(i,20){
    if(((n>>i)&1LL)==1){
        bi[i]++;
        max=i;
        coun++;
    }
}
cout << max+1<<' '<< max*2+coun-1<< endl;
rep(i,max){
    cout << i+1<<' '<<i+2 <<' '<<'0'<< endl;
    cout << i+1<<' '<<i+2 << ' '<< (1<<i)<<endl;
}
sum=(1LL<<max);
rep(i,max){
    if(bi[i]==1){
        cout << i+1<<' '<<max+1 <<' '<<sum<< endl;
        sum+=(1LL<<(i));
    }
}
return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, pair<ll, ll> > pll;

set<ll> ms;
ll N, Q;
ll d[200005];
ll s[200005];
ll t[200005];
ll x[200005];
vector<ll> insert[200005];
vector<ll> del[200005];

int main()
{
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> s[i] >> t[i] >> x[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> d[i];
    }

    for (int i = 0; i < N; i++) {
        int l = lower_bound(d, d + Q, s[i] - x[i]) - d;
        int r = lower_bound(d, d + Q, t[i] - x[i]) - d;

        if (l != r) {
            insert[l].push_back(x[i]);
            del[r].push_back(x[i]);
        }
    }

    for (int i = 0; i < Q; i++) {
        for (int j = 0; j < del[i].size(); j++) {
            ms.erase(del[i][j]);
        }
        for (int j = 0; j < insert[i].size(); j++) {
            ms.insert(insert[i][j]);
        }
        
        if (!ms.empty()) {
            cout << *(ms.begin()) << endl;
        }
        else {
            cout << -1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 34152
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
 
vector<int> sz, p;

void init(int n){
      p.resize(n);
      sz.resize(n);
      for(int i=0; i < n; i++){
            p[i] = i;
            sz[i] = 1;
      }
      return;
}

int find(int u){
      if(p[u] == u){
            return u;
      }
      return p[u] = find(p[u]);
}

void unite(int u, int v){
      int pu = find(u); int pv = find(v);
      if(pu == pv) return;
      if(sz[pv] > sz[pu]) swap(pv, pu);
      sz[pu] += sz[pv];
      p[pv] = pu;
      return;
}

int same(int u, int v){
      return find(u) == find(v);
}

int find_size(int u){
      return sz[find(u)];
}

int run_test(){
      int n, m, k;
      cin >> n >> m >> k;
      int deg[n];
      fill(deg, 0);
      init(n);
      for(int i=0;i <m; i++){
            int a, b;
            cin >> a >> b;
            a--; b--;
            unite(a, b);
            deg[a]++; deg[b]++;
      }
      vector<int> v[n];
      for(int i=0; i<k; i++){
            int a, b;
            cin >> a >> b;
            a--; b--;
            v[a].pb(b);
            v[b].pb(a);
      }
      for(int i=0; i < n; i++){
             int t = find_size(i) - deg[i] - 1;
             for(auto x: v[i]){
                  if(same(x, i)) t--;
             }
             cout <<t << " ";
      }
      return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 9500
#include <iostream>

int main() {
  const int rankNum = 14;
  const int suitNum = 4;
  int n;
  std::cin >> n;

  bool isRank[suitNum][rankNum] = {};

  char suitbuf;
  int rankbuf;
  for(int i = 0; i <= n; ++i) {
    std::cin.ignore();
    std::cin >> suitbuf >> rankbuf;
    switch (suitbuf) {
      case 'S':
        isRank[0][rankbuf] = true;
        break;
      case 'H':
        isRank[1][rankbuf] = true;
        break;
      case 'C':
        isRank[2][rankbuf] = true;
        break;
      case 'D':
        isRank[3][rankbuf] = true;
        break;
    }
  }


  for(int i = 0; i < suitNum; ++i) {
    for(int j = 1; j < rankNum; ++j) {
      if(!isRank[i][j]) {
        switch (i) {
          case 0:
            std::cout << "S " << j << std::endl;
            break;
          case 1:
            std::cout << "H " << j << std::endl;
            break;
          case 2:
            std::cout << "C " << j << std::endl;
            break;
          case 3:
            std::cout << "D " << j << std::endl;
            break;
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3068
h, w, K = map(int, input().split())
lc = []
for _ in range(h):
    lc += list(input().split())

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        cnt = 0
        for k in range(h):
            for l in range(w):
                if i >> k & 1:
                    continue
                if j >> l & 1:
                    continue
                if lc[k][l] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)

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

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    if(n == 3){
        cout << "2 5 63" << endl;
    }else if(n == 4){
        cout << "2 5 20 63" << endl;
    }else if(n == 5){
        cout << "2 5 20 30 63" << endl;
    }else{
        int t = 0;
        vector<int> ans(n), a = {2, 3, 4, 6};
        for(int i = 0; i < n; i++){
            ans[i] = 6 * (int)(i / 4) + a[i % 4];
            t += ans[i];
            t %= 6;
        }
        if(t == 2){
            ans[4] = 6 * (int)(1 + n / 4);
        }else if(t == 3){
            ans[5] = 6 * (int)(1 + n / 4);
        }else if(t == 5){
            ans[5] = 6 * (int)(n / 4) + 4;
        }
        cout << ans[0];
        for(int i = 1; i < n; i++){
            cout << " " << ans[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long N = l[0], M = l[1];
            var ans = 0L;

            if (N == 1 && M == 1)
                ans = 1;
            else if (N == 1 && M > 1)
                ans = M - 2;
            else if (N > 1 && M == 1)
                ans = N - 2;
            else if (N >= 3 && M >= 3)
                ans = (M - 2) * (N - 2);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			TreeMap<String, ArrayList<Integer>>TM=new TreeMap<String, ArrayList<Integer>>();
			for(int i=0;i<n;i++)
			{
				String st=in.next();
				int m=in.nextInt();
				ArrayList<Integer>AL=new ArrayList<Integer>();
				for(int j=0;j<m;j++)
					AL.add(in.nextInt());
				TM.put(st,AL);
			}
			int ans=Integer.MAX_VALUE;
			String name="";
			Iterator it = TM.keySet().iterator();
			String key[]=new String[TM.size()];
			for(int i=0;it.hasNext();i++)
				key[i]=(String)it.next();
			for(int i=0;i<key.length;i++)
			{
				ArrayList<Integer> AL2=TM.get(key[i]);
				int ref[]=new int[31];
				int cnt=0;
				for(int j=0;j<key.length;j++)
				{
					if(i==j)
						continue;
					ArrayList<Integer>AL3=TM.get(key[j]);
					for(int k=0;k<AL3.size();k++)
						ref[AL3.get(k)]++;	
				}
				for(int j=0;j<31;j++)
				{
					for(int k=0;k<AL2.size();k++)
					{
						if(AL2.get(k)==j)
							cnt+=n-ref[j];
					}
				}
				if(ans>cnt)
				{
					ans=cnt;
					name=key[i];
				}
			}
			System.out.println(ans+" "+name);
		}
	}

	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 32220
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::Chars;

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       N: usize,
       mut a:[usize;N-1],
    }

    let mut b = vec![0; N];
    for &item in &a {
        b[item - 1] += 1;
    }
    for &c in &b {
        echo!(c);
    }
}


Measured memory_bytes: 5512
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int i = N % 10;
      switch(i){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
          System.out.println("hon");
          break;
        case 0:
        case 1:
        case 6:
        case 8:
          System.out.println("pon");
          break;
        case 3:
          System.out.println("bon");
          break;
      }
  }
}

Measured memory_bytes: 35628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String[] array = br.readLine().split(" ");
			int N = Integer.parseInt(array[0]);
			int K = Integer.parseInt(array[1]);

			int[] A = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

			Map<Integer, Integer> map = new HashMap<>();

			for (Integer a : A) {
				if (map.containsKey(a)) {
					map.put(a, map.get(a) + 1);
				} else {
					map.put(a, 1);
				}
			}

			int count = map.entrySet().stream().sorted(Entry.comparingByValue()).limit(Math.max(map.size() - K, 0))
					.mapToInt(s -> s.getValue()).sum();

			System.out.println(count);
		}
	}
}


Measured memory_bytes: 51996
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
 
int main(){
    long long n,k;cin>>n>>k;
    long long t;
    map<long long, long long> teleporters;
    for (long long i=0;i<n;i++){
        cin >> t;
        teleporters[i+1] = t;
    }
    long long present_location = 1;
    bool cycle = false;
    long long cycle_length = 0;
    vector<long long> past_positions(n+1);
    set<long long> appeared_factors;
    for (long long i=0;i<k;i++){
        present_location = teleporters[present_location];
        if (appeared_factors.find(present_location) != appeared_factors.end()){
            cycle = true;
            cycle_length = i - distance(past_positions.begin(), find(past_positions.begin(), past_positions.end(), present_location)) + 1;
            break;
        } else {
            past_positions[i+1] = present_location;
            appeared_factors.insert(present_location);
        }
    }
    if (cycle){
        long long cycle_start_point = distance(past_positions.begin(), find(past_positions.begin(), past_positions.end(), present_location));
        long long remain = k - cycle_start_point;
        cout << past_positions[cycle_start_point + (remain % cycle_length)] << endl;
 
    } else {
        cout << present_location << endl;
    }
    return 0;
}

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

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
  ll r;
  cin >> r;
  
  cout << r*r << endl;
  
  return 0;
}


Measured memory_bytes: 3608
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scan(&a, &b, &c, &x)

	count := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				total := 500*i + 100*j + 50*k
				if total == x {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func fill(a []int, initValue int) {
	for i := 0; i < len(a); i++ {
		a[i] = initValue
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	alOdd := make([][]int, n)
	alEvn := make([][]int, n)
	var u, v, w int
	for i := 0; i < n-1; i++ {
		u, v, w = ri()-1, ri()-1, ri()
		if w%2 == 1 {
			alOdd[u] = append(alOdd[u], v)
			alOdd[v] = append(alOdd[v], u)
		} else {
			alEvn[u] = append(alEvn[u], v)
			alEvn[v] = append(alEvn[v], u)
		}
	}
	ans := make([]int, n)
	fill(ans, -1)
	isVisited := make([]bool, n)
	var c int
	q := make([]int, 0, n)
	q = append(q, 0)
	ans[0] = 0
	for len(q) != 0 {
		c, q = q[0], q[1:]
		isVisited[c] = true
		for _, v := range alOdd[c] {
			if !isVisited[v] && ans[v] == -1 {
				ans[v] = (ans[c] + 1) % 2
				q = append(q, v)
			}
		}
		for _, v := range alEvn[c] {
			if !isVisited[v] && ans[v] == -1 {
				ans[v] = ans[c]
				q = append(q, v)
			}
		}
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}


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

int main()
{
int A,B;
  cin>>A>>B;
  if(A<=5)
  {
  cout<<0<<endl;
  }
  else if(A>=6&&A<=12)
  {
  cout<<B/2<<endl;
  }
  else if(A>=13)
  {
  cout<<B<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m, i, s, max, min;
		while(true) {
			s = 0;
			m = 0;
			n = sc.nextInt();
			min = sc.nextInt();
			max = sc.nextInt();
			if(n == 0 && min == 0 && max ==0) break;
			int a[] = new int[n];
			for(i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			for(i = min - 1; i < max; i++) {
				if(s <= a[i] - a[i + 1] || s < a[i + 1] - a[i]) {
					s = a[i] - a[i + 1];
					m = i + 1;
				}
			}
			System.out.println(m);
		}
		sc.close();
	}
}


Measured memory_bytes: 56440
#include <iostream>
#include <vector>
#include <string>

int main()
{
  std::string S;
  std::cin >> S;

  std::string judge = "No";

  for (auto c : S) {
    if (c == '7') judge = "Yes";
  }

  std::cout << judge << std::endl;
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 40
#define INF 1 << 31
#define MOD 1000000007
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vector<int>> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
struct edge {
    int to, cost;
};

ll dp[301][301][301]; // そこまでのコスト

int main() {
    rep(i, 301) rep(j, 301) rep(k, 301) dp[i][j][k] = INF_LL;
    dp[0][0][0] = 0;
    int n, a;
    cin >> n >> a;
    vi h(n + 1, 0);
    rep(i, n) cin >> h[i + 1];
    rep(i, n) rep(j, i + 2) rep(k, i + 1) {
        if(dp[i][j][k] == INF_LL) {
            continue;
        }
        chmin(dp[i + 1][j + 1][k], dp[i][j][k]);
        chmin(dp[i + 1][j][i + 1], dp[i][j][k] + max(0, h[i + 1] - h[k]));
    }
    // rep(i, n + 1) {
    //     rep(j, i + 1) {
    //         rep(k, i + 1) cout << (dp[i][j][k] == INF_LL ? -1 : dp[i][j][k])
    //                            << " ";
    //         cout << endl;
    //     }
    //     cout << endl;
    // }
    ll ans = INF_LL;
    rep(j, n + 1) chmin(ans, dp[n][a][j]);
    cout << ans << endl;
}


Measured memory_bytes: 213376
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    string s,t="";
    cin>>s;
    ll ss = s.size();
    rep(i,ss){
        if(s[i]=='A'||s[i]=='C') t += s[i];
        else if((i!=ss-1)&&(s[i]=='B'&&s[i+1]=='C')){
            t += 'D';
            i++;
        }else t += 'B';
    }
    ll ts = t.size();
    ll ct=0,ca=0,cd=0,ans=0;
    rep(i,ts){
        if((t[i]=='A')&&(ct==0)){
            ct=1,ca=1;
        }else if(ct>0){
            if(t[i]=='A'){
                ct++,ca++;
            }else if(t[i]=='D'){
                ans += (ct-cd);
                ct++,cd++;
            }else{
                ct=0,ca=0,cd=0;
            }
        }
    }
    cout<<ans<<endl;
}


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

int n, q;

class DisjointSet {
public:
    DisjointSet(int size) {
        rank_.resize(size, 0);
        p_.resize(size, 0);
        for (int i = 0; i < size; i++) {
            p_[i] = i;
            rank_[i] = 0;
        }
    }

    inline bool same(int x, int y) {
        return findSet(x) == findSet(y);
    };

    inline void link(int x, int y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else{
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    inline void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    inline int findSet(int x) {
        if (x != p_[x]) {
            p_[x] = findSet(p_[x]);
        }
        return p_[x];
    }

    std::vector<int> rank_, p_;
};
int c, x, y;
int main() {
    std::cin >> n >> q;
    DisjointSet DS(n);
    for (int i = 0; i < q; i++) {
        std::cin >> c >> x >> y;
        if (c) {
            if (DS.same(x, y)) {
                std::cout << 1 << std::endl;
            }else{
                std::cout << 0 << std::endl;
            }
        }
        else {
            DS.unite(x, y);
        }
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++)
#define ll long long

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

int main() {
    int n, X;
    cin >> n >> X;
    vector<int> x(n);
    rep(i, 0, n) cin >> x[i];
    //x.push_back(X);

    sort(x.begin(), x.end());
    
    vector<int> diff;
    rep(i, 0, n) {
        diff.push_back(abs(X-x[i]));
    }

    sort(diff.begin(), diff.end());
    //cout << diff[0] << " " << diff[1] << endl;
    if(diff.size() == 1) {
        cout << diff[0] << endl;
    }
    else {
        int ans = diff[0];
        rep(i, 1, n-1) {
            ans = gcd(ans, gcd(diff[i], diff[i+1]));
        }
        
        cout << ans << endl;
    }

    return 0;

}

Measured memory_bytes: 1276
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> L = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            L.add(sc.nextInt());
        }

        sc.close();
        return new TestCase(N, L);
    }

    public static String process(TestCase testCase) {
        List<Integer> L = testCase.L;

        int largest = 0;
        int sum = 0;

        for (int side : L) {
            largest = Math.max(largest, side);
            sum += side;
        }

        return (largest < (sum - largest)) ? YES : NO;
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final List<Integer> L;

        public TestCase(int N, List<Integer> L) {
            this.N = N;
            this.L = L;
        }
    }
}


Measured memory_bytes: 23508
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(a>b){
    printf("a > b\n",a,b);
  }else if(a<b){
    printf("a < b\n",a,b);
  }else if(a==b){
    printf("a == b\n",a,b);
  }
  return 0;
}



Measured memory_bytes: 2040
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<lint,lint> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint x[200100];
lint h[200100];
vector<pint> v,w;
int main()
{
	int n,a;lint d;cin>>n>>d>>a;
	rep(i,n){
		cin>>x[i]>>h[i];w.pb(mp(x[i],h[i]));
		//h[i]=(h[i]+a-1)/a;
	}
	sort(All(w));
	rep(i,n){
		x[i]=w[i].fi;h[i]=(w[i].se+a-1)/a;
	}
	lint out=0,ns=0;int it=0;
	rep(i,n){
		while(it<(int)v.size() && v[it].fi<x[i]){
			ns-=v[it].se;it++;
		}
		//cout<<i<<' '<<it<<' '<<ns<<endl;
		lint lest=max(0LL,h[i]-ns);
		out+=lest;ns+=lest;v.pb(mp(x[i]+d+d,lest));
	}
	cout<<out<<endl;
}


Measured memory_bytes: 15468
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, k;
    cin >> n >> k;

    lli mod_n = 1000000007;
    lli min = 0, max = 0, sum = 0;
    for(int i = k; i<=n+1; i++){
        min = (i-1)*(i/2.0);
        max = (n + n-i+1)*(i/2.0);
        sum += (max - min + 1);
        sum %= mod_n;
        max = min = 0;
    }
    cout << sum << endl;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.size() - 1; i++)
    {
        if(s[i] == 'A')
        {
            if(s[i + 1] == 'C')
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int X;
    cin >> X;
    cout << (X >= 30 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<ll>
#define pi pair<ll,ll>
#define vp vector<pi>
#define mp map<ll,ll>
#define pb push_back
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll T;cin>>T;while(T--) 
#define MAX 100004
#define __sort(v) sort(v.begin(),v.end())
#define rep(i,a,b) for(ll i=a;i<b;i++)
const ll inf=1e+9;
const ll mod=7 + 1e+9;
 
 
 
int32_t main(){
 
     fast;
     
     ll k;
     cin>>k;
     ll ans = 0;
     rep(i,1,k+1)
     {
		 rep(j,1,k+1)
		 {
			 rep(o,1,k+1)
			   { ans = ans + __gcd(i,__gcd(j,o));}
	      }
	   }
	   
     cout<<ans;
     
     return 0;
 }


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    ll S, x, y;
    cin >> S;

    const ll v = 1000000000;
    x = (v - (S % v)) % v;
    y = (S + x) / v;

    cout << "0 0 1000000000 1 " << x << " " << y << endl;
    return 0;
}

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

int main() {
  int N, a, b, c, d;
  cin >> N;
  
  a = N/1000;
  b = N/100 - 10*a;
  c = N/10 - 100*a - 10*b;
  d = N % 10;
    
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }
    else {
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

struct A {
    ll val;
    ll prev;
    ll next;
};

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

    ull N, K;
    cin >> N >> K;
    char s[N];
    for (ll i = 0; i < N; ++i) {
        cin >> s[i];
    }

    char hikaku = s[0];
    ull co = 1;
    vector<ll> vl;
    for (ll i = 1; i < N; ++i) {
        if (hikaku != s[i]) {
            vl.push_back(co);
            co = 1;
            hikaku = s[i];
        } else {
            co++;
        }
    }
    vl.push_back(co);

    ull ruiseki = 0;
    ull start = 0;
    ull count = 0;
    if (s[0] == '1') {
        ruiseki += vl[0];
        start = 1;
        count = 1;
    }
    for (ll i = 0; i < K; ++i) {
        if (count >= vl.size()) {
            cout << ruiseki << endl;
            return 0;
        }
        ruiseki += vl[count];
        count++;
        if (count >= vl.size()) {
            cout << ruiseki << endl;
            return 0;
        }
        ruiseki += vl[count];
        count++;
    }

    ull ans = ruiseki;

    for (ll i = start + 1; i < vl.size(); i += 2) {
        if (count >= vl.size()) {
            break;
        }
        if (i == 1) {
            ruiseki = ruiseki - vl[i-1];
        } else {
            ruiseki = ruiseki - vl[i-2] - vl[i-1];
        }
        ruiseki += vl[count];
        count++;
        if (count >= vl.size()) {
            ans = max(ans, ruiseki);
            break;
        }
        ruiseki += vl[count];
        count++;
        ans = max(ans, ruiseki);
    }

    cout << ans << endl;

}

Measured memory_bytes: 1528
import Data.Array
import Data.List

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  [k, n] <- readInts
  as <- listArray (1, n) . sort <$> readInts
  print $ solve k n as

solve :: Int -> Int -> Array Int Int -> Int
solve k n as = k - 
  (maximum [ (as ! (i + 1)) - (as ! i) | i <- [1..n-1] ]) `max` (as ! 1 - as ! n + k)

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

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

    int a[n], b[n], c[m], d[m];

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

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

    for (int i = 0; i < n; i++) {
        int num;
        int min_dist = 1e9;
        for (int j = 0; j < m; j++) {
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (min_dist > dist) {
                min_dist = dist;
                num = j+1;
            }
        }
        cout << num << endl;
    }

    return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  string T="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<S.size();i++){
    for(int j=0;j<T.size();j++){
      if(S.at(i)==T.at(j)){
        S.at(i)=T.at(j+N);
        break;
      }
    }
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int a, b, x;
  
  cin >> a >> b;
  x = (a + b) / 2;
  
  if((a+b) % 2 == 0)
  {
  	cout << x << endl;
  }else{
  	cout << x + 1 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
typedef long long ll;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
using namespace std;
using pii = pair<int, int>;

int main() {
	int h, w; cin >> h >> w;
	char s[21][21];
	REP(i, h) REP(j, w) cin >> s[i][j];
	int ans = 0;
	int d[21][21];
	REP(i, h) {
		REP(j, w) {
			if (s[i][j] == '#')continue;
			REP(k, 21) REP(l, 21) d[k][l] = INF;
			queue<pii>Q;
			Q.push({ i,j });//全探索開始！
			d[i][j] = 0;
			while (!Q.empty()) {
				int y = Q.front().first;
				int x = Q.front().second;
				Q.pop();
				for (int k = 0; k < 4; ++k) {
					int ny = y + dy[k];//const int dy[4] = { -1, 0, 0, 1 };
					int nx = x + dx[k];//const int dx[4] = { 0, -1, 1, 0 };
					if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] == '.' && d[ny][nx] == INF) {
						Q.push({ ny,nx });
						d[ny][nx] = d[y][x] + 1;
					}
				}
			}
			REP(k, h) {
				REP(l, w) {
					if (d[k][l] == INF)continue;
					if (s[k][l] == '#')continue;
					ans = max(ans, d[k][l]);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
list($H, $W) = ints();
$wf = new Wf(10);
for($i = 0; $i <= 9; $i++){
  $nums = ints();
  for($j = 0; $j <= 9; $j++){
    $wf->connect($i+1, $j+1, $nums[$j]);
  }
}
$wf->solve();
$sum = 0;
for($i = 0; $i < $H; $i++){
  $nums = ints();
  foreach($nums as $num){
    if($num == -1){
      
    }else{
      $sum+=$wf->d[$num+1][2];
    }
  }
}
echo $sum;
/**
 * Warshall–Floyd
 * Attention: 1-origin
 **/
class Wf{
  public $d;
  public $n;
  function __construct($n)	{
    $this->n = $n;
    for($i = 1; $i <= $this->n; $i++){
      for($j = 1; $j <= $this->n; $j++){
        $this->d[$i][$j] = 10**18;
      }  
    }
  }
  function connect($a, $b, $c){
    $this->d[$a][$b] = $c;
  }
  function solve(){
    for($k = 1; $k <= $this->n; $k++){
      for($i = 1; $i <= $this->n; $i++){
        for($j = 1; $j <= $this->n; $j++){
          if($this->d[$i][$j] > $this->d[$i][$k] + $this->d[$k][$j]){
            $this->d[$i][$j] = $this->d[$i][$k] + $this->d[$k][$j];
          }
        }
      }
    }
    return $this->d;
  }
}
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}

Measured memory_bytes: 4728
#include<stdio.h>
#include<stdlib.h>


typedef struct{
  char type;
  int num;
}card;

int isStable(card *,card *);
void copy(card *,card *);
int  BubbleSort(card *);
int  selectionSort(card *);
void print_dataset(card *);

int n;

int main(){
  int i;
  card *c,*b,*s;
  

  scanf("%d",&n);
  c = (card *)malloc(n*sizeof(card));
  b = (card *)malloc(n*sizeof(card));
  s = (card *)malloc(n*sizeof(card));
  for(i=0;i<n;i++) scanf(" %c%d",&c[i].type,&c[i].num);

   copy(b,c);
  copy(s,c);

  BubbleSort(b);
  selectionSort(s);

  print_dataset(b);
  printf("Stable\n");
  print_dataset(s);
  if(isStable(s,b)!=1) printf("Not stable\n");
  else printf("Stable\n");
  
  free(c);
  free(s);
  free(b);
  
  return 0;
}



int BubbleSort(card *a){
  int i,j,stock,s3,count=0;

  for(i=0;i<n;i++){
    for(j=n-1;j>0;j--){
      if(a[j].num<a[j-1].num){
	stock=a[j].num;
	a[j].num=a[j-1].num;
	a[j-1].num=stock;

	s3=a[j].type;
	a[j].type=a[j-1].type;
	a[j-1].type=s3;
	
	count++;
      }
    }
  }

  return count;
}

int selectionSort(card *a){
  int i,j,mini,stock,s3,count=0;
  int flag=1;
  
  for(i=0;i<n;i++){
    mini=i;
    flag=1;
    for(j=i;j<n;j++){
      if(a[j].num<a[mini].num){
        mini=j;
        flag=0;
      }
    }
    
    if(flag==0){
    stock=a[i].num;
    a[i].num=a[mini].num;
    a[mini].num=stock;

    s3=a[mini].type;
    a[mini].type=a[i].type;
    a[i].type=s3;
	
    
    count++;
    }
 
  }

  return count;
}

void print_dataset(card *a){
  int i;

  for(i=0;i<n;i++){
    printf("%c%d",a[i].type,a[i].num);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
}

int isStable(card *sta,card *not){
  int i;
  for(i=0;i<n;i++){
    if(sta[i].type != not[i].type) return -1;
  }

  return 1;
}

void copy(card *a,card *b){
  int i;
  for(i=0;i<n;i++){
    a[i].type=b[i].type;
    a[i].num=b[i].num;
  }
}



Measured memory_bytes: 2100
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var count = 0L;
        var firstB = 0;
        var lastA = 0;
        var ba = 0;
        for (int i=0;i<N;++i)
        {
            var str = Console.ReadLine();
            if (str[0] == 'B') firstB++;
            if (str[str.Length-1] == 'A') lastA++;
            if (str[0] == 'B' && str[str.Length - 1] == 'A') ba++;
            var beforeLetter = str[0];
            for (int j=1;j<str.Length;++j)
            {
                if (beforeLetter == 'A' && str[j] == 'B') count++;
                beforeLetter = str[j];
            }
        }
        if (ba == firstB && ba == lastA) firstB--;
        count += Math.Max(0,Math.Min(firstB,lastA));
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 11220
n = int(input())
x = list(map(int, input().split()))

x_diff = []
for i in range(n-1):
    x_diff.append(x[i+1] - x[i])



def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

base = 1
for i in range(1, n):
    base *= i
    base %= 10**9+7

frac = []
for i in range(1, n):
    frac.append(base*modinv(i) % (10**9+7))

import itertools
frac = list(itertools.accumulate(frac))

ans = 0
for i in range(n-1):
    ans += frac[i]*x_diff[i]
    ans %= 10**9+7

print(ans)


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

int main() {
  int N;
  cin >> N;
  int A[N];
  int k = 1;
  int count = 0;

  while (count < N) {
    bool flag = 1;
    int tmp = 5*k + 2;
    for (int j = 2; j*j <= tmp; j++) {
      if (tmp % j == 0) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      A[count] = tmp;
      count++;
    }
    k += 2;
  }

  rep(i, N) cout << A[i] << " " ;
  return 0;
}

Measured memory_bytes: 256