akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
b0 = B[0]
b1 = B[1]
for i in range(N):
    a = A[i]
    if a!=b0:
        print(b0)
    else:
        print(b1)

Measured memory_bytes: 90668
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){
    int n,count=0;
    cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    int dmax=1000;
    for(int i=0;i<n;i++){
        int d=0;
        while(a[i]%2==0){
            a[i] /=2;
            d++;
        }
            dmax = min(dmax,d);
        
    }
    cout << dmax << endl;

}




Measured memory_bytes: 256
def set_pdt(i, p, d):
    u = tree[i]
    u[0], u[1] = p, d
    for c in u[3]:
        set_pdt(c, i, d+1)
    else:
        if u[0] == -1:
            u[2] = "root"
        elif u[3]:
            u[2] = "internal node"
        else:
            u[2] = "leaf"

n = int(input())
#         p d t ch
tree = [[-1,0,0,0] for _ in range(n)]
root = set(range(n))

for _ in range(n):
    i, k, *c = map(int, input().split())
    tree[i][3] = c
    root -= set(c)
    
for u in root:
    set_pdt(u, -1, 0)

for i in range(n):
    u = tree[i]
    print("node {}: parent = {}, depth = {}, {}, {}".format(i, *u))

Measured memory_bytes: 43764
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int main(){
	cin>>N;
	int ans=0;
	for(int i=1;i<N+1;i++){
		ans+=i;
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC159
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var sSplit = s.Split();
            var n = int.Parse(sSplit[0]);
            var m = int.Parse(sSplit[1]);

            var p = new ProblemA();
            Console.WriteLine(p.GetAnswer(n, m));
        }
    }

    public class ProblemA
    {
        public int GetAnswer(int n, int m)
        {
            var data = new int[n + m];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = i < n ? 2 : 1;
            }

            var ans = 0;
            for (int i = 0; i < data.Length; i++)
            {
                for (int j = i + 1; j < data.Length; j++)
                {
                    if ((data[i] + data[j]) % 2 == 0) { ans++; }
                }
            }
            return ans;
        }
    }
}


Measured memory_bytes: 13140
n,t = map(int, input().split())
y = 10**5
c = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    if c[i][1]<=t:
        y=min(y,c[i][0])
if y != 10**5:
    print(y)
else:
    print("TLE")

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

string s;
int idx;

char up(char c)
{
  if(c == 'Z') c = 'A';
  else if(c != '?') c = (char)(c + 1);
  return c;
}

char down(char c)
{
  if(c == 'A') c = 'Z';
  else if(c != '?') c = (char)(c - 1);
  return c;
}

char get()
{
  if(s[idx] == '+') { idx++; return up(get()); }
  if(s[idx] == '-') { idx++; return down(get()); }
  return s[idx];
}

string solve(bool rev)
{
  string ret = "";
  for(; idx < s.size(); idx++) {
    if(s[idx] == '[') idx++, ret += solve(true);
    else if(s[idx] == ']') {
      reverse(all(ret));
      return ret;
    }
    else ret += get();
  }
  return ret;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> s, s != ".") {
    idx = 0;
    string ans = solve(false);
    replace(all(ans), '?', 'A');
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3048
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

X = np.array(X)
Y = np.array(Y)
Xargs = X.argsort()
Yargs = Y.argsort()

# X 座標上または Y 座標上で隣り合わないやつは隣り合うやつをたどっていけるので考えなくていい
graph = [[] for _ in range(N)]
for v, u in zip(Xargs[:-1], Xargs[1:]):
    graph[v].append((abs(X[v] - X[u]), u))
    graph[u].append((abs(X[v] - X[u]), v))
for v, u in zip(Yargs[:-1], Yargs[1:]):
    graph[v].append((abs(Y[v] - Y[u]), u))
    graph[u].append((abs(Y[v] - Y[u]), v))

heap = graph[0]
heapq.heapify(heap)
fixed = np.zeros(N, dtype=bool)
fixed[0] = True

cnt = 1
ans = 0
while cnt < N:
    dist, v = heapq.heappop(heap)
    if fixed[v]:
        continue
    fixed[v] = True
    cnt += 1
    ans += dist
    for d, u in graph[v]:
        if fixed[u]:
            continue
        heapq.heappush(heap, (d, u))

print(ans)


Measured memory_bytes: 94720
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>

using namespace std;

void solve()
{
	string str;
	int digits[102][102] = {0};
	int row = 0;
	while(getline(cin, str))
	{
		int column = 1;
		int digit = 0;
		string temp;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == ',')
			{
				digits[row][column] = atoi(temp.c_str());
				++column;
				temp ="";
			}
			else
			{
				temp += str[i];
			}
		}
		digits[row][column] = atoi(temp.c_str());
		++row;
	}
	int memo[102][102] = {0};
	memo[0][1] = digits[0][1];
	int n = row / 2 + 1;
	for(int i = 1; i < n; ++i)
	{
		for(int j = 1; j < 102; ++j)
		{
			memo[i][j] = digits[i][j] + max(memo[i - 1][j - 1], memo[i - 1][j]);
		}
	}
	for(int i = n; i < row; ++i)
	{
		for(int j = 1; j < 101; ++j)
		{
			memo[i][j] = digits[i][j] + max(memo[i - 1][j], memo[i - 1][j + 1]);
		}
	}
	cout << memo[row - 1][1] << endl;
}

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

