akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    int N, K; cin>>N>>K;
    vector<lint> A, B(N+1);
    string s; cin>>s;
    B[0]=0;
    char a = s[0];
    int cnt=0;
    REP(i, N){
        if(a!=s[i]){
            A.push_back(cnt);
            a=s[i];
            cnt = 1; 
        }
        else cnt++;
    }
    A.push_back(cnt);
    lint n = (lint)A.size();
    if(n==1){
        cout << A[0] << endl;
        return 0;
    }
    REP(i, n){
        B[i+1] = B[i] + A[i];
    }
    B[n+2] = B[n+1];
    //REP(i, n) cout << A[i] << " ";
    //cout << endl;
    //REP(i, n+1) cout << B[i] << " ";
    //cout << endl;
    lint res = 0;
    lint idx;
    if(s[0]=='1') idx = 1;
    else {
        idx = 2;
        res = B[1+2*(K-1)+1];
        res = B[min(n, (lint)1+2*(K-1)+1)];
    }
    for(; idx+2*K<=n+1; idx+=2){
        if(idx+2*K==n+1) res=max(res, B[n]-B[idx-1]);
        else res = max(res, B[idx+2*K]-B[idx-1]);
    }
    cout << res << endl;
    return 0;
}

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

int main(void){
	ll d = 1e+9 + 7;
	int N;
	cin >> N;
	ll A[N];
	ll tot = 0;
	rep(i,N) {
		cin >> A[i];
		tot += A[i];
		tot = tot%d;
	}
	tot = (tot - A[0] + d)%d;
	ll ans = tot*A[0];
	ans %= d;
	for (int i = 1; i < N-1; i++){
		tot = (tot - A[i] + d)%d;
		ans += tot*A[i];
		ans %= d;
	}
	ans = (ans+d)%d;
	cout << ans << endl;
return 0;
}


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


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int GetBkNum(vector<string> area, int h, int w)
{
	int H = (int)area.size();
	int W = (int)area.front().length();
	string row(W, ' ');
	for (int i = 0; i < H; ++i) {
		if ((h >> i) & 0x1) {
			area[i] = row;
		}
	}
	for (int i = 0; i < W; ++i) {
		if ((w >> i) & 0x1) {
			for (int j = 0; j < H; ++j) {
				area[j][i] = ' ';
			}
		}
	}
	int numBk = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (area[i][j] == '#')
				++numBk;
		}
	}
	return numBk;
}

int main()
{
	auto& in = cin;
	int H, W, K;
	in >> H >> W >> K;

	vector<string> area;
	for (int i = 0; i < H; ++i) {
		string str;
		in >> str;
		area.emplace_back(move(str));
	}

	int WW = pow(2, W);
	int HH = pow(2, H);
	int numK = 0;
	for (int h = 0; h < HH; ++h) {
		for (int w = 0; w < WW; ++w) {
			if (GetBkNum(area, h, w) == K)
				++numK;
		}
	}
	cout << numK;

	return 0;
}


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

