akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>

#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define fs first
#define sc second
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a)
{
  return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b)
{
  return take_mod(a + b);
}

inline ll sub(ll a, ll b)
{
  return take_mod(a - b);
}

inline ll mul(ll a, ll b)
{
  return take_mod(a * b);
}

inline ll pow(ll x, ll n)
{
  ll res = 1LL;
  while (n > 0)
  {
    if (n & 1)
      res = mul(res, x);
    x = mul(x, x);
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll x)
{
  return pow(x, mod - 2);
}

void make_fact(ll n)
{
  fact[0] = 1;
  ll res = 1;
  for (int i = 1; i <= n; i++)
  {
    fact[i] = res;
    res = mul(res, i + 1);
  }
}

void make_invfact(ll n)
{
  invfact[0] = 1;
  invfact[n] = mod_inv(fact[n]);
  for (int i = n - 1; i >= 1; i--)
  {
    invfact[i] = mul(invfact[i + 1], i + 1);
  }
}

ll perm(ll n, ll k)
{
  return mul(fact[n], invfact[n - k]);
}

ll comb(ll n, ll k)
{
  return mul(mul(fact[n], invfact[n - k]), invfact[k]);
}

int main(){
  ll N, M;

  cin >> N >> M;

  map<ll, ll> fact;
  for (ll i = 2; i <= M; i++){
    ll tmp = 0;
    while(M % i == 0){
      tmp++;
      M /= i;
    }
    if(tmp >= 1){
      fact[i] = tmp;
    }
  }

  make_fact(200020);
  make_invfact(200020);

  ll ans = 1;
  for (auto &x : fact)
  {
    ll xx = x.second;
    ans = mul(ans, comb(xx + N - 1, N - 1));
  } // x

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main(void){
	map<string, int> word;
	string instr, mfstr, maxl = "";
	int noo = 0;
	
	while(cin >> instr){
		if(word.find(instr) != word.end()){
			word[instr]++;
		}
		else{
			word.insert(pair<string, int>(instr, 1));
		}

		if(instr.size() > maxl.size())	maxl = instr;
	}

	map<string, int>::iterator p;
	for(p = word.begin(); p != word.end(); p++){
		if(noo < p->second){
			noo = p->second;
			mfstr = p->first;
		}
	}

	cout << mfstr << " " << maxl << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for(int i = a; i <= n; i++)
#define sum(start, end) accumulate(start, end, 0)

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<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

typedef long long ll;


string solve() {
    string str = "";
//=============================================================================


    int a, b, c;
    cin >> a >> b >> c;
    ll x;
    cin >> x;

    int cont = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if ((500*i + 100*j + 50*k) == x) cont++;
                if ((500*i + 100*j + 50*k) > x) break;
            }
        }
    }

    cout << cont << endl;


//=============================================================================
    return str;
}

int main() {	
    std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
    cout << solve() << endl;
}

Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    name = 'CODEFESTIVAL2016'
    s = input()
    ans = 0
    for i in range(16):
        if s[i] != name[i]:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38508
// 5/4
// 2-3-2. 最長共通部分裂問題(LCS)の類題

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

int dp[1010][1010];

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

    string s, t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();

    dp[0][0] = 0;

    rep(i, n + 1) {
        dp[i][0] = i;
    }
    rep(j, m + 1) {
        dp[0][j] = j;
    }

    rep(i, n) {
        rep(j, m) {
            // if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
            // else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);

            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j];
            else dp[i + 1][j + 1] = min(min(dp[i + 1][j] + 1, dp[i][j + 1] + 1), dp[i][j] + 1);

            // cout << "dp[i+1][j+1] = " << dp[i + 1][j + 1] << endl;
            // printf("dp[%d][%d] = %d\n", i + 1, j + 1, dp[i + 1][j + 1]);
        }
    }

    cout << dp[n][m] << endl;
    // cout << max(n - dp[n][m], m - dp[n][m]) << endl;
}


Measured memory_bytes: 7092
import math

n, m=map(int, input().split())
t = {}
# a = int(math.sqrt(m))

s=0

for i in range(2, m+2):
#     print(i)
    cnt = 0
    while m%i==0:
        m=m//i
        cnt += 1

    if cnt>0:
        t[i]=cnt

    if m==1:
        break

# if m!=1:
#     t[m]=1

def combi(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) 

out=1
for tk in t.keys():
    out *= combi(t[tk]+n-1, n-1)
#     out = out%(1000000007)
print(out%(1000000007))

Measured memory_bytes: 114396
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	ll res = pow(3, N);
	ll mul = 1;
	REP(i, N){
		int a;
		cin >> a;
		if(a%2==0)
			mul *= 2;
	}
	cout << res - mul << endl;
}


