akhauriyash/Code-Regression huggingface dataset:
# Dinic's algorithm
#https://tjkendev.github.io/procon-library/python/max_flow/dinic.htmlより
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

N,M = map(int, input().split())
S = [list(input()) for i in range(N)]
dc = Dinic(N*M+2)
 
s =N*M
t = N*M+1
for i in range(N):
    for j in range(M):
        if (i+j) % 2 == 0:
            dc.add_edge(s,M*i+j,1)
        else:
            dc.add_edge(M*i+j,t,1)
 
for i in range(N):
    for j in range(M):
        if j+1 < M and S[i][j] == "." and S[i][j+1] == ".":
            u,v = M*i+j,M*i+j+1
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u, v, 1)
        if i+1 < N and S[i][j] == "." and S[i + 1][j] == ".":
            u,v = M*i+j, M*(i+1)+j
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)
 
print(dc.flow(s, t))
for u in range(N*M+2):
    for v, cap, _ in dc.G[u]:
        ui, uj = divmod(u, M)
        vi, vj = divmod(v, M)
        if (ui+uj) % 2 == 0 and cap == 0 and u != s and u != t and v != s and v!= t:
            if ui+1 == vi:
                S[ui][uj] = "v"
                S[vi][vj] = "^"
            elif ui == vi+1:
                S[ui][uj] = "^"
                S[vi][vj] = "v"
            elif uj+1 == vj:
                S[ui][uj] = ">"
                S[vi][vj] = "<"
            elif uj == vj+1:
                S[ui][uj] = "<"
                S[vi][vj] = ">"
 
for res in S:
    print("".join(res))

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

#ifdef LOCAL_PC
	#define debug(args...) { cout.flush(); fflush(stdout); fprintf(stderr, args); }
#else
	#define debug(args...) ; /*  */
#endif
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty rnd(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class num> inline void rd(num &x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	if (neg) x = -x;
} template <class T, class... Args> inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n, m; rd(n, m);
	vector<int> h(n+1);
	for (int i = 1; i <= n; i++) rd(h[i]);

	vector<vector<int>> edges(n+1);
	for (int i = 0; i < m; i++) {
		int u, v; rd(u, v);
		edges[u].pb(v);
		edges[v].pb(u);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		bool ok = true;
		for (int v : edges[i]) ok &= h[i] > h[v];
		ans += ok;
	}

	cout << ans << endl;
}



Measured memory_bytes: 8712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final long c = scanner.nextLong();

        final List<Sushi> naturalList = IntStream.range(0, n)
                .mapToObj(i -> new Sushi(scanner.nextLong(), scanner.nextInt()))
                .collect(Collectors.toList());

        final List<Sushi> reverseList = naturalList.stream()
                .map(sushi -> new Sushi(c - sushi.distance, sushi.value))
                .collect(Collectors.toList());

        long max = Math.max(calc(naturalList, reverseList, n), 0);

        Collections.reverse(naturalList);
        Collections.reverse(reverseList);

        max = Math.max(max, calc(reverseList, naturalList, n));
        System.out.println(max);
    }

    private static long calc(final List<Sushi> naturalList, final List<Sushi> reverseList, final int n) {
        final long[] array = new long[n];
        long sumValue = naturalList.get(0).value;
        array[0] = sumValue - naturalList.get(0).distance;
        for (int i = 1; i < n; i++) {
            sumValue += naturalList.get(i).value;
            final long distance = naturalList.get(i).distance;
            array[i] = Math.max(sumValue - distance, array[i - 1]);
        }

        long max = array[n - 1];
        sumValue = 0;
        for (int i = n - 1; i > 0; i--) {
            sumValue += reverseList.get(i).value;
            max = Math.max(max, array[i - 1] + sumValue - 2 * reverseList.get(i).distance);
        }
        return Math.max(max, sumValue + reverseList.get(0).value - reverseList.get(0).distance);
    }

    private static class Sushi {
        final long distance;
        final long value;

        Sushi(final long distance, final long value) {
            this.distance = distance;
            this.value = value;
        }
    }

    static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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


