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

using namespace std;

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

	vector<pair<int, int>> ans;
	int sum = n * (n + 1) / 2;
	int sum_t = sum - n;
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (n % 2 == 0) {
				if (n + 1 - i != j) {
					ans.emplace_back(make_pair(i, j));
				}
			} else {
				if (j != n - i) {
					ans.emplace_back(make_pair(i, j));
				}
			}
		}
	}

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

	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	string S;
	cin >> S;

	vector<int> nums;

	if (S[0] == '0') nums.push_back(0);

	int j = 0;

	for (int i = 0; i < S.size();)
	{
		j = i;

		while (i < S.size() && S[i] == S[j])
		{
			++j;
		}
		nums.push_back(j - i);
		i = j;
	}

	if (S.back() == '0') nums.push_back(0);

	int max_ = 0;

	for (int i = 0; i < nums.size(); i += 2)
	{
		int k = i + (2 * K + 1);

		if (k >= nums.size()) k = nums.size();

		int tmp = 0;

		for (int j = i; j < k; j++)
		{
			tmp += nums[j];
		}

		max_ = max(max_, tmp);

		//cout << tmp << endl;
	}

	cout << max_ << endl;


	/*
	for (int i = 0; i < nums.size(); i++)
	{
		cout << nums[i] << " ";
	}
	*/
}

Measured memory_bytes: 1020
n = int(input())
a = list(map(int, input().split()))
alice = []
bob = []

for i in range(n):
    if i % 2 == 0:
        alice.append(max(a))
        a.remove(max(a))
    else:
        bob.append(max(a))
        a.remove(max(a))

print(sum(alice)-sum(bob))

Measured memory_bytes: 9084
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -float('inf')
for item in range(1, 1024):
    fund = 0
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (item >> x) % 2 == 1 and f[i][x] == 1:
                cnt += 1
        fund += p[i][cnt]
    ans = max(ans, fund)

print(ans)

Measured memory_bytes: 42092
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n;
  cin >> n;
  
  map <int,int>mp;
  
  REP(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  
  int ans = 0;
  ITR(itr,mp){
    if(itr->second % 2 == 1) ans++;
  }
  
  cout << ans << endl;


 return 0;
}

Measured memory_bytes: 4864
N = int(input())
*A, = map(int, input().split())
b = [0] * N
for i in range(N-1, -1, -1):
   chk = sum(b[i:N:i+1])
   if chk % 2 ^ A[i]:
       b[i] = 1

print(sum(b))
ans = []
for i, v in enumerate(b):
    if v == 1:
        ans.append(i+1)
print(*ans)


Measured memory_bytes: 14132
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int d[3333];
int main()
{
	int num, kai;
	scanf("%d%d", &num, &kai);
	for (int i = 0; i < num; i++)scanf("%d", &d[i]);
	ll s1 = 0, s2 = 0;
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < num; j++)
		{
			if (d[i] > d[j])
			{
				s2++;
				if (i < j)s1++;
			}
		}
	}
	printf("%lld\n", (s1*kai + s2*kai%mod*(kai - 1) % mod*(mod + 1) / 2) % mod);
}

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

int dp[100000][3]; 
//dp[i][j]表示第i天玩第j项活动，从第一天到第i天累计获得第最大第快乐值
int a[100000][3];
//a[i][3]保存第i天，三项每项获得第快乐值

int main(){
    int n,lage;
    cin>>n;
    cin>>a[0][0]>>a[0][1]>>a[0][2];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;++i){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    lage=max(dp[n-1][0],dp[n-1][1]);
    lage=max(lage,dp[n-1][2]);
    cout<<lage<<endl;
    return 0;
}

Measured memory_bytes: 2560
N = input()

ans = 0
for i in range(len(N)):
    if i < len(N) - 1:
        if i % 2 == 0:
            ans += 9 * 10 ** i
    else:
        if i % 2 == 0:
            ans += int(N) - 10 ** i + 1

print(ans)


Measured memory_bytes: 38256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

string S,T;

string ans = "";
 