Measured memory_bytes: 512
a = int(input())
f = 10 ** 9
for i in range(1, a):
    c = str(a-i)
    d = str(i)
    e = 0
    for j in range(len(c)):
        e += int(c[j])
    for j in range(len(d)):
        e += int(d[j])
    f = min(f, e)
print(f)


Measured memory_bytes: 3060
k = int(input())
from collections import deque
queue = deque(range(1,10)) # 1から10のベースとなるルンルン数
count = 0
 
while count < k: # K番目になるまで
  count += 1
  tmp = queue.popleft()
  tail = tmp % 10 # 末尾の数
  if tail!=0:
    queue.append(tmp*10+tail-1)  # 0以外の時、末尾の1つ前の数を末尾に追加
  queue.append(tmp*10+tail) # 末尾と同じ数を末尾に追加
  if tail!=9:
    queue.append(tmp*10+tail+1) # 9以外の時、末尾の次の数を末尾に追加
  
print(tmp) # K番目のルンルン数

Measured memory_bytes: 11956
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;


int main()
{
    ll N, K;
    //桁数を回答する

    cin >> N >> K;

    int res = 1;
    for(ll i = K; i <= N; i *= K)
    {
        ++res;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main() {
	int n;

	std::cin >> n;

	int i = 1;

	for (i=1;i<=n;i++) {
		int x = i;
		if(x%3==0){
			std::cout << " " << i;
		}
		else if (x % 10 == 3) {
			std::cout << " " << i;
		}
		else {
			for (;;) {
				x /= 10;
				if (x % 10 == 3) {
					std::cout << " " << i;
					break;
				}
				if (x == 0) break;
			}
		}
	}
	std::cout << std::endl;

	return 0;
}


Measured memory_bytes: 3092
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
S=""

for i in range(n):
  if i-k>=0:
    if t[i]==t[i-k]:
      if t[i]=="r":
        if S[i-k]=="p":
          S+="r"
        elif S[i-k]=="r":
          S+="p"
          ans+=p
      elif t[i]=="s":
        if S[i-k]=="r":
          S+="s"
        elif S[i-k]=="s":
          S+="r"
          ans+=r
      elif t[i]=="p":
        if S[i-k]=="s":
          S+="p"
        elif S[i-k]=="p":
          S+="s"
          ans+=s
      continue
  if t[i]=="r":
    ans+=p
    S+="p"
  elif t[i]=="s":
    ans+=r
    S+="r"
  elif t[i]=="p":
    ans+=s
    S+="s"
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin>>q;
    vector<int> sum(100010,0);
    FOR(i,2,len(sum)){
        if(is_prime(i) && is_prime((i+1)/2)){
            sum[i]=sum[i-1]+1;
        }else{
            sum[i]=sum[i-1];
        }
    }
    rep(i,q){
        int l,r;
        cin>>l>>r;
        //cout<<sieve(r)<<' '<<sieve(l-1)<<'\n';
        cout<<sum[r]-sum[l-1]<<'\n';
    }
}

Measured memory_bytes: 1024
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<int,int>
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 500005;

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     ll x,y,a,b,c;
     cin >> x >> y >> a >> b >> c;
     ll v1[a],v2[b],v3[c];
     for(ll i=0;i<a;i++)    cin >> v1[i];
     for(ll i=0;i<b;i++)    cin >> v2[i];
     for(ll i=0;i<c;i++)    cin >> v3[i];
     sort(v1,v1+a);
     sort(v2,v2+b);
     sort(v3,v3+c);
     vector<ll> v;
     for(ll i=a-1;i>=a-x;i--)   v.pb(v1[i]);
     for(ll i=b-1;i>=b-y;i--)   v.pb(v2[i]);
     for(ll i=0;i<c;i++)        v.pb(v3[i]);
     sort(all(v));
     ll ans = 0;
     ll n = v.size();
     for(ll i=n-1;i>=n-x-y;i--)   ans += v[i];
     cout<<ans;   
}

