akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S, T = MAP()

for i in range(N):
	print(S[i], end = "")
	print(T[i], end = "")
print()

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

class Program {
  static void Main() {
    var s = "";
    while ((s = Console.ReadLine()) != null) {
      var arr = s.Split().Select(int.Parse).ToArray();
      var a = arr[0];
      var b = arr[1];
      int r;
      while ((r = a % b) > 0) {
        a = b;
        b = r;
      }
      Console.WriteLine("{0} {1}", b, arr[0] / b * arr[1]);
    }
  }
}


Measured memory_bytes: 16348
#include<stdio.h>
#include<string.h>
const int N=1000000;
int main()
{
	int x,y,r,f,i;
	while(scanf("%d%d",&x,&y),x)
	{
		static int m[1000000];
		memset(m,255,4*N);
		f=i=0;
		do
		{
			r=x%y;
			if(r==0)f=printf("%d 0\n",i);
			if(m[r]>=0)f=printf("%d %d\n",m[r],i-m[r]);
			m[r]=i;
			x=r*10;
			++i;
		}while(!f);
	}
	return 0;
}

Measured memory_bytes: 4668
#include<iostream>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

multimap<int,int> ckout;
int ckin[100],seat[17];

void rm(multimap<int,int>::iterator p){
	rep(i,17)if(seat[i]==p->second)seat[i]=-1;
	ckout.erase(p);
}
int findseat(int k){
	int l=k%5==1?5:2,len=0,p,pos;
	for(p=0;p<17;p++){
		if(seat[p]==-1){
			if(!len)pos=p;
			if(++len==l)return pos;
		}else len=0;
	}
	return -1;
}
int main(){
	fill(ckin,ckin+100,-1); fill(seat,seat+17,-1);
	int n,k,t,q;
	multimap<int,int>::iterator p;
	for(k=t=0;k<100||ckout.empty();t++){
		while((p=ckout.find(t))!=ckout.end())rm(p);
		while(ckin[k]==-1&&t>=5*k){
			if((q=findseat(k))!=-1){
				int l=k%5==1?5:2;
				ckin[k]=t;
				rep(i,l)seat[q+i]=k;
				ckout.insert(make_pair(t+17*(k%2)+3*(k%3)+19,k));
				k++;
			}else break;
		}
	}
	while(cin>>n)cout<<ckin[n]-n*5<<endl;
	return 0;
}