void solve(){
	int N = S.length();
	int M = T.length();
	//Sの先頭からi文字、Tの先頭からj文字見たときの
	//条件を満たす最大長の文字列の長さをdp[i][j]とおく
	vector<vector<int>> dp(N+1,vector<int>(M+1,0));

    for (int i=1;i<=N;i++) {
        for (int j=1;j<=M;j++) {
        	//斜め方向に更新
        	//Sのi文字目とTのj文字目が一致しているなら
        	//LCSは一文字増えるはず
        	//もし一致していないならLCSの長さには変化なしなので
        	//斜め移動しても意味がない
            if (S[i-1]==T[j-1]) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
            //dp[i][j-1]に対して、Tのj文字目を考慮しても特にLCSの長さは変わらず
            //Tのj文字目とSのi文字目が仮に同じだったときは、すでに斜め方向のdpによってカウントされているので
            //それについては縦横方向の更新時には考慮しなくてもよい
            dp[i][j] = max(dp[i][j],dp[i][j-1]);
            dp[i][j] = max(dp[i][j],dp[i-1][j]);
        }
    }

    // 復元
    int i=N, j=M;
    while (i>0 && j>0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j]==dp[i-1][j]) {
        	//縦方向の遷移では特にLCSの長さは変化しない
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j]==dp[i][j-1]) {
        	//横方向の遷移では特にLCSの長さは変化しない
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
        	//斜め方向の遷移ではLCSに、Sのi文字目とTのj文字目が一致しているなら
        	//その文字が追加されているはず
            ans=S[i-1]+ans; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
}
 
int main(){
	cin >> S;
	cin >> T;
 
	solve();

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

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
int main(){
    int a,b,c; cin >> a >> b >> c;
    cout << min(a,min(b,c)) << " " << max(a,max(b,c)) << endl;
}
  




Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define N 16 
using namespace std;
int m,n;
double neko[N][N];
double dfs(int pos,int k,int bit);

int used[N][1<<N]={};
double mem[N][1<<N];
double calc(int pos,int bit){
  if(used[pos][bit]++)return mem[pos][bit];
  double mx = 0;
  for(int i=0;i<m;i++)if(((bit>>i)&1)==0)mx=max(mx,dfs(pos,i,bit));
  return mem[pos][bit] = mx;
}

double dfs(int pos,int k,int bit){
  if(pos==n) return 1;
  double p = neko[k][pos];
  return p*dfs(pos+1,k,bit) + (1-p)*calc(pos,bit|(1<<k));
}

int main(){
  cin>>m>>n;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)cin>>neko[i][j];
  
  printf("%.10f\n",calc(0,0));
  return 0;
}

Measured memory_bytes: 15556
//=========================================================
// Contents    : AOJ ITP1_4_B
//               半径 r の円の、面積と円周の長さを求める
// Constraints : 0 < r < 10,000
// Author      : 廣部智也
// LastUpdate  : 2020/05/26
// Since       : 2020/05/23
//=========================================================

#include <stdio.h>
#include <math.h>                       // M_PI (円周率) 使用のため

