akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
//const int INF = 2147483647;
const int INF=1e9;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-10;

struct Edge
{
    int from, to, cap, flow;
};

int n, m, s, t, num;
vector<Edge> edges;    // 边数的两倍
vector<int> G[maxn];   // 邻接表，G[i][j]表示结点i的第j条边在e数组中的序号
bool vis[maxn];        // BFS使用
int d[maxn];           // 从起点到i的距离
int cur[maxn];         // 当前弧指针

void ClearAll(int n)
{
    for (int i = 0; i < n; i++)
        G[i].clear();
    edges.clear();
}

void ClearFlow()
{
    for (int i = 0; i < edges.size(); i++)
        edges[i].flow = 0;
}

void AddEdge(int from, int to, int cap)
{
    edges.push_back((Edge) {from, to, cap, 0});
    edges.push_back((Edge) {to, from, 0, 0});
    num = edges.size();
    G[from].push_back(num - 2);
    G[to].push_back(num - 1);
}

bool BFS()
{
    memset(vis, 0, sizeof(vis));
    queue<int> Q;
    Q.push(s);
    vis[s] = 1;
    d[s] = 0;
    while (!Q.empty())
    {
        int x = Q.front(); Q.pop();
        for (int i = 0; i < G[x].size(); i++)
        {
            Edge& e = edges[G[x][i]];
            if (!vis[e.to] && e.cap > e.flow)
            {
                vis[e.to] = 1;
                d[e.to] = d[x] + 1;
                Q.push(e.to);
            }
        }
    }
    return vis[t];
}

int DFS(int x, int a)
{
    if (x == t || a == 0)
        return a;
    int flow = 0, f;
    for (int& i = cur[x]; i < G[x].size(); i++)
    {
        Edge& e = edges[G[x][i]];
        if (d[x] + 1 == d[e.to] && (f = DFS(e.to, min(a, e.cap - e.flow))) > 0)
        {
            e.flow += f;
            edges[G[x][i] ^ 1].flow -= f;
            flow += f;
            a -= f;
            if (a == 0) break;
        }
    }
    return flow;
}

int Maxflow(int s, int t)
{
    int flow = 0;
    while (BFS())
    {
        memset(cur, 0, sizeof(cur));
        flow += DFS(s, INF);
    }
    return flow;
}

int h, w;
char pic[107][107];

int main(int argc, char const *argv[])
{
    scanf("%d%d", &h, &w);
    s = 0;
    t = h + w + 1;
    for (int i = 1; i <= h; i++)
        scanf("%s", pic[i] + 1);

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            //char c;
            //cin>>c;

            if (pic[i][j] != '.')
            {
                AddEdge(i, j + h, 1);
                AddEdge(j + h, i, 1);
            }
            if (pic[i][j] == 'S')
            {
                AddEdge(s, i, INF);
                AddEdge(s, j + h, INF);
            }
            if (pic[i][j] == 'T')
            {
                AddEdge(i, t, INF);
                AddEdge(j + h, t, INF);
            }

        }
    }

    int ans = Maxflow(s, t);
    if (ans >= INF)
        printf("-1\n");
    else
        printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 6772
import numpy as np

a1,a2,a3 = map(int,input().split())
a4,a5,a6 = map(int,input().split())
a7,a8,a9 = map(int,input().split())

a = np.array([[a1, a2, a3], [a4, a5, a6], [a7, a8, a9]])

n = int(input())
for i in range(n):
  b = int(input())
  a = np.where(a == b, 0, a)

if a[0,0] + a[0,1] + a[0,2] == 0:
  print("Yes")
elif a[1,0] + a[1,1] + a[1,2] == 0:
  print("Yes")
elif a[2,0] + a[2,1] + a[2,2] == 0:
  print("Yes")
elif a[0,0] + a[1,0] + a[2,0] == 0:
  print("Yes")
elif a[0,1] + a[1,1] + a[2,1] == 0:
  print("Yes")
elif a[0,2] + a[1,2] + a[2,2] == 0:
  print("Yes")
elif a[0,0] + a[1,1] + a[2,2] == 0:
  print("Yes")
elif a[2,0] + a[1,1] + a[0,2] == 0:
  print("Yes")