Measured memory_bytes: 0
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    set <char> st;
    st.insert('R');
    st.insert('U');
    st.insert('D');
    set <char> ts;
    ts.insert('L');
    ts.insert('U');
    ts.insert('D');
    for (int i = 0; i < len(s); i++) {
        if (i % 2) {
            if  (!ts.count(s[i])) {
                cout << "No";
                return 0;
            }
        }
        else {
            if (!st.count(s[i]))
            {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> value(N);
  vector<int> cost(N);
  
  for(int i=0; i<N; i++) cin >> value[i];
  for(int i=0; i<N; i++) cin >> cost[i];
  
  vector<int> div(N);
  for(int i=0; i<N; i++) div[i] = value[i]-cost[i];
  
  sort(div.begin(), div.end());
  reverse(div.begin(), div.end());
  
  int ans=0;
  int j=0;
  while(div[j]>0){
    ans += div[j];
    j++;
  }
    
  
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
ans=n

#累積和を求める
wcum=[];wcount=0
ecum=[];ecount=0
for i in range(n):
  if s[i]=="W":
    wcount+=1
  else:
    ecount+=1
  ecum.append(ecount)
  wcum.append(wcount)
ans=ecum[n-1]-ecum[0]
for i in range(1,n):
  v=wcum[i-1]+(ecum[n-1]-ecum[i])
  if ans>v:
    ans=v
print(ans)
  

Measured memory_bytes: 20428
#include <stdio.h>

int main(){
	int H,W;
	int x,y;
	int i=0;
	while(i==0){
	scanf("%d%d",&H,&W);
		if(H==0 || W==0){break;}
	for(x=0;x<H;x++){
		for(y=0;y<W;y++){
			printf("#");
		}
		printf("\n");
	}
	printf("\n");
	
	}
	return 0;
}

Measured memory_bytes: 572
n = int(input())
AB = sorted([[int(i) for i in input().split()] for i in range(n)], reverse = True)
CD = sorted([[int(i) for i in input().split()] for i in range(n)], key = lambda x: x[1])

cnt = 0
for a, b in AB:
    for cd in CD:
        if a < cd[0] and b < cd[1]:
            cnt += 1
            CD.remove(cd)
            break
            
print(n - len(CD))

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
 if(a==5 && b==7 && c==5){
    cout << "YES" << endl;
  }
  else if(a==7 && b==5 && c==5){
    cout << "YES" << endl;
  }
  else if(a==5 && b==5 && c==7){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  int se=0,go=0;
  for(int i=0;i<3;i++){
    cin >> a[i];
    if(a[i]==7) se++;
    else if(a[i]==5) go++;
  }

  cout << (se==1&&go==2?"YES":"NO") << endl;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int N, A, B;
    cin>>N>>A>>B;
    string S;
    cin >> S;
    int d=0, f=0;
    rep(i,N){
        bool y=false;
        if(S[i]=='a'){
            if(d+1+f<=A+B){
              y=true;
                d++;
            }
        }
        if(S[i]=='b'){
            if(d+f+1<=A+B && f+1<=B){
              y=true;
                f++;
            }
        }
        if(y) Yes; else No;
    }
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

class TwoDCumulativeSum {
public:
	ll H, W;
	vector<vector<ll>> data;
	vector<vector<ll>> rui;

	TwoDCumulativeSum(vector<vector<ll>> &data) : H(data.size()), W(data[0].size()), data(data) {
		rui.assign(H+1, vector<ll>(W+1, 0));
		for (ll i = 0; i < H; ++i)
			for (ll j = 0; j < W; ++j)
				rui[i+1][j+1] = rui[i][j+1] + rui[i+1][j] - rui[i][j] + data[i][j];
	}

	// クエリ [x1, x2) × [y1, y2) の長方形区域の和を返す
	ll query(ll x1, ll x2, ll y1, ll y2) {
		return rui[x2][y2] - rui[x1][y2] - rui[x2][y1] + rui[x1][y1];
	}
};


signed main() {
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<vector<ll>> v(N,vector<ll>(N,0));
	rep(i,M){
		ll t1,t2;
		cin >> t1 >> t2;
		t1--;t2--;
		v[t1][t2]++;
	}

	TwoDCumulativeSum rui(v);
	vector<ll> ans(Q,0);
	rep(i,Q){
		int t1,t2;
		cin >> t1 >> t2;
		t1--;//t2--;
 
		ll c=rui.query(t1,t2,t1,t2);
		ans[i]=c;
	}
 
	rep(i,Q)p(ans[i]);


	return 0;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};
int alpha[26]={};

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        alpha[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if(alpha[i]>=2){
            cout << "no"<<endl;
            return 0;
        }
    }
    cout << "yes"<<endl;
    return 0;
}

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

#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cerr.tie(NULL);

#define dbg(x) cerr << #x << " = " << x << ",  ";
#define vw(v)                        \
    cerr << endl                     \
         << endl                     \
         << (#v) << " is: " << endl; \
    for (int B : (v))                \
    {                                \
        cerr << B << " ";            \
    }                                \
    cerr << endl
#define check(x) cerr << "here " << (x) << "?" << endl

#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
ll const INF = 2147483647, R_INF = 9223372036854775807, MOD = 1e9 + 7;

//const int N =
int self_max(int &x, int y)
{
    x = max(x, y);
}
int main()
{
    FAST_IO
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(3));
    rep(i, 0, n)
    {
        rep(j, 0, 3)
        {
            cin >> v[i][j];
        }
    }
    vector<vector<int>> DP(n, vector<int>(3, 0));
    DP[0] = v[0];
    rep(i, 1, n)
        rep(j, 0, 3)
            rep(k, 0, 3)
                if (k != j)
                    self_max(DP[i][j], DP[i - 1][k] + v[i][j]);
    
    cout << max({DP[n - 1][0], DP[n - 1][1], DP[n - 1][2]});
}

Measured memory_bytes: 11264
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <utility>
typedef long long int64;
static const int MAXN = 5004;
static const int LOGN = 15;
static const int MAXM = 202;
 
int n, m, b[MAXM][MAXN];
int64 a[MAXN];
 
template <typename T> struct rmq {
 
std::pair<T, int> f[LOGN][MAXN];
 
void build(int n, T *arr) {
    for (int i = 0; i < n; ++i) f[0][i] = std::make_pair(arr[i], i);
    for (int j = 1; j < LOGN; ++j)
        for (int i = 0; i <= n - (1 << j); ++i)
            f[j][i] = std::max(f[j - 1][i], f[j - 1][i + (1 << (j - 1))]);
}
 
inline std::pair<T, int> query(int l, int r) {
    if (l == r) return f[0][l];
    int sz = sizeof(int) * 8 - __builtin_clz(r - l) - 1;
    return std::max(f[sz][l], f[sz][r - (1 << sz) + 1]);
}
 
};
rmq<int> quq;
 
int64 sum[MAXN][MAXN] = {{ 0 }};
 
void recursive_max(int l, int r)
{
    if (l > r) return;
    std::pair<int, int> p = quq.query(l, r);
    int m = p.second;
    // Add p.first to [l, m] * [m, r]
    sum[l][m] += p.first;
    sum[l][r + 1] -= p.first;
    sum[m + 1][m] -= p.first;
    sum[m + 1][r + 1] += p.first;
    recursive_max(l, m - 1);
    recursive_max(m + 1, r);
}
 
int main()
{
    scanf("%d%d", &n, &m);
    a[0] = 0;
    for (int i = 1; i < n; ++i) scanf("%lld", &a[i]), a[i] += a[i - 1];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) scanf("%d", &b[j][i]);
 
    for (int i = 0; i < m; ++i) {
        quq.build(n, b[i]);
        recursive_max(0, n - 1);
    }
 
    // Postprocess 2-D prefix sums
    for (int i = 0; i < n; ++i)
        for (int j = 1; j < n; ++j) sum[i][j] += sum[i][j - 1];
    for (int j = 0; j < n; ++j)
        for (int i = 1; i < n; ++i) sum[i][j] += sum[i - 1][j];
 
    int64 ans = -1LL << 62;
    for (int i = 0; i < n; ++i)
        for (int j = i; j < n; ++j)
            ans = std::max(ans, sum[i][j] - (a[j] - a[i]));
    printf("%lld\n", ans);
 
    return 0;
}


Measured memory_bytes: 200320
#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;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	forn(i, sz(s)) {
		s[i] = ((s[i]-'A')+n)%26 +'A';
	}
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 3592
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


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

A = [list(map(int,input().split())) for i in range(N)] #N*M配列の取得
B = [list(map(int,input().split())) for i in range(M)] #M*L配列の取得
ANS = [[0]*L for i in range(N)] #N*L


for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y] += B[z][y]*A[x][z]