int main(){
    
    double r = 0, area = 0, circle = 0;
    
    // データの入力
    scanf("%lf", &r );                  // double型：scanfは"%lf"、printfは"%f"
    
    if( r < 0 || r > 100000 ){
        return 0;
    }
    
    // データの処理
    area    = r * r * M_PI;
    circle  = r * 2 * M_PI;

    // データの出力
    printf("%f %f\n", area , circle );
    
    return 0;
}



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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for(int i = a; i <= min(a+k-1, b); i++) {
    cout << i << endl;
  }
  for(int i = max(b-k+1, a+k); i <= b; i++) {
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
from collections import Counter
import copy
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
Q = int(input())
total = sum(A)
for i in range(Q):
    x,y = map(int,input().split())
    num = copy.deepcopy(c[x])
    total = total + ((y-x)*num)
    c[x] = 0
    c[y] += num
    print(total)


Measured memory_bytes: 89972
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int k,x;
int main(void){
    scanf("%d %d",&k,&x);
    if (k*500>=x)
    {
        printf(yes);
    }else
    {
        printf(no);
    }
    
    
    return 0;
}


Measured memory_bytes: 128
def div2(x: int):
    if x % 2 == 0:
        return int(x / 2)
    else:
        return False


def judge(l: list, count: int):
    l = list(map(div2, l))

    if False in l:
        print(count)
        return
    else:
        judge(l, count + 1)


n = int(input())
a_list = list(map(int, input().split(" ")))

judge(a_list, 0)


Measured memory_bytes: 3188
// 5/13 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const ll INF = 1000000009;

int main() {
    ll N;  // モンスターの数
    ll D;  // 爆弾の距離
    ll A;  // 爆弾の威力
    cin >> N >> D >> A;

    // vector<ll> X(N), H(N);
    vector<pair<ll, ll>> Monster(N);
    rep(i, N) {
        ll x, h;
        cin >> x >> h;
        Monster[i] = make_pair(x, h);
    }

    sort(Monster.begin(), Monster.end());

    // 以下は自力実装。いくつかのデータでTLE。

    // vector<ll> max_j(N);
    // vector<ll> damage_sum(N, 0);

    // rep(i, N) {
    //     auto it = upper_bound(Monster.begin(), Monster.end(), make_pair(Monster[i].first + 2 * D, INF));

    //     // cout << it - Monster.begin() - 1 << endl;
    //     max_j[i] = it - Monster.begin() - 1;
    // }

    // ll ans = 0;

    // rep(i, N) {
    //     ll hitpoint_left = Monster[i].second - damage_sum[i];

    //     if (hitpoint_left > 0) {
    //         ll attack_num = hitpoint_left / A;
    //         if (hitpoint_left % A != 0) attack_num += 1;

    //         for (int k = i; k <= max_j[i]; k++) {
    //             damage_sum[k] += A * attack_num;
    //         }

    //         ans += attack_num;
    //     }
    // }

    // 以下は解説動画のsnukeさんの実装

    ll tot = 0;  // その時点のトータルダメージ
    queue<pair<ll, ll>> q;
    ll ans = 0;

    rep(i, N) {
        ll x = Monster[i].first;
        ll h = Monster[i].second;        

        while (q.size() && q.front().first < x) {
            tot -= q.front().second;
            q.pop();
        }

        h -= tot;

        if (h > 0) {
            ll num = (h + A - 1) / A;
            tot += num * A;
            q.emplace(make_pair(x + 2 * D, num * A));
            ans += num;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 7920
def f(L):
    a=len(L)
    b=L[0]
    c=0
    for i in range(len(L)):
        if L[i]<b:
            b=L[i]
        if b==L[i]:
            c+=1
    return c
a=int(input())
L=list(map(int,input().split()))
print(f(L))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
int A[6060];
int dp[2060][2020];
int ma[2020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,3*N) {
		cin>>A[i];
		A[i]--;
	}
	
	int ret=0;
	FOR(x,N) {
		FOR(y,N) dp[x][y]=-1<<20;
		ma[x]=-1<<20;
	}
	dp[A[0]][A[1]]=0;
	ma[A[0]]=ma[A[1]]=0;
	
	for(i=2;i+2<3*N;i+=3) {
		sort(A+i,A+i+3);
		if(A[i]==A[i+2]) {
			ret++;
			continue;
		}
		vector<vector<int>> cand;
		if(A[i]==A[i+1]) {
			FOR(x,N) cand.push_back({A[i+2],x,max(dp[A[i+1]][x],dp[x][A[i+1]])+1});
		}
		if(A[i+1]==A[i+2]) {
			FOR(x,N) cand.push_back({A[i+0],x,max(dp[A[i+1]][x],dp[x][A[i+1]])+1});
		}
		for(j=i;j<i+3;j++) {
			FOR(x,N) cand.push_back({x,A[j],ma[x]});
		}
		
		
		cand.push_back({A[i+0],A[i+1],dp[A[i+2]][A[i+2]]+1});
		cand.push_back({A[i+0],A[i+2],dp[A[i+1]][A[i+1]]+1});
		cand.push_back({A[i+1],A[i+2],dp[A[i+0]][A[i+0]]+1});
		
		int tmp=-1;
		FOR(x,N) tmp=max(ma[x],tmp);
		cand.push_back({A[i+0],A[i+1],tmp});
		cand.push_back({A[i+0],A[i+2],tmp});
		cand.push_back({A[i+1],A[i+2],tmp});
		
		FORR(c,cand) {
			dp[c[0]][c[1]]=max(dp[c[0]][c[1]],c[2]);
			ma[c[0]]=max(ma[c[0]],c[2]);
			ma[c[1]]=max(ma[c[1]],c[2]);
		}
	}
	
	int ma2=0;
	FOR(x,N) ma2=max(ma2,ma[x]);
	ma2=max(ma2,dp[A[3*N-1]][A[3*N-1]]+1);
	
	cout<<ma2+ret<<endl;
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        if(b == c){
            cout << 1 << endl;
        }else{
            cout << 2 << endl;
        }
    }else{
        if(b == c){
            cout << 2 << endl;
        }else{
            if(a == c){
                cout << 2 << endl;
            }else{
                cout << 3 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
    "os"
    "bufio"
    "strings"
    "strconv"
)

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    //N, _ := strconv.Atoi(arr[0])
    M, _ := strconv.Atoi(arr[1])
    var L, R int
    var min, max int

    for i := 0; i < M; i++ {
        line = readLine(reader)
        arr = strings.Split(line, " ")
        L, _ = strconv.Atoi(arr[0])
        R, _ = strconv.Atoi(arr[1])

        if i == 0 {
            min = L
            max = R
        } else {
            if min < L {
                min = L
            }

            if max > R {
                max = R
            }
        }
    }

    var retval int

    if max - min >= 0 {
        retval = max - min + 1
    } else {
        retval = 0
    }

    fmt.Println(retval)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 5504
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

bool isPrime(long long n) {
  if (n < 2)
    return false;
  
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0)
      return false;
  
  return true;           
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;

  int r = 0;
  REP (i, n) {
    int x;
    cin >> x;
    r += isPrime(x);
  }
  cout << r << endl;
  
  return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	vector<int>v(26);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		v[s[0] - 'A']++;
	}
	int ans = 0;
	while (1) {
		sort(v.begin(), v.end(), greater<int>());
		for (int i = 0; i < k; i++) {
			if (v[i] == 0) {
				cout << ans << endl; return 0;
			}
			v[i]--;
		}
		ans++;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	if( n == 22 ) cout << "Christmas Eve Eve Eve" << endl;
	if( n == 23 ) cout << "Christmas Eve Eve" << endl;
	if( n == 24 ) cout << "Christmas Eve" << endl;
	if( n == 25 ) cout << "Christmas" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main() {
	int R;
	cin>>R;
	if(R<1200)cout<<"ABC";
	else if(R<2800)cout<<"ARC";
	else cout<<"AGC";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<bitset>
#include<algorithm>
using namespace std;
char str[55];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	scanf("%s",str);
	bool ok=1;
	for(int i=0;i<a;++i) if(str[i]>='0'&&str[i]<='9') continue; else ok=0;
	if(str[a]!='-') ok=0;
	for(int i=a+1;i<=a+b;++i) if(str[i]>='0'&&str[i]<='9') continue; else ok=0;
	if(ok) puts("Yes");else puts("No");
} 

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define mp make_pair
#define fir first
#define sec second
#define N 200010
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
typedef pair<int,int> pii;
inline int inn()
{
    int x,ch;while((ch=gc)<'0'||ch>'9');
    x=ch^'0';while((ch=gc)>='0'&&ch<='9')
        x=(x<<1)+(x<<3)+(ch^'0');return x;
}
struct segment{
    int l,r,mn,pt;
    segment *ch[2];
}*rt;pii a[N];
inline int push_up(segment* &rt) { return rt->mn=min(rt->ch[0]->mn,rt->ch[1]->mn); }
inline int update_tags(segment* &rt,int v) { return rt->mn+=v,rt->pt+=v; }
inline int push_down(segment* &rt)
{   return update_tags(rt->ch[0],rt->pt),update_tags(rt->ch[1],rt->pt),rt->pt=0;    }
int build(segment* &rt,int l,int r,int x)
{
    rt=new segment,rt->l=l,rt->r=r,rt->pt=0;
    if(l==r) return rt->mn=x-l;int mid=(l+r)>>1;
    build(rt->ch[0],l,mid,x),build(rt->ch[1],mid+1,r,x);
    return push_up(rt);
}
int update(segment* &rt,int s,int t,int v)
{
    if(s>t) return 0;
    int l=rt->l,r=rt->r,mid=(l+r)>>1;
    if(s<=l&&r<=t) return update_tags(rt,v);
    if(rt->pt) push_down(rt);
    if(s<=mid) update(rt->ch[0],s,t,v);
    if(mid<t) update(rt->ch[1],s,t,v);
    return push_up(rt);
}
int main()
{
    int n=inn(),m=inn(),Ans=min(n,m);
    for(int i=1,l,r;i<=n;i++)
        l=inn(),r=inn(),a[i]=mp(l,r);
    sort(a+1,a+n+1),build(rt,1,m+1,m+1);
    for(int l=0,c=0;l<=m;l++)
    {
        while(c<n&&a[c+1].fir<=l)
            c++,update(rt,a[c].sec+1,m+1,1);
        Ans=min(Ans,n-c+l+rt->mn);
    }
    return !printf("%d\n",n-Ans);
}

Measured memory_bytes: 20608
import java.io.*;

public class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while(true){
            String[] str = br.readLine().split(" ");
            int h = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
            StringBuilder sb = new StringBuilder();

            if( h == 0 && w == 0)break;
            for(int i=0; i<h; i++){
                if(i==0 || i==h-1){
                    for(int k=0; k<w; k++){
                        sb.append("#");
                    }
                    sb.append("\n");
                }else{
                    for(int k=0; k<w; k++){
                        if(k==0 || k==w-1){
                            sb.append("#");
                        }else{
                            sb.append(".");
                        }
                    }
                    sb.append("\n");
                }
            }
            System.out.println(sb);
        }

    }
}

Measured memory_bytes: 25100
import java.util.*;
 
public class Main {
    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();
		}
		long x = 0;
		long as = 0;
		long evena = 0;
		for(int i=0; i<n; i++){
			as += a[i];
			if(i%2!=0){
				evena += a[i];
			}
		}
		x = as - 2*evena;
		long ans[] = new long[n];
		ans[0] = x;
		for(int i=0; i<n-1; i++){
			ans[i+1] = (a[i]*2) - ans[i];
		}
		for(long i: ans){
			System.out.print(i + " ");
		}
	}
}


Measured memory_bytes: 64648
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, k;
	string s;

	cin>>n>>k>>s;

	s[k-1]+=abs('a'-'A');

	cout<<s<<endl;
}


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N);
  for(ll i = 0; i < N; i++){
    ll t = 0;
    for(ll j = 0; j < 10; j++){
      ll s;
      cin>>s;
      t+=(s<<j);
    }
    v[i]=t;
  }
  vector<vector<ll>> w(N,vector<ll>(11));
  for(ll i = 0; i < N; i++){
    for(ll j = 0; j < 11; j++){
      cin>>w[i][j];
    }
  }
  ll ans = -INF;
  for(ll i = 1; i < (1LL<<10);i++){
    ll p = 0;
    for(ll j = 0; j < N; j++){
      p+=w[j][__builtin_popcount(i&v[j])];
    }
    chmax(ans,p);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let r = read_as_vec::<f64>()[0];

    println!("{}", 2.0*r*std::f64::consts::PI);
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean ans = false;
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			if(s.equals("Y")) {
				ans = true;
				break;
			}
		}
		if(ans) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
	}

}


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

