akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");

		int A = Integer.parseInt(lines[0]);
		int B = Integer.parseInt(lines[1]);

		if(A > 12) {
			System.out.println(B);
		}else if(A > 5) {
			System.out.println(B/2);
		}else {
			System.out.println(0);
		}
	}

}


Measured memory_bytes: 35908
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n,m,ans1 = 0,ans2 = 0,d = 1000000;
  cin >> n >> m;
  vector <ll> v(m),stp(n+2);
  for (int i = 0; i < m; ++i)
  {
    cin >> v[i];
  }
  for (int i = 0; i < m; ++i)
  {
    stp[v[i]] = -1;
  }
  stp[0] = 1;
  if (stp[1] != -1)
  {
    stp[1] = 1;
  }
  else
    stp[1] = 0;
  for (int i = 2; i < n+1; ++i)
  {
    if (stp[i] == -1)
    {
      stp[i] = 0;
      continue;
    }
    stp[i] = (stp[i-1]+stp[i-2])%mod;
  }
  cout << stp[n]%mod << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll func(pair<ll,ll> a , pair<ll,ll> b ){
	return a.first + a.second > b.first+b.second;
}

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

	ll N ;
	vector<pair<ll,ll> > AB;

	cin >> N ; 
	rep(i, N){
		ll inpa, inpb;
		cin >> inpa >> inpb ;

		AB.pb(mp(inpa, inpb));
	}

	sort(all(AB), func);

	ll A = 0;
	ll B = 0;
	rep(i, N){
		if(i % 2 == 0) A += AB[i].first;
		else B += AB[i].second;
	}

	cout << A-B << endl;
	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
# coding: utf-8
S = str(input())
n = len(S) - 1
ops = []
for i in range(2**n):
    op = [""] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            op[n-1-j] = "+"
    ops.append(op[:])
    
ans = 0
for op in ops:
    s = [t for t in S]
    tmp = ""
    for k in range(len(op)):
        tmp += s[k]
        tmp += op[k]
    tmp += s[-1]
    ans += eval(tmp)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    if(a+b>c+d) cout<<"Left"<<endl;
    else if(a+b==c+d) cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,x = LI()
    return 3 * (n-fractions.gcd(n,x))


print(main())



Measured memory_bytes: 5456
N, M = map(int, input().split(' '))
cands = None
for _ in range(N):
  items = set(list(map(int, input().split(' ')))[1:])
  if cands is None:
    cands = items
    continue
  else:
    cands &= items
  
  if len(cands) == 0:
    break
