akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 100

int par[MAX],rank[MAX];
int V,E;

struct edge{
  int u,v,cost;
};

bool comp(const edge &e1,const edge &e2){
  return e1.cost < e2.cost;
}

void init(){
  for(int i = 0 ; i < V ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);

  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]){
      rank[x]++;
    }
  }
}

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

edge es[MAX*MAX];

int kruskal(){
  init();
  sort(es,es+E,comp);

  int res = 0;
  for(int i = 0 ; i < E ; i++){
    edge e = es[i];
    if(!same(e.u,e.v)){
      res += e.cost;
      unite(e.u,e.v);
    }
  }
  return res;
}

int main(){
  while(cin >> V >> E , (V | E)){
    int a,b,c;
    for(int i = 0 ; i < E ; i++){
      cin >> a >> b >> c;
      es[i] = (edge){a,b,c};
    }
    cout << kruskal() << endl;
  }

  return 0;
}

Measured memory_bytes: 1184
a, b, c = map(int, input().split())
if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)



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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> vec(m+1);
  int a,b;
  for(int i=0;i<n;i++){
    cin>>a;
    for(int j=0;j<a;j++){
      cin>>b;
      vec.at(b)++;
      }
    }
  int answer=0;
  for(int i=0;i<m+1;i++){
    if(vec.at(i)==n){
      answer++;
      }
    }
  cout<<answer<<endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	s = readline() |> chomp
	k = 1
	for i in 2:n
		if s[i]!=s[i-1]
			k += 1
		end
	end
	println(k)
end

main()

Measured memory_bytes: 168936
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
int main(){
    cin>>N;
    vector<bool> v;
    for(ll i=0;i<N;i++){
        ll d1,d2;cin>>d1>>d2;
        v.push_back((d1==d2));
    }
    for(ll i=0;i<v.size()-2;i++){
        if(v[i] && v[i+1] &&v[i+2]){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3628
//05
#include<iostream>

using namespace std;

int main(){
  static bool cmp[1000001]={true,true};
  for(int i=2;i<1000001;i++){
    if(!cmp[i]){
      for(int j=2;i*j<1000001;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int k[2];cin>>k[0]>>k[1],k[0]|k[1];){
    int r[2]={};
    for(int i=0;i<2;i++){
      bool m=false;
      for(int l=k[i];l>=2;l--){
	if(!cmp[l]&&k[i]%l==0){
	  r[i]+=(m)?-l:l;
	  m=true;
	}
      }
    }
    cout<<((r[0]>r[1])?'a':'b')<<endl;
  }
  return 0;
}

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

int N, M, X, A[200];

int main()
{
	scanf("%d%d%d", &N, &M, &X);
	for (int i = 0; i < M; ++i) scanf("%d", A + i);

	int left = 0, right = 0;
	for (int i = 0; i < M; ++i) {
		if (A[i] < X) ++left;
		else ++right;
	}
	printf("%d\n", min(left, right));

	return 0;
}


Measured memory_bytes: 128
from itertools import product
from operator import itemgetter
import sys
def main(N, K, P):
    X = sorted(map(itemgetter(0), P))
    Y = sorted(map(itemgetter(1), P))
    Xd, Yd = dict(), dict()
    for i, (x, y) in enumerate(zip(X, Y)):
        Xd[x] = i
        Yd[y] = i

    C = [[0] * (N + 1) for _ in range(N + 1)]
    for x, y in P:
        i, j = Xd[x] + 1, Yd[y] + 1
        C[i][j] += 1
    for i in range(1, N + 1):
        for j in range(N):
            C[i][j + 1] += C[i][j]
    for j in range(1, N + 1):
        for i in range(N):
            C[i + 1][j] += C[i][j]

    ans = 10**20
    for x1, y1 in product(range(N), repeat=2):
        for x2, y2 in product(range(x1, N), range(y1, N)):
            c = C[x2 + 1][y2 + 1] - C[x1][y2 + 1] - C[x2 + 1][y1] + C[x1][y1]
            if c >= K:
                s = (X[x2] - X[x1]) * (Y[y2] - Y[y1])
                assert s >= 0
                if s != 0:
                    ans = min(ans, s)
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    P = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, K, P)


Measured memory_bytes: 73964
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;

int k; 
bool vis[100005]; 

heap<ii, vector<ii>, greater<ii> > pq; 
signed main()
{
	cin >> k; 
	for(int i = 1; i <= 9; i++) {	
		pq.push({i, i % k}); 
	}
	while(!pq.empty()) {
		ii T = pq.top(); pq.pop();
		int u = T.se, w = T.fi;
		if(vis[u]) continue; 
		vis[u] = 1; 
		if(!u) {
			cout << w; 
			return 0; 
		}
		for(int i = 0; i <= 9; i++) {
			pq.push({w + i, (u * 10 + i) % k});
		}
	}
}

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

// DATA TYPES
typedef long long ll;
#define double long double
//

// CONTAINERS
#define vec vector
#define pb push_back
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)x.size()
#define mp make_pair
#define ii pair<int, int>
#define F first
#define S second
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &L, const std::pair<T,U> &R) {
  return {L.first + R.first, L.second + R.second};
}
//

// LOOP
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
//

// BIT
#define bitcount(n) __builtin_popcountll(n)
//

// DEBUG
#define format(x) << #x << ": " << (x)
#define com << ", "
#define ndl << "\n"
#define debug1(x) cerr format(x) ndl;
#define debug2(x, y) cerr format(x) com format(y) ndl;
#define debug3(x, y, z) cerr format(x) com format(y) com format(z) ndl;
void debug_out() { cerr << "\n"; }
template <typename H, typename... T> 
void debug_out(H h, T... t) { cerr << " " << (h); debug_out(t...); }
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
// 

// CONSTANTS
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
//

// NUMERICAL OPERATIONS
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}
//

// Init variables here
const int N = 1e6 + 7;

void init() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  int n;
  cin >> n;
  cout << n * n * n << "\n";
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    init();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



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

namespace ConsoleApp18
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] array = line.Split(' ');
            
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);

            int count=0;

            for (int i = a; i <= b; i++)
            {
                string s = i.ToString();
                if (s.Reverse().SequenceEqual(s))
                {
                    count++;
                }
 
            }
            Console.WriteLine(count);

        }
    }
}

