akhauriyash/Code-Regression huggingface dataset:
def next(N, i):
    return ((N-i-1)+N)%N

def getState(N, G, i, j):
    return  G[i][j] == G[i][next(N, j)] and  G[i][j] == G[next(N, i)][j] and G[i][j] == G[next(N, i)][next(N, j)]

def getInit(N, G):
    dcnt = 0
    for i in range(N//2):
        for j in range(N//2):
            if not getState(N, G, i, j): dcnt += 1
    return dcnt

C, N = map(int, input().split())
#G = [[0]*N]*N
G = [['N' for _ in range(N)] for _ in range(N)]
for i in range(N):
    str = input()
    for j in range(N):
        G[i][j] = int(str[j])

ans = 0
dcnt = getInit(N, G)
if dcnt == 0: ans += 1

for i in range(C-1):
    k = int(input())
    for j in range(k):
        r, c = map(int, input().split())
        r -= 1
        c -= 1
        pre = getState(N, G, r, c)
        G[r][c] = 0 if G[r][c]== 1 else 1
        post = getState(N, G, r, c)
        if not pre and post: dcnt -= 1
        elif  pre and not post: dcnt += 1
    if dcnt == 0: ans += 1

print(ans)



Measured memory_bytes: 14404
#include <stdio.h>
int main(void) {
	int i,a[10],tmp,j;
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	for(j=9;j>0;j--){
        for(i=0;i<j;i++){
            if(a[i]<a[i+1]){
                tmp=a[i];
	            a[i]=a[i+1];
		        a[i+1]=tmp;
		    }
        }
	}
	printf("%d\n",a[0]);
    printf("%d\n",a[1]);
    printf("%d\n",a[2]);
	return 0;
}



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

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int BubbleSort(int, int[]);
    int count = BubbleSort(n, a);
    for(int i = 0; i < n - 1; i++)
        cout << a[i] << ' ';
    cout << a[n - 1] << '\n' << count << endl;
    return 0;
}

int BubbleSort(int n, int a[]) {
    int count = 0;
    void swap(int&, int&);
    for(int i = 0; i < n - 1; i++) 
        for(int j = n - 1; j > i; j--) 
            if(a[j - 1] > a[j]) {
                swap(a[j - 1], a[j]);
                count++;
            }
    return count;
}

void swap(int& a, int& b) {
    int temp = a;
    a = b;
    b = temp;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main(){
    string x, y;
    int z[256] = {};
    int zz[256] = {};
    cin >> x >> y;
    for(int a = 0; a < (int)x.size(); a++){
        if(z[(int)x[a]] == 0) z[(int)x[a]] = (int)y[a];
        else if(z[(int)x[a]] != (int)y[a]){
            cout << "No" << endl;
            return 0;
        }
        if(zz[(int)y[a]] == 0) zz[(int)y[a]] = (int)x[a];
        else if(zz[(int)y[a]] != (int)x[a]){
            cout << "No" << endl;
            return 0;
        }
    }
 
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;


int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  LL n, a, b;
  cin >> n >> a >> b;
  if ((a & 1) == (b & 1)) cout << (b - a) / 2 << endl;
  else {
    LL t1 = a + (b - a) / 2;
    LL t2 = (n - b + 1) + (b - a) / 2;
    cout << min(t1, t2);
  }

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 200005;
int n;
vector<int>ntoj[maxn],jton[maxn];
int lk[maxn],dy[maxn];
int vis[maxn];
bool hungary(int x,int id) {
	if(vis[x]==id) return 0;
	vis[x] = id;
	for(int y:jton[x]) {
		if(!lk[y]) {
			lk[y] = x;
			return 1;
		}
	}
	for(int y:jton[x]) {
		if(hungary(lk[y],id)) {
			lk[y] = x;
			return 1;
		}
	}
	return 0;
}
void wuj() {
	puts("-1");
	exit(0);
}
bool vi[maxn];
int fr[maxn],to[maxn];
void dfs(int x) {
	vi[x] = 1;
	for(int y:ntoj[x]) {
		if(!vi[dy[y]]) {
			fr[y] = x;
			to[y] = dy[y];
			dfs(dy[y]);
		}
	}
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		int sz; scanf("%d",&sz);
		jton[i].resize(sz);
		for(int j=0;j<sz;j++) {
			int x; scanf("%d",&x);
			ntoj[x].push_back(i);
			jton[i][j]=x;
		}
		if((!hungary(i,i))) wuj();
	}
	for(int i=1;i<=n;i++) {
		dy[lk[i]]=i;
	}
	int rt = 1;
	while(lk[rt]) rt++;
	dfs(rt);
	for(int i=1;i<=n;i++) {
		if(!vi[i]) wuj();
	}
	for(int i=1;i<n;i++) {
		printf("%d %d\n",fr[i],to[i]);
	}
}

Measured memory_bytes: 22784
n = int(input())
v = list(map(int, input().split()))

v1 = v[0::2]
v2 = v[1::2]

m1, m2 = {}, {}
for vi in v1:
    if vi in m1:
        m1[vi] += 1
    else:
        m1[vi] = 1
for vi in v2:
    c = m2[vi] if vi in m2 else 0
    m2[vi] = c + 1

p1 = [(k, m1[k]) for k in m1.keys()]
p2 = [(k, m2[k]) for k in m2.keys()]

p1.sort(key=lambda x: x[1], reverse=True)
p2.sort(key=lambda x: x[1], reverse=True)

if n == 2:
    if v1[0] == v2[0]:
        ans = 1
    else:
        ans = 0
else:
    if p1[0][0] == p2[0][0]:
        if p1[0][1] < p2[0][1]:
            ans = n - p2[0][1] - p1[1][1]
        elif p1[0][1] > p2[0][1]:
            ans = n - p1[0][1] - p2[1][1]
        else:
            h = p1[0][1]
            if len(p1) == 1:
                ans = n - h
            else:
                if p1[1][1] < p2[1][1]:
                    ans = n - h - p2[1][1]
                else:
                    ans = n - h - p1[1][1]
    else:
        ans = n - p1[0][1] - p2[0][1]
print(ans)


Measured memory_bytes: 23264
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
# import random

# N = 10**5
# A = [random.randrange(1,10**9+1) for _ in range(N)]

# import time

def main():
    l = 0
    r = N
    while r-l > 1:
        m = (r+l)//2
        ok = True
        if m == 1:
            pre = -1
            for a in A:
                if pre >= a:
                    ok = False
                    break
                pre = a
        else:
            dp = {}
            needreset = 10**15
            exception = set()
            pre = -1
            for a in A:
                ind = a
                for _ in range(40):
                    # 修正
                    if needreset >= ind or ind in exception:
                        if not ind in dp:
                            dp[ind] = 0 if pre < a else 1
                    else:
                        dp[ind] = 0 if pre < a else 1
                        exception.add(ind)
                    # たす
                    if dp[ind] < m:
                        dp[ind] += 1
                        break
                    elif ind == 1:
                        ok = False
                        break
                    else:
                        # 繰り上がり
                        dp[ind] = 1
                        ind -= 1
                if not ok: break
                # 更新
                if pre > a:
                    needreset = a
                    exception = set()
                pre = a

        if ok:
            r = m
        else:
            l = m

    print(r)


if __name__ == "__main__":
    #dt = time.time()
    main()
    #print(time.time()-dt)


Measured memory_bytes: 142824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;
    cin>>n;
    ll dp[3][n+1];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<=n;j++)
            dp[i][j]=0;
    }
    for(int i=1;i<=n;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        if(i==1)
        {
            dp[0][i]=x;
            dp[1][i]=y;
            dp[2][i]=z;
        }
        else{
            dp[0][i]=max(dp[1][i-1],dp[2][i-1])+x;
            dp[1][i]=max(dp[0][i-1],dp[2][i-1])+y;
            dp[2][i]=max(dp[0][i-1],dp[1][i-1])+z;
        }
    }
    cout<<max(dp[0][n],max(dp[1][n],dp[2][n]));
    return 0;
}