int main() {
  int n,m; cin>>n>>m;
  int ans=1;
  for (int i=1; i*i<=m; i++) {
    if (m%i) continue;
    if (i>=n) ans=max(ans, m/i);
    if (m/i>=n) ans=max(ans, i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef long long LL;
const int MaxN = 2e5;

int n, m;
int all;
int pre[2 * MaxN + 5], last[MaxN + 5], other[2 * MaxN + 5];
bool vis[MaxN + 5];
int num[MaxN + 5];
bool flag;

void build(int x, int y)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
}

void Dfs(int x, int cnt)
{
	if(cnt == 2) {
		return;
	}
	int ed = last[x], dr;
	vis[x] = 1;
	while(ed != -1)
	{
		dr = other[ed];
		if(vis[dr] == 0) {
			num[dr] = cnt + 1;
			Dfs(dr, cnt + 1);
		}
		ed = pre[ed];
	}
}

int main()
{
	while(scanf("%d %d", &n, &m) != EOF)	
	{
		all = -1;
		memset(last, -1, sizeof(last));
		memset(vis, 0, sizeof(vis));
		for(int i = 1; i <= m; i++) {
			int u, v;
			scanf("%d %d", &u, &v);
			build(u, v); build(v, u);
		}
		Dfs(1, 0);
		if(num[n] == 2) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef pair<int,int> P;

int main() {
    int i,j,n,p,q,temp;
    int t=0;
    int flag=0;
    string s;
    cin>>s;
    int size=s.size();
    if(size==2)cout<<s;
    else{
        reverse(s.begin(),s.end());
        cout<<s;
    }
    return 0;
}


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

long long comb(int n, int r) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}

int main(){
    long long n, p;
    cin >> n >> p;

    vector<long long> a(n);
    long long cnt_odd = 0;
    long long cnt_even = 0;
    for(long long i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 0) cnt_even++;
        else cnt_odd++;
    }

    long long ans = 1;
    for(long long i = 0; i < cnt_even; i++) ans *= 2;
    long long cnt = 0;
    if(p == 0){
        for(long long i = 0; i <= cnt_odd; i += 2) cnt += comb(cnt_odd, i);
    }
    else{
        for(long long i = 1; i <= cnt_odd; i += 2) cnt += comb(cnt_odd, i);
    }
    ans *= cnt;

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

Measured memory_bytes: 3576
matrix = []
while True:
    values = input()
    if '?' in values:
        break
    matrix.append([x for x in values.split()])
    
for a, op, b in matrix:
    if '+' == op:
        print(int(a) + int(b))
    elif '-' == op:
        print(int(a) - int(b))
    elif '*' == op:
        print(int(a) * int(b))
    elif '/' == op:
        print(int(a) // int(b))
    else:
        pass

Measured memory_bytes: 7716
function Main (input) {
  const num = parseInt(input.split(/\s/g)[0]);

  if (num === 1) return console.log('%s', 1);

  const pattern = new Array(num).fill('')
    .map((value1, index1) => {
      return new Array(num).fill('').map((value2, index2) => Math.pow(index1 + 1, index2 + 1));
    })
    .map((values) => (
      values.filter((value, index) => {
        if (index === 0) return false;
        return value <= num;
      })
    ))
    .filter((values) => values.length)
    .map((values) => Math.max(...values));
  console.log('%s', Math.max(...pattern));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 52264
import java.util.*;
import java.io.*;
public class Main
{   
   
	public static void main(String[] args)throws IOException {
		FastReader kb=new FastReader();
        int n=kb.nextInt();
        int w=kb.nextInt();
        long dp[][]=new long[101][100001];
        int arr[]=new int[n+1];
        int brr[]=new int[n+1];
        for(int i=1;i<=n;i++){arr[i]=kb.nextInt();brr[i]=kb.nextInt();}
        for(int i=1;i<arr.length;i++)
        {
           for(int j=1;j<=w;j++)
           {
               if(j>=arr[i])dp[i][j]=Math.max(dp[i-1][j],brr[i]+dp[i-1][j-arr[i]]);
               else dp[i][j]=dp[i-1][j];
           }
        }
        System.out.println(dp[n][w]);
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
  
}













Measured memory_bytes: 125524
#include<bits/stdc++.h>
using namespace std;
map<int, int> M;
int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)
	{
		int x;
		scanf("%d", &x);
		M[x]++;
	}
	if(M[0] == N)
	{
		puts("Yes");
		return 0;
	}
	if(N%3 != 0)
	{
		puts("No");
		return 0;
	}
	int sum = 0;
	for(map<int, int>::iterator it = M.begin(); it != M.end(); it++)
	{
		//cout << (*it).first << " " << (*it).second << endl;
		if((*it).second % (N/3) != 0)
		{
			puts("No");
			return 0;
		}
		int tmp = (*it).second/(N/3);
		while(tmp--)
			sum ^= (*it).first;
	}
	if(sum == 0)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 7284
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n, k = na()

if k == 1:
    print(0)
else:
    print(n - k)

Measured memory_bytes: 3064
#coding: utf-8
n = int(input())
s = str(input())
# list = list(map(int,input().split()))
# strings = list(map(str, [input() for i in range(amount)]))
count = 1

for i in range(1,n):
    if s[i-1] != s[i]:
        count += 1

print(count)



Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	ll num;
	cin >> num;
	ll ans = 0;
	if (!(num % 2)) ans = num;
	else ans = num*2;
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <cstdio>
using namespace std;
int pre[105],in[105];
int pos=-1;
void rec (int l,int r) {
	if (l>=r) return;
	int cur=pre[++pos],cpos=l;
	while (in[cpos]!=cur) cpos++;
	rec (l,cpos);
	rec (cpos+1,r);
	printf ("%d",cur);
	if (cur!=pre[0]) printf (" ");
	else printf ("\n");
}
int main () {
	int n;
	scanf ("%d",&n);
	for (int i=0;i<n;i++) {
		scanf ("%d",&pre[i]);
	}
	for (int i=0;i<n;i++) {
		scanf ("%d",&in[i]);
	}
	rec(0,n);
    return 0;
}


Measured memory_bytes: 2752
def main22():
    buf = input("");
    bufs = buf.split();
    hai = [];
    for i in range(len(bufs)):
        hai.append(int(bufs[i]));
    if hai[0] -hai[1] == 0:
        print(hai[2]);
    elif hai[0] -hai[2] == 0:
        print(hai[1]);
    else:
        print(hai[0]);







if __name__ == '__main__':
    main22()

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void 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;
		}
	}
	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)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int r, g, b;
	int ans;
	cin >> r >> g >> b;
	if ((g * 10 + b) % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, readline().split())
a = list(map(int, readline().split()))

dp = [False] * (K + K + 1)
for i in range(K):
    if not dp[i]:
        for j in a:
            dp[i + j] = True

if dp[K]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 4596
n=int(input())
cnt=0
s=[1,2,3,4,5,6,7,8,9,10,11,12,13]
h=[1,2,3,4,5,6,7,8,9,10,11,12,13]
c=[1,2,3,4,5,6,7,8,9,10,11,12,13]
d=[1,2,3,4,5,6,7,8,9,10,11,12,13]
while(cnt<n):
    a,b=map(str,input().split())
    b=int(b)
    if a=="S":
        s.remove(b)
    elif a=="H":
        h.remove(b)
    elif a=="C":
        c.remove(b)
    elif a=="D":
        d.remove(b)
    cnt+=1

for i in range(len(s)):
    print("S"+" "+str(s[i]))

for i in range(len(h)):
    print("H"+" "+str(h[i]))

for i in range(len(c)):
    print("C" + " " + str(c[i]))

for i in range(len(d)):
    print("D" + " " + str(d[i]))


Measured memory_bytes: 5612
import java.util.Scanner;

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

		int n = sc.nextInt() - 1;
		int m = sc.nextInt() - 1;

		int pattern = 0;

		for(int i = n; i > 0; i--)
		{
			pattern += i;
		}

		for(int i = m; i > 0; i--)
		{
			pattern += i;
		}

		System.out.println(pattern);

	}
}


