akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;

    auto is_int = [](char c) {
        if (c != '-')
            return true;
        return false;
    };
    auto no = []() {
        print("No");
        exit(0);
    };
    REP(i, a) {
        if (!is_int(s[i])) {
            no();
        }
    }
    if (s[a] != '-')
        no();
    FOR(i, a + 1, b + a + 1) if (!is_int(s[i])) no();
    print("Yes");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,string> p1,pair<ll,string> p2){
return p2.fi>p1.fi;
}
vector<ll> v[100006];
void solve(){
ll n,m,a,b;
cin>>n>>m;
ll h[n];
input(h,n);
fr(i,0,m){
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
bool all=1;
ll ans=0;
fr(i,1,n+1){
    all=1;
tr(v[i],it){
ll k=*it;
if(h[i-1]<=h[k-1]){
    all=0;
    break;
}
}
if(all){ ans++;
//cout<<i<<endl;
}
}
cout<<ans<<endl;
}
int main()
{   fast;
    ll t=1;
    //cin>>t;
    fr(zz,1,t+1){
    solve();
    }
}


Measured memory_bytes: 10288
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const long long INF = 1e18;

int main(){

    int N, M, P;
    cin >> N >> M >> P;
    vector<vector<pair<int, int>>> E(N);
    int a, b, c;
    for(int i = 0; i < M; i++){
        cin >> a >> b >> c;
        E[a - 1].push_back(make_pair(b - 1, c - P));
    }

    vector<long long> currentCost(N, -INF);
    vector<long long> nextCost(N, -INF);

    currentCost[0] = 0;
    nextCost[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            long long nodeCost = currentCost[j];
            if(nodeCost == -INF){
                continue;
            }
            for(auto e: E[j]){
                nextCost[e.first] = max(nextCost[e.first], nodeCost + e.second);
            }
        }

        for(int i = 0; i < N; i++){
            currentCost[i] = nextCost[i];
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            long long nodeCost = currentCost[j];
            if(nodeCost == -INF){
                continue;
            }
            for(auto e: E[j]){
                long long tempCost = nextCost[e.first];
                long long next = nodeCost + e.second;
                if(next > tempCost){
                    nextCost[e.first] = INF;
                }
            }
        }

        for(int i = 0; i < N; i++){
            currentCost[i] = nextCost[i];
        }
    }


    if(currentCost[N - 1] == INF){
        cout << -1 << endl;
    }
    else{
        cout << max(0LL, currentCost[N - 1]) << endl;
    }

    return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int h, w, k, ans, dp[102][10];
long long int p(long long int a){
	if(a==0||a==-1||a==-2||a==-3)return 1;
	if(a==1)return 2;
	if(a==2)return 3;
	if(a==3)return 5;
	if(a==4)return 8;
	if(a==5)return 13;
	if(a==6)return 21;
	if(a==7)return 34;
}
int main(){
	cin >> h >> w >> k;
	dp[0][1] = 1;
	dp[1][1] = 1;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			dp[i+1][j] = (dp[i][j]*p(j-2)*p(w-1-j)+dp[i][j-1]*p(j-3)*p(w-1-j)+dp[i][j+1]*p(j-2)*p(w-2-j)+MOD)%MOD;
		}
	}	
	
	cout << dp[h+1][k] % MOD << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

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

int main() {
    int N;
    cin >> N;
    if (N % 10 == 3) {
        out("bon");
    } else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) {
        out("pon");
    } else {
        out("hon");
    }
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int upper = Integer.parseInt(br.readLine());
        int lower = Integer.parseInt(br.readLine());
        int height = Integer.parseInt(br.readLine());
        int area = (upper+lower)*height/2;
        System.out.println(area);
    }
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  double x;
  x=(v[0]+v[1])/2.0;
  rep(i,n-2){
    x=(x+v[i+2])/2.0;
  }
  cout << x << endl;
    
    
  return 0;
}

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

using namespace std;

int main(void)
{
	
	int n;
	int Max1,Max2,Max3;
	Max1=0;
	Max2=0;
	Max3=0;
	
	for(int i=0;i<=9;i++){
		cin>>n;
		if(n>=Max1){
			Max3=Max2;
			Max2=Max1;
			Max1=n;
		}
		else if(n>=Max2){
			Max3=Max2;
			Max2=n;
		}
		else if(n>=Max3){
			Max3=n;
		}
		else{
		}
		/*cout<<Max1<<endl;
		cout<<Max2<<endl;
		cout<<Max3<<endl;*/
	}
	cout<<Max1<<endl;
	cout<<Max2<<endl;
	cout<<Max3<<endl;
}


