akhauriyash/Code-Regression huggingface dataset:
// prob name -
//author - COOL
#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define int long long int
#define mii map<int, int>
#define vi vector<int>
#define fi(i, a, n)             \
    for (int i = 0; i < n; i++) \
    {                           \
        cin >> a[i];            \
    }
#define fo(i, a, n)             \
    for (int i = 0; i < n; i++) \
    {                           \
        cout << a[i] << " ";    \
    }
#define PB push_back
#define MP make_pair
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define mk(arr, n, type) type *arr = new type[n];
#define pw(b, p) pow(b, p) + 0.1
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define Pi 3.14159265358979
using namespace std;
// int knapsack(int * wt,int * price ,int n,int totW ){
// if(n==0){
//     return 0;
// }
// int inc =0,exc =0;
// int currweight = wt[n-1];
// if((totW - currweight>=0)){
// inc = price[n-1] + knapsack(wt,price,n-1,totW -currweight); 
// }
// else{
// exc =  knapsack(wt,price,n-1,totW); 
// }
// return max(inc ,exc);
// }
int knapsackBU(int *wt,int * price,int n, int totalweight){
int dp[n+1][totalweight+1];
    
    if(n==0){
        return 0;
    }
    for (int  i = 0; i <= n; i++)
    {
        for (int  j = 0; j <=totalweight ; j++)
        {
        
            if (i==0||j==0)
            {
                dp[i][j] =0;
            }
            
        }        
    }
    for (int item = 1; item <= n; item++)
    {
        for (int  weight = 1; weight <=totalweight ; weight++)
        {
            int inc =0,exc =0;
            exc =dp[item-1][weight];
            int currweight = wt[item-1];
            if((weight - currweight)>=0){
                inc = price[item - 1] + dp[item - 1][weight - currweight];
            }
        int ans= max(inc,exc);
           dp[item][weight] = ans;
        }        
    }
    // for (int  i = 0; i <=n; i++)
    // {
    //     for (int  j = 0; j <=totalweight; j++)
    //     {
    //         cout<<dp[i][j]<< " ";
    //     }
    //     cout<<endl;
    // }
    return dp[n][totalweight];
}
using namespace std; //_S_A_R_T_H_A_k_//
/// JAI SHREE RAM!!! ;{'*' <_l_> '*' };
/// Saare jahan se acha hindustan humara .....
/// JAI HIND DOSTON //-__ -//
int32_t main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
        int n,w;
        cin>>n>>w;
        int price[n];
        int  wt[n];
        for (int  i = 0; i < n; i++)
        {    cin>>wt[i];
            cin>>price[i];
          }
        cout<<knapsackBU(wt,price,n,w)<<endl;
    return 0;
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,ans=1;
	cin>>x;
	for(int i=2;1<<i<=x;i++)
		ans=max(ans,int(pow(int(pow(x,1.0/i)+0.001),i)));
	cout<<ans<<endl;
}


Measured memory_bytes: 384
my_equal::Char->Char->Bool
my_equal c d = case (c,d) of
              ('?',_) -> True
              (_,'?') -> True
              (a,b)   -> a==b

try_gen::String->String->Maybe String
try_gen rest   []      = Just rest
try_gen []     (y:rest)  = Nothing
try_gen (x:xs) (y:ys)  = if my_equal x y then case try_gen xs ys of
                                                Nothing   -> Nothing
                                                Just rest -> Just (y:rest)
                                         else Nothing

total_case::String->String->[Maybe String]
total_case [] t = []
total_case (s:ss) t = (try_gen (s:ss) t):(map (\x -> case x of
                                                      Nothing -> Nothing
                                                      Just st -> Just (s:st)) (total_case ss t))

solver::String->String->String
solver s t = let ls =  filter (Nothing/=) (total_case s t) in
             case ls of
                []        -> "UNRESTORABLE"
                otherwise -> let Just str = last ls in map (\c-> if c =='?' then 'a' else c) str

main::IO()
main=do
  s<-getLine
  t<-getLine
  putStr (solver s t)
  putStr "\n"

Measured memory_bytes: 636
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int a;
    int b;
    int c;
    int d;
    int e;
 
   cin >> a >> b >> c >>d >>e;
  
   if(c >= e && d >=e){
     
      if(a-e >= c && b-e >=d){
     
        cout << "Yes" << endl;
     
      }else{
        cout << "No" << endl;
      }
   }else{
     cout << "No" << endl;
   }
  
  return 0;
}


