akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,q,fa[N],x[N],y[N],tt;
long long m;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

void No() {
	cout<<"No";exit(0);
}

int main() {
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++) fa[i]=i;
	int blo=n;
	for(int i=1;i<=q;i++) {
		int a,b,c;cin>>a>>b>>c;
		++a,++b;
		if(!c) {
			if(getf(a)!=getf(b)) fa[getf(a)]=getf(b),--blo;
		}
		else x[++tt]=a,y[tt]=b;
	}
	for(int i=1;i<=tt;i++)
		if(m<n||getf(x[i])==getf(y[i])) No();
	if(m>n-blo+1ll*blo*(blo-1)/2) No();
	else cout<<"Yes";
	return 0;
}


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

int main(){
    char s[4];
    cin >> s;

    if(s[0]=='7'|| s[1]=='7'|| s[2]=='7'|| s[3]=='7'){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3536
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	int n4 = (H / 2) * (W / 2), n2 = (H % 2 == 1 ? W / 2 : 0) + (W % 2 == 1 ? H / 2 : 0), n1 = (H % 2 == 1 && W % 2 == 1 ? 1 : 0);
	vector<int> c(26);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			++c[S[i][j] - 'a'];
		}
	}
	bool ok = true;
	for (int i = 0; i < 26 && ok; ++i) {
		int u4 = min(n4, c[i] / 4); c[i] -= u4 * 4; n4 -= u4;
		int u2 = min(n2, c[i] / 2); c[i] -= u2 * 2; n2 -= u2;
		int u1 = min(n1, c[i]); c[i] -= u1; n1 -= u1;
		if (c[i] > 0) ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	long x;
	cin >> x;
	long a;
	a = x % 11;
	if(a > 6) cout << x / 11 * 2 + 2 << endl;
	else if(a == 0)cout << x / 11 * 2 << endl;
	else cout << x / 11 * 2 + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }

void test_case() {
	int n;
	scanf("%d", &n);
	vector<long long> a(n);
	for(int i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
	}
	char s[n+1];
	scanf("%s", s);
	assert((int) strlen(s) == n);
	vector<long long> base;
	for(int i = n - 1; i >= 0; --i) {
		// if(a[i] == 0) {
			// continue;
		// }
		long long x = a[i];
		for(long long b : base) {
			x = min(x, x^b);
		}
		if(x == 0) {
			continue;
		}
		if(s[i] == '0') {
			base.push_back(x);
		}
		else {
			puts("1");
			return;
		}
	}
	puts("0");
}

int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		test_case();
	}
}


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

using namespace std;

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

int main(void){
  ll x,k,d; cin >> x >> k >> d;//position x, k times, d move;
  x=abs(x);
  double A=(double)d;
  double B=(double)x/(double)k;
  if(A < B){
    ll Min=x-d*k;
    cout << Min << endl;
    exit(0);
  }

  k-=x/d;
  x%=d;

  if(k%2==0){
    cout << x << endl;
  }else{
    cout << abs(x-d) << endl;
  }

  return 0;
}

Measured memory_bytes: 3680
use proconio::input;
use std::cmp::max;

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let ac = a * c;
    let ad = a * d;
    let bc = b * c;
    let bd = b * d;

    println!("{}", max(max(ac, ad), max(bc, bd)));
}


Measured memory_bytes: 2160
#include "bits/stdc++.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
using ll = long long;
using namespace std;

/*
ll GCD(ll a, ll b) {
	return b ? GCD(b, a%b) : a;
}

sort(a, a + N, greater<int>())   // descend
sort(a, a+N)                    //  ascend


** nCk
void comb(vector<vector <long long int > > &v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


** main内でnCn~nC0 生成 **
vector<vector<long long int> > v(n + 1, vector<long long int>(n + 1, 0));
	comb(v);


*/