Measured memory_bytes: 2560
h, w = map(int, input().split())

ans = float('inf')
if h % 3 == 0:
    ans = min(ans, 0)
else:
    ans = min(ans, w)
if w % 3 == 0:
    ans = min(ans, 0)
else:
    ans = min(ans, h)

for i in range(1, w):
    s1 = h // 2 * i
    s2 = (h - h // 2) * i
    s3 = h * (w - i)
    s = sorted([s1, s2, s3])
    ans = min(ans, s[-1] - s[0])

for i in range(1, w):
    s1 = h * i
    s2 = (h // 2) * (w - i)
    s3 = (h - h // 2) * (w - i)
    s = sorted([s1, s2, s3])
    ans = min(ans, s[-1] - s[0])

for i in range(1, h):
    s1 = w // 2 * i
    s2 = (w - w // 2) * i
    s3 = w * (h - i)
    s = sorted([s1, s2, s3])
    ans = min(ans, s[-1] - s[0])

for i in range(1, h):
    s1 = w  * i
    s2 = (w // 2) * (h - i)
    s3 = (w - w // 2) * (h - i)
    s = sorted([s1, s2, s3])
    ans = min(ans, s[-1] - s[0])

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

int A, B, K;

int main() {

	cin >> A >> B >> K;

	for (int i = A; i <= min(A + K-1,B); ++i) {
		cout << i << endl;
	}

	for (int i = max(B - K + 1, A + K); i <= B; ++i) {
		cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    long long sum = 0;
    long long init_min = 0;
    int n;
    cin>>n;
    vector<int> cards(n);
    for(int i = 0;i<n;i++){
        cin>>cards[i];
        sum += cards[i];
        init_min += abs(cards[i]);
    }
    long long sunuke=0, arai = sum;
    long long  min = init_min;
    for(int i = 0;i<n-1;i++){
        arai -=  cards[i];
        sunuke += cards[i];
        if (abs(arai-sunuke) < min){min = abs(arai-sunuke);}
    }
    cout<<min<<endl;
}


Measured memory_bytes: 1024
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e2 + 5, INF = 1e9;
int n,m, d[N][N], edge[N][N];



void Floyd(){
    cin>>n>>m;
    fill_n(&d[0][0], N*N, INF);
    for (int i = 0; i < n; i++)d[i][i] = 0;
    
    for(int i = 1; i <= m; i++){
        int u,v,dist;
        cin>>u>>v>>dist;
        u--,v--;
        d[u][v] = edge[u][v] = dist;
        d[v][u] = edge[v][u] = dist;
    }
    
    for(int k = 0; k < n; k++)
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if(d[i][k] < INF && d[k][j] < INF)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    

    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            if(edge[i][j] == 0)continue;
            int used = 0;
            for (int k = 0; k < n; k++){
                if(d[k][j] == d[k][i] + edge[i][j]) used = 1;
                if(d[k][i] == d[k][j] + edge[i][j]) used = 1;
            }
            if(!used)ans++;
        }
    }
    cout<<ans<<endl;
}



int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    Floyd();
    
    return 0;
}


Measured memory_bytes: 384
N,Y = (int(i) for i in input().split())

x,y,z = 0,0,0

flg = False
for x in range(N+1):
    for y in range(0,N-x+1):
        z = N-x-y
        m = 10000*x+5000*y+1000*z
        if m == Y:
            print(x,y,z)
            flg = True
            break
    if flg==True:
        break

if flg==False:
    print(-1,-1,-1)

Measured memory_bytes: 40924
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] A = nextIntArray(sc, N);

		int min = Integer.MAX_VALUE;
		int maxDiff = 0;
		int cntMax = 0;
		for (int a : A) {
			if (a < min) {
				min = a;
				continue;
			}
			int diff = a - min;
			if (diff > maxDiff) {
				maxDiff = diff; 
				cntMax = 1;
				// System.out.println("reset");
				// System.out.println(a);
				continue;
			}
			if (diff == maxDiff) {
				// System.out.println(a);
				cntMax++;
			}
		}

		System.out.println(cntMax);
	}
}


Measured memory_bytes: 50988
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;

	bool ok = true;
	if (S[A] != '-')ok = false;
	rep(i, 0, A)
	{
		if (!('0' <= S[i] && S[i] <= '9'))
		{
			ok = false;
		}
	}
	rep(i, 0, B)
	{
		if (!('0' <= S[A+1+i] && S[A+1+i] <= '9'))
		{
			ok = false;
		}
	}
	if (ok)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int m = sc.nextInt();
                if(m == 0)break;
                
                int[] a = new int[m+1];
                for(int i=1;i<=m;i++) {
                	 a[i] = sc.nextInt();
                }
                
                Arrays.sort(a);
                int gap = a[m];
                for(int i=1;i<m;i++) {
                	int b = Math.abs(a[i]-a[i+1]);
                	if(b < gap)
                		gap = b;
                }
                
                System.out.println(gap);
            }
        }
    }
}