Measured memory_bytes: 3096
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

def factorize(n: int):
    d = Counter()
    m= 2
    
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
            
        m += 1
        
    if n > 1:
        d[n] += 1
        
    return d


n,m = li()

MOD = 10**9+7

# 二項係数の準備
inv = inv_mod(n+100,MOD)
fac = fact(n+100,MOD)
facInv = fact_inv(n+100,inv,MOD)


primes = factorize(m)
ans = 1

if n == 1 or m == 1:
    print(ans)
else:
    for pi in primes.values():
        ans = ans * nCr(n+pi-1, pi, MOD, fac, facInv) % MOD
    print(ans)


Measured memory_bytes: 15368
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	int n;
	string s;
	cin >> n >> s;

	if (n % 2 == 1)
	{
		cout << "No"; return;
	}

	rep(i, n / 2)
	{
		if (s[i] != s[i + n / 2])
		{
			cout << "No"; return;
		}
	}

	cout << "Yes";
}

/*****/

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

	//std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
import sys
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, a, b = LI()
    print(min(n * a, b))




if __name__ == "__main__":
    main()

Measured memory_bytes: 5332
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;


int main(){

    int n;
    cin >> n;

    vector<int> p;

    rep(i,n){
        int tmp;
        cin >> tmp;

        p.pback(tmp);
    }

    int ans = 0;

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <math.h>
#include <map>
#include <set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/** In set, multiset ,map etc the concept of index
    does not exist. */

/*

Bring me back to the time
When we were free, just you and I
Now I can feel the pressure building
The battle for us to survive

[Pre-Chorus]
You're an addiction
The only drug I'll ever need
Like a prescription
I crave you to breathe

[Chorus]
You're an addiction
The only drug I'll ever need
You're an addiction
The only drug I'll ever need

[Drop]
(You're an addiction)
(The only drug I'll ever need)

[Verse 2]
Bring me back to the time
When we would make it 'cross the line
Now I can feel the end is nearing
The time for us has arrived

[Pre-Chorus]
You're an addiction
The only drug I'll ever need
Like a prescription
I crave you to breathe

*/

/*

When I saw you I would lose control
Made me feel like there was no tomorrow
Should've told you that you're beautiful
But the days pass and now it's so long ago

Did you make it?
Did you break free?
Did you manage to be who you wanna be?
Maybe somewhere you think about me too

I wonder where are you now
~

*/


using namespace std;
using namespace __gnu_pbds;

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

/** find_by_order(int k) -> iterator to kth largest element
    order_of_key(int e)  -> position of element with
    value 'e' ie. number of elements strictly less than e */

int mod=1000000007;

int powmod(int64_t a,int64_t b){
int64_t ans=1;while(b>0){if(b&1){b--;ans=(ans*a)%mod;}
else{a=(a*a)%mod;b=b>>1;}}return ans;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cout<<fixed;
    ///learn from your mistakes
    ///read the question properly
    ///initialize variables s'il vous plait
    int n,k;
    cin>>n>>k;
    int p = ceil(n/(double)2);
    if(p>=k){
        cout<<"YES";
    }
    else cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
vector<vector<pll>> adj;

void dijkstra(int s, vector<ll> & d, vector<int> & p) {
    int n = adj.size();
    d.assign(n, INF);
    p.assign(n, -1);

    d[s] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push({0, s});
    while (!q.empty()) {
        int v = q.top().second;
        ll d_v = q.top().first;
        q.pop();
        if (d_v != d[v])
            continue;

        for (auto edge : adj[v]) {
            int to = edge.first;
            ll len = edge.second;

            if (d[v] + len < d[to]) {
                d[to] = d[v] + len;
                p[to] = v;
                q.push({d[to], to});
            }
        }
    }
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	adj.resize(n);
	for (int i = 1; i < n; i++) {
		adj[i].push_back({i - 1, 0});
	}
	for (int i = 0; i < m; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		u--; v--;
		adj[u].push_back({v, c});
	}
	vector<ll> d(n);
	vector<int> p(n);
	dijkstra(0, d, p);
	if (d[n - 1] != INF)
		cout << d[n - 1];
	else
		cout << -1;
	return 0;
}

Measured memory_bytes: 10496
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

for i in range(n):
    if a[i] > 1:
        ary[a[i]-2] += 1
        ary[a[i]-1] += 1
    ary[a[i]] += 1

print(max(ary))

Measured memory_bytes: 13964
#include <stdio.h>

int main() {
    int d, y, x, area;
    while ( scanf("%d", &d) != EOF ) {
        area = 0;
        for (int i=0; i<600/d; i++) {
            x = d * i;
            y = x * x;
            area += d * y;
        }
        printf("%d\n", area);
    }
    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b)	swap(a,b);
	if(a>c) swap(a,c);
	if(b>c) swap(b,c);
	int ans=(a*b)/2;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    H, N = MI()
    A = LI()

    if sum(A) >= H:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 84300
#include <iostream>
#include <cstring>
using namespace std;
const int Max = 200;

string a[Max], b[Max];
void BubbleSort(string a[], int N)
{
    int flag = 1, i = 0;
    while(flag)
    {
        flag = 0;
        for(int j=N-1; j>i; j--)
        {
            if(a[j][1] < a[j-1][1])
            {
                string temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
                flag = 1;
            }
        }
        i++;
    }
}
void SelectSort(string a[], int N)
{
    for(int i=0; i<N-1; i++)
    {
        int minj = i;
        for(int j=i+1; j<N; j++)
        {
            if(a[minj][1]>a[j][1])
                minj = j;
        }
        if(i!=minj)
        {
            string temp = a[i];
            a[i] = a[minj];
            a[minj] = temp;
        }
    }
}
void print(string a[], int N)
{
    for(int i=0; i<N-1; i++)
    {
        cout << a[i] << " ";
    }
    cout << a[N-1] << endl;
}
int main()
{
    int N, flag = 0;
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    BubbleSort(a, N);
    SelectSort(b, N);
    for(int i=0; i<N; i++)
    {
        if(a[i]!=b[i])
        {
            flag = 1;
            break;
        }
    }
    print(a, N);
    cout << "Stable" << endl;
    print(b, N);
    if(flag)
        cout << "Not stable" << endl;
    else
        cout << "Stable" << endl;
    return 0;
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,t,min=1000000009;
  cin>>n>>t;
  vector<int> a(n),b(n);
  std::map<int, int> mp;
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
    b[i] = (min>a[i] ? 0:a[i]-min); 
    min=std::min(min,a[i]);
    mp[b[i]]++;
  }

  cout<<mp[*max_element(b.begin(), b.end())];
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{   int n,a[101];
    cin>>n;
    for(int i=0;i<n;i++)  cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
	  for(int j=0;j<n-1;j++)
	  {
	    if(a[j]>a[j+1])
	    {
		  int t;
		  t=a[j];
		  a[j]=a[j+1];
		  a[j+1]=t;
		}
	  }
	}
	cout<<a[n-1]-a[0];
	return 0;
}

Measured memory_bytes: 256
N,M,R=map(int, input().split())
r=list(map(int, input().split()))
dp=[[10**9]*N for _ in range(N)]
for _ in range(M):
    A,B,C=map(int, input().split())
    A-=1
    B-=1
    dp[A][B]=C
    dp[B][A]=C
for z in range(N):
    for x in range(N):
        for y in range(N):
            dp[x][y]=min(dp[x][y], dp[x][z]+dp[z][y])

import itertools
ans=10**9
for p in itertools.permutations(range(R)):
    t=0
    rp=[r[i] for i in p]
    for i in range(R-1):
        t+=dp[rp[i]-1][rp[i+1]-1]
    ans=min(ans,t)
print(ans)

Measured memory_bytes: 47192
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main () {
	io_optimized
	long long int h,n,a;
	while(cin>>h>>n)
	{
		int a[h];
		long long int sum=0;
		for(int i=0;i<h;i++)
		{
			cin>>a[i];
		}
		sort(a,a+h);
		for(int i=0;i<h-n;i++)
		{
			sum+=a[i];
		}
		cout<<sum<<"\n";
	}

	return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int n,m;
cin>>n>>m;
int a[m],b[m];
map<int,bool>ms,me;
rep(i,m){
  cin>>a[i]>>b[i];
if(a[i]==1){
  ms[b[i]]=true;
}
if(b[i]==n){
  me[a[i]]=true;
}
}
for(int i=2;i<n;i++){
  if(ms[i]&&me[i]){
    cout<<"POSSIBLE"<<endl;
return 0;
  }
}
cout<<"IMPOSSIBLE"<<endl;

  return 0;
}


Measured memory_bytes: 20608
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
#define int long long

int a[51];
int p[51];

int saiki(int lev,int h){
    if(lev==1){
        if(h==1){
            return 0;
        }else if(h<5){
            return h-1;
        }else{
            return 3;
        }
    }else{
        if(h==1){
            return 0;
        }
        if(h<=1+a[lev-1]){
            return saiki(lev-1,h-1);
        }
        if(h==a[lev-1]+2){
            
            return 1+p[lev-1];
        }
        if(h<=2+2*a[lev-1]){
            return 1+p[lev-1]+saiki(lev-1,h-a[lev-1]-2);
        }

        return p[lev];
    }

}

signed main(){
    int n,x;
    cin >> n >> x;
    a[0] =1;
    a[1] =5;
    p[0] =1;
    p[1] =3;
    for(int i=2;i<51;i++){
        a[i]= 2*a[i-1]+3;
        p[i]= 2*p[i-1]+1;
    }
    cout << saiki(n,x) << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

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

void solve_75B(){
    int h, w;
    cin >> h >> w;
    char s[h][w];
    int ans[h][w];
    REP(i,h){
        REP(j, w){
            cin >> s[i][j];
            ans[i][j] = 0;
            if(s[i][j] == '#') ans[i][j] = -1;
        }
    }

    REP(i,h){
        REP(j,w){
            if(s[i][j] == '#') continue;
            REP(k, 8){
                if(i + dx[k] < 0 || i + dx[k] >= h || j + dy[k] < 0 || j + dy[k] >= w) continue;

                if(s[i + dx[k]][j + dy[k]] == '#') ans[i][j]++;
            }
        }
    }

    REP(i,h){
        REP(j,w){
            if(ans[i][j] < 0) cout << '#';
            else cout << ans[i][j];
        }
        cout << endl;
    }
    
}

int main(void){
    solve_75B();
    
    return 0;
}

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

using namespace std;

int C[10000];
int n;

void CountingSort(int A[], int B[], int k) {

	for (int i = 0; i <= k; ++i) {
		C[i] = 0;
	}

	for (int j = 1; j <= n; ++j) {
		/* C[i] ??? i ???????????°????¨?????????? */
		C[A[j]]++;
	}

	/* C[i] ??? i ??\????????°???????????°????¨??????????*/
	for (int i = 1; i <= k; ++i) {
		C[i] = C[i] + C[i - 1];
	}

	for (int j = n; j > 0; --j) {
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}

}

int main() {

	scanf("%d", &n);

	int A[n];
	int B[n];

	int k = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &A[i]);
		if (A[i] > k) {
			k = A[i];
		}
	}

	CountingSort(A, B, k);

	for (int i = 1; i <= n; ++i) {
		if (i != 1) {
			cout << " ";
		}
		cout << B[i];
	}
	cout << endl;

	return 0;
}

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