Measured memory_bytes: 46708
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  string S;
  cin>>S;
  rep(i,0,S.size()) {
    S[i]='x';
  }
    cout<<S<<endl;
}
  


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};

struct UF
{
  vector<int> par; // 親のインデックスを記憶する配列
  vector<int> sz; // サイズを記憶する。
  vector<int> rank;
  // 初期化
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  // 親を求める
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  // xとyの属する集合を併合
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  // xとyが同じ集合ならtrue
  bool same(int x, int y) { return find(x) == find(y); }
  // 素の集合のサイズを求める
  int size(int n){return sz[find(n)];}
};
ll da[111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  UF uni(n+10);
  for(int i=0;i<n;i++){
    ll L;
    cin>>L;
    for(int j=0;j<L;j++){
      ll a;cin>>a;
      if(da[a]){
	uni.merge(i+1,da[a]);
      }else{
	da[a]=i+1;
      }
    }
  }
  bool fl=false;
  for(int i=1;i<=n;i++)
    if(uni.size(i)==n)fl=true;
  cout<<(fl?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 1664
S=input()
N=len(S)
ans=0
for i in range(2**(N-1)):
  F=S[0]
  q="{:0>10b}".format(i)[::-1]
  for j in range(1,N):
    if int(q[j-1])&1:
      F+="+"
    F+=S[j]
  ans+=eval(F)    
print(ans)

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int cnt(ll a){
    int p=0;
    while(a%2==0){
        a/=2;
        p++;
    }
    return p;
}
int main(){
   int n, ans = 0;
   cin >> n;
   rep(i, 0, n){
       ll q;
       cin >> q;
       ans += cnt(q);
   }
   cout << ans << endl;
}

Measured memory_bytes: 3560
#include<cstdio>
int main(void){
	int n, m;
	char a[101];
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf("%s", a);
			for (int j = 0; j < m; j++){
					printf("%c", a[j]);
				}
				printf("\n");
				for (int j = 0; j < m; j++){
					printf("%c", a[j]);
				}
printf("\n");
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[10];
int main(){
	scanf("%s",in);
	if(in[0]=='a'||in[0]=='e'||in[0]=='i'||in[0]=='o'||in[0]=='u')printf("vowel\n");
	else printf("consonant\n");
}

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

using namespace std;
using ll = long long;

int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif


    int a, b, c;
    cin >> a >> b >> c;
    if(b * c >= a) puts("Yes"); else puts("No");
    return 0;
}

Measured memory_bytes: 3632
use std::cmp;
use std::option::Option;

type Graph = Vec<(Vec<usize>, Option<usize>)>;

fn computeLengthFrom(mut graph: &mut Graph, from: usize) -> usize {
  if let Some(len) = graph[from].1 {
    return len;
  };
  let mut max = 0;
  for j in 0..graph[from].0.len() {
    let k = graph[from].0[j];
    let size = computeLengthFrom(&mut graph, k);
    max = cmp::max(max, size + 1);
  };
  graph[from].1 = Some(max);
  max
}

fn main() {
  
  let nm = read::<usize>();
  let n = nm[0];
  let m = nm[1];
  let mut graph: Vec<(Vec<usize>, Option<usize>)> = vec![(vec![], None); n];
  for _ in 0..m {
    let xy = read::<usize>();
    graph[xy[0]-1].0.push(xy[1]-1);
  }
  
  let mut max = 0;
  for i in 0..n {
    let size = computeLengthFrom(&mut graph, i);
    max = cmp::max(max, size);
  }
  
  println!("{}", max);
}

fn read<T: std::str::FromStr>() -> Vec<T> {
  gets().split_whitespace().filter_map(|s|s.parse().ok()).collect()
}

fn gets() -> String {
  let mut line = String::new();
  std::io::stdin().read_line(&mut line).ok();
  line.trim().to_string()
}


Measured memory_bytes: 11608
#include <stdio.h>
#include <string>
#include <iostream>

using namespace std; 

string s;

int a[30];

int main(void)
{
	bool ok = true;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		int tmp = s[i] - 'a';
		
		if (a[tmp])
		{
			ok = false;
			break;
		}
		a[tmp]++;

	}
	if (ok)
		printf("yes\n");
	else
		printf("no\n");
	return false;
}

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

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

int n,a[233333];
long long fr,sc,ndad;int main(){
	n=read();
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;++i){
		int x=read();
		if(a[i]>=x)sc+=a[i]-x;
		else{
			if((x-a[i])%2){
				++x;++sc;
			}
			fr+=(x-a[i])>>1;
		}
	}
	printf("%s",fr>=sc?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                String S = scan.next();
                
                if(S.equals("ABC")){
                    System.out.println("ARC");
                }
                if(S.equals("ARC")){
                    System.out.println("ABC");
                }
        }
}