int main() {
    char a;
    cin >> a;
    char alpha[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                    'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                    's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    char ans = 'A';
    for(char al : alpha) {
        if(al == a) {
            ans = 'a';
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>m>>n;
	vs in(n);
	rep(i,n)cin>>in[i];
	int out=0;
	int cow=0,coe=0;
	rep(i,n)rep(j,m)if(in[i][j]=='W')cow++;
	int ma=cow;
	rep(i,m){
		int co=0;
		rep(j,n)if(in[j][i]=='W')co++;
		cow-=co;
		coe+=n-co;
		if(ma>cow+coe){
			ma=cow+coe;
			out=i+1;
		}
	}
	cout<<out<<" "<<out+1<<endl;
}

Measured memory_bytes: 4516
import java.util.Scanner;

public class Main {

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

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();

        if (k % 2 == 1) {
            System.out.println(b - a);
        } else {
            System.out.println(a - b);
        }
    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};

int h,w,k;
int ans;

void r(int a,vector<string> v){
    if(a == w){
        int cnt = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(v[i][j] == '#'){
                    cnt++;
                }
            }
        }
        if(cnt == k) ans++;
        return;
    }
    r(a + 1, v);
    for (int i = 0; i < h; i++) {
        v[i][a] = '-';
    }
    r(a + 1, v);
}

void l(int a,vector<string> v){
    if(a == h){
        r(0, v);
        return;
    }
    l(a + 1, v);
    for (int i = 0; i < w; i++) {
        v[a][i] = '-';
    }
    l(a + 1, v);
}



int main(){
    cin >> h >> w >> k;
    vector<string> v(10);
    for (int i = 0; i < h; i++) {
        cin >> v[i];
    }
    l(0, v);
    cout << ans << endl;
    return 0;
}


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

int main() {
  int x;
  cin >> x;
  int y = 360;
  while (y % x != 0) {
    y += 360;
  }

  cout << y / x << endl;

  return 0;
}

/*
*/


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
#define REP(i,N) for(i=0;i<N;i++)
int N;
vector<int> v;
vector<int> prime;

vector<int> factoring(int n){
  vector<int> w(prime.size(),0);
  int i;
  REP(i,prime.size()){
    if(n%prime[i])continue;
    while(n%prime[i]==0){
      n/=prime[i];
      w[i]++;
    }
    if(n<=1) break;
  }
  return w;
}

void fact_N(){
  int i,j;
  for(i=2;i<=N;i++){
    vector<int> w = factoring(i);
    REP(j,prime.size()){
      v[j] += w[j];
    }
  }
}

void Eratosthenes(int n){
  //2～Nまでの素数
  prime.resize(N+1,0);
  int i,j;
  for(i=2;i<=N;i++){
    prime[i] = i;
  }
  for(i=2;i<=sqrt(N);i++){
    for(j=2*i; j<=N; j++){
      if(prime[j] != 0 && prime[j]%i == 0)prime[j] = 0;
    }
  }
//  REP(i,prime.size()) cout << prime[i] << " ";
//  cout << endl;
  i = 0;
  while(i<prime.size()){
    if(prime[i] == 0)prime.erase(prime.begin()+i);
    else i++;
  }
//  REP(i,prime.size()) cout << prime[i] << " ";
//  cout << endl;
}

int main(void){
  int i,n=0;
  int n_74 = 0;
  int n_24 = 0;
  int n_14 = 0;
  int n_4 = 0;
  int n_2 = 0;
  cin >> N;
  Eratosthenes(N);
  v.resize(prime.size(),0);
  fact_N();
  REP(i,prime.size()){
    if(v[i] >= 74) n_74++;
    if(v[i] >= 24) n_24++;
    if(v[i] >= 14) n_14++;
    if(v[i] >= 4) n_4++;
    if(v[i] >= 2) n_2++;
  }
  n += n_74;
  n += n_2>=1 ? n_24*(n_2-1):0;
  n += n_4>=1 ? n_14*(n_4-1):0;
  n += n_4>=1 && n_2>=2?n_4*(n_4-1)*(n_2-2)/2:0;
//  REP(i,prime.size()){
//    cout << prime[i] << " " << v[i] << endl;
//  }
  cout << n << endl;
  return 0;
}

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

int main(){
	
	int no1, no2;
	int tmp;

	while(1){
		cin >> no1 >> no2;
		if (no1 == 0 && no2 == 0) break;

		if (no1 > no2){
			tmp = no1;
			no1 = no2;
			no2 = tmp;
		}

		cout << no1 << " " << no2 << endl;
	}

	return 0;
}

Measured memory_bytes: 2992
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int H,W,i,j;
	scanf("%d%d",&H,&W);
	int a[H+1][W+1];
	for(i=1;i<=H;i++)for(j=1;j<=W;j++)scanf("%d",&a[i][j]);
	int count=0,ans[250000][4];
	for(i=1;i<=H;i++){
		if(i%2==1){
			for(j=1;j<W;j++){
				if(a[i][j]%2==1){
					ans[count][0] = ans[count][2] = i;
					ans[count][1] = j;
					ans[count][3] = j+1;
					count++;
					a[i][j+1]++;
				}
			}
			if(a[i][W]%2==1 && i<H){
				ans[count][0] = i;
				ans[count][1] = ans[count][3] = j;
				ans[count][2] = i+1;
				count++;
				a[i+1][j]++;
			}
		}else{
			for(j=W;j>1;j--){
				if(a[i][j]%2==1){
					ans[count][0] = ans[count][2] = i;
					ans[count][1] = j;
					ans[count][3] = j-1;
					count++;
					a[i][j-1]++;
				}
			}
			if(a[i][1]%2==1 && i<H){
				ans[count][0] = i;
				ans[count][1] = ans[count][3] = j;
				ans[count][2] = i+1;
				count++;
				a[i+1][j]++;
			}
		}
	}
	
	printf("%d\n",count);
	for(i=0;i<count;i++){
		printf("%d %d %d %d\n",ans[i][0],ans[i][1],ans[i][2],ans[i][3]);
	}
	return 0;
}

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