print(len(cands))
 

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long N, long long K, long long Q, std::vector<long long> A){

    lli ans = INF;
    REP(i,0,N){
        vector<lli> v,p;
        REP(j,0,N){
            if(A[j]<A[i]){
                if(v.size()>=K){
                    SORT(v);
                    REP(x,0,v.size()-K+1)p.push_back(v[x]);
                }
                v.clear();
            }
            else{
                v.push_back(A[j]);
            }
        }
        if(v.size()>=K){
            SORT(v);
            REP(x,0,v.size()-K+1)p.push_back(v[x]);
        }
        SORT(p);
        if(p.size()>=Q)chmin(ans,p[Q-1]-p[0]);
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    func(N, K, Q, std::move(A));
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
		if(a<0){
			a=-a;
			b=-b;
			c=-c;
		}
		if(d<0){
			d=-d;
			e=-e;
			f=-f;
		}
		y=((c*d)-(a*f))/((b*d)-(a*e));
		x=((b*f)-(c*e))/((b*d)-(a*e));
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 2660
#include<bits/stdc++.h>
using namespace std;
long long m(long long a,long long b){
    long long r=1;
    while(b--){
        r*=a;
    }
    return r;
}
int main(){
    long long n;cin>>n;
    vector<long long> a;
    if(n==0){
        cout<<0;
        return 0;
    }
    long long t=0;
    while(n){
        a.push_back(abs(n%2));
        n-=abs(n%2)*m(-1,t);
        n/=2;
        t++;
    }
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++) cout<<a[i];
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

int main()
{
		int N;
		cin >> N;
		vector<int> H(N);
		for (int i = 0; i < N; i++) cin >> H[i];

		int cnt = 1;
		int maxH = H[0];
		for (int i = 0; i < N-1; i++) {
			if (H[i + 1] >= maxH) {
				maxH = H[i + 1];
				cnt++;
			}
		}
		cout << cnt << endl;
}

Measured memory_bytes: 256
x = raw_input().split()
a1 = int(x[0])
b1 = int(x[1])
a2 = float(x[0])
b2 = float(x[1])

p1 = a1 / b1
r = a1 % b1
p2 = a2 / b2

print u"%d %d %f" % (p1, r, p2)

Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define mt make_tuple
#define ldb double
#define pii pair<int,int>
#define pll pair<ll,ll>
template<typename T>void ckmn(T &a,T b){a=min(a,b);}
template<typename T>void ckmx(T &a,T b){a=max(a,b);}
int ri(){int x;scanf("%i",&x);return x;}
void rd(){}
template<typename...T>void rd(int &x,T&...args){scanf("%i",&x);rd(args...);}
template<typename...T>void rd(ll &x,T&...args){scanf("%lld",&x);rd(args...);}
template<typename...T>void rd(ldb &x,T&...args){scanf("%lf",&x);rd(args...);}
template<typename...T>void rd(pii &x,T&...args){scanf("%i %i",&x.first,&x.second);rd(args...);}
const int mod=1e9+7;//998244353
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
void ckadd(int&a,int b){a=add(a,b);}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
void cksub(int&a,int b){a=sub(a,b);}
int mul(int a,int b){return (ll)a*b%mod;}
void ckmul(int&a,int b){a=mul(a,b);}
int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;}
int inv(int x){return powmod(x,mod-2);}
const int N=5005;
struct SUM{
	int sum[N*2];
	void Add(int i,int x){ckadd(sum[i+N],x);}
	int Get(int i){return sum[i+N];}
}SM;
int dp[N][N],res[N],sum_dp[N];
int main(){
	int n,A,B;
	rd(n,A,B);
	if(A>B)swap(A,B);
	dp[0][0]=1;
	sum_dp[0]=1;
	for(int i=1;i<=n+1;i++){
		res[i]=mul(2,res[i-1]);
		for(int suf=0;suf<=i;++suf){
			if(suf>0)dp[i][suf]=dp[i-1][suf-1];
			ckadd(dp[i][suf],SM.Get(i-suf));
			//printf("%i ",dp[i][suf]);
		}
		for(int j=2;j<=A;j++){
			if(i-j>=0)ckadd(dp[i][1],sum_dp[i-j]);
		}
		for(int suf=0;suf<=i;suf++){
			if(i<=n&&suf>=B){
				ckadd(res[i],dp[i][suf]);
				dp[i][suf]=0;
			}else ckadd(sum_dp[i],dp[i][suf]);
		}
		//printf("%i\n",res[i]);
		if(i>=A){
			for(int suf=0;suf<=i-A;++suf){
				//if(dp[i-A][suf])printf("%i %i\n",i-A-suf,dp[i-A][suf]);
				SM.Add(i-A-suf,dp[i-A][suf]);
			}
		}

		//for(int suf=0;suf<=i;suf++)printf("%i ",dp[i][suf]);
		//printf("%i\n",res[i]);
	}
	int ans=res[n];
	for(int i=B+1;i<=n+1;i++)ckadd(ans,dp[n+1][i]);
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 70652
n=gets.to_i
m=2**n
a=[]
m.times do
  a<< gets.to_i
end
1.upto(n) do |i|
  (2**(n-i)).times do |j|
    x=a[2*j]
    y=a[2*j+1]
    a[j]=x==y ? x:(x-y).abs
  end
end
p a[0]

Measured memory_bytes: 4276
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll n;
ll a[55];
signed main() {
	ll ans = 0;
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n - 1) {
		for (ll j = i + 1; j < n; j++) {
			ans += a[i] * a[j];
		}
	}
	cout << ans << endl;
	ggr
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;

int t[nax];

int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	REP(i, n) scanf("%d", &t[i]);
	REP(i, n + 5) t[n+i] = t[i];
	ll ans = -1;
	FOR(move, 0, n - 1) {
		ll maybe = (ll) x * move;
		REP(i, n) maybe += t[i];
		if(ans == -1 || ans > maybe)
			ans = maybe;
		
		
		REP(i, 2 * n + 2) mini(t[i], t[i+1]);
	}
	assert(ans != -1);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 5000
#define M 500000
#define MAX(a, b) ((a)>(b)?(a):(b))

typedef struct tagBX {
    short b;
    short x;
    struct tagBX *next;
} BX;

BX bx[M], *abx[N + 1];

short work1[N+1];
short work2[N+1];

int main(void) {
    int m, n, a, i, j;
    int ans = 0;
    short *prev, *now, *tmp;
    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++) {
        scanf("%d %d %d", &a, &bx[i].b, &bx[i].x);
        bx[i].next = abx[a];
        bx[i].x += 1;
        abx[a] = bx + i;
    }
    prev = work1;
    now = work2;
    for (i = 1; i <= n; i++) {
        BX *p;
        memset(now, 0, sizeof(short)*i);
        for (p = abx[i]; p != NULL; p = p->next) {
            if (p->x > now[p->b]) now[p->b] = p->x;
        }
        for (j = 1; j <= i; j++) {
            now[j] = MAX(now[j], MAX(prev[j], prev[j-1])-1);
            ans += now[j] > 0;
        }
        tmp = prev;
        prev = now;
        now = tmp;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 10596
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll a, b;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
int mark[5010];
int main()
{
    IOS;
    int n;cin>>n;
    int x,y;cin>>x>>y;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int d=j-i;;
            int temp=abs(x-i)+1+abs(y-j);
            d=min(d,temp);
            mark[d]++;
        }
    }
    for(int i=1;i<n;i++)cout<<mark[i]<<endl;
}








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

int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  a.push_back(a[0]+k);
  int l =0;
  rep(i,n){
     l = max(l,a[i+1]-a[i]);
  }
  
  int ans = k-l;
  cout << ans << endl;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {

		// Listに標準入力の値を取得
		ArrayDeque<String> inputs = new ArrayDeque<>();
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			while (br.ready()) {
				String[] lineArray = br.readLine().split(" ");
				Arrays.<String> stream(lineArray).forEach(s -> inputs.add(s.trim()));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		String str1 = inputs.pop();
		String str2 = inputs.pop();
		
		char[] c1 = str1.toCharArray();
		char[] c2 = str2.toCharArray();
		int result = 0;
		
		for (int i = 0; i < c1.length; i++) {
			if (c1[i] != c2[i]) {
				result++;
			}
		}
		System.out.println(result);
	}
}


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

int	main()
{
  int	n, a, b, t_sum, sum = 0;
  
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++)
  {
    t_sum = 0;
    for (int j = i; j > 0; j = j / 10)
    {
      t_sum += j % 10;
    }
    if (a <= t_sum && t_sum <= b)
      sum += i;
  }
  cout << sum << endl;
  return (0);
}