for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()




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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int n, ans = 0, a;

	cin >> n;
	vector<int> seq(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a >= n + 1)
		{
			ans++;
			continue;
		}
		if (seq[a] < a)
			seq[a]++;
		else
		{
			ans++;
			continue;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (seq[i] != i)
			ans += seq[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3816
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

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

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

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

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

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

fn cum(v: &Vec<i64>) -> Vec<i64> {
  let mut ret = vec![0; v.len() + 1];
  for (i, &x) in v.iter().enumerate() {
    ret[i+1] = ret[i] + x;
  }
  ret
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    cap: usize,
    wv: [(usize, i64); n],
  }
  let mut item = vec![vec![]; 4];
  let w0 = wv[0].0;
  for &(w, v) in &wv {
    item[w - w0].push(v);
  }
  for vec in item.iter_mut() {
    vec.sort();
    vec.reverse();
  }
  let sum: Vec<_> = item.iter().map(|v| cum(v)).collect();
  let mut ans = 0;
  for i0 in 0 .. sum[0].len() {
    for i1 in 0 .. sum[1].len() {
      for i2 in 0 .. sum[2].len() {
        for i3 in 0 .. sum[3].len() {
          if w0 * i0 + (w0 + 1) * i1 + (w0 + 2) * i2 + (w0 + 3) * i3 <= cap {
            ans = cmp::max(ans, sum[0][i0] + sum[1][i1] + sum[2][i2] + sum[3][i3]);
          }
        }
      }
    }
  }

  puts!("{}\n", ans);
}


Measured memory_bytes: 4352
if __name__ == '__main__':
    n = input()
    arares = input().split()
    arare_kinds = set(arares)
    n_arare_kinds = len(arare_kinds)

    if n_arare_kinds == 3:
        print("Three")
    elif n_arare_kinds == 4:
        print("Four")
    else:
        exit(0)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1005;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
char lol[4] = {'R', 'L', 'U', 'D'};
int x[N], y[N];
vector<pii> v;
void solve(){
	int n, k;
	cin >> n >> k;
	int ans = (n / k) * (n / k) * (n / k);
	if(k % 2 == 0){
		n += k / 2;
		ans += (n / k) * (n / k) * (n / k);
	}
	cout << ans;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

using namespace std;

int main() {
    int k;
    cin >> k;
    vector<int> a = vector<int>(k, 0);
    for (int i = 0; i < k; ++i)
    {
        cin >> a[i];
    }
    
    long long min = 2;
    long long max = 2;
    
    for (int i = k - 1; i >= 0; --i)
    {
        if (a[i] > max)
        {
            cout << -1 << endl;
            return 0;
        }
        max = max + (long long)(a[i] - (long long)1 - (max % (long long)a[i]));
        if ((min % (long long)a[i]) != 0)
        {
            min = min + (long long)(a[i] - (min % (long long)a[i]));
        }
    }
    
    if (min > max)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << min << " " << max << endl;
    }
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

bool check(int n) {
    vector<P> v;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        v.emplace_back(P(a, b));
    }
    sort(all(v), [](const P& p, const P& q){return (p.second == q.second) ? (p.first < p.first) : (p.second < q.second);});
    int sm = 0;
    for (auto p : v) {
        sm += p.first;
        if (sm > p.second) {
            return false;
        }
    }
    return true;
}

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

    int n;
    while (cin >> n, n) {
        cout << (check(n) ? "Yes" : "No") << endl;
    }

}