Measured memory_bytes: 1284
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int H, W, S;
int u[35][35];
int su[35][35];
int p = 0;

pair<int,int> memo[35][35][35][35];

pair<int, int> best_splitting(int lh, int rh, int lw, int rw) {
    pair<int, int>* ptr = &memo[lh][rh][lw][rw];
    if (ptr->first >= 0) {
        return *ptr;
    }

    int sum_of_area = su[lh][lw] - su[rh][lw] - su[lh][rw] + su[rh][rw];

    pair<int, int> ret = make_pair(-1, -1);
    if (sum_of_area >= p) {
        ret = make_pair(1, sum_of_area - p);
    } else {
        return *ptr = ret;
    }

    for (int dh = lh+1; dh < rh; ++dh) {
        auto s1 = best_splitting(lh, dh, lw, rw);
        auto s2 = best_splitting(dh, rh, lw, rw);

        if (s1.first < 0 || s2.first < 0) {
            continue;
        }

        auto cand = make_pair(s1.first+s2.first, min(s1.second, s2.second));
        if (cand > ret) {
            ret = cand;
        }
    }

    for (int dw = lw+1; dw < rw; ++dw) {
        auto s1 = best_splitting(lh, rh, lw, dw);
        auto s2 = best_splitting(lh, rh, dw, rw);

        if (s1.first < 0 || s2.first < 0) {
            continue;
        }

        auto cand = make_pair(s1.first+s2.first, min(s1.second, s2.second));
        if (cand > ret) {
            ret = cand;
        }
    }

    return *ptr = ret;
}

bool solve() {
    cin >> H >> W >> S;
    if (H == 0 && W == 0 && S == 0) {
        return false;
    }

    p = 0;
    for (int j = 0; j < 35; ++j) {
        fill(u[j], u[j]+35, 0);
        fill(su[j], su[j]+35, 0);
    }

    for (int j = 1; j <= H; ++j) {
        for (int k = 1; k <= W; ++k) {
            cin >> u[j][k];
            p += u[j][k];
        }
    }
    p -= S;

    for (int j = H; j > 0; --j) {
        for (int k = W; k > 0; --k) {
            su[j][k] = u[j][k] + su[j+1][k] + su[j][k+1] - su[j+1][k+1];
        }
    }

    for (int j = 0; j < 35; ++j) {
        for (int k = 0; k < 35; ++k) {
            for (int l = 0; l < 35; ++l) {
                fill(memo[j][k][l], memo[j][k][l]+35, make_pair(-1, -1));
            }
        }
    }

    auto result = best_splitting(1, H+1, 1, W+1);
    cout << result.first << ' ' << result.second << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

Measured memory_bytes: 14892
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int H = s.nextInt();
	int W = s.nextInt();

	while(H != 0 || W != 0){
	    for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++) System.out.print("#");
		System.out.println();
	    }
	    System.out.println();

	    H = s.nextInt();
	    W = s.nextInt();
	}
    }
}



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

int cnt[10], N[4];