Measured memory_bytes: 3592
use std::io::*;
use std::str::FromStr;


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let mut a: Vec<usize> = (0..n).map(|_| read()).collect();
    let a_max = *a.iter().max().unwrap();
    let mut dp = vec![0; a_max+1];
 
    for &v in &a {
        let mut i = 1;
        while i*v <= a_max {
            dp[i*v] +=1;
            i+=1;
        }

    }
    let ans = a.iter().filter(|&n| dp[*n] == 1).count();
    print!("{}", ans);
}


Measured memory_bytes: 7548
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  string ans="kogakubu10gokan";
  rep(i,a){
    string s;int n;
    cin>>n>>s;
    if(n<=b)ans=s;
  }
  cout<<ans<<endl;


}

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

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    int x, y;
    vector<vector<int>> from(n + 1), to(n + 1);

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        from.at(y).push_back(x);
        to.at(x).push_back(y);
    }

    vector<int> dp(n + 1), indeg(n + 1);
    queue<int> q;

    for(int i = 1; i <= n; ++i) {
        indeg.at(i) = from.at(i).size();
        if(indeg.at(i) == 0) {
            q.push(i);
        }
    }

    int qf;

    while(q.size() != 0) {
        qf = q.front();
        q.pop();
        for(int qft: to.at(qf)) {
            dp.at(qft) = max(dp.at(qft), dp.at(qf) + 1);
            if(--indeg.at(qft) == 0) q.push(qft);
        }
    }

    int ans = 0;

    for(int i = 1; i <= n; ++i) {
        ans = max(ans, dp.at(i));
    }

    printf("%d\n", ans);

    return 0;
}

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