Measured memory_bytes: 35732
#include<stdio.h>

int main (){
    
    int A,B,C,temp;
    
    scanf("%d %d %d",&A,&B,&C);
  
  	if(A > B){
      temp = B;
      B = A;
  	  A = temp;
    }
    
    if(A <= C && B >= C ){
        printf("Yes");
    }else{
        printf("No");
    }
	
        return 0;
  
}



Measured memory_bytes: 128
import java.util.*;
class Main{
    /*
     * 整数 -> nextInt() (遅い場合は下のni())
     * 単語 -> next()
     * 1行 -> nextLine()
     * 注意 : nextLIneをnext(),nextInt()のあとに呼び出す場合、次が改行だと改行だけ取ってしまうので注意
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for(int i=0;i<N;i++) A[i] = sc.nextLong();

        Map<Long,Long> mp = new HashMap<>();
        for(int i=0;i<N;i++){
            if(mp.containsKey(A[i])){
                mp.put(A[i],mp.get(A[i])+1);
            }else{
                mp.put(A[i],1L);
            }
        }

        long ans = 0;
        for(Map.Entry<Long,Long> e : mp.entrySet()){
            long key = e.getKey();
            long val = e.getValue();

            if(key > val) ans += val;
            else if(key < val) ans += (val - key);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 60732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
105*20=2100=100*21
みたいなのは大丈夫
*/

ll ans=1;
ll x,n=6;

int main(void){
	cin>>x;
	ll a = x/100;
	x%=100;
	ll b = x/5;
	if(x%5>0)b++;
	if(b>a)ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from itertools import accumulate

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

gcd_L = [0] + list(accumulate(L, gcd))
gcd_R = list(accumulate(L[::-1], gcd))[::-1] + [0]


# [0,1,2,3,4]
# [4,3,2,1,0]
# N = 4
m_gcd = 0

for i in range( N):
	m_gcd = max(m_gcd, gcd(gcd_L[i], gcd_R[i + 1]))
print(m_gcd)

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

using namespace std;

map<pair<int, int>, int> freq;

pair<int, int> f(int x){
    int a = x % 10;
    int b = 0;
    while(x){
        b = x % 10;
        x /= 10;
    }
    return make_pair(a, b);
}

int main(){
    int n;
    cin >> n;
    int num = 1, ans = 0;
    for(int i = 1; i <= n; ++i){
        pair<int, int> p = f(i);
        freq[p]++;
    }
    for(int i = 1; i <= n; ++i){
        pair<int, int> p = f(i);
        pair<int, int> q(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int shortest_length(int sy, int sx, int gy, int gx, vector<string> field, char block) {
    int h = field.size();
    int w = field[0].size();
    vector<vector<int>> d(h, vector<int> (w, INF));
    d[sy][sx] = 0;
    queue<P> que;
    que.push(make_pair(sy, sx));
    while (que.size()) {
        P p = que.front();
        que.pop();
        int y = p.first;
        int x = p.second;
        if (x == gx && y == gy) break;
        for (int dx = -1, dy = 0, i = 0; i < 4; dx += dy, dy = dx - dy, dx = dy - dx, i++) {
            int ny = y + dy;
            int nx = x + dx;
            if (nx >= 0 && nx < w && ny >= 0 && ny < h && field[ny][nx] != block && d[ny][nx] == INF) {
                d[ny][nx] = d[y][x] + 1;
                que.push(make_pair(ny, nx));
            }
        }
    }
    if (d[gy][gx] == INF) return -1;
    return d[gy][gx];
}


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    int ans = 0;
    rep(start_y, h) {
        rep(start_x, w) {
            rep(goal_y, h) {
                rep(goal_x, w) {
                    if (field[start_y][start_x] == '#' || field[goal_y][goal_x] == '#') continue;
                    int sl = shortest_length(start_y, start_x, goal_y, goal_x, field, '#');
                    ans = max(ans, sl);
                }
            }
        }
    }
    cout << ans << endl;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	ll N;
	cin>>N;
	ll ar[N];
	ll sum=0;
	ll ans=0;

	for(ll i=0;i<N;i++){
		cin>>ar[i];
		sum+=ar[i];
	}
	for(ll i=0;i<N;i++){
		sum-=ar[i];
		ans+=((sum)%MOD*ar[i]);
		ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5196
x, y = map(int, input().split())

result = 0
if (x == 3):
    result += 100000
elif (x == 2):
    result += 200000
elif (x == 1):
    result += 300000


if (y == 3):
    result += 100000
elif (y == 2):
    result += 200000
elif (y == 1):
    result += 300000

if(result == 600000):
    result += 400000

print(result)


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

using namespace std;

#define INF 10000

void next(int *c, int n){
  for(int i = 0; i <= n; i++){
    if(c[i] < 3){
      c[i]++;
      break;
    }else{
      c[i] = 0;
    }
  }
}

bool is_abc(int *c, int n){
  int count_a = 0;
  int count_b = 0;
  int count_c = 0;
  for(int i = 0; i < n; i++){
    switch(c[i]){
      case 0:
        count_a++;
        break;
      case 1:
        count_b++;
        break;
      case 2:
        count_c++;
        break;
    }
  }
  if(count_a != 0 && count_b != 0 && count_c != 0){
    return true;
  }else{
    return false;
  }
}

int main(){
  int n;
  int a, b, c;
  cin >> n >> a >> b >> c;
  
  vector<int> l(n);
  for(int i = 0; i < n; i++) cin >> l[i];
  
  int controller[n + 1];
  for(int i = 0; i <= n; i++) controller[i] = 0;
  
  int mp_min = INF;
  while(controller[n] == 0){
    if(is_abc(controller, n)){
      int a_l = 0;
      int b_l = 0;
      int c_l = 0;
      int mp = -30;
      for(int i = 0; i < n; i++){
        switch(controller[i]){
          case 0:
            a_l += l[i];
            mp += 10;
            break;
          case 1:
            b_l += l[i];
            mp += 10;
            break;
          case 2:
            c_l += l[i];
            mp += 10;
            break;
        }
      }
      mp += abs(a - a_l);
      mp += abs(b - b_l);
      mp += abs(c - c_l);
      mp_min = min(mp, mp_min);
    }
    
    next(controller, n);
    
  }
  
  cout << mp_min << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,sum=0;
    int s[100]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    sort(s,s+n);
    if(sum%10==0){
        for(int i=0;i<n;i++){
            if(s[i]%10!=0){
                sum-=s[i];
                break;
            }
        }
    }
    if(sum%10==0) sum=0;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  string s; cin >> s;
  string ans = "";
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '0') ans = ans + '0';
    else if(s[i] == '1') ans = ans + '1';
    else if(ans.size() > 0) ans.erase(ans.size() - 1);
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,m,tmp;
    scanf("%d %d",&n,&m);
    int** A = new int*[n];
    for(int i = 0; i < n; i++) A[i] = new int[m];
    int b[m];
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&tmp);
            A[i][j] = tmp;
        }
    }
    for(int i = 0; i < m; i++){
        scanf("%d",&tmp);
        b[i] = tmp;
    }
    long long int sum;
    for(int i = 0; i < n; i++){
        sum = 0;
        for(int j = 0; j < m; j++){
            sum += A[i][j] * b[j];
        }
        printf("%lld\n",sum);
    }
 
    for(int i = 0; i < n; i++){
        delete[] A[i];
    }
    delete A;
}


Measured memory_bytes: 2764
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            System.out.println(A + B >= C ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 21716
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	ll a;
	double b;
	cin >> a >> b;

	ll ib = b * 100 + 0.5;

	a = a * ib;
	a = a / 100;

	cout << a << endl;

	

}
	

Measured memory_bytes: 3736
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
//#define ll long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};
#define double long double

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << (a * b);
}


Measured memory_bytes: 3652
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lson root<<1
#define rson root<<1|1
using namespace std;

int cnt;
char c[3];

int main()
{
	scanf("%s",c);
	cnt+=c[0]=='o';
	cnt+=c[1]=='o';
	cnt+=c[2]=='o';
	printf("%d\n",700+cnt*100);
}

Measured memory_bytes: 256
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


N, Q = map(int, input().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, input().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 18740
#include<stdio.h>
void bable(int *);
int main(){
  int sides[3];
  int tri=0,acute=0,right=0,obtuse=0;

  while(scanf("%d%d%d",&sides[0],&sides[1],&sides[2])!=EOF){
    bable(sides);
    if( sides[0]<(sides[1]+sides[2]) && sides[2]>(sides[0]-sides[1]) ){
      tri++;

      if(sides[0]*sides[0] == sides[1]*sides[1] + sides[2]*sides[2])
	right++;
      else if(sides[0]*sides[0] < sides[1]*sides[1] + sides[2]*sides[2])
	acute++;
      else if(sides[0]*sides[0] > sides[1]*sides[1] + sides[2]*sides[2])
	obtuse++;
    }
    else break;
    
  }
  printf("%d %d %d %d\n",tri,right,acute,obtuse);
  
  return 0;
}

void bable(int *sides){
  int i,j,temp;

  for(i=0;i<3;i++){
      for(j=i+1;j<3;j++){
	if(sides[i]<=sides[j]){
	  temp = sides[i];
	  sides[i] = sides[j];
	  sides[j] = temp;
	}
      }
  }
}



Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>


using namespace std;



int main() {

	int N, H, H0 = 0, count = 0, max = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> H;
		if (H0 >= H) {
			count++;
		}
		else{
			count = 0;
		}
		H0 = H;
	
		if (count > max) {
			max = count;
		}
	}

	cout << max;

	return 0;

}

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

//#define kk
//#define int long long
#define FOR(i, n) for(int i=1; i<=n; i++)
#define ff first
#define ss second
#define ll int
#define inf 1000000000
#define pb push_back

const long long INF=1e18+5;
 
typedef pair<int, int> pi;

vector<int> arr[100001];
int maxD;
int dp[100001];

int dfs(int v, int d){
	if(dp[v]!=-1) return dp[v];
	
	int temp=0;
	for(int child: arr[v]){
		temp=max(temp, 1+dfs(child, d+1));
	}
	return dp[v]=temp;
}

void solve(){
	int n, m;
	cin>>n>>m;
	
	for(int i=1; i<=m; i++){
		int a, b;
		cin>>a>>b;
		arr[a].pb(b);
	}
	
	for(int i=1; i<=n; i++) dp[i]=-1;
	
	int ans=0;
	
	for(int i=1; i<=n; i++){
		maxD=-1;
		int res=dfs(i, 0);
		ans=max(ans, res);
	}
	cout<<ans<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 11444
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

Vi color;
vector<vector<the> >G;

void dfs(int u, int r)
{
	for (the tnu : G[u]) {
		if (color[tnu.first] != -1)  continue;
		//cout << tnu.first << " " << r << endl;
		int t = (r + tnu.second) % 2;

		if (t == 0) {
			color[tnu.first] = 0;
		}
		else {
			color[tnu.first] = 1;
		}
		dfs(tnu.first, t);
	}
	return;
}


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

	G.resize(n);
	rep(i, n - 1) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back({ v,w });
		G[v].push_back({ u,w });
	}