int main()
{
     FAST;
     int t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 8560
x=[]
y=[]
z=[]
while True:
    try:
        n=input()
    except EOFError:
        break
    
    
    #print(ord('T'))
    #print(ord('t'))
    
    for i in n.lower():
        x.append(ord(i))
    #print(x)
    
    
    for k in range(27):
        y.append(97+k)
    #print(y)
    
    
for l in y:
    if x.count(l)==0:
        z.append(0)
    elif x.count(l)!=0:
        z.append(x.count(l))
#print(z)
    
    
for m in range(26):
    print(chr(m+97),end=' ')
    print(':',end=' ')
    print(z[m])
    


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

try:
    h = list(input().split())
    #listA<-[1,2,2,3,1]
    #print(listA)
    #ここに逐次処理を書けばいいと思う。
except:
    quit();
    #または、quit(),os.exit()をして止める。

dp=[]

for i in range(N):
    dp.append(0)

dp[1]=abs(int(h[0])-int(h[1]))

for j in range(2,N):
    min=float('inf')
    for i in range(j-2,j):
        num=abs(int(h[i])-int(h[j])) + dp[i]
        if num < min:
            min=num
    dp[j]=min

print(dp[N-1])



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int count = 0;
    vector<int> xxx(2);
    for (int i = 0; i < n - 1; i++)
    {
        if (a.at(i) == a.at(i + 1))
        {
            xxx.at(count) = a.at(i);
            count++;
            i++;
            if(count==2){
                break;
            }
        }
    }
    if (count < 2)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << (long long)xxx.at(0) * xxx.at(1) << endl;
    }
}


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

int H, W;
vector<string> fi;
int Left[2100][2100], Right[2100][2100], Up[2100][2100], Down[2100][2100];

int main() {
    // 入力
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];

    // 前処理
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Left[i][j] = cur;
        }
    }
    for (int i = 0; i < H; ++i) {
        int cur = 0;
        for (int j = W-1; j >= 0; --j) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Right[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = 0; i < H; ++i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Up[i][j] = cur;
        }
    }
    for (int j = 0; j < W; ++j) {
        int cur = 0;
        for (int i = H-1; i >= 0; --i) {
            if (fi[i][j] == '#') cur = 0;
            else ++cur;
            Down[i][j] = cur;
        }
    }

    // 集計
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') continue;
            res = max(res, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 72448
n=int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.insert(0,[0,0,0])
a,x,y = zip(*l)

for i in range(n):
  count=a[i+1]-a[i]
  x_len=abs(x[i+1]-x[i])
  y_len=abs(y[i+1]-y[i])
  
  if (x_len+y_len)>count:
    print('No')
    exit()
  elif (count-(x_len+y_len))%2!=0:
    print('No')
    exit()
  else:
    continue
else:
  print('Yes')
   

Measured memory_bytes: 35420
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <random>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(x=0; x<(to); x++) // for簡略表記
#define DUMP(ar) for(int i=0; i<ar.size(); i++) cout << "[" << i << "]:" << ar[i] << endl // 配列一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ

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

    string s;
    lint k;
    cin >> s;
    cin >> k;

    lint ans = 0;
    int s_size = s.size();
    bool flag_firstend = false;
    int start_pos = -1;
    int cont = 0;
    bool flag = false;

    if(s[0] == s.back()) flag_firstend = true;
    if(flag_firstend){
        for(start_pos=0; start_pos<s.size()-1; start_pos++){
            if(s[start_pos] != s[start_pos+1]){
                ans += (start_pos + 1) / 2;
                break;
            }
        }
        if(start_pos == s.size()-1){
            ans = s.size() * k / 2;
            goto ANSWER;
        }
    }
    s.append(s);

    // cout << "start_pos = " << start_pos << endl;
    for(int i=start_pos+1; i<s.size()-1; i++){
        if(i >= s_size && flag == false){
            break;
        }
        if(s[i] == s[i+1]){
            if(i == s_size-1) flag = true;
            cont += 1;
        }else if(cont != 0){
            if(flag){
                // cout << "i発見 ans=" << ans;
                ans += (cont + 1) / 2 * (k - 1);
                // cout << " -> ans=" << ans << endl;
                cont = 0;
                for(int k=s.size()-1; k>=0; k--){
                    if(s[k] != s[k-1]){
                        break;
                    }
                    cont += 1;
                }
                ans += (cont + 1) / 2;
                goto ANSWER;
            }else{
                ans += (cont + 1) / 2 * k;
                // cout << "s発見 ans=0 -> ans=" << ans << endl;
                cont = 0;
            }
        }
    }

ANSWER:
    COUT(ans);

    return 0;
}

Measured memory_bytes: 256
S=list(str(input()))
S_int = [int(s) for s in S]
N=len(S)

A1 = [0]*N#0から始まる
A2 = [0]*N#1から始まる
for i in range(N):
  if i%2==0:
    A2[i]=1
  else:A1[i]=1
count1=0
count2=0
for i in range(N):
  if S_int[i]!=A1[i]:
    count1 += 1
  if S_int[i]!=A2[i]:
    count2 += 1
print(min(count1,count2))