typedef long long ll ;
typedef long double ld ;

#define f first
#define s second
#define pll pair<ll,ll>
#define pub push_back
#define sortt(vv) sort(vv.begin(),vv.end())
#define mp make_pair

const ll maxn = 1e5 + 10 ;
const ll INF = 1e9 + 10 ;

ll n , m , mark[maxn] , dp[maxn] ;
vector<ll> g[maxn] , ord;

void dfs(ll v)
{
 mark[v] = 1;
 for(auto u : g[v]){
    if(!mark[u])dfs(u) ;
 }
 ord.pub(v) ;
}

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

 cin >> n >> m ;
 for(int i = 1 ; i <= m ; i ++){
   ll v , u ;
   cin >> v >> u ;
   g[v].pub(u) ;
 }

 for(int i = 1 ; i <= n ; i ++){
    if(!mark[i])dfs(i) ;
 }
 reverse(ord.begin() , ord.end()) ;

 dp[ord[n-1]] = 0;
 ll ans = 0 ;
 for(int i = n-2 ; i >= 0 ; i --){
    ll v = ord[i] ;
    for(auto u : g[v])dp[v] = max(dp[v] , dp[u]+1) ;
    ans = max(ans , dp[v]) ;
 }
 cout << ans ;
    return 0;
}


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