Measured memory_bytes: 46976
from time import time
from random import randrange
start = time()
d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
    s.append(list(map(int, input().split())))
t = []
v = 0
last = [-1]*26
for i in range(d):
    bst = -10**10
    for j in range(26):
        tmp = s[i][j]
        for k in range(26):
            if j!=k:
                tmp -= c[k]*(i-last[k])
        if tmp>bst:
            bst = tmp
            bst_idx = j
    last[bst_idx] = i
    t.append(bst_idx)
    v += s[i][bst_idx]
    for j in range(26):
        v -= c[j]*(i-last[j])
mx = v
while time()-start<1.85:
    newt = t[:]
    nd = randrange(d)
    now = newt[nd]
    nq = randrange(25)
    newt[nd] = nq if nq<now else nq+1
    v = 0
    last = [-1]*26
    for i in range(d):
        v += s[i][newt[i]]
        last[newt[i]] = i
        for j in range(26):
            v -= c[j]*(i-last[j])
    if v>mx:
        mx = v
        t = newt
for i in t:
    print(i+1)


Measured memory_bytes: 85980
#include<bits/stdc++.h>
#define N 100
using namespace std;
int n,D,ans;
int X[N][N];
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	return;
}
inline int P(int x){
	return x*x;
}
int main(){
	Rd(n);Rd(D);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=D;j++){
			scanf("%d",&X[i][j]);
		}
	}
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			int x=0;
			for(int k=1;k<=D;k++)x+=P(X[i][k]-X[j][k]);
			int o=sqrt(x);
			if(o*o==x)ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  char c;
  cin>>c;
  
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel"<<endl;
  }
  
  else
    cout << "consonant" << endl;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;

    int64_t cur;
    map<int64_t, int64_t> m;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        m[cur] += 1;
    }

    int64_t ans = 0;
    for (auto p: m) {
        int64_t one = p.first;
        int64_t num = p.second;
        
        if (num < one) {
            ans += num;
        } else if (num == one) {
            continue;
        } else {
            ans += (num - one);
        }
    }

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


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     ll n,k;
     cin>>n>>k;
     if(n%k==0) cout<<0<<endl;
     else if(n<k){
        if(abs(n-k)<n) cout<<abs(n-k)<<endl;
        else cout<<n<<endl;
     }
     else{
        cout<<k-(n%k)<<endl;
     }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ll long long