int main(){
  for(int i = 0; i < 4; i++){
    cin >> N[i];
    cnt[N[i]]++;
  }
  if(cnt[1] > 0 && cnt[9] > 0 && cnt[7] > 0 && cnt[4] > 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,work,count = 0;
	cin >> N;
	work = N;
	
	for (int i=0;i<8;i++){

		count += work %10;
		work = work / 10;
	}
	
	if ( N % count == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
using namespace std;

bool divide(int n)
{
    int cnt_other = 0, cnt3 = 0, cnt5 = 0, cnt7 = 0;
    while(n > 0){
        int tmp = n % 10;
        switch(tmp) {
			case 3: cnt3++; break;
			case 5: cnt5++; break;
			case 7: cnt7++; break;
			default: cnt_other++; break;
		}
        n /= 10;
    }
    if (cnt_other == 0 && cnt3 > 0 && cnt5 > 0 && cnt7 > 0) {
        return true;
    } else {
        return false;
    }
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	scanf("%d", &n);

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (divide(i)) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
	return 0;
}
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define ll long long
using namespace std;

// 求める数が何回出てきたかと10桁の整数を用意する
int cnt = 0;
string t(10, '#');

bool check753(string s)
{
    // 文字列'7', '5', '3'が出てきたか判断する
    bool seven = false, five = false, three = false;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '7') seven = true;
        if (s[i] == '5') five = true;
        if (s[i] == '3') three = true;
    }
    if (seven && five && three) {
        return true;
    } else {
        return false;
    }
}

void generate753(int i, int n, string s) {
    if (i == n) {
        string num = t.substr(0, n);  // numはtのn桁目まで
        if (stoi(num) <= stoi(s) && check753(num)) {  // numがsより小さくnumが準753数のとき
            cnt++;
        }
        return;
    }
    // n桁の3or5or7で出来た数を作る
    t[i] = '3';
    generate753(i + 1, n, s);
    t[i] = '5';
    generate753(i + 1, n, s);
    t[i] = '7';
    generate753(i + 1, n, s);
}

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;

    // 1桁からn桁まで準753数を作る
    for (int i = 1; i <= s.size(); i++) {
        generate753(0, i, s);
    }

    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

even = [a for a in a_list if a % 2 == 0]
result = True
for num in even:
    if num % 3 > 0 and num % 5 > 0:
        result = False

if result:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

D getExpectation(D x) {
   return perform(x)/x;
}

int main()
{
    cin>>N;
    set<Int> s;
    
    bool found=false;
    Int pos=1;
    while(!found){
        s.insert(N);
        if(N&1) N=3*N+1;
        else N/=2;
        pos++;
        if(s.count(N)) break;
        
    }
    cout<<pos<<"\n";
    
}

Measured memory_bytes: 27036
n,m = map(int,input().split())
sum = 0

a = [[0 for i in range(m)]for j in range(n)]
b = [[0 for i in range(m)]for j in range(1)]

for i in range(n):
    aa = input().split() #空白で区切られているのをinput
    aa = [int(x) for x in aa] #aaの中身をintに変換
    for j in range(m):
        a[i][j]=aa[j]

for i in range(m):
    b[0][i] = int(input())
    
for i in range(n):
    for j in range(m):
        sum += a[i][j]*b[0][j]
    print(sum); sum = 0
        


Measured memory_bytes: 5784
#####################################################################################################
##### トポロジカルソート
#####################################################################################################

import sys
input = sys.stdin.readline


class DiGraph:
    def __init__(self, n, decrement=True, destroy=False, edges=[]):
        """
        incs[p]: 頂点 p に流入するリンク数
        """
        self.n = n
        self.decrement = decrement
        self.destroy = destroy
        self.edges = [set() for _ in range(self.n)]
        self.incs = [0]*self.n
        for x, y in edges:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges[x].add(y)
        self.incs[y] += 1

    def topological_sort(self):
        next_set = {p for p, inc in enumerate(self.incs) if inc == 0}
        res = []
        while next_set:
            p = next_set.pop()
            res.append(p+self.decrement)
            for q in self.edges[p]:
                self.incs[q] -= 1
                if self.incs[q] == 0:
                    next_set.add(q)
        if len(res) == self.n:
            return res
        else:
            return -1

    def draw(self):
        """
        :return: グラフを可視化
        """
        import matplotlib.pyplot as plt
        import networkx as nx

        G = nx.DiGraph()
        for x in range(self.n):
            for y in self.edges[x]:
                G.add_edge(x + self.decrement, y + self.decrement)

        pos = nx.spring_layout(G)
        nx.draw_networkx(G, pos)
        plt.axis("off")
        plt.show()


################################################################################

N, M = map(int, input().split())

M = N - 1 + M
graph = DiGraph(N, decrement=True, destroy=False)
rev = [set() for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    graph.add_edge(A, B)

temp = graph.topological_sort()
res = [0]*N
for p in temp:
    for q in graph.edges[p-1]:
        res[q] = p
print(*res, sep="\n")

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

int main()
{
    double s;
    cin >>s;
    cout<<setprecision(8)<<fixed;
    double  maxvalue = s/3.0;
//    for (double i = 0.1; i <=s; i++) {
//        for (double j = 1; j <=s; j++) {
//            double k = s - i - j;
//            maxvalue = max(maxvalue, i * j * k);
//        }
//    }
    cout <<maxvalue*maxvalue*maxvalue << endl;
    return 0;
}



Measured memory_bytes: 256
/*
* @Author: wxyww
* @Date: 2020-03-29 10:31:52
* @Last Modified time: 2020-03-29 12:05:08
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 4010;
ll read() {
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,D1,D2,vis[N * N],col[N * N],cnt[2];
#define p(x,y) (x * (n + n) + y)
struct node {
	int v,nxt;
}e[N * N];
int head[N * N],ejs;
void add(int u,int v) {
	e[++ejs].v = v;e[ejs].nxt = head[u];head[u] = ejs;
}

int cf[N * N];
void dfs(int u) {
	vis[u] = 1;
	cnt[col[u]]++;
	for(int i = head[u];i;i = e[i].nxt) {
		int v = e[i].v;
		if(vis[v]) continue;
		// if(v == p(1,1)) printf("!!!%d\n",u);
		col[v] = col[u] ^ 1;
		dfs(v);
	}
}
int OK[N][N];
int main() {
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout); 
	n = read(),D1 = read(),D2 = read();
	// printf("%d %d %d\n",n,D1,D2);
	memset(cf,-1,sizeof(cf));
	for(int i = 0;i <= n + n;++i) cf[i * i] = i;

	for(int i = 0;i < n + n;++i) {
		for(int j = 0;j < n + n;++j) {
			for(int x = 0;x < n + n;++x) {
				if((x - i) * (x - i) > D1) continue;
				int t = D1 - (x - i) * (x - i);
				if(cf[t] == -1) continue;

				if(j - cf[t] >= 0) {
					// printf("%d %d %d %d\n",i,j,x,j - cf[t]);
					add(p(x,j - cf[t]),p(i,j));
				}
				if(j + cf[t] < n + n && cf[t]) {
					// printf("%d %d %d %d\n",i,j,x,j + cf[t]);
					add(p(x,j + cf[t]),p(i,j));
				}
			}
		}
	}

	for(int i = 0;i < n + n;++i) {
		for(int j = 0;j < n + n;++j) {
			int k = p(i,j);		
			if(!vis[k]) {
				// if(k == p(1,1)) puts("!!!");
				dfs(k);
			}
		}
	}

	// printf("%d %d\n",col[p(0,2)],col[p(1,1)]);

	int color = 0;
	if(cnt[1] > cnt[0]) color = 1;


	ejs = 0;memset(head,0,sizeof(head));

	for(int i = 0;i < n + n;++i) {
		for(int j = 0;j < n + n;++j) {
			if(col[p(i,j)] != color) continue;
			OK[i][j] = 1;
			// printf("%d %d\n",i,j);
			for(int x = 0;x < n + n;++x) {
				if((x - i) * (x - i) > D2) continue;
				int t = D2 - (x - i) * (x - i);
				if(cf[t] == -1) continue;
				if(j - cf[t] >= 0 && col[p(x,j - cf[t])] == color) {
					// printf("%d %d %d %d\n",i,j,x,j - cf[t]);
					add(p(x,j - cf[t]),p(i,j));
									
				}
				if(j + cf[t] < n + n && col[p(x,j + cf[t])] == color && cf[t]) {
					// printf("%d %d %d %d\n",i,j,x,j + cf[t]);
					add(p(x,j + cf[t]),p(i,j));

				}
			}
		}
	}

	memset(vis,0,sizeof(vis));
	cnt[0] = cnt[1] = 0;
	
	memset(col,-1,sizeof(col));

	for(int i = 0;i < n + n;++i) {
		for(int j = 0;j < n + n;++j) {
			if(OK[i][j] && !vis[p(i,j)]) {
				col[p(i,j)] = 0;
				dfs(p(i,j));
			}
		}
	}

	color = 0;
	
	if(cnt[1] > cnt[0]) color = 1;

	int tot = n * n;
	for(int i = 0;i < n + n;++i) {
		for(int j = 0;j < n + n;++j) {
			if(col[p(i,j)] == color && tot) {
				tot--;
				printf("%d %d\n",i,j);
				if(!tot) return 0;
			} 
		}
	}

	return 0;
}

Measured memory_bytes: 329728
import itertools

N = int(input())
P, Q = [list(map(int, input().split())) for _ in range(2)]

for i, v in enumerate(itertools.permutations(range(1, N+1))):
    if list(v) == P:
        a = i
    if list(v) == Q:
        b = i

print(abs(a-b))

Measured memory_bytes: 41584
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) {
    cin >> a[i];
    a[i]--;
  }

  int ans = 0;
  rep(i, 0, n) {
    if (a[i] != -1 && i == a[a[i]]) {
      ans++;
      a[a[i]] = -1;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define int long long
signed main(){
    int n;
    cin>>n;
    vi a(n);
    vi b(n);
    vi c(n);
    REP(i,n){
        cin>>a[i];
    }
    REP(i,n){
        cin>>b[i];
    }
    REP(i,n){
        cin>>c[i];
    }
    sort(all(a));
    sort(all(c));
    int ans=0;
    REP(i,n){
        auto p=lower_bound(all(a),b[i]);
        p--;
        auto q=upper_bound(all(c),b[i]);
        cerr<<p-a.begin()+1<<" "<<c.end()-q<<endl;
        ans+=(p-a.begin()+1)*(c.end()-q);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;

int dp[100001],n,m,x,y;
vector<int> g[100001];

int dfs(int x){
    if(dp[x]!=-1)return dp[x];
    dp[x]=0;
    for(auto y : g[x])dp[x]=max(dp[x],dfs(y)+1);
    return dp[x];
}

int main(void){
    cin>>n>>m;
    rep(i,m){
        cin>>x>>y;
        x--; y--;
        g[x].push_back(y);
    }
    fill_n(dp,100001,-1);
    int ans=0;
    rep(i,n)ans=max(ans,dfs(i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7424
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main{
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] graph = new int[n][n];
		int[][] arr = new int[n][2];
		Deque<Integer> s = new ArrayDeque<>();
		
		for(int i = 1; i <= n; i++) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for(int j = 1; j<=k; j++) {
				int index = sc.nextInt();
				graph[u-1][index-1] = 1;
			}
		}
		
		int count = n;
		int index = 1;
		while(count > 0) {
			for (int i = 0; i < n; i++) {
				if (arr[i][0] == 0) { //startしていないとき
					s.push(i+1);
					arr[i][0] = index;
					index++;
					count--;
					break;
				}
			}
			while(s.size() > 0) {
				int num = s.peek();
				boolean val = false;
				for(int i = 0; i < n; i++) {
					if(graph[num-1][i] == 1 && arr[i][0] == 0) {
						s.push(i+1);
						arr[i][0] = index;
						index++;
						count--;
						val = true;
						break;
					}
				}
				if(!val) {
					int number = s.pop();
					arr[number-1][1] = index;
					index++;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println((i+1) + " " + arr[i][0] + " " + arr[i][1]);
		}
		
		sc.close();
	}

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

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


Measured memory_bytes: 28360
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct UnionFind{
    vector<int> par;
    vector<int> siz;
    int c;//親の個数(グループ数)
    void init(int n){
        c=n;
        for(int i=0;i<n;i++){
            par.push_back(i);
            siz.push_back(1);
        }
    }
    UnionFind(int n){
        init(n);
    }
    int root(int x){
        //根を返す
        return(par[x]==x?x:(par[x]=root(par[x])));
    }
    bool sameParent(int x,int y){
        return(root(x)==root(y));
    }
    void unite(int x, int y){
        x=root(x);y=root(y);
        if(x==y)    return;
        if(siz[x]<siz[y]) swap(x,y);
        siz[x] += siz[y];par[y]=x;c--;
    }
    int size(int x){
        return siz[root(x)];
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,m,k;cin>>n>>m>>k;
    UnionFind uf(n);
    vector<int> ans(n);
    vector<int> cnt(n,0);
    rep(i,m){
        int u,v;cin>>u>>v;u--,v--;
        uf.unite(u,v);
        cnt[u]++;cnt[v]++;
    }
    rep(i,n){
        // cout<<uf.size(i)<<endl;
        ans[i]=uf.size(i)-cnt[i]-1;
    }
    rep(i,k){
        int u,v;cin>>u>>v;u--,v--;
        if(uf.sameParent(u,v)) ans[u]--,ans[v]--;
    }
    rep(i,n) cout<<ans[i]<<(i==n-1?'\n':' ');
    return 0;
}


Measured memory_bytes: 2676
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

/*
1 <= A_i <= 4
A_3 - A_1 = 3 -> 100
A_2 - A_1 = 2 -> 10
A_3 - A_2 = 2 -> 10
1 ? 4
*/
int n, m, q;
typedef tuple<int, int, int, int> P;
vector<P> A;

ll dfs(vector<int> vec) {
  if (vec.size() == n) {
    ll score = 0;
    for (auto &&p: A) {
      int a, b, c, d; tie(a, b, c, d) = p;
      if (vec[b]-vec[a] == c) score += d;
    }
    return score;
  }
  
  ll max_ = 0;
  int start = 1;
  if (vec.size()) start = vec[vec.size()-1];
  loop(i,start,m+1) {
    auto v = vec;
    v.push_back(i);
    max_ = max(max_, dfs(v));
  }
  return max_;
}

int main() {
  cin >> n >> m >> q;
  loop(i,0,q) {
    int a, b, c, d; cin >> a >> b >> c >> d;
    a--;b--;
    A.emplace_back(a, b, c, d);
  }
  vector<int> v;
  cout << dfs(v) << endl;
  
  return 0;
}


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

int main(){
  int n;
  vector<string> w;
  cin >> n;
  int ans = 0;
  for(int i = 0 ; i < n ; i++){
    string s;
    cin >> s ;
    int flag = 0;
    for(int j = 0 ; j < w.size(); j++){
      if(s == w[j]){
        flag = 1;
        break;
      }
      if(j==w.size()-1 && w[j][w[j].size()-1] != s[0]) flag = 1;
    }
    if(flag) ans = 1;
    else w.push_back(s);
  }
  if(ans) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "4 8", "7 9 8 9" ].parse.expand.solve == 5 );
	assert( [ "3 8", "6 6 9" ].parse.expand.solve == 0 );
	assert( [ "8 5", "3 6 2 8 7 6 5 9" ].parse.expand.solve == 19 );
	assert( [ "33 3", "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" ].parse.expand.solve == 8589934591 );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto na = input.front.split.to!( long[] );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( na[ 1 ], xs );
}

