akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct Edge {
	int from, to, flow, rev;
	Edge() {}
	Edge(int from, int to, int flow, int rev) {
		this->from = from;
		this->to = to;
		this->flow = flow;
		this->rev = rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

const int VMAX = 100;

void add_edge(Graph &g, int s, int t, int flow) {
	g[s].push_back(Edge(s, t, flow, g[t].size()));
	g[t].push_back(Edge(t, s, 0, g[s].size() - 1));
}

int dfs(Graph &g, int s, int t, int level[], int seenEdgeCount[], int flow) {
	if (s == t) return flow;
	
	for (int &i = seenEdgeCount[s]; i < g[s].size(); i++) {
		int nv = g[s][i].to;
		if (level[nv] != level[s] + 1 || g[s][i].flow <= 0) continue;	//辺残量も確認する！
		int f = dfs(g, nv, t, level, seenEdgeCount, min(flow, g[s][i].flow));
		if (f <= 0) continue;
		//s --> nv間にfだけ流す
		g[s][i].flow -= f;
		g[nv][g[s][i].rev].flow += f;
		return f;
	}
	return 0;
}

int maxflow(Graph g, int s, int t) {
	int i, level[VMAX], ret = 0;

	while (true) {
		for (i = 0; i < g.size(); i++) level[i] = -1;
		queue<int> que;
		
		level[s] = 0;
		que.push(s);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (i = 0; i < g[v].size(); i++) {
				if (g[v][i].flow <= 0) continue;
				int nv = g[v][i].to;
				if (level[nv] == -1) {
					level[nv] = level[v] + 1;
					que.push(nv);
				}
			}
		}
		if (level[t] == -1) break;
		
		int seenEdgeCount[VMAX] = {0};
		
		int flowINF = 1e+9;	//辺容量の最大値よりも大きな値にする
		
		while (true) {
			int f = dfs(g, s, t, level, seenEdgeCount, flowINF);
			if (f <= 0) break;
			ret += f;
		}
	}
	return ret;
}

int n, m;
Graph g;

int main() {
	int i;
	
	cin >> n >> m;
	g.resize(n);
	for (i = 0; i < m; i++) {
		int u, v, f;
		cin >> u >> v >> f;
		add_edge(g, u, v, f);
	}
	cout << maxflow(g, 0, n - 1) << endl;
	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
		return 0;
	}
}

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

type Point = (i32, i32);

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn dist(a: Point, b: Point) -> f64 {
   let ret: f64 = ((a.0 - b.0) * (a.0 - b.0) + (a.1 - b.1) * (a.1 - b.1)) as f64;
   ret.sqrt()
}

fn main() {
    let n: i32 = input();
    let mut places: Vec<Point> = Vec::new();
    for _ in 0..n {
        let place = input_int_tuple();
        places.push(place);
    }

    let mut sum_distance = 0f64;
    for i in 0..n {
        for j in 0..n {
            if i == j {
                continue;                
            }
            sum_distance += dist(places[i as usize], places[j as usize]);
        }
    }
    println!("{}", sum_distance / n as f64);

}


Measured memory_bytes: 4352
n, m, k = list(map(int, input().split()))

max_len = n+10  # 適宜変更する
mod = 998244353


def modinv(x):
    '''
    xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
    Python標準のpowは割った余りを出すことも可能。
    '''
    return pow(x, mod-2, mod)


# 二項係数の左側の数字の最大値を max_len　とする。nとかだと他の変数と被りそうなので。
# factori_table = [1, 1, 2, 6, 24, 120, ...] 要は factori_table[n] = n!
# 計算時間はO(max_len * log(mod))
modinv_table = [-1] * (max_len + 1)
modinv_table[0] = None  # 万が一使っていたときにできるだけ早期に原因特定できるようにしたいので、Noneにしておく。
factori_table = [1] * (max_len + 1)
factori_inv_table = [1] * (max_len + 1)
for i in range(1, max_len + 1):
    factori_table[i] = factori_table[i-1] * (i) % mod

modinv_table[1] = 1
for i in range(2, max_len + 1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
    factori_inv_table[i] = factori_inv_table[i-1] * modinv_table[i] % mod


def binomial_coefficients(n, k):
    '''
    n! / (k! * (n-k)! )
    0 <= k <= nを満たさないときは変な値を返してしまうので、先にNoneを返すことにする。
    場合によっては0のほうが適切かもしれない。
    '''
    if not 0 <= k <= n:
        return None
    return (factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]) % mod