	color.resize(n, -1);
	color[0] = 0;

	dfs(0, 0);

	rep(i, n) cout << color[i] << endl;
}


Measured memory_bytes: 7424
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;
#include <iomanip>

int main(int argc, char const *argv[]) {
  ld ans = 0, n, m, d, k;std::cin >> n >> m >> d;
  if(d==0) k = n;
  else k = 2*n-2*d;
  ans = (k*(m-1))/(n*n);
  std::cout << fixed << setprecision(20) << ans << '\n';
  return 0;
}


Measured memory_bytes: 632
package main

import "fmt"

var n, ans int

const arraySize = 101

var a = [arraySize][arraySize]int{}

func findAns(i, j, sum int) {
	if i == 1 && j == n-1 && sum+a[i][j] > ans {
		ans = sum + a[i][j]
		return
	}
	if i == 0 {
		findAns(i+1, j, sum+a[i][j])
	}
	if j+1 < n {
		findAns(i, j+1, sum+a[i][j])
	}
}
func main() {

	fmt.Scanf("%d", &n)

	for i := 0; i < 2; i++ {
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &a[i][j])
		}
	}
	findAns(0, 0, 0)
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,k,i;
	char s[100001],scp[100001];
	scanf("%d%d%s",&n,&k,s);
	for(i=0;s[i]!=0;i++)scp[i]=s[i];
	int g=i,wh=0,bl=0;
	for(i=0;i<g;i++)scp[i]=(scp[i]=='0'?'1':'0');
	for(i=0;i<g;i++){
		if(s[i]=='0')wh++;
		else bl++;
	}
	int zz[100000]={0},cc=0;
	if(s[0]=='0')zz[0]=1;
	for(i=1;i<g;i++){
		if(s[i-1]=='0'&&s[i]=='0'){
			zz[cc]++;
		}if(s[i-1]=='1'&&s[i]=='0'&&zz[0]!=0){
			zz[++cc]++;
		}else if(s[i-1]=='1'&&s[i]=='0'&&zz[0]==0){
			zz[cc]++;
		}
	}
	int oo[100000]={0},cco=0;
	if(s[0]=='1')oo[0]=1;
	for(i=1;i<g;i++){
		if(s[i-1]=='1'&&s[i]=='1'){
			oo[cco]++;
		}if(s[i-1]=='0'&&s[i]=='1'&&oo[0]!=0){
			oo[++cco]++;
		}else if(s[i-1]=='0'&&s[i]=='1'&&oo[0]==0){
			oo[cco]++;
		}
	}
	cc++;cco++;