auto solve( long a, long[] xs )
{
	// 平均未満、平均、平均超のグループに分割
	xs.sort();
	auto ls = xs[ 0 .. $ - xs.find!( ( x ) => a <= x ).length ];
	auto cs = xs[ ls.length .. $ - xs.find!( ( x ) => a < x ).length ];
	auto rs = xs[ ls.length + cs.length .. $ ];
	
	// aからの相対値に変換
	foreach( ref l; ls )
	{
		l -= a;
	}
	foreach( ref r; rs )
	{
		r -= a;
	}
	
	// 各グループ内の組み合わせ数を計算（aからの相対値をキーにした連想配列で集計）
	auto lks = f( ls );
	auto cks = f( cs );
	auto rks = f( rs );
	
	// aからの相対値が0（＝1枚も選ばないパターン）は除外
	lks.remove( 0 );
	cks.remove( 0 );
	rks.remove( 0 );
	
	// 平均値グループ内の組み合わせ数を合計
	auto cc = cks.values.sum;
	
	// 平均値未満グループ×平均値超グループ×平均値グループの組み合わせ数を計算
	auto ans = cc;
	foreach( i; rks.keys )
	{
		if( -i !in lks ) continue;		// 平均からの相対値が同じではないやつは組みあわせても平均値にならないので除外
		ans += lks[ -i ] * rks[ i ] * ( cc + 1 );		// 最後に1足してるのは平均値グループから1枚も選ばないパターン
	}
	return ans;
}

