akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

class Main{

	public static void main(String[] args) {
		FastReader f = new FastReader();
		int h = ii(f), w = ii(f);
		String[] str = new String[h];
		long[][] dp = new long[h][w];
		boolean f1, f2;
		for(int i=0; i<h; i++)
			str[i] = f.nextLine();
		dp[0][0] = 1;
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				if(i == 0 && j == 0)
					continue;;
				f1 = j == 0 || str[i].charAt(j-1) == '#';
				f2 = i == 0 || str[i-1].charAt(j) == '#';
				if(!f1 && !f2)
					dp[i][j] = (dp[i-1][j] % MOD) + (dp[i][j-1] % MOD) % MOD;
				else if(f1 && f2)
					dp[i][j] = 0;
				else if(f1)
					dp[i][j] = dp[i-1][j];
				else
					dp[i][j] = dp[i][j-1];
			}
		}
		System.out.println(dp[h-1][w-1] % MOD);

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static int ii(FastReader fr) {
		return fr.nextInt();
	}

	static long il(FastReader fr) {
		return fr.nextLong();
	}

	static double id(FastReader fr) {
		return fr.nextDouble();
	}

	static void printArray(Object[] arr) {
		for (Object x : arr)
			print(x, " ");
		printn("");
	}

	static void print(Object s, String sep) {
		System.out.print(s + sep);
	}

	static void printn(Object s) {
		System.out.println(s);
	}

	static long[] inputArrL(int n, FastReader fr) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = fr.nextLong();
		return arr;
	}

	static int[] inputArr(int n, FastReader fr) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = fr.nextInt();
		return arr;
	}

	static int max(int... args) {
		int max = Integer.MIN_VALUE;
		for (int x : args) {
			max = Math.max(x, max);
		}
		return max;
	}

	static int min(int... args) {
		int min = Integer.MAX_VALUE;
		for (int x : args) {
			min = Math.min(x, min);
		}
		return min;
	}

	static long max(long... args) {
		long max = Integer.MIN_VALUE;
		for (long x : args) {
			max = Math.max(x, max);
		}
		return max;
	}

	static long min(long... args) {
		long min = Integer.MAX_VALUE;
		for (long x : args) {
			min = Math.min(x, min);
		}
		return min;
	}

	static int lenDigit(int d) {
		if (d == 0)
			return 1;
		int l = 0;
		while (d != 0) {
			l++;
			d /= 10;
		}
		return l;
	}

	static int MOD = 1000000007;

}



Measured memory_bytes: 33080
'use strict';

const chunks = [];
process.stdin.on("data", chunk => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const body = Buffer.concat(chunks).toString("utf8");
  main(body.trim());
});

function main(data) {
  for (let i = 0; i < data.length; i++) {
    const c = data.charAt(i);
    if (i % 2 == 0) {
      // Odd
      if (c === "L") {
        console.log("No");
        return;
      }
    } else {
      // Even
      if (c === "R") {
        console.log("No");
        return;
      }
    }
  }
  console.log("Yes");
}


Measured memory_bytes: 21192
#!/usr/bin/env python3
import sys


def solve(N: int, D: int):
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N,D = [ int(s) for s in input().split() ]
    if N % (2*D+1) == 0:
        print(int(N / (2*D+1)))
    else:
        print(int(N / (2*D+1))+ 1)

    

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]

import itertools

ans=-float("inf")

for v in itertools.product([0,1], repeat=10):
  if sum(v)==0: 
    continue #例外排除
  a=0
  for i in range(n):
    temp=0
    for j in range(10):
      if f[i][j]==v[j]==1:
        temp+=1
    a+=p[i][temp]
  ans=max(ans,a)
print(ans)

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

typedef pair<int, int> ii;

#define x first
#define y second

const int N = 100005;
vector<int> parent;
vector<int> sizeNode;
vector<int> height;
vector<int> row;

void make_set(int v, int heightColumn){
    parent[v] = v;
    height[v] = heightColumn;
    sizeNode[v] = 1;
}