int main(){
  int H,W,K;cin>>H>>W>>K;
  vector<vector<char>> c(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int ans=0;
  
  for(int i=0; i<(1<<H); i++){
    for(int j=0; j<(1<<W); j++){
      int cnt = 0;
      
      for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
		  if(i&(1<<h) || j&(1<<w))continue;
          if(c[h][w]=='#')cnt++;
        }
      }
      if(K==cnt)ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
ll a[110],b[110];
ll dp[100005];
int main()
{
	ll n,w;
	cin>>n>>w;
	for(ll i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}

	for(ll i=1;i<=n;i++){
		for(ll j=w;j>=a[i];j--){
			dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
		}
	}
	
	cout<<dp[w];

}

Measured memory_bytes: 4424
import java.util.Scanner;

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

		if (s.indexOf("RRR") != -1) {
			System.out.println(3);
		} else if (s.indexOf("RR") != -1) {
			System.out.println(2);
		} else if (s.indexOf("R") != -1) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 35604
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}




void oneCase () {
    int n;
    cin >> n;
    string line;
    cin >> line;
    vector<set<int>> positions(26);
    for (int pos = 0; pos < n; ++pos) {
        auto letter = line[pos];
        auto letterNum = int(letter) - 97;
        positions[letterNum].insert(pos);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int pos;
            char letter;
            cin >> pos >> letter;
            --pos;
            auto oldNum = int(line[pos]) - 97;
            positions[oldNum].erase(pos);
            positions[int(letter) - 97].insert(pos);
            line[pos] = letter;
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            --r;
            int counter = 0;
            for (int ln = 0; ln < 26; ++ln) {
                auto left = positions[ln].lower_bound(l);
                if (left == positions[ln].end()){
                    continue;
                }
                counter += *left <= r;
            }
            cout << counter << "\n";
        }
    }
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  rep(i, n) cout << s[i];
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int n, m; cin>>n>>m;
    vector<bool> a(n + 10, true);
    for(int i=0; i<m; i++){
        int A; cin>>A;
        a[A] = false;
    }

    vector<ll> dp(n + 10, 0);
    dp[0] = 1;
    if(a[1]) dp[1] = 1;
    for(int i=1; i<n; i++){
        if(!a[i + 1]) continue;

        (dp[i + 1] = dp[i] + dp[i - 1]) %= MOD;
    }

    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;
int a[MAXN];
map<int,int> odd;
map<int,int> even;
typedef pair<int,int> pa;
pa od[MAXN];
pa ev[MAXN];
int main(){
	int n;
	int mxo=0,mx1=0,mxe=0,mx2=0;
	int num1,num2,num3,num4;
	int inf=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]); 
		inf=inf<a[i]?a[i]:inf;
		if(i&1){
			odd[a[i]]=odd.count(a[i])?odd[a[i]]+1:1;
		}
		else{
			even[a[i]]=even.count(a[i])?even[a[i]]+1:1;
		}
	}
	n>>=1;
	int cnt=0;
	for(map<int,int>::iterator it=odd.begin();it!=odd.end();it++){
		od[++cnt]=make_pair(it->second,it->first);
	}
	cnt=0;
	for(map<int,int>::iterator it=even.begin();it!=even.end();it++){
		ev[++cnt]=make_pair(it->second,it->first);
	}
	sort(od+1,od+n+1);
	sort(ev+1,ev+n+1);
	if(n==1){
		mx1=mx2=0;
	}
	mxe=od[n].first,mxo=ev[n].first;
	mx1=od[n-1].first,mx2=ev[n-1].first;
	num1=od[n].second,num3=ev[n].second;
	num2=od[n-1].second,num4=ev[n-1].second;
	if(num1!=num3){
		printf("%d\n",n*2-mxe-mxo);
	} 
	else{
		printf("%d\n",min(n*2-mx1-mxe,n*2-mx2-mxo));
	}
	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