using namespace std;
#define int long long
#define N 666666
int arr[N];
signed main(){
	int ans=0;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%lld",&arr[i]);
	for(int i=2;i<=n;i++){
		if(arr[i]+arr[i-1]>m){
			ans+=((arr[i]+arr[i-1])-m);
			arr[i]-=min(((arr[i]+arr[i-1])-m),arr[i]);
			
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
using System;

namespace A___Buying_Sweets
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            x -= a;
            x %= b;
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 11220
def sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)]
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

pl=sieve_of_eratosthenes(100000)

p_list = [0 for i in range(100001)]

for p in pl:
    if 2*p-1<=100000:
        p_list[2*p-1]+=1
    p_list[p]+=1


ps_list = [0]
ps = 0

for i in range(1,100001):
    if p_list[i]>=2:
        ps+=1
    ps_list.append(ps)



Q = int(input())

for i in range(Q):
    l,r = list(map(int,input().split()))
    print(ps_list[r]-ps_list[l-1])

Measured memory_bytes: 8320
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
import heapq
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')


def main():
    # ダイクストラ
    def dijkstra(start, edge):
        costs=[inf]*N
        costs[start]=0
        hash={}
        queue=[(0, start)]  # 第一要素が優先的に評価されるので
        while queue:
            c, v=heapq.heappop(queue)
            if v in hash:
                continue
            hash[v]=1
            costs[v]=c
            for node, cost in edge[v]:
                if node in hash:
                    continue
                heapq.heappush(queue, (c + cost, node))

        return costs
    N = I()
    #Kからdijkstra
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = MI_()
        c+=1
        edge[a].append((b, c))
        edge[b].append((a,c))
    
    Q, K = MI()
    
    cost = dijkstra(K-1, edge)
    for _ in range(Q):
        x, y = MI_()
        print(cost[x]+cost[y])

    
    
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 94240
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	q := getNextInt(scanner)
	for i := 0; i < q; i++ {
		a := getNextInt64(scanner)
		b := getNextInt64(scanner)

		ans := int64(0)
		l := int64(0)
		r := a
		x := search(l, r, a, b)
		if x*x > a*b {
			x--
		}
		ans += x - 1
		y := (a * b / x)
		if x*y >= a*b {
			y--
		}
		if y > b {
			ans += y - b
		}

		l = int64(0)
		r = b
		x = search(l, r, a, b)
		if x*x > a*b {
			x--
		}
		ans += x - 1
		y = (a * b / x)
		if x*y >= a*b {
			y--
		}

		if y > a {
			ans += y - a
		}
		fmt.Fprintln(writer, ans)
	}
	writer.Flush()
}