Measured memory_bytes: 3128
from heapq import *
n, m = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x:x * (-1), a))
heapify(a)

for i in range(m):
    temp_num = heappop(a) * (-1)
    heappush(a,(-1) * (temp_num //2))

print(-sum(a))

Measured memory_bytes: 14180
import sys
n, m = map(int, input().split())
num = []
s = []
c = []
ans = 0
keta = 1
list = [False,False,False,False,False]
for i in range(m):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)



for i in range(n):
    num.append(0)
if(n>1):
    num[0] = 1

for i in range(m):
    if(list[s[i]-1] and not num[s[i]-1] == c[i]):
        print(-1)
        sys.exit()
    num[s[i]-1] = c[i]
    if(n > 1 and num[0] == 0):
        print(-1)
        sys.exit()
    list[s[i]-1] = True


for i in num[::-1]:
    ans = ans + i*keta
    keta = keta * 10

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

vector<int> g[MAX_N], gr[MAX_N];
int dp[MAX_N], id[MAX_N];
bool visited[MAX_N];

void dfs(int cur, int &k){
    visited[cur] = true;
    for(auto to : g[cur]){
        if(visited[to])continue;
        dfs(to, k);
    }
    id[k] = cur;
    ++k;
}


int main() {
    int n, m;
    cin >> n >> m;
    REP(i,m){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        gr[y].push_back(x);
    }
    int k=0;
    REP(i,n){
        if(visited[i])continue;
        dfs(i,k);
    }
    REP(i,n){
        for(auto j : gr[id[i]]){
            dp[j] = max(dp[j], dp[id[i]]+1);
        }
    }
    int ans = 0;
    REP(i,n) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

ll gcd(ll a,ll b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}

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

    vector<int> a(M),b(M),c(M,0);
    int box=0;
    for (int i = 0; i < M; ++i) {
        cin>>a[i]>>b[i];
        for (int j = 0; j < b[i]; ++j) {
            cin>>box; --box;
            c[i]+=(1<<box);
        }
    }

    vector<vector<ll>> dp(M+1,vector<ll>(1<<N,1e18)); //dp[i][j]
    dp[0][0]=0;
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < (1 << N); ++j) {
            //配る
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]); //使わない
            int tmp=j|c[i];
            dp[i+1][tmp]=min(dp[i+1][tmp],dp[i][j]+a[i]);
        }
    }
    if(dp[M][(1<<N)-1]==1e18){
        cout<<-1<<endl;
        return 0;
    }
    cout<<dp[M][(1<<N)-1]<<endl;

    return 0;
}

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