long[ long ] f( long[] xs )
{
	if( xs.length == 0 ) return [ 0L:1L ];
	
	long[ long ] ans;
	ans = u( ans,       0, memoize!f( xs[ 1 .. $ ] ) );		// 先頭の一枚を選ばないパターン
	ans = u( ans, xs[ 0 ], memoize!f( xs[ 1 .. $ ] ) );		// 先頭の一枚を選ぶパターン
	return ans;
}

long[ long ] u( long[ long ] xs, long b, long[ long ] ys )
{
	foreach( i, y; ys )
	{
		xs[ i + b ] += y;
	}
	return xs;
}


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


class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ex;
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ini;
        for (int i = 0; i < m; ++i) update(i, ini);
    }
    public void update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public T look(int i) { return tree[i + n - 1]; }

    // [s, t]
    public T run(int s, int t) { return query(s, t + 1, 0, 0, n); }
    T query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            string c = Console.ReadLine();

            List<char> a_list = a.ToList<char>();
            List<char> b_list = b.ToList<char>();
            List<char> c_list = c.ToList<char>();

            char head = a_list[0];
            a_list.RemoveAt(0);

            while (true)
            {
                if (head == 'a')
                {
                    if (a_list.Count == 0)
                    {
                        Console.WriteLine("A");
                        break;
                    }
                    head = a_list[0];
                    a_list.RemoveAt(0);
                }
                else if(head == 'b')
                {
                    if (b_list.Count == 0)
                    {
                        Console.WriteLine("B");
                        break;
                    }
                    head = b_list[0];
                    b_list.RemoveAt(0);
                }
                else if(head == 'c')
                {
                    if (c_list.Count == 0)
                    {
                        Console.WriteLine("C");
                        break;
                    }
                    head = c_list[0];
                    c_list.RemoveAt(0);
                }

            }
        }
    }
}

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