Measured memory_bytes: 3104
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = true;

  private static PrintWriter _err = new PrintWriter(System.err);

  private void solve(Scanner sc, PrintWriter out) {
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();

    out.println((b / x) - (a / x) + (a % x == 0 ? 1 : 0));
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 9812
#include <stdio.h>

int main(void){
  int stack[10];
  int i=0; // i is StackPointer.
  int temp;
  while(scanf("%d",&temp)!=EOF){
    if(temp==0){
      //POP
      i--;
      printf("%d\n",stack[i]);
    }else{
      //PUSH
      stack[i] = temp;
      i++;
    }
  }
  return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, q;
string s;
char t[200000], d[200000];
int main(void){
    cin>>n>>q>>s;
    for(int i=0;i<q;i++){
        cin>>t[i]>>d[i];
    }
    int l=-1, r=n;
    for(int i=q-1;i>=0;i--){
        if(l+1<=n+1){
            if(d[i]=='L'&&t[i]==s[l+1]){
                l++;
            }
        }
        if(d[i]=='R'&&t[i]==s[l])l--;
        if(r-1>=0){
            if(d[i]=='R'&&t[i]==s[r-1]){
                r--;
            }
        }
        if(d[i]=='L'&&t[i]==s[r])r++;
    }
    cout<<max(0, n-max(0, l+1)-max(0, n-r))<<endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int N; cin >> N;
    string s, t; cin >> s >> t;
    for (int i = 0; i < N; i++)
    {
        if(s.substr(i, N-i) == t.substr(0, N-i)){
            s += t.substr(N-i, i);
            break;
        }
        if(i==N-1) s += t;
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut s = String::new();

    stdin().read_line(&mut s).ok();
    let nums: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    let x = nums[0];
    let y = nums[1];

    stdin().read_line(&mut s).ok();
    let mut ps: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    ps.sort();
    ps.reverse();
    ps = ps[..(x as usize)].to_vec();

    stdin().read_line(&mut s).ok();
    let mut qs: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    qs.sort();
    qs.reverse();
    qs = qs[..(y as usize)].to_vec();

    stdin().read_line(&mut s).ok();
    let mut rs: Vec<i64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    s.clear();
    rs.sort();

    ps.append(&mut qs);
    ps.append(&mut rs);
    ps.sort();
    ps.reverse();

    // let mut res_i: Option<usize> = None;
    // for i in 0..rs.len() {
    //     if rs[i] > ps[i] {
    //         res_i = Some(i);
    //     } else {
    //         break;
    //     }
    // }

    // rs.reverse();

    // let res: i64;
    // if let None = res_i {
    //     res = ps.iter().sum::<i64>();
    // } else {
    //     println!("{:?}", &ps[res_i.unwrap() + 1..]);
    //     println!("{:?}", &rs[..res_i.unwrap() + 1]);
    //     res = (ps[res_i.unwrap() + 1..].iter().sum::<i64>()
    //         + rs[..res_i.unwrap() + 1].iter().sum::<i64>()) as i64;
    // }

    //    // $B8e$O!"MW$O(B bottom rs.len() $B8D$N(B ps $B$K$D$$$F(B
    //    // allignment $B$NLdBj(B
    //    let mut switch_cnt = 0;
    //    let mut rs_i = 0;
    //    for ps_item in ps.iter_mut() {
    //        while rs_i < rs.len() {
    //            if ps_item < &mut rs[rs_i] {
    //                // *ps_item = rs[rs_i];
    //                switch_cnt += 1;
    //                rs_i += 1;
    //                break;
    //            }
    //            rs_i += 1;
    //        }
    //    }
    //    rs.reverse();
    //
    //    let res = ps[switch_cnt..].iter().sum::<i64>() + rs[..switch_cnt].iter().sum::<i64>();

    //     for res_elem in ps.iter_mut() {
    //         for rs_i in 0..rs.len() {
    //             if rs[i] {
    //                 rs = rs[rs_i..].to_vec();
    //                 break;
    //             }
    //         }
    //     }
    //
    //
    //
    //         if rs.len() > 0 {
    //             if *res_item < *rs.peek().unwrap() {
    //                 *res_item = rs.pop().unwrap();
    //             } else {
    //                 break;
    //             }
    //         } else {
    //             break;
    //         }
    //     }

    let res: i64 = ps[..(x + y) as usize].to_vec().iter().sum();

    println!("{}", res);
}


Measured memory_bytes: 14436
s=input()
t=''
i=0
while(i<len(s)):
    if i<len(s)-1 and s[i:i+2]=='BC':
        t+='D'
        i+=2
    else:
        t+=s[i]
        i+=1
t=t[::-1]
N=len(t)
i=0
ans=0
while(i<N):
    if t[i]=='D':
        j=i
        cnt=0
        while(j<N and t[j]!='B' and t[j]!='C'):
            if t[j]=='D':
                cnt+=1
            else:
                ans+=cnt
            j+=1
        i=j
    i+=1
print(ans)

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


int main() {
	double r;
	cin >> r;

	cout << 2.0 * 3.141592*r << endl;
	


}

Measured memory_bytes: 3784
#include <iostream>

using namespace std;

#define MAX_WORD (1000)

class Navie{
private:

	int strLength;
	char str[MAX_WORD];
	
public:
	
	Navie(char str[]){
		int i;
		for(i = 0;str[i] != '\0';i++){
			this->str[i] = str[i];
		} 
		this->str[i] = '\0';
		this->strLength = i;
	}
	
	void saerch(char cmpstr[]){
		int i;
		
		for(i = 0;i < this->strLength;i++){
			if(this->str[i] == cmpstr[0]){
				if(inspect(i+1,&cmpstr[1]) == true){
					cout << i << endl;
				}
			}
		}
	}
	
	bool inspect(int n,char cmpstr[]){
		int i;
		for(i = 0;cmpstr[i] != '\0';i++){
			if(this->str[n+i] != cmpstr[i]){
				return false;
			}
		}
		return true;
	}
	
};

int main(){

	char str[MAX_WORD];
	char temp[MAX_WORD];
	
	Navie *nav;

	cin >> str;

	nav = new Navie(str);
	
	cin >> temp;
	
	nav->saerch(temp);
	
	delete nav;
	
	return 0;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int arr[101010]={};
int arr2[101010]={};
int N=100001;
void Er(){
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
}

int main(){
	int q;
	int l,r;
	Er();
	FOR(i,1,100001){
		if(arr[i]==1&&arr[(i+1)/2]==1)arr2[i]=1;
	}
	arr2[0]=0;
	arr2[1]=0;
	arr2[2]=0;
	FOR(i,2,100001){
		arr2[i]+=arr2[i-1];
	}
	cin>>q;
	FOR(i,0,q){
		cin>>l>>r;
		cout<<arr2[r]-arr2[l-1]<<endl;
	}

    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt(), B = sc.nextInt();
		
		String s = sc.next();
		
		for(int i = 0; i<A; i++) {
			if(s.charAt(i) - '0' < 0 && s.charAt(i) > 9) {
				System.out.println("No");
				System.exit(0);
			}
		}
		
		if(s.charAt(A) != '-') { System.out.println("No"); System.exit(0); }
		
		for(int i = A+1; i<=A+B; i++) {
			if(s.charAt(i) - '0' < 0 && s.charAt(i) > 9) {
				System.out.println("No");
				System.exit(0);
			}		
		}
		
		System.out.println("Yes");
	}

}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i=0;i<v.size();++i) cin >> v[i];
  auto sum=0;
  for(int i=0;i<n;++i){
    if(abs(v[i])>abs(v[i]-k)) sum+=abs(v[i]-k)*2;
    else sum+=abs(v[i])*2;
  }
  cout << sum << endl;

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i ++) {
    if (s.at(i) == '2') {
      cnt ++;
    }
  }

  cout << cnt << endl;
}


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