int main() {
	ll n, k;
	cin >> n >> k;
	double ans = 0;
	rep(i, 1, n + 1) {
		ll p = i;
		ll d = 0;
		while (k > p) {
			p = p * 2;
			d++;
		}
		ans += pow(0.5, d);
	}
	printf("%.12lf\n", ans / n);
}

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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N;
    cin >> N;
    vector<vector<unsigned long>> children(N + 1);
    {
        vector<pair<long, long>> robots(N + 1);
        robots[0] = pair<long, long>{-2000000000, 4000000000};
        for(long i{1}, x, d; i <= N; ++i){
            cin >> x >> d;
            robots[i] = pair<long, long>{x, x + d};
        }
        sort(robots.begin(), robots.end());
        stack<pair<unsigned long, long>> st;
        for(unsigned long i{0}; i <= N; ++i){
            while(!st.empty() && st.top().second <= robots[i].first)st.pop();
            if(!st.empty())children[st.top().first].emplace_back(i);
            while(!st.empty() && st.top().second < robots[i].second)st.pop();
            st.emplace(i, robots[i].second);
        }
    }
    vector<unsigned long> dp(N + 1, 1);
    for(unsigned long i{N + 1}; i--; ++dp[i])for(const auto& j : children[i])(dp[i] *= dp[j]) %= MOD;
    cout << (dp[0] + 998244352) % MOD << endl;
    return 0;
}

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

int main()
{


        int A, B;
        cin >> A >> B;

        if (A % 3 == 0) {
                cout << "Possible" << endl;
                return 0;
        }
        else if (B % 3 == 0) {
                cout << "Possible" << endl;
                return 0;
        }
        else if ((A+B) % 3 == 0) {
                cout << "Possible" << endl;
                return 0;
        }
        cout << "Impossible" << endl;







}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int x, y;
    do
    {
        scanf("%d %d", &x, &y);
        if (x != 0 || y != 0)
        {
            int count = 0;
            for (int i = 1; i <= x; i++)
            {
                for (int j = 1; j <= x; j++)
                {
                    for (int k = 1; k <= x; k++)
                    {
                        if(i < j && j < k && j + i + k == y){
                            count = count + 1;
                        }
                    }
                }
            }
        printf("%d\n", count);
        }
    } while (x != 0 || y != 0);
    return 0;
}


Measured memory_bytes: 2040
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    count = 0
    X = ""
    Y = ""
    for j in S[:i]:
        X += j

    for k in S[i:]:
        if X.find(k) != -1 and Y.find(k) == -1:
            Y += k
            count += 1
 
    ans = max(count, ans)

print(ans)

Measured memory_bytes: 3064
require 'prime'
a, b = gets.chomp.split.map(&:to_i)

a, b = b, a if a > b
until a == 0
  a, b = b%a, a
end

# bが最大公約数
k = []

def my_divisor_list(a)
  return [1] if a == 1
  Prime.prime_division(a).map do |e|
    Array.new(e[1]+1).map.with_index do |element, i|
      e[0]**i
    end
  end.inject{|p,q| p.product(q)}.map do |a|
    [a].flatten.inject(&:*)
  end.sort
end
k = my_divisor_list(b)

def prime_or_1?(n)
  return true if n == 1
  return true  if n == 2 or n == 3
  return false if (n % 2).zero?
  3.step(Math.sqrt(n).to_i, 2) {|i| return false if (n % i).zero?}
  true
end