Measured memory_bytes: 6316
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;

char S[11];
int len;
LL f(int n) {
    string s = S;
    LL res = 0;
    int pos = 0;
    int cnt = 1;
    REP (i, len-1) {
	int bit = 1 << i;
	if (n&bit) {
	    string sub = s.substr(pos, cnt);
	    //cout << sub << endl;
	    res += atoll(sub.c_str());
	    pos += cnt;
	    cnt = 1;
	} else {
	    cnt++;
	}
    }
    string sub = s.substr(pos, cnt);
    //cout << sub << endl;cout << endl;
    res += atoll(sub.c_str());
    return res;
}

int main(void) {
    scanf("%s", S);
    len = strlen(S);
    LL ans = 0;
    REP (i, 1 << (len-1)) {
	ans += f(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
int a,n,k,i,ii,flag;
scanf("%d %d",&n,&k);
int d[9] ;
for(i = 0;i < 9;i++)
	d[i] = 999;
int m = 0;
int t = n / 1000;
	n = n % 1000;
int h = n / 100;
	n = n % 100;
int z = n / 10;
	n = n % 10;
int o = n ;
int gm = m;
int gt = t;
int gh = h;
int gz = z;
int r = 1;

for(i = 0;i < k;i++)
	scanf("%d",&d[i]);

	for(a = 0;a < k;a++){
		for(i = 0;i < k;i++){
			while(r == 1){
				for(ii = 0;ii < k;ii++){
					if(o == d[ii]){
						o += 1;
					if(o == 10){
						o = 0;
						z += 1;
						}
						r = 0;
						break;
						} 
				
				r = 2;
				}
			}
			if(r == 2)
				break;
			if(o == d[i]){
				o += 1;
				r = 1;
			}
		}
}
r = 1;
	if(z >= 1){for(a = 0;a < k;a++){
		for(i = 0;i < k;i++){
			if(z == 10){
				z = 0;
				h += 1;
			}
			while(r == 1){
				for(ii = 0;ii < k;ii++){
					if(z == d[ii]){
						z += 1;
					if(z == 10){
						z = 0;
						h += 1;
						}
						r = 0;
						break;
						} 
				
				r = 2;
				}
			}
			if(r == 2)
				break;
			if(z == d[i]){
				z += 1;
				r = 1;
			}
		}
}
if(z != gz &&(d[0] != 0 && d[1] != 0 && d[2] != 0 && d[3] != 0 && d[4] != 0 && d[5] != 0 && d[6] != 0 && d[7] != 0 && d[8] != 0))
o = 0;
if(z != gz && o != 0 &&(d[0] != 1 && d[1] != 1&& d[2] != 1&& d[3] != 1&& d[4] != 1&& d[5] != 1 & d[6] != 1&& d[7] != 1&& d[8] != 1))
o = 1;
}

r = 1;
	if(h >= 1){for(a = 0;a < k;a ++){
		for(i = 0;i < k;i++){
			if(h == 10){
				h = 0;
				t += 1;
			}
			while(r == 1){
				for(ii = 0;ii < k;ii++){
					if(h == d[ii]){
						h += 1;
					if(h == 10){
						h = 0;
						t += 1;
						}
						r = 0;
						break;
						} 

				r = 2;
				}
			}
			if(r == 2)
				break;
			if(h == d[i]){
				h += 1;
				r = 1;
			}
		}
}
if(h != gh &&(d[0] != 0 && d[1] != 0 && d[2] != 0 && d[3] != 0 && d[4] != 0 && d[5] != 0 && d[6] != 0 && d[7] != 0 && d[8] != 0))
z = 0;
if(h != gh && z != 0 &&(d[0] != 1 && d[1] != 1&& d[2] != 1&& d[3] != 1&& d[4] != 1&& d[5] != 1 & d[6] != 1&& d[7] != 1&& d[8] != 1))
z = 1;
}

r = 1;
	if(t >= 1){for(a = 0;a < k;a++){
		for(i = 0;i < k;i++){
			if(t == 10){
				t = 0;
				m += 1;
			}
			while(r == 1){
				for(ii = 0;ii < k;ii++){
					if(t == d[ii]){
						t += 1;
					if(t == 10){
						t = 0;
						m += 1;
						}
						r = 0;
						break;
						} 

				r = 2;
				}
			}
			if(r == 2)
				break;
			if(t == d[i]){
				t += 1;
				r = 1;
			}
		}
}
if(t != gt &&(d[0] != 0 && d[1] != 0 && d[2] != 0 && d[3] != 0 && d[4] != 0 && d[5] != 0 && d[6] != 0 && d[7] != 0 && d[8] != 0))
h = 0;}

r = 1;
if(m >= 1){
	for(a = 0;a < k;a++){
		for(i = 0;i < k;i++){
			while(r == 1){
				for(ii = 0;ii < k;ii++){
					if(m == d[ii]){
						m += 1;
						r = 0;
						break;
						} 

				r = 2;
				}
			}
			if(r == 2)
				break;
			if(m == d[i]){
				m += 1;
				r = 1;
			}
		}
}
if(m != gm&&(d[0] != 0 && d[1] != 0 && d[2] != 0 && d[3] != 0 && d[4] != 0 && d[5] != 0 && d[6] != 0 && d[7] != 0 && d[8] != 0))
t = 0;}
		printf("%d",m * 10000 + 1000 * t + 100 * h + 10 * z + 1 * o);
		return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, m(1e7), s, t; cin >> N;
  int W[N]; for (int &w: W) cin >> w;
  for (int T{}; T < N; ++T)
    {s = t = 0; for (int i{}; i < N; ++i) if (i <= T) s += W[i]; else t += W[i];
    m = min(m, abs(s - t));}
  cout << m;}

Measured memory_bytes: 3596
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = k
for i in range(n):
    if i == 0:
        ans = min(ans,a[n-1]-a[0])
    else:
        ans = min(ans,k-(a[i]-a[i-1]))
print(ans)

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[1000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int x;
  cin>>x;
  for(int i=0;i<x;i++){
    int s,y,z,ans;
    cin>>s>>y>>z;
    if(s==0){ans=*min_element(a+y,a+z);}
    else if(s==1){ans=*max_element(a+y,a+z);}
    cout<<ans<<endl;
  }
    
  
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int h,w,kk;
	cin>>h>>w>>kk;
	long long int ans=0;
	int i,j;
	vector< vector<char> > a(h,vector<char> (w));
	vector< vector<char> > b;
	int r[h];
	int c[w];
	long long int count =0;
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='#')
			{
				r[i]++;
				c[j]++;
				count++;
			}
		}
	}
	memset(r,0,sizeof(r));
	memset(c,0,sizeof(c));
	if(1)
	{
		for(i=0;i<pow(2,h);i++)
		{
			  int k,l;
			  int x=i;
			  for(k=0;k<h;k++)
			  {
			  	r[k]=x%2;
			  	x/=2;
			  }
			  for(j=0;j<pow(2,w);j++)
			  {
			  	x=j;
			  	for(l=0;l<w;l++)
			  	{
			  		c[l]=x%2;
					x=x/2;	
				}
				b=a;
				int y,z;
				count=0;
				for(y=0;y<h;y++)
				{
					if(r[y]==1)
					{
						for(z=0;z<w;z++)
						{	
							if(c[z]==1 && b[y][z]=='#')
							count++;
						}	
					}
				}
				if(count==kk)
				ans++;
			  }
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 4084
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main()
{
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
		double x = (c*e - b*f) / (a*e - b*d);
		double y = (c*d - a*f) / (b*d - a*e);

		printf("%.3f %.3f\n", x + 0.0, y + 0.0);
	}
	
	return 0;
}

Measured memory_bytes: 3156
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        int c=0;
        int f=0;
        for (int i=0;i<n;i++){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if (a==b){
                c++;
                if (c==3){
                    f=1;
                    System.out.print("Yes");
                    break;
                }
            }
            else
                c=0;
        }
        if(f==0)
            System.out.print("No");
    }
}

