akhauriyash/Code-Regression huggingface dataset:
n,m;
i,j;
s;
k,l;
f;

char a[50][55],b[50][55];

main(){
  scanf("%d%d\n",&n,&m); // N, Mの入力
  
  for(i=0;i<n;i++)
    gets(a[i]); // 画像Aの読み取り
  
  for(i=0;i<m;i++)
    gets(b[i]); // 画像Bの読み取り
  
  for(i=0;i<=n-m;i++)    // 行のループ （画像Aに対して）
    for(j=0;j<=n-m;j++){ // 列のループ （画像Aに対して）
    f=1;
    
    for(k=0;k<m;k++)     // 行のループ（画像Bに対して）
      for(l=0;l<m;l++)   // 列のループ（画像Bに対して）
        f&=a[i+k][j+l]==b[k][l];  // f = f & (a[i+k][j+l]==b[k][l]); と同じ
                                  // a[i+k][j+l]==b[k][l]は a[i+k][j+l]とb[k][l]が同じか確かめる 返り値は1(true)か0(false)
                                  // f & a[i+k][j+l]==b[k][l]でfとa[i+k][j+l]==b[k][l]のANDを取る
                                  // fもa[i+k][j+l]==b[k][l]もtrueな時だけf & a[i+k][j+l]==b[k][l]の値はtrueになる
                                  // f = f & (a[i+k][j+l]==b[k][l]); でfの値を更新
                                  // 要するにa[i+k][j+l]==b[k][l]がずっとtrueな時だけfは最終的にtrueになる
        s+=f;                     // sにfを足し合わせ
    }
    
    puts(s?"Yes":"No");           // sが1(true)ならYes, 0(false)ならNoを出力
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  char data[4];
  char pm[]="+-";
  int plmi[]={1,-1};
  for(int i=0;i<4;i++){
    cin>>data[i];
  }
  bool flg=false;
  int ans;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
	ans=data[0]-'0'+(data[1]-'0')*plmi[i]+(data[2]-'0')*plmi[j]+(data[3]-'0')*plmi[k];
	if(ans==7){
	  cout<<data[0]<<pm[i]<<data[1]<<pm[j]<<data[2]<<pm[k]<<data[3]<<"=7\n";
	  flg=true;
	  break;
	}
      }
      if(flg)break;
    }
    if(flg)break;
  }

  return 0;
}


Measured memory_bytes: 256
<?php

function input(string $func = null) {
    if ($func === null) {
        return trim(fgets(STDIN));
    } else {
        return $func(trim(fgets(STDIN)));
    }
}

function input_array(string $func = null) {
    if ($func === null) {
        return explode(' ', trim(fgets(STDIN)));
    } else {
        return array_map(function($v) use ($func) {
            return $func($v);
        }, explode(' ', trim(fgets(STDIN))));
    }
}

$n = input('intval');
$as = input_array('intval');
$bs = input_array('intval');

$overs = [];
$count = 0;
$to_be_added = 0;

for ($i = 0; $i < $n; $i++) {
    if ($as[$i] > $bs[$i]) {
        $overs[] = $as[$i] - $bs[$i];
    } else if ($as[$i] < $bs[$i]) {
        $count++;
        $to_be_added += $bs[$i] - $as[$i];
    }
}
rsort($overs);

for ($i = 0, $c = count($overs); $i < $c; $i++) {
    if ($to_be_added <= 0) {
        break;
    }
    $to_be_added -= $overs[$i];
    $count++;
}

if (array_sum($as) < array_sum($bs)) {
    echo "-1\n";
} else {
    echo "{$count}\n";
}

Measured memory_bytes: 21232
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		String t = in.nextLine();
		for(int i = 0; i < t.length(); i++) {
			String tmp = s.substring(i) + s.substring(0, i);
			if(tmp.equals(t)) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll inf = 1e18;
const int mod = 10007;

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    vint dp;
    dp.push_back(-1);
    dp.push_back(a[0]);
    for (int i = 1; i < n; i++) {
        for (int j = dp.size()-1; j >= 0; j--) {
            if (dp[j] < a[i]) {
                dp.push_back(a[i]);
                break;
            }
            else if (dp[j] >= a[i] && dp[j-1] < a[i]) {
                dp[j] = a[i];
                break;
            }
        }
        // rep(i,dp.size()) cout << dp[i] << ' ';
        // cout << endl;
    }
    cout << dp.size() - 1 << endl;
}