Measured memory_bytes: 51748
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
int main(){
	long double a,b,c;
	cin>>a>>b>>c;
	long double eps= 1.0E-14;
	cout<<(sqrt(a) +sqrt(b) +eps < sqrt(c) ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 256
C = [int(input()) for _ in range(5)]
ans = 0
tmp = []
for c in C:
    if c % 10 == 0:
        ans += c
    else:
        tmp.append(c)
tmp.sort()
t_max = 0
for t in tmp:
    t_max = max(t_max, 10 - (t % 10))
    ans += 10 - (t % 10) + t
print(ans-t_max)



Measured memory_bytes: 3060
///AtCoder Beginner Contest 141


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

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

  string str;
  cin>>str;

  if(str=="Sunny")
  {
      cout<<"Cloudy"<<"\n";
  }
  else if(str=="Cloudy")
  {
      cout<<"Rainy"<<"\n";
  }
  else if(str=="Rainy")
  {
      cout<<"Sunny"<<"\n";
  }


  return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  9 20:52:55 2020

@author: H_Hoshigi
"""

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

A_list.sort()
A_now = 0
answer = "YES"
for i in A_list:
    if i == A_now:
        answer = "NO"
        break
    else:
        A_now = i

print(answer)


Measured memory_bytes: 26808
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<string>
using namespace std;
#define INF 100000
int adj[31][31][31][31];
string l1,l2;
int mp[31][31];
int h,w;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int x,int y){
	return 0<=x&&x<h&&0<=y&&y<w;
}
int bfs(int x,int y){
	queue<pair<int ,pair<int,int> > > que;
	que.push(make_pair(0,make_pair(0,0)));
	mp[0][0]=0;
	while(!que.empty()){
		int d=que.front().first;
		int x=que.front().second.first;
		int y=que.front().second.second;
		que.pop();		
		for(int i=0;i<4;i++){
			int nx=dx[i]+x;
			int ny=dy[i]+y;

			if(!valid(nx,ny))continue;
			if(!adj[x][y][nx][ny])continue;

			if(mp[nx][ny]>mp[x][y]+1){
				mp[nx][ny]=mp[x][y]+1;
				que.push(make_pair(mp[nx][ny],make_pair(nx,ny)));
			}
		}
	}
	/*
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout<<mp[i][j];
		}
		cout<<endl;
	}
	*/
	return mp[h-1][w-1];
}
int main(){
	while(1){
		string str;		
		getline(cin,str);
		sscanf(str.c_str(),"%d%d",&w,&h);
		if(h*w==0)break;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)mp[i][j]=INF;
		fill_n((int *)adj,31*31*31*31,0);
		for(int i=0;i<h;i++){
			getline(cin,l1);
			if(i!=h-1)getline(cin,l2);
			for(int j=0;j<w-1;j++){
				if(l1[j*2+1]=='0'){
					adj[i][j][i][j+1]=1;
					adj[i][j+1][i][j]=1;				
				}		
			}
			if(i==h-1)break;	
			for(int j=0;j<w;j++){
				if(l2[j*2]=='0'){
					adj[i][j][i+1][j]=1;
					adj[i+1][j][i][j]=1;				
				}		
			}
		}
		int x;
		cout<<(((x=bfs(h-1,w-1))==INF)?0:x+1)<<endl;
	}	
}

Measured memory_bytes: 4868
#include<stdio.h>
#define MAX 110
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,time;
int dis[MAX],fin[MAX],color[MAX],num[MAX][MAX];
void dfs(void);
void visit(int);

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

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

void visit(int u){
  int v;
  color[u] = GRAY;
  dis[u] = ++time;
  for(v=1; v<=n; v++){
    if(num[u][v] == 1 && color[v] == WHITE) visit(v);
  }
  color[u] = BLACK;
  fin[u] = ++time;
}

void dfs(){
  int u;//for each vertex u in v. use in this part count "u" convenientry.
  for(u=1;u<=n;u++){
    color[u] = WHITE;
  }
    time = 0;
    for(u=1;u<=n;u++){
      if (color[u] == WHITE) visit(u);
    }
    for(u=1;u<=n;u++){
      printf("%d %d %d\n",u,dis[u],fin[u]);
    }
}


  



Measured memory_bytes: 2104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.*;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.sort;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 998244353;

    int[] a,b,c,d,x;
    int n,m,q;
    int ans = 0;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextInt();
        q = in.nextInt();
        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];
        x = new int[n];
        for (int i = 0; i < q; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
            c[i] = in.nextInt();
            d[i] = in.nextInt();
        }
        dfs(0, 1,0);
        out.println(ans);
    }

    private void dfs(int t, int v, int sum) {
        if (t == n) {
            ans = Math.max(ans, sum);
            return;
        }
        for (int i = v; i <= m; i++) {
            x[t] = i;
            int nsum = sum;
            for (int j = 0; j < q; j++) if (b[j] == t + 1 && x[t] - x[a[j] - 1] == c[j]) {
                nsum += d[j];
            }
            dfs(t + 1, i, nsum);
        }
    }

}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int a = (A+D-1) / D;
  int b = (C+B-1) / B;
  
  if(a>=b) cout << "Yes" << endl;
  else cout << "No" << endl;

}

  

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 60;
const int N = (int)1e6 + 7;
const int MAXN = (int)3e6 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

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

void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes";
			return;
		}
		a -= d;
		if (a <= 0) {
			cout << "No";
			return;
		}
	}
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

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

int main() {
  int sx, sy, tx, ty;
  cin>>sx>>sy>>tx>>ty;
  int x=tx-sx, y=ty-sy;
  for(int i=0; i<y; i++) {
    cout<<"U";
  }
  for(int i=0; i<x; i++) {
    cout<<"R";
  }
  for(int i=0; i<y; i++) {
    cout<<"D";
  }
  for(int i=0; i<=x; i++) {
    cout<<"L";
  }
  for(int i=0; i<=y; i++) {
    cout<<"U";
  }
  for(int i=0; i<=x; i++) {
    cout<<"R";
  }
  cout<<"D";
  cout<<"R";
  for(int i=0; i<=y; i++) {
    cout<<"D";
  }
  for(int i=0; i<=x; i++) {
    cout<<"L";
  }
  cout<<"U";
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <set>
#include <map>
#include <vector>
using namespace std;

map<int, map<int, int>> byrem;

const int N = 100500;
bool was[N];

int sum(map<int, int> M) {
    int s = 0;
    for (auto pr : M)
        s += pr.second;
    return s;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        byrem[x % m][x]++;
    }
    int ans = 0;
    for (int a = 0; a < m; a++) {
        int b = (m - a) % m;
        if (was[a] || was[b])
            continue;
        was[a] = was[b] = true;
        if (a != b) {
            auto A = byrem[a];
            auto B = byrem[b];
            set<int> eA, oA;
            set<int> eB, oB;
            for (auto pr : A) {
                ((pr.second % 2) ? oA : eA).insert(pr.first);
            }
            for (auto pr : B) {
                ((pr.second % 2) ? oB : eB).insert(pr.first);
            }
            while (oA.size() > 0 && oB.size() > 0) {
                int x = *oA.begin();
                int y = *oB.begin();
                assert(A.count(x));
                assert(B.count(y));
                A[x]--;
                B[y]--;
                oA.erase(oA.begin());
                oB.erase(oB.begin());
                eA.insert(x);
                eB.insert(y);
                ans++;
            }
            if (!oB.empty()) {
                A.swap(B);
                oA.swap(oB);
                eA.swap(eB);
            }
            int sB = sum(B);
            int sA = sum(A);
            if ((int)oA.size() <= sB) {
                ans += (sA + sB) / 2;
            } else {
                ans += (sA + sB - (oA.size() - sB)) / 2;
            }
        } else {
            int s = sum(byrem[a]);
            ans += s / 2;
        }
    }
    printf("%d\n", ans);

}


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

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Console.Read();
            if (b == 'A')
                Console.WriteLine("T");
            else if (b == 'T')
                Console.WriteLine("A");
            else if (b == 'C')
                Console.WriteLine("G");
            else
                Console.WriteLine("C");

#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


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

int main()

{
    int a, b, t;
    while(scanf("%d %d", &a, &b)!=EOF){
        a+=b;
        t=0;
        while(a!=0){
           a=a/10;
           t++;
        }
        printf("%d\n", t);

    }
    return 0;
}

Measured memory_bytes: 3124
A = int(input())
B = int(input())
C = int(input())
X = int(input())

can = []

for num_A in range(A + 1):
    for num_B in range(B + 1):
        for num_C in range(C + 1):
            num = 500 * num_A + 100 * num_B + 50 * num_C
            can.append(num)

print(can.count(X))

Measured memory_bytes: 8276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans=0;
  for(int i=0;i<4;i++){
    char x;
    cin>>x;
    if(x=='-'){
      ans--;
    }
    if(x=='+'){
      ans++;
    }
    
  }
  cout<<ans<<endl;
}



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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

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

int main()
{
    int n; cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    ll ans = a[0];
    rep(i,n){
        ans = gcd(ans,a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> p;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  sort(p.begin(), p.end());
  int sum=0;
  for(int i=0;i<K;i++){
    sum+=p[i];
  }
  cout << sum;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >>w;
    int ans = H*W - h*W - w * H + h*w;
    cout << ans << endl;
}


Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Coerce

main = do
  n <- readLn :: IO Int
  x0:xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let loop acc prev prevN (x:xs) | prev + 1 == x = let (x',xss) = span (== x) xs
                                                       m = length x' + 1
                                                   in loop (acc * prevN ^ m) x (fromIntegral m) xss
                                 | otherwise = 0
      loop acc _ _ [] = acc
  if x0 == 0 then
    print (loop 1 0 1 (sort xs) :: N)
  else
    print 0

--
-- Modular Arithmetic
--

modulo :: Int64
modulo = 998244353
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined

{-# RULES
"^9/Int" forall x. x ^ (9 :: Int) = let u = x; v = u * u * u in v * v * v
"^9/Integer" forall x. x ^ (9 :: Integer) = let u = x; v = u * u * u in v * v * v
 #-}

fromIntegral_Int64_N :: Int64 -> N
fromIntegral_Int64_N n | 0 <= n && n < modulo = N n
                       | otherwise = N (n `mod` modulo)

{-# RULES
"fromIntegral/Int->N" fromIntegral = fromIntegral_Int64_N . (fromIntegral :: Int -> Int64)
"fromIntegral/Int64->N" fromIntegral = fromIntegral_Int64_N
 #-}


Measured memory_bytes: 25980
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    if(a > b) swap(a,b);
    int diff = b - a;
    if(diff % 2 == 0) {
        cout << a + diff / 2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N, H, W;
  cin >> N >> H >> W;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  int ans = 0;
  rep(i, N) {
    if (A[i] >= H && B[i] >= W)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define alphanso                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
int main()
{
    int n, i, ans=0; cin>>n;
    int v[n], c[n];
    for(i=0; i<n; i++) cin>>v[i];
    for(i=0; i<n; i++) cin>>c[i];
    for(i=0; i<n; i++){
        if(v[i]>=c[i])
            ans+=(v[i]-c[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#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++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y; cin>>x>>y;
    ll ans=0;
    if (x==1) ans+=300000;
    if (x==2) ans+=200000;
    if (x==3) ans+=100000;
    if (y==1) ans+=300000;
    if (y==2) ans+=200000;
    if (y==3) ans+=100000;
    if (x==1 && y==1) ans+=400000;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
			int[] Count = new int[29];
	        String str;
			while( null != ( str = kb.readLine() ) ) {
	            int len = str.length();
	            if( null == str || 0 == len ) { break; }
	            char c;
	       		for( int i=0; i<len; i++ ) {
	       			c = Character.toUpperCase( str.charAt( i ) );
	       			if(  'A' <= c && c <= 'Z' ) {
	       				Count[ c - 'A' ]++;
	       			}
	       		}
       		}
       		for( int i=0; i<26; i++ ) {
				System.out.printf( "%c : %d\n", ('a'+i ), Count[ i ] );
       		}
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 17080
from enum import Enum
from queue import Queue

import numpy as np

import collections
import bisect
import sys
import math

from scipy.sparse.csgraph import floyd_warshall

BIG_NUM = 200000000000
MOD = 1000000007
EPS = 0.000000001

def warshall_floyd(d,n):
    #d[i][j]:iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

N,M,L = map(int,input().split())
d = [[float("inf") for i in range(N)] for j in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
for i in range(N):
    d[i][i] = 0
d = floyd_warshall(d)
for i in range(N):
    for j in range(i,N):
        if d[i][j] <= L:
            d[i][j] = 1
            d[j][i] = 1
        else:
            d[i][j] = float("inf")
            d[j][i] = float("inf")
    d[i][i] = 1
d = floyd_warshall(d)
Q = int(input())
for q in range(Q):
    s,t = map(int,input().split())
    if d[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(d[s-1][t-1])-1)


Measured memory_bytes: 22756
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
using namespace std;

int main()
{
    ll N;
    cin >> N;
    ll ans = 1;

    vector<ll> v(N);

    for (int i=0; i<N; i++) {
        cin >> v[i];
        if (v[i] == 0) {
            ans = 0;
            N = 0;
        }
    }

    for (int i=0; i<N; i++) {
        if (v[i] <= 1000000000000000000 / ans) {
            ans *= v[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 4060
#include <cstdio>
#include <vector>
using namespace std;
vector <int> v1[666017];
vector <long long> v[666017];
int n,i,x;
long long y,s,nr;
void u (long long y)
{
    int i,k;
    long long m;
    m=(1LL)*y%666013;
    if (m<0)
        m+=666013;
    k=v[m].size();
    k--;
    for (i=0;i<=k;i++)
    {
        if (v[m][i]==y)
        {
            nr=(0LL)+nr+v1[m][i];
            v1[m][i]++;
            return;
        }
    }
    v[m].push_back(y);
    v1[m].push_back(1);
    return;
}
int main()
{
    scanf ("%d", &n);
    v[0].push_back(0);
    v1[0].push_back(1);
    s=0LL;
    nr=0LL;
    for (i=1;i<=n;i++)
    {
        scanf ("%d", &x);
        s=(0LL)+s+x;
        u(s);
    }
    printf ("%lld\n", nr);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    cout << min(A, B) << " " << max(0, A+B-N) << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
n=len(l)
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[i]+l[j]>l[k]:
                ans+=1

print(ans)


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

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

    string s, t;
    cin >> s >> t;
    int n = int(s.size());
    int cnt = 0;

    for (int i = 0; i < n; ++i)
	cnt += s[i] != t[i];

    cout << cnt << "\n";
}


Measured memory_bytes: 3784
def main ():
	N = int(input())
	A = list(map(int,input(). split ()))
	if 0 in A:
		print(0)
		return
	prod = 1
	for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1)
			return
	print(prod)
main ()

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


void solve() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        uf.unionSet(x, y);
    }

    set<int> S;
    for (int i = 0; i < N; i++) {
        S.insert(uf.root(i));
    }

    cout << S.size() << endl;
    
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N,num_query;
vector<int> V;

int main(){

	scanf("%d",&N);

	int tmp;
	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	scanf("%d",&num_query);

	int L,R,mid;
	int left,right;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);

		L = 0,R = N-1,mid = (L+R)/2;
		left = N;

		while(L <= R){

			if(V[mid] >= tmp){

				left = mid;
				R = mid-1;
			}else{

				L = mid+1;
			}
			mid = (L+R)/2;
		}

		L = 0,R = N-1,mid = (L+R)/2;
		right = N;

		while(L <= R){

			if(V[mid] > tmp){

				right = mid;
				R = mid-1;
			}else{

				L = mid+1;
			}
			mid = (L+R)/2;
		}

		printf("%d %d\n",left,right);
	}

	return 0;
}



Measured memory_bytes: 3536
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;


const int MAX_SIZE = 1000010;
const long long MOD = 1000000007;

long long inv[MAX_SIZE];
long long fact[MAX_SIZE];
long long factinv[MAX_SIZE];

void init() {
  inv[1] = 1;
  for (int i=2; i<MAX_SIZE; i++) {
    inv[i] = ((MOD - inv[MOD%i]) * (MOD/i))%MOD;
  }
  fact[0] = factinv[0] = 1;
  for (int i=1; i<MAX_SIZE; i++) {
    fact[i] = (i * fact[i-1])%MOD;
    factinv[i] = (inv[i] * factinv[i-1])%MOD;
  }
}

long long C(int n, int k) {
  if (n >=0 && k >= 0 && n-k >= 0) {
    return ((fact[n] * factinv[k])%MOD * factinv[n-k])%MOD;
  }
  return 0;
}

long long power(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n%2 == 1) {
    return (x * power(x, n-1)) % MOD;
  } else {
    long long half = power(x, n/2);
    return (half * half) % MOD;
  }
}

long long gcm(long long a, long long b) {
  if (a < b) {
    return gcm(b, a);
  }
  if (b == 0) return a;
  return gcm(b, a%b);
}

ll H, W, A, B;

ll calc(ll x, ll y, ll s, ll t) {
  return C(s-x+t-y, s-x);
}

int main() {
  init();
  cin >> H >> W >> A >> B;
  ll ans = 0;
  for (auto i = 0; i < H-A; ++i) {
    ans += (calc(0, 0, i, B-1) * calc(i, B, H-1, W-1))%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

int main(){
    int K;
    cin >> K;
    bool ver[K];
    fill(ver,ver+K,false);
    deque<P> dque;
    dque.push_back(make_pair(1,1));
    while(1){
        P p=dque.back();
        dque.pop_back();
        if(!p.first){
            cout << p.second << endl;
            return 0;
        }
        if(ver[p.first]) continue;
        ver[p.first]=true;
        dque.push_back(make_pair((10*p.first)%K,p.second));
        dque.push_front(make_pair(++p.first%K,++p.second));
    }
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
  string s;
  cin >> s;
  
  int sn = 0, tn = 0;
  for(int i = 0; i < s.size(); ++i){
    if(s[i] == 'S') sn++;
  }
  tn = s.size() - sn;

  int ls = 0, rs = sn, lt = 0, rt = tn;
  int ans = abs(ls - lt) + abs(rs - rt);
  for(int i = 0; i < s.size(); ++i){
    if(s[i] == 'S'){
      ls++;
      rs--;
    }
    else{
      lt++;
      rt--;
    }
    int t = max(0, lt - ls);
    int s = max(0, rs - rt);
    ans = max(ans, t + s);
  }

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

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

int main(void) {
	int N;
	string ans;
	scanf("%d", &N);
	if (N % 2 == 0) {
		printf("%lf", 0.5);
	} else {
		printf("%lf", (double) (N / 2 + 1) / N);
	}

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MOD = 1e9+7;

ll N, K;

int solve() {
    ll ret = 0;
    FOR (k, K, N+2) {
        (ret += (N-k+1) * k + 1) %= MOD;
    }
    return ret;
}

int main() {
    cin >> N >> K;
    cout << solve() << endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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 (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    ll n; cin >> n;

    vector<vector<ll>> g(n*n);

    vector<vector<ll>> k(n, vector<ll>(n-1));
    REP(i, n) REP(j, n-1) {
        ll opp; cin >> opp;
        --opp;
        ll a = min(i, opp);
        ll b = max(i, opp);
        ll ki = a * n + b;
        k[i][j] = ki;
    }

    vector<ll> indeg(n*n, 0);
    REP(i, n) {
        REP(j, n-2) {
            g[k[i][j]].push_back(k[i][j+1]);
            ++indeg[k[i][j+1]];
        }
    }

    deque<ll> zeroin;
    vector<ll> toposo;
    REP(_i, n*n) {
        ll i = _i / n;
        ll j = _i % n;
        if (i >= j) continue;
        if (indeg[_i] == 0) {
            zeroin.push_back(_i);
        }
    }
    while (zeroin.size()) {
        ll u = zeroin.front(); zeroin.pop_front();
        toposo.push_back(u);
        for (ll v : g[u]) {
            if (--indeg[v] == 0) {
                zeroin.push_back(v);
            }
        }
    }
    REP(_i, n*n) {
        ll i = _i / n;
        ll j = _i % n;
        if (i >= j) continue;
        if (indeg[_i]) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<ll> dp(n*n+1, 1);
    for (ll u : toposo) {
        for (ll v : g[u]) {
            chmax(dp[v], dp[u] + 1);
        }
    }
    cout << *max_element(ALL_OF(dp)) << endl;
    
}


Measured memory_bytes: 66800
#include<iostream>
using namespace std;
int main(){
	int ab[2001];
	ab[0]=1;
	for(int i=1;i<=1000;i++)ab[i]=ab[i-1]+1;
	for(int i=0;i<1000;i++)ab[2000-i]=ab[i];

	int n;
	while(cin>>n){
		long long int ans=0;
		for(int i=0;i<=2000;i++){
			int cd=n-i;
			if(cd>2000)continue;
			if(cd<0)break;
			ans+=(long long int)ab[i]*ab[cd];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define c(n) cout<<n<<endl;
int a[114];
signed main(){
	int n;
	cin>>n;
	int sum=0;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	int ans=11111111;	
	int wa=0;
	rep(i,n){
		wa=0;
		rep(j,i+1){
			wa+=a[j];
		}
		if(abs(sum-wa*2)<ans){
			ans=abs(sum-wa*2);
		}
	}
	c(ans)		
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int k, s, a = 0;
  std::cin >> k >> s;

  for ( int x = 0; x <= k; x++ ) {
    for ( int y = 0; y <= k; y++ ) {
      if ( x + y > s ) break;
      if ( s - ( x + y ) <= k ) a += 1;
    }
  }

  std::cout << a << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string s,s1,s2;
    cin>>s>>s1>>s2;

    string a,b,c;
    a=(s[0]-97)+65;
    b=(s1[0]-97)+65;
    c=(s2[0]-97)+65;
    cout<<a<<b<<c<<endl;



}


Measured memory_bytes: 3608
fun main(args: Array<String>) {
    val mod = (1e9 + 7).toInt().toBigInteger()
    val n = readLine()!!.toInt()
    if (n < 2) {
        println(0)
        return
    }
    println((10.toBigInteger().pow(n) - 9.toBigInteger().pow(n) * 2.toBigInteger() + 8.toBigInteger().pow(n)).mod(mod))
}

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

using namespace std;

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

	int n;
	double sum = 0;
	cin >> n;

	for(int i = 0; i < n; i++) {
		double a;
		cin >> a;
		sum += (1.0/a);
	}

	double ans = 1.0/sum;
	cout << fixed << setprecision(15) << ans;

	return 0;
}

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

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  int n;
  cin >> n;
  string s[n];
  rep(i, n) cin >> s[i];
  int    counter[4] = { 0, 0, 0, 0 };
  string ans[4]     = { "AC", "WA", "TLE", "RE" };
  rep(i, n) {
    rep(j, 4) {
      if (ans[j] == s[i]) {
        counter[j]++;
      }
    }
  }

  cout << "AC x " << counter[0] << endl;
  cout << "WA x " << counter[1] << endl;
  cout << "TLE x " << counter[2] << endl;
  cout << "RE x " << counter[3] << endl;

  return 0;
}


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

using namespace std;

int main() {
  int64_t N, X;
  cin >> N >> X;
  int64_t costs[2][2010];
  int64_t result = 0;
  for (int i = 0; i < N; i++) {
    cin >> costs[0][i];
    result += costs[0][i];
  }

  for (int k = 1; k < N; k++) {
    int curr = k & 1;
    int prev = 1 - curr;
    memcpy(costs[curr], costs[prev], sizeof(costs[curr]));

    int64_t sum = X * k;
    for (int v = 0; v < N; v++) {
      int v2 = v + 1;
      if (v2 >= N) v2 -= N;
      costs[curr][v2] = min(costs[curr][v2], costs[prev][v]);
      sum += costs[curr][v2];
    }
    result = min(result, sum);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll W, a, b;
    cin >> W >> a >> b;
    
    if(a+W<b) pt(b-a-W);
    else if(b+W<a) pt(a-b-W);
    else pt(0);
    
}








Measured memory_bytes: 256