Measured memory_bytes: 36204
#include <iostream>
#include <string>
int main() {
	int num = 0;
	int JadgeNums[4] = {};
	std::cin >> num;

	std::string Jadge;

	for (int i = 0; i < num; i++) {
		std::cin >> Jadge;
		if (Jadge == "AC") {
			JadgeNums[0]++;
			continue;
		}
		if (Jadge == "WA") {
			JadgeNums[1]++;
			continue;
		}
		if (Jadge == "TLE") {
			JadgeNums[2]++;
			continue;
		}
		if (Jadge == "RE") {
			JadgeNums[3]++;
			continue;
		}
	}

	std::string JadgeName[4] = { "AC","WA","TLE","RE" };

	for (int i = 0; i < 4; i++) {
		std::cout << JadgeName[i] << " x " << JadgeNums[i] << std::endl;
	}

	return 0;

}



Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    long long a, b, c;
    cin >> a >> b >> c;

    long long x = c - a - b;
    if(0 < x && 4 * a * b < x * x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		double r = sc1.nextDouble();

		System.out.println(String.format("%.8f", r*r*Math.PI) + " " + String.format("%.8f", 2*r*Math.PI));

		sc1.close();

	}

}


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

unsigned long long gcd(unsigned long long x, unsigned long long y){
    return y == 0 ? x : gcd(y, x % y);
}