//	for(i=0;i<cco;i++)printf("%d\n",oo[i]);
	if(k>=cc){
		printf("%d\n",n);
		return 0;
	}
	int tmp=0,anss=0;
	if(s[0]=='0'){
		for(i=0;i<k;i++)tmp+=(zz[i]+oo[i]);
		anss=tmp;
		tmp+=(zz[k]+oo[k]);
		tmp-=zz[0];
		anss=max(anss,tmp);
		if(s[g-1]=='0'){
			for(i=k+1;i<=cco;i++){
				tmp+=(zz[i]+oo[i]);
				tmp-=(zz[i-k]+oo[i-k-1]);
				anss=max(anss,tmp);
			}
			tmp+=zz[cc];
			tmp-=(zz[cc-k]+oo[cc-k-1]);
			anss=max(anss,tmp);
		}else{
			for(i=k+1;i<=cco;i++){
				tmp+=(zz[i]+oo[i]);
				tmp-=(zz[i-k]+oo[i-k-1]);
				anss=max(anss,tmp);
			}
		}
	}
	else {
		for(i=0;i<k;i++)tmp+=(zz[i]+oo[i]);
		tmp+=oo[k];
		anss=tmp;
		if(s[g-1]=='0'){
			for(i=k+1;i<=cco;i++){
				tmp+=(zz[i-1]+oo[i]);
				tmp-=(zz[i-k-1]+oo[i-k-1]);
				anss=max(anss,tmp);
			}
		}else{
			for(i=k+1;i<=cco;i++){
				tmp+=(zz[i-1]+oo[i]);
				tmp-=(zz[i-k-1]+oo[i-k-1]);
				anss=max(anss,tmp);
			}
			tmp+=zz[cc];
			tmp-=(zz[cc-k]+oo[cc-k]);
			anss=max(anss,tmp);
		}
	}
	printf("%d\n",anss);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mt make_tuple