#define inf 1e9
#define eps 1e-10
#define mod 9901
#define mkp make_pair
using namespace std;
int i,j,k,m,s,t,n,ans1,ans2,n1,nn,m1,mx;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int kabs(int a)
{
   if (a<0) return -a;
   return a; 
}
void add(int &x,int y)
{
   x+=y;
   if (x>=mod) x-=mod;
}
void dec(int &x,int y)
{
	x-=y;
	if (x<0) x+=mod;
}
int a[101000],b[101000];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		a[i]=30000*i;
	for (i=1;i<=n;i++)
		b[i]=30000*(n-i+1);
	for (i=1;i<=n;i++)
		scanf("%d",&s),b[s]+=i;
	for (i=1;i<=n;i++)
		printf("%d ",a[i]);
	puts("");
	for (i=1;i<=n;i++)
		printf("%d ",b[i]);
	puts("");
}

Measured memory_bytes: 768
import numpy as np
from numba import njit


@njit
def main(I):
    N,K=I[0],I[1]
    A = I[2:]
    A.sort()
    lb = -10**18-1
    rb = 10 ** 18 + 1
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                elif a < 0:
                    il = np.searchsorted(A,0- (-target)//a,side='left')
                    d = max(i - il, 0)
                else:
                    ir = np.searchsorted(A,target//a,side='right')
                    d = min(ir, i)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

I=np.array([int(_) for _ in open(0).read().split()],dtype=int)
print(main(I))

Measured memory_bytes: 121372
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    if (n == 2)
    {
        cout << 1 << endl;
        return 0;
    }
    int ans = 2;
    for (int i = 2; i * i <= n - 1; i++)
    {
        if ((n - 1) % i == 0)
        {
            // for (int j = 2; j * j <= i; j++)
            // {
            //     if (i % j == 0)
            //     {
            //         ans++;
            //         if (j * j != i)
            //             ans++;
            //     }
            // }
            ans++;
            if (i * i != (n - 1))
                ans++;
        }
    }
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            int m = n;
            while (m % i == 0)
                m /= i;
            if (((m - 1) % i) == 0)
            {
                ans++;
            }
            m = n;
            if (i * i == n)
                continue;
            int x = n / i;
            while (m % x == 0)
                m /= x;
            if (((m - 1) % x) == 0)
                ans++;
        }
    }
    cout << ans << endl;
}


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

struct line {
	int height;
	int lineA;
	int lineB;
};

bool comp(const line &a, const line &b) {
	return a.height > b.height;
}