int main(void) {
  int n;
  int blood[4] = {0};
  char tmp[4];

  while (scanf("%d,%s", &n, tmp) == 2) {
    switch (tmp[0]) {
    case 'A':
      if (tmp[1] == 'B') {
        blood[2]++;
      } else {
        blood[0]++;
      }
      break;
    case 'B':
      blood[1]++;
      break;
    case 'O':
      blood[3]++;
      break;
    }
  }

  for (int i = 0; i < 4; i++) {
    cout << blood[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1208
import java.math.*;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    Map<Integer, Integer> map = new HashMap<>();


    public static void main(String[] args) {
        new Main().run();
    }

    long sum = 1;

    long[] cnt = new long[n+1];

    void run() {

        for (int i=1; i<=n; i++) {
            for (int j=i; j<=n; j+=i) {
                cnt[j]++;
            }
        }

        for (int i=2; i<=n; i++) sum += (long)i * cnt[i];

        System.out.print(sum);


    }
    Map<Integer, Integer> primes(int n) {
        List<Integer> list = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();

        while (n >= 4 && n % 2 == 0) {
            list.add(2);
            n /= 2;
        }
        int d = 3;
        int q = n / d;
        while (q >= d) {
            if (n % d == 0) {
                list.add(d);
                n = q;
            } else {
                d += 2;
            }
            q = n / d;
        }
        list.add(n);

        for (int t: list) {
            if (map.containsKey(t)) {
                map.put(t, map.get(t) + 1);
            } else {
                map.put(t, 1);
            }
        }
        return map;

    }


}



Measured memory_bytes: 115824
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll K, X, ans;
    scanf("%lld %lld", &K, &X);
    if ( 500 * K >= X ) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<list>
using namespace std;
static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u) {
    V[u] = true;
    for(int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if(!V[v]) dfs(v);
    }
    out.push_front(u);
}

int main() {
    int s, t, M;
    
    cin >> N >> M;
    
    for(int i = 0; i < N; i++) V[i] = false;
    
    for(int i = 0; i < M; i++) {
        cin >> s >> t;
        G[s].push_back(t);
    }
    
    for(int i = 0; i < N; i++) {
        if(!V[i]) dfs(i);
    }
    
    for(list<int>::iterator it = out.begin(); it != out.end(); it++) {
        cout << *it << endl;
    }
    
    return 0;
}


Measured memory_bytes: 6076
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

long[] dijkstra(long from, long to, long[][] edges)
{
	long[] path;
	auto cost = new long[](edges.length); fill(cost, long.max); cost[from] = 0;
	long[][] open = [[from]];
	while (!open.empty)
	{
		auto n = open.front; open.popFront;
		auto p = n[0];
		foreach (i; 0..edges.length)
		{
			if (edges[p][i] == -1) continue;
			auto c = cost[p] + edges[p][i];
			if (c < cost[to] && c < cost[i]) { cost[i] = c; if (i == to) path = i ~ n; else open ~= i ~ n; }
		}
	}
	return cost[to] ~ path;
}

void main()
{
	auto N = RD;
	double ans = 0.0;
	foreach (i; 0..N)
	{
		auto x = RD!string;
		auto u = RD!string;
		if (u == "BTC") ans += x.to!double * 380000.0;
		else ans += x.to!long;
	}

	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 256
s=input()[::-1]
i=0
while i<len(s):
    if i+5<=len(s) and s[i:i+5]=='esare':
        i+=5
    elif i+5<=len(s) and s[i:i+5]=='maerd':
        i+=5
    elif i+6<=len(s) and s[i:i+6]=='resare':
        i+=6
    elif i+7<=len(s) and s[i:i+7]=='remaerd':
        i+=7
    elif i<len(s):
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S, result = "Three";
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "Y") {
      result = "Four";
      break;
    } 
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    string S; cin >> S;
    int ans=0;
    REP(i,S.size()){
        if(S[i]=='1') ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S = to_string(N);
    ll keta_n = S.size();
    ll ans = 0;
    rep(A,1,N+1){
        string as = to_string(A);
        ll sz = as.size();
        char lv = as[0];
        char rv = as[sz-1];
        if(rv == '0') continue;
        if(lv == rv){
            ll v = lv - '0';
            if(v <= N) ans++;
        }
        ll keta = 2;
        while(keta <= keta_n){
            if(keta != keta_n){
                ll val = 1;
                rep(i,0,keta-2){
                    val *= 10;
                }
                ans += val;
            }else{
                ll val = 1;
                rep(i,0,keta-2){
                    val *= 10;
                }
                ll start = (rv - '0');
                rep(i,0,keta-1) start *= 10;
                start += (lv - '0');
                if(S[0] > rv){
                    ans += val;
                }else if(S[0] == rv){
                    rep(j,0,val){
                        if(start + j * 10 <= N) ans++;
                    }
                }

            }
            keta++;

        }

    }
    print(ans);

}


Measured memory_bytes: 256
n = int(input())
a = []
n_sum = (n/2) * (n+1)
for i in range(1,n+1):
    if i % 3 == 0:
        a.append(i)
    elif i % 5 == 0:
        a.append(i)
    elif i % 15 == 0:
        a.append(i)
print(int(n_sum-sum(a)))

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

int main(){
  int n;cin>>n;
  string ans="";
  if(!n){
    cout<<0;
    return 0;
  }
  while(n){
    if(n%2){
      n--;
      ans="1"+ans;
    }else ans="0"+ans;
    n/=(-2);
  }
  cout<<ans;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            var A = Scanner.ScanEnumerable<long>().ToArray();
            var xor = A.Aggregate((current, item) => current ^ item);
            var answer = new long[N];
            for (var i = 0; i < N; i++)
            {
                answer[i] = xor ^ A[i];
            }

            Console.WriteLine(string.Join(" ", answer));
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 72992
#include <iostream>
using namespace std;
long long mod = 1000000007, n, fact[(1<<20)], invf[(1<<20)];

long long pow2( long long a, long long st ) {
    long long ret = 1;
    for ( ; st ; st /= 2 ) {
        if ( st%2 ) {
            ret *= a;
            ret %= mod;
        }
        a *= a;
        a %= mod;
    }
    return ret;
}
long long comb ( long long k, long long n ) {
    return fact[n]*invf[k]%mod*invf[n-k]%mod;
}
long long s( long long k ) {
    if ( n-k-1 > k-1 ) { return 0; }
    return comb( n-k-1, k-1 );
}
long long f[(1<<20)];

int main () {
    cin >> n;
    fact[0] = 1;
    invf[0] = 1;
    for ( int i = 1 ; i <= n ; i ++ ) {
        fact[i] = fact[i-1]*i%mod;
        invf[i] = pow2( fact[i], mod-2 );
    }

    long long ans = 0;
    for ( int k = 1 ; k < n ; k ++ ) {
        f[k] = s(k)*fact[k]%mod*fact[n-k-1]%mod;
        ans += ( f[k] - f[k-1] + mod)%mod*k%mod;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}


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

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

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


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

typedef long long ll;

int N;
int A[100010],B[100010];
ll sumA = 0,sumB = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i),sumA += A[i];
    for(int i = 0; i < N; i++)scanf("%d",B + i),sumB += B[i];

    ll num = sumB - sumA;
    if(num < 0)
    {
        printf("No\n");
        return 0;
    }

    for(int i = 0; i < N; i++)num -= max(0,(B[i] - A[i] + 1) / 2);
    if(num >= 0)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,a,b;cin >> n >> a >> b;
  int ans = 0;
  rep(i,n+1){
    string x = to_string(i);
    int q=0;
    for(int t=0;t<x.size();t++){
      q+= x[t]-'0';
    }
    if(a<=q&&q<=b) ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    long long q,a,b,score,sqr,ans;
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        score=a*b;
        sqr=sqrt(score);
        if(sqr*sqr+sqr<score)
            ans=2*sqr-1;
        else
        {
            ans=2*(sqr-1);
            if(sqr*sqr==score&&a!=b) ans--;
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x,  n, sum=0, max=-1000000, min=1000000;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> x;
        if(x > max){
            max = x;
        }
        if(x < min){
            min = x;
        }
        sum += x;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3096
// D - AtCoder Express 2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int LR[501][501]; // LとRの二次元の座標とみなす
ll c_LR[501][501]; // c_LR[i][j]: L=i, R=jまでの二次元累積和
int p[100000];
int q[100000];

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

	// train
	int L, R;
	for (int i=0; i<M; i++) {
		cin >> L >> R;
		LR[L][R]++;
	}

	// query
	for (int i=0; i<Q; i++) {
		cin >> p[i] >> q[i];
	}

	// 二次元累積和を計算
	for (int i=1; i<=N; i++) {
		for (int j=1; j<=N; j++) {
			c_LR[i][j] = c_LR[i-1][j] + c_LR[i][j-1] - c_LR[i-1][j-1] + LR[i][j];
		}
	}

	// answer to queries
	ll ans;
	for (int i=0; i<Q; i++) {
		ans = c_LR[N][q[i]] - c_LR[p[i] - 1][q[i]];
		cout << ans << endl;
	}

	return 0;
}

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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  vector<int> x(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &x.at(i));
  }

  long long ans = 1e9;
  for (int i = 0; i <= N - K; i++) {
    long long left = x.at(i);
    long long right = x.at(i + K - 1);
    long long movement = min(abs(left) + right - left, abs(right) - left + right);
    ans = min(ans, movement);
  }

  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 640
def op(x):
    return '+' if x == 1 else '-'
a, b, c, d = map(int, input())

for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            if a + i * b + j * c + k * d == 7:
                print(str(a) + op(i) + str(b) + op(j) + str(c) + op(k) + str(d) + '=7')
                exit()


Measured memory_bytes: 3060
# coding: utf-8


class Player:

    def __init__(self):
        self.point = 0

    def add_point(self, point):
        self.point += point

    def get_point(self):
        return self.point


def main():

    _ = int(input())
    cards = list(map(int, input().split(' ')))
    cards = sorted(cards, reverse=True)

    alice = Player()
    bob = Player()
    players = [alice, bob]
    for i, card in enumerate(cards):
        players[i % len(players)].add_point(card)

    print(alice.get_point() - bob.get_point())

    return 0


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
a,b,c,d,e,f=map(int,input().split())
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
w=[]
for i in range(0,f//100+1):
    for j in range(0,f//100+1):
        x=i*a*100+j*b*100
        if x<=f:
            w.append(x)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i==0 and j==0:
            continue
        elif e*(i//100)<j:
            continue
        elif f<i+j:
            continue
        else:
            con=(100*j)/(i+j)
            if max_con<=con:
                max_con=con
                ans=i+j
                ans_2=j
print(ans,ans_2)


Measured memory_bytes: 12440
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

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

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

  return 0;
}


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

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x1 - (y2 - y1);
    y4 = y1 + (x2 - x1);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

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

int main() {
	int H;
	cin >> H;
	int W;
	cin >> W;
	vector<vector<char>> a(H, vector<char>(W));
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			cin >> a.at(h).at(w);
		}
	}

	bool bAllWhite = false;
	for (int h = 0; h < H; h++) {
		bAllWhite = true;
		for (int w = 0; w < W; w++) {
			if (a.at(h).at(w) == '#') {
				bAllWhite = false;
				break;
			}
		}
		if (bAllWhite) {
			for (int w = 0; w < W; w++) {
				a.at(h).at(w) = ' ';
			}
		}
	}
	for (int w = 0; w < W; w++) {
		bAllWhite = true;
		for (int h = 0; h < H; h++) {
			if (a.at(h).at(w) == '#') {
				bAllWhite = false;
				break;
			}
		}
		if (bAllWhite) {
			for (int h = 0; h < H; h++) {
				a.at(h).at(w) = ' ';
			}
		}
	}
	for (int h = 0; h < H; h++) {
		bAllWhite = true;
		for (int w = 0; w < W; w++) {
			if (a.at(h).at(w) != ' ') {
				cout << a.at(h).at(w);
				bAllWhite = false;
			}
		}
		if (! bAllWhite) {
			cout << endl;
		}
	}
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end(), greater<int>());
  long long w = 0, h = 0;
  long long rec = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) == a.at(i + 1) && w == 0) {
      w = a.at(i);
      i++;
      continue;
    }
    if (a.at(i) == a.at(i + 1) && w != 0) {
      h = a.at(i);
      rec = w * h;
      break;
    }
  }
  cout << rec << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <list>