Measured memory_bytes: 3952
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static int distToEnter(int N , int row , int col){
		int ret = Math.min(row, col);
		ret = Math.min(ret, N - 1 - row);
		ret = Math.min(ret, N - 1 - col);
		return ret;
	}
	static class Point{
		int x;
		int y;
		Point(int a , int b){
			x = a;
			y = b;
		}
	}
	static long solve(int N , int P[]){		
		int dist[][] = new int[N][N];
		int occupied[][] = new int[N][N];
		for(int i = 0 ; i < N ; ++i){
			for(int j = 0 ; j < N ; ++j){
				dist[i][j] = distToEnter(N, i, j);
				occupied[i][j] = 1;
			}
		}
		long ret = 0;
		int dx[] = { 0 , 0 , 1 , -1};
		int dy[] = { 1 ,-1 , 0 ,  0};
		for(int p : P){
			int row = p / N;
			int col = p % N;
			ret += dist[row][col];
			occupied[row][col] = 0;
			Point init = new Point(col, row);
			Queue<Point> q = new LinkedList<Point>();
			q.add(init);
			while(!q.isEmpty()){
				Point cp = q.poll();
				int d = dist[cp.y][cp.x] + occupied[cp.y][cp.x];
				for(int k = 0 ; k < 4 ; ++k){
					int nx = cp.x + dx[k];
					int ny = cp.y + dy[k];
					if(nx < 0 || ny < 0 || nx >= N || ny >= N){
						continue;
					}
//					System.out.println(dist[ny][nx]+" "+d+" "+nx+" "+ny);
					if(dist[ny][nx] > d){
						dist[ny][nx] = d;
						q.add(new Point(nx , ny));
					}
				}
			}
//			System.out.println(Arrays.deepToString(dist));
		}
		return ret;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int P[] = new int[N * N];
		for(int i = 0 ; i < P.length ; ++i){
			P[i] = sc.nextInt() - 1;
		}
		System.out.println(solve(N , P));
	}
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

const int N = 2e5 + 7;

int n;
char s[N];
int last[26][N];
string ans = "";

int g[26][N];
int pre[26][N];

int main()
{
    _upgrade
    cin >> (s + 1);
    n = strlen(s + 1);
    reverse(s + 1, s + n + 1);
    for(int i = 0; i < 26; i++)
        last[i][n + 1] = n + 1;
    for(int i = n; i >= 0; i--)
    {
        for(int j = 0; j < 26; j++)
        {
            last[j][i] = last[j][i + 1];
        }
        if(i != n)
        {
            last[s[i + 1] - 'a'][i] = i + 1;
        }
    }

    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < 26; j++)
        {
            for(int k = 0; k < 26; k++)
            {
                if(last[j][g[k][i - 1]] > g[j][i])
                {
                    g[j][i] = max(g[j][i], last[j][g[k][i - 1]]);
                    pre[j][i] = k;
                }
                if(g[j][i] == n + 1)
                {
                    while(i > 0)
                    {
                        cout << (char)(j + 'a');
                        j = pre[j][i];
                        i--;
                    }
                    cout << "\n";
                    return 0;
                }
            }
        }
    }

	return 0;
}