int main() {
  int a;
  string b;
  cin >> a >> b;
  int l=1;
  for(int i=0;i<a-1;i++){
  if(b.at(i)!=b.at(i+1)){
  l++;
  }
  } 
  cout << l << endl;
}

Measured memory_bytes: 512
import sys
from collections import defaultdict
from math import ceil

def main():
    n, *p = map(int, sys.stdin.read().split())
    p = [None] + p
    res = defaultdict(int)
    cnt = 0
    for i in range(1, n + 1):
        if p[i] == i:
            cnt += 1
        else:
            if cnt >= 1:
                res[cnt] += 1
                cnt = 0
    res[cnt] += 1

    ans = 0
    for k, v in res.items():
        ans += v * ceil(k / 2)
    print(ans)

if __name__ == '__main__':
    main()

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

bool solve(long long N, const vector<long long> &a) {
    long long S = 0;
    for (int i = 0; i < N; ++i) S += a[i];
    if (S % (N * (N+1)/2) != 0) return false;
    long long num = S / (N * (N+1)/2);
    for (int i = 0; i < N; ++i) {
        long long b = a[(i+1)%N] - a[i] - num;
        if (b % N != 0 || b > 0) return false;
    }
    return true;
}

int main() {
    long long N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    if (solve(N, a)) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
bool b[1111][1111][1111];
int main() {
	int n; cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int a[3]; cin >> a[0] >> a[1] >> a[2];
		sort(a, a + 3);
		if (b[a[0]][a[1]][a[2]])sum++;
		b[a[0]][a[1]][a[2]] = true;
	}
	cout << sum << endl;
}

Measured memory_bytes: 7064
a,b,c,d = map(int, input().split())

num1 = c
num2 = d
while (num2>0):
  num1,num2 = max(num1,num2),min(num1,num2)
  r = num1%num2
  num1 = num2
  num2 = r
lcm = int(c*d/num1)

n1 = (a-1)//c+(a-1)//d-(a-1)//lcm
n2 = b//c+b//d-b//lcm
n = n2-n1
ans = b-a+1-n
print(int(ans))

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

struct Index {
  int x, y, z;
  Index(int a, int b, int c) : x(a), y(b), z(c) {}
  bool operator<(const auto &right) const {
    if (x != right.x) return x < right.x;
    if (y != right.y) return y < right.y;
    return z < right.z;
  }
};

struct Data {
  Index index;
  LL v = 0;
  Data(Index idx, LL w) : index(idx), v(w) {}
  bool operator<(const auto &right) const {
    return v < right.v;
  }
};