func search(l, r, a, b int64) int64 {
	for l < r {
		x := (l + r) >> 1
		if x*x < a*b {
			l = x + 1
			continue
		}
		r = x
	}

	return l
}


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

int dp[100007];

int f(int x, vector<int> g[]){
    if(g[x].size()==0) return 0;

    int &ans = dp[x];
    if(ans!=-1) return ans;
    
    ans = 0;
    for(int i=0;i<g[x].size();i++){
        ans = max(ans,f(g[x][i], g));
    }
    ans++;
    
    return ans;
}


int main(){
    memset(dp,-1, sizeof(dp));
    int n, m;
    cin>>n>>m;
    
    vector<int>g[n+1];
    for(int i=0;i<m;i++){
        int x, y;
        cin>>x>>y;
        g[x].push_back(y);
    }
    vector<int> indegree(n+1,0);
    for(int i=1;i<=n;i++){
        for(int j=0;j<g[i].size();j++){
            indegree[g[i][j]]++;
        }
    }
    
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(indegree[i]==0){
            ans = max(ans, f(i,g));
        }
    }
    cout<<ans;
}

Measured memory_bytes: 11136
def isPalindrome(s: str):
    for i in range(len(s) // 2):
        if s[i] != s[len(s)-i-1]:
            return False
    return True


s = input()
n = len(s)
if isPalindrome(s) and isPalindrome(s[0:(n-1)//2]) and isPalindrome(s[(n+3)//2-1:n]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
def main():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())

    if A == B:
        print('YES')
        return

    d = abs(A - B)
    dv = V - W

    if d <= dv * T:
        print('YES')
    else:
        print('NO')
    return


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>

using namespace std;

vector<long long> lun;
void rec(string s, int depth) {
    lun.push_back(stoll(s));
    if(depth == 10) return;
    depth++;
    if(s.back() == '0') {
        rec(s + '0', depth);
        rec(s + '1', depth);
    } else if(s.back() == '1') {
        rec(s + '0', depth);
        rec(s + '1', depth);
        rec(s + '2', depth);
    } else if(s.back() == '2') {
        rec(s + '1', depth);
        rec(s + '2', depth);
        rec(s + '3', depth);
    } else if(s.back() == '3') {
        rec(s + '2', depth);
        rec(s + '3', depth);
        rec(s + '4', depth);
    } else if(s.back() == '4') {
        rec(s + '3', depth);
        rec(s + '4', depth);
        rec(s + '5', depth);
    } else if(s.back() == '5') {
        rec(s + '4', depth);
        rec(s + '5', depth);
        rec(s + '6', depth);
    } else if(s.back() == '6') {
        rec(s + '5', depth);
        rec(s + '6', depth);
        rec(s + '7', depth);
    } else if(s.back() == '7') {
        rec(s + '6', depth);
        rec(s + '7', depth);
        rec(s + '8', depth);
    } else if(s.back() == '8') {
        rec(s + '7', depth);
        rec(s + '8', depth);
        rec(s + '9', depth);
    } else if(s.back() == '9') {
        rec(s + '8', depth);
        rec(s + '9', depth);
    }
}

int main() {
    int K;
    cin >> K;
    for(int i = 1; i <= 9; i++) {
        rec(to_string(i), 1);
    }
    sort(lun.begin(), lun.end());
    cout << lun[K - 1] << endl;
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  double d;
  while(~scanf("%lf",&d)){
    if(48.0>=d) puts("light fly");
    else if(51.0>=d) puts("fly");
    else if(54.0>=d) puts("bantam");
    else if(57.0>=d) puts("feather");
    else if(60.0>=d) puts("light");
    else if(64.0>=d) puts("light welter");
    else if(69.0>=d) puts("welter");
    else if(75.0>=d) puts("light middle");
    else if(81.0>=d) puts("middle");
    else if(91.0>=d) puts("light heavy");
    else
      puts("heavy");
  }
}

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

#define n 1005

ll dp[n][n][2][2][2];
bool vis[n][n][2][2][2];
ll x[n],y[n],z[n];

int N,M;


ll rec(ll pos,ll barang,ll a,ll b,ll c){
	if(pos == N+1 && barang != M) {
		return -1e18;
	}
	if(pos == N + 1 && barang == M) return 0;
	if(vis[pos][barang][a][b][c]) return dp[pos][barang][a][b][c];
	
	vis[pos][barang][a][b][c] = 1;
	
	ll &ret = dp[pos][barang][a][b][c];
	ll ans = 0;

		if(a == 0){
			ans -= x[pos];
		} 
		else{
			ans += x[pos];
		}
	

		if(b == 0){
			ans -= y[pos];
		}
		else{
			ans += y[pos];
		}

		 if( c == 0) {
			ans -= z[pos];
		 }
		 else {
			ans += z[pos];
		 } 
	
	ret = max(ans+rec(pos+1,barang+1,a,b,c), rec(pos+1,barang,a,b,c));
	return ret;
}




int main(){
	cin >> N >> M;
	for(int i = 1;i <= N; i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	ll maks = -1e18;
	for(int i = 0; i < 2; i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) 
	{
		rec(1,0,i,j,k);
		
		maks = max(maks,dp[1][0][i][j][k]);
	}
	cout << maks << "\n";
}


Measured memory_bytes: 70528
k, s = list(map(int, input().split()))
z = min(k,s)
y = min(k,s-z)
xmax = min(y + z,k)
x = s-z-y
count = 0

while x <= xmax and z >= 0 :
    z0 = z
    y0 = y
    while z >= 0 and y<= k:
        z -= 1
        y += 1
        count+=1
    z = z0+1
    y = y0-1
    while y >= 0 and z<= k:
        y -= 1
        z += 1
        count+=1
    z = z0-1
    y = y0
    x +=1
print(count)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer h = Integer.parseInt(sc.next());
        Integer n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int sum = 0;
        for (int num : a) {
            sum += num;
        }

        String result = h <= sum ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 48440