akhauriyash/Code-Regression huggingface dataset:
//from:https://atcoder.jp/contests/exawizards2019/submissions/4794708

#include<cstdint>
using namespace std;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

#define MOD 1000000007

int main()
{
//	using mint=modint<1000000007>;

	int n;
	string s;
	cin >> n >> s;

	if(s[0]=='W')
	{
		cout << 0 << endl;
		return 0;
	}

	long long left=1;			
	long long ans=1;	

	for(int i=1;i<2*n;i++)
	{
		int odd=(s[i]=='B' ? 1:0);
		if(left%2==odd)
		{
			ans*=left;
			ans%=MOD;
			left--;

			if(left<0)
			{
				cout << 0 << endl;
				return 0;
			}

		}
		else
		{
			left++;
		}
//		cout << i << " : " << s[i] << " : " << left << " : " << ans << endl;
	}

	if(left!=0)
	{
		cout << 0 << endl;
		return 0;
	}

	for(int i=1;i<=n;i++)
	{
		ans*=i;
		ans%=MOD;
	}


	cout << ans%MOD << endl;

}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a>c || a+b <c){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        }
    }
}

Measured memory_bytes: 21972
#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>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int ret=0;
    bool ok=false;
    rep(i,n){
        int x;
        cin>>x;
        ret^=x;
        if(x%2)ok=true;
    }
    if(ret==1)cout<<"Bob"<<endl;
    else if(ret==0&&!ok)cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
constexpr long MOD = 1e9 + 7;
using namespace std;