int main() {
  int X, Y, Z, K; std::cin >> X >> Y >> Z >> K;
  std::vector<LL> A(X), B(Y), C(Z);
  for (int i = 0; i < X; ++i) std::cin >> A[i];
  for (int i = 0; i < Y; ++i) std::cin >> B[i];
  for (int i = 0; i < Z; ++i) std::cin >> C[i];

  std::sort(A.rbegin(), A.rend());
  std::sort(B.rbegin(), B.rend());
  std::sort(C.rbegin(), C.rend());

  std::priority_queue<Data> que;
  std::set<Index> done;

  Index idx(0, 0, 0);
  que.push(Data(idx, A[0] + B[0] + C[0]));
  done.insert(idx);
  for (int i = 0; i < K; ++i) {
    Data d = que.top();
    que.pop();

    int x = d.index.x;
    int y = d.index.y;
    int z = d.index.z;
    std::cout << d.v << std::endl;

    Index idx_x(x+1, y, z), idx_y(x, y+1, z), idx_z(x, y, z+1);
    if (!done.count(idx_x) && x + 1 < X) {
      que.push(Data(idx_x, A[x+1] + B[y] + C[z]));
      done.insert(idx_x);
    }
    if (!done.count(idx_y) && y + 1 < Y) {
      que.push(Data(idx_y, A[x] + B[y+1] + C[z]));
      done.insert(idx_y);
    }
    if (!done.count(idx_z) && z + 1 < Z) {
      que.push(Data(idx_z, A[x] + B[y] + C[z+1]));
      done.insert(idx_z);
    }
  }
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int a, b;
  cin >> a >> b;

  if (a > b)  swap(a, b);
  for (int i = 0; i < b; ++i)
    cout << a;
  cout << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cerr << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi  pair    <int,int>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define OO  (ll)1e18
#define EPS 1e-9
using namespace std;
using namespace __gnu_pbds;
void ONLINE__JUDGE();

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
pii swapii( pii pr ){ return { pr.S , pr.F }; }
ll binEXP( ll x , ll pw , ll MOD = LLONG_MAX );
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 1e5 + 7;

ll x , k; vii vec; ll dp[MAX];
ll go( ll i ){

    if ( i+1 == x ){
        return 0;
    }

    ll& ret = dp[i];
    if ( ~ret ) return ret;

    ll ans = OO;
    for ( int j = 1; j <= k; ++j ){
        if ( i+j < x ){
            ans = min( ans , go(i+j) + abs(vec[i] - vec[i+j]) );
        }
    }
    return ret = ans;
}
int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x >> k; vec.resize(x); mem( dp , -1 );
    for ( ll& i : vec ) cin >> i;
    cout << go(0);
    return 0;
}

void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}

ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


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


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}





int main()
{
speed
ll n;
cin>>n;
ll f[100009];
mem(f,0);
ll z;
ll s=0;
rep(i,0,n)
{
	cin>>z;
	s+=z;
	f[z]++;
}
ll q;
cin>>q;
rep(i,0,q)
{
	ll a,b;
	cin>>a>>b;
	s+=f[a]*(b-a);
	f[b]+=f[a];
	f[a]=0;
	cout<<s<<endl;
}
}



Measured memory_bytes: 8956
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N = 1e6 + 10;
using namespace std;
int A;
int n;
int main() {
  ios::sync_with_stdio(false);
  cin>>A>>n;
  while(n--){
      int t;
      cin>>t;
      A-=t;
      if(A<=0){
          cout<<"Yes"<<endl;
          return 0;
      }
  }
  cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
number_of_prefecture, number_of_cities = [int(x) for x in input().split(' ')]

city_list = []

import bisect
import collections
city_dict = collections.defaultdict(list)

for i in range (number_of_cities):
    prefecture_id, year_of_establishment = [int(x) for x in input().split(' ')]
    city_dict[prefecture_id].append(year_of_establishment)
    city_list.append([prefecture_id, year_of_establishment])

for prefecture in city_dict:
    city_dict[prefecture].sort()

for j in city_list:
    prefecture = j[0]
    year = j[1]
    city_number = bisect.bisect(city_dict[prefecture],year)
    front_string = '0'*(6 - len(str(prefecture))) + str(prefecture)
    back_string = '0'*(6 - len(str(city_number))) + str(city_number)
    print(front_string+back_string)


Measured memory_bytes: 38456
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int sq = (int)Math.sqrt((double)N);
		if((A+B>N+1) || (A<sq && B<sq)) System.out.println(-1);
		else if(A+B==N+1){
			for(int i=B;i<=N;++i) System.out.print(i+" ");
			for(int i=B-1;i>=1;--i) System.out.print(i+" ");
			System.out.println();
		}else{
			int tempA = (N/B)+(N%B!=0? 1:0);
			int hidari = 0;
			while(tempA+hidari!=A){
				hidari++;
				if(hidari>N){
					System.out.println(-1);
					return;
				}
				if((N-hidari)%B==0) tempA--;
			}
			
			int[] a = new int[N];
			int count = 0;
			for(int i=1;i<=hidari;++i){
				a[count] = i;
				count++;
			}
			int nowN = N-hidari;
			for(int i=1;i<=nowN/B;i++){
				for(int j=i*B;j>(i-1)*B;j--){
					a[count] = j+hidari;
					count++;
				}
			}
			for(int j=nowN;j>B*(nowN/B);--j){
				a[count] = j+hidari;
				count++;
			}
			for(int i=0;i<N;++i) System.out.print(a[i]+" ");
			System.out.println();
		}
		return;
	}
}