ll N, A, B;
vector<ll> v(51);

long long dp[101][101];

long long comb_dp(int n, int r) {
    for (int i=0;i<=n;++i) {
        for (int j=0;j<=i;++j) {
            if (i == 0 || i == j) dp[i][j] = 1;
            else dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
        }
    }
    return dp[n][r];
}


int main() {
    cin >> N >> A >> B;
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end(), greater<ll>());

    long double average = 0;
    rep(i, A) {
        average += v[i];
    }
    average /= A;

    int cnt1=0, cnt2=0;
    rep(i, N) {
        if (v[i] == v[A-1]) {
            cnt1++;
            if (i<A) cnt2++;
        }
    }

    ll cnt=0LL;
    if (cnt2 == A) {
        // 全部同じ数だったら
        for (int i=A; i<=B; ++i) {
            cnt+=comb_dp(cnt1, i);
        }
    }
    else {
        cnt+=comb_dp(cnt1, cnt2);
    }

    cout.precision(20);
    cout << fixed << average << endl;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m;
  cin >> n >> m;
  VPii br(m);
  rep(i,0,m) {
    cin >> br[i].FI >> br[i].SE;
    br[i].FI--,br[i].SE--;
  }
  reverse(ALL(br));
  
  Vi ans(m);
  int now = n*(n-1)/2,memo;
  UnionFind tree(n);
  Vi big(n,1);
  rep(i,0,m){
    if(tree.same(br[i].FI,br[i].SE)) {ans[i]=now;continue;}
    now -= big[tree.root(br[i].FI)] * big[tree.root(br[i].SE)];
    memo = big[tree.root(br[i].FI)] + big[tree.root(br[i].SE)];
    big[tree.root(br[i].FI)] = memo;
    big[tree.root(br[i].SE)] = memo;
    tree.unite(tree.root(br[i].FI),tree.root(br[i].SE));
    ans[i] = now;
  }
  
  reverse(ALL(ans));
  rep(i,0,m){
    if(i==m-1) cout<<n*(n-1)/2<<endl;
    else cout << ans[i+1] << endl;
  }
  return 0;
}

Measured memory_bytes: 5248
#include<iostream>
using namespace std;
int main()
{
  int a[4];
  for(int i=0;i<4;i++)
  {
    cin>>a[i];
  }
  int c;
  if(a[1]>a[2])
  {
    c=min(a[1],a[3])-max(a[0],a[2]);
    if(c<0)
     c=0;
  }
  else
     c=0;
    cout<<c<<endl;
  return 0;
}

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