Measured memory_bytes: 22100
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ak = 0;
    int bk = 0;
    int an = 0;
    int bn = 0;
    for (int i = 0; i < n; i++) {
      int v = sc.nextInt();
      if (ak == 0) {
        ak = v;
        an ++;
      } else if (v == ak) {
        an ++;
      } else if (bk == 0) {
        bk = v;
        bn ++;
        if (Math.abs(ak - bk) > 1) {
          System.out.println("No");
          return;
        }
      } else if (v == bk) {
        bn ++;
      } else {
        System.out.println("No");
        return;
      }
    }
    if (bk == 0) {
      System.out.println((ak == n - 1 || 2 * ak <= n) ? "Yes" : "No");
    } else {
      if (ak < bk) {
        int tk = ak;
        ak = bk;
        bk = tk;
        int tn = an;
        an = bn;
        bn = tn;
      }
      System.out.println((bn < ak && 2 * (ak - bn) <= an) ? "Yes" : "No");
    }
  }
}

Measured memory_bytes: 50660
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
    vector<double> pow;
    pow.push_back(1);
    double N, K;
    cin >> N >> K;
    while(pow[pow.size()-1]<K) {
        pow.push_back(pow[pow.size()-1]*2);
    }

    vector<double> vec(N+1, 0);
    int cnt=0;
    for(int n=1; n<=N; n++) {
        if(cnt<pow.size() && n==pow[cnt]) {
            vec[n] = pow.size()-cnt-1;
            cnt++;
        } else if(cnt<pow.size()) {
            if(pow[pow.size()-cnt-1]*n>=K) {
                vec[n] = pow.size()-cnt-1;
            } else {
                vec[n] = pow.size()-cnt;
            }
        }
    }

    double ans=0;
    for(int n=1; n<=N; n++) {
        ans += (double)1/(N*pow[vec[n]]);
    }
    cout << setprecision(15) << ans << endl;


    return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  string s[n];
  for(int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);

  for(int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
 
int main() {
	// your code goes here
	int n;
	
	string s;
	cin>>s;
    n=s.length();
    int p=2019;
	//int val[n];
	ll ans=0;
	
 
	unordered_map<ll,ll>mp;
	ll sum[n+1];
	sum[n]=0;
	int power=1;
	for(int i=n-1;i>=0;i--)
	{
		sum[i]=sum[i+1]+power*(s[i]-'0');
		sum[i]=sum[i]%p;
		power=power*10;
		power=power%p;
		// mp[sum[i]]++;
	}
	for(int i=0;i<=n;i++)
	mp[sum[i]]++;
	for(auto x:mp)
	ans+=((x.second-1)*x.second)/2;
	cout<<ans;
 
 
 
 
 
	return 0;
}



Measured memory_bytes: 5320
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong p) {
	int i=0;
	for(int j = 0; j < k; j++ ) {
		llong sum = 0;
		while( sum + T[i] <= p) {
			sum += T[i];
			i++;
			if(i == n ) return n;
		}
	}
	return i;
}