p k.select{ |i| prime_or_1?(i) }.size


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if (p[i] > p[i - 1] && p[i] < p[i + 1])
            ans++;
        if (p[i] < p[i - 1] && p[i] > p[i + 1])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(x, y, a, b, c);
    VIN(ll, p, a);
    sort(all(p), std::greater<ll>());
    VIN(ll, q, b);
    sort(all(q), std::greater<ll>());
    VIN(ll, r, c);
    sort(all(r), std::greater<ll>());
    PQG<ll> que;
    ll m = 0;
    rep(i, x)
    {
        que.push(p[i]);
        m += p[i];
    }
    rep(i, y)
    {
        que.push(q[i]);
        m += q[i];
    }
    int id = 0;
    while (id < c)
    {
        if (que.empty() || que.top() > r[id]) break;
        m += r[id] - que.top();
        que.pop();
        ++id;
    }
    cout << m << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, sum = 0;
    cin >> n;
    int d[n];
    REP(i,n) cin >> d[i];

    REP(i,n) {
        for (int j = i+1; j < n; j++) {
            sum += d[i]*d[j];
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll k,a,b,x,i,j,z,n;
    cin>>a>>b>>x;
    if(x>=b){
        x=b-1;
    }
    cout<<(a*x)/b-a*(x/b)<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	ll N,K;
	string s;
	cin>>N>>K;
	cin>>s;
	for(ll i=0;i<N;i++){
		if(i==K-1) printf("%c",tolower(s[i]));
		else cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e6 + 10;
int n, k;
int a[N];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= k; i++)ans += a[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3848
import java.util.Scanner;

public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			System.out.println(calcFractorialMod(n));
		}
	}

	/**
	 * @param n
	 * @return nの階乗 mod MOD
	 */
	private static long calcFractorialMod(int n) {
		long result = 1L;
		for (int i = 2; i <= n; i++) {
			result = result * i % MOD;
		}
		return result;
	}
}


Measured memory_bytes: 21844
import collections

N, D, A = [int(i) for i in input().split()]  # 数, 範囲, 攻撃力
XH = [tuple(map(int, input().split())) for _ in range(N)]  # 座標, 体力
XH.sort()

queue = collections.deque()
ans = 0
damage = 0

for x, h in XH:
    while queue and queue[0][0] < x:
        damage -= queue.popleft()[1]

    h -= damage
    if h > 0:
        count = -(-h // A)
        ans += count

        queue.append((x + 2*D, count * A))
        damage += count * A

print(ans)

Measured memory_bytes: 81368
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> C(N-1), S(N-1), F(N-1);
  REP(i, N-1) cin >> C[i] >> S[i] >> F[i];

  REP(i, N-1){
    int now = C[i]+S[i];
    FOR(j, i+1, N-1){
      now = (max(now, S[j])+F[j]-1)/F[j]*F[j]+C[j];
    }
    cout << now << "\n";
  }
  cout << 0 << "\n";

  return 0;
}

Measured memory_bytes: 256
//g++  5.4.0
 
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ff first
#define ss second
#define pii pair<int,int>
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
 
const int nax = 2e6+1;
const int mod = 1e9+7;
int f[nax] , invf[nax];
 