Measured memory_bytes: 59520
#include <iostream>
#include <math.h>
#include <algorithm>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    REP(r, N / R + 1)
    {
        if (r * R > N)
            break;
        REP(g, N / G + 1)
        {
            if (r * R + g * G > N)
                break;
            if ((N - (r * R + g * G)) % B == 0)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N = 0;
  int M = 0;
  std::cin >> N >> M;
  std::string str;  //今回は15文字入力と予めわかっている
  std::vector<int> j_row(M, 0);
  std::vector<std::vector<int>> v(N, j_row);
  int K[40];

  std::vector<int> a_row(40, 0);
  std::vector<std::vector<int>> A(40, j_row);

  for (int i = 0; i < N; i++) {
    cin >> K[i];
    for (int j = 0; j < K[i]; ++j) {
      cin >> A[i][j];
    }
  }
  /*
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < A[i].size(); j++) {
        std::cout << A[i][j] << " ";
      }
      std::cout << std::endl;
    }
    */

  int counter_2 = 0;
  for (int m = 0; m < M; m++) {
    int counter = 0;
    for (int i = 0; i < N; i++) {
      auto itr = std::find(A[i].begin(), A[i].end(), m + 1);
      //  最初の要素5へのイテレータを返す
      if (itr != A[i].end()) {
        counter += 1;
      }
    }

    if (counter == N) {
      // std::cout << m << std::endl;
      counter_2 += 1;
    }
  }

  std::cout << counter_2 << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x[] = new int[n];
    for(int i = 0;i<n;i++){
      x[i] = sc.nextInt();
    }
    int mindis = 200000000;
    int minplace = -1;
    for(int i = 0;i<101;i++){
      int dis = 0;
      for(int j = 0;j<n;j++){
        dis += Math.abs(x[j] - i) * Math.abs(x[j] - i);
      }
      if(dis < mindis){
        mindis = dis;
        minplace = i;
      }
    }
    int ans = 0;
    for(int i = 0;i<n;i++){
      ans += (x[i] - minplace) * (x[i] - minplace);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

ans = 0

for i in range(n):
    a = list(map(int, input().split()))
    tmp = 0
    for j in range(m):
        tmp += a[j]*b[j]
    tmp += c
    if tmp > 0: ans += 1
print(ans)

Measured memory_bytes: 3060
/// {{{
#include "bits/stdc++.h"
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
#define   rep(i, s, t)       for(int i = int(s); i < int(t); ++i)
using namespace std;
typedef long long i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

int N, Q;
string s;

signed main()
{
  cin >> N >> Q;
  cin >> s;

  vector<int> x;

  for (int i = 0; i+1 < N; ++i) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      x.push_back(i);
    }
  }

  rep(k, 0, Q) {
    int l, r;
    cin >> l >> r;
    --l, --r;

    int a = lower_bound(ALL(x), l) - begin(x);
    int b = upper_bound(ALL(x), r-1) - begin(x);

    cout << (b - a) << '\n';
  }

  return 0;
}



Measured memory_bytes: 1276
N = int(raw_input())

s = []
for i in range(N):
    s.append(int(raw_input()))

score = sum(s)

if score%10 != 0:
    print score
else:
    a=sorted(s)
    exit=False
    for i in a:
        if i%10 != 0:
            print score-i
            exit=True
            break
    if not exit:
        print 0

Measured memory_bytes: 2568
#include <stdio.h>
#include <math.h>

int isprime(int x){
	int i, k=1;
	
	for(i=3; i<=sqrt(x); i++){
		if(x%i==0) {
			k=0;
			break;
		}
	}

	return k;
}

int main(void){
	while(1){
		int n;
		scanf(" %d", &n);
		if(n==0) break;
		if(n%2 == 0) n--;
		
		while(isprime(n) != 1 || isprime(n-2) != 1){
			n-=2;
		}
		
		printf("%d %d\n", n-2, n);
	}

	return 0;
}

Measured memory_bytes: 600
s = input()
n = len(s)

ans = [0] * n

# 左と右からそれぞれR, Lを見ていく。
# cntが奇数の場合は開始点に近い側が+1(切り上げ)になる。

# 左からRを数える。Lまで
cntr = 0
for itr, val in enumerate(s):
  if val == "R":
    cntr += 1
  else:
    ans[itr - 1] += (cntr - 1) // 2 + 1
    ans[itr] += cntr // 2
    cntr = 0
    
# 右からLを数える。Rまで
cntl = 0
for itr, val in enumerate(s[::-1]):
  if val == "L":
    cntl += 1
  else:
    ans[n - 1 - itr] += cntl // 2
    ans[n - 1 - itr + 1] += (cntl - 1) // 2 + 1
    cntl = 0
    
print(*ans)

Measured memory_bytes: 6400
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
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-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[210000];
int f[210000];
int t[210000];
int main(){
	int a;scanf("%d",&a);
	scanf("%s",in);
	char now='W';
	int cnt=0;
	for(int i=0;i<a*2;i++){
		if(now!=in[i]){
			f[i]=1;
			now=in[i];
			cnt++;
		}
	}
	if(cnt%2)f[a*2]=1;
	//for(int i=0;i<=a*2;i++)printf("%d",f[i]);printf("\n");
	for(int i=0;i<a*2;i++){
		if(f[i]){
			t[i]=1;
			f[i]=0;
		}else{
			if(f[i+1]==0){
				f[i+1]=1;
				t[i]=2;
			}else{
				f[i+1]=0;
				t[i]=2;
			}
		}
	}
	for(int i=0;i<a*2+1;i++){
		if(f[i]){printf("0\n");return 0;}
	}
	long long ret=1;
	int rem=0;
	for(int i=0;i<a*2;i++){
		if(t[i]==1)rem++;
		else{
			ret=ret*rem%mod;
			rem--;
		}
	}
	if(rem!=0)ret=0;
	for(int i=0;i<a;i++)ret=ret*(i+1)%mod;
	printf("%lld\n",ret);
}

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

int main()
{
  int count = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    if (i % 2 == 0)
    {
      if (s[i] == 'L')
      {
        cout << "No" << endl;
        return 0;
      }
    }
    if (i % 2 == 1)
    {
      if (s[i] == 'R')
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

map<string, int> mp;
char botton[][3] = {{'A', 'B', 'C'}, {'D', 'E', 'F'}, {'G', 'H', 'I'}};

int main(){

  
  string s;
  REP(i,1000){
    cin >> s;
    int len = s.length();
    bool ok = false;
    if(len == 1){
      cout << s << "\n";
      continue;
    }
    REP(j,len-1){
      bool make = false;
      int x, y;
      REP(ii,3){
        REP(jj,3){
          if(botton[ii][jj] == s[j]){
            x = jj; y = ii;
            make = true;
            break;
          }
        }
        if(make){
          make = false;
          break;
        }
      }

      REP(k,4){
        int xx = x + dx[k], yy = y + dy[k];
        if(xx >= 0 && xx < 3 && yy >= 0 && yy < 3){
          if(s[j+1] == botton[yy][xx]){
            make = true;
            break;
          }
        }
      }
      if(!make){
        break;
      }
      if(make && j == len - 2){
       ok = true;
      }
    }
    if(ok){
      cout << s << "\n";
    }
  }

  return 0;
}




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

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

    ll ans = 1e18;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i != 0)
            continue;

        ll j = N / i;
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l.reverse()
f = True

for i in range(len(l)-1):
    if l[i] < l[i+1]:
        if l[i+1] - l[i] == 1:
            l[i+1] -= 1
        else:
            f = False
            break

print("Yes" if f == True else "No")


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n,m;
int mod(int i){ return (i+n)%n; }
int main() {
  cin >> n >> m;

  vector<P> ans;
  int a = 0,b = 1;
  if(n%2==1){
    rep(i,m){
      ans.emplace_back(a,b);
      a = mod(a-1);
      b = mod(b+1);
    }
  }else{
    int p = (m+1)/2;
    rep(i,p){
      ans.emplace_back(a,b);
      a = mod(a-1);
      b = mod(b+1);
    }
    b = mod(b+1);
    rep(i,m-p){
      ans.emplace_back(a,b);
      a = mod(a-1);
      b = mod(b+1);
    }
  }
  rep(i,m){
    P p = ans[i];
    cout << min(p.first,p.second)+1 << " " << max(p.first,p.second)+1 << endl;
  }  
}


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

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

Measured memory_bytes: 256
n=int(input())
a=[0]*n
m=0
mi=0
for i in range(n):
    a[i]=int(input())
    if a[i]>=m:
        mi = i
        m=a[i]
la = sorted(a, reverse=True)
for i in range(n):
    if i == mi:
        print(la[1])
    else:
        print(m)

Measured memory_bytes: 14140
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int ch[5555];
ll dp[5555][5555][2],sp[2][5555][2],c[5555]={1ll};
std::vector<int> g[5555];

void solve(int v, int p = -1){
	int i,u,j,k,x=0,y=1,s,t;
	ch[v] = 1;
	for(i=g[v].l_ength()-1; i>=0; --i){
		u = g[v][i];
		if(u == p){
			continue;
		}
		solve(u,v);
	}
	for(i=0; i<=ch[v]; ++i){
		for(j=0; j<2; ++j){
			sp[x][i][j] = 0ll;
		}
	}
	sp[x][1][0] = 1ll;
	for(i=g[v].l_ength()-1; i>=0; --i){
		u = g[v][i];
		if(u == p){
			continue;
		}
		for(j=0; j<=ch[v]+ch[u]; ++j){
			for(k=0; k<2; ++k){
				sp[y][j][k] = 0ll;
			}
		}
		for(j=0; j<=ch[v]; ++j){
			for(k=0; k<=ch[u]; ++k){
				for(s=0; s<2; ++s){
					for(t=0; t<2; ++t){
						add_mod(sp[y][j+k][s^t],sp[x][j][s]*dp[u][k][t]%MOD);
						add_mod(sp[y][j][!(s^t)],sp[x][j][s]*dp[u][k][t]%MOD*c[k]%MOD);
					}
				}
			}
		}
		ch[v] += ch[u];
		std::swap(x,y);
	}
	for(i=0; i<=ch[v]; ++i){
		for(j=0; j<2; ++j){
			dp[v][i][j] = sp[x][i][j];
			// printf("%d, %d %d: %lld\n",v,i,j,dp[v][i][j]);
		}
	}
}

int main(void){
	int n,x,y,i;
	ll ans = 0ll;
	std::cin >> n;
	for(i=1; i<=n; i+=2){
		c[i+1] = c[i-1]*i%MOD;
	}
	for(i=1; i<n; ++i){
		std::cin >> x >> y;
		--x; --y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	solve(0);
	for(i=0; i<=n; ++i){
		add_mod(ans,dp[0][i][0]*c[i]%MOD);
		add_mod(ans,MOD-(dp[0][i][1]*c[i]%MOD));
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 161244
# -*- coding: utf-8 -*-

N = int(input())
H = list(map(int, input().split()))
C = list(map(lambda x:False, H))

Ans = "Yes"


base = H[0]
for i in range(1,N):
    if H[i] < base:
        Ans = "No"
    if H[i] > base:
        base = H[i] - 1

print(Ans)


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

int main() {
    int X;
    cin>>X;
    int ans = 1;
    for(int i=2;i<=sqrt(X);++i){
        int tmpans = i;
        while(tmpans <= X){
            tmpans *= i;
        }
        tmpans /= i;
        if(ans < tmpans)ans = tmpans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}


const ll N=2e5+5;


int main()
{ 

IOS;

string s;cin>>s;

ll c=0;

//sort(all(s));

for(int i=0;i<3;i++){
  if(s[i]=='R')c++;
}

if(!c||c==3||c==1){
  d1(c);
  return 0;
}

if(c==2){
  if(s[0]=='R'&&s[2]=='R'){
    d1(1);
    
  }
  else d1(c);
}


//d1(c);
//end_routine();

return 0;
 
 }


Measured memory_bytes: 3676
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true) {
			int n = stdIn.nextInt();
			int k = stdIn.nextInt();
			int m = stdIn.nextInt();
			if(n == 0 && k == 0 && m == 0) break;
			list = new ArrayList<Integer>();
			for(int i = 0; i < n; i++) {
				list.add(i+1);
			}
			int nowp = m-1;
			list.remove(nowp);
			while(list.size() != 1) {
				nowp += k-1;
				nowp %= list.size();
				list.remove(nowp);
			}
			
			System.out.println(list.get(0));
		}
	}
}

Measured memory_bytes: 36048
#include <bits/stdc++.h>
using namespace std;
int a, b, cnt;
int main()
{
  int n;cin>>n;
  for (int i = 1; i <= n; i+=1)
  {
  	cin >> a;
    if (i & 1)
      if (a & 1) ++cnt;
  }
  cout<<cnt<<endl;
}

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

int main()
{
	int n, x, c=0;
	while(true) {
		cin >> n >> x;
		if (n==0 && x == 0) {
			break;
		}
		c= 0;
		for(int i = 1; i <= n-2; i++) {
			for(int j = i+1; j <= n-1; j++) {
				for(int k = j+1; k <= n; k++) {
					if(i+j+k == x) {
						c+=1;
					}
				}
			}
		}
		cout << c << endl;
	}
}



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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
struct Edge{
int t;
};
struct Node{
  int no;
  vector<int> edge;
  bool have(int x){
    bool res=false;
    int n=edge.size();
    rep(i,n){
      if(edge[i]==x)res=true;
    }
    return res;
  }
};
signed main(){
  int n,m;cin>>n>>m;
  int res=0;
  vector<Node> node(n+1);
  vector<int> p(n-1);
  rep(i,n-1){
    p[i]=i+2;
  }
  rep(i,m){
    int a,b;cin>>a>>b;
    node[a].edge.push_back(b);
    node[b].edge.push_back(a);
  }
  do{
    int s=1;
    rep(i,n-1){
      if(!node[s].have(p[i])){
        goto FINE;
      }
      s=p[i];
    }
    res++;
    FINE:;
  }while(next_permutation(p.begin(),p.end()));
  cout<<res<<endl;
  return 0;
}


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

int ok(int x){
    if (x % 2 == 0){
        if (x % 3 == 0)
            return 1;
        else if (x%5== 0)
            return 1;
        else
            return 0;
    }else
    {
        return 1;
    }

}

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

    // Yes
    int res=1;
    for (int i=0;i<N;++i){
        if (ok(A[i]) == 0) 
            res = 0;
    }

    if (res == 1)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;


}

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

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int N;
  cin >> N;

  if(N == 1){
    cout << "Hello World" << endl;
  }else{
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N, M = (int(i) for i in input().split()) 

lv = []
for i in range(N):
    a = [int(i) for i in input().split()] 
    lv.append(set(a[1:]))

res = lv[0]
for i in lv:
    res = res & i

print(len(res))


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long


int main() {
    int n, m, c;
    cin >> n >> m >> c;

    int b[20];
    for (int i=0; i < m; i++) {
        cin >> b[i];
    }


    int ans = 0;
    for (int k=0; k < n; k++) {
        int a;
        int sum = 0;
        for (int i=0; i < m; i++) {
            cin >> a;
            sum += b[i] * a;
        }
        sum += c;
        if (sum > 0) ans++;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {

	int x,y;
	cin>>x>>y;
	if(y%2!=0)
		cout<<"No";
	else {
		int z = y/2;
		int k= 0;
		for(int i=x; i>=0; i--) {
			k = x - i;
			if(i+2*k==z) {
				cout<<"Yes";
				return 0;
			}

		}
		cout<<"No";
	}


	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int dp[105][4][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
	int K;
	cin >> K;
    dp[0][0][0] = 1;
    rep(i,n) rep(j,4) rep(k,2) {
        int nd = s[i] - '0';
        rep(d,10) {
            int ni = i+1, nj = j, nk = k;
            if(d != 0) nj++;
            if(nj > K) continue;
            if(k == 0) {
                if(d > nd) continue;
                if(d < nd) nk = 1;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())

reds = []
for _ in range(N):
    reds.append(tuple(map(int, input().split())))
    
blues = []
for _ in range(N):
    blues.append(tuple(map(int, input().split())))

reds.sort()
blues.sort()

ans = 0
for blue in blues:
    c, d = blue

    # 条件に当てはまる赤を抽出
    targets = [red for red in reds if red[0] < c and red[1] < d]
    targets.sort(key=lambda x:x[1])

    # 赤のうち一番y座標が大きいものを抽出
    if targets:
        target = targets.pop()
        reds.remove(target)
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    
    int a, b;
    cin >> a >> b;
    int h, w;
    cin >> h >> w;
    cout << a * b - (h * b + a * w - h * w) << endl;
	return 0;
} 

Measured memory_bytes: 256
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repe(i, n) for(int i = 0; i <= (n); i++)
#define fo(i, a, b) for(int i = (a); i < (b); i++)
#define foe(i, a, b) for(int i = (a); i <= (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

struct E {
	int idx, cnt;
	E() : idx(-1), cnt(0) {}
	bool operator<(const E& o) const {
		if (cnt == o.cnt) return idx < o.idx;
		else return cnt < o.cnt;
	}
	bool operator>(const E& o) const { 
		if (cnt == o.cnt) return idx > o.idx;
		else return cnt > o.cnt;
	}
};
vector<E> even(100003);
vector<E> odd(100003);

int n;

int get(int idxe, int idxo) {
	return (n - 1) / 2 + 1 - even[idxe].cnt + n / 2 - odd[idxo].cnt;
}
int main() {

	cin >> n;
	rep(i, n) {
		int v;
		cin >> v;
		if (i & 1) {
			odd[v].idx = v;
			odd[v].cnt++;
		} else {
			even[v].idx = v;
			even[v].cnt++;
		}
	}

	sort(odd.begin(), odd.end(), greater<E>());
	sort(even.begin(), even.end(), greater<E>());

	int oddI = 0, evenI = 0;

	if (odd[oddI].idx == even[evenI].idx) {
		if (get(evenI + 1, oddI) < get(evenI, oddI + 1)) {
			cout << get(evenI + 1, oddI) NL;
		} else {
			cout << get(evenI, oddI + 1) NL;
		}
	} else {
		cout << get(evenI, oddI) NL;
	}
	return 0;

}



Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7) cout<<"YES";
  else if(a==5&&b==7&&c==5) cout<<"YES";
  else if(a==7&&b==5&&c==5) cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                  1000000007
#define eps         0.00000000000000001
#define endl                       '\n'

using namespace std;

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

vector<int> adj[300010];
vector<int> par(300010,-1);
vector<int> disco(300010,-1);
vector<int> finis(300010,-1);
vector<int> typ(300010,0);
vector<int> vis(300010,0);
vector<int> dis(300010,0);
vector<int> val;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int a,b,c;
    cin>>a>>b>>c;
    vector<int> v={a,b,c};
    sort(v.begin(),v.end());
    if(v[1]==c)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 14336
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
bool judge(vector<vector<char>> s,int i,int j){
  bool flag=true;
  if(s[i][j]=='#'){
    flag=false;
    if(s[i][j+1]=='#')flag=true;
    if(s[i][j-1]=='#')flag=true;
    if(s[i+1][j]=='#')flag=true;
    if(s[i-1][j]=='#')flag=true;
  }
  return flag;
}
signed main(){
  int h,w;cin>>h>>w;
  vector<vector<char>> s(h+2,vector<char>(w+2,'.'));
  rep1(i,h){
    rep1(j,w){
      cin>>s[i][j];
    }
  }
  bool flag=false;
  rep1(i,h){
    rep1(j,w){
      if(!judge(s,i,j)){
        flag=true;
      }
    }
  }
  	if(!flag){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(true){
            int h = scanner.nextInt();
            int s = scanner.nextInt();
            if(h ==0 || s ==0){break;}
            for(int i=0; i<h; i++){
                if(i==0 || i==h-1){
                    for(int j=0; j<s; j++){
                        System.out.print("#");
                    }
                }else{
                    for(int j=0; j<s; j++){
                        if(j==0 || j==s-1){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
        scanner.close();
    }
}


Measured memory_bytes: 36468
def fact(x):
    if x == 0 or x == 1:
        return 1

    ans = 1
    for i in range(1,x+1):
        ans *= i
    return ans
def combi(n,r):
    return fact(n)//((fact(r))*(fact(n-r)))

N, P = map(int,input().split())
A = list(map(lambda x: int(x)%2,input().split()))
cnt1 = A.count(1)
t = P
sumC = 0
while  t <= cnt1:
    sumC += combi(cnt1,t)
    t += 2
print(sumC*(2**(N-cnt1)))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long long int f(long long int,long long int,long long int);

int main(void)
{
    long long int n,m,mod=1000000007,ans,x,now=1;
    scanf("%lld %lld",&n,&m);
    if(n-m>1||n-m<-1)
    {
        printf("0");
        return 0;
    }
    x=f(n,mod,now);
    ans=f(m,mod,x);
    if(n==m) ans*=2;
    printf("%lld",ans%mod);
    return 0;
}

long long int f(long long int n,long long int mod,long long int now)
{
    int i;
    for(i=1;i<=n;i++)
    {
        now*=i;
        now%=mod;
    }
    return now;
}




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

vector<vector<int>> refresh(vector<vector<int>> b, int h){
    vector<vector<int>> ret(h, vector<int>(5, 0));
    rep(j, 5){
        vector<int> nonzero;
        for(int i = h-1; i >= 0; --i){
            if(b[i][j] != 0) nonzero.push_back(b[i][j]);
        }

        rep(i, nonzero.size()){
            ret[h-i-1][j] = nonzero[i];
        }

    }

    return ret;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    while(1){
        int h;
        cin >> h;

        if(h == 0) break;

        vector<vector<int>> b(h, vector<int>(5));
        rep(i, h) rep(j, 5) cin >> b[i][j];

        int res = 0;
        while(1){

            int r_sm = 0;
            rep(i, h){

                int sm = 0;
                if(b[i][0]==b[i][1] && b[i][1]==b[i][2] && b[i][2]==b[i][3] && b[i][3]==b[i][4]){
                    sm += b[i][0] * 5;
                    rep(j, 5) b[i][j] = 0;
                }

                else if((b[i][0]==b[i][1] && b[i][1]==b[i][2] && b[i][2]==b[i][3]) || (b[i][1]==b[i][2] && b[i][2]==b[i][3] && b[i][3]==b[i][4])){
                    if(b[i][0] == b[i][1]){
                        sm += b[i][0] * 4;
                        rep(j, 4) b[i][j] = 0;
                    }
                    else{
                        sm += b[i][1] * 4;
                        rep1(j, 5) b[i][j] =0;
                    }
                }

                else if((b[i][0]==b[i][1] && b[i][1]==b[i][2]) || (b[i][1]==b[i][2] && b[i][2]==b[i][3]) || (b[i][2]==b[i][3] && b[i][3]==b[i][4])){
                    if(b[i][0] == b[i][1] && b[i][1]==b[i][2]){
                        sm += b[i][0] * 3;
                        rep(j, 3) b[i][j] = 0;
                    }
                    else if(b[i][2]==b[i][3] && b[i][3] == b[i][4]){
                        sm += b[i][2] * 3;
                        for(int j = 2; j < 5; ++j) b[i][j] = 0;
                    }
                    else{
                        sm += b[i][1] * 3;
                        rep1(j, 4) b[i][j] = 0;
                    }
                }

                r_sm += sm;

            }

            if(r_sm == 0) break;
            else{
                res += r_sm;

                // cout << endl;
                // rep(i, h){
                //     rep(j, 5) cout << b[i][j] << " ";
                //     cout << endl;
                // }

                b = refresh(b, h);
                // cout << endl;
                // rep(i, h){
                //     rep(j, 5) cout << b[i][j] << " ";
                //     cout << endl;
                // }
            }
        }

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

const int maxN=1e5+5;

bool visited[maxN];
int dist[maxN];
int in_degree[maxN];
graph g(maxN);

void dfs(int nodo)
{
	visited[nodo]=1;
	for(int x: g[nodo])
	{
		dist[x]=max(dist[x],dist[nodo]+1);
		in_degree[x]--;
		if(!(in_degree[x]))
			dfs(x);
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n,m;
	cin>>n>>m;
	while (m--)
	{
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		in_degree[y]++;
	}
	
	for (int i = 1; i < n+1; i++)
	{
		if( (!visited[i]) && (!in_degree[i]) )
			dfs(i);
	}
	
	int ans=0;
	for (int i = 1; i < n+1; i++)
	{
		ans=max(ans,dist[i]);
	}
	
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 10496
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	long N=sc.nextLong();
	long A=sc.nextLong();
	long B=sc.nextLong();
	if((B-A)%2==0) {
		System.out.println((B-A)/2);
	}else {
		if(N-B<=A-1) {
			System.out.println((2*N-B-A)/2+1);
		}else {


			System.out.println((A+B-2)/2+1);


		}

	}


	}
}

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

int n;

int main()
{
    cin>>n;
    int a=n,c=0;
    while(a>0)
    {
        c+=a%10;
        a/=10;
    }
    if(n%c==0)
    {
      cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Long](N+1)
  for(i <- 1 to N)
    A(i) = in.next().toLong


  //
  def check(mid: Int, base: Int): Long = {
    if(mid < base) {
      val l = imos(mid-1)
      val r = imos(base-1) - l
      (r-l).abs
    }
    else {
      val l = imos(mid) - imos(base-1)
      val r = imos(N) - imos(mid)
      (r-l).abs
    }
  }



  // 下に凸のグラフの最小値
  def ternarySearchInt(small: Int, big: Int, i: Int): Int = {
    if(big - small <= 2) {
      val mid = (big + small) / 2
      if(check(big, i) <= check(mid, i)) big
      else if(check(small, i) <= check(mid, i)) small
      else mid
    }
    else{
      val midl = (big + small) / 2
      val midr = midl + 1
      if (check(midl, i) >= check(midr, i))
        ternarySearchInt(midl, big, i)
      else
        ternarySearchInt(small, midr, i)
    }
  }


  val imos = new Array[Long](N+1)
  for(i <- 1 to N) {
    imos(i) = imos(i-1) + A(i)
  }

  var ans = Long.MaxValue
  for(i <- 3 to N-1) { // iが右ブロックの最初
    val l = ternarySearchInt(1, i-1, i)
    val r = ternarySearchInt(i, N, i)
    val P = imos(l-1)
    val Q = imos(i-1) - P
    val R = imos(r) - imos(i-1)
    val S = imos(N) - imos(r)
    val hoge = List(P,Q,R,S)

    ans = Math.min(ans, hoge.max - hoge.min)
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 69148
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
const int mod=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}

int32_t main(){
	
	//FIO();
	
		string s,t;cin>>s>>t;
		if(s.length()+1==t.length()&&t.substr(0,s.length())==s)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	
	
	return 0;
	
		
}


Measured memory_bytes: 3600
import sys
from heapq import *
input = sys.stdin.readline


def main():
    n = int(input())
    a = list(map(int, input().split()))

    af = a[:n]
    ab = [-v for v in a[2*n:]]
    af_sum = sum(af)
    ab_sum = -sum(ab)

    heapify(af)
    heapify(ab)
    judge = [0]*(n+1)
    judge[0] += af_sum
    judge[n] -= ab_sum
    
    for i in range(n):
        if a[n+i] > af[0]:
            af_sum -= heappop(af)
            heappush(af, a[n+i])
            af_sum += a[n+i]
        judge[i+1] += af_sum
        
        if -a[2*n-1-i] > ab[0]:
            ab_sum += heappop(ab)
            heappush(ab, -a[2*n-1-i])
            ab_sum += a[2*n-1-i]
        judge[n-1-i] -= ab_sum
    

    ans = max(judge)
    print(ans)

    
if __name__ == "__main__":
    main()


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  vi arr(n);
  REP(i, 0, n)  cin >> arr[i];

  int cnt = 0;
  for(int i = 1; i < n - 1; i++){
    if((arr[i - 1] < arr[i] && arr[i] < arr[i + 1]) || (arr[i - 1] > arr[i] && arr[i] > arr[i + 1]))
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int ans=0;
  for(int i=1;i<=n;i++){
    int sum=0;
    sum+=i/10000;
    sum+=(i-i/10000*10000)/1000;
    sum+=(i-i/1000*1000)/100;
    sum+=(i-i/100*100)/10;
    sum+=i-i/10*10;
    if(a<=sum && b>=sum) ans += i;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256