Measured memory_bytes: 53132
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll dp[100005];
bool visited[100005];
vector<ll> adj[100005];

void visit(ll vertex)
{
    visited[vertex] = 1;
    dp[vertex]=0;

    for(ll child: adj[vertex])
    {
        if(!visited[child])
        {
            visit(child);
        }
        dp[vertex] = max(dp[vertex] , dp[child]+1);
    }
}


int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    
    freopen("output.txt", "w", stdout);
    #endif

    ll n,m,i,j;
    cin>>n>>m;

    for(i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        adj[x].pb(y);
    }

    for(i=1; i<=n; i++)
    {
        if(!visited[i])
        {
            visit(i);
        }
    }
    ll ans=0;
    for(i=1;i<=n;i++)
    {
        ans = max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12452
/* You can't hack me! */
#pragma warning(disable : 4996)
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef set<ll> sll;
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(auto i=a; i!=(b); i+=(b)>(a)?1:-1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define sc scanf
#define pr printf
#define in(x) sc("%lld", &(x))
#define id(x) sc("%Lf", &(x))
#define os(x) cout<<x<<" "
#define on(x) cout<<x<<"\n"
#define nl cout<<"\n"
const ll P=998244353;
const ll N=200010;

int main()
{
    /*ios::sync_with_stdio(false);
    cin.tie(0);*/
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t=1;
    //cin>>(t);
    while(t--)
    {
        ll a, b, c, k, s=0;
        cin>>a>>b>>c>>k;
        if(a>=k)
        {
            s=k;
            on(s);
            continue;
        }
        k-=a;
        s=a;
        if(b>=k)
        {
            on(s);
            continue;
        }
        k-=b;
        s-=k;
        on(s);
    }
    cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
vector<vl> Adj;
vector<ll> parent;
vector<ll> level;
vector<bool> used;

void bfs(ll s)
{
    queue<ll> q;
    q.push(1);
    used[1] = true;
    level[1] = 0;parent[1] = -1;
    while(!q.empty())
    {
        ll u = q.front();
        q.pop();
        for(ll v : Adj[u])
        {
            if(!used[v])
            {
              level[v] = level[u] + 1;
              used[v] = true;
              parent[v] = u;
              q.push(v);
            }
        }
    }
}
void Compute(ll n,ll m)
{
    KAKA
    Adj.resize(n + 1);
    parent.resize(n + 1,-1);
    level.resize(n + 1,-1);
    used.resize(n + 1,false);
    pragi(0,m)
    {
        ll u,v;
        cin>>u>>v;
        Adj[u].eb(v);
        Adj[v].eb(u);
    }
    bfs(1);
    bool flag = true;
    pragi(2,n + 1)
    {
     if(!used[i])
     {
         flag = false;
         break;
     }
    }
    if(!flag) cout<<"No"<<"\n";
    else
    {
        cout<<"Yes"<<"\n";
        pragi(2,n + 1)
        {
            cout<<parent[i]<<"\n";
        }
        cout<<"\n";
    }
    

}
int main()
{
    KAKA
    ll n,m;
    cin>>n>>m;
    Compute(n,m);
}

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

int main(){
  ll N;
  cin>>N;
  ll sqrt=pow(N,0.5);
  ll FS=floor(sqrt);
  ll tmp;
  ll ans=1e18;
  for (ll i=FS; i>=1;--i){
    if (N%i!=0) continue;
    tmp=N/i;
    ans=tmp+i-2;
    break;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 200009;

int n,k;
int cnt[maxn],f[maxn];
ll ans;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,m,q,sum[510][510] = {};
	cin >> n >> m >> q;
	for(int i = 0;i < m;i++){
		int l,r;
		cin >> l >> r;
		sum[l][r]++;
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}
	for(int i = 0;i < q;i++){
		int a,b;
		cin >> a >> b;
		cout << sum[b][b] - sum[a - 1][b] - sum[b][a - 1] + sum[a - 1][a - 1] << endl;
	}
	return 0;
}

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

const int N = 100005;
const int M = (1<<18);
ll p;
int n;
int t [N];
int tree [M+M];

void update (int u) {
	for (u+=N+M; u>=1; u/=2)
		tree[u]++;
	}

int query (int a, int b)
	{
	a += N+M;
	b += N+M;
	int res = tree[a] + tree[b];
	while (a/2 != b/2)
		{
		if (a%2==0) res += tree[a+1];
		if (b%2==1) res += tree[b-1];
		a /= 2;
		b /= 2;
		}
	return res;
	}

bool check (int m)
	{
	int i;
	for (i=0; i<M+M; i++)
		tree[i] = 0;
	update(0);
	ll out = 0;
	int pre = 0;
	for (i=1; i<=n; i++)
		{
		pre += ((t[i]<=m) ? -1 : 1);
		out += query(pre+1, n+1);
		update(pre);
		}
	if (p%2==0) return (2*out >= p+2);
	if (p%2==1) return (2*out >= p+1);
	}

int main ()
	{
	int i, a, b;
	scanf ("%d", &n);
	p = (1ll*(n+1)*n)/2;
	for (i=1; i<=n; i++)
		scanf ("%d", &t[i]);
	a = -1;
	b = 1000000001;
	while (b-a>1)
		(check((a+b)/2) ? b : a) = (a+b)/2;
	printf ("%d\n", b);
	return 0;
	}


Measured memory_bytes: 2688
N,M = map(int,input().split())
errors = 0
ans = 0
error_arr = [0]*(N+1)
s_arr = ['WA']*(N+1)
for i in range(M):
  idx,s = input().split()
  idx = int(idx)
  if s_arr[idx]!='AC':
    if s=='WA':
      error_arr[idx] += 1
    else:
      s_arr[idx]='AC'
      ans += 1
      errors += error_arr[idx]
      s_arr[idx] = 'AC'

print(ans,errors)
    
  
  

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

#define ll long long
#define all(v) v.begin(), v.end()

const ll N = (ll)(2000007);
const ll MOD = (ll)(1e9 + 7);

ll f[N];
ll powerf(ll a, ll b, ll c) {
	ll res = 1;
	while(b > 0) {
		if(b&1) {
			res = (res * a);
			res = res % c;
		}
		b/=2;
		a = (a * a) % c;
	}
	return res;
}

int main() {
	
	ll ans = 0;
	f[0] = 1;
	for(int i=1; i<N; i++) {
		f[i] = f[i-1] * i;
		f[i] = f[i] % MOD;
	}

	ll x, y;
	cin >> x >> y;
	for(ll u = 0; u<=x; u++) {
		ll v = x - u;
		if(v % 2 != 0) continue;
		v/=2;
		if((2*u) + v == y) {
			ll val = (f[u] * f[v]) % MOD;
			ans = ans + (f[u+v] * powerf(val, MOD-2, MOD));
			ans = ans % MOD;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 16000
//

fun main() {
    abc167d()
}

fun abc167d() {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val town = readLine()!!.split(" ").map { it.toInt() - 1 }
    var i = 0
    val visited = mutableSetOf<Int>(0)
    var isLooped = false
    var checkLooped = false
    var count = 0
    var loopReturnedNum = 0
    while (!checkLooped && count < n) {
        i = town[i]
        count++
        if (visited.contains(i)) {
            checkLooped = true
            loopReturnedNum = i
        } else {
            visited.add(i)
        }
    }
    val loopedCount = count
    var cycleCount = 0
    if (checkLooped) {
        count = 0
        while (!isLooped) {
            i = town[i]
            count ++
            if (i == loopReturnedNum) {
                cycleCount = count
                isLooped = true
            }
        }
    }
    val startCount = loopedCount - cycleCount
    val t = ((k - startCount) % cycleCount.toLong())
    i = 0
    if (startCount > k) {
        repeat(k.toInt()) {
            i = town[i]
        }
        println(i + 1)
    } else {
        repeat(t.toInt() + startCount) {
            i = town[i]
        }
        println(i + 1)
    }
}


Measured memory_bytes: 76452