int solve() {
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;
	while(right - left > 1) {
		mid = (left + right) / 2;
		int v = check(mid);
		if(v == n) right = mid;
		else left = mid;
	}
	return right;
}

main() {
	cin >> n >> k;
	for( int i = 0; i < n; i++) cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}

Measured memory_bytes: 3860
#include <cstdio>
#include <algorithm>
#include <functional>

template <typename T>
class segment_tree{
    using F = T(*)(T, T);
    T *tree;
    std::size_t len;
    T e;
    F op;
public:
    segment_tree(F func, T ident, std::size_t n) : op(func), e(ident), len(n){
        tree = new T[2 * len];
        for(std::size_t i = 1; i < 2 * len; ++i){
            tree[i] = ident;
        }
    }
    ~segment_tree(){
        delete[] tree;
    }

    void update(std::size_t pos, T val){
        tree[len + pos] = val;
        for(pos = (len + pos) / 2; pos > 0; pos >>= 1){
            tree[pos] = op(tree[2 * pos], tree[2 * pos + 1]);
        }
    }
    
    T query(std::size_t left, std::size_t right){
        left += len;
        right += len;

        T v_l = e, v_r = e;
        while(left < right){
            if(left  & 1) v_l = op(v_l, tree[left++]);
            if(right & 1) v_r = op(tree[right - 1], v_r);
            left >>= 1;
            right >>= 1;
        }
        return op(v_l, v_r);
    }
};

int main(){
    int n, q, com, x, y;
    std::scanf("%d%d", &n, &q);
    segment_tree<int> st([](int x, int y){ return std::min(x, y); }, (1U << 31) - 1, n);

    for(int i = 0; i < q; ++i){
        std::scanf("%d%d%d", &com, &x, &y);
        if(com == 0){
            st.update(x, y);
        }else{
            std::printf("%d\n", st.query(x, y+1));
        }
    }

    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

vector<int> tsort(vector<vector<int>> G){

  int n = G.size();
  vector<int> sorted,indeg(n,0); //入次数
  for(int u = 0; u < n; u++){
    for(int v : G[u]){
      indeg[v]++;
    }
  }

  priority_queue<int,vector<int>,greater<int>> q; //最小値
  for(int u = 0; u < n; u++){
    if(indeg[u] == 0) q.push(u);
  }
  while(!q.empty()){
    int u = q.top(); q.pop();
    for(int v : G[u]){
      indeg[v]--;
      if(indeg[v] == 0) q.push(v);
    }
    sorted.push_back(u);
  }
  return sorted;
}

using P = pair<int,int>;

signed main(){

  int n; cin >> n;
  map<pair<int,int>,int> dic;
  int k = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      dic[P(i,j)] = k++;
    }
  }

  vector<vector<int>> G(k);
  for(int i = 0; i < n; i++){
    vector<int> v(n-1);
    for(int j = 0; j < n-1; j++){
      cin >> v[j];
      v[j]--;
      if(j == 0) continue;
      int preu = dic[minmax(i,v[j-1])];
      int u = dic[minmax(i,v[j])];
      G[preu].push_back(u);
    }
  }

  auto t = tsort(G);
  if(t.size() != k){
    cout << -1 << endl;
    return 0;
  }
  vector<int> dp(k,0);
  int ans = 0;
  for(int i = 0; i < k; i++){
    for(int j : G[t[i]]){
      dp[j] = max(dp[j],dp[t[i]]+1);
      ans = max(ans,dp[j]);
    }
  }
  cout << ans+1 << endl;

  return 0;
}


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

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

