akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1007][1007],t[1007],p[1007];
queue<int>q[2];
int main(){
cin>>n;
for(int i=1;i<=n;++i)
for(int j=1;j<n;++j)
cin>>a[i][j];
for(int i=1;i<=n;++i)
q[0].push(i);
int now=1;
for(int day=1,tot=n*(n-1)/2;day<=n*(n-1)/2;++day){
now^=1;
while(!q[now].empty()){
int x=q[now].front();
q[now].pop();
int y=a[x][++t[x]];
if(p[y]==x){
tot--;
q[1-now].push(x);
q[1-now].push(y);
p[x]=p[y]=0;
}
else
p[x]=y;
}
if(!tot){
cout<<day<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}

Measured memory_bytes: 4224
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#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>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 2e5 + 10;

LL dp[110][N];
LL a[N], pr[N];
int n, k;


int main()
{
	
	scanf("%d%d", &n, &k);

	for (int i = 1;i <= n;i++)
		cin >> a[i];

	for (int i = 1;i <= n;i++)
		pr[i] = pr[i - 1] + a[i];
	
	for (int i = 0;i <= k;i++)
		dp[0][i] = 1;

	for (int i = 1;i <= n;i++) {
		for (int j = 0;j <= k;j++)
			dp[i][j] = (dp[i - 1][j] - (a[i] >= j ? 0 : dp[i - 1][j - a[i] - 1]) + MOD) % MOD;

		for (int j = 1;j <= k;j++)
			dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
	}

	printf("%lld\n", (dp[n][k] - dp[n][k - 1] % MOD + MOD) % MOD);
	cin >> n;
}

Measured memory_bytes: 82372
N,K = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ]  for i in range(N) ]

lix = [0]*N
liy = [0]*N
for i in range(N):
  x,y = li[i]
  lix[i] = [x,i,0]
  liy[i] = [y,i,0]
lix.sort( key = lambda x:x[0] )
liy.sort( key = lambda x:x[0] )
for i in range(N):
  lix[i][2]=i
  liy[i][2]=i
lix.sort( key = lambda x:x[1] )
liy.sort( key = lambda x:x[1] )

lim = [ [0]*(N+1) for i in range(N+1) ]
for i in range(N):
  lim[ 1+lix[i][2] ][ 1+liy[i][2] ] = 1
for i in range(1,N+1):
  for j in range(1,N+1):
    lim[i][j]+=lim[i-1][j]+lim[i][j-1]-lim[i-1][j-1]

lix.sort( key = lambda x:x[2] )
liy.sort( key = lambda x:x[2] )

ma = 1000000000000000000000000000000000000000
for xi in range(N):
  for xj in range(xi+1,N+1):
    for yi in range(N):
      for yj in range(yi+1,N+1):
        if ( lim[xj][yj] - lim[xj][yi] - lim[xi][yj] + lim[xi][yi]  >= K ):
          s = (lix[xj-1][0]-lix[xi][0])*(liy[yj-1][0]-liy[yi][0])
          ma = min(s,ma)
print ( ma )


Measured memory_bytes: 44268
import numpy as np
import sys
sys.setrecursionlimit(10**5+1)
input = sys.stdin.readline

def dfs(v,G,visit):
    visit[v-1]=1    
    for next in G[v-1]:        
        if visit[next-1]:
            continue
        _ = dfs(next,G,visit) 
 
N, M =map(int, input().split())
G  = [[] for _ in range(N)]
for i in range(M):
    a,b ,_= map(int, input().split())
    G[a-1].append(b)
    G[b-1].append(a)
 
count = 0

visit = np.array([0]*N)
for i in range(1,N+1):
  if visit[i-1]:
    continue
  if G[i-1]:  
    _ = dfs(i,G,visit)
  else:
    visit[i-1] = 1
  count += 1

print(count)