int main() {
    int n, k;
    double a = 0;
    cin >> n;
    vector<int> ks;
    REP(i,n) {
        cin >> k;
        ks.push_back(k);
        a += k;
    }
    
    int m = int(round(a / n));
    
    long cost = 0;
    REP(i,n) {
        cost += (ks[i] - m) * (ks[i] - m);
    }
    
    cout << cost << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <numeric>
using namespace std;


int main(void) {
    int n; cin >> n;
    vector<int> as;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        as.push_back(a);
    }

    sort(as.begin(), as.end());
    
    if (n % 2 == 0) {
        int uppermin = as[n / 2];
        int lowermax = as[n / 2 - 1];
        long long uppersum = 0;
        long long lowersum = 0;
        for (int i = 0; i < n / 2; i++) {
            uppersum += as[n / 2 + i];
            lowersum += as[i];
        }
        cout << 2 * uppersum - uppermin - 2 * lowersum + lowermax << endl; 
    }
    else {
        long long res;
        long long uppersum = 0;
        long long lowersum = 0;
        for  (int i = 0; i < n / 2; i++) {
            uppersum += as[n / 2 + i];
            lowersum += as[i];
        }
        uppersum += as[n - 1];
        
        //cout << uppersum << endl;
        //cout << lowersum << endl;

        res = 2 * uppersum - 2 * lowersum - as[n / 2] - as[n / 2 + 1];

        uppersum -= as[n / 2];
        lowersum += as[n / 2];

        //cout << uppersum << endl;
        //cout << lowersum << endl;

        res = max(res, 2 * uppersum - 2 * lowersum + as[n / 2] + as[n / 2 - 1]);
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

void cmax(ll& lhs,ll rhs){
    lhs=max(lhs,rhs);
}
int main(){
    int n;
    cin>>n;
    int t;
    cin>>t;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];

    vector<int> ids(n);
    iota(ids.begin(),ids.end(),0);
    sort(ids.begin(),ids.end(),[&](int lhs,int rhs){return a[lhs]<a[rhs];});
    vector<vector<ll>> dp(n+1,vector<ll>(t+1));

    for(int i=0;i<n;i++){
        int x=ids[i];
        for(int j=0;j<t;j++){
            cmax(dp[i+1][j],dp[i][j]);
            cmax(dp[i+1][min(ll(t),j+a[x])],dp[i][j]+b[x]);
        }
        cmax(dp[i+1][t],dp[i][t]);
    }

    ll res=*max_element(dp[n].begin(),dp[n].end());
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

vector<P> v[100001];
P g[100001];
ll dp[101][8];

int main() {
	ll n,k;
	cin>>n>>k;
	ll v=n/k,c=n/k;
	if(k%2==0&&n%k>=k/2)c++;
	if(k%2==1)c=0;
	cout<<v*v*v+c*c*c<<endl;
	return 0;
}


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

int main(){
  int x;
  cin >> x;
  int ans = 0;
  for(int i=1;i*(i+1)/2<=x;i++){
    ans = i;
  }
  if(ans*(ans+1)/2 == x) cout << ans << endl;
  else cout << ans+1 << endl;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int A,B,C,X;cin>>A>>B>>C>>X;
  int ans=0;
  REP(i,A+1) {
    if (500*i>X) continue;
    REP(j,B+1) {
      if (100*j+500*i>X) continue;
      if (100*j+500*i>=X-C*50) ans++;
    }
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    n, m = map(int, rl().split())
    ans = n * (n - 1) // 2 + m * (m - 1) // 2
    print(ans)

    
if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x:x[1])

time = 0

for a,b in AB:
    time += a
    if time <= b:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 55260
N, K = gets.split(/\s+/).map(&:to_i)
numerator = 0.0
kakeru = 1
waru   = 1.0
N.downto(1){|dice|
	until K <= dice * kakeru
		kakeru *= 2
		waru   /= 2.0
	end
	numerator += waru
}
p(numerator / N)


Measured memory_bytes: 1916
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, dist[200001], a, b, c;
vector<pi> e[200010], em;
bool vis[200001];
unordered_set<int> inr[200010], m;

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		memset(vis, false, sizeof(vis));
		memset(dist, 63, sizeof(dist));
		Forn(i, 200005)
			e[i]=em, inr[i]=m;
		while(M--)
		{
			a=in(), b=in(), c=in();
			e[a].eb(mp(b, c));
			e[b].eb(mp(a, c));
		}
		priority_queue<pi> q;
		dist[1]=0;
		vis[1]=true;
		q.push(mp(0, 1));
		while(!q.empty())
		{
			int st=q.top().s, cost=-q.top().f;
			q.pop();
			vis[st]=true;
			if(cost>dist[st])
				continue;
			foreach(it, e[st])
			{
				int ed=it->f, c=it->s, d=dist[st]+(!inr[st].count(c));
				if(vis[ed]||dist[ed]<d)
					continue;
				if(dist[ed]>d)
				{
					dist[ed]=d;
					q.push(mp(-d, ed));
					inr[ed].clear();
				}
				inr[ed].insert(c);
			}
		}
		if(dist[N]>INF)
			puts("-1");
		else
			printf("%d\n", dist[N]);
	}
	return 0;
}

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

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

const long long MOD = 1000000007;


int main(){
  int n;
  bool ans=true;
  cin >> n;
  vector<int> h(n);
  rep(i,n)  cin >> h.at(i);
  
  for(int i=n-1;i>0;i--){
    if(h.at(i-1)-1>h.at(i)) ans=false;
    else if(h.at(i-1)-1==h.at(i)) h.at(i-1) -=1;
  }
    
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 640
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

const int mod = 1e9 + 7;

long long pow(long long a, long long b, long long mod){
	a %= mod;
	long long res = 1;
	while(b){
		if(b & 1){res *= a;res %= mod;}
		b >>= 1;
		a = a * a % mod;
	}
	return res % mod;
}

int phi(int n) {
    int result = n;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}
int main(){
	FIO
	
	int n;
	cin >> n;
	cout << (long long)phi(n) << '\n';
	return 0;
}



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

int main(){
    int n;  cin >> n;
    vector<string>s(n);
    vector<vector<int> >dic(n, vector<int>(26));    //文字列のそれぞれの小文字の数
    rep(i, n){
	cin >> s[i];
	rep(j, s[i].size()){
	    dic[i][s[i][j]-'a']++;
	}
    }
    rep(i, 26){
	int count=50;	//小文字の最大の数
	rep(j, n){
	    count=min(count, dic[j][i]);
	}
	rep(j, count)	printf("%c", (char)('a'+i));
    }
    printf("\n");
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

if __name__ == '__main__':
    # n = 100
    # n = 9995
    # n = 3141592653589793
    n = input()

    ary = list(map(int, list(str(n))))

    # ひと桁のときの対応
    if len(ary) == 1:
       print(sum(ary))
       sys.exit()

    # ふた桁のときの対応
    if len(ary) == 2:
        if sum(ary) <= 9:
            print(9)
            sys.exit()
        else:
            print(sum(ary))
            sys.exit()

    # すでに9が並んでたら上位を減らさない
    if ary[1:-1].count(9) != len(ary[1:-1]):
        ary[0] = ary[0] - 1
        ary[-2] = 9
        ary[-1] = 9

    # 真ん中はすべて9にする
    ary[1:-1] = [9 for i in range(0, len(ary[1:-1]))]

    # 下位が99 or 98でなかったら下位を89にする
    if sum(ary[-2:]) < 18:
        ary[-2] = 8
        ary[-1] = 9

    # print(ary)
    print(sum(ary))


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();
            int n = s.Length;
            var lr = new bool[n];
            bool before = false;
            var lrt = new List<int[]>();
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'R')
                {
                    lr[i] = true;
                }
                if (before)
                {
                    if (lr[i])
                    {
                        lrt.Last()[0]++;
                    }
                    else
                    {
                        lrt.Last()[1] = 1;
                    }
                }
                else
                {
                    if (lr[i])
                    {
                        lrt.Add(new int[2] { 1, 0 });
                    }
                    else
                    {
                        lrt.Last()[1]++;
                    }
                }
                before = lr[i];
            }
            int i0 = 0;
            int[] output = new int[n];
            foreach (int[] t in lrt)
            {
                i0 += t[0] - 1;
                output[i0] += (t[0] + 1) / 2 + t[1] / 2;
                output[i0 + 1] += t[0] / 2 + (t[1] + 1) / 2;
                i0 += t[1] + 1;
            }
            Console.WriteLine(string.Join(" ", output));


#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 24924
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main() {
    int a,b;

    cin >> a >> b;

    int val = stoi(to_string(a) + to_string(b));
    if(fmod(sqrt((float)val), 1) == 0) cout << "Yes" <<endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[26],b[26];	
signed main(){
	ic(n)
	sc(s)
	int ans=0;
	rep(1,i,n){
		int cnt=0;
		for(char c='a';c<='z';c++){
			bool hidari=false,migi=false;
			rep(0,j,i)if(s[j]==c)hidari=true;
			rep(i,j,n)if(s[j]==c)migi=true;
			if(hidari==true&&migi==true){
				cnt++;
			}
		}
		if(cnt>ans)ans=cnt;
	}
	c(ans)
}	
			

Measured memory_bytes: 256
#!/usr/bin/env python3

n_list = []
m_list = []
a_list = []

while True:
    n, m = list(map(int, input().split(' ')))

    if n == 0 and m == 0:
        break

    a = list(map(int, input().split(' ')))

    n_list.append(n)
    m_list.append(m)
    a_list.append(a)


for n, m, a in zip(n_list, m_list, a_list):
    m_sum = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            tmp = a[i] + a[j]
            if m_sum < tmp and tmp <= m:
                m_sum = tmp

    if m_sum > 0:
        print(m_sum)
    else:
        print('NONE')



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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll H, W;

int main() {
   cin >> H >> W;

   ll ans = 1e18;
   if (H % 3 == 0 || W % 3 == 0) {
      ans = 0;
   } else {
      ans = min(ans, (H/3+1)*W - H/3*W);
      swap(H, W);
      ans = min(ans, (H/3+1)*W - H/3*W);
      swap(H, W);
   }

   // if (H % 3 == 0 || W % 3 == 0) ans = 0;
   // ll d = abs(H/3 * W - (H/3+1) * W);
   // swap(H, W);
   // ll e = abs(H/3 * W - (H/3+1) * W);
   // swap(H, W);
   // ans = min({ans, e, d});

   for (int k = 0; k < 2; k++) {
      for (int h1 = 1; h1 < H; h1++) {
         int h2 = H - h1;
         ll a = h1 * W;
         ll b = h2 * (W/2);
         ll c = h2 * ((W+1)/2);
         ans = min(ans, max({a, b, c}) - min({a, b, c}));
      }
      swap(H, W);
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;
int id, comp_count;
vector<vector<int>> g(1e5 + 5);
vector<int> vis(1e5 + 5);
vector<int> component_id(1e5 + 5);
vector<int> c_size(1e5 + 5);
void dfs(int u){
    vis[u] = true;
    component_id[u] = id;
    //c_size[id]++;
    comp_count++;
    for(int b : g[u]){
        if(!vis[b])
            dfs(b);
    }
}

int main(){
    Shazam;
    int n, m, k; cin>>n>>m>>k;
    for(int i = 0 ; i < m; i++){
        int a, b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    id = 1;
    for(int i = 1; i <=n; i++ ){
       if(!vis[i]){ 
        comp_count = 0;
        dfs(i);
        c_size[id++] = comp_count;
       }
    }
    vector<int> ans(n+1,-1);
    for(int i = 0; i < k; i++){
        int a,b; cin>>a>>b;
        if(component_id[a]==component_id[b])
            ans[a]--, ans[b]--;
    }
    for(int i = 1; i < n+1; i++){
        cout<<c_size[component_id[i]] + ans[i] - g[i].size()<<" ";
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 10704
#include <stdio.h>

int main(void){
int N,A,B;
  
  scanf("%d %d %d",&N,&A,&B);
  A = N*A;
    if(A>=B){
   		 printf("%d",B);
    }else{
   		 printf("%d",A);
    }
  
  return(0);
  
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  int t[101];
  int p, x;
  int ans = 0;

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

  cin >> m;
  
  for(int i = 0;i < m;i++){
    cin >> p >> x;
    cout << ans + (x - t[p - 1]) << endl;
  }
  return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;
    cin >> n;
    vector<P> reds(n);
    vector<P> blues(n);

    rep(i, n) {
        int a, b;
        cin >> a >> b;
        P p(a, b);
        reds[i] = p;
    }

    rep(i, n) {
        int a, b;
        cin >> a >> b;
        P p(a, b);
        blues[i] = p;
    }

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

    sort(reds.begin(), reds.end(), [](P i, P j) {
        return i.second > j.second;
    });
    set<int> red_used;
    int ans = 0;
    for (P blue : blues) {
        for (int i = 0; i < n; i++) {
            P red = reds[i];
            if (blue.first <= red.first || blue.second <= red.second) continue;
            if (red_used.find(i) != red_used.end()) continue;
            red_used.insert(i);
            ans++;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 0;
	auto tmp = n;

	while (tmp > 5) {
		ans += tmp / 5 / 2;
		tmp /= 5;
	}

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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

typedef long long ll;

const int N_MAX = 100000;

int N;
int l[N_MAX];
int r[N_MAX];
int w[N_MAX];

multiset<ll> ls, rs;
ll lf, rf;
ll ans;

void dumpDP(int i) {
  printf("i: %d\n", i);
  printf("  ls: {"); ITR(ls, it) if (*it + lf >= 0) printf("%lld, ", *it + lf); printf("}\n");
  printf("  rs: {"); ITR(rs, it) if (*it + rf <= 1e9)printf("%lld, ", *it + rf); printf("}\n");
}

void erase_one(multiset<ll> &st, ll v) {
  auto it = st.find(v);
  if (it != st.end()) st.erase(it);
}

void solve() {
  REP(i, N) w[i] = r[i] - l[i];
  ls.insert(l[0]); rs.insert(l[0]);
  ans = 0;
  lf = rf = 0;
  FOR(i, 1, N - 1) {
    // dumpDP(i);
    lf -= w[i]; rf += w[i - 1];
    ll le = *ls.rbegin() + lf;
    ll re = *rs.begin() + rf;
    ll l3 = l[i];
    // printf("  e: (%lld, %lld), l3: %lld\n", le, re, l3);
    if (l3 > re) {
      erase_one(rs, re - rf);
      ls.insert(re - lf);
      rs.insert(l3 - rf);
      rs.insert(l3 - rf);
      ans += l3 - re;
      // printf("  rs->ls: %lld, rs << %lld, ans += %lld\n", re, l3, l3 - re);
    } else if (l3 < le) {
      erase_one(ls, le - lf);
      rs.insert(le - rf);
      ls.insert(l3 - lf);
      ls.insert(l3 - lf);
      ans += le - l3;
      // printf("  ls->rs: %lld, ls << %lld, ans += %lld\n", le, l3, le - l3);
    } else {
      ls.insert(l3 - lf);
      rs.insert(l3 - rf);
      // printf("  ls << %lld rs << %lld, ans += 0\n", l3, l3);
    }
  }

  // dumpDP(N);

  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) {
    scanf("%d%d", l + i, r + i);
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 10752
#include <stdio.h>
int main(void){
    int a,b,c;
    int ans = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i=a; i<=b; i++)
    {
        //printf("%d\n",i);
        if(c % i == 0)
        {
            ans++;
        }
    }
    
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 2148
#include<stdio.h>
int main(void)
{
    int k,s,x,y,z,count = 0;
    scanf("%d %d",&k,&s);
    for(x = 0 ; x <= k ; x++)
    {
        for(y = 0 ; y <= k ; y++)
        {
            if(s - x - y >= 0 && s - x - y <= k)
            {
                count++;
            }
        }
    }
    printf("%d\n",count);
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    string s=to_string(n);
    int dig=(int)s.size();
    int ans=0;
    rep(i,dig-1){
        if(i%2==0){
            if(i==0)ans+=9;
            else ans+=pow(10,i+1)-pow(10,i);
        }
    }
    if(dig%2==1)ans+=n-pow(10,dig-1)+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int q[8][8];

int main() {
    int k;
    cin >> k;
    for (int i = 0, r, c; i < k; i++) {
        cin >> r >> c;
        q[r][c] = 1;
        for (int j = r + 1, k = c + 1; j < 8 && k < 8; j++, k++) q[j][k] = -1;
        for (int j = r + 1, k = c - 1; j < 8 && k >= 0; j++, k--) q[j][k] = -1;
        for (int j = r - 1, k = c + 1; j >= 0 && k < 8; j--, k++) q[j][k] = -1;
        for (int j = r - 1, k = c - 1; j >= 0 && k >= 0; j--, k--) q[j][k] = -1;
        for (int j = 0; j < 8; j++) {
            if (j == r) continue;
            q[j][c] = -1;
        }
        for (int k = 0; k < 8; k++) {
            if (k == c) continue;
            q[r][k] = -1;
        }
    }
    int p[8];
    for (int i = 0; i < 8; i++) p[i] = i;
    do {
        int qt[8][8] = {};
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                qt[i][j] = q[i][j];
            }
        }
        bool flag = true;
        for (int i = 0; i < 8; i++) {
            if (qt[i][p[i]] == 1) continue;
            if (qt[i][p[i]] == -1) {
                flag = false;
                break;
            }
            qt[i][p[i]] = 1;
            for (int j = i + 1, k = p[i] + 1; j < 8 && k < 8; j++, k++) {
                if (qt[j][k] == 1) {
                    flag = false;
                    break;
                }
                qt[j][k] = -1;
            }
            for (int j = i + 1, k = p[i] - 1; j < 8 && k >= 0; j++, k--) {
                if (qt[j][k] == 1) {
                    flag = false;
                    break;
                }
                qt[j][k] = -1;
            }
            for (int j = i - 1, k = p[i] + 1; j >= 0 && k < 8; j--, k++) {
                if (qt[j][k] == 1) {
                    flag = false;
                    break;
                }
                qt[j][k] = -1;
            }
            for (int j = i - 1, k = p[i] - 1; j >= 0 && k >= 0; j--, k--) {
                if (qt[j][k] == 1) {
                    flag = false;
                    break;
                }
                qt[j][k] = -1;
            }
        }
        if (flag) {
            for (int i = 0; i < 8; i++) {
                for (int j = 0; j < 8; j++) {
                    if (qt[i][j] == 1) cout << 'Q';
                    else cout << '.';
                }
                cout << endl;
            }
            break;
        }
    } while (next_permutation(p, p+8));
}


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

ab.sort(key=lambda x: x[1])

ans=True
now=0
for i in range(n):
    now+=ab[i][0]
    if now>ab[i][1]:
        ans=False
        break

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 53728
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int D = ReadInt();
    Console.Write("Christmas");
    for (int i = 0; i < 25-D; i++) {
      Console.Write(" Eve");
    }
    Console.WriteLine();
  }

  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++) cin >> a[i];

	bool check = true;
	int count = 0;

	while(check) {
		for(int i=0;i<n;i++) {
			if(a[i]%2 != 0) check = false;
		}
		if(check == true) {
			count++;
			for(int i=0;i<n;i++) a[i] /= 2;
		}
	}

	cout << count << endl;

}


Measured memory_bytes: 256
n, a, b = gets.strip.split.map(&:to_i)

# 各桁の和を求める
def digit_sum n
  sum = 0
  while n > 0 do
    sum += n % 10
    n /= 10
  end
  sum
end

sum =0
for i in 1..n
  if digit_sum(i) >= a && digit_sum(i) <= b
    sum += i
  end
end

puts "#{sum}"


Measured memory_bytes: 1788
def recur(heights):
    global ans
    if heights == [0]:
        return 1
    ans += 1
    new_heights = []
    for h in heights:
        new_heights.append(h - 1)
    for splitted_new_heights in split_heights(new_heights):
        recur(splitted_new_heights)


def split_heights(heights):
    splitted_heights = []
    partial_heights = []
    for h in heights:
        if h == 0 and len(partial_heights) > 0:
            splitted_heights.append(partial_heights)
            partial_heights = []
        elif h != 0:
            partial_heights.append(h)
    if len(partial_heights) > 0:
        splitted_heights.append(partial_heights)
    return splitted_heights


def main():
    global ans
    ans = 0
    N = int(input())
    h = list(map(int, input().split()))
    for splitted_heights in split_heights(h):
        recur(splitted_heights)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68436
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,m,i,j,k,t1,t2,t3,t4,ans;
int a[66],b[66];
int main(){
	scanf("%lld%lld",&n,&m);
	if (n==m){
		puts("1");return 0;
	}
	memset(a,0,sizeof(a));memset(b,0,sizeof(b));
	for (a[0]=0,i=n;i;i>>=1) a[++a[0]]=(i&1);
	for (b[0]=0,i=m;i;i>>=1) b[++b[0]]=(i&1);
	for (k=b[0];a[k]==b[k];k--);
	for (j=k-1;j&&!b[j];j--);
	t1=n&((1LL<<k)-1);t2=(1LL<<(k-1))+(1LL<<j)-1;
	t3=(1LL<<(k-1))+(t1);t4=(1LL<<k)-1;
	if (t3<=t2) ans=t4-t1+1;else ans=t2-t1+1+t4-t3+1;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int N, M;

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

    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}

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

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

	for (int i = 1;i < N; i++) {
		int v = A[i];
		int j = i - 1;

		for (int k = 0;k < N - 1;k++) cout << A[k] << " ";
		cout << A[N - 1];
		cout << endl;

		while (j >= 0 && A[j] > v)
			{
				A[j + 1] = A[j];
				j--;
			}
		A[j + 1] = v;
		
	}
	for (int k = 0;k < N - 1;k++) cout << A[k] << " ";
	cout << A[N - 1];
	cout << endl;

    return 0;
}

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

int main()
{
    int d[5], t = 0;
    vector<pair<int, int>> e;
    for (int i = 0; i < 5; i++)
    {
        cin >> d[i];
        if (d[i] % 10 == 0)
            t += d[i];
        else
            e.push_back({d[i] % 10, d[i]});
    }
    sort(e.begin(), e.end());
    for (int i = 0; i < e.size(); i++)
    {
        if (!i)
            t += e.at(i).second;
        else
            t += (e.at(i).second / 10 + 1) * 10;
    }
    cout << t << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define P pair<int, int>;
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main()
{
	ll n;
	map<string, ll> M;
	ll ans = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		string s;
		cin >> s;
		sort(all(s));
		ans += M[s];
		M[s]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=b;i<=c;i++){
		if(i%a==0){
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG"; 
return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
int N;
int ans=0;

void f(long long n, int x , int y , int z){
  if(n>N) return;

  if(x==1 && y==1 && z==1) ans++;

  f(10*n+3,1,y,z);
  f(10*n+5,x,1,z);
  f(10*n+7,x,y,1);
  return ;
}
int main(){
  cin >>N;
  f(0,0,0,0);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vl x(m), y(m);
    for (int i = 0; i < m; ++i) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }
    vector<bool> pos(n, false);
    vector<int> balls(n, 1);
    pos[0] = true;
    for (int i = 0; i < m; ++i) {
        balls[x[i]]--;
        balls[y[i]]++;
        if (pos[x[i]]) {
            pos[y[i]] = true;
            if (balls[x[i]] == 0)
                pos[x[i]] = false;
        }
    }
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        if (pos[i])
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[10000000], d[10000000];
int main() {
    
    ll i,j,k, l, test, n, m, x;
    cin>>n>>x;
    for(i=0;i<n;i++) cin>>a[i];
    //ll d=0;
    i=1;
    ll count=1;
    ll sum=0;
    for(i=0;i<n;i++) {
        sum+=a[i];
        if(sum<=x) count++;
    }
    cout<<count;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int n,m,ans,indeg[100001],dp[100001];
vector<vector<int>> graph;

int main(){
	cin >> n >> m;
	graph.resize(n+1);
	for(int i = 0 ; i < m ; i += 1){
		int a,b;
		cin >> a >> b;
		graph[a].push_back(b);
		indeg[b] += 1;
	}
	queue<int> q;
	for(int i = 1 ; i <= n ; i += 1){
		if(indeg[i] == 0){
			q.push(i);
		}
	}
	vector<int> order;
	while(q.size()){
		int a = q.front();
		q.pop();
		order.push_back(a);
		for(int i : graph[a]){
			indeg[i] -= 1;
			if(indeg[i] == 0){
				q.push(i);
			}
		}
	}
	for(int i : order){
		for(int j : graph[i]){
			dp[j] = max(dp[j],dp[i]+1);
			ans = max(ans,dp[j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7032
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
typedef long long ll;
using namespace std;

int main(void) {
  long double a, b, c, d=0.000000000000001;
  cin >> a >> b >> c;
  if (sqrt(a)+sqrt(b)+d<sqrt(c)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[1001];
void factorial(int n){
    fact[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD;
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=fact[r]*fact[n-r]%MOD;
        return fact[n]*fermat_inv(x)%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(1000);
    while(t--){
        int n;
        string s;
        cin>>n>>s;
        int l=n,ans=0;
        for(int i=n-1;i>=0;i--){
            if(s[i]=='W')
                l=i;
        }
        for(int i=n-1;i>l;i--){
            if(s[i]=='R'){
                ans++;
                while(l<n&&s[++l]!='W');
            }
        }
        cout<<ans;
    }
}

Measured memory_bytes: 3740
// Aizu 0358: Shopping
// 2017.9.19 bal4u@uu
#include <stdio.h>

int main()
{
	int m, f, b;
	scanf("%d%d%d", &m, &f, &b);
	if (b > m + f) puts("NA");
	else if (m >= b) puts("0");
	else printf("%d\n", b - m);
	return 0;
}

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

//素数判定
#include <stdbool.h>
#include <math.h>

bool IsPrimeNumber(long n)
{
    if (n <= 3)
        return true;
    if (n % 2 == 0)
        return false;

    int r = (long)sqrt((double)n);

    for (int i = 3; i <= r; i += 2)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main()
{
    ll x;
    cin >> x;
    while (true)
    {
        if (IsPrimeNumber(x))
            break;
        else
            x++;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vector<ll> sum;
void pre_process(vector<ll> &a, vector<ll> &s) {  //累積和のvector
    ll n = (ll)a.size();
    s.assign(n + 1, 0);
    for (ll i = 0; i < n; i++) {
        s[i + 1] = (s[i] + a[i]) % mod;
        s[i + 1] %= mod;
    }
}
ll query(ll i, ll j, vector<ll> &s) {  //区間[i,j]の和
    return (s[j] - s[i]);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll suma = 0;
    pre_process(a, sum);
    rep(i, n - 1) {
        suma += ((a[i] * (sum[n] - sum[i + 1])) % mod);
        suma %= mod;
    }

    /*ll sumb = 0;
    rep(i, n - 1) {
        for (ll j = i + 1; j < n; j++) sumb += a[i] * a[j];
    }
    cout << sumb << endl;*/

    cout << (suma + mod) % mod << "\n";
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  sort(x.begin(),x.end());
  vector<int> ST(x[n-1]-x[0]+1);
  for(int i=x[0];i<=x[n-1];i++){
    for(int k=0;k<n;k++){
      ST[i-x[0]]+=pow((i-x[k]),2);
    }
  }
  sort(ST.begin(),ST.end());
  cout << ST[0] << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Pair<F, S>{
	F first;
	S second;
	public Pair(F f, S s) {
		first = f;
		second = s;
	}
}

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Pair<Integer, Integer>[] nums = new Pair[N + M];
		for(int i = 0; i < N; i++) {
			nums[i] = new Pair<Integer, Integer>(sc.nextInt(), 1);
		}
		for(int i = 0; i < M; i++) {
			int B = sc.nextInt();
			int C = sc.nextInt();
			nums[N + i] = new Pair<Integer, Integer>(C, B);
		}
		Arrays.sort(nums, new Comparator<Pair<Integer, Integer>>(){
			public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
				return o2.first - o1.first;
			}
		});
		long ans = 0;
		int cardnum = 0;
		for(int i = 0; i < nums.length; i++) {
			int add_card_num = Math.min(nums[i].second, N - cardnum);
			cardnum += add_card_num;
			ans += (long)add_card_num * (long)nums[i].first;
			if(cardnum == N) break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 104724
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  int64 ret = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ret += x - 1;
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 256