int find_set(int v){
    if(v == parent[v]){
        return v;
    }
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if(a != b){
        if(sizeNode[a] < sizeNode[b]){
            swap(a, b);
        }
        parent[b] = a;
        sizeNode[a] += sizeNode[b];
        height[a] += height[b];
    }
}

/*input

*/

int main(){
    int n;
    cin >> n;
    vector<ii> point(n, ii(0,0));
    row.assign(N + 1, -1);
    parent.assign(N + 1, -1);
    sizeNode.assign(N + 1, -1);
    height.assign(N + 1, -1);
    for(int i = 0; i < n;i ++){
        cin >> point[i].x >> point[i].y;
    }
    sort(point.begin(), point.end());
    for(int i = 0; i < n;){
        int x = point[i].x;
        vector<ii> col;
        int dup = 0;
        while(i < n && point[i].x == x){
            if(row[point[i].y] != -1) dup ++;
            col.push_back(point[i]);
            i++;
        }
        make_set(x, col.size() - dup);
        for(int j = 0; j < col.size(); j ++){
            int y = col[j].y;
            if(row[y] == -1)
                row[y] = x;
            else{
                union_sets(x, row[y]);
            }
        }
    }
    long long ans = 0;
    vector<int> check(N + 1, 0);
    for(int i = 0; i < N;i ++){
        if(parent[i] != -1){
            int p = find_set(i);
            if(check[p] == 0){
                ans += (1LL * sizeNode[p] * height[p]);
                check[p] = 1;
            }
        }
    }
    cout << ans - n;
}


Measured memory_bytes: 5900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    if (b % a == 0) {
        cout << a + b << "\n";
    } else {
        cout << b - a << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int n, col[205], tot, head[205];
int dp[205][205];
char s[205][205];

struct node
{
	int v, next;
}a[205 * 205];

bool dfs(int x, int p){
	col[x] = p;
	for (int i = head[x]; i != -1; i = a[i].next){
		int v = a[i].v;
		if(col[v] == p) return true;
		if(!col[v] && dfs(v, p ^ 1)) return true;
	}
	return false;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) head[i] = -1;
	for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = 0x3f3f3f3f;
	for (int i = 1; i <= n; i++){
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= n; j++){
			if(s[i][j] == '1') a[tot] = node{j, head[i]}, head[i] = tot++, dp[i][j] = 1;
		}
	}
	for (int i = 1; i <= n; i++) dp[i][i] = 0;
	if(dfs(1, 2)) {printf("-1\n"); return 0;}
	for (int k = 1; k <= n; k++){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ans = max(ans, dp[i][j]);
	printf("%d\n", ans + 1);

	return 0;
}
/**/

Measured memory_bytes: 768
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力                                                                                                  
        int N = sc.nextInt();
	if(N%10 == 9 || N/10 == 9) System.out.println("Yes");
	else System.out.println("No");

    }
}



Measured memory_bytes: 21844
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  xs <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    m :: Int
    m = round $ toRational (sum xs) / toRational n
  print . sum . map (^ 2) . map (subtract m) $ xs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
N = int(input())
X = list(map(int,input().split(' ')))
Y = []
for i,j in enumerate(X):
  Y.append((i,j))
Z = sorted(Y,key=lambda x:x[1])
First_half = Z[int(N/2-1)][1]
Last_half = Z[int(N/2)][1]

for i,j in enumerate(X):
  if j <= First_half:
    print(Last_half)
  else:
    print(First_half)

  

Measured memory_bytes: 39568
import math
K,A,B=map(int,input().split())
if A>=K:
    print(1)