Measured memory_bytes: 119124
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<1010;i++)
	{
		if((a*i)%b==c) {printf("YES");return 0;}
	}
	printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  int a;
  vector<int> t(N);
  for(int i=0;i<2*M;i++){
    cin>>a;
    for(int j=0;j<N;j++){
      if(j+1==a){
        t.at(j)++;
        break;
      }
    }
  }
  for(int i=0;i<N;i++)cout<<t.at(i)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

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

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll k,n;
    cin>>k>>n;
    ll arr[n];
    rep(i,0,n)cin>>arr[i];
    sort(arr,arr+n);
    ll temp=0;
    rep(i,0,n-1){
    	temp=max(temp,arr[i+1]-arr[i]);
    }
    temp=max(temp,k-arr[n-1]+arr[0]);
    cout<<k-temp<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, k, c;
    string s;

    cin >> n >> k >> c >> s;

    deque<int> l, r;

    ll count = 1;

    for (ll i = 0; i < n; i++)
    {
        if (s[i] == 'o')
        {
            l.push_back(i);
            count++;

            if (count > k)
            {
                break;
            }

            i += c;
        }
    }

    count = 1;

    for (ll i = n - 1; i >= 0; i--)
    {
        if (s[i] == 'o')
        {
            r.push_front(i);
            count++;

            if (count > k)
            {
                break;
            }

            i -= c;
        }
    }

    count = 1;

    for (int i = 0; i < k; i++)
    {

        if (l[i] == r[i])
        {
            cout << l[i] + 1 << endl;
        }
    }
}

Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
long inf = 1000000007;