unsigned long long lcm(unsigned long long x,unsigned long long y){
    return x / gcd(x,y) * y;
}

int main(){
    unsigned long long i,n,m,total=1;
    scanf("%lld %lld",&n,&m);
    unsigned long long a[n];
    for (i=0; i<n; i++){
        scanf(" %lld",&a[i]);
        a[i]/=2;
        total=lcm(total, a[i]);
    }
    for(i = 0; i < n; i++)
        if(total / a[i] % 2 == 0){
            printf("0\n");
            return 0;
        }
    printf("%lld\n",(m/total+1)/2);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
const LL INF=1e10;

int main(){
  int N;
  LL T;
  cin >> N >> T;
  vector<LL> t(N);
  rep(i,N) cin >> t[i];
  LL ans=0, time=0;
  t.push_back(INF);
  rep(i,N){
    if(t[i]+T>t[i+1]) ans+=t[i+1]-t[i];
    else ans+=T;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4224
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<iomanip>
#include<iostream>
#define F(A, B) for(int A=0; A<B; A++)
using namespace std;

int main(){
	int R, n;

	cin >> R >> n;
	while(!(R==0 && n==0) ){
		int pos[41][2]={ {0, 0} };
		int l, r, h;
		F(i, n){
			cin >> l >> r >> h;
			for(int j=l+20; j<r+20; j++){
				if(pos[j][0] < h)pos[j][0] = h;
			}
		}
		for(int i=40; i>0; i--){
			pos[i][1] = min(pos[i][0], pos[i-1][0]);
			pos[i][0] = max(pos[i][0], pos[i-1][0]);
		}

		double min=100;
		for(int i=20-R+1; i<=20+R-1; i++){
			double tmp=pos[i][1]-sqrt(static_cast<double>(R*R-(i-20>0 ? i-20:20-i)*(i-20>0 ? i-20:20-i) ) );
			if(min > tmp)min = tmp;
		}
		if(min <= -R){
			min = 0;
		}else{
			min = min+R;
		}
		cout << fixed << setprecision(4) << min << endl;

		cin >> R >> n;
	}

}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std;
typedef long double lld;
typedef long long ll;
const ll inf = 1e18;
const int maxn = 3005;
ll a[maxn], dp[maxn][maxn];

ll dfs(int l, int r) {
    if (l > r) return 0;
    if (dp[l][r] != inf) return dp[l][r];
    dp[l][r] = max(a[l] - dfs(l + 1, r), a[r] - dfs(l, r - 1));
    return dp[l][r];
}

int main() {
//    freopen("in.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = inf;
        }
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    cout << dfs(1, n)<< endl;
    return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int n,ans = 0;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            int tmp = lower_bound(l.begin(),l.end(),l[i]+l[j]) - l.begin();
            ans += max(tmp-(j+1),0);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);
        String str = scn.nextLine();
        String changed = "";

        for(int i = 0; i < str.length(); i++){

            if(Character.isUpperCase( str.charAt(i))){
                changed += Character.toLowerCase(str.charAt(i));
            }
            else if(Character.isLowerCase( str.charAt(i))){
                changed += Character.toUpperCase(str.charAt(i));
            }
            else{
                changed += str.charAt(i);
            }
        }
        System.out.println(changed);
    }
}


Measured memory_bytes: 31368
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int A[200000];