else:
  print("No")

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

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

    if (a % 3 == 0 or b % 3 == 0 or (a + b) %3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
pair<ll,ll>p[114514];
int main() {
	ll m,d;
	cin>>m>>d;
	ll ans=0;
	for(int i=1;i<=m;i++){
		for(int j=10;j<=d;j++){
			ll x=j/10,y=j%10;
			if(x>=2&&y>=2&&i==x*y)ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

N = int(input())
p = list(map(float, input().split()))
p = [0] + p
dp = [0] * (N + 1)
dp[0] = 1

for i in range(1, N + 1):
    for j in range(i, 0, -1):
        dp[j] = dp[j - 1] * p[i] + dp[j] * (1 - p[i])
    dp[0] = dp[0] * (1 - p[i])

print(sum(dp[N // 2 + 1:]))


Measured memory_bytes: 43244
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,i,j,k;
    int a[27]={0},b[27]={0};
    string s;
    cin >> n >> s;
    for(i=0;i<n;i++)
    {
        a[s[i]-'a']++;
    }
    k=-1;
    for(i=0;i<n;i++)
    {
        a[s[i]-'a']--;
        b[s[i]-'a']++;
        int x=0;
        for(j=0;j<26;j++)
        {
            if(a[j]>0 && b[j]>0)
                x++;
        }
        if(x>k)
            k=x;
    }
    cout << k << endl;
    return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  double R;cin>>R;
  double pip =3.1415926535;
  cout<<(double)2*R*pip<<endl;
}





Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for(int i = (s), mi = (t); i <= mi; i++)
#define dwn(i, s, t) for(int i = (s), mi = (t); i >= mi; i--)
#define LL long long

LL read() {
	LL x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 100010
#define MOD 1000000007

int n, La[maxn], Lb[maxn], f[maxn], g[maxn], S[maxn];
LL A[maxn], a, b;

int main() {
	n = read(); a = read(); b = read();
	if(a > b) swap(a, b);
	int pa = 0, pb = 0;
	rep(i, 1, n) {
		A[i] = read();
		if(i > 1 && A[i] - A[i-1] < a) S[i] = S[i-1] + 1; else S[i] = S[i-1];
		while(A[i] - A[pa+1] >= a) pa++;
		while(A[i] - A[pb+1] >= b) pb++;
		La[i] = pa; Lb[i] = pb;
	}
	
	f[1] = g[1] = 1;
	rep(i, 2, n) {
		f[i] = g[i-1];
		if(A[i] - A[i-1] >= a) f[i] += f[i-1]; if(f[i] >= MOD) f[i] -= MOD;
		if(i - 2 > 0 && A[i] - A[i-2] < a) f[i] = 0;
		g[i] = f[min(i-1,Lb[i]+1)];
		if(Lb[i] == i - 1) g[i] += g[i-1]; if(g[i] >= MOD) g[i] -= MOD;
		// printf("%d %d\n", La[i-1], Lb[i]);
		if(Lb[i] < i - 2 && S[i-1] - S[Lb[i]+1]) g[i] = 0;
		// printf("f[%d] = %d, g[%d] = %d\n", i, f[i], i, g[i]);
	}
	
	printf("%d\n", (f[n] + g[n]) % MOD);
	
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define mo 998244353
#define mx 200005
#define ll long long
ll f[mx] = {1,1}, ff[mx] = {1};
ll q(ll a, ll n){
    ll t = 1;
    while(n){
        if(n&1) t = t * a % mo;
        a = a * a % mo ; n >>= 1;
    }
    return t;
}
ll c(ll m , ll k){
    return f[m] * ff[m-k] % mo * ff[k] % mo;
}
int main(){
    for(ll i = 1 ; i < mx ; ++i)
        f[i]  = i * f[i-1] % mo , 
        ff[i] = ff[i-1] * q(i,mo-2) % mo;
    ll n , m , k , sum = 0;
    cin >> n >> m >> k;
    for(int i = 0 ; i <= k ; ++i)
        sum = (sum + m * q(m-1,n-i-1) % mo * c(n-1,i)) % mo;
    cout<< sum <<endl;
}

Measured memory_bytes: 6760
#include<cstdio>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
const int mod=1000000007;
int n,k,f[2010];
int main() {
	scanf("%d%d",&n,&k);f[1]=1;
	dwn(i,n-1,1) dwn(j,n-i+1,1) f[j]=(f[j+1]+f[j-1])%mod;
	int ans=f[n-k+1];
	rep(i,1,n-k-1) ans=(ans+ans)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int N,A[10010];
int min()
{
    int i;
    int min=A[0];
    for(i=0;i<N;i++)
    {
        if(A[i]<min)
            min=A[i];
    }
    return min;
}
int max()
{
    int i;
    int max=A[0];
    for(i=0;i<N;i++)
    {
        if(A[i]>max)
            max=A[i];
    }
    return max;
}
long long sum()
{
    long long sum=0;
    int i;
    for(i=0;i<N;i++)
    {
        sum+=A[i];
    }
    return sum;
}
int main()
{
    cin>>N;
    for(int i=0;i<N;i++)
    {
        cin>>A[i];
    }
    cout<<min()<<' '<<max()<<' '<<sum()<<endl;
}


Measured memory_bytes: 3140
object Main {
	def main(args:Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		val n = sc.next // 最初の数字を読み取る
		
		val n2 = n.distinct

		if(n.equals(n2)) println("yes")
		else println("no")
	}
}

Measured memory_bytes: 27448
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        for(int i=0;i<s.length();i++){
        	if(Character.isUpperCase(s.charAt(i))){
            	System.out.print(s.substring(i,i+1).toLowerCase());
        	}else{
        		System.out.print(s.substring(i,i+1).toUpperCase());
        	}
        }
        System.out.println("");
	}
}

Measured memory_bytes: 17008
#include <iostream>

using namespace std;

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

  if(a.length() > b.length()) {
    cout << "GREATER" << endl;
    return 0;
  }
  else if(a.length() < b.length()) {
    cout << "LESS" << endl;
    return 0;
  }
  else {
    for(int i = 0; i < a.length(); i++) {
      if(a[i] > b[i]) {
	cout << "GREATER" << endl;
	return 0;
      }
      else if(a[i] < b[i]) {
	cout << "LESS" << endl;
	return 0;
      }
    }
  }

  cout << "EQUAL" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdbool.h>
using namespace std;
int main(){
  int a,b;
  int n;
  cin>>a>>b;
  cin>>n;
  bool flag=false;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    if((a<x&&x<b)||(a<y&&y<b)||(x<=a&&b<=y)){
      flag=true;
    }
  }
  if(flag){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  return(0);
}

Measured memory_bytes: 3096
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable long inf = 3L * 10L^^18;

void main() {
    int n, m;
    scan(n, m);

    auto uf = UnionFind(n);

    foreach (i ; 0 .. m) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        uf.unite(ai, bi);
    }

    long a = uf.count_node(0), b = uf.count_node(1);
    long c = n - a - b;

    debug {
        writeln(a, " ", b);
    }

    long ans = a * (a - 1) / 2 + b * (b - 1) / 2 + c * (c - 1) / 2 + max(a, b) * c - m;

    writeln(ans);
}


struct UnionFind {
    private {
        int N;
        int[] p;
        int[] rank;
        int[] num_v;
    }

    this (int n) {
        N = n;
        p = iota(N).array;
        rank = new int[](N);
        num_v = new int[](N);
        foreach (i ; 0 .. N) {
            num_v[i] = 1;
        }
    }

    int find_root(int x) {
        if (p[x] != x) {
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        int u = find_root(x), v = find_root(y);

        if (u == v) return;

        if (rank[u] < rank[v]) {
            p[u] = v;
            num_v[v] += num_v[u];
            num_v[u] = 0;
        }
        else {
            p[v] = u;
            num_v[u] += num_v[v];
            num_v[v] = 0;

            if (rank[u] == rank[v]) {
                rank[u]++;
            }
        }
    }

    int count_node(int x) {
        return num_v[find_root(x)];
    }
}




void solve(int n, int v, int w) {
    if (n == 1) {
        writeln(min(v, w));
        return;
    }

    auto va = new int[](0);
    va ~= v;

    while (v > 1) {
        if (v % n <= 1) {
            v /= n;
        }
        else {
            v = (v / n) + 1;
        }

        va ~= v;
    }

    va.reverse();

    auto wa = new int[](0);
    wa ~= w;

    while (w > 1) {
        if (w % n <= 1) {
            w /= n;
        }
        else {
            w = (w / n) + 1;
        }

        wa ~= w;
    }

    wa.reverse();

    debug {
        writeln(va);
        writeln(wa);
    }

    int ans = 0;

    while (!va.empty) {
        while (!wa.empty) {
            if (va.front == wa.front) {
                ans = max(ans, va.front);
                va.popFront;
                wa.popFront;
                break;
            }
            else if (va.front < wa.front) {
                va.popFront;
                break;
            }
            else {
                wa.popFront;
            }
        }
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 4476
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = 0;
    int now = h[0];
    int cnt = 1;
    rep2(i,1,n) {
        if(h[i] <= now) {
            cnt++;
            now = h[i];
        } else {
            chmax(ans,cnt-1);
            cnt = 1;
            now = h[i];
        }
    }
    chmax(ans,cnt-1);
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int a;
  for (int i = 1; i <= n; i++) {
   if (i % 3 == 0 || i % 10 == 3) {
    System.out.print(" " + i);
   } else if (i >= 30) {
    a = i;
    while (a >= 30) {
     a /= 10;
     if (a == 3 || a % 10 == 3) {
      System.out.print(" " + i);
      break;
     }
    }
   }
  }
  System.out.println();
 }
}

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

int main() {
	int a, b;

	cin >> a >> b;
	
	if ((a+b)%2 == 0) {
		cout << (a + b) / 2 << endl;
	}
	else {
		cout << ((a + b) / 2) + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	ll N, M;
	cin >> N >> M;
	vl WA(N, 0);
	vb AC(N, false);
	rep(i, M) {
		ll p;
		string S;
		cin >> p >> S;
		p--;
		if (!AC[p]) {
			if (S == "WA")
				WA[p]++;
			else
				AC[p] = true;
		}
	}
	ll ans_WA = 0;
	ll ans_AC = 0;
	rep(i, N) {
		if (AC[i]) {
			ans_WA += WA[i];
			ans_AC++;
		}
	}
	cout << ans_AC << " " << ans_WA << endl;
	return 0;
}

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

#define cnd(c, a, b) (c ? a : b);
#define fl(x,y,z) for(int x=y;x<z;x++)
#define fe(x,y,z) for(int x=y;x<=z;x++)
#define fge(x,y,z) for(int x=y;x>=z;x--)

#define debug(x) std::cerr << #x << " --> " << x << "\n";
#define fastIO std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define pb push_back
#define pob pop_back
 
#define ln '\n'

typedef long long int ll;

void solve() {
	ll n, tmp, max_val;
	ll ans,count;
	vector<ll> vec;
	cin>>n;

	fl(i,0,n) {
		cin>>tmp;
		vec.pb(tmp);
	}
	max_val = vec[0];
	ans = 0;
	fl(i,1,n) {
		if(vec[i]>=max_val) {
			max_val = vec[i];
		} else {
			ans += max_val - vec[i];
		}
	}
	cout<<ans<<ln;
	return;
}

int main() {
    fastIO
    int t = 1;
    // cin >> t;
    fl(i,0,t) {
    	// cout << "Case #"<< i+1 <<": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 5328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int n,m,a[305][305],f[305],ok[305],s[305];

bool check(int x){
	for(int i=1; i<=m; i++) ok[i] = 1, s[i] = 0;
	for(int i=1; i<=n; i++) {
		f[i]=1;
		s[a[i][f[i]]]++;
		if(s[a[i][f[i]]] > x) ok[a[i][f[i]]] = 0;
	}
	while(1){
		int cnt = 0;
		for(int i=1; i<=n; i++){
			if(ok[a[i][f[i]]]) continue;
			cnt++;
			while(ok[a[i][f[i]]]==0 && f[i]<=m){
				f[i]++;
				s[a[i][f[i]]]++;
				if(s[a[i][f[i]]] > x) ok[a[i][f[i]]] = 0;
			}
		}
		bool mask = 1;
		for(int i=1; i<=n; i++){
			if(f[i] > m) return false;
			if(ok[a[i][f[i]]] == 0) mask=0;
		}
		if(cnt==0 && mask) break;
	}

	return true;
}

int main(){
	cin >> n >> m;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
			cin >> a[i][j];
	// cout << check(1) << endl;
	int L=1,R=n,ans=n;
	while(L<=R){
		int mid = (L+R)/2;
		if(check(mid)) ans=mid,R=mid-1;
		else L=mid+1;
	}
	cout << ans << endl;


    return 0;
}
// 3 3
// 1 2 3
// 3 2 1
// 2 3 1

Measured memory_bytes: 640
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define repp(i,a,n)   for(int i=a;i<n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    vi a(n),b(N,1);
    rep(i,n)cin>>a[i];
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        if(a[x-1]<=a[y-1])b[x-1]=0;
        if(a[y-1]<=a[x-1])b[y-1]=0;
    }
    int ans=0;
    rep(i,n) if(b[i])ans++;
    cout<<ans<<nl;
    return 0;
}


Measured memory_bytes: 4464
#include <stdio.h>

int main(void)
{
	int l;
	
	while (scanf("%d", &l) * l != 0){
		int m[12], n[12];
		int i;
		
		for (i = 0; i < 12; i++){
			scanf("%d %d", m + i, n + i);
			l -= m[i] - n[i];
			if (l <= 0){
				printf("%d\n", i + 1);
				l = 1200000000;
			}
		}
		if (0 < l && l <= 1000000){
			puts("NA");
		}
	}
	
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	int r;
	scanf("%d",&r);
	if(r<1200) puts("ABC");
	else if(r<2800) puts("ARC");
	else puts("AGC");
	return 0;
}

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

#define ll unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
string convertToTitle(ll n) {
        string r = "";
        while (n > 0) {
            r = (char)(97 + (n - 1) % 26) + r;
            n = (n - 1) / 26;
        }
        return r;
    }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    while(t--){
        ll n;cin>>n;
        cout<<convertToTitle(n);
    }
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll choose2(ll n){
    return n*(n-1)/2;
}
int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n) a[i]--;
    vector<int> cnt(n);
    rep(i,n) cnt[a[i]]++;
    ll tot = 0;
    rep(i,n){
        tot+=choose2(cnt[i]);
    }
    rep(i,n){
        ll ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]]-1);
        cout << ans <<endl;
    }
    return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {FIN;
    
    ll n,k;cin>>n>>k;
    if(k>=n)cout<<min(k-n,n)<<"\n";
    else{

        ll cal = n/k;
        ll rest = n-cal*k;
        cout<<min(k-rest,rest)<<"\n";

    }
    return 0;
}



Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 */

public class Main {

	public static void printlnYN(boolean b){
		if(b) System.out.println("Yes");
		else System.out.println("No");
	}

	public static void main(String[] args) throws IOException {

		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
    	String S = sc.next();

    	int max = 0;


    	for(int i = 1; i < N; i++){
    		String X = S.substring(0, i);
    		String Y = S.substring(i, S.length());

    		int m = 0;
    		for(int j = 0; j < 26; j++){
    			if(r(X, (char)('a'+j)) && r(Y, (char)('a'+j))) m++;
    		}
    		if(m > max) max = m;
    	}

    	System.out.println(max);

	}

	public static boolean r(String S, char c){
		boolean ans = false;
		for(int i = 0; i < S.length(); i++){
			if(S.charAt(i) == c){
				ans = true;
				break;
			}
		}
		return ans;
	}

}

Measured memory_bytes: 21972
#include <stdio.h>

int main(){
    char s[200000];
    char t[200000];
    int ss,st;
    ss = scanf("%s", s);
    st = scanf("%s", t);
    if (ss== -1 || st == -1){
        puts("0");
    }
    else{
    
        int count = 0;
        int i= 0;

        while (s[i] != '\0' && i <200000){
            
            if (s[i] != t[i]){
                count++;
            }
            i++;
        }
        printf("%d", count);
    }
    return 0;
}

Measured memory_bytes: 2488
#include<stdio.h>
int main()
{
	int n,c,p,i,x,z;
	scanf("%d %d",&n,&c);
	x=0;
	for(i=0;i<c;i++){
		scanf("%d",&p);
		x+=p;
	}
	n++;
	z=x/n;
	if(x%n!=0)	z++;
	printf("%d\n",z);
	return 0;
}


Measured memory_bytes: 2120
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for (i = 0; i <= VMAX; i++) C[i] = 0;

  for (i = 0; i < n; i++){
    scanf("%d", &A[i+1]);
    C[A[i+1]]++;
  }

  for (i = 1; i <= VMAX; i++) C[i] = C[i] + C[i-1];

  for (j = 1; j <= n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

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


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


int main(){
  int n;
  cin>>n;
  int i1=0;
  int i2=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==-1)i1++;
    if(a[i]==-2)i2++;
  }

  vector<int> ans;
  int s2=0;
  int p1=0;

  //cout<<"is"<<" "<<i1<<endl;
  //cout<<"is"<<" "<<i2<<endl;

  if(i2%2==0){
    //cout<<"a";
    for(int i=0;i<n;i++){
      if(a[i]==2||a[i]==-2){
        //cout<<i+1;
        ans.push_back(i+1);
      }
    }
  }else if(i2%2!=0&&i1==0){
    //cout<<"b";
    for(int i=0;i<n;i++){
      if(a[i]==2){
        //cout<<i+1;
        ans.push_back(i+1);
      }else if(a[i]==-2){
        if(i2-1!=s2){
          //cout<<"a";
          //cout<<i+1;
          ans.push_back(i+1);
          s2++;
        }
      }
    }
  }else if(i2%2!=0&&i1>0){
    //cout<<"c";
    for(int i=0;i<n;i++){
      if(a[i]==2||a[i]==-2){
        //cout<<i+1;
        ans.push_back(i+1);
      }else if(a[i]==-1&&p1==0){
        //cout<<i+1;
        ans.push_back(i+1);
        p1=1;
      }
    }
  }

  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<endl;
  }
}



Measured memory_bytes: 3160
//
//  main.cpp
//  B - Power Socket
//
//  Created by Hashizo on 2019/09/01.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef LONG_MAX
#undef LONG_MIN

#define LONG_MAX	9223372036854775807
#define LONG_MIN	(-LONG_MAX  -1)

#define ll long long

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll a,b;
	ll cnt = 0;
	ll concent = 1;
	
	cin >> a >> b;

	while(1) {
		if (b <= concent) {
			break;
		}
		concent = concent + a - 1;
		cnt++;
	}
	
	
	

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            int count = 1;
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                
                int x = Integer.parseInt(input[0]);
                int y = Integer.parseInt(input[1]);
                
                // x ??¨ y ????????????0?????´????????????
                if(x == 0 && y == 0) {
                    break;
                }
                
                // x ??¨ y????????????????°???????????????????????????? (????§???????????????§??????) 
                if(x > y) {
                    int temp = x;
                    x = y;
                    y = temp;
                }
                
                System.out.println(x + " " + y);
                
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
}

Measured memory_bytes: 27152
from collections import defaultdict
n = int(input())
counter = defaultdict(int)
for x in map(str, range(1, n+1)):
  head = x[0]
  tail = x[-1]
  counter[(head, tail)] += 1
ans = 0
items = list(counter.items())
for (head, tail), cnt in items:
  ans += cnt * counter[(tail, head)]
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int a[maxn];
int main(){
	n=read();k=read();
	int ans=0;
	for(register int i=1;i<=n;i++){
		a[i]=read();
		if(a[i]>=k)ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int sub(int a,vector<char>b,int c,int d){
  if(c%2019==0&&c!=0)return 1;
  return sub(a+1,b,c+b[d]*a,d+1);
}
int main(){ 
  string a,b="abc";
  cin>>a;
  sort(a.begin(),a.end());
  if(a==b)cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int k,n=s.size();
  cin>>k;
  int a[n];
  for(int i=0;i<n;i++){
    if(('z'-s[i]+1)<=k&&s[i]!='a'){
      k-=('z'-s[i]+1);
      s[i]='a';
    }
  }
  k%=26;
  s[n-1]+=k;
  if(s[n-1]>'z') s[n-1]=s[n-1]-'z'-1+'a';
  cout<<s<<endl;
}
      
  

Measured memory_bytes: 512
import java.util.*;

    fun main(args: Array<String>) {
        val scan = Scanner(System.`in`)
        val inputStr = scan.nextLine()
        val num1 = Integer.parseInt(inputStr)
        val charArray = inputStr.toCharArray()
        var num2 = 0
        for (i in charArray) {
            num2 = num2 + Character.getNumericValue(i)
        }
        if ((num1 % num2) == 0) {
		System.out.print("Yes");
	} else {
		System.out.print("No");
	}
    }

Measured memory_bytes: 31264
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


void construct(LL n, LL a, LL b, LL used, vector<LL>& ans){
    LL b1 = 0, b2 = -1;
    for(LL i = 0; i < n; ++i){
        if((used>>i) & 1) continue;
        LL ab = (a>>i) & 1;
        LL bb = (b>>i) & 1;
        if((ab ^ bb) == 1){
            b1 = i;
        }
    }
    for(LL i = 0; i < n; ++i){
        if((used>>i) & 1) continue;
        if(i == b1) continue;
        b2 = i;
    }
    //cerr << "a=" << a << ", b=" << b << ", b1=" << b1 <<", b2=" << b2 << ", used=" << used << endl;
    if(b2 == -1){
        ans.push_back(a);
        ans.push_back(b);
        return;
    }
    construct(n, a, a^(1<<b2), used|(1<<b1), ans);
    construct(n, a^(1<<b2)^(1<<b1), b, used|(1<<b1), ans);
}

vector<LL> solve(LL n, LL a, LL b){
    LL cnt = 0;
    for(LL i = 0; i < n; ++i){
        cnt += (a>>i)&1;
        cnt += (b>>i)&1;
    }
    if(cnt % 2 == 0){
        return vector<LL>();
    }
    vector<LL> ans;
    construct(n, a, b, 0, ans);
    return ans;
}

int main(){
    LL n, a, b;
    cin >> n >> a >> b;
    vector<LL> ans = solve(n, a, b);
    if(ans.empty()){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
        for(LL i = 0; i < ans.size(); ++i){
            cout << ans[i];
            if(i+1 == ans.size()){
                cout << endl;
            }else{
                cout << " ";
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2164
W, H = map(int, raw_input().split())

p_list = list()
q_list = list()

for i in range(W):
    p_list.append(int(raw_input()))
    
for j in range(H):
    q_list.append(int(raw_input()))

p_list.sort()
q_list.sort()

cp = H+1
cq = W+1

res = 0
pid = 0
qid = 0

while True:
    if pid == W:
        if qid == H:
            break
        else:
            choice = 'q'
    elif qid == H:
        choice = 'p'
    elif p_list[pid] < q_list[qid]:
        choice = 'p'
    else:
        choice = 'q'
    if choice == 'p':
        cq -= 1
        res += cp*p_list[pid]
        pid += 1
    else:
        cp -= 1
        res += cq*q_list[qid]
        qid += 1

print res 

Measured memory_bytes: 36252
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        int[] nm = inta();
        int a = 0;
        int b = 0;
        for(int i = 0; i < nm[1]; i++)
        {
            if(i%2 == 1)
            {
                a = i / 2 + 2 + nm[1];
                b = -i / 2 + 1 + 2 * nm[1];
            }
            else
            {
                a = i / 2 + 1;
                b = 1 - i / 2 + nm[1];
            }
            WriteLine(a+" "+b);
        }
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 37704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

ll ksm(ll a,ll p){
    if(p==1) return a%mod;
    if(p%2==1) return a*ksm(a,p-1)%mod;
    ll t=ksm(a,p/2);
    return t*t%mod;
}

int main() {
    ll n; cin >> n;
    if (n<2) {
        cout << 0 << "\n";
        return 0;
    }
    ll ans=(ksm(10,n)+ksm(8,n))%mod-2*ksm(9,n)%mod;
    if (ans<0){
        cout << ans+mod << "\n";
    }
    else cout << ans%mod << "\n";
}















Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int cl[120000],lst[120000];
vector<int> eds[120000];
int n,m,q,a,b,v,d,c;
void dfs1(int v,int d,int c)
{
	if (!cl[v]) cl[v]=c;
	if (lst[v]>=d) return;
	lst[v]=d;
	if (d==0) return;
	for (int u: eds[v]) dfs1(u, d - 1, c);
}
vector<tuple<int, int, int >> vv;
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;i++)
	{
		cin>>a>>b;
		--a, --b;
		eds[a].pb(b);
		eds[b].pb(a);
	}
	cin>>q;
	for (int i=0;i<q;i++)
	{
		cin>>v>>d>>c;
		--v;
		vv.pb(make_tuple(v, d, c));
	}
	reverse(vv.begin(),vv.end());
	for (int i=0;i<q;i++)
	{
		int v, d, c;
		tie(v, d, c) = vv[i];
		dfs1(v, d, c);
	}
	for (int i=0;i<n;i++) cout<<cl[i]<<endl;
	return 0;
}

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main(){
  ll x;
  cin >> x;
  ll sum = 0;
  for (ll i = 1; i <= x; i++) {
    if (i * (i + 1) / 2 >= x) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=150005;
int n;
vector<pii>edge[maxn];
vector<pll>val[maxn];
ll chk;

void merge(vector<pll>&res,vector<pll>s1,vector<pll>s2,int d1,int d2){
	vector<pll>t1,t2,tres;
	if(s1.size()>s2.size())swap(s1,s2),swap(d1,d2);
	int pt1=0,pt2=0;
	rep(i,s1.size()){
		ll a=s1[i].fst,b=s1[i].snd;
		while(pt1<s2.size()&&b+s2[pt1].fst+d1+d2<=chk)pt1++;
		if(pt1-1>=0&&(t1.empty()||s2[pt1-1].snd+d2<t1.back().snd))
			t1.pb(mp(a+d1,s2[pt1-1].snd+d2));
		while(pt2<s2.size()&&a+s2[pt2].snd+d1+d2>chk)pt2++;
		if(pt2<s2.size()){
			while(!t2.empty()&&t2.back().fst==s2[pt2].fst+d2)t2.pop_back();
			t2.pb(mp(s2[pt2].fst+d2,b+d1));
		}
	}
	pt1=pt2=0;
	while(pt1<t1.size()||pt2<t2.size()){
		if(pt2==t2.size()||(pt1<t1.size()&&t1[pt1]<t2[pt2]))tres.pb(t1[pt1]),pt1++;
		else tres.pb(t2[pt2]),pt2++;
	}
	res.clear();
	rep(i,tres.size()){
		if(!res.empty()&&tres[i].snd>=res.back().snd)continue;
		res.pb(tres[i]);
	}
}

void dfs(int x){
	val[x].clear();
	if(edge[x].empty()){
		val[x].pb(mp(0,0));
		return;
	}
	dfs(edge[x][0].fst);
	dfs(edge[x][1].fst);
	merge(val[x],val[edge[x][0].fst],val[edge[x][1].fst],edge[x][0].snd,edge[x][1].snd);
//	rep(i,val[x].size())printf("(%lld,%lld)\n",val[x][i].fst,val[x][i].snd);
//	puts("");
	rep(i,int(val[x].size())-1)assert(val[x][i].fst<val[x][i+1].fst&&val[x][i].snd>val[x][i+1].snd);
}

bool check(ll x){
	chk=x;
	dfs(1);
	return !val[1].empty();
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int p,a;
		scanf("%d%d",&p,&a);
		edge[p].pb(mp(i,a));
	}
	ll l=-1,r=1e16;
	while(r-l>1){
		ll mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%lld\n",r);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 36916
n = int(input())
A = [int(input()) for _ in range(n)]

First = max(A)
ind = A.index(First)
A[ind] = 0
Second = max(A)
A[ind] = First

for i in range(n):
    if A[i] == First:
        print(Second)
    else:
        print(First)

Measured memory_bytes: 12512
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=100005;

int n,F[N],vis[N];
vector<int> go[N];

namespace flow {
	const int V = 200020, E = 1000004;
	int S, T, tot = 1, fst[V], nxt[E], to[E], flow[E], lvl[V];
	
	void addedge(int u, int v, int w) {
		nxt[++tot] = fst[u]; fst[u] = tot; to[tot] = v; flow[tot] = w;
		nxt[++tot] = fst[v]; fst[v] = tot; to[tot] = u; flow[tot] = 0;
	}
	
	int bfs() {
		queue<int> q;
		for(int i = 0; i <= T; i ++)
			lvl[i] = 0;
		q.push(S); lvl[S] = 1;
		int u, v;
		while (!q.empty()) {
			u = q.front(); q.pop();
			for (int i = fst[u]; i; i = nxt[i])
				if (flow[i] && !lvl[v = to[i]]) {
					lvl[v] = lvl[u] + 1;
					q.push(v);
				}
		}
		return lvl[T];
	}
	
	int dinic(int u, int f) {
		if (u == T)
			return f;
		int v, k = f;
		for (int i = fst[u]; i && k; i = nxt[i])
			if (flow[i] && lvl[v = to[i]] == lvl[u] + 1) {
				int t = dinic(v, min(k, flow[i]));
				if (!t)
					lvl[v] = 0;
				else
					k -= t, flow[i] -= t, flow[i ^ 1] += t;
			}
		return f - k;
	}
	
	int mf() {
		int res = 0;
		while(bfs()) res += dinic(S, 2e9);
		return res;
	}
	
	void getmatch() {
		for(int s = 1; s < n; ++s)
			for(int i = fst[s]; i; i = nxt[i])
				if(to[i] != S && !flow[i]) {
					F[s] = to[i] - n; break;
				}
	}
}

int main()
{
	scanf("%d",&n);
	flow::S=2*n+1;
	flow::T=2*n+2;
	for(int i=1,d,x; i<n; i++)
	{
		flow::addedge(flow::S,i,1);
		scanf("%d",&d);
		for(int j=1; j<=d; ++j)
		{
			scanf("%d",&x);
			go[x].push_back(i);
			if(x!=1)
				flow::addedge(i,n+x,1);
		}
	}
	for(int i=2; i<=n; i++)
		flow::addedge(n+i,flow::T,1);
	int f=flow::mf();
	if(f<n-1)
	{
		puts("-1");
		return 0;
	}
	flow::getmatch();
	vector<pair<int,int>> out;
	out.resize(n);
	queue<int> q;
	q.push(1);
	vis[1]=true;
	while(!q.empty()) {
		int u=q.front(); q.pop();
		for(auto &v:go[u]) if(!vis[F[v]]) {
			vis[F[v]]=true;
			out[v]=make_pair(u,F[v]);
			q.push(F[v]);
		}
	}
	for(auto p=out.begin()+1; p!=out.end(); ++p)
		if(!p->first){
			puts("-1");
			return 0;
		}
	for(auto p=out.begin()+1; p!=out.end(); ++p)
		printf("%d %d\n",p->first,p->second);
	return 0;
}


Measured memory_bytes: 22804
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

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

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

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

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

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >>N;
  ll p[N];
  rep(i, N) cin >> p[i];
  ll count = 0;
  rep(i, N) if(p[i]!=i+1)count++;
  
  //cout << count << endl;
  if (count == 2 || count == 0) cout << "YES" << endl;
  else cout <<"NO" << endl;
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3 && i%5)
        sum+=i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	
	
	string a,b;
  cin>>a>>b;
  string r = a+b;
  int t = atoi(r.c_str());
  for(int i = 0; i < 10000; i++){
  	if((i*i) == t)	 {cout<<"Yes"<<"\n"; return 0;}
  }
  cout<<"No"<<"\n";
}









Measured memory_bytes: 256
N,K = list(map(int,input().split()))
p = 998244353
LR = []
for i in range(K):
    LR.append(list(map(int,input().split())))
T = [0]*(2*N+10)
T[1] = 1
S = [0]*(2*N+10)
S[1] = 1
S[2] = -1
for i in range(1,N):
    for j in range(K):
        L,R = LR[j]
        S[i+L]=S[i+L]+T[i]
        S[i+R+1]=S[i+R+1]-T[i]
    T[i+1] = (T[i]+S[i+1])%p
print(T[N])

Measured memory_bytes: 79928