def binomial_coefficients2(n, k):
    '''
    (n * (n-1) * ... * (n-k+1)) / (1 * 2 * ... * k)
    '''
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans


mod = 998244353

ans = 0
for next_same in range(0, k+1):
    ans += binomial_coefficients(n-1, next_same) * m * pow(m-1, n-next_same-1, mod)
    ans %= mod

print(ans)


Measured memory_bytes: 32680
N = int(input())
A = tuple(map(int, input().split()))

ans = 0
dic = {}
for i in range(N):
    ans += dic.get(i - A[i], 0)
    dic[i + A[i]] = dic.get(i + A[i], 0) + 1
    # for j in range(i+1, N):
    #     if i - A[i] == j + A[j]:
    #     # if i - j == A[i] + A[j]:
    #         ans += 1

print(ans)

Measured memory_bytes: 40268
n = int(input())
xy = []
for i in range(n):
    a = int(input())
    s = []
    for j in range(a):
        x, y = map(int, input().split())
        s.append([x, y])
    xy.append(s)

ans = 0
for bit in range(1, 2**n):
    flg = True
    # i人目の証言を検証する
    for i in range(n):
        if not flg:
            break

        # i人目が不親切の場合は検証する意味なし
        if not (bit >> i & 1):
            continue

        # i人目の各証言を確認
        for j in xy[i]:
            x = j[0]
            y = j[1]

            # 証言と矛盾していたらダメ
            if (bit >> (x - 1) & 1) ^ y:
                flg = False
                break
    if flg:
        ans = max(ans, bin(bit).count('1'))

print(ans)


Measured memory_bytes: 3188
n = int(input())

R = [0]*n

ans = -float('inf')
#今見てるとこ以前の最小値
minimum = float('inf')
for i in range(n):
    R[i] = int(input())
    if i == 0:
        minimum = R[i]
        continue
    minimum = min(minimum, R[i-1])
    ans = max(ans, R[i] - minimum)
    
print(ans)


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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll N, K;
vector<ll> A, F;


int main(int argc, char **argv)
{
	cin >> N >> K;
	A.resize(N);
	F.resize(N);
	REP(i, N) cin >> A[i];
	REP(i, N) cin >> F[i];

	sort(ALL(A));
	sort(ALL(F), greater<ll>());

	auto isok =
		[&](ll x) -> bool
		{
			ll cnt{0};
			REP(i, N)
			{
				ll tmp = x / F[i];
				cnt += max(0ll, A[i]-tmp);
			}
			return cnt<=K;
		};

	ll ok{(ll)1e13+1};
	ll ng{-1};
	while (abs(ok-ng) > 1)
	{
		ll mid = (ng + ok) >> 1;
		if (isok(mid)) ok = mid;
		else ng = mid;
	}
	std::cout << ok << std::endl;
}


Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int[] A1 = new int [3];
		int[] A2 = new int [3];
		int[] A3 = new int [3];
		
		A1[0] = sc.nextInt();
		A1[1] = sc.nextInt();
		A1[2] = sc.nextInt();
		
		A2[0] = sc.nextInt();
		A2[1] = sc.nextInt();
		A2[2] = sc.nextInt();
		
		A3[0] = sc.nextInt();
		A3[1] = sc.nextInt();
		A3[2] = sc.nextInt();
		
		int N = sc.nextInt();
		ArrayList<Integer> nums = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			nums.add(sc.nextInt());
		}

		for(int i = 0; i < N; i++) {
			for(int j = 0; j < 3; j++) {
				if(nums.get(i) == A1[j]) {
					A1[j] = -1;
				}
				if(nums.get(i) == A2[j]) {
					A2[j] = -1;
				}
				if(nums.get(i) == A3[j]) {
					A3[j] = -1;
				}
			}
		}

		boolean ans = false;
		
		if(A1[0]==-1 && A1[1]==-1 && A2[2]==-1) {
			ans = true;
		}
		if(A2[0]==-1 && A2[1]==-1 && A2[2]==-1) {
			ans = true;
		}
		if(A3[0]==-1 && A3[1]==-1 && A3[2]==-1) {
			ans = true;
		}
		
		if(A1[0]==-1 && A2[0]==-1 && A3[0]==-1) {
			ans = true;
		}
		if(A1[1]==-1 && A2[1]==-1 && A3[1]==-1) {
			ans = true;
		}
		if(A1[2]==-1 && A2[2]==-1 && A3[2]==-1) {
			ans = true;
		}
		
		if(A1[0]==-1 && A2[1]==-1 && A3[2]==-1) {
			ans = true;
		}
		if(A1[2]==-1 && A2[1]==-1 && A3[0]==-1) {
			ans = true;
		}
		
		if(ans) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		sc.close();
	}
	
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{  int n,d;
double p,q;
   int sum=0,i;
cin>>n;
cin>>d;
for(i=0;i<n;i++)
{
    cin>>p;
    cin>>q;
    p=pow(p,2);
    q=pow(q,2);
    p=sqrt(p+q);
    if(p<=d)
    sum++;
}
cout<<sum;
}

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

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int arr[] = new int[N+1];
    int srt[] = new int[N+1];
    for(int i = 1; i<=N; i++){
      arr[i] = sc.nextInt();
      srt[i] = arr[i];
    }
    Arrays.sort(srt);
    for(int i = 1; i<=N; i++){
      if(arr[i] >= srt[N/2+1]){
        System.out.println(srt[N/2]); 
      }
      else{
        System.out.println(srt[N/2+1]); 
      }
    }
  }
}

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