int main() {
  int n,m;
  cin >> n >> m;
  ll dp[n+10];
  rep(i,n+10) dp[i] = 0;
  dp[0] = 1;
  bool a[n+1];
  rep(i,n+1) a[i] = 1;
  int ai;
  rep(i,m) {
    cin >> ai;
    a[ai] = 0;
  }
  rep(i,n) {
    if (a[i]) {
      dp[i+1] = (dp[i]+dp[i+1])%MOD;
      dp[i+2] = (dp[i]+dp[i+2])%MOD;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 4444
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
typedef long long ll;
#define INF 0x3f3f3f3f

using namespace std;
int main(int argc, char *argv[]) {
	set<string> s;
	int n;
	cin >> n;
	string last;
	cin >> last;
	s.insert(last);
	for(int i = 1; i < n; i++)
	{
		string t;
		cin >> t;
		if(last[last.size() - 1] != t[0] || s.find(t) != s.end()) {
			cout << "No" << endl;
			return 0;
		}
		s.insert(t);
		last = t;
	}
	cout << "Yes" << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  while(N > 0) {
    N = N - 1000;
  }
  if (N == 0) {
    cout << 0 << endl;
  }
  else {
    cout << - N << endl;
  }
}

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

int main(){
	int sec;
	scanf("%d", &sec);
	int h = sec / 3600;
	sec %= 3600;
	int m = sec / 60;
	int s = sec % 60;
	printf("%d:%d:%d\n", h, m, s);
}



Measured memory_bytes: 3220
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

LL fact[1000005];
LL inv_fact[1000005];

LL mod_pow(LL a, LL p) {
	LL tmp = a;
	LL ret = 1;
	while (p) {
		if (p & 1) ret = (ret*tmp) % MOD;
		p >>= 1;
		tmp = (tmp*tmp) % MOD;
	}
	return ret;
}

LL mod_inv(LL a) {
	return mod_pow(a, MOD - 2);
}

LL f(int n, int k) {
	if (2 * k - n < 0)return 0;
	return (((fact[k - 1] * fact[k]) % MOD) * inv_fact[2*k-n]) %MOD;
}

int main() {
	int n;
	scanf("%d", &n);
	fact[0] = inv_fact[0] = 1;
	FOR(i, 1, 1000005) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = mod_inv(fact[i]);
	}
	LL ret = 0;
	LL cum = 0;
	FOR(k, (n + 1) / 2, n) {
		auto ways = (f(n, k) - f(n, k - 1) + MOD) % MOD;
		ret = (ret + (k*ways)%MOD) % MOD;
	}
	cout << ret << endl;
	return 0;
}

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

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

    long long ans = 1;
    for (int i = 1; i <= N; i++) {
        ans *= i;
        if (ans / 1000000007 > 0) {
            ans %= 1000000007;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=105,M=10005;

bool f[M];
int n,s[N]; 

int main(){
	scanf("%d",&n);
	f[0]=true;
	rep(i,1,n){
		scanf("%d",s+i);
		per(j,M-1,s[i]){
			f[j]|=f[j-s[i]];
		}
	}
	per(i,M-1,0) if(f[i]&&(!i||i%10!=0)) return printf("%d\n",i),0;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n; cin >> n;
    cout << n * 800 - (n/15) * 200 << endl;
    return 0;
}

Measured memory_bytes: 256
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0);def f(i,c)(h=(H[i].map{|e|f e,i}.max||0)+1)>=K&&c!=1&&(h=0;$r+=1);h end;N,K,Q,*A=`dd`.split.map &:to_i;H=Hash.new{|h,k|h[k]=[]};2.upto(N){|i|H[A[i-$r=2]]<<i};f(1,1);p$r--~Q/Q

Measured memory_bytes: 225316
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

ary = [ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 ]

main = readInt >>= print . ( ary !! ) . pred

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1.0)

typedef long long ll;
const int maxn=1e5+10;
ll a[maxn];

int main()
{
    ll n,sum,ans;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    sort(a+1,a+1+n);
    if(n%2)
    {
        ans=0;
        sum=0;
        int m=n/2+1;
        for(int i=1;i<=m-2;i++)
            sum-=2*a[i];
        sum-=(a[m-1]+a[m]);
        for(int i=m+1;i<=n;i++)
            sum+=2*a[i];
        ans=max(ans,sum);
        sum=0;
        for(int i=m+2;i<=n;i++)
            sum+=2*a[i];
        sum+=a[m]+a[m+1];
        for(int i=m-1;i>=1;i--)
            sum-=2*a[i];
        ans=max(sum,ans);
        cout << ans << endl;
    }
    else
    {
        ans=0;
        int m=n/2;
        int l=1,r=n;
        for(int i=1;i<m;i++)
        {
            ans+=a[r]*2;
            ans-=a[l]*2;
            r--,l++;
        }
        cout << ans+a[r]-a[l] << endl;
    }
    return 0;
}


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

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

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int n, k;
    cin >> n >> k;

    ll ans = 0;
    for (ll i = k; i <= n+1; ++i) {
        ans += (i*(2*n-i+1))/2 - (i*(i - 1) / 2) + 1;
        ans %= MOD;
    }

    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
#include<valarray>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<list>
#include<utility>
#include<bitset>
#include<algorithm>
#include<functional>
#include<ios>
#include<bits/ostream_insert.h>
#include<iosfwd>
#include<exception>
#include<bits/char_traits.h>
#include<bits/localefwd.h>
#include<bits/ios_base.h>
#include<streambuf>
#include<bits/basic_ios.h>
#include<bits/ostream.tcc>
#include<bits/stl_algobase.h>
#include<bits/postypes.h>
#include<cwchar>
#include<bits/cxxabi_forced.h>
#include<bits/c++config.h>
#include<ostream>
#include<istream>
#include<bits/c++config.h>
#include<bits/stringfwd.h>
#include<bits/allocator.h>
#include<bits/cpp_type_traits.h>
#include<bits/ostream_insert.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator.h>
#include<bits/stl_function.h>
#include<ext/atomicity.h>
#include<bits/localefwd.h>
#include<bits/locale_classes.h>
#include<ext/numeric_traits.h>
#include<bits/stl_algobase.h>
#include<bits/range_access.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<iosfwd>
#include<exception>
#include<bits/char_traits.h>
#include<bits/localefwd.h>
#include<bits/ios_base.h>
#include<streambuf>
#include<bits/basic_ios.h>
using namespace std;
int n,c,k=0;
pair<int,int> ans[100];
pair<int,pair<int,int> > t[100000];
int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++){
		int a,b,d;
		scanf("%d%d%d",&a,&b,&d);
		t[i].first=a;
		t[i].second.first=b;
		t[i].second.second=d;
	}
	sort(t,t+n);
//	cout<<"-----------------------------------------------"<<endl;
//	for(int i=0;i<n;i++) cout<<t[i].first<<' '<<t[i].second.first<<' '<<t[i].second.second<<endl;
//	cout<<"-----------------------------------------------"<<endl;
	ans[0].first=t[0].second.first;
	ans[0].second=t[0].second.second;
	for (int i=1;i<n;i++){
		int f=1,l=-1;
		for (int j=0;j<=k;j++)
			if (ans[j].first<t[i].first||(ans[j].first==t[i].first&&ans[j].second==t[i].second.second)){
				f=0;
				if (l==-1||t[i].first-ans[l].first>t[i].first-ans[j].first)
					l=j;
			}
		if (f==1) k++;
		if (l==-1) l=k;
//		cout<<f<<endl;
		ans[l].first=t[i].second.first;
		ans[l].second=t[i].second.second;
	}
//	cout<<"-----------------------------------------------"<<endl;
//	for(int i=0;i<10;i++) cout<<ans[i].first<<' '<<ans[i].second<<endl;
	cout<<k+1;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <functional>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int ans = max(2*a-1, a+b);
  ans = max(ans, 2*b-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;

	static int calc(boolean[] ok, int pos) {
		int ret = 0;
		while (true) {
			while (pos < ok.length && !ok[pos]) {
				pos += 2;
			}
			if (pos >= ok.length) break;
			int prev = pos;
			while (pos < ok.length && ok[pos]) {
				pos += 2;
			}
			ret += Math.max(0, (pos - prev) / 2 - N + 1);
		}
		return ret;
	}

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			sc.nextInt();
			char[] s = sc.next().toCharArray();
			boolean[] ok = new boolean[s.length];
			for (int i = 1; i < s.length - 1; ++i) {
				ok[i] = s[i] == 'O' && s[i - 1] == 'I' && s[i + 1] == 'I';
			}
			System.out.println(calc(ok, 1) + calc(ok, 2));
		}
	}
}