int main() {
    int n; cin >> n;
    long pow = 1;
    for (int i = 1; i <= n; i++) {
        pow *= i;
        pow %= inf;

    }
   

    cout << pow << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll zero = 0;
ll INF = 10000000000;

int main(){
    ll N;
    cin >> N;
    ll four,odd;
    four = 0;
    odd = 0;
    ll tmp;
    for(ll i = 0; i < N ; i++){
        cin >> tmp;
        if(tmp % 4 == 0){
            four++;
        }
        else if(tmp % 2 == 1){
            odd++;
        }
    }
    bool ans = false;
    if(four >= N/2){
        ans = true;
    }
    else if(four >= odd){
        ans = true;
    }
    if(ans){
        printf("Yes");
    }
    else{
        printf("No");
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=2005,INF=1<<29;

struct BIT{
    vector<int> bit;
    int N;
    //1-indexed
    
    void init(int n_){
        N=n_;
        n_*=2;
        for(int i=30;i>=0;i--){
            if(n_&(1<<i)){
                n_=1<<i;
                n_++;
                break;
            }
        }
        bit.assign(n_,0);
    }
    
    int sum(int i){
        int s=0;
        while(i>0){
            s+=bit[i];
            i-=i&-i;
        }
        return s;
    }
    
    //sからtの和=sum(t)-sum(s-1)
    
    void add(int i,int x){
        while(i<=N){
            bit[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Q;cin>>N>>Q;
    BIT bi;
    bi.init(N);
    
    while(Q--){
        int a,b,c;cin>>a>>b>>c;
        if(a==0){
            bi.add(b,c);
        }else{
            cout<<bi.sum(c)-bi.sum(b-1)<<"\n";
        }
    }
}



Measured memory_bytes: 3328
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */
  

const ll MOD = 1e9 + 7;

vector<ll> sumup(const vector<ll>& a) {
  int N = a.size();
  vector<ll> res(N + 1, 0);
  for (int i = 0; i < N; i++) res[i + 1] = (res[i] + a[i]) % MOD;
  return res;
}

int main() {
  int N;
  string s;
  while (cin >> N >> s) {
    s = "<" + s;
    vector<ll> dp(N + 1, 0);
    dp[N] = 1;
    for (int i = 0; i < N; i++) {
      auto sum = sumup(dp);
      vector<ll> ndp(N + 1, 0);
      int rem = N - i;
      for (int r = 0; r < rem; r++) {
        if (s[i] == '<') {
          ndp[r] = (sum[rem + 1] - sum[r + 1] + MOD) % MOD;
        } else {
          ndp[r] = sum[r + 1];
        }
      }
      dp = ndp;
    }
    cout << dp[0] << endl;
  }
  return 0;
}


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

int main () {
  string s, t;
  cin >> s >> t;
  int ans = 1000000;
  int counter = 0;
  for (int i = 0; i < (s.size() - t.size() + 1); i++)  {
    rep(j, t.size()) {
      if (s.at(i+j) == t.at(j)) {
        counter++;
      }
    }
    int replace_number = t.size() - counter;
    ans = min (replace_number, ans);
    counter = 0;
  }
  cout << ans << endl;
  return 0;
}

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

int n;
int f[1111111];

int main(){
    ios_base::sync_with_stdio(false);

    cin >> n;

    int cnt = 1;
    while(f[n] == 0){
        
        f[n] = 1;

        if(n % 2 == 0){
            n /= 2;
        } else {
            n = 3 * n + 1;
        }

        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
// abc131c.cpp : Anti-Division
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  ll A,B,C,D; cin>>A>>B>>C>>D;
  ll E = C/__gcd(C, D)*D;
	ll n = B-A+1;
	ll c = (B/C-(A-1)/C) + (B/D-(A-1)/D) - (B/E-(A-1)/E);
	cout<< n-c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int ary(int x, int n){
	if(n == 1)return -1;
	if(x == 0)return 0;
	return ary(x/n, n)+x%n;
}

int Root(int n){
	int root = 1;
	rrep(i,n){
		if(i*i > n)break;
		root = i;
	}
	return root;
}


int n, s;
int solve1(){
	int root = Root(n);
	rrep(i,root){
		if(ary(n, i) == s)return i;
	}
	return -1;
}

int solve2(){
	int root = Root(n), ans = INF;
	rrep(i,root){
		int b = (n-s)/i+1, p = i, q = n-p*b;
		if(b <= 1 or q < 0 or q >= b or i >= b)continue;
		if(p*b+q == n and p+q == s)chmin(ans, b);
	}
	return ans == INF ? -1 : ans;
}

signed main(){
	scanf("%lld%lld", &n, &s);
	if(n == s){
		printf("%lld\n", n+1);
		return 0;
	}
	if(n == 1 or n < s){
		printf("-1\n");
		return 0;
	}
	
	int tmp = solve1();
	if(tmp != -1){
		printf("%lld\n", tmp);
		return 0;
	}
	tmp = solve2();
	if(tmp != -1){
		printf("%lld\n",tmp);
		return 0;
	}
	printf("-1\n");
	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)


using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;


int main(){
	fast_io; cout_precision;
	int n;	cin >> n; int arr[n] , a[n];
	for(int i=0; i<n;i++){
		cin >> arr[i];	a[i] = arr[i];
	}
	int num=0;
	sort(a,a+n);
	for(int i=0; i<n; i++)	if(a[i] != arr[i])	num++;
	if(num >2)	cout<<"NO";
	else	cout<<"YES";
	
	return 0;
}

Measured memory_bytes: 256
import math
N = int(input().strip())
X = list(map(int, input().strip().split()))

min_effort = 100000000000
for i in range(100):
    accumulated_effort = 0
    for j in range(N):
        accumulated_effort += int(math.pow(i - X[j], 2))
    if min_effort > accumulated_effort:
        min_effort = accumulated_effort

print(min_effort)

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

int main() {
    int n;
    cin >> n;
    long long a[n];
    int i;
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }

    long long sum = 0;
    long long cnt1 = 0,
              cnt2 = 0;
        for(i = 0; i < n; i++) {
            sum += a[i];
            if (i % 2 == 0) {
                while(sum <= 0) {
                    sum++;
                    cnt1++;
                }
            }
            else {
                while(sum >= 0) {
                    sum--;
                    cnt1++;
                }
            }
        }

        sum = 0;

        for(i = 0; i < n; i++) {
            sum += a[i];
            if (i % 2 == 0) {
                while(sum >= 0) {
                    sum--;
                    cnt2++;
                }
            }
            else {
                while(sum <= 0) {
                    sum++;
                    cnt2++;
                }
            }
        }
    cout << min(cnt1, cnt2) << endl;
}


Measured memory_bytes: 4384
#include <iostream>

using namespace std;

int input1;
int input2;
int input3;

int main(){
    cin >> input1 >> input2 >> input3;

    int result = 0;
    input3 = input3 + 0.5;
    int quotient = input3 / input1;

    for (int i=0; i<quotient; i++){
        if(input3>=input1){
            input3 = input3 - input1;
            result = result + input2;
        }
        else{
            break;
        }
    }

    cout << result << "\n";

    return 0;
}

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

const ll MOD = 1e9 + 7;
ll dp[1000][2005];
int s;

int main(){
    cin >> s;
    for (int i = 0; i <= (s + 2) / 3; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i][j] = 0;
        }
    }
    for (int j = 0; j <= s; j++) {
        dp[0][j] = 1;
    }
    for (int i = 0; i <= (s + 2) / 3; i++) {
        for (int j = 3 * i; j <= s; j++) {
            dp[i+1][j + 3] = dp[i][j];
        }
        for (int j = 3 * (i+1); j <= s; j++) {
            dp[i+1][j+1] = (dp[i+1][j+1] + dp[i+1][j]) % MOD;
        }
    }
    ll ans = 0;
    for (int i = 0; i <= (s + 2) / 3; i++) {
        ans = (ans + dp[i][s]) % MOD;
        ans = (ans - dp[i][s-1]) % MOD;
        ans = (ans + MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
template< typename T >
struct BIT {
    vector< T > data;

    BIT(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for(++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for(++k; k < data.size(); k += k & -k) data[k] += x;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,q;
    cin>>n>>q;
    vec c(n);
    rep(i,n) cin>>c[i];
    vector<P> A,ANS;
    map<P,int> B;
    rep(i,q){
        ll l,r;
        cin>>l>>r;
        ANS.push_back(P(r,l));
        A.push_back(P(r,l));
    }
    sort(all(A));
    vec last(n+1,0);
    BIT<int> bit(n);
    int now=0;
    rep(i,q){
        while(now<A[i].first) bit.add(last[c[now]],1),last[c[now]]=now+1,now++,bit.add(now,-1);
        B[A[i]]=bit.sum(A[i].second-1);
    }
    rep(i,q) cout<<B[ANS[i]]<<"\n";
}

Measured memory_bytes: 60500
#include <bits/stdc++.h>
using namespace std;
class topological_sort {
  const int n;
  const vector<vector<int>>& grh;
  vector<int> srd;
  vector<int> ckd;
  bool flg;

  bool dfs (int crr) {
    if (ckd[crr] == 1) return true;
    if (ckd[crr] == 2) return false;
    bool ret = false;
    ckd[crr] = 1;
    for (int nxt : grh[crr]) {
      ret |= dfs(nxt);
    }
    ckd[crr] = 2;
    srd.insert(srd.begin(), crr);
    return ret;
  }

  public:
    topological_sort (
        const vector<vector<int>>& grh
      ) :
      n(grh.size()),
      grh(grh),
      srd(),
      ckd(n, 0),
      flg(false)
      {
        for (int i = 0; i < n; i++) {
          flg |= (ckd[i] == 0 && dfs(i));
        }
      }
    bool has_cycle () {return flg;}
    auto sorted() const -> const vector<int>& {return srd;}
    auto operator[](int i) const -> int {return srd[i];}
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> grh(n);
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    grh[s].push_back(t);
  }
  topological_sort tps(grh);
  assert(!tps.has_cycle());
  for (int i = 0; i < n; i++) {
    cout << tps[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3700
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i, n) EFOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS 1e-10
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double PI  = acos(-1.0);

stack<string> st;

string i2s(int num) {
	stringstream ss;
	ss << num;
	return ss.str();
}

bool is_op(string symbol) {
	if(symbol.find("+") != string::npos) return true;
	if(symbol.find("-") != string::npos) return true;
	if(symbol.find("*") != string::npos) return true;
	return false;
}

void calc(string symbol) {
	if(!is_op(symbol)) {
		st.push(symbol);
		return;
	}
	int b = atoi(st.top().c_str()); st.pop();
	int a = atoi(st.top().c_str()); st.pop();
	if(symbol == "+") {
		st.push(i2s(a+b));
	} else if(symbol == "-") {
		st.push(i2s(a-b));
	} else if(symbol == "*") {
		st.push(i2s(a*b));
	}
}

int main(int argc, char *argv[]) {
	// Something to do
	string input_line;
	getline(cin, input_line);

	string symbol;
	istringstream stream(input_line);
	while(getline(stream, symbol, ' ')) {
		calc(symbol);
	}

	cout << st.top() << endl;
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")


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


	long long a, b, c, d, ans;
	cin >> a >> b >> c >> d;
	ans = max(b * d, a * c);
	ans = max(ans, b * c);
	ans = max(ans, a * d);

	if ((a <= 0) && (b >= 0)) ans = max(0LL, ans);
	if ((c <= 0) && (d >= 0)) ans = max(0LL, ans);

	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    long long int A,B,C;
    scanf("%lld%lld%lld",&A,&B,&C);
    printf("%lld %lld %lld\n",C,A,B);
}

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

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

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

	int ans = 0;
	for (int i = 1; i <= n; i++){
		int count = 0;
		for (int j = 1; j <= i ; j++){
			if (i % j == 0){
				count++;
			}
		}
		if (count == 8 && i % 2){
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;

int h, w, n;
set<int> s[200002];

int main()
{

    // ifstream cin("a.in");
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> w >> n;
    for(int i = 1; i <= n; ++i)
    {
        int a, b;
        cin >> a >> b;
        s[b].insert(a);
    }
    for(int i = 1; i <= w; ++i)
        s[i].insert(h+1);
    int ans = (1<<20);
    int col = 1;
    for(int i = 1; i <= h; ++i)
    {
        ans = min(ans, (*s[col].lower_bound(i+1)) - 1);
        if(col < w && *s[col+1].lower_bound(i+1) != i+1)
            ++col;
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    int a = vec[i];
    for (int j = i + 1; j < N; j++){
      int b = vec[j];
      for (int k = j + 1; k < N; k++){
        int c = vec[k];
        int M = max(max(a, b), c);
        if (a != b && b != c && c != a && M < a + b + c - M){
          ans++;
        }
      }
    }
  }
  cout << ans;
}



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

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

const int maxn=37;
const int mo=998244353;

unsigned long long pw[maxn];
int n,len1,len2,a[maxn],b[maxn];
char s[maxn];

map<unsigned long long,int> mp[maxn];

void add(){
	unsigned long long hsh=0;
	for(int i=1;i<=len1;++i)
		hsh=(hsh+(s[a[i]]-'a'+3)*pw[i-1]);
	for(int i=1;i<=len2;++i)
		hsh=(hsh-(s[b[i]]-'a'+3)*pw[n-i]);
	++mp[len1][hsh];
}
ll res;
void query(){
	unsigned long long hsh=0;
	for(int i=1;i<=len1;++i)
		hsh=(hsh-(s[a[i]]-'a'+3)*pw[n-i]);
	for(int i=1;i<=len2;++i)
		hsh=(hsh+(s[b[i]]-'a'+3)*pw[i-1]);
//	for(int i=1;i<=len1;++i)printf("%c ",s[a[i]]);puts("");
//	for(int i=1;i<=len2;++i)printf("%c ",s[b[i]]);puts("");
//	printf("%d %d !\n",len1,hsh);
	res+=mp[n-len1][hsh];
}

void dfs1(int x){
	if(x>n){
		add();
		return ;
	}
	a[++len1]=x;
	dfs1(x+1);
	--len1;b[++len2]=x;
	dfs1(x+1);
	--len2;
}

void dfs2(int x){
	if(x<=n){
		query();
		return ;
	}
	a[++len1]=x;
	dfs2(x-1);
	--len1;b[++len2]=x;
	dfs2(x-1);
	--len2;
}

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	pw[0]=1;
	for(int i=1;i<=2*n;++i)
		pw[i]=pw[i-1]*233;
	dfs1(1);
	dfs2(2*n);
	printf("%lld\n",res);
	return 0;
}



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

const int inf=1e5+9;
int dp[inf];
// dp[0]=0;
int main_dfs(int v,vector<int> &visited,map<int,vector<int>> &ma){
visited[v]=1;
// cout<<v;
for(int neigh=0;neigh<ma[v].size();neigh++){
    //  int path=0;
        if(visited[ma[v][neigh]]==0){
                dp[v]=max(dp[v],main_dfs(ma[v][neigh],visited,ma));
                // dp[v]=path;
                }
        else
        {   
            dp[v]=max(dp[v],1+dp[ma[v][neigh]]);
        }
        
}

return 1+dp[v];
}
int main(){
int n,m,v1,v2;
cin>>n>>m;

map<int,vector<int>>ma;
vector<int>visited(n,0);
for(int i=0;i<m;i++){
cin>>v1>>v2;
ma[v1].push_back(v2);
}

for(int v=1;v<=n;v++){
        if(visited[v]==0){
                main_dfs(v,visited,ma);
        }
}
// for(int i=1;i<=n;i++){
//     cout<<dp[i]<<endl;
// }
cout<<*max_element(dp+1,dp+n+1);

return 0;
}




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

#define NMAX 100005
using namespace std;

long long dp[105][NMAX], val[NMAX], w[NMAX];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, g;
    cin >> n >> g;

    for(int i = 1; i <= n; ++i){
        cin >> w[i] >> val[i];
        for(int j = 0; j <= NMAX - 5; ++j)
            dp[i][j] = (1 << 30);
    }

    dp[1][0]= 0;
    dp[1][val[1]] = w[1];
    for(int i = 2; i <= n; ++i){
        dp[i][0] = 0;
        for(int j = 1; j <= NMAX - 5; ++j)
            if(val[i] <= j)
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + w[i]);
            else dp[i][j] = dp[i - 1][j];
    }
    long long maxx = 0;
    for(int j = 0; j <= NMAX - 5; ++j)
        if(dp[n][j] <= g)
            maxx = j;
    cout << maxx << '\n';
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n;
    cin >> n;
    int a[100010];
    rep(i,n){
        int A;
        cin >> A;
        a[A - 1] = i+ 1;
    }
    rep(i, n) cout << a[i] << ' ';
    return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define REPR(i, n) for (int i = n-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<n)
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision(n)
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VP = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int POW(ll a, ll b, ll m)
{
    ll res = 1;
    while(b > 0)
    {
        if (b & 1) res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return (int)res;
}

int main() {
  string S;
  cin >> S;
  ll len = S.size();
  VVll dp(len, Vll(13, 0));
  REPR(i, len)
  {
    if (i == len - 1)
    {
        if (S.at(i) != '?')
        {
            REP(j, 13) if (S.at(i)-'0' == j) dp.at(i).at(j) = 1;
        }
        else REP(j, 10) dp.at(i).at(j) = 1;
        continue;
    }
    int tmp = POW(10, len-i-1, 13);
    REP(j, 13)
    {
        if (S.at(i) == '?')
        {
            REP(s_i, 10)
            {
                dp.at(i).at(j) += dp.at(i+1).at((13 + j - ((s_i * tmp) % 13)) % 13);
                dp.at(i).at(j) %= mod;
            }
        }
        else
        {
            dp.at(i).at(j) += dp.at(i+1).at((13 + j - (((S.at(i)-'0') * tmp) % 13)) % 13);
            dp.at(i).at(j) %= mod;
        }
    }
  }
  cout << dp.at(0).at(5) << endl;

  return 0;
}

Measured memory_bytes: 13696
#include <iostream>
#include <cstring>

using namespace std;
struct Item{
    long long val;
    int wgt;
};
long long dp[101][100002];
Item *obj;

long long knapsck(int n, int w){
    if(n==0 || w < 0)
        return 0ll;
    if(dp[n][w]!=-1)
        return dp[n][w];
    long long a = -1;
    if(w-obj[n-1].wgt >= 0)
        a = knapsck(n-1, w-obj[n-1].wgt) + obj[n-1].val;
    long long b = knapsck(n-1, w);
    return dp[n][w] = max(a, b); 
}

int main() {
    int n,w;
    cin>>n>>w;
    memset(dp, -1, sizeof(dp));
    obj = new Item[n];
    for (int i=0;i<n; i++)
        cin >> obj[i].wgt >> obj[i].val;
    
    cout<<knapsck(n, w);
     
    return 0;
}

Measured memory_bytes: 82524
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


A = read_ints()
if len(set(A)) == 2:
    print('Yes')
else:
    print('No')


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int count = 0;
  while (true) {
    int minnum = min(a, min(b, c));
    a -= minnum;
    b -= minnum;
    c -= minnum;
    int maxnum = max(a, max(b, c));

    if (a == 0) {
      a = maxnum / 2 * 2;
    } else if (b == 0) {
      b = maxnum / 2 * 2;
    } else if (c == 0) {
      c = maxnum / 2 * 2;
    }
    count += maxnum / 2;

    if (a / 2 == 0 && b / 2 == 0 && c / 2 == 0) {
      break;
    }
  }

  int count1 = 0;
  if (a == 1) {
    count1++;
  }
  if (b == 1) {
    count1++;
  }
  if (c == 1) {
    count1++;
  }
  if (count1 == 0) {
    cout << count << endl;
  } else if (count1 == 1) {
    cout << count + 1 << endl;
  } else {
    cout << count + 2 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node {int p,l,r;};
struct Node T[MAX];
int n;

void preParse(int u)
{
  if(u==NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u)
{
  if(u==NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u)
{
  if(u==NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main()
{
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      T[i].p=NIL;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d%d%d",&v,&l,&r);
      T[v].l=l;
      T[v].r=r;
      if(l!=NIL)T[l].p=v;
      if(r!=NIL)T[r].p=v;
    }
  for(i=0;i<n;i++)if(T[i].p==NIL)root=i;
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int a, b,i=1;
	cin >> a >> b;
	string str = to_string(a) + to_string(b);
	int num = stoi(str);
	vi v;
	while (i*i <= 100100) {
		v.pb(i*i);
		i++;
	}
	for (int j = 0; j < v.size(); j++) {
		if (num == v[j]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
numa = sum(a)
numb = 0
cntb = 0
ans = 0
for i in range(n+1):
    if numa <= k:
        while cntb < m and numa + b[cntb] <= k:
            numa += b[cntb]
            cntb += 1
        ans = max(ans,n-i+cntb)
    if i != n:
        numa -= a[-(i+1)]
print(ans)

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;




// void answer()
// {




// }




int32_t main()
{   fastio;

    int n;
    cin>>n;
    int cnt = 0;
    for(int i=1; i <= n; i++)
    {
        if(n%i == 0) cnt += (n/i)-1;
        else cnt += (n/i);
    }
    cout<<cnt<<"\n";



}

Measured memory_bytes: 3652
def floor_sum(n, m, a, b):
    ans = 0
    if a >= m:
        ans += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ans += n * (b // n)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
      return ans
    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans

t = int(input())
for _ in range(t):
    n, m, a, b = map(int, input().split())
    print(floor_sum(n, m, a, b))


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
double a[3000],b[3000];
double dp[3000][1500];
double solve(int n,int i,int k)
{
	if(i==n)
		return 1;
	if(dp[i][k]!=-1)
		return dp[i][k];
	if(k==n/2)
	{
		return dp[i][k]=solve(n,i+1,k)*a[i];
	}
	else
	{
		return dp[i][k]=solve(n,i+1,k)*a[i]+solve(n,i+1,k+1)*b[i];
	}
}

int main()
{
  	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=1-a[i];
	}
	for(int i=0;i<3000;i++)
	{
		for(int j=0;j<1500;j++)
			dp[i][j]=-1;
	}
	cout<<fixed<<setprecision(10)<<solve(n,0,0);
	return 0;
}


Measured memory_bytes: 35584
#include<stdio.h>
int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if(a + b > c + d){
		printf("Left");
	}else if(a + b == c + d){
		printf("Balanced");
	}else{
		printf("Right");
	}
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
int dp[6000][6000] = {};
int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	for (int j = 1; j < s.size(); j++) {
		if (s[0] == s[j]) {
			dp[0][j] = 1;
		}
	}
	for (int i = 1; i < s.size(); i++) {
		for (int j = 0; j < s.size(); j++) {
			if (i != j && s[i] == s[j]) {
				if (j == 0) {
					dp[i][j] = 1;
				}
				else {
					if (j - dp[i - 1][j - 1] > i) {
						dp[i][j] = dp[i - 1][j - 1] + 1;
					}
					else {
						dp[i][j] = 1;
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < s.size(); j++) {
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans;
}


Measured memory_bytes: 119040
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;

const int N = 12, M = 1e3 + 2;
const int inf = 1e9;
int dp[M][1 << N];
vector<pii> keys;
int n, m;

int solve(int idx, int mask) {
	if (mask == ((1 << n) - 1)) {
		return 0;
	}
	if (idx == m - 1) {
		if ((mask | keys[idx].second) == ((1 << n) - 1)) {
			return dp[idx][mask] = keys[idx].first;
		}
		return inf;
	}
	if (dp[idx][mask] != -1)
		return dp[idx][mask];
	int ans = 1e9;
	ans = min(ans, solve(idx + 1, mask));
	ans = min(ans, keys[idx].first + solve(idx + 1, mask | keys[idx].second));
	return dp[idx][mask] = ans;
}

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n >> m;
	keys.resize(m);
	int poss = 0;
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		keys[i].first = a;
		keys[i].second = 0;
		for (int j = 0; j < b; ++j) {
			int c; cin >> c;
			--c;
			keys[i].second |= (1 << c);
		}
		poss |= keys[i].second;
	}
	if (poss + 1 != (1 << n)) {
		cout << -1 << "\n";
		return 0;
	}
	sort(all(keys));
	memset(dp, -1, sizeof(dp));
	int ans = solve(0, 0);
	cout << ans << "\n";
}

Measured memory_bytes: 16384
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[105][4][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2) {
        int nd = s[i] - '0';
        rep(d,10) {
            int ni = i+1, nj = j, nk = k;
            if (d != 0) ++nj;
            if (nj > K) continue;
            if (k == 0) {
                if (d > nd) continue;
                if (d < nd) nk = 1;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
        
    } 
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,b=0,i=1,j,saidai=0;
    string s;
    cin >> s;
    a=s.size();
    for(i=0;i<a;i++)
    {
        if(s.at(i)!='A')
        {
            continue;
        }
        for(j=0;saidai<a-j-1;j++)
        {
            if(s.at(i)=='A' && s.at(a-j-1)=='Z')
            {
                cout << a-j-i << endl;
                return 0;
            }
        }
    }
    return 0;

}


Measured memory_bytes: 3720
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline().rstrip()
#mod=1000000007
#res=['Yes', 'No']
############# CODE STARTS HERE #############
a, b=mi()
print('safe' if a>b else 'unsafe')

Measured memory_bytes: 9500
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 文字列の入力
    s <- getLine

    -- 出力
    putStrLn $ map (\c -> if c == ',' then ' ' else c) s 


Measured memory_bytes: 380
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int A = 0;
	int B1 = 0; 
	int B = 0;
	int flag = 0; 
	int power = 1;
	int output;
	int i = 0; 
	int j = 0;
	int check = 0;
	cin>>A>>B1; 
	B = B1;
	
	while(B1>0)
	{
		B1 = B1/10;
		if(B1>0)
		{
			flag = flag + 1;
		}
	}
	flag = flag + 1;

	for(i=0;i<flag;i++)
	{
		power = power * 10;
	}
	A = A * power;
	output = A + B;

	
	for(j=0;j<=output;j++)
	{
		check = j * j;
		if(check==output)
		{
			cout<<"Yes";
			break;
		}
		if(j==output)
		{
			cout<<"No";
		}
	}

}

Measured memory_bytes: 256
/*
 *       ~ AtCoder  Botay ~
 *        code by kazalika
 */

#include <bits/stdc++.h>

using namespace std;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  long long k;
  cin >> n >> k;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i]--;
  }
  if (a[0] == 0) {
    cout << 1;
    return 0;
  }
  vector <long long> timer(n);
  long long nn = 0, t = 0;
  while (!timer[nn]) {
    timer[nn] = t;
    if (timer[nn] == k || a[nn] == nn) {
      cout << nn + 1;
      return 0;
    }
    nn = a[nn];
    t++;
  }
  k -= timer[nn];
  assert(k >= 0);
  if (!k || a[nn] == nn) {
    cout << nn + 1;
    return 0;
  }
  long long st = nn, cn = 1;
  nn = a[nn];
  vector <long long> v = {st};
  while (st != nn) {
    v.push_back(nn);
    nn = a[nn];
    cn++;
  }
  assert(v.size() == cn);
  cout << v[k % cn] + 1;

}

Measured memory_bytes: 7092
#include<bits/stdc++.h>
using namespace std;
#define max 200000
#define ll long long

int main(){
    int n,T;
    cin>>n>>T;
    int t[max];
    for(int i=0;i<n;i++)
        cin>>t[i];
    ll x=0;
    for(int i=0;i<n-1;i++)
        x+=t[i+1]-t[i]>T?T:t[i+1]-t[i];
    x+=T;
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 1024