int main(){
    ll ans=0;
    ll a,b,n;cin >> a >>b >>n;
    if(n/b==0){
        cout << a*n/b-n/b*a <<endl;
        return 0;
    }
    rep(i,n/b){
        if(i>a)break;
        ll x=i*b+b-1;
        chmax(ans,a*x/b-x/b*a);
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 3620
N = gets.to_i
h = gets.split.map(&:to_i)
h.unshift(0)

dp = Array.new(N+1, Float::INFINITY)

dp[0] = dp[1] = 0
dp[2] = (h[2] - h[1]).abs

for i in 3..N do
  dp[i] = [
    dp[i-1] + (h[i] - h[i-1]).abs,
    dp[i-2] + (h[i] - h[i-2]).abs
  ].min
end

puts dp[N]


Measured memory_bytes: 11780
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1e9 as usize + 9;

fn main() {
    input! {
        mut a: usize,
        mut b: usize,
        mut k: usize,
    }
    let sub = min(a, k);
    a -= sub;
    k -= sub;
    if k > 0 {
        let sub = min(b, k);
        b -= sub;
        k -= sub;
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 4352
from copy import copy
from collections import defaultdict


def bubblesort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if int(C[j][-1]) < int(C[j-1][-1]):
                C[j], C[j-1] = C[j-1], C[j]
    return C


def selectionsort(C, N):
    for i in range(N):
        minj = i
        for j in range(i+1, N):
            if int(C[j][-1]) < int(C[minj][-1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C
  

def soot_order(C):
    ret = defaultdict(list)
    for c in C:
        soot = c[0]
        number = c[1]
        ret[number].append(soot)
    return ret


def judge_stable(C, N, order):
    
    cursor = 0
    stable = True
    while cursor < N:
        number = C[cursor][1]
        soots = order[number]
        for soot in soots:
            if C[cursor][0] != soot:
                print("Not stable")
                stable = False
                cursor += N
                break
            else:
                cursor += 1
    if stable:
        print("Stable")
        

def main():
    N = int(input())
    C = [c for c in input().split()]    
    
    order = soot_order(C)
    
    _C = copy(C)
    C_order = bubblesort(_C, N)
    print(' '.join(C_order))
    
    judge_stable(C_order, N, order)
    
    C_order = selectionsort(C, N)
    print(' '.join(C_order))
    
    judge_stable(C_order, N, order)
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    string res = "";

    rep(i, n) {
        if (s[i] == '0' || s[i] == '1') {
            res += s[i];
        }
        else {
            if (res.size() == 0) continue;
            if (res.size() == 1) {
                res = "";
                continue;
            }
            res.erase(res.size()-1, 1);
        }
    }

    cout << res << endl;
    return 0;
}

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

int main(){
  ll n,k;
  cin>>n>>k;
  ll a[1000005],f[1000005];
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>f[i];
  sort(a,a+n);
  sort(f,f+n);
  reverse(f,f+n);
  ll l=-1,r=1e12;
  while(l+1!=r){
    ll m=(l+r)/2;
    ll sum=0;
    rep(i,n){
      sum+=max(a[i]-m/f[i],0LL);
    }
    if(sum<=k) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}

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

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

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

int main(){
	int N;
	cin >> N;
	vector<string> s(N);
	for(int i=0; i<N; i++) cin >> s[i];
	int M;
	cin >> M;
	vector<string> t(M);
	for(int i=0; i<M; i++) cin >> t[i];

	int X=0, Y=0;
	string temp;
	for(int i=0; i<N; i++){
		temp = s[i];
		for(int j=0; j<N; j++){
			if(temp == s[j]) Y++;
		}
		for(int j=0; j<M; j++){
			if(temp == t[j]) Y--;
		}
		if(Y>X) X=Y;
		Y=0;
	}
	for(int i=0; i<M; i++){
		temp = t[i];
		for(int j=0; j<N; j++){
			if(temp == s[j]) Y++;
		}
		for(int j=0; j<M; j++){
			if(temp == t[j]) Y--;
		}
		if(Y>X) X=Y;
		Y=0;
	}
	cout << X;
}

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

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

int main(){
	int n;
	while( cin >> n, n ){
		int k[10001];
		rep(i,n) cin >> k[i];
		sort( k, k+n );
		if( k[n-1] < 2 )
			cout << "NA" << endl;
		else{
			int zero = 0;
			rep(i,n) if(k[i]==0) zero++;
					 else break;
			cout << n-zero+1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> word(n);
  for(int i=0;i<n;i++){
    cin >> word[i];
  }
  int cnt=0;
  for(int i=0;i<n-1;i++){
    if(word[i][word[i].size()-1]==word[i+1][0]) cnt++;
    else break;
  }
  if(cnt==n-1){
    sort(word.begin(),word.end());
    int cnt=0;
    for(int i=0;i<n-1;i++){
      if(word[i]==word[i+1]){
	cout << "No\n";
	break;
      }
      else cnt++;
    }
    if(cnt==n-1) cout << "Yes\n";
  }
  else cout << "No\n";

  
  return 0;
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S="",T="";
  char a,b; cin >> a >> b;

  for(int i = 0; i < a - '0'; i++){
    S += b;
  }
  for(int i = 0; i < b - '0'; i++){
    T += a;
  }

  cout << (S < T ? S : T) << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    char a[7],b[4];
    scanf("%s%s",a,b);
    strcat(a,b);
    int n=atoi(a);
    int r=sqrt(n);
    Yes(r*r==n);
    return 0;
}
	

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

public class Main {
	//////
	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;
		}
	}

	//////

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

		FastReader scan = new FastReader();
	
		long N=scan.nextLong();
		long temp=N;
		long count=0;
		while(temp>0){
			count+=temp%10;
			temp=temp/10;
		}
		
		if(N%count==0){
			System.out.println("Yes");
		}else
			System.out.println("No");
		
		
		
	}		
}



Measured memory_bytes: 20820
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


int main() {
	int a, b, k; cin >> a >> b >> k;
	int count = 0;
	int res;

	for (int i = min(a, b); i >= 1; i--) {
		if (a%i == 0 && b%i == 0) {
			count++;
		}
		if (count == k) {
			res = i;
			break;
		}
	}

	cout << res << endl;
}	

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main()
{
    int R, G, B, N, ans = 0;
    cin >> R >> G >> B >> N;
    int rmax = N / R;
    for (int i = 0; i < rmax + 1; i++)
    {
        int rest1 = N - R * i;
        int gmax = rest1 / G;
        if (gmax != 0)
        {
            for(int j = 0; j < gmax + 1; j++)
            {
                int rest2 = rest1 - G * j;
                int rest = rest2 % B;
                if (rest == 0) ans++;
                else continue;
            }   
        }
        else
        {
            int rest = rest1 % B;
            if (rest == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
S = [input() for i in range(h)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=w*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][w*ni+nj] = 1

# print(N)

# for k in range(m):
#     for i in range(m):
#         for j in range(m):
#             N[i][j] = min(N[i][j], N[i][k]+N[k][j])

N = floyd_warshall(N)


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(int(ans))

Measured memory_bytes: 31456
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>

#define INF 2000000001
#define MAX 10001
#define NIL -1

using namespace std;

typedef struct {
    int toid;
    int far;
} PATH;

vector<PATH> D[MAX];
int N;
int Dist[MAX];

void dijkstra(){//0??????????????¢??????????????£?????????
    
    bool complete[MAX];
    vector<int> S;
    
    for (int i = 0; i < N; i++) {
        complete[i] = false;
        Dist[i] = INF;
    }
 
    //???????¨????
    Dist[0] = 0;
    S.push_back(0);
    int u=0,minf;
    complete[u] = true;
    
    while (1) {
        if (S.size() == N) break;
        
        //????????????
        for (int j = 0; j < D[u].size(); j++) {
            if (!complete[D[u][j].toid] && Dist[u] + D[u][j].far < Dist[D[u][j].toid]) {
                Dist[D[u][j].toid] = Dist[u] + D[u][j].far;
            }
        }
        
        
        
        u = NIL;
        minf = INF;
        
        //?¨??????´??°
//        for (int i = 0; i < S.size(); i++) {
//            
//            for (int j = 0; j < D[S[i]].size(); j++) {
//                if (Dist[D[S[i]][j].toid] < minf && !complete[D[S[i]][j].toid]) {
//                    minf = Dist[D[S[i]][j].toid];
//                    u = D[S[i]][j].toid;
//                }
//            }
//            
//        }
        
        for (int i = 0; i < N; i++) {
            if (!complete[i] && Dist[i] < minf) {
                minf = Dist[i];
                u = i;
            }
        }
        
        S.push_back(u);
        complete[u] = true;
        //u = S.size()-1;//????????§u????????§??¨????????????????????????
    }
}

int main(){
    cin >> N;
    for (int i = 0; i < N; i++) {
        int bb1,bb2;
        cin >> bb1 >> bb2;
        for (int j = 0; j < bb2; j++) {
            PATH bb3;
            cin >> bb3.toid >> bb3.far;
            D[i].push_back(bb3);
        }
    }
    
    dijkstra();
    
    for (int i = 0; i < N; i++) {
        printf("%d %d\n",i,Dist[i]);
    }
    
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,inf=mod*mod*3ll;;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

string S;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>S;

if(S=="ABC") cout<<"ARC"<<endl;
else cout<<"ABC"<<endl;

}
	


Measured memory_bytes: 3620
#include <stdio.h>
#include <ctype.h>

int main(void)
{
	int i,num[26]={0};
	char ch;
	
	while(scanf("%c",&ch) != EOF) {
		if(isupper(ch)) num[ch - 'A']++;
		else if(islower(ch)) num[ch - 'a']++;
	}
	for (i=0; i<26; i++) {
		printf("%c : %d\n",(i + 'a'),num[i]);
	}
	return 0;
}

Measured memory_bytes: 544
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  int n;cin>>n;
  vector<int> A;
  rep(i,n){
    int a;cin>>a;
    A.push_back(a);
  }
  int memo = 1;
  ll ans = 0;
  rep(i,n){
    if(memo == A[i]){
      memo++;
    }else{
      ans++;
    }
  }
  if(ans == n){
    cout<<-1<<endl;
    return 0;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1528
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[][] abc = new int[N][3];
    for (int i = 0; i < N; i++) {
      abc[i][0] = sc.nextInt();
      abc[i][1] = sc.nextInt();
      abc[i][2] = sc.nextInt();
    }
    sc.close();

    long[][] dp = new long[N][3];
    for (int j = 0; j < 3; j++) dp[0][j] = abc[0][j];
    for (int i = 1; i < N; i++) {
      for (int j = 0; j < 3; j++) {
        dp[i][j] = Math.max(
            abc[i][j] + dp[i - 1][(j + 1) % 3], 
            abc[i][j] + dp[i - 1][(j + 2) % 3]);
      }
    }
    long ans = 0;
    for (int j = 0; j < 3; j++) ans = Math.max(ans, dp[N - 1][j]);
    System.out.println(ans);
  }
}

Measured memory_bytes: 101000
n = int(input())
l = list(map(int,input().split()))
#print(l)

a = []
for i in range(len(l)):
    if l[i]%2 == 0:
        a.append(l[i])
#print(a)

x = 0
for j in range(len(a)):
    if a[j] % 3 ==0 or a[j] % 5 ==0:
        x += 1
if x == len(a):
    print('APPROVED')
else:
    print('DENIED')







Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,r,a,b,c,d[201][201],ans=1LL<<60;
vector<ll>v;
int main(void){
    cin>>n>>m>>r;
    for(int i=0;i<r;i++){
        cin>>a;
        v.push_back(a-1);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)d[i][j]=0;
            else d[i][j]=1LL<<60;
        }
    }
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        a--,b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    do{
        ll tmp=0;
        for(int i=1;i<r;i++)tmp+=d[v[i-1]][v[i]];
        ans=min(ans,tmp);
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  int N, M, L[200000], R[200000], l, r;
  scanf("%d %d\n", &N, &M);
  for(int i=1; i<=M; i++){
    scanf("%d %d\n", &L[i], &R[i]);
  }
  l=L[1]; r=R[1];
  for(int i=2; i<=M; i++){
    if(L[i]>l) l=L[i];
    if(R[i]<r) r=R[i];
  }
  if(l<=r){
  printf("%d", r-l+1);
  }
  else printf("%d", 0);
  return(0);
}

/* L最大、R最小*/

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
  int no;
  double time;
  vector<pair<double, int> > v;
  vector<pair<double, int> > buf;
  vector<pair<int, double> > result;

  for(int i=0; i<3; i++){
    v.clear();

    for(int j=0; j<8; j++){
      cin >> no >> time;

      v.push_back(make_pair(time, no));
    }
    sort(v.begin(), v.end());

    for(int j=0; j<8; j++){
      if(j < 2){
        result.push_back(make_pair(v[j].second, v[j].first));
      } else {
        buf.push_back(v[j]);
      }
    }
  }
  sort(buf.begin(), buf.end());
  result.push_back(make_pair(buf[0].second, buf[0].first));
  result.push_back(make_pair(buf[1].second, buf[1].first));

  for(int i=0; i<result.size(); i++){
    cout << result[i].first << " " << result[i].second << endl;
  }

  return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;
    if( (A+B) % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
    } 
    else{
        cout << (A+B) /2 << endl;
    }
}

Measured memory_bytes: 256