Measured memory_bytes: 18000
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  




void solve(){
	int h , n ;
	cin >> h >> n; 
	vector<pii> atk(n);
	rep(i,0,n){
		cin >> atk[i].fst >> atk[i].snd;
	}
	vi dp(h+10,MOD);
	dp[h] = 0 ;
	for(int i = h ; ~i ; --i){
		rep(j,0,n){
			int cur = max(i-atk[j].fst,0ll);
			dp[cur] = min(dp[cur],dp[i]+atk[j].snd);
		}
	}
	trace(dp);
	cout << dp.front() << endl;
}
signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3736
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

res = sum(B)
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        res += C[A[i]-1]

print(res)

Measured memory_bytes: 3064
from scipy.sparse.csgraph import floyd_warshall

# ダイクストラではなくワーシャルフロイドで解く
N, M, L = map(int, input().split())
# graph = [[] for _ in range(N)]
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    if c > L:
        continue
    distant[a][b] = c
    distant[b][a] = c

distant = floyd_warshall(distant)
another = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if distant[i][j] <= L:  # 行けるところまでいくという印象
            another[i][j] = 1
another = floyd_warshall(another)
Q = int(input())
for _ in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    if another[s][t] == float('inf'):
        print(-1)
        continue
    print(int(another[s][t])-1)
    # if distant[s][t] == float('inf'):
    #     print(-1)
    #     continue
    # print(int(distant[s][t])//L + min(1, int(distant[s][t]) % L) - 1)