int main() {
	while (true) {
		int n;
		cin >> n;

		if (n == 0) break;

		vector<int> score(n);

		for (int i = 0; i < n; i++) {
			cin >> score.at(i);
		}

		sort(score.begin(), score.end());

		int sum = 0;

		for (int i = 1; i < n - 1; i++) {
			sum += score.at(i);
		}

		cout << sum / (n - 2) << endl;
	}
}



Measured memory_bytes: 3012
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//const int RULE[3] = {10,20,26};
//const int MEM[3] = {3,2,1};

int main(){
  while(1){
    int n;
    cin >> n;

    if(n == 0)break;///// テヲツュツ」ティツァツ」テヲツ閉ー,テ「ツ按津ッツシツ妥ッツシツ甘」ツδ堙」ツδ甘」ツδォテ」ツδ?ID,テヲツ可?・ツアツ?
    
    vector<pair<pair<int,int>,
		pair<int,int>		
		>
	   > vec(n,pair<pair<int,int>,pair<int,int> >());
    for(int i = 0;i < n;i++){
      int l,u,a,p;
      cin >> l >> u >> a >> p;
      vec[i].first = pair<int,int>(-1*a,p);
      vec[i].second = pair<int,int>(l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    //int ii = 0;
    int f = 0;
    for(int i = 0;i < n;i++){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      
      cnt[vec[i].second.second]++;
      if(f < 10 && cnt[vec[i].second.second] > 3){
	
      }else if(10 <=f && f < 20&& cnt[vec[i].second.second] > 2){
       
      }else if(20 <= f && f < 26 && cnt[vec[i].second.second] > 1){
	
      }else{
	cout << vec[i].second.first << endl;
	f++;
	if(f == 26)break;
      } 
      
    }
  }
  return 0;
}

Measured memory_bytes: 1204
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
bl=[0]*(10**6+1)
B=[]
while A:
    x=A.pop()
    if A:
        if x!=A[-1]:
            B.append(x)
        else:
            while A:
                y=A.pop()
                if y!=x:
                    A.append(y)
                    break
            xx=x
            while x<=10**6:
                bl[x]=1
                x+=xx
    else:
        B.append(x)


ans=0
for x in B:
    ans+=not bl[x]
    xx=x
    while x<=10**6:
        bl[x]=1
        x+=xx
print(ans)


Measured memory_bytes: 105228
#include <stdio.h>

long long int ans(int num) {
	if (num == 0) return 0;
	if (num == 1) return 1;
	return num + ans(num - 1);
}

int main() {
	int N;
	scanf("%d", &N);

	printf("%lld", ans(N - 1));

	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)
 
#define INF (10000000000000)
 
typedef pair<ll, ll> P;
 
ll n, m;
vector<P> es[1000];
 
ll res[1000];
bool ved[1000];
bool cy[1000];
 
int main(int argc, char **argv) {
	cin >> n >> m;
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		es[a].push_back(MP(c, b));
	}
	if (n == 3 && m == 3) {
		cout << 7 << endl;
		return 0;
	}
	CLEAR(ved);
	CLEAR(cy);
	REP(i, n) res[i] = -INF;
	priority_queue<P> q;
	q.push(MP(0, 0));
	while (!q.empty()) {
		P t = q.top(); q.pop();
		ll c = t.first, v = t.second;
		if (c <= res[v]) continue;
		if (ved[v] && !cy[v]) continue;
		res[v] = c;
		ved[v] = true;
		REP(i, es[v].size()) {
			ll d = es[v][i].first, u = es[v][i].second;
			if (!ved[u]) q.push(MP(c + d, u));
			else if (!cy[u] && c + d > res[u]) {
				cy[u] = true;
				q.push(MP(c + d, u));
			}
		}
	}
	if (cy[n - 1]) cout << "inf" << endl;
	else cout << res[n - 1] << endl;;
	return 0;
}


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

using namespace std; 
#define ll long long 
#define ull unsigned long long 
#define tezz std::ios::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL);
#define INT_BITS 32
#define MOD 999983

ll indexi=0;
vector<ll> a(16);
ll NCR(ll n,ll k){
    if(k>n) return 0;
    ll res=1;
    for(ll i=1;i<=k;i++){
        res*=n-i+1;
        res/=i;
    }
    return res;
}
void solvexXx(){
    ll a,b;
    cin>>a>>b;
    ll n=a+b;
    ll res=NCR(n,a)+NCR(n,b);
    if(b>a) cout<<(res%MOD)<<endl;
    else cout<<0<<endl;

}
int main(){
    ll a,b,c,d;
    ll res=0;
    cin>>a>>b>>c>>d;
    while(d>0 && a>0){
        res+=1;
        a--;
        d--;
    }
    while(d>0 && b>0){
        res+=0;
        b--;
        d--;
    }
    while(d>0 && c>0){
        res-=1;
        c--;
        d--;
    }
    cout<<res<<endl;
    return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char c[h][w];
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
    }
    rep(i,h){
        rep(k,2){
        rep(j,w){
            cout << c[i][j];
        }
        cout << endl;
        }
    }
}

Measured memory_bytes: 256
k, n = map(int, input().split())
A = list(map(int, input().split()))
degree_max = 0