#define ll long long
#define eb emplace_back
#define fi first
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a) 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) 
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626
 
using namespace std;
 using namespace __gnu_pbds;
 template <typename T>
 using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
//----------------------------------------------------------------------------------------------------------------------
 
#define MOD 1000000007 
  
void swap(char &a, char & b){
    char temp = a;
    a = b;
    b = temp;
 
}
 
const ll md = 1e9 + 7;
const int MAXN = 2*1e5 + 50;
 
vector< int > graph[MAXN];
int in_degrees[MAXN];
int dist[MAXN];
bool visited[MAXN];
ll inf = 1e18*1LL;



void dfs(int root){
    visited[root] = true;
    for(auto it : graph[root]){
        dist[it] = max(dist[it],dist[root] + 1);
        --in_degrees[it];
        if(in_degrees[it] == 0){
            dfs(it);
        }
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int a,b;
        cin >> a >> b;
        graph[a].pb(b);
        ++in_degrees[b];
    }
    int fakeVert = 0;
    for(int i = 1;i <= n;i++){
        ++in_degrees[i];
        graph[fakeVert].pb(i);
    }
    dfs(fakeVert);
    int ans = 0;
    for(int i = 1;i <= n;i++) ans = max(ans,dist[i]);

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

Measured memory_bytes: 10488
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  int a[3][3];
  bool check[3][3];
  memset(check,false,sizeof(check));
  for(ii=0;ii<3;ii++){
    for(jj=0;jj<3;jj++){
      cin >> a[ii][jj] ;
    }
  }

  int n;

  cin >> n;

  vector<int> b(n);

  for(ii=0;ii<n;ii++){
    cin >> b[ii];
  }

  for(kk=0;kk<n;kk++){
    for(ii=0;ii<3;ii++){
      for(jj=0;jj<3;jj++){
        if(b[kk] == a[ii][jj]){
          check[ii][jj] = true;
        }
      }
    }
  }

  //for(ii=0;ii<3;ii++){
  //  for(jj=0;jj<3;jj++){
  //    if(check[ii][jj]){
  //      cout << "○";
  //    }
  //    else{
  //      cout << "×";
  //    }
  //  }
  //  cout << endl;
  //}
  bool bingFlg = false;
  int num = 0;
  // 縦

  for(ii=0;ii<3;ii++){
    num = 0;
    for(jj=0;jj<3;jj++){
      if(check[jj][ii]){
        num++;
      }
    }
    if(num ==  3){
      bingFlg = true;
    }
  }

  //cout << bingFlg << endl;

  // 横
  for(ii=0;ii<3;ii++){
    num = 0;
    for(jj=0;jj<3;jj++){
      if(check[ii][jj]){
        num ++;
      }
    }
    if(num ==  3){
      bingFlg = true;
    }
  }

  // 斜め
  num = 0;
  for(ii=0;ii<3;ii++){

    if(check[ii][ii]){
      num++;
    }
  }
  
  if(num ==  3){
    bingFlg = true;
  }
  //cout << bingFlg << endl;

  num = 0;  
  for(ii=0;ii<3;ii++){

    if(check[2-ii][ii]){
      num++;
    }
  }

  if(num == 3){
    bingFlg = true;
  }

  if(bingFlg){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <numeric>

int main(void) {
    int n;
    int price[10];
    std::cin >> n;
    for(int i=0;i<n;i++) std::cin >> price[i];

    auto sum = std::accumulate(price, price+n, 0);
    auto max = *std::max_element(price, price+n);

    std::cout << (sum - max / 2) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B,C,D; cin >> A >> B >> C >> D;
    int out=0;
    for(int i=min(A,C);i<=max(B,D);i++){
        if(A<=i && i<=B && C<=i && i<=D){
            out++;
            cerr << i << endl;
        }
    }
    cout << max(0,out-1) << endl;
    return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

using std::vector;

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

    int a, b, c, d;
    d = n % 10;
    c = (n / 10) % 10;
    b = (n / 100) % 10;
    a = (n / 1000) % 10;

    if (a + b + c + d == 7)
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    else if (a + b + c - d == 7)
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    else if (a + b - c + d == 7)
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    else if (a + b - c - d == 7)
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    else if (a - b + c + d == 7)
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    else if (a - b + c - d == 7)
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    else if (a - b - c + d == 7)
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    else if (a - b - c - d == 7)
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;

    return 0;
}


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

int main() {
	int a;
	cin>>a;
	if(a==3){
	    cout<<"YES"<<'\n';
    }
    else if(a==5){
        cout<<"YES"<<'\n';
    }
    else if(a==7){
        cout<<"YES"<<'\n';
    }
    else{
        cout<<"NO"<<'\n';
    }
	return 0;
}


Measured memory_bytes: 384
sx, sy, tx, ty = list(map(int, input().split()))
y = ty-sy
x = tx-sx
print("U"*y+"R"*x+"D"*y+"L"*(x+1)+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U")

Measured memory_bytes: 3060
n=int(input())
a=[int(input()) for _ in range(n)]
aa=list(set(a))
ma1=aa[-1]
aa1=a.count(aa[-1])
if aa1==1:
    for i in range(n):
        if a[i]==ma1:
            print(aa[-2])
        else:
            print(ma1)
else:
    for i in range(n):
        print(ma1)

Measured memory_bytes: 17188
def poyo():
    ans = -1
    A = []
    for i in range(1, 100):
        t = sum([ord(x) - ord('0') for x in str(i)])
        ans = max(ans, t)
        A.append(ans)
        # print(ans)

    import numpy as np
    maxi, cnt = np.unique(A, return_counts=True)
    print(maxi)
    print(np.cumsum(cnt))
    for x, y in zip(maxi, np.cumsum(cnt)):
        print(x, y)


def naive(N):
    ans = -1
    for i in range(N + 1):
        t = sum([ord(x) - ord('0') for x in str(i)])
        ans = max(ans, t)
    return ans


# poyo()
import math


def solve(N):
    if N < 10:
        return (N)
    else:
        ans = (len(str(N + 1)) - 1) * 9
        ans += ord(str(N + 1)[0]) - ord('0') - 1
        return (ans)


def check():
    for i in range(10000):
        # print(i)
        assert solve(i) == naive(i)


N = int(input())
print(solve(N))


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 300005;

int n, a, b, tab[N], i, cou, lim, c, d;

int main() {
scanf("%d %d %d", &n, &a, &b);
if (a + b > n + 1) {
	printf("-1\n");
	return 0;
}
if (a == 1) {
	if (b != n) {
		printf("-1\n");
		return 0;
	}
	for (i=0;i<n;i++) printf("%d ", n - i);
	printf("\n");
	return 0;
}
if (b == 1) {
	if (a != n) {
		printf("-1\n");
		return 0;
	}
	for (i=1;i<=n;i++) printf("%d ", i);
	printf("\n");
	return 0;
}
for (i=1;i<=a;i++) tab[i] = n - a + i;
c = a + 1;
d = b - 1;
lim = 0;
cou = 0;
while (true) {
	if (c > n) break;
	if (d >= tab[1]) d = tab[1] - 1;
	for (i = d;i > lim && c<=n;c++, i--) {
		tab[c] = i;
	}
	lim = d;
	d += (b - 1);
	cou++;
}
if (cou > a) {
	printf("-1\n");
	return 0;
}
for (i=1;i<=n;i++) printf("%d ", tab[i]);
printf("\n");
return 0;
}



Measured memory_bytes: 3328