# 燃料が4で
# 1 -> 4 -> 2
# のとき、距離は7だから一見すると補給回数は1で良さそうだけど、実は2回必要
# 今、２点間の最小距離を求めておいて、もう一つのグラフは「最短距離がL以下の2点に辺(重み1)を張る」


Measured memory_bytes: 19036
#include <iostream>
#include <string>

using namespace std;

int main(){
    string str,ans;
    int now=0;
    cin>>str;

    for(int i=0;str[i]!='\0';i++){
        switch (str[i]) {
            case '0':
                ans[now]='0';
                now++;
                break;
            case '1':
                ans[now]='1';
                now++;
                break;
            case 'B':
                if(now>0){
                    now--;
                }
                break;
        }
    }

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

    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, M = map(int, input().split())
    edge = [[] for _ in range(N)]

    for i in range(M):
        fr, to = map(int, input().split())
        fr -= 1
        to -= 1
        edge[fr].append(to)

    maxLeng = [-1] * N

    def search(now):
        if maxLeng[now] != -1:
            return maxLeng[now]

        ret = 0
        for to in edge[now]:
            ret = max(ret, search(to))

        maxLeng[now] = ret + 1
        return ret + 1

    ans = 0
    for i in range(N):
        ans = max(ans, search(i))

    print(ans - 1)

sol()

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

int main() {
	int a, b, c,s1,s2,s3,count=0,d1,d2,d3;
	cin >> a >> b >> c;
	if(a>=b&&a>=c)
		if (b >= c) {
			d1 = a;
			d2 = b;
			d3 = c;
		}
		else {
			d1 = a;
			d2 = c;
			d3 = b;
		}
	else if(b>=c)
		if (a >= c) {
			d1 = b;
			d2 = a;
			d3 = c;
		}
		else {
			d1 = b;
			d2 = c;
			d3 = a;
		}
	else if (b >= a) {
		d1 = c;
		d2 = b;
		d3 = a;
	}
	else {
		d1 = c;
		d2 = a;
		d3 = b;
	}

	s1 = d1 - d2; s2 = d1 - d3;
	count += s1; s3 = s2 - s1;
	count += (s3 / 2); 
	if (s3 % 2 == 1) count += 2;
	cout << count << endl;


	return 0;
}

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

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let (x, y) = (it.next().unwrap(), it.next().unwrap());

    let mut a: HashSet<_> = [1, 3, 5, 7, 8, 10, 12].iter().cloned().collect();
    let mut b: HashSet<_> = [4, 6, 9, 11].iter().cloned().collect();
    //    let mut c: HashSet<_> = [2].iter().cloned().collect();
    a.insert(x);
    a.insert(y);
    if a.len() == 7 {
        println!("Yes");
        return;
    }
    b.insert(x);
    b.insert(y);
    if b.len() == 4 {
        println!("Yes");
        return;
    }

    if x == 2 && y == 2 {
        println!("Yes");
        return;
    }
    println!("No");
}


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