#include <algorithm>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {
		int N, A, B, C, X;
		cin >> N >> A >> B >> C >> X;
		if( ( N == 0 ) &&
			( A == 0 ) &&
			( B == 0 ) &&
			( C == 0 ) && 
			( X == 0 ) ) break;
		vector<int> y;
		for(int i = 0; i < N; i++) {
			int y_i;
			cin >> y_i;
			y.push_back( y_i );
		}
		int ans = -1;
		int reel = 0;
		for(int i = 0; i < 10000 + 1; i++) {
			if( y.at(reel) == X ) reel ++;
			if( reel == y.size() ) {
				ans = i;
				break;
			}
			X = ( A * X + B ) % C;
		}
		cout << ans << endl;
	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }
    int res=0;
    int now=10;
    for(int i=0;i<d5;i++){
        if(now>n)break;
        res+=n/now;
        now*=5;
    }
    cout<<res<<endl;
}

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

int main(){
int X;  cin >> X;
int b_max = 32;
int p_max = 10;
int ans = 0;

for (int b = 1; b < b_max; b++) {
    for (int p = 2; p < p_max; p++) {
        int val = pow(b, p);
        if (val <= X) {
            ans = max(ans, val); 
        }
    }
}
cout << ans << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <atcoder/all>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string S;

int main() {
  std::cin >> S;

  auto sa = atcoder::suffix_array(S);

  ll N = S.size();

  ll ans = N*(N+1)/2;

  auto lcp = atcoder::lcp_array( S, sa );

  for( auto x : lcp ) {
    ans -= x;
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 15624
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
ll f(ll a) { return a * a * a * a * a; }
int main() {
	ll x;
	scanf("%lld", &x);
	for (ll i = -100; i <= 1000; i++) {
		for (ll j = -1000; j <= 1000; j++) {
			if (f(i) - f(j) == x) {
				printf("%lld %lld\n", i, j);
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using A = array<int, 2>;
using P = pair<int, int>;
constexpr int MOD{1000000000 + 7};
constexpr int MAX{510000};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr array<int, 4> dx{1, 0, -1, 0}, dy{0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}

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 PER(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));

// *****************************************************************************

class Graph
{
private:
    vector<vector<int>> to_;
    vector<bool> seen_;
    const int k_;

public:
    Graph(int n, int k) : to_(n), seen_(n, false), k_(k)
    {
    }
    void connect(int a, int b);
    ll BFS();
};

void Graph::connect(int a, int b)
{
    to_[a].push_back(b);
    to_[b].push_back(a);
}

ll Graph::BFS()
{
    ll pattern = 1;
    seen_[0] = true;
    queue<int> next_nodes;
    next_nodes.push(0);
    while (!next_nodes.empty())
    {
        int now = next_nodes.front();
        next_nodes.pop();

        int num_children = 0;
        for (int next : to_[now])
            if (seen_[next] == false)
                num_children++;

        if (now == 0)
        {
            pattern = (pattern * PER(k_, num_children + 1)) % MOD;
        }
        else
        {
            pattern = (pattern * PER(k_ - 2, num_children)) % MOD;
        }

        for (int next : to_[now])
        {
            if (seen_[next])
                continue;
            next_nodes.push(next);
            seen_[next] = true;
        }
    }

    return pattern;
}

void solve()
{
    int n, k;
    cin >> n >> k;
    Graph g(n, k);
    for (int i = 0, a, b; i < n - 1; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        g.connect(a, b);
    }
    cout << g.BFS() << endl;
}

// *****************************************************************************

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(0);

    COMinit();
    solve();
}


Measured memory_bytes: 18552
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 100; i > 0; i--) {
		if (a%i == 0 && b%i == 0) {
			k--;
			if (k == 0) {
				cout << i << endl;
				return 0;
			}
		}
	}
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int N,M,S[50][3]={0};
	int i,j;
	char H[51][51];
	
	scanf("%d%d",&N,&M);
	for(i=0;i<N;i++) scanf("%s",H[i]);
	
	for(i=0;i<N;i++){
		for(j=0;j<M;j++){
			if(H[i][j]!='W'&&i<N-2) S[i][0]++;
			if(H[i][j]!='B'&&i>0&&i<N-1) S[i][1]++;
			if(H[i][j]!='R'&&i>1) S[i][2]++;
		}
		if(i<N-1){
			S[i+1][0]=S[i][0];
			S[i+1][1]=S[i][1];
			S[i+1][2]=S[i][2];
		}
	}
	
	int min=2500;
	for(i=0;i<N-2;i++){
		for(j=i+1;j<N-1;j++){
			if(min>S[i][0]+S[j][1]-S[i][1]+S[N-1][2]-S[j][2]){
				min=S[i][0]+S[j][1]-S[i][1]+S[N-1][2]-S[j][2];
			}
		}
	}
	
	printf("%d\n",min);
	
	return 0;
}



Measured memory_bytes: 2044