int main(){
	int n, m, a;
	while(cin >> n >> m >> a, n || m || a){
		vector<line> lines(m);
		
		for(int i = 0; i < m; i++){
			cin >> lines[i].height >> lines[i].lineA >> lines[i].lineB;
		}
		sort(lines.begin(), lines.end(), comp);
		
		for(int i = 0; i < m; i++){
			if(lines[i].lineA == a){
				a = lines[i].lineB;
			}else if(lines[i].lineB == a){
				a = lines[i].lineA;
			}
		}
		cout << a << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
def SelectionSort(A, N):
    swap_n = 0

    for i in range(N):
        min_j = i

        for j in range(i + 1, N):
            if A[j] < A[min_j]:
                min_j = j

        if i != min_j:
            A[i], A[min_j] = A[min_j], A[i]
            swap_n += 1

    return swap_n

N = int(input())
A = [int(a) for a in input().split()]

swap_n = SelectionSort(A, N)

print(*A)
print(swap_n)

Measured memory_bytes: 7756
s = gets.chomp
num = 0

while num <= s.size
  num2 = num
  if s[num..num+4] == 'dream'
    if s[num..num+6] == 'dreamer'
      if s[num+5..num+9] == 'erase'
        num = num - 2
      end
      num += 2
    end
    num += 5
  end
  if s[num..num+4] == 'erase'
    if s[num..num+5] == 'eraser'
      num += 1
    end
    num += 5
  end
  if num == num2
    break
  end
end

if num == s.size
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 2044
#include<iostream>
#include<map>

using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    map<int, int> a;
    for (ll i = 0; i < N;i++){
        ll tmp;
        cin >> tmp;
        a[tmp]++;
    }
    int ans = 0;

    for(auto p : a){
        int key = p.first;
        int num = p.second;
        if(key>num){
            ans += num;
        }else{
            ans += num - key;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
using System;
using System.Linq;

namespace AtCoderMake.ABC164
{
    class ABC164A
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();
            if (s[0] > s[1])
            {
                Console.WriteLine("safe");
            }
            else
            {
                Console.WriteLine("unsafe");
            }
        }
    }
}


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

using namespace std;

const int mod = 998244353;

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  vector<vector<long long>> dp(C + 1, vector<long long>(D + 1, 0));
  dp[A][B] = 1;
  for(int a = A; a <= C; a++){
    for(int b = B; b <= D; b++){
      if(a == A && B == b) continue;
      dp[a][b] = dp[a - 1][b] * b + dp[a][b - 1] * a - dp[a - 1][b - 1] * ((a - 1) * (b - 1));
      dp[a][b] %= mod;
    }
  }
  
  
  cout << (mod + dp[C][D]) % mod << endl;
  
  return 0;
}

Measured memory_bytes: 73620
#include <iostream>
#include <algorithm>

int min(int x, int y)
{
	return x>y ? y : x;
}

int main()
{	
	int n, m;
	std::cin >> n;
	int* A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	std::cin >> m;
	int* B = new int[m];
	for (int i=0; i<m; i++) std::cin >> B[i];
	
	int* C = new int[min(n,m)];
	for (int i=0; i<min(n,m); i++) C[i] = -1;
	std::set_intersection(A, A+n, B, B+m, C);
	
	for (int i=0; i<min(n,m); i++) {
		if (C[i] < 0) break;
		std::cout << C[i] << std::endl;
	}
	
	delete[] A;
	delete[] B;
	delete[] C;
	
	return 0;
}



Measured memory_bytes: 5204
n = int(input())
As = list(map(int, input().split()))
MOD = 10**9 + 7
S = sum(As)
b = 0
for a in As:
    b += pow(a,2,MOD)
    b %= MOD
ans = (pow(S,2,MOD)-b)*pow(2,MOD-2,MOD)
print(ans%MOD)

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

int main() {
    int W, H, x, y, r;

    cin >> W >> H >> x >> y >> r;

    // 水平方向
    if (((x + r) > W) || ((x - r) < 0)) {
        cout << "No" << endl;
        return 0;
    } 

    // 垂直方向
    if (((y + r) > H) || ((y - r) < 0)) {
        cout << "No" << endl;
        return 0;
    }

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


Measured memory_bytes: 3092
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n;
  cin >> n;
  vector<vector<int> > e(n+1);
  REP(i,n-1) {
    int a,b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  vector<int> d(n+1,0);
  int v=1;
  queue<pair<int,int> > q;
  q.emplace(v,2);
  int md=0;
  while(!q.empty()) {
    int tv,td;
    tie(tv,td) = q.front();
    q.pop();
    if(d[tv]==0) {
      v=tv;
      md=td;
      d[tv]=td;
      for(auto nv: e[tv]) q.emplace(nv,td+1);
    }
  }
  d.assign(n+1,0);
  q.emplace(v,2);
  md=0;
  while(!q.empty()) {
    int tv,td;
    tie(tv,td) = q.front();
    q.pop();
    if(d[tv]==0) {
      md=td;
      d[tv]=td;
      for(auto nv: e[tv]) q.emplace(nv,td+1);
    }
  }
  cout << (md%3?"First":"Second") << endl;
}


Measured memory_bytes: 14452
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define INF 1145141919810893931
using namespace std;

ll solv(vector<ll> a, ll n) {
	ll ret = 0;
	vector<ll> vec;
	ll count = 0;
	ll maxi = a[0];
	bool first = true;
	while (n) {
		if (!first&&n & 1) {
			if (maxi >= a[count]) {
				ret += maxi - a[count] + 1;
				maxi++;
			}
		}
		if (maxi < a[count]) {
			maxi = a[count];
		}
		n /= 2;
		count++;
		first = false;
	}return ret;
}

ll count(ll n) {
	ll count = 0;
	while (n) {
		if (n & 1) count++;
		n /= 2;
	}return count;
}

int main() {
	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	ll mini = INF;
	rep(i, n) cin >> a[i];
	rep(i, pow(2, n)) {
		if (count(i) == k) {
			mini = min(mini, solv(a,i));
		}
	}cout << mini << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    switch(N%10){
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:
        System.out.print("hon");
        break;
      case 0:
      case 1:
      case 6:
      case 8:
        System.out.print("pon");
        break;
      case 3:
        System.out.print("bon");
        break;
    }
  }
}

Measured memory_bytes: 35740
a,b=map(int, input().split())
s=input()
if s.count("-")==1:    
    s_forward=s.split("-")[0]
    s_back=s.split("-")[1]
    if len(s_forward)==a and len(s_back)==b:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

using namespace std;

struct Point {
    double X;
    double Y;

    Point add(const Point &p) {
        return {this->X + p.X, this->Y + p.Y};
    }

};

struct Circle {
    Point C;
    double R;

};


double dist(const Point &a, const Point &b) {
    return sqrt(pow(a.X - b.X, 2) + pow(a.Y - b.Y, 2));
}

Point get_circle_center(double bx, double by, double cx, double cy) {
    double B = bx * bx + by * by, C = cx * cx + cy * cy, D = bx * cy - by * cx;
    return {(cy * B - by * C) / (2 * D), (bx * C - cx * B) / (2 * D)};
}

Circle circle_from(Point A, Point B, Point C) {
    Point I = get_circle_center(B.X - A.X, B.Y - A.Y, C.X - A.X, C.Y - A.Y);
    return {I.add(A), dist(I.add(A), A)};
}

Circle circle_from(Point A, Point B) {
    Point c = A.add(B);
    c.X /= 2.0, c.Y /= 2.0;
    return {c, dist(A, B) / 2.0};
}

Circle min_circle_trivial(vector<Point> &P) {
    assert(P.size() <= 3);
    if (P.empty()) {
        return {{0, 0}, 0};
    } else if (P.size() == 1) {
        return {P[0], 0};
    } else if (P.size() == 2) {
        return circle_from(P[0], P[1]);
    }
    return circle_from(P[0], P[1], P[2]);
}

bool is_inside(const Circle &c, const Point &p) {
    return dist(c.C, p) <= c.R;
}


Circle welzl_helper(int n, vector<Point> &P, vector<Point> R) {
    if (n == 0 || R.size() == 3) {
        return min_circle_trivial(R);
    }
    int idx = rand() % n;
    Point p = P[idx];
    swap(P[idx], P[n - 1]);

    Circle d = welzl_helper(n - 1, P, R);
    if (is_inside(d, p)) {
        return d;
    }
    R.push_back(p);
    return welzl_helper(n - 1, P, R);

}

Circle welzl(vector<Point> &P) {
    random_shuffle(P.begin(), P.end());
    return welzl_helper(P.size(), P, {});
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<Point> v;
    for (int i = 0; i < n; i++) {
        double a, b;
        cin >> a >> b;
        v.push_back({a, b});
    }
    Circle c = welzl(v);
//    cout << c.C.X << ' ' << c.C.Y << endl;
    cout << setprecision(8) << fixed << c.R << endl;


}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = (new BufferedReader(new InputStreamReader(System.in)));
		String line;
		br.readLine();
		while ((line = br.readLine()) != null) {
			String[] xyz = line.split(" ");
			int a = Integer.parseInt(xyz[0]);
			int b = Integer.parseInt(xyz[1]);
			int c = Integer.parseInt(xyz[2]);

			if (a > b && a > c) {
				printIsRightTriangle(a, b, c);
			} else if (b > a && b > c) {
				printIsRightTriangle(b, a, c);
			} else if (c > a && c > b) {
				printIsRightTriangle(c, b, a);
			} else {
				printIsRightTriangle(a, b, c);
			}
		}
	}

	public static void printIsRightTriangle(int long_value, int short_value1, int short_value2) {
		if ((long_value * long_value) == (short_value1 * short_value1 + short_value2 * short_value2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 20164
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define LL long long
using namespace std;
map <LL,int> M;
int n;
int main(){
	scanf("%d",&n);
	int i;
	LL sum=0,x,ans=0;
	M[0]=1;
	for (i=1;i<=n;i++){
		scanf("%lld",&x);
		sum+=x;
		ans+=(LL)M[sum];
		M[sum]++;
	}
	cout<<ans;
}


Measured memory_bytes: 12800
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[4];
        for (int i = 0; i < 4; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        boolean flag = true;
        if (a[0] != 1)
            flag = false;
        if (a[1] != 4)
            flag = false;
        if (a[2] != 7)
            flag = false;
        if (a[3] != 9)
            flag = false;
        if (flag) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21716
#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;

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

ll pair_search(pll match, vector<pll> r){
  pll maxi;
  //r_y, index
  maxi = make_pair(-1, -1);
  REP(i, r.size()){
    if(r[i].FI < match.FI && r[i].SE < match.SE && maxi.FI < r[i].SE){
      maxi.FI = r[i].SE;
      maxi.SE = i;
    }
  }
  //cout << maxi.FI << " " << maxi.SE << endl;
  return maxi.SE;
}


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

  int n;
  cin >> n;
  
  vector<pll> r(n), b(n);
  REP(i, n)
    cin >> r[i].FI >> r[i].SE;

  REP(i, n)
    cin >> b[i].FI >> b[i].SE;

  sort(r.begin(), r.end());
  sort(b.begin(), b.end());

  ll count = 0;
  REP(i, n){
    ll posi = pair_search(b[i], r);
    if(posi == -1)
      continue;
    else{
      count++;
      r.erase(r.begin() + posi);
    }
  }
  
  cout << count << "\n";  
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/14  Problem: 070_abc_c / Link: https://abc070.contest.atcoder.jp/tasks/abc070_c?lang=en  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;
/*最大公約数を求める関数(再帰版ユーグリッドの互除法)*/
long long  gcd(long long  a, long long  b) { return b ? gcd(b, a%b) : a; }

/*最小公倍数を求める関数。最小公倍数の性質( a×b÷[aとbの最大公約数] )を利用。*/
long long  lcm(long long  a, long long  b) { return a / gcd(a, b) * b; }

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

	cin >> N;
	ans = 1;
	FOR(i, 0, N) {
		LL c; cin >> c;
		ans = lcm(ans, c);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	hs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&hs[i])
	}

	result := 0
	for {
		start := 0
		isAllZero := false
		for i, h := range hs {
			if h != 0 {
				start = i
				break
			}
			if i == n-1 {
				isAllZero = true
			}
		}

		if isAllZero {
			break
		}

		end := n - 1
		s1 := start + 1
		for i := s1; i < n; i++ {
			if hs[i] == 0 {
				end = i - 1
				break
			}
		}

		for i := start; i <= end; i++ {
			hs[i]--
		}

		result++
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
n = int(input())
s = input()
MOD = 10**9+7

t = ["" for i in range(2*n)]
cntr, cntl = 0, 0

for i in range(2*n):
  if i%2==0 and s[i]=='B':
    t[i] = "R"
    cntr += 1
  elif i%2==0 and s[i]=='W':
    t[i] = "L"
    cntl += 1
  elif i%2==1 and s[i]=='B':
    t[i] = "L"
    cntl += 1
  elif i%2==1 and s[i]=='W':
    t[i] = "R"
    cntr += 1
if cntl!=cntr:
  print(0)
  exit()

cur = 1
rs, ls = 0, 0
for i in range(2*n-1, -1, -1):
  if t[i]=="L":
    ls += 1
  else:
    cur = (cur*(max(0, ls-rs)))%MOD
    rs += 1

MAX = 2*10**5+1
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]

def comb_build(n):
  fact[0] = inv[0] = invfact[0] = 1
  fact[1] = inv[1] = invfact[1] = 1
  for i in range(2, n):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
    invfact[i] = invfact[i-1]*inv[i]%MOD

comb_build(MAX)
print((cur*fact[n])%MOD)

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

#define int            long long 
#define vi             vector<int>
#define mod            1000000007
#define MAX            INT_MIN
#define MIN            INT_MAX
#define ff             first
#define ss             second
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define pqb            priority_queue<int>
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define ps(x,y)        fixed<<setprecision(y)<<x         
#define FIO            ios_base::sync_with_stdio(false); cin.tie(NULL);
                  
void c_p_c()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

int32_t main()
{
	c_p_c();


	int k;
	cin>>k;

	string s;
	cin>>s;

	int len = s.length();

	if(len<=k)
		cout<<s<<endl;
	else
	{
		for(int i=0;i<k;i++)
		{
			cout<<s[i];
		}
		cout<<"...";
	}




	return 0;
}


Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define MAXN 200100
#define ll long long
int n, m, cnt, a[MAXN], dp[MAXN], c[MAXN], d[MAXN];
int flag[MAXN], Left, Right, mid, first, last, ans, ans1[MAXN];
struct node
{
	int v;
	node *next;
}pool[2*MAXN], *h[MAXN];
void addedge(int u, int v)
{
	node *p = &pool[++cnt], *q = &pool[++cnt];
	p->v = v; p->next = h[u]; h[u] = p;
	q->v = u; q->next = h[v]; h[v] = q;
}
void dfs(int u)
{
	flag[u] = 1;
	Left = first;
	Right = last;
	ans = 0;
	while(Left <= Right)
	{
		mid = (Left + Right) / 2;
		if(dp[mid] < a[u]) ans = mid, Left = mid+1;
		else Right = mid-1;
	}
	c[u] = ans+1;
	d[u] = dp[ans+1];
	dp[ans+1] = a[u];
	if(ans+1 > last) last++;
	ans1[u] = last;
	for(node *p = h[u]; p; p = p->next)
	{
		if(flag[p->v] == 0)
		{
			dfs(p->v);
		}
	}
	dp[c[u]] = d[u];
	if(d[u] == 0) last--;
}
int main()
{
	scanf("%d",&n);
	int u, v;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u, v);
	}
	first = last = 0;
	dfs(1);
	for(int i=1;i<=n;i++) printf("%d\n",ans1[i]);
	
	return 0;
}

Measured memory_bytes: 26980
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-9;
const ll MOD=1000000007LL;
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);};
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 dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<vector<int>> G,par;
vector<int> dep;
int n;
void dfs(int i,int p){
	for(auto e:G[i]){
		if(e==p)continue;
		par[e][0]=i;
		dep[e]=dep[i]+1;
		dfs(e,i);
	}
}
void build(){
	par[0][0]=-1;
	dep[0]=0;
	dfs(0,-1);
	for(int j=1;j<20;j++){
		for(int i=0;i<n;i++){
			if(par[i][j-1]==-1){
				par[i][j]=-1;
			}else{
				par[i][j]=par[par[i][j-1]][j-1];
			}
		}
	}
}
int lca(int u,int v){
	if(dep[u]>dep[v])swap(u,v);
	for(int i=19;i>=0;i--){
		if(((dep[v]-dep[u])>>i)&1)v=par[v][i];
	}
	if(u==v)return u;
	for(int i=19;i>=0;i--){
		if(par[u][i]!=par[v][i]){
			u=par[u][i];
			v=par[v][i];
		}
	}
	return par[u][0];
}
int main(){
	cin>>n;
	G.resize(n);
	par.resize(n);
	dep.resize(n);
	for(int i=0;i<n;i++){
		int c;cin>>c;
		for(int j=0;j<c;j++){
			int ch;cin>>ch;
			G[i].push_back(ch);
		}
		par[i].resize(30);
	}
	int q;cin>>q;
	build();
	while(q--){
		int u,v;cin>>u>>v;
		cout<<lca(u,v)<<endl;
	}
}