int main()
{
	int N;
	int64_t T;
	scanf("%d%lld", &N, &T);
	int64_t end{}, sum{};
	for (int i{}; i < N; i++)
	{
		int64_t t;
		scanf("%lld", &t);
		if (end <= t) sum += T;
		else sum += t + T - end;
		end = t + T;
	}
	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
  { 
   int a,b,c,d,e;
   scanf("%d %d %d",&a,&b,&c);
   d=b;
   b=a;
   a=d;
   e=c;
   c=a;
   a=e;
  printf("%d %d %d",a,b,c);
  return 0;
  }
   

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;

ll modfact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
    return result; 
} 
 
int main() 
{
	fast;
	ll n,m; cin>>n>>m;
	ll ans = 0;
	if(abs(n-m) >= 2) cout << 0 << endl;
	else if(abs(n-m) == 1)
	{
		ans = ((modfact(n,MOD) % MOD) * (modfact(m,MOD) % MOD)) % MOD;
		cout << ans << endl;
	}
	else
	{
		ans = 2*(((modfact(n,MOD)) % MOD) * ((modfact(m,MOD)) % MOD)) % MOD;
		cout << ans << endl;
	}
 	return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

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

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

	if (S == "Sunny"){
		cout << "Cloudy" << endl;
	}
	if (S == "Cloudy"){
		cout << "Rainy" << endl;
	}
	if (S == "Rainy"){
		cout << "Sunny" << endl;
	}

	return 0;
}


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

int main() {
  int n,k;
  int ans=1;
  cin >> n >> k;
  for (int i=0; i<n; i++) {
    if(ans+k>2*ans) {
      ans *= 2;
    } else {
      ans += k;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 9 || b >= 9){
        print (":(");
    }
    else if (a <= 8 && b <= 8){
        print ("Yay!");
    }
return 0;
}     

Measured memory_bytes: 256
#include <iostream>
#include <stack>

int main(){
	std::stack<int> garage;
	int vehicle_num; //railroad car
	
	while(std::cin >> vehicle_num){
		if(vehicle_num != 0) garage.push(vehicle_num);
		else{
			std::cout << garage.top() << std::endl;
			garage.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll mod = 1e9+7;

// mod pにおけるi(1<=i<=n)の逆元
vector<ll> list_minv(ll n, ll m) {
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
        inv[i] = inv[m % i] * (m - m / i) % m;
    }
    return inv;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int mx = 1;
    rep(i,n) cin >> a[i], chmax(mx, a[i]);

    auto prime_factrize = [&](ll a) -> map<ll,ll> {
        map<ll, ll> m;
        for (ll i = 2; i*i <= a; i++) {
            if (a%i != 0) continue;
            ll cnt = 0;
            while (a%i == 0) {
                cnt++;
                a /= i;
            }
            m[i] += cnt;
        }
        if (a > 1) m[a]++;
        return m;
    };

    map<ll, ll> p;
    rep(i,n) {
        map<ll, ll> t = prime_factrize(a[i]);
        for (auto v : t) {
            if (p[v.first] < v.second) p[v.first] = v.second;
        }
    }

    ll lcm = 1;
    for(auto v: p) {
        rep(i,v.second) (lcm*=v.first)%=mod;
    }

    vector<ll> minv = list_minv(mx, mod);

    ll ans = 0;
    rep(i,n) {
        (ans += lcm*minv[a[i]]) %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8704
<?php
$lengthA = (int) fgets(STDIN);
$stdinA = explode(" ",fgets(STDIN));

$lengthKey = (int) fgets(STDIN);
$stdinKey = explode(" ",fgets(STDIN));
// print_r($stdinA);

$count = 0;

for($j=0; $j<$lengthKey; ++$j){
    $result = linearSearch($stdinA, $stdinKey[$j], $lengthA);
    if($result == 1){
        $count++;
    }
}

echo $count . PHP_EOL;

function linearSearch($stdin, $key, $N){
    $i=0;
    while((int)$stdin[$i] != (int)$key){
        $i++;
        // NotFound
        if($i===$N){
            return 0;
        }
    }
    return 1;
}


Measured memory_bytes: 10996
#include<iostream>
using namespace std;
int main(){
  int a,b,c,count,ans,i;
  cin >> a >> b >> c;
  ans = 0;
  count = 0;
  for(i=0;i<b;i++){
    count += a;
    if(count%b==c){
      ans = 1;
      break;
    }
  }
  cout << ((ans == 1) ? "YES":"NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

string s;
cin>>s;
int n;
n=s.size();
if(s[n-1]=='s')
s+="es";
else
s+='s';

cout<<s<<endl;

return 0;
}


Measured memory_bytes: 3664