using namespace std;

#define int int64_t

signed main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum1 = 0, sum2 = 0;
    for(int i = 0; i < n; i++) {
        cin >> b[i];
        c[i] = b[i] - a[i];
        sum1 += max(c[i], (int)0) / 2;
        sum2 += min(c[i], (int)0);
    }
    
    cout << ((sum1 + sum2 >= 0) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;

int main(){
	string s;
	cin >> s;
	bool f= true;
	for(int i=1;i<s.size();++i){
		if(s[i-1] == 'A' && s[i] == 'C'){
			cout << "Yes" << endl;
			f = false;
			break;
		} 
	}
	
	if(f) cout << "No" << endl;

	
	return 0;


}



Measured memory_bytes: 256
def main():
  n = int(input())
  v = input_list()
  evens = []
  odds = []
  vs = v[:]
  kind = len(set(vs))
  if kind == 1:
    print(n//2)
    exit(0)
  
  for i, vv in enumerate(v):
    if i % 2 == 0:
      evens.append(vv)
    else:
      odds.append(vv)
  ec = collections.Counter(evens)
  oc = collections.Counter(odds)
  m = n//2
  
  ans = 0
  em = ec.most_common()
  om = oc.most_common()
  if em[0][0] == om[0][0]:
    p1 = m-em[0][1] + m-om[1][1]
    p2 = m-em[1][1] + m-om[0][1]
    print(min(p1,p2))
  else:
    print(m-em[0][1] + m-om[0][1])
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

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

int main() {
  int A, B, a, b;
  cin >> A >>B ;
  a= A%2;
  b= B%2;
  if(a*b ==0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
}

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

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

constexpr int INF = (1 << 30) - 1;
constexpr int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
constexpr int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

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

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

	int minv = S.size();

	for ( int i = 0; i < S.size() - 1; i++ ) {
		if ( S[i] != S[i + 1] ) {
			minv = min(minv, max(i + 1, (int)S.size() - i - 1));
		}
	}

	cout << minv << endl;

	return ( 0 );
}


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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> A[i][j];

  int N;
  cin >> N;

  int b = 0;
  rep(i, N) {
    cin >> b;
    rep(i, 3) {
      rep(j, 3) {
        if (A[i][j] == b) A[i][j] = 0;
        if (
            // 横
            (A[0][0] == 0 && A[0][1] == 0 && A[0][2] == 0) ||
            (A[1][0] == 0 && A[1][1] == 0 && A[1][2] == 0) ||
            (A[2][0] == 0 && A[2][1] == 0 && A[2][2] == 0) ||
            // 縦
            (A[0][0] == 0 && A[1][0] == 0 && A[2][0] == 0) ||
            (A[0][1] == 0 && A[1][1] == 0 && A[2][1] == 0) ||
            (A[0][2] == 0 && A[1][2] == 0 && A[2][2] == 0) ||
            // 斜め
            (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) ||
            (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0)) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

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

Measured memory_bytes: 3608
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

A = [read_int() for _ in range(3)]
N = read_int()[0]
B = [read_int()[0] for _ in range(N)]

# card = [[0 for j in range(3)] for i in range(3)]
bingo = [[0, 1, 2],[3,4,5], [6,7,8], [0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
def solve():
    for b in B:
        for row in A:
            pos = ind_or_f(row, b)
            if pos != -1:
                row[pos] = -1
                break
    for bb in bingo:
        flag = True
        for b in bb:
            if A[b // 3][b % 3] != -1:
                flag = False
            if not flag:
                break
        if flag == True:
            return "Yes"
    return "No"

def ind_or_f(l, x, default=-1):
    return l.index(x) if x in l else default

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3760
N, M = map(int, input().split())
A = map(int, input().split())
card = {}
for a in A:
    if a not in card:
        card[a] = 1
    else:
        card[a] += 1

for i in range(M):
    Bi, Ci = map(int, input().split())
    if Ci not in card:
        card[Ci] = Bi
    else:
        card[Ci] += Bi

total = 0
count = 0
for num in sorted(card.keys(), reverse=True):
    if count + card[num] <= N:
        count += card[num]
        total += num * card[num]
    else:
        added = N - count
        count += added
        total += added * num
        break
print(total)

Measured memory_bytes: 86296
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int, int>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	ll n;
	cin >> n;
	string ans="";
    
    while(n){
        int rem=n%26;
        if(rem){
            char c=rem-1+'a';
            string s;
            s.push_back(c);
            ans.insert(0,s);
            n=n/26;
        }
        else{
            ans.insert(0,"z");
            n=n/26-1;
        }
    }
    cout << ans;

}	

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

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;




	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int[] d = {a,b,c};
		Arrays.sort(d);
		int ans = d[2]*10+d[1]+d[0];
		System.out.println(ans);
		
	}
}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 21716
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

int n, l[mxn], r[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
    }
    sort(r, r+n), sort(l, l+n);//bug(l, r);

    ll ans = 0;
    for (int cur = 0, ri = 0, li = n-1, i = 1; i<=n; i++) {
        if (i&1) {
            ans += max(0, l[li]-cur);
            if (l[li]-cur > 0) cur = l[li--];
        } else {
            ans += max(0, cur-r[ri]);
            if (cur-r[ri] > 0) cur = r[ri++];
        }
        if (i == n) ans += abs(cur);//bug(i, ans);
    }
    ll ans2 = 0;
    for (int cur = 0, ri = 0, li = n-1, i = 1; i<=n; i++) {
        if (i&1) {
            ans2 += max(0, cur-r[ri]);
            if (cur-r[ri] > 0) cur = r[ri++];
        } else {
            ans2 += max(0, l[li]-cur);
            if (l[li]-cur > 0) cur = l[li--];
        }
        if (i == n) ans2 += abs(cur);//bug(i, ans2);
    }
    cout << max(ans, ans2) << '\n';
}

Measured memory_bytes: 1024
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<Vec<usize>> = (0..n)
        .map(|_| (1..n).map(|_| sc.read::<usize>() - 1).collect())
        .collect();
    let mut pos = vec![0; n];
    let mut que = std::collections::VecDeque::new();

    for i in 0..n {
        let j = a[i][0];
        if a[j][0] == i && i < j {
            que.push_back((i, j, 1));
        }
    }
    let mut result = 0;
    while let Some((i, j, time)) = que.pop_front() {
        result = std::cmp::max(result, time);
        pos[i] += 1;
        if pos[i] < n - 1 {
            let j = a[i][pos[i]];
            if a[j][pos[j]] == i {
                que.push_back((i, j, time + 1));
            }
        }
        pos[j] += 1;
        if pos[j] < n - 1 {
            let i = a[j][pos[j]];
            if a[i][pos[i]] == j {
                que.push_back((i, j, time + 1));
            }
        }
    }
    if pos.into_iter().all(|x| x == n - 1) {
        println!("{}", result);
    } else {
        println!("{}", -1);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(){
  int a;
  cin >> a;
  int max = 0;
  int min = 1000000000;
  for(int i = 0;i < a;i++){
    int b;
    cin >> b;
    if(b < min){
      min = b;
    }
    if(b > max){
      max = b;
    }
  }
  cout << max - min << endl;
}


Measured memory_bytes: 256
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn gcd(x: i32, y: i32) -> i32 {
    if x == 0 {
        y
    }
    else if y == 0 {
        x
    }
    else {
        if x > y {
            gcd(y, x % y)
        }
        else {
            gcd(x, y % x)
        }
    }
}

fn main() {
    from_line!(x: i32, y: i32);
    println!("{}", gcd(x, y));
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a,b;
  cin>>n>>a>>b;
  int xx = min(a, b);
  int yy = a + b - n > 0 ? a + b - n : 0;
  cout<<xx<<" "<<yy<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 5e5 + 10;
int N;
LL A[500], S, X, D, ANS;
int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", &A[i]);
        if (i <= 2)
            S += A[i];
        else
            X ^= A[i];
    }
    if (S - X < 0 || (S - X) % 2 != 0)
    {
        printf("-1\n");
        return 0;
    }
    else
        D = (S - X) / 2;
    LL ANS = D;
    for (int i = 60; i >= 0; i--)
    {
        int x = ((X >> i) & 1LL), d = ((D >> i) & 1LL);
        if (d && x)
        {
            printf("-1\n");
            return 0;
        }
        if (!d && x && (ANS | (1LL << i)) <= A[1])
            ANS |= (1LL << i);
    }
    if (ANS == 0 || ANS > A[1])
        printf("-1\n");
    else
        printf("%lld\n", A[1] - ANS);
    return 0;
}

Measured memory_bytes: 3768
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.range;

void main() {
  string s = readln.strip;

  long cnt = 0;
  char[] last = new char[](10000); 
  long p = -1;
  for (long i = 0; i < s.length; i++) {
    if (i+1 < s.length && s[i] != s[i+1]) {
      cnt += 2;
      i++;
    } else {
      if (p >= 0 && last[p] != s[i]) {
        cnt += 2;
        p--;
      } else {
        p++;
        last[p] = s[i];
      }
    }
  }
  writeln(cnt);
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;


void solve()
{
    int n, k; cin >> n >> k;
    cout << (int)pow(k-1, n-1) * k << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
N = int(input())
list_A = []
for _ in range(N):
    A = int(input())
    list_A.append(A)
    
sorted_list = sorted(list_A)
A = sorted_list[len(sorted_list)-1]
B = sorted_list[len(sorted_list)-2]

for i in range(N):        
    if list_A[i] == A:
      print(B)
    else:
      print(A)

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

int main() {
  string s;
  cin >>s;
  sort(s.begin(),s.end());
  if(s[0]=='a'&&s[1]=='b'&&s[2]=='c'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
// Vivek Rai
// Blazer_007

#include<bits/stdc++.h>
using namespace std;

#define fastio    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl      '\n'

typedef long long int ll;
const int hell = 1e9 + 7 ;

signed main() {

    fastio

    string t;
    cin >> t;

    for( int i = 0 ; i < t.length() ; i++ ) {
        if( t[i] == '?' && t[i+1] == '?' && i+1 < t.length() ) {
            if( i-1 >= 0 && t[i-1] == 'P') {
                t[i] = 'D';
                t[i+1] = 'D';
            } else {
                t[i] = 'P';
                t[i+1] = 'D';
            }
            
        }
        else if( t[i] == '?' && t[i-1] == 'P' && i-1 > 0 ) 
            t[i] = 'D';
        else if( t[i] == '?' && t[i+1] == 'D' && i+1 < t.length() )
            t[i] = 'P';
        else if( t[i] == '?' )
            t[i] = 'D';
    } 
    cout << t << endl;

    return 0;
}

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

int main(){
  
  string c;
  cin >> c;
  
  string s[5] = {"a","e","u","i","o"};
 
  if(c == s[0]) cout <<"vowel\n";
  else if(c == s[1]) cout <<"vowel\n";
  else if(c == s[2]) cout <<"vowel\n";
  else if(c == s[3]) cout <<"vowel\n";
  else if(c == s[4]) cout <<"vowel\n";
  else cout <<"consonant\n";
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  cin>>a>>b>>c;
  if((a-b)==b-c)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;

}


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

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var n = h[0];
		var a = read().GroupBy(x => "/255456376"[x] - '0').OrderBy(g => g.Key).ToDictionary(g => g.Key, g => g.Max());

		var dp = new string[50];
		for (int i = 0; i < dp.Length; i++)
		{
			var cs = a.Keys.Where(x => x <= i && dp[i - x] != null).ToArray();
			dp[i] = cs.Any() ? cs.Select(c => string.Join("", (dp[i - c] + a[c]).OrderByDescending(x => x))).OrderBy(x => x.Length).ThenBy(x => x).Last() : a.Keys.Contains(i) ? a[i].ToString() : null;
		}

		if (n < dp.Length) Console.WriteLine(dp[n]);
		else
		{
			var c0 = a.Keys.First();
			var k = (n - dp.Length + c0) / c0;
			var t = dp[n - k * c0];
			var cd = a[c0].ToString()[0];
			Console.WriteLine(t.Insert(t.IndexOf(cd), new string(cd, k)));
		}
	}
}


Measured memory_bytes: 14164
local mmi, mma = math.min, math.max
local n, wtot = io.read("*n", "*n")
local w, v = {}, {}
w[1], v[1] = io.read("*n", "*n")
local woffset = w[1] - 1
w[1] = 1
for i = 2, n do
  local a, b = io.read("*n", "*n")
  w[i], v[i] = a - woffset, b
end
local dp = {}
for i = 1, n + 1 do
  dp[i] = {}
  for j = 1, 4 * n do
    dp[i][j] = 0
  end
end
for i = 1, n do
  for j = i, 1, -1 do
    for k = 4 * (i - 1), 1, -1 do
      dp[j + 1][k + w[i]] = mma(dp[j + 1][k + w[i]], dp[j][k] + v[i])
    end
    dp[j + 1][w[i]] = mma(dp[j + 1][w[i]], v[i])
  end
end
local ret = 0
for i = 2, n + 1 do
  local offset = woffset * (i - 1)
  for j = 1, (i - 1) * 4 do
    if offset + j <= wtot then
      ret = mma(ret, dp[i][j])
    end
  end
end
print(ret)


Measured memory_bytes: 1144
#include <algorithm>
#include <iostream>
#include <string>

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

  std::string blocks[4] = {"dream", "dreamer", "erase", "eraser"};
  for (auto &&b : blocks) {
    std::reverse(b.begin(), b.end());
  }

  std::reverse(S.begin(), S.end());

  std::size_t i = 0, i_old = 0;
  while (true) {
    for (auto &&b : blocks) {
      if (S.substr(i, b.length()) != b) continue;
      i += b.length();
    }
    if (i == i_old) break;
    i_old = i;
  }

  std::cout << ((i == S.length()) ? "YES" : "NO") << std::endl;

  return 0;
}

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

ll N, M;
vector<ll> E[200000], R[200000];

ll parent[200000];
set<ll> st;

void dfs(ll v, ll p) {
  bool ok = true;
  for (ll u : R[v]) {
    if (!st.count(u)) {
      ok = false;
    }
  }
  if (!ok) return;

  parent[v] = p;
  st.insert(v);

  for (ll u : E[v]) {
    dfs(u, v);
  }

  st.erase(v);
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, N + M - 1) {
    ll A, B;
    cin >> A >> B, A--, B--;
    E[A].push_back(B);
    R[B].push_back(A);
  }

  ll root;
  REP(i, 0, N) if (R[i].size() == 0) root = i;

  dfs(root, -1);

  REP(i, 0, N) {
    cout << parent[i] + 1 << endl;
  }
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<int> h(n);
    for (auto &x: h) cin >> x;
    vector<vector<int>> e(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    int ans = 0;
    auto f = [&](int c) {
        bool ok = true;
        for (auto &to: e[c]) {
            if (h[c] <= h[to]) ok = false;
        }
        ans += ok;
    };
    for (int i = 0; i < n; i++) f(i);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8744
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;
 
lli power(lli a, lli b, lli M = mod)
{
	lli result = 1;
    for (;;)
    {
        if (b & 1)
            result = (result*a);
        b >>= 1;
        if (!b)
            break;
        a = (a*a);
    }
    return result;
}
int main()
{
	IOS;
	lli n;
	cin>>n;
	map<lli,lli> m;
	lli ans = 1;
	for(lli i = 2; (i*i)<n; i++)
	{
		if((n-1)%i == 0)
		{
			if(m.find(i) == m.end())
			ans++, m[i] = 1;
			lli temp = (n-1)/i;
			if(m.find(temp) == m.end())
			ans++, m[temp] = 1;
		}
	}
	if(n != 2)
	ans++;
	for(lli i = 2; i<=sqrt(n); i++)
	{
		if(n%i == 0)
		{
			lli temp = n;
			while(temp%i == 0)
			temp/=i;
			if(temp%i == 1 and (m.find(i) == m.end()))
			ans++, m[i] = 1;

			if(i != (n/i))
			{
				lli temp = n;
				lli l = n/i;
				while(temp%l == 0)
				temp/=l;
				if(temp%l == 1 and (m.find(l) == m.end()))
				ans++, m[l] = 1;
				
			}
		}
	
	}
	cout<<ans<<endl;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string S; cin >> S;
  ll N = S.size();
  set<string> s;
  for (ll i = 0; i < N; i++) {
    string t = "";
    for (ll j = 0; j < 5; j++) {
      if (i+j<N) {
        t = t+S[i+j];
        s.insert(t);
      }
    }
  }
  vector<string> v;
  for (auto it = s.begin(); it != s.end(); it++) {
    v.push_back(*it);
  }
  sort(v.begin(), v.end());
  ll K; cin >> K;
  cout << v[K-1] << endl;
}

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

#define int long long
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a;
map<int,int> m;

signed main() {
    cin >> n;
    rep(i,n) cin >> a,m[a]++;
    if (m.size()==1) {
        auto itr = m.begin();
        if (itr->fi == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else if (m.size()==2) {
        auto itr = m.begin();
        if (itr->fi == 0 && itr->se*2 == (++itr)->se) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else if (m.size() == 3) {
        auto itr = m.begin();
        int a,b,c,d;
        a = itr->se;d = itr->fi;++itr;
        b = itr->se;d ^= itr->fi;++itr;
        c = itr->se;d ^= itr->fi;
        if ((a == b) && (b == c) && !d) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else cout << "No" << endl;
}







Measured memory_bytes: 5120
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=900000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[110];
int n;
int dp[110000];
int solve(int a){
	if(~dp[a])return dp[a];
	for(int i=0;i<n;i++){
		if(a<p[i])continue;
		if(solve(a-p[i])==0)return dp[a]=1;
	}
	return dp[a]=0;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);n=a;
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	for(int i=0;i<110000;i++)dp[i]=-1;
	int ret=solve(b);
	if(ret==1)printf("First\n");
	else printf("Second\n");
}

Measured memory_bytes: 3712
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static ArrayList<Integer[]> list=new ArrayList<>();
static ArrayList<Integer[]> set=new ArrayList<>();


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

   String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();
 
 //   String[] s=sc.nextLine().split(" ");
//     String[] e=sc.nextLine().split(" ");

//int N=Integer.parseInt(nyuA);

int N=Integer.parseInt(nyuA);
//int K=Integer.parseInt(nyuB);



System.out.println((int)Math.sqrt(N)*(int)Math.sqrt(N));


	}

}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

template<int mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x(x%mod) {}
    mint(std::string s) {
        long long z = 0;
        REP(i, s.size()) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& n) {
        return os << n.x;
    }
    bool operator==(const mint a) const {
        return this->x == a.x;
    }
};

int bitpopcount(ll n) {
    int res = 0;
    while (n) {
        if (n & 1) {
            res++;
        }
        n >>= 1;
    }
    return res;
}

int main() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    // dp[i][j] : 男i人目まででの人数 j は使った女の集合
    vector<vector<mint<MOD>>> dp(n+1, vector<mint<MOD>>(1<<n,0));
    dp[0][0] = 1;
    REP(i, n) REP(j,n) cin >> a[i][j];
    REP(i, n) {
        REP(j, 1<<n) {
            if (bitpopcount(j) == i) {
                REP(k, n) {
                    if (((j & (1 << k)) == 0) && a[i][k]) {
                        dp[i + 1][j | (1 << k)] += dp[i][j];
                    }
                }
            }
        }
    }
    cout << dp[n][(1 << n) - 1] << endl;
    return 0;
}

Measured memory_bytes: 377216
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int n, a, b, c[200005];

signed main()
{
    cin >> c[0] >> c[1] >> c[2];
    sort(c, c + 3);

    //for(int i = 0; i < n; i++){}

    cout << c[2] * 10 + c[1] + c[0] << endl;



    return 0;
}
/*


*/


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    
    int cnt0=0,cnt1=0;
    rep(i,n){
        if(s.at(i)=='0') cnt0++;
        else cnt1++;
    }
    
    cout<<2*min(cnt0,cnt1)<<endl;
}


Measured memory_bytes: 512
import java.util.*;
class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int N = sc.nextInt();
        N %=10;
      	//for(int N=0;N<10;N++){
        if(N==3) System.out.println("bon");
        else if((N==0)||(N==1)||(N==6)||(N==8)) System.out.println("pon");
        else System.out.println("hon");
        //}
    }
}

Measured memory_bytes: 35756
import sys
dict_in={"AB":[0,1],"AC":[0,2],"BC":[1,2]}
dict_out={0:"A",1:"B",2:"C"}
n,a,b,c=map(int,input().split())
var=[a,b,c]
s=[dict_in[input()] for i in range(n)]
ans=[]
for i in range(n):
  if var[s[i][0]]>var[s[i][1]]:
    var[s[i][0]]-=1
    var[s[i][1]]+=1
    ans.append(dict_out[s[i][1]])
  elif var[s[i][0]]<var[s[i][1]]:
    var[s[i][0]]+=1
    var[s[i][1]]-=1
    ans.append(dict_out[s[i][0]])
  else:
    if var[s[i][0]]==0 and var[s[i][1]]==0:
      print("No")
      sys.exit()
    inc=s[i][1]
    for j in range(i+1,n):
      if not(s[i][0] in s[j]):
        inc=s[i][1]
        break
      elif not(s[i][1] in s[j]):
        inc=s[i][0]
        var[s[i][0]]+=1
        var[s[i][1]]-=1
        break
    if inc==s[i][1]:
      var[s[i][0]]-=1
      var[s[i][1]]+=1
    ans.append(dict_out[inc])
print("Yes")
for i in range(len(ans)):
  print(ans[i])

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

int main(){
  int a,b,c,d,max=0,flag=0;
  cin>> a>>b;
  for(int i=0;i<a;i++){
    cin>>c>>d;
    b+=c-d;
    if(b<0)flag=1;
    else if(b>max)max=b;
  }
  if(flag!=1)cout<<max<<endl;
  else cout<<"0"<<endl;
  return 0;
}

Measured memory_bytes: 1160
import numpy as np

num_of_candidate, start_point, num_of_questions = map(int, input().split())
# winner_list = [int(input()) for i in range(num_of_questions)]
if start_point > num_of_questions:
	for i in range(num_of_candidate):
		print("Yes")
	exit()


start_points = np.array([start_point for i in range(num_of_candidate)])

got_points = np.array([0 for i in range(num_of_candidate)])
for i in range(num_of_questions):
	winner_id = int(input())
	got_points[winner_id - 1] += 1

lost_points = np.array([num_of_questions for i in range(num_of_candidate)]) - got_points

result_points = start_points - lost_points

for i in range(num_of_candidate):
	if result_points[i] > 0:
		print("Yes")
	else:
		print("No")


Measured memory_bytes: 18348
N,A,B = map(int,input().split())
sum_all = 0

def digits_sum(n):
  n = str(n)
  n = list(n)
  for i in range(len(n)):
    n[i] = int(n[i])
  return sum(n)

for i in range(1,N+1):
  if(A<=digits_sum(i)<=B):
   sum_all += i

print(sum_all)
  

Measured memory_bytes: 3060
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	final static long MOD = 100000007;

	void solve() {
		int R = sc.nextInt();
		int C = sc.nextInt();
		int r1 = sc.nextInt();
		int c1 = sc.nextInt();
		int r2 = sc.nextInt();
		int c2 = sc.nextInt();

		int dr1 = Math.abs(r1 - r2);
		int dr2 = R - dr1;

		int dc1 = Math.abs(c1 - c2);
		int dc2 = C - dc1;
		long res = solve(Math.min(dr1, dr2), Math.min(dc1, dc2));
		if (dr1 == dr2) { res *= 2; res %= MOD; }
		if (dc1 == dc2) { res *= 2; res %= MOD; }
		out.println(res);
	}

	static final long[] fact = new long[1000 + 10];
	static final long[] fact_inv = new long[1000 + 10];
	static {
		long[] inv = new long[1000 + 10];
		inv[1] = fact[0] = fact_inv[0] = 1;
		for (int i = 2; i < inv.length; i++)
			inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
		for (int i = 1; i < fact.length; i++)
			fact[i] = (fact[i - 1] * i) % MOD;
		for (int i = 1; i < fact_inv.length; i++)
			fact_inv[i] = (fact_inv[i - 1] * inv[i]) % MOD;
	}

	long C(long n, long k) {
		if (n < 0 || k < 0 || n < k) return 0;
		return fact[(int) n] * fact_inv[(int) (n - k)] % MOD * fact_inv[(int) k] % MOD;
	}

	long solve(int r, int c) {
		return C(r + c, r);
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;

  vector<int> arr(n);

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

  int maxx = 0;
  int ans = 0;
  for (int x : arr) {
    maxx = max(maxx, x);
    ans += maxx - x;
  }
  cout << ans << endl;
}

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

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 4780