Measured memory_bytes: 28048
N = int(input())
A = list(map(int, input().split()))
ans = 1

limit = pow(10,18)

f = 0
for i in range(N):
    if A[i] != 0 and f == 0:
        ans *= A[i]
    elif A[i] != 0:
        pass
    else:
        print(0)
        exit()

    if ans > limit:
        f = 1

if f == 1:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,l,r) for(int i=l;i<r;i++)
using namespace std;
using ll = long long;
static const ll MOD=1e9+7;
static const int inf=2e9+10;
static const ll INF=9e18+10;
const int dx[9]={1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9]={0, 1, 0, -1, 1, 1, -1, -1, 0};

#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

int main(){
    int n;cin>>n;
    int x,y;
    int maxa,mina,maxb,minb;
    maxa=maxb=-inf;
    mina=minb=inf;
    rep(i,n){
        cin>>x>>y;
        chmax(maxa,x+y);
        chmin(mina,x+y);
        chmax(maxb,x-y);
        chmin(minb,x-y);
    }
    int ans=max(maxa-mina,maxb-minb);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
int h[100001], n, c[100001];
int main(){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> h[i];
	c[n] = 0;
	c[n-1] = abs(h[n] - h[n-1]);

	for(int j=n-2;j>=1;j--)
		c[j] = min((abs(h[j+1] - h[j]) + c[j+1]), (abs(h[j+2] - h[j]) + c[j+2]));
					
	cout << c[1];
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int t = a-b;
	if(t>=c)
		cout<<0<<endl;
	else
		cout<<c-t<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

long long mod_pow(long long x, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int n, m;
string s;

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

    std::cout << mod_pow(m, n, MOD) << '\n';

    return 0;
}



Measured memory_bytes: 3152
n = int(input())
arr = [input() for i in range(n)]
listarr = [[arr[i][j] for j in range(10)] for i in range(n)]
for i in range(n):
    listarr[i].sort()
tuplearrsort = [tuple(listarr[i]) for i in range(n)]
dic = {}

for i in range(n):
    if tuplearrsort[i] in dic:
        dic[tuplearrsort[i]] += 1
    else:
        dic[tuplearrsort[i]] = 1
      
count = 0
for key in dic:
    count += (dic[key] * (dic[key]-1)) // 2
    
print(count)

Measured memory_bytes: 54284
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

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

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

    cout << (N - 2) * 180 << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

const int INF=500001;

ll f(ll n){
    return n*(n+1)/2;
}

int main(){
    string s;
    cin>>s;
    ll n,b0=0,b1=0;
    ll sum=0;
    n=s.size();
    rep(i,n-1){
        if(s[i]=='<'&&s[i+1]=='<'){
            b0++;
            continue;
        }else if(s[i]=='<'&&s[i+1]=='>'){
            b0++;
            continue;
        }else if(s[i]=='>'&&s[i+1]=='>'){
            b1++;
            continue;
        }else if(s[i]=='>'&&s[i+1]=='<'){
            b1++;
            sum+=f(max(b0,b1))+f(min(b0,b1)-1);
            b0=0;
            b1=0;
            continue;
        }
    }
    if(s[n-1]=='>'){
        b1++;
        sum+=f(max(b0,b1))+f(min(b0,b1)-1);
        b1=0;
        b0=0;
    }else if(s[n-1]=='<') b0++;
    sum+=f(b0);
    cout<<sum;
}

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

int main() {
  string str = "";
  int moziNum;
  int a;
  cin >> moziNum >> a;
  
  vector<string> vec(moziNum);
  
  for(int i = 0; i < moziNum; i++ ){
   cin >> vec.at(i); 
  }
  
  // 昇順でソート
  sort(vec.begin(), vec.end());
  
  for(int i = 0; i < moziNum; i++){
    str += vec.at(i);
  }
  
  cout << str;
}


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

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(s*t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int hantei(int,int,int,int *);

int main()
{
  int n,i,A[20],q,m;

  scanf("%d",&n);
  if(n>20) exit(1);
  for(i=0;i<n;i++){
    scanf(" %d",&A[i]);
    if(A[i]<1 || A[i]>2000) exit(2);
  }
  
  scanf("%d",&q);
  if(q>200) exit(3);
  for(i=0;i<q;i++){
    scanf(" %d",&m);
    if(m<1 || m>2000) exit(4);
    if(hantei(n,0,m,&A[0])) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int hantei(int n,int i,int m,int *A) //mからAの要素をひいていく
{
  int num1,num2;
  
  if(m==0) return 1;
  if(i>=n) return 0;
  
  if(m>0){
    num1 = hantei(n,i+1,m,&A[0]); //mから引かない場合
    if(num1) return 1;
    num2 = hantei(n,i+1,m-A[i],&A[0]); //mから引く場合
    //printf("確認 num1:%d,num2:%d\n",num1,num2);
    if(num2) return 1;
  }

  return num1;
  
}



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

int main(void)
{
    ll n;
    cin >> n;
    int ans = 0;
    int mx = 0;
    rep(i, 0, n)
    {
        int tmp;
        cin >> tmp;
        mx = max(mx, tmp);
        ans += tmp;
    }
    cout << ans - mx / 2 << endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>

#define DEBUG

#ifdef DEBUG

#define printd printf

#else

#define printd(...)

#endif

int main() {
    int h, w;
    std::cin >> h >> w;

    int costs[10][10];
    int a[h][w];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            std::cin >> costs[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> a[i][j];
        }
    }

    // calculate the minimum costs to change a number to another
    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                costs[i][j] = std::min(costs[i][j], costs[i][k] + costs[k][j]);
            }
        }
    }
    // calculate sums
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == -1) {
                continue;
            }
            ans += costs[a[i][j]][1];
        }
    }
    std::cout << ans << std::endl;
    
    return 0;
}

Measured memory_bytes: 384