void solve(){
	ll ans = 0;
	if(A[0] != 0)
		ans = -1;
	else
		repr(i, N - 1){
			int d = A[i + 1] - (A[i] + 1);
			if(!d){
				ans += 1LL;
			}
			else if(d > 0){
				ans = -1;
				break;
			}
			else{
				ans += (ll)A[i + 1];
			}
		}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> A[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double t,a;
	cin>>n>>t>>a;
	double h[n+1];
	double minn=10000;
	int ind;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
		h[i]=t-h[i]*0.006;
		double cha=abs(h[i]-a);
		if(cha<minn)
		{
			minn=cha;
			ind=i;
		}
	}
	cout<<ind<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=3e3+2;
ll mod,g[N][N],C[N][N],f[N];

ll pow(ll x,ll y,ll p,ll res=1) {
    for(;y;y>>=1,x=x*x%p) if(y&1) res=res*x%p;
    return res;
}

int main() {
    int n;scanf("%d%lld",&n,&mod);
    for(int i=0;i<=n;++i) {
        C[i][0]=g[i][0]=1;
        for(int j=1;j<=i;++j) 
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod,
            g[i][j]=(g[i-1][j-1]+1ll*(j+1)*g[i-1][j]%mod)%mod;
    }
    ll ans=0;
    for(int i=0;i<=n;++i) {
        ll k=C[n][i];
        if(i&1) k=mod-k;
        ll x=pow(2,n-i,mod-1);x=pow(2,x,mod);
        ll num=pow(2,n-i,mod),y=1,res=0;
        for(int j=0;j<=i;++j)
            res=(res+1ll*g[i][j]*y%mod)%mod,y=num*y%mod;
        ans=(ans+k*res%mod*x%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 139392
n = int(input())
count = 0
for i in range(1,n+1,2): #1以上n以下の奇数iについて考えます
    prime = 1 #それ自身を含む
    for j in range(1,i//2):
        if i % j == 0:
            prime += 1
    if prime == 8:
        count += 1
print(count)   

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int a[3];
    rep(i,3) cin>>a[i];
    sort(a,a+3);
    if(a[0]==a[1] and a[1]!=a[2]){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(a[1]==a[2] and a[1]!=a[0]){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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

int main() {
    int x,y;
    cin >> x >> y;
    if(y >= 2*x and (y - 2*x) %2 == 0 and 4*x >= y){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(ll i=(ll)m ; i < (ll) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

//オンライン

template<typename T,const T id>
struct ConvexHullTrick{
    struct Line{
        T a,b;
        Line(T a=0,T b=0):a(a),b(b){}
        T get(T x){return -(x-a)*(x-a)-b;}
    };

    struct Node{
        Line l;
        Node *lhs,*rhs;
        Node(Line l):l(l),lhs(nullptr),rhs(nullptr){}
    };

    const T mi,ma;
    Node* root=nullptr;

    ConvexHullTrick(T mi=0,T ma=1<<30):mi(mi),ma(ma){}
    Node* insert(Node* p,T lb,T ub,Line& l){
        if(!p)return new Node(l);
        if(p->l.get(lb)>=l.get(lb)&&p->l.get(ub)>=l.get(ub))return p;
        if(p->l.get(lb)<=l.get(lb)&&p->l.get(ub)<=l.get(ub)){
            p->l = l;
            return p;
        }
        T mid=(lb+ub)/2;
        if(p->l.get(mid)<l.get(mid))swap(p->l , l);
        if(p->l.get(lb)<=l.get(lb)){
            p->lhs=insert(p->lhs,lb,mid,l);
        }
        else {
            p->rhs=insert(p->rhs,mid,ub,l);
        }
        return p;

    }
    void insert(T a,T b){
        Line l(a,b);
        root=insert(root,mi,ma,l);
    }

    void insert(Line l){
        root=insert(root,mi,ma,l);
    }
    T query(Node* p,T lb,T ub,T t){
        if(!p)return id;
        if(lb==ub)return p->l.get(t);
        T mid=(lb+ub)/2;
        if(t<=mid)return max(p->l.get(t),query(p->lhs,lb,mid,t));
        else return max(p->l.get(t),query(p->rhs,mid,ub,t));
    }

    T query(T x){
        return query(root,mi,ma,x);
    }
};


int main(){
    int n;cin>>n;
    ll c;cin>>c;
    ConvexHullTrick<ll,-longinf> cht; 
    ll ret=0; 
    rep(i,n){
        ll h;cin>>h;
        if(i)ret=-cht.query(h);
        cht.insert(h,c+ret);
    }  
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 2000000000000000000 //2e18
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

const int N=200005;
vector<int> adj[N];
vector<int> dp(N);
vector<bool> vis(N,false);

int dfs(int s)
{
    if(vis[s]) return dp[s];
    vis[s]=true;
    for(int u:adj[s])
    {
        dp[s]=max(dp[s],dfs(u)+1);
    }
    return dp[s];
}

void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,pos,sum=0,flag=0,count=0;
    string S,T,U; 
    // int mx;
    cin>>n>>m;
    while(m--)
    {
        cin>>u>>v;
        adj[u].pb(v);
    }
    int ans=0;
    rep(i,1,n+1)
    {
        if(!vis[i])
        {
            ans=max(ans,dfs(i));
        }
    }
    cout<<ans;
}

 

signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 14432
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a < b){
		printf("<\n");
	}
	else if(a > b){
		printf(">\n");
	}
	else{
		 printf("=\n");
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
bool comp(const pair<int,int>a,const pair<int,int>b){
	if(a.first!=b.first)return a.first<b.first;
	else{
		return a.second>b.second;
	}
}
int main(){
	int num[9]={2,5,5,4,5,6,3,7,6},n,m;
	cin>>n>>m;
	vector<pair<int,int>>a(m);//firstに数字のコスト,secondに数字
	for(int i=0;i<m;i++){
		cin>>a[i].second;
		a[i].first=num[a[i].second-1];
	}
	sort(a.begin(),a.end(),comp);
	vector<string>dp(n+1,"");//nまでのdpテーブル,配列の長さを入れる
	for(int i=1;i<n+1;i++){
		for(int j=0;j<m;j++){
			if(i-a[j].first==0||i-a[j].first>=0&&dp[i-a[j].first]!="\0"){
				string hoge=to_string(a[j].second)+dp[i-a[j].first];//足す順番は関係ない
				if(hoge.length()>dp[i].length())dp[i]=hoge;
				else if(dp[i].length()==hoge.length()){
					dp[i]=max(hoge,dp[i]);
				}
			}
		}
	}
	cout<<dp[n]<<endl;
	
}



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

int main(){
	int n, x;
	while(cin >> n, n){
		int a[10] = {0};
		for(int i = 0; i < n; i++){
			cin >> x;
			a[x]++;
		}

		for(int i = 0; i < 10; i++){
			if(a[i] == 0){
				cout << "-" << endl;
				continue;
			}
			for(int j = 0; j < a[i]; j++){
				cout << "*";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  int n;
  cin >> n;
  int m = (n / 1000 + (n % 1000 > 0 ? 1 : 0)) * 1000;
  cout << m - n << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    ll sum=0,count=0;
    rep(i,s.size()){
        if(s[i]=='W'){
            sum+=i-count;
            count++;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()


void solve(){
 ll d;
  cin >> d;
  vll c(26);
  rep(i,0,26) cin >> c[i];  
  
 vvll s(d,vll(26));
  rep(i,0,d){
    rep(j,0,26) cin >> s[i][j]; 
  }
  
  vll t(d);
  rep(i,0,d) t[i]=(i%26);
  
  vector<set<ll>> v(26);
  rep(j,0,26){
    v[j].insert(-1);
    v[j].insert(d);
  }
  
  ll ans=0;
  rep(i,0,d){
    ans+=s[i][t[i]];
    v[t[i]].insert(i);
    rep(j,0,26) ans-=c[j]*(i-*v[j].rbegin());
  }
  
  vll f(d,0);
  
  ll m=d*26;
  
  rep(k,0,5000){
      rep(i,0,d){
        if(f[i]>m) continue;
        rep(j,1,26){
        ll cost=ans;
      auto prev=v[t[i]].find(i);
      auto next=prev;    
      prev--;
      next++;
      cost=cost-c[t[i]]*(i-*prev)*(*next-i);
        v[t[i]].erase(i);  
      t[i]=(t[i]+j)%26;
      
      v[t[i]].insert(i);
      prev=v[t[i]].find(i);
      next=prev;
      prev--;
      next++;
      cost=cost+c[t[i]]*(i-*prev)*(*next-i);
      
      if(cost>ans) {
        ans=cost;
      }
      else {
        v[t[i]].erase(i);
        t[i]=(t[i]-j+26)%26; 
        v[t[i]].insert(i); 
        f[i]++;
      }
      }
      }
      }
  
  rep(i,0,d) cout << t[i]+1 << endl;

  
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int x[maxn], y[maxn]; char d[maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> d[i];
	auto apply = [&](double t, int ind){
		pair<double, double> ans;
		ans.first = x[ind];
		ans.second = y[ind];
		if(d[ind] == 'L') ans.first -= t;
		if(d[ind] == 'R') ans.first += t;
		if(d[ind] == 'U') ans.second += t;
		if(d[ind] == 'D') ans.second -= t;
		return ans;
	};
	auto fdx = [&](double t){
		double maxx, minx, maxy, miny;
		maxx = minx = apply(t, 0).first;
		maxy = miny = apply(t, 0).second;
		for(int i = 1; i < n; i++){
			auto r = apply(t, i);
			maxx = max(maxx, r.first);
			minx = min(minx, r.first);
			maxy = max(maxy, r.second);
			miny = min(miny, r.second);
		}
		return (maxx - minx) * (maxy - miny);
	};
	double lo = 0, hi = 1e9;
	for(int i = 0; i < 200; i++){
		double p0 = lo + (hi - lo) / 3;
		double p1 = hi - (hi - lo) / 3;
		if(fdx(p0) < fdx(p1)) hi = p1;
		else lo = p0;
	}
	cout << fixed << setprecision(12) << fdx(lo) << endl;
	return 0;
}


Measured memory_bytes: 1152