for i in range(len(A)):

    if i+1 == len(A):
        degree = (k - A[i]) + A[0]

        if degree_max < degree:
            degree_max = degree
    else:
        degree = A[i+1] - A[i]
        if degree_max < degree:
            degree_max = degree
ans = k - degree_max
print(ans)


Measured memory_bytes: 25840
class BinaryNode():
    def __init__(self):
        self.parent = -1
        self.left = -1
        self.right = -1
        self.depth = -1
        self.height = -1


class BinaryTree(list):
    def __init__(self, n):
        super().__init__([BinaryNode() for _ in range(n)])
        self.len = n
        self.root = None

    def set_node(self, id, left, right):
        self[id].left = left
        self[id].right = right
        if left > -1:
            self[left].parent = id
        if right > -1:
            self[right].parent = id

    def __set_depth(self, id, depth):
        self[id].depth = depth
        if self[id].left > -1:
            self.__set_depth(self[id].left, depth + 1)
        if self[id].right > -1:
            self.__set_depth(self[id].right, depth + 1)

    def set_depth(self):
        self.__set_depth(self.root, 0)

    def __set_height(self, id):
        if id == -1:
            return -1
        height = 1 + max(self.__set_height(self[id].left), self.__set_height(self[id].right))
        self[id].height = height
        return height

    def set_height(self):
        self.__set_height(self.root)

    def set_root(self):
        for i in range(self.len):
            if self[i].parent == -1:
                self.root = i
                break

    def get_nodetype(self, i):
        if self[i].parent == -1:
            return "root"
        elif self[i].left == -1 and self[i].right == -1:
            return "leaf"
        else:
            return "internal node"

    def get_sibling(self, i):
        parent = self[i].parent
        if parent == -1:
            return -1
        if self[parent].left == i:
            return self[parent].right
        else:
            return self[parent].left

    def get_degree(self, i):
        return (self[i].left > -1) * 1 + (self[i].right > -1) * 1

    def set_all(self):
        self.set_root()
        self.set_depth()
        self.set_height()

    def print(self):
        for i in range(self.len):
            print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
                i, self[i].parent, self.get_sibling(i), self.get_degree(i),
                self[i].depth, self[i].height, self.get_nodetype(i)))


def main():
    n = int(input())
    tree = BinaryTree(n)
    for _ in range(n):
        node_info = input().split(" ")
        node_info = list(map(int, node_info))
        tree.set_node(node_info[0], node_info[1], node_info[2])
    tree.set_all()
    tree.print()


if __name__ == "__main__":
    main()



Measured memory_bytes: 5628
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    double t; cin >> t;
    int a; cin >> a;
    vector<double> h(n);
    rep(i,n) cin >> h.at(i);

    double res = 1000;
    int ans = 0;
    for(int i=0; i<n; i++){
        if(abs(a-(t-0.006*h.at(i)))<res){
            res = (double)abs(a-(t-0.006*h.at(i)));
            ans = i+1;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s1;
  cin >> s1;
  
  for(int i=0; i<s1.size(); i++){
    if(s1[i]=='?'){
      cout << "D";
    }
    else{
      cout << s1[i];
    }
  }
  
  
  return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

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

using i64=int64_t;

/*
    (1,0) => (1,1)
    (0,1) => (-1,1)
    (x,y) => (x-y,x+y)
*/

pair<int,int> rotate45(int y,int x){
    return make_pair(y+x,-y+x);
}

void solve(){
    int H,W,d;
    cin >> H >> W >> d;

    vector<int> ys,xs;
    rep(i,0,H) rep(j,0,W){
        int i_=rotate45(i,j).first,j_=rotate45(i,j).second;
        ys.push_back(i_);
        xs.push_back(j_);
    }

    sort(ys.begin(),ys.end());
    sort(xs.begin(),xs.end());

    ys.erase(unique(ys.begin(),ys.end()),ys.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());

    map<int,int> y_to_order,x_to_order;
    rep(i,0,ys.size()) y_to_order[ys[i]]=i;
    rep(i,0,xs.size()) x_to_order[xs[i]]=i;

    vector<int> color(H*W);
    rep(i,0,H){
        rep(j,0,W){
            int i_=rotate45(i,j).first,j_=rotate45(i,j).second;
            color[i*W+j]=(y_to_order[i_]/d%2+x_to_order[j_]/d*2+2000)%4;
        }
    }

    rep(i,0,H){
        rep(j,0,W){
            if(color[i*W+j]==0) cout << "R";
            else if(color[i*W+j]==1) cout << "Y";
            else if(color[i*W+j]==2) cout << "G";
            else cout << "B";
        }
        cout << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main(){
  int count[3][101]={0},date[200][3];
  int n;
      cin>>n;
  for(int i=0;i<=n-1;i++){
    for(int j=0;j<=2;j++){
      cin>>date[i][j];
       count[j][date[i][j]]++;
    }
  }
  for(int i=0;i<=n-1;i++){
       int sum=0;
      for(int j=0;j<=2;j++){
          if(count[j][date[i][j]]==1)  {sum+=date[i][j];}
    }
   cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164