int main() {
    int a,b,c,d,e;
    while(cin>>a && a){
        cin>>b>>c>>d>>e;
        int na, nb, nc;
        cin>>na>>nb>>nc;
        int ans = a*na+b*nb+c*nc;
        if(nc >= d){
            ans = min(ans,a*na+b*nb+e*nc);
        }else if(nb+nc >= d){
            ans = min(ans, a*na+b*(nb+nc-d)+d*e);
        }else if(na+nb+nc >= d){
            ans = min(ans, a*(na+nb+nc-d)+d*e);
        }else{
            ans = min(ans, d*e);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    vector<int> a;
    int n, t;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> t;
        a.push_back(t);
    }
    vector<int> dp = {0, abs(a[0]-a[1])};
    for(int j = 2; j < n; ++j){
        dp.push_back(min(abs(a[j] - a[j - 1]) + dp[j - 1], abs(a[j] - a[j - 2]) + dp[j - 2]));
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 1400
N, M = map(int, input().split())
li = []
for i in range(M):
  liin = input().split()
  li.append([int(liin[0]), liin[1]])

ans1, ans2 = 0, 0
done = set([0])
miss = {}

for i in range(M):
  if li[i][0] in done:
    continue
  if li[i][1] == "AC":
    ans1 += 1
    done.add(li[i][0])
    if li[i][0] in miss:
      ans2 += miss[li[i][0]]
      del miss[li[i][0]]
  else: # "WA"
    if li[i][0] in miss:
      miss[li[i][0]] += 1
    else:
      miss[li[i][0]] = 1

print(ans1,ans2)

Measured memory_bytes: 28064
from array import array
from collections import deque
import re

N,K = list(map(int, input().split()))
S = input()

_111_list = re.split(r'0+', S)
_000_list = re.split(r'1+', S)
if _000_list[0] == '':
    _000_list.pop(0)
if _000_list[-1] == '':
    _000_list.pop(-1)

_len_array = array('l', [0]*(len(_000_list) + len(_111_list)))
i = 0
_len_array[i] = len(_111_list.pop(0))

for _000, _111 in zip(_000_list, _111_list):
    i += 1
    _len_array[i] = len(_000)
    i += 1
    _len_array[i] = len(_111)

i_start = 0
i_end = min(len(_len_array), (K+1) + K)

_sum_max = sum(_len_array[i_start:i_end])
_sum = _sum_max

while(True):
    i_start += 2
    i_end += 2
    if i_end > len(_len_array):
        break
    _sum = _sum - _len_array[i_start-2] - _len_array[i_start-1] + _len_array[i_end-2] + _len_array[i_end-1]
    _sum_max = max(_sum_max, _sum)

print(_sum_max)


Measured memory_bytes: 51292
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

long double f(long double a, long double b, long double theta) {
    // if(theta > M_PI / 2.0 - EPS) {
    //     return 0.0;
    // }
    long double ret;
    if(a * tan(theta) <= b) {
        ret = a * a * b - a * a * a * tan(theta) / 2.0;
    } else {
        ret = b * b / tan(theta) * a / 2.0;
    }
    return ret;
}

void solve() {
    long double a, b, x;
    cin >> a >> b >> x;

    long double ok = M_PI / 2.0;
    long double ng = 0.0;

    while(1) {
        if(ok - ng <= 0.00000001) break;
        long double mid = (ok + ng) / 2.0;
        if(f(a, b, mid) < x) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << ok / M_PI * 180 << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int n;
int a,b,c;
vector<pair<int,int>> v[100001];
int ans[100001];

void dfs(int num,int node){
    ans[node]=num;
    for(int i=0;i<v[node].size();i++){
        int next=v[node][i].first,x=v[node][i].second;
        if(ans[next]!=-1)continue;
        dfs((num+x)%2,next);
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b>>c;
        v[a].push_back(make_pair(b,c%2));
        v[b].push_back(make_pair(a,c%2));
    }
    for(int i=1;i<=n;i++)ans[i]=-1;
    dfs(0,1);
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 8320
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        if (n % 2 == 0) {
            System.out.println(n);
        } else {
            System.out.println(n * 2);
        }
    }
}


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

typedef long long ll;

int t = 1;

void solve() {
	int k, n, c = 0; cin >> n >> k;
	vector<int> f (n);
	for (int i = 0; i < n; i++) cin >> f[i];
	sort(f.begin(), f.end());
	
	for (int i = 0; i < k; i++) c += f[i];
	
	cout << c << endl;
	
}

int main() 
{ 
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("data.in", "r", stdin);
	
	//cin >> t;
	while (t--) solve();
	
    return 0; 
}





Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <time.h>
#include <unistd.h>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
};

int main(void) {
    if (time(NULL) & 8) sleep(3);
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (a + b + c) % 29;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1728
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int dns(int n,int i,int a,int b,int c,int *l,int d,int e,int f){
	int num1,num2,num3,num4;

	if(i==n){
		if(min({d,e,f})==0){
			return inf;
		}
		return abs(a-d)+abs(b-e)+abs(c-f)-30;
	}

	num1 = dns(n,i+1,a,b,c,l,d,e,f);
	num2 = dns(n,i+1,a,b,c,l,d+l[i],e,f)+10;
	num3 = dns(n,i+1,a,b,c,l,d,e+l[i],f)+10;
	num4 = dns(n,i+1,a,b,c,l,d,e,f+l[i])+10;

	return min({num1,num2,num3,num4});
}

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

    int n,a,b,c;
	cin >> n >> a >> b >> c;
	int l[n];

	rep(i,n){
		cin >> l[i];
	}

    cout << dns(n,0,a,b,c,l,0,0,0) << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$x);
$FIVE_SIX = 5+6;

if($x<=6){
  echo "1";
}elseif($x<=11){
  echo "2";
}else{
  $tmp = (int)($x/$FIVE_SIX);
 // echo $tmp*$FIVE_SIX."\n";
  if($tmp*$FIVE_SIX==$x){
    echo $tmp*2;
  }elseif($tmp*$FIVE_SIX+6>=$x){
      echo $tmp*2+1;
  }else{
    echo ($tmp*2)+2;
  }
}

Measured memory_bytes: 4604
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]
xx = sorted(x)
mid = n//2-1

d = {}
for i in range(n):
    if i<=mid:
        d[xx[i]] = xx[mid+1]
    else:
        d[xx[i]] = xx[mid]

for i in range(n):
    print(d[x[i]])


Measured memory_bytes: 34820
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a[]={1,100,10000};
  int d,n;
  cin>>d>>n;
  if(n==100)n++;
  int ans=a[d]*n;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
L = int(input())
def digits_count(n):
  cnt = 0
  while n != 0:
    cnt += 1
    n //= 2
  return cnt
def doubling(n, m):
  y = 1
  base = n
  while m != 0:
    if m % 2 == 1:
      y *= base
    base *= base
    m //= 2
  return y
m = digits_count(L)
A = [0 for _ in range(m)]
for i in range(m, 0, -1):
  A[i-1] = L % 2
  L //= 2
binomial = [1 for _ in range(m)]
for i in range(1, m):
  binomial[i] = binomial[i-1] * 2
vert = [[i*m+i+1, binomial[i]] for i in range(m-1)]
vert = vert[:] + [[i*m+i+1, 0] for i in range(m-1)]
S = doubling(2, m - 1)
for i in range(1, m):
  if A[i] == 1:
    vert.append([(m-i-1)*m+m-1, S])
    S += binomial[m-i-1]
print(m, len(vert))
for i in vert:
  print(i[0] // m + 1, i[0] % m + 1, i[1])

Measured memory_bytes: 3064
def main():
    A = [int(input()) for i in range(5)]
    B = []
    for a in A:
        if a % 10 == 0:
            B.append(a)
        else:
            B.append((1+a//10)*10)
    ans = sum(B)
    maxV = max(A, key=lambda x: (10 - x % 10) % 10)
    print(ans - (10 - maxV % 10) % 10)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int n = s.length();
        String s1 = s.substring(0, (n - 1) / 2);
        String s2 = s.substring((n + 3) / 2 - 1, n);
        boolean v = s.equals(new StringBuffer(s).reverse().toString())
                && s1.equals(new StringBuffer(s1).reverse().toString())
                && s2.equals(new StringBuffer(s2).reverse().toString());
        System.out.println(v ? "Yes" : "No");
    }
}


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

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

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

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

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

set < int > S;

int main()
{
    _upgrade
    int n; cin >> n;
    while(n--)
    {
        int x; cin >> x;
        if(S.find(x) != S.end()) S.erase(x);
        else S.insert(x);
    }
    cout << sz(S) << "\n";
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
auto divv = [](ll n) {
  unordered_set<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
//   sort(ALL(v));
  return v;
};

auto isprime = [](auto n){
  bool isPrime = true;
  for(decltype(n) i = 2; i <= sqrt(n); ++i)
  {
      if(n % i == 0)
      {
          isPrime = false;
          break;
      }
  }
  return isPrime;
};

int main() {
    ll n,k;
    cin>>n>>k;


    unordered_set<ll> divn,divk;
    divn = divv(n);
    // for(auto it:y){
    //     divn.insert(it);
    // }
    {
        ll lim = sqrt(k);
        fr(i, 1, lim+1){
            if(k%i ==0){
                divk.insert(i);
                divk.insert(k/i);
            }
        }
    }
    ll sum=0;
    for(auto it:divk) if(divn.count(it)) if(isprime(it)) sum++;
    pr(sum);
}


Measured memory_bytes: 768
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n,k;
    cin >> n >> k;
    vector<long long> array1(n+1,0);
    vector<long long> array2(n+1,-1);
    vector<long long> array3(n,0);
    vector<long long> array4(n,0);
    for(int i=1;i<n+1;i++){
        cin >> array1[i];
    }
    array2[1]=1;
    long long p=1;
    long long x=array1[p];
    long long m=1;
    long long mod=0;
    array3[0]=1;
    long long y=0;
    bool flag = true;
    while(flag==true){
        if(array2[x]<0){
            p=p+1;
            array2[x]=p;
            array3[m]=x;
            m=m+1;
            x=array1[x];
        }else{
            y=array2[x];
            mod=p-y+1;
            flag = false;
        }
    }

    if(mod==p){
        cout <<array3[k%p] << endl;
    }else{
        for(int i=y;i<p+1;i++){
            array4[i-y]=array3[i-1];
        }
        if(k<p){
            cout << array3[k] << endl;
        }else{
            cout << array4[(k-(y-1))%mod] << endl;
        }
    }
}

Measured memory_bytes: 9528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		long ans = 0;
		for(int mask = 0 ; mask < 1<<(n - 1) ; mask++) {
			long sum = 0;
			String x = "" + s.charAt(0);
			for(int i = 0 ; i < n - 1 ; i++) {
				if((mask&(1<<i)) >= 1) {
					x += "+" + s.charAt(i + 1);
				} else {
					x += s.charAt(i + 1);
				}
			}
			String[] split = x.split("\\+");
			for(int i = 0 ; i < split.length ; i++) {
				sum += Long.valueOf(split[i]);
			}
			ans += sum;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    cout << max(0LL, a-2*b) << '\n';
    return 0;
}


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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int m;
  m=max({a,b,c});
  long x;
  x=m*pow(2,k);
  cout << a+b+c-m+x;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    int64 n;
    int64 rs = 1;
    cin >> n;
    rs = n + n*n + n*n*n;
    ctn(rs);
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] nums = new long[n];
        for(int i = 0; i < n; i++) nums[i] = sc.nextLong();
        sc.close();
        for(int i = 0; i < n - 1; i++){
            nums[i + 1] = lcm(nums[i] , nums[i + 1]);
        }
        System.out.println(nums[n - 1]);
    }
    public static long lcm(long a, long b){
        return a / gcd(a, b) * b;
    }
    public static long gcd(long a, long b){
        while(a % b != 0){
            return gcd(b, a%b);
        }
        return b;
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#define Vmaxn 100010
#define Emaxn 500010
#define inf 2147483646

using namespace std;

struct Node
{
    int x,y,val,pre;
};
//邻接表存储方法
int g_[Vmaxn];
Node g[Emaxn];

int n,m,r;
int dis[Vmaxn],cnt[Vmaxn];
bool h[Vmaxn];//判断是否在队列中
queue<int> q;

int main()
{
    int i,j,k,t,ans;
    int p,p_;
    bool negative;

    cin>>n>>m>>r;
    memset(g_,-1,sizeof g_);
    for(i=0;i<m;i++)
    {
        cin>>g[i].x>>g[i].y>>g[i].val;
        g[i].pre=g_[g[i].x];
        g_[g[i].x]=i;
    }
    if(n==1){
        cout<<0<<endl;
        exit(0);
    }

    for(i=0;i<n;i++)
        dis[i]=inf,h[i]=true;
    memset(cnt,0,sizeof cnt);
    dis[r]=0,h[r]=false;
    q.push(r);

    negative=false;
    while(!q.empty())
    {
        p=q.front();q.pop();h[p]=true;
        cnt[p]++;
        if(cnt[p]>=n){
            negative=true;
            break;
        }
        j=g_[p];
        while(j!=-1)
        {
            p_=g[j].y;
            if(dis[p]+g[j].val<dis[p_])//当前一个节点被更新了，它以后还有可能更新别的节点，所以入队
            {
                dis[p_]=dis[p]+g[j].val;
                if(h[p_])
                {
                    q.push(p_);
                    h[p_]=false;
                }
            }
            j=g[j].pre;
        }
    }
    if(negative==true)
        cout<<"NEGATIVE CYCLE"<<endl;
    else{
        for(i=0;i<n;i++)
            if(dis[i]==inf)
                printf("INF\n");
            else
                printf("%d\n",dis[i]);
    }
    return 0;
}



Measured memory_bytes: 4084
/*THINK GONNA FAIL ? IF U DIDNT FAIL THEN WHAT IS THE POINT OF LEARNING */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define ran(v) v.begin(),v.end()
#define mod 1000000007
#define inf 1e15
#define ff first
#define ss second
// #define N --

using namespace std;

vector<list<int>> adjList;
vector<int> dp, vis;
int ans = INT_MIN;
int n, m;

void LongestPath(int node) {
	vis[node] = true;

	for (int child : adjList[node]) {
		if (!vis[child])
			LongestPath(child);
		dp[node] = max(dp[node], dp[child]);
	}

	dp[node]++;
	ans = max(ans, dp[node]);
}

int32_t main() {
	fast
	int t_c = 1;
//	cin >> t_c;
	while (t_c--) {
		cin >> n >> m;
		adjList.resize(n + 1), vis.resize(n + 1), dp.resize(n + 1);
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			adjList[a].pb(b);
		}
		for (int i = 1; i <= n; i++)
			if (!vis[i])
				LongestPath(i);
		cout << ans  - 1 << endl;
	}
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


int32_t main(){
  fastio;
  string s;
  cin >> s;
  int res=0;
  for(int i=0;i<3;i++){
    int cur = 0;
    for(int j=i;j<3;j++){
      if(s[j] == 'R')cur++;
      else break;
    }
    res = max(res,cur);
  }  
  cout << res << endl;

  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3652
#include<stdio.h>
main(void){
  
  int i,a,b,key,temp;
   
  scanf("%d %d",&a,&b);
  
  if(a<b){
    temp=b;
    b=a;
    a=temp;
  }

  while(b>0){
    temp=a%b;
    a=b;
    b=temp;
  }
  key=a;
  printf("%d\n",key);
  return 0;
}

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

int main() {
  int n, c, v;
  int arr_v[50] = {};
  int arr_c[50] = {};

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr_v[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> arr_c[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (arr_v[i] > arr_c[i]) {
      ans += arr_v[i] - arr_c[i];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define all(a) a.begin(),a.end()
using namespace std;

int warikan(ll x){
  ll count=0;
  while(true){
    if(x%2!=0) break;
    x=x/2;
    count++;
  }
  return count;
}

int main(){
  ll n,a,A=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    A+=warikan(a);
  }
  cout<<A<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    long long N;
    cin >> N;
    long long A[N];
    long long B[N];
    long long sums=0;

    for(int i=0;i<N;i++){
        cin >> A[i];
        if(i==0){
            B[i] = A[i];
        }
        else{
            B[i] = B[i-1] + A[i];
        }
        sums = sums + A[i];
    }

    long long mins = 0;
    long long diffs = abs(B[mins] - (sums - B[mins]));


    for(int i=1;i<N-1;i++){
        if(diffs > abs(B[i] - (sums - B[i]))){
            diffs = abs(B[i] - (sums - B[i]));
            mins = i;
        }
    }
    cout << abs(B[mins] - (sums - B[mins])) << endl;
    return 0;

}

Measured memory_bytes: 3328
while 1:
    hands = list(map(int, input().split()))
    if hands[0] == 0:
        break

    for i, hand in enumerate(hands):
        if hand > 10:
            hands[i] = 10

    if 1 in hands:
        cnt = hands.count(1)
        hands.sort(reverse=True)
        score = 0
        for hand in hands:
            if hand != 1:
                score += hand
            else:
                if score + cnt > 11:
                    score += 1
                    cnt -= 1
                else:
                    score += 11
                    cnt -= 1
    else:
        score = sum(hands)
    if score > 21:
        score = 0

    print(score)



Measured memory_bytes: 5596
N = gets.to_i
A = gets.split.map &:to_i
B = gets.split.map &:to_i
ans = 0
(0...N).each{ |i|
  b = B[i]
  x = [b, A[i]].min
  ans += x
  b -= x
  x = [b, A[i+1]].min
  ans += x
  A[i+1] -= x
}
p ans


Measured memory_bytes: 19468
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    long a[n+1];
    long b[n];
    for(int i = 0;i<n+1;i++) cin >> a[i];
    for(int i = 0;i<n;i++) cin >> b[i];
    long g=0;
    for(int i = 0;i<n;i++){
        if(b[i]>a[i]){
          g += a[i];
          b[i] -= a[i];
          a[i] = 0;
          int moto = a[i+1];
          a[i+1] -= b[i];
          if(a[i+1] <= 0) a[i+1] = 0;
          g += moto - a[i+1];
        }
        else{
          g+= b[i];
          b[i] = 0;
        }
    }
    cout<<g;
    return 0;
}

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

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a > k){
        cout << ":(" << endl;
    }
    else
    {
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <string>
#include <ios>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <iterator>
#define INFINIT_LL 0x7F00000000000000
#define LL long long
using namespace std;

int main() {
	string S;
	cin >> S;

	int K = 1;
	if (S.length() == 1) {
		cout << 1;
		return 0;
	}

	int next_idx = 1;
	string S_prev = S.substr(0,1);
	string S_next = S.substr(next_idx, 1);

	for (int i = 0; i < S.length();i++) {
		if (next_idx >= S.length())break;
		if (S_prev.compare(S_next)==0) {
			S_next = S_next + S.substr(++next_idx,1);
		}
		else {
			if (next_idx >= S.length())break;
			//cout << S_prev << "\n";
			int S_next_len = S_next.length();
			S_prev = S_next;
			S_next = S.substr(next_idx+ 1, 1);
			next_idx++;
			K++;
		}
	}

	cout << K;
	return 0;
}

Measured memory_bytes: 644