int binpow(int a,int b)
{
    int res = 1;
    a %= mod;
    while( b )
    {
        if( (b&1) ) res = (res*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}
void init()
{
    f[0] = 1;
    for(int i=1 ; i<nax ; i++ ) f[i] = (f[i-1]*i)%mod;
    invf[nax-1] = binpow( f[nax-1] , mod-2);
    for(int i=nax-2 ; i>=0 ; i-- ) invf[i] = (invf[i+1] * (i+1))%mod;
}
 
int ncr(int n,int r)
{
    return ((f[n]*invf[n-r])%mod * invf[r] )%mod;
}
 
signed main()
{
    fast;
    init();
    int n , m ,q;
    cin >> n >> m >> q;
    int ans = ncr( m+n-2 , n-1 );
    vector<int> dp(q,0);
    vector<pii> points(q);
    for(int i=0 ; i<q ; i++ )
        cin >> points[i].ff >> points[i].ss;
    sort( points.begin() , points.end()) ;
    for(int i=0 ; i<q ; i++ )
    {
        dp[i] = ncr( points[i].ff-1 + points[i].ss-1 , points[i].ss-1 );
        
        for(int j=0; j <i ; j++ )
        {
            if( points[i].ff >= points[j].ff && points[i].ss >= points[j].ss )
            {
                int xx = ncr( points[i].ff + points[i].ss - (points[j].ff + points[j].ss) , points[i].ff - points[j].ff );  
                dp[i] -= (dp[j]*xx)%mod;
                dp[i] += mod;
                dp[i] %= mod;
            }
        }
    }
    for(int i=0 ; i<q ; i++ )
    {
        int xx = ncr( m+n-2 - (points[i].ff-1 + points[i].ss-1) , n-1 -points[i].ff+1);
        dp[i] *= xx;
        dp[i] %= mod;
        ans -= dp[i];
        ans += mod;
        ans %= mod;
    }
    cout << ans;
}

Measured memory_bytes: 31616
#include <iostream>

using namespace std;

int main(){
  long long n, m, ans;

  cin >> n >> m;

  if(n >= m/2){
    ans = m/2; 
  }else {
    ans = n;
    ans += (m-n*2)/4;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
	// your code goes here
	int n;
	int a[200100],b[200100];
	cin>>n;
	for(int i=0;i<n;i++){
	    cin>>a[i]>>b[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	
	if(n%2==0){
	    cout<<(b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1<<endl;    
	}else{
	    cout<<b[n/2]-a[n/2]+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 5184
# 動的計画法(dp)
# dp[N](数列)を求めたい。
# dp[0]からdp[N-1]は既知(最小となるっている)とする。
# dp[N] = (dp[N-1] + 1) , (dp[N-6] + 1) , ... , (dp[N-6^i] + 1) , (dp[N-9] + 1) , ... , (dp[N-9^j] + 1)の中から最小のものを選べば良い
# プログラム上では0からNまで回して1つずつ最小化すれば良い
N = int(input())

INF = 10**7
dp = [INF for _ in range(N+1)] # 0からNまで
dp[0] = 0 # 0番目以外は大きい値に初期化

for i in range(1, N+1):
    dp[i] = dp[i-1] + 1
    power = 6
    while power <= N: # N-6^xが非負の範囲で
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6
    power = 9
    while power <= N: # N-9^xが非負の範囲で
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9

print(dp[N])


"""
# 大きい方から貪欲に取るのは誤り(例えば12について、12=9+1+1+1になるが12=6+6の方がより少ない)
N = int(input())

money = [1]
for i in range(1, 100):
    if 6**i <= N:
        money.append(6**i)
    if 9**i <= N:
        money.append(9**i)
    if 6**i > N and 9**i > N:
        break
money.sort()
money.reverse()

zannkinn = N
ans = 0
for i in range(len(money)):
    ans += zannkinn//money[i]
    zannkinn = zannkinn % money[i]
    if zannkinn == 0:
        break

print(ans)
"""

Measured memory_bytes: 3956
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");

   //  String nyu=sc.nextLine();
int[] num=new int[3];
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);

 num[0]=Integer.parseInt(nyu[0]);
 num[1]=Integer.parseInt(nyu[1]);
 num[2]=Integer.parseInt(nyu[2]);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

Arrays.sort(num);


System.out.println(num[2]-num[0]);


	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define REREASE

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define INF 1e9+123
#define ALL(v) v.begin(), v.end()

int main(){
    ll N;
    cin>>N;
    ll sum=0;
    REP(i,N-1){
        sum+=i;
    }
    cout<<sum;
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int binary(int *A, int n, int key){
    int begin = 0, end = n, mid;

    while(begin < end){
        mid = (begin + end) / 2;
        if (A[mid] == key){
            return 1;
        }else if (A[mid] > key){
            end = mid;
        }else{
            begin = mid + 1;
        }
    }

    return 0;
}


int main(void){
    int n, S[100000], q, key, sum = 0;

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%d", &key);
        if(binary(S, n, key)){
            sum++;
        }
    }

    printf("%d\n", sum);
    return 0;
}

/*5
1 2 3 4 5
3      
3 4 1*/


Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

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

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		int[] h = new int[n];
		int ans = 1;
		int maxh = sc1.nextInt();

		for ( int i = 1 ; i < n ; i++) {
			h[i] = sc1.nextInt();
			if (h[i] >= maxh) {
				ans++;
				maxh = h[i];
			}
		}

		System.out.println(ans);

		sc1.close();

	}

}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    int ans = 0;
    while(a>=b) {
        b *= 2;
        ans++;
    }
    while(b>=c) {
        c *= 2;
        ans++;
    }
    // cout << ans << endl;
    if(ans<=k) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int A,B;
	cin>>A>>B;
	
	int ans=0;
	for(int i=A;i<=B;i++){
		if(i%10==(i/10000)%10&&(i/10)%10==(i/1000)%10)
			ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define ll long long
const int maxn=50+10;
ll dp[maxn][maxn][maxn*maxn];
int a[maxn],sum[maxn]; // i Ç°i¸öÊý kºÍÎªk 
int main(){
	int N,A;
	scanf("%d%d",&N,&A);
	for(int i=1;i<=N;i++){
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
		dp[i][0][0]=1;
	}
	dp[0][0][0]=1;
	for(int i=1;i<=N;i++)
		for(int j=1;j<=i;j++)
			for(int k=1;k<=sum[i];k++){
				if(k<a[i])
					dp[i][j][k]=dp[i-1][j][k];
				else
					dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-a[i]];
					
				//printf("[%d,%d,%d]=%d\n", i, j, k, dp[i][j][k]);
			}
	ll ans=0;
	for(int i=1;i<=N;i++)
		ans+=dp[N][i][i*A];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 25136
from itertools import groupby
n, a, b, c, d = map(int, input().split())
s = input()

g = groupby(s[a:c])
h = groupby(s[b:d])

for i, j in g:
    if i == "#" and len(list(j)) > 1:
        print("No")
        exit()

for i, j in h:
    if i == "#" and len(list(j)) > 1:
        print("No")
        exit()

if c < d:
    print("Yes")
    exit()

e = groupby(s[b-2:d+1])
for i, j in e:
    if i == "." and len(list(j)) > 2:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 74196
//https://atcoder.jp/contests/dp/tasks/dp_r
#include <iostream>
#include <vector>
using namespace std;
int const mod = 1e9 + 7;

int mul(int a, int b)
{
    return (long long)a * b % mod;
}
void add_self(int&a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

class Matrix
{
   
    int size;

public:
    vector<vector<int>> mat;
    Matrix(int n)
    {
        size = n;
        mat.assign(size, vector<int>(size));
    }
    void makeit_identical_matrix()
    {
        for (int x = 0; x < size; ++x)
                mat[x][x] = 1;
    }
    Matrix operator*(Matrix const &obj)
    {
        Matrix answer(size);
        for (int i = 0; i < size; ++i)
            for (int j = 0; j < size; ++j)
                for (int k = 0; k < size; ++k)
                   answer.mat[i][k] = (answer.mat[i][k]%mod + mul(mat[i][j], obj.mat[j][k]))%mod;

        return answer;
    }
};

Matrix binary_exponential_mul(Matrix  &mat, long long k, int size)
{
    Matrix answer(size);
    answer.makeit_identical_matrix();
    while (k > 0)
    {
        if (k & 1)
            answer = answer * mat;
            
        mat = mat * mat;
        k = k / 2;
    }
    return answer;
}

int main()
{
    int n;
    long long k;
    cin >> n >>k;
    Matrix m(n);
    for(int i=0; i<n;++i)
      for(int j=0;j<n;++j)
        cin >> m.mat[i][j];
    Matrix result = binary_exponential_mul(m, k, n);
    
    int  answer = 0;
    for(int i=0; i<n;++i)
      for(int j=0;j<n;++j)
        add_self(answer, result.mat[i][j]);
    
    cout << answer <<endl;
        
    return 0;
}

Measured memory_bytes: 384
using System;

class Program
{
	static void Main(string[] args)
	{
		string ret = "";
		// 整数の入力
		int a = int.Parse(Console.ReadLine());
		int b = int.Parse(Console.ReadLine());
		int c = int.Parse(Console.ReadLine());
		int d = int.Parse(Console.ReadLine());
		int e = int.Parse(Console.ReadLine());
		int k = int.Parse(Console.ReadLine());

		// 最大値、最小値を求める
		int max = Math.Max(a, Math.Max(b, Math.Max(c, Math.Max(d, e))));
		int min = Math.Min(a, Math.Min(b, Math.Min(c, Math.Min(d, e))));
		// 最大値と最小値の差がkより大きいか
		if (max - min > k)
		{
			ret = ":(";
		}
		else
		{
			ret = "Yay!";
		}
		//出力
		Console.WriteLine(ret);
	}
}



Measured memory_bytes: 11092
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(s: chars);

    let x = s.iter().filter(|&&c| c == 'x').count();
    if x >= 8 {
        println!("NO");
    } else {
        println!("YES");
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(void) {
    int in[6];

    for (int i = 0; i < 6; i++) cin >> in[i];

    if (in[4] - in[0] > in[5]) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
h, w, m = list(map(int, input().split()))

objects = [list(map(int, input().split())) for _ in range(m)]

rows = [o[0]-1 for o in objects]
cols = [o[1]-1 for o in objects]
obj_dict = {(o[0]-1, o[1]-1): 1 for o in objects}

rows_appearance = [0] * h
for rr in rows:
    rows_appearance[rr] += 1

# print(rows_appearance)
m_row = max(rows_appearance)
m_row_num = 0
row_idx = []
for idx, rr in enumerate(rows_appearance):
    if rr == m_row:
        m_row_num += 1
        row_idx.append(idx)

cols_appearance = [0] * w
for cc in cols:
    cols_appearance[cc] += 1

# print(cols_appearance)
m_col = max(cols_appearance)
m_col_num = 0
col_idx = []
for idx, cc in enumerate(cols_appearance):
    if cc == m_col:
        m_col_num += 1
        col_idx.append(idx)


if m_row_num * m_col_num > m:
    # 鳩の巣原理。objectがないマスが必ずある。
    minus = 0
else:
    minus = 1
    for rr in row_idx:
        for cc in col_idx:
            if (rr, cc) not in obj_dict:
            # if rr, cc に対象物がなければ
                minus = 0
                break

print(m_col + m_row - minus)


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

int main() {
    string S;
    int K;
    cin >> K >> S;
    if(S.size() <= K){cout << S << endl;
    }else{
        for (int i = 0; i < K; i++){
            cout << S.at(i);
        }
        cout <<"..." <<endl;
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s;
	ll k;
	cin>>s>>k;
	for(int i=0;i<s.size();i++){
		if(s[i]!='1'){
			cout<<s[i];
			return 0;
		}
		if(k-1==i){
			cout<<"1";
			return 0;
		}
	}
}

Measured memory_bytes: 256
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


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

    int a, b, c, x, y, z;
    cin >> a >> b >> c;
    x = (a*100)+(b*10)+c;
    if(x % 4 == 0)
        cout << "YES" << endl;
    else
        cout  << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3608
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
 
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let t=read::<i32>();
    
    let ans = b * (t / a);
    
    println!("{}",ans)
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    string tmp;
    int i,j;
    for(i=0;i<s.size();i++){
        tmp=s.at(s.size()-1);
        s.erase(s.size()-1);
        s=tmp+s;
        if(s==t){
            cout << "Yes" << endl;
            return 0;
        }
        //cout << i << " " << tmp << " " << s << endl;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;



template <class iter>
std::pair<complex<double>, double> min_ball(iter left, iter right, int seed = 1333) {
    const int n = right - left;
    using P=complex<double>;
    using ld=double;
    
    assert(n >= 1);
    if (n == 1) {
        return {*left, ld(0)};
    }

    std::mt19937 mt(seed);
    std::shuffle(left, right, mt);
    // std::random_shuffle(left, right); // simple but deprecated

    iter ps = left;
    using circle = std::pair<P, ld>;
    auto cross=[](const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); };
    auto dot=[](const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); };
    auto make_circle_3 = [&](const P &a, const P &b, const P &c) -> circle {
        ld A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b),
           S = cross(b - a, c - a);
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
        ld r2 = std::norm(p - a);
        return {p, r2};
    };

    auto make_circle_2 = [](const P &a, const P &b) -> circle {
        P c = (a + b) / (ld)2;
        ld r2 = std::norm(a - c);
        return {c, r2};
    };

    auto in_circle = [](const P &a, const circle &c) -> bool {
        const double eps=1e-9;
        return std::norm(a - c.first) <= c.second + eps;
    };

    circle c = make_circle_2(ps[0], ps[1]);

    // MiniDisc
    for (int i = 2; i < n; ++i) {
        if (!in_circle(ps[i], c)) {
            // MiniDiscWithPoint
            c = make_circle_2(ps[0], ps[i]);
            for (int j = 1; j < i; ++j) {
                if (!in_circle(ps[j], c)) {
                    // MiniDiscWith2Points
                    c = make_circle_2(ps[i], ps[j]);
                    for (int k = 0; k < j; ++k) {
                        if (!in_circle(ps[k], c)) {
                            c = make_circle_3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

int main(){
    int N;cin>>N;
    vector<complex<double>> pos(N);
    REP(i,N){
        int x,y;
        cin>>x>>y;
        pos[i]=complex<double>(x,y);
    }
    printf("%.16f\n",sqrt(min_ball(All(pos)).second));
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i)
#define ALL(arr) (arr).begin(), (arr).end()
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class T>
T Next() { T buf; cin >> buf; return buf; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "BinaryMatrix.h"
#include "BIT.h"
#include "Factorization.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "LazySegmentTree.h"
#include "Math.h"
#include "Matrix.h"
#include "MinMax.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "UnionFind.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
// template <class T>
// auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

int n, k;
string s;
int main() {
	cin >> n >> k;
	--k;
	cin >> s;
	s[k] -= 'A' - 'a';
	cout << s << endl;
	return 0;
}



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


int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  double sum = 0.0000000;
  for(int i=0;i<n;++i){
      cin>>x[i]>>y[i];
  }
  //////sum
  for(int i=0;i<n;++i){
      for(int j=0;j<n;++j){
          double tot =0;
          tot =((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
          sum += sqrt((double)tot); 
      }
  }
  ////////階乗
  double kaijo=1;
  for(int i=0;i<n;++i){
      kaijo*=i+1;
  }
  double kaijo2=1;
  for(int i=0;i<n-1;++i){
      kaijo2*=i+1;
  }
  cout<<fixed<<setprecision(10)<<sum/n<<endl;

}

Measured memory_bytes: 256
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var ary = new int[8];
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < 8; j++) ary[j] = int.Parse(s[j].ToString());
            var amax = ary.OrderByDescending(x => x).Where(y => y >= 0);
            var resmax = "";
            foreach (var x in amax)
                resmax += x.ToString();
            var resmax0 = int.Parse(resmax);
            var amin = ary.OrderBy(x => x).Where(y => y >= 0);
            var resmin = "";
            foreach (var x in amin)
                resmin += x.ToString();
            var resmin0 = int.Parse(resmin);
            Console.WriteLine(resmax0 - resmin0);
        }

    }
}

Measured memory_bytes: 10060
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int l = Integer.parseInt(sc.next());
    int r = Integer.parseInt(sc.next());
    int d = r-l;
    
    if (d >= 2019) {
      System.out.println("0");
      return;
    }
    
    int pro = 0;
    int ans = 2019;
    
	for (int i=l; i<=r; i++){
      for (int j=i+1; j<=r; j++){
        pro = ((i%2019) * (j%2019) ) % 2019;
        //System.out.println(i+", "+j+" : " + pro);
        if (pro < ans) {
          ans = pro;
        }
      }
    }

    System.out.println(ans);

  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
using namespace std;
// Initialize the matrix with 0 
const int MAXN =2e3+10;
const int MAXR =2e3+10+10;
const int MODN=1e9+7;
int l[MAXN][MAXR] = { 0 }; 
  
void initialize() 
{ 
  
    // 0C0 = 1 
    l[0][0] = 1; 
    for (int i = 1; i < MAXN; i++) { 
        // Set every nCr = 1 where r = 0 
        l[i][0] = 1; 
        for (int j = 1; j < i + 1; j++) { 
  
            // Value for the current cell of Pascal's triangle 
            l[i][j] = (l[i - 1][j - 1] + l[i - 1][j])%MODN; 
        } 
    } 
} 
  
// Function to return the value of nCr 
int nCr(int n, int r) 
{ 
    // Return nCr 
    return l[n][r]; 
} 
int32_t main(){
	int n,k;
	initialize();
	cin>>n>>k;
	for(int sta=1;sta<=k;sta++){
		cout<<(nCr(k-1,sta-1)*nCr(n-k+1,sta))%MODN<<endl;
	}
}

Measured memory_bytes: 30464
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

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;
}
using namespace std;

vector<vector<int>>g;
vector<int>cost,par;


void solve(){
	int n,m;
	cin>>n>>m;
	cost.resize(n,0);
	par.resize(n);
	g.resize(n);
	map<int,int>r;
	int root;
	rep(i,n+m-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		r[b]++;
		g[a].pb(b);
	}
	for(int i=0;i<n;++i){
		if(!r[i])root=i;
	}
	par[root]=root;
	queue<int>q;
	q.push(root);
	while(!q.empty()){//子孫の計算が終わっていない状態で探索を開始するとやり直しになり、TLEになる。
		int v=q.front();
		q.pop();
		for(int x:g[v]){
			r[x]--;
			if(chmax(cost[x],cost[v]+1))par[x]=v+1;
			if(!r[x])q.push(x);
		}
	}
	for(int i=0;i<n;++i){
		if(i==root)cout<<0<<"\n";
		else cout<<par[i]<<"\n";
	}
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 13312
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int x, y, g[1000] = {0};

int main() {

	g[1] = 300000;
	g[2] = 200000;
	g[3] = 100000;

	scanf("%d %d", &x, &y);

	if (x > y) {
		swap(x, y);
	}

	int res = g[x] + g[y];

	if (x == 1 && y == 1) {
		res += 400000;
	}

	printf("%d\n", res);

	return 0;

}

Measured memory_bytes: 3780
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		char[] s_char = s.toCharArray();
		char[] t_char = t.toCharArray();
		Arrays.sort(s_char);
		Arrays.sort(t_char);
		String s_asc = new String(s_char);
		String t_asc = new String(t_char);
		String t_desc = new StringBuilder(t_asc).reverse().toString();
		if(s_asc.compareTo(t_desc) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool ff=0;for(auto outi:v){cout<<(ff?" ":"")<<outi;ff=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
int main(){
  startupcpp();
  int i,N,bf=1;
  string s;
  cin>>s;
  N=s.size();
  rep(i,N-1)if(s[i]!=s[N-i-2])break;
  if((s[N-1]&1)||(~s[0]&1)||i!=N-1){
    print(-1);
    return 0;
  }
  rep(i,N-1){
    print(bf<<" "<<i+2);
    if(s[i]&1)bf=i+2;
  }
}

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

int main() {
  int n, m, i;
  cin >> n >> m;
  
  vector<vector<int>> x(n, vector<int>(2));
  for(i = 0; i < n; i++){
    cin >> x.at(i).at(0) >> x.at(i).at(1);
  }
  
  sort(x.begin(), x.end());
  
  int j = 0, a, b;
  long long ans = 0;
  pair<int, int> y;
  priority_queue<pair<int, int>> pq;
  for(i = 1; i <= m; i++){
    while(j < x.size() && x.at(j).at(0) <= i){
      a = x.at(j).at(0);
      b = x.at(j).at(1);
      pq.push(make_pair(b, a));
      j++;
    }
    if(!(pq.empty())){
      y = pq.top();
      ans += y.first;
      pq.pop();
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 6904
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

    auto one_try = 1900 * M + 100 * (N-M);
    auto p_success = pow(1.0/2, M);

    cout << one_try / p_success << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

int main(){
  long n,a,b;
  cin>>n>>a>>b;
  long mn = a*(n-1)+b;
  long mx = a+b*(n-1);

  cout << max(0L,mx-mn+1) << endl;

  return 0;
}


Measured memory_bytes: 768