else:
    if A<=B:
        print(-1)
    else:
        if (K-A)%(A-B)==0:
            print((K-A)//(A-B)*2+1)
        else:
            print((K-A)//(A-B)*2+3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    ll X;
    cin >> X;

	bool b=(30<=X);
    cout << (b ? "Yes" : "No") << endl; 
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

struct edge { int to; long long cost; };
const int MAX_V = 100010;

vector<edge> tree[MAX_V];
long long depth[MAX_V];

// v: 今いる頂点, p: v の親
void dfs(int v, int p, long long d) {
	depth[v] = d;
	for (int i = 0; i < tree[v].size(); i++) {
		edge e = tree[v][i];
		if (e.to == p) { continue; }
		dfs(e.to, v, d + e.cost);
	}
}

int main()
{
	int n;
	cin >> n;
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		tree[a].push_back({ b, c });
		tree[b].push_back({ a, c });
	}
	int q, k;
	cin >> q >> k;
	k--;
	dfs(k, -1, 0);
	rep(i, q) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << depth[x] + depth[y] << endl;
	}
	return 0;
}

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

vector<int> g[2020];
int dist[2020];

void dfs(int curr, int prev) {
	for (int next : g[curr]) if (next != prev) {
		dist[next] = dist[curr] + 1;
		dfs(next, curr);
	}
}

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

	vector<int> u(n - 1), v(n - 1);
	for (int i = 0; i < n - 1; i++) {
		scanf("%d %d", &u[i], &v[i]);
		u[i]--;
		v[i]--;
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}

	int ans = INT_MAX;
	for (int i = 0; i < n - (K % 2); i++) {
		if (K % 2 == 0) {
			dist[i] = 0;
			dfs(i, -1);
		} else {
			dist[u[i]] = 0;
			dist[v[i]] = 0;
			dfs(u[i], v[i]);
			dfs(v[i], u[i]);
		}

		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (dist[i] * 2 > K) {
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

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

int main(){
  string S;
  cin >> S;
  if(S.at(2)==S.at(3)){
    if(S.at(4)==S.at(5)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
S= list(input())


index_num_R = [n for n, v in enumerate(S) if v == "R"]
index_num_L = [n for n, v in enumerate(S) if v == "L"]


count_R = 0
count_L = 0

for num_R in index_num_R:
  if num_R %2==1:
    count_R = count_R +1

  
for num_L in index_num_L:
  if num_L %2==0:
    count_L = count_L +1


if count_R==0 and count_L==0:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
import sys


class Node():

	def __init__(self,id,key):
		
		self.id = id
		self.key = key
		self.root = -1
		self.left = -1
		self.right = -1
		self.parent = -1
		self.sibling = -1
		self.degree = 0
		self.depth = 0
		self.height = 0

def print_nodes(Nodes,node_id,type,output):

	#TYPE
	#0 : Preorder
	#1 : Inorder
	#2 : Postorder

	if node_id == -1:
		return

	if type == 0:
		output.append(Nodes[node_id].key)

	print_nodes(Nodes,Nodes[node_id].left,type,output)
	if type == 1:
		output.append(Nodes[node_id].key)
	print_nodes(Nodes,Nodes[node_id].right,type,output)
	if type == 2:
		output.append(Nodes[node_id].key)

def insert(T,z):

	if len(T) == 1:
		return


	y = -1
	x = T[0]

	while True:
		y = x
		if z.key < x.key:
			if x.left == -1:
				break
			else:
				x = T[x.left]
		else:
			if x.right == -1:
				break
			else:
				x = T[x.right]

	z.parent = y.id
	if z.key < y.key:
		y.left = z.id
	else:
		y.right = z.id

def find(Nodes,Node,key):

	if Node.key == key:
		return True


	if Node.key > key:
		if Node.left == -1:
			return False
		else:
			return find(Nodes,Nodes[Node.left],key)
	if Node.key < key:
		if Node.right == -1:
			return False
		else:
			return find(Nodes,Nodes[Node.right],key)

	

def test():

	n = int(sys.stdin.readline())
	T = [Node(0,0)] * n
	root = 0
	id = 0

	for i in range(n):

		inputs = sys.stdin.readline().split()

		if inputs[0] == "insert":
			if id == 0:
				T[id] = Node(id,int(inputs[1]))
				id += 1
				continue

			key = int(inputs[1])
			tmp_node = Node(id,key)
			T[id] = tmp_node
			insert(T,tmp_node)
			id += 1

		if inputs[0] == "find":
			result = find(T,T[0],int(inputs[1]))
			if result == False:
				print("no")
			elif result == True:
				print("yes")

		if inputs[0] == "print":
			output = []
			#In-order
			print_nodes(T,T[0].id,1,output)
			for j in range(len(output)-1):
				print(f" {output[j]}",end = '')
			print(f" {output[j+1]}")

			#Pre-order
			output2 = []
			print_nodes(T,T[0].id,0,output2)
			for j in range(len(output2)-1):
				print(f" {output2[j]}",end = '')
			print(f" {output2[j+1]}")

if __name__ == "__main__":
	test()





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

int main() {
    int N;
    cin >> N;
    int A[N];
    int B[N];
    int C[N - 1];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N - 1; i++){
        cin >> C[i];
    }

    int prev = -10;
    int sum = 0;
    for(int i = 0; i < N; i++){
        int choice = A[i] - 1;
        sum += B[choice];
        if(choice - 1 == prev){
            sum += C[prev];
        }
        prev = choice;
    }
    cout << sum << endl;

}

Measured memory_bytes: 508
#include <stdio.h>
//printf("1\n");

int main(){
    int a,b,n;
 //   printf("1\n");
    scanf("%d %d %d",&n,&a,&b);
    
    if(a>b || (n==1&&a!=b)){
        printf("0");
        return 0;
    }
    if(a==b){
        printf("1");
        return 0;
    }else{
        printf("%lld",(long long)(b-a)*(n-2)+1);
    }
    
}

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

void eratosthenes(vector<int> &plist, int n) {
    vector<bool> is_prime(n + 1, 1);

    is_prime[0] = is_prime[1] = false;

    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            plist.push_back(i);
            for (int j = 2; i * j <= n; j++) {
                is_prime[i * j] = false;
            }
        }
    }
}

int main() {
    int x;
    cin >> x;
    vector<int> plist;
    eratosthenes(plist, 1000000);
    cout << *lower_bound(plist.begin(), plist.end(), x) << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define MAX 1000005
#define fs first
#define sc second
#define N 7
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;


ll a1[100005]={0};
ll a2[100005]={0};

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
 cin.tie(0);
vi v,v1;
ll n,num;
map<ll,ll> mymap;

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

map<ll,ll> :: iterator it=mymap.end();
it--;
int f=0;
for(it;;it--)
{
  //cout<<it->fs<<" "<<it->sc<<endl;
  if(it->sc==2 || it->sc==3)
  {
    v.pb(it->fs);
  }
  if(it->sc>=4)
    v1.pb(it->fs);
  if(it==mymap.begin())
    break;
}

ll area=0;
//cout<<v[0]<<endl;
if(v.size()>0 && v1.size()>0)
{
  area=v[0]*v1[0];
//   if(v.size()>=2)
//   area=max(v[0]*v[1],v1[0]*v[0]);
// if(v.size()==1)
//   area=max(area,v[0]*v1[0]);
}
 if(v.size()>=2)
  area=max(area,v[0]*v[1]);
 if(v1.size()>=1)
  area=max(v1[0]*v1[0],area);
cout<<area<<endl;

return 0;

}

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

#define ll long long

using namespace std;

int a[20000];

int main(){
    int max = 0;
    int k,t;
    cin >> k >> t;
    for(int i = 0;i < t;i++){
        cin >> a[i];
    }

    sort(a,a+t);

    int ans = a[t-1];
    for(int i = 0;i < t - 1;i++){
        ans -= a[i];
    }

    if(ans <= 0){
        cout << 0 << endl;
    }else if(ans == a[t-1]){
        cout << ans - 1 << endl;
    }
    else{
        cout << ans  - 1<< endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define ll long long
using namespace std;
 
const ll md = 1e9 + 7;
 
ll q(ll a, int b)
{
	ll ans = 1, x = a;
	while (b)
	{
		if (b & 1)
			ans = (ans * x) % md;
		x = (x * x) % md;
		b >>= 1;
	}
	
	return ans;
}
 
int main()
{
	int n;
	scanf("%d", &n);
	printf("%lld\n", ((q(10ll, n) + q(8ll, n)) % md - (q(9ll, n) << 1) % md + md) % md);
	
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,m;
  cin >> n >> m;
  vpll a(n), b(m);
  REP(i, n)
    cin >> a[i].FI >> a[i].SE;
  REP(i, m)
    cin >> b[i].FI >> b[i].SE;

  vll ans(n);
  REP(i, n){
    ll minV = INF;
    ll minP = -INF;
    REP(j, m){
      ll value = abs(a[i].FI-b[j].FI)+abs(a[i].SE-b[j].SE);
      if(minV > value){
        minV = value;
        minP = j;
      }
    }
    ans[i] = minP+1;
  }

  REP(i, n)
    cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll N, M;
vector<ll> vecA;

bool sat(ll m) {
  ll left = 2*m;
  ll right = 2*N - 1;
  while (left < right) {
    if (vecA.at(left) + vecA.at(right) < M)  return false;
    left ++;
    right --;
  }
  return true;
}

ll binsch(ll l, ll r) {
  while (l + 1 < r) {
    ll mid = (l + r) / 2;
    if (sat(mid))  r = mid;
    else           l = mid;
  }
  return r;
}

ll calc(ll left, ll right, ll shift, ll res) {
    while (left < right) {
      ll v = vecA.at(left) + vecA.at(right) - shift;
      DLOG("v %lld", v);
      if (res < v)  res = v;
      left++;
      right--;
    }
    return res;
}

int main() {
  cin >> N >> M;
  vecA.resize(2*N);
  for (ll i = 0; i < 2*N; i++)  cin >> vecA.at(i);
  sort(vecA.begin(), vecA.end());
  ll border = binsch(-1, N);
  DLOG("border %lld\n", border);
  ll ans = calc(0, 2*border-1, 0, 0);
  ans = calc(2*border, 2*N-1, M, ans);
  cout << ans << endl;
  
  return 0;
}



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

int main(){
    deque<string> str(3);
    int turn = 0;
    bool result= false;
    for(int i=0; i<3; i++){
        cin >> str.at(i);
    }
    while(1){
        if(result==true) break;
        for(int i=0; i<3; i++){
            if(turn==i){
                if(str[i].size()==0){
                    cout << char('A' + i) << "\n";
                    result=true;
                    break;
                }
                for(int j=0; j<3; j++){
                    if(str[i][0]=='a'+j){
                        turn=j;
                    }
                }
                str[i].erase(str[i].begin());
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()

print(s[0]+str(len(s)-2)+s[-1])


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

using namespace std;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	int sum=0;
	for(char x:s){
		sum+=(x-'0');
	}
	if(sum==1){
		sum*=10;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String result = "No";
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                if(i * j == N){
                    result = "Yes";
                    break;
                }
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21204
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::cin >> N;
	
	long result = 1;
	for (int i = 1; i <= N; ++i) {
		result = result * i % 1000000007L;
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.pop()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 85552
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  ll A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;

  ll res = 5000000000*2;     // MAX
  rep(i, max(X,Y)+1) {    // A: a, B: b, AB: i*2
    ll a = X-i, b = Y-i;
    if(a<0)a=0;
    if(b<0)b=0;
    res = min(res, A*a+B*b+C*(i*2));
  }
  cout << res << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
#include <sstream>
#include <istream>
#include <iterator>
#include <numeric>
#include <tuple>
#include <cassert>
#include <bitset>
using namespace std;

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

	int cnt = 0;
	for (int d = max(a, b); d > 0 ; d--)
	{
		if ((a % d == 0) && (b % d == 0))
			cnt++;

		if (cnt == k)
		{
			cout << d;
			return 0;
		}
	}
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

height = 10 ** 10
for i in range(N-1, -1, -1):
    if H[i] > height:
        if H[i] - 1 > height:
            print("No")
            exit()
        else:
            height = H[i] - 1
    else:
        height = H[i]

print("Yes")


Measured memory_bytes: 14224
i = int(input())
 
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
res = sum(b)
 
for j in range(i-1):
    if a[j] + 1 == a[j+1]:
      res += c[a[j] - 1]
print(res)

Measured memory_bytes: 9156
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 10000000 + 5;
char s[20] , od[12];
bool hash[maxn];

int get(char c) {
  switch(c) {
     case 'A': return 1;
     case 'C': return 2;
     case 'G': return 3;
     case 'T': return 4;
  }
}

int h(char s[]) {
   int len = strlen(s);
   int k = 0;
   for(int i = 0 ; i < len ; i++) {
      k = k * 5 + get(s[i]);
   }
   return k;
}

int main()
{
  int n;
  scanf("%d",&n);
  for(int i = 1 ; i <= n ; i++) {
     scanf("%s%s",od , s);
     if(od[0] == 'i') hash[h(s)] = 1;
     if(od[0] == 'f') {
        if(hash[h(s)]) printf("yes\n");
        else printf("no\n");
     }
  }
  return 0;
}


Measured memory_bytes: 8348
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
#[allow(non_snake_case, unused_variables)]
fn main() {
    let S: String = read();
    let mut ans = "No";
    for i in 0..S.len()-1 {
        if &S[i..i+2]=="AC" {
            ans = "Yes";
            break;
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 4476
#include <stdio.h>
int main(){
	char a[3];
	int x=0,y=0,z=0;
	scanf("%s",&a);
	for (int i = 0; i < 3; ++i)
	{
		if (a[i]=='a')
		{
			x=x+1;
		}else if (a[i]=='b')
		{
			y=y+1;
		}else if (a[i]=='c')
		{
			z=z+1;
		}
	}
	if (x==1&&y==1&&z==1)
	{
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
//2100
/*int main(){
	int t, n;
	std::cin >> t;
	int MA = 0, MN = 0;
	int saizo[101];
	while(t--){
		std::cin>>n;
		for(int i = 0; i < n; ++i)
			std::cin >> saizo[i];
		for(int i = 0; i < n-1; ++i){
			int dif=saizo[i+1]-saizo[i];
			MA=std::max(MA,dif);
			MN=std::min(MN,dif);
		}
		std::cout<<MA<<" "<<-MN<<std::endl;
		MN=0,MA=0;
	}
	return 0;
}*/

int main(){
	int n;
	while(std::cin>>n){
		if(n==0)break;
		int s=0;
		for(int i=2;i*i<=n;++i){
			if(n%i==0){
				s+=i;
				if(i!=n/i)s+=n/i;
			}
		}
		if(n!=1)s+=1;
		if(s>n)std::cout<<"abundant number"<<std::endl;
		else if(s==n)std::cout<<"perfect number"<<std::endl;
		else std::cout<<"deficient number"<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1148
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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;
}

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

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

int main() {
    int x = 10001;
    int y = 10001;

    while (true) {
        cin >> x >> y;

        if (x == 0 && y == 0) break;

        if (x < y) {
            printf("%d %d\n", x, y);
        } else {
            printf("%d %d\n", y, x);
        }
    }
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int e = a*b;
  int f = c*d;
  
  if (e >= f) {
    cout << e << endl;
  }
  else {
    cout << f << endl;
  }
  
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

//const int inf = 1001001001;
//const int mod = (int)1e9+7;
const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    int N;
    cin >> N;
    ll ans=1, input;
    bool ng = false;
    REP(i, N) {
        cin >> input;
        if (input == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (1e18/ans < input || ans > (ll)1e18 || ans < 0) {
            ng = true;
        }

        if (!ng) ans *= input;
    }
    if (ng || ans > (ll)1e18 || ans < 0) {
        cout << "-1" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

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

		int N = Integer.parseInt(sc.next());

		String S = sc.next();

		sc.close();

		char last = '0';
		int count = 0;
		for(int i = 0;i < N;i++) {
			if(last == S.charAt(i)) {

			}else {
				count++;
				last = S.charAt(i);
			}
		}


		System.out.println(count);


	}
}


Measured memory_bytes: 24660
using System;

public class Hello{
    public static void Main(){
        int i = 1;
        int x = 1;
        while(x != 0){
            x = int.Parse(Console.ReadLine());
            if(x != 0){
                Console.WriteLine("Case "+i+": "+x);
                i = i + 1;
            }
        }
    }
}



Measured memory_bytes: 15956
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;

#define MAX 1000000
typedef pair<int, int> P;

int main(void) {
	while(1) {
		int e, y, z, ans = MAX;

		scanf("%d", &e);
		if(!e) break;
		for(z = 0; z*z*z <= e; z++) {
			y = (int)sqrt((double)e - z*z*z);
			ans = min(ans, e - y*y - z*z*z + y + z);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1188
(defun main ()
  (let* ((n (read))
	 (s (make-array n)))
    (dotimes (i n)
      (setf (aref s i) (read-line)))
    (format t "AC x ~a~%" (count "AC" s :test #'equal))
    (format t "WA x ~a~%" (count "WA" s :test #'equal))
    (format t "TLE x ~a~%" (count "TLE" s :test #'equal))
    (format t "RE x ~a~%" (count "RE" s ::test #'equal))))

(main)


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


int main() {
  int n,d; cin >> n >> d;
  int w = d*2 + 1;
  int ans = (n+(w-1))/w;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())

A = list(map(int, sys.stdin.readline().split()))

abstotal = 0
count_minus = 0
abs_A = []
for i in range(N):
    abstotal += abs(A[i])
    abs_A.append(abs(A[i]))
    if A[i] < 0:
        count_minus += 1

ans = abstotal
if count_minus%2 == 1:
    ans = abstotal - 2 * min(abs_A)

print(ans)



Measured memory_bytes: 14236
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}
/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    char c[3][3];
    for(int i = 0; i < 3;i++) for(int j = 0; j < 3;j++) cin >> c[i][j];
    for(int i = 0; i < 3;i++) cout << c[i][i]; cout << endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行ずつ取得
            int gohyaku = int.Parse(Console.ReadLine());
            int hyaku = int.Parse(Console.ReadLine());
            int goju = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());

            // 総当たりでxと等しくなる場合にcountを増やす
            int count = 0;
            for(int i = 0; i <= gohyaku; i++)
            {
                for(int j = 0; j <= hyaku; j++)
                {
                    for(int k = 0; k <= goju; k++)
                    {
                        if(500 * i + 100 * j + 50 * k == x)
                        {
                            count++;
                        }
                    }
                }
            }

            // 標準出力に出力
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
function Main (input) {
  input = input.split("\n");
  var N = parseInt(input[0], 10);
  var S = input[1].split("");
  var ans = 0;
  for (var i = 0; i < N; i++) {
    if (S[i] == "A" && S[i+1] == "B" && S[i+2] == "C") {
      ans++;
    }
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
class Stack < Array
  attr_accessor :top
  def initialize(size)
    @top = 0
    super(size)
  end
  def pop
    @top -= 1
    return self[@top+1]
  end

  def push(x)
    @top += 1
    self[@top] = x
  end
end

input = gets.split(' ')
stack = Stack.new(1000)
input.each do |i|
  if i == '+'
    a = stack.pop
    b = stack.pop
    stack.push(a+b)
  elsif i == '-'
    a = stack.pop
    b = stack.pop
    stack.push(b-a)
  elsif i == '*'
    a = stack.pop
    b = stack.pop
    stack.push(a*b)
  else
    stack.push(i.to_i)
  end
end
puts stack.pop

Measured memory_bytes: 8736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, C, ans = INT_MAX;
    cin >> N >> C;
    auto D = make_v<int>(C, C), c = make_v<int>(N, N), p = make_v<int>(3, C);
    for (int i = 0; i < C; ++i)
    {
        for (int j = 0; j < C; ++j)
        {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            cin >> c[i][j];
        }
    }
    for (int j = 0; j < C; j++)
    {
        for (int k = 0; k < N; k++)
        {
            for (int l = 0; l < N; l++)
            {
                p[(k + l) % 3][j] += D[c[k][l] - 1][j];
            }
        }
    }

    for (int c1 = 0; c1 < C; c1++)
    {
        for (int c2 = 0; c2 < C; c2++)
        {
            if (c1 == c2)
                continue;
            for (int c3 = 0; c3 < C; c3++)
            {
                if (c1 == c3 or c2 == c3)
                    continue;
                chmin(ans, p[0][c1] + p[1][c2] + p[2][c3]);
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1280
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    vll G(N);
    FOR(i, 1, N){
        ll a;
        cin >> a;
        a--;
        G[a].push_back(i);
    }
    rep(i, N){
        cout << G[i].size() << endl;
    }
}

Measured memory_bytes: 20292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> red;
    vector<pair<int, int>> blue;
    for (int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        pair<int, int> p = make_pair(a, b);
        red.push_back(p);
    }
    sort(red.begin(), red.end());

    for (int i=0; i<n; i++) {
        int a, b;
        cin >> a >> b;
        pair<int, int> p = make_pair(a, b);
        blue.push_back(p);
    }
    sort(blue.begin(), blue.end());
    
    int res = 0;
    for (int i=0; i<n; i++) {
        int num = -1;
        for (int j=0; red[j].first < blue[i].first && j < red.size(); j++) {
            if (num == -1 && red[j].second < blue[i].second) num = j;
            else if (num != -1 && red[num].second < red[j].second && red[j].second < blue[i].second) num = j;
        }
            if (red[num].first < blue[i].first && red[num].second < blue[i].second){
                res++;
                red.erase(red.begin() + num);
            }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();

    if a + b + c < 22 {
      println!("{}", "win")
    } else {
      println!("{}", "bust")
    }
    
}


Measured memory_bytes: 4352
#include<stdio.h>

#define MAX 110
#define INFINITY 1000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

void Dijkstra(void);

int n;
int num[MAX][MAX];

int main(){
  int i,j,k,u,v,c;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      num[i][j] = INFINITY;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d%d",&v,&c);
      num[u][v] = c;
    }
  }

  Dijkstra();

  return 0;
}

void Dijkstra(){
  int i,u,v,min;
  int d[MAX],pi[MAX],color[MAX];

  for(u=0; u<n; u++){
    d[u]= INFINITY;
    color[u] = WHITE;
  }
  d[0] = 0;

  while(1){
    min = INFINITY;
    u = NIL;
    for(i=0; i<n; i++){
      if(color[i] != BLACK && d[i] < min){
	min = d[i];
	u = i;
      }
    }

    if(min == INFINITY) break;
    color[u] = BLACK;

    for(v=0; v<n; v++){
      if(color[v] != BLACK && num[u][v] != INFINITY){
	if(d[u] + num[u][v] < d[v]){
	  pi[v] = u;
	  d[v] = d[u] + num[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i=0; i<n; i++){
    printf("%d %d\n",i,d[i]);
  }
}



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

using namespace std;
const int N = 2e5 + 1;
long long k;
int n,a[N];
bool avail[N];
vector <int> V;
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    V.push_back(0);
    int start = 1; bool run = false;
    while (avail[a[start]] == false){
        start = a[start];
        avail[start] = true;
        V.push_back(start);
    }
    //V.push_back(a[start]);
    //for (int i = 1; i < V.size(); i++) cout << V[i] << " "; cout << "\n";
    int d , c = V.size() - 1;
    for (int i = 1; i < V.size(); i++)
        if (a[start] == V[i]) d = i;
    //cout << d << " " << c << "\n";
    if (k < d) cout << V[k];
    else{
        k = k - d + 1;
        k = k % (c - d + 1);
        if (k == 0) cout << V[c];
        else cout << V[d + k - 1];
    }
    return 0;
}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
#define ll long long
#define NMAX 1000
using namespace std;
ll cmmmdc(int a, int b)
{
    ll r=a%b;
    while(r!=0)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main()
{
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    while(A>0 && C>0)
    {
        C=C-B;
        if(C>0)
            A=A-D;
    }
    if(A>0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
		if (B-A<=0) System.out.println("delicious");
		else if (B-A<=X) System.out.println("safe");
		else System.out.println("dangerous");
		sc.close();		
	}

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

}

Measured memory_bytes: 35780