akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    
    int set_AB = 0;
    if(A+B>=C*2){
      set_AB = C*2;
    }else{
      set_AB = A+B;
    }
    int common = Math.min(X,Y);
    int max = Math.max(X,Y);
    
    int last_price = 0;
    if(X>=Y){
      last_price = A;
    }else{
      last_price = B;
    }
    
    int last = max-common;//残りの枚数、値段は枚数が多いほう
    int extra = 0;
    if(last_price>=C*2){
       extra = C*2*last;
      }else{
       extra = last_price*last;
      }
   
    int charge = set_AB*common+extra;
    System.out.println(charge);
  }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
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;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
//#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;
const double e = 1e-10;

void debug_vector(vector<int>& v)
{
    int n = v.size();
    for (int i = 0; i < n; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}


//////////////////////
//// coding start ////
//////////////////////

// global variety

// function
void solve();

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

void solve(){
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans1, ans2;
    sort(all(A));
    if (N == 2){
        ans2 = A[0];
        ans1 = A[1];
        printf("%lld %lld\n", ans1, ans2);
        return ;
    }
    ans1 = A[N-1];
    ll tmp = ans1 / 2;
    auto iter = lower_bound(all(A), tmp);
    int ind = iter - A.begin();
    ans2 = (A[ind-1] > ans1 - A[ind] ? A[ind-1] : A[ind]);
    printf("%lld %lld\n", ans1, ans2);
}



Measured memory_bytes: 1024
import collections
que_a = collections.deque(input())
que_b = collections.deque(input())
que_c = collections.deque(input())

card = "a"

while 1:
    if card == "a":
        if len(que_a) == 0:
            print("A")
            break
        card = que_a.popleft()
        
    if card == "b":
        if len(que_b) == 0:
            print("B")
            break
        card = que_b.popleft()
        
        
    if card == "c":
        if len(que_c) == 0:
            print("C")
            break
        card = que_c.popleft()

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

int main() {
  int N, A;
  int tmp_A;
  cin >> N;
  cin >> A;
 
  tmp_A = N % 500;
  
  if (tmp_A <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl; 
  }
}

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

struct UnionFind {
	vector <int> r;

	UnionFind(int n) {
		r = vector<int>(n, -1);
	}

	int root(int x) {
		if(r[x] < 0) return x;
		return r[x] = root(r[x]);
	}

	bool Union(int x, int y) {
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if(r[x] > r[y]) swap(x, y);
		r[x] += r[y];
		r[y] = x;
		return true;
	}

	int size(int x) {
		return -r[root(x)];
	}
};


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

	UnionFind UF(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a -= 1;
		b -= 1;
		UF.Union(a, b);
	}

	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans = max(ans, UF.size(i));
	}

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

Measured memory_bytes: 3916
#include <bits/stdc++.h>          
using namespace std;               
typedef long long ll;
int main() {
    ll N,M;
    cin >> N >> M;
    vector<ll> p(M);
    vector<string> S(M);
    for (ll i=0; i<M; i++) {
        cin >> p[i] >> S[i];
    }
    vector<vector<ll>> kaitou(N,vector<ll>(2,0));
    ll countAC = 0;
    ll countWA = 0;
    for (ll i=0; i<M; i++) {
        if (S[i] == "AC") {
            if (kaitou.at(p[i]-1).at(0) == 0) {
                kaitou.at(p[i]-1).at(0) = 1;
            }
        }
        else if (kaitou.at(p[i]-1).at(0) == 0){
            kaitou.at(p[i]-1).at(1)++;
        }
    }
    for (ll i=0; i<N; i++) {
        countAC += kaitou.at(i).at(0);
        if (kaitou.at(i).at(0) == 1) {
            countWA += kaitou.at(i).at(1);
        }
    }
    cout << countAC << " " << countWA << endl;
}

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

int w , h ;
int gx , gy , color , ans ;
int map[101][101] = {} ;
int dx[] = { 0,1,0,-1 } ;
int dy[] = { 1,0,-1,0 } ;

void judge( int nx , int ny ){
	if( nx==gx && ny==gy ) ans = 1 ;
	
	map[nx][ny] = 0 ;
	
	for( int i=0 ; i<4 ; i++ ){
		if( nx+dx[i]>0 && nx+dx[i]<=w && ny+dy[i]>0 && ny+dy[i]<=h )
			if( map[nx+dx[i]][ny+dy[i]] == color )
				judge( nx+dx[i] , ny+dy[i] ) ;
	}
}

int main(){
	
	int sx , sy ;
	int n ;
	int c , d , x , y ;
	int a , b ;
	
	while(1){
		cin >> w >> h ;
		if( w==0 && h==0 ) break;
		
		cin >> sx >> sy ;
		cin >> gx >> gy ;
		cin >> n ;
		
		for( int i=0 ; i<n ; i++ ){
			cin >> c >> d ;
			cin >> x >> y ;
			if( d==0 ){
				a = 4 ;
				b = 2 ;
			}else {
				a = 2 ;
				b = 4 ;
			}
			
			for( int j=x ; j<=x+a ; j++ ){
				for( int k=y ; k<=y+b ; k++ ){
					map[j][k] = c ;
					if( sx==j && sy==k ) color = c ;
				}
			}
		}
		
		ans = 0 ;
		judge( sx , sy ) ;
		
		if( ans == 1 ) cout << "OK" << endl ;
		else cout << "NG" << endl ;
		
		for( int i=1 ; i<w ; i++ )
			for( int j=1 ; j<h ; j++ )
				map[i][j] = 0 ;
	}
	
return 0;
}

Measured memory_bytes: 1196
N = input()
K = int(input())
m = len(N)
dp = [[[0] * (K+1) for _ in range(2)] for _ in range(m+1)]
dp[0][0][0] = 1

for i in range(1, m+1):
    l = int(N[i-1])
    for k in range(K+1):
        dp[i][1][k] += dp[i-1][1][k]
        if l != 0:
            dp[i][1][k] += dp[i-1][0][k]
        else:
            dp[i][0][k] += dp[i-1][0][k]
        if k - 1 >= 0:
            dp[i][1][k] += 9 * dp[i-1][1][k-1]
            if l != 0:
                dp[i][0][k] += dp[i-1][0][k-1]
                dp[i][1][k] += (l - 1) * dp[i-1][0][k-1]
print(dp[m][0][K] + dp[m][1][K])



Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int a, b;
	cin >> a >> b;
	a--;
	b--;
	vector<bool> v(3, true);
	v[a] = false;
	v[b] = false;
	for (int i = 0; i < 3; i++)
	{
		if (v[i])
			cout << i + 1 << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0 #必要な最小の水やり操作の回数
active = 0 #直前の花の高さ

for i in range(n):
    if active < h[i]: #直前の花より大きかったら(h[i]-前の花の高さ)を求める
        ans += h[i] - active
    active = h[i]

print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    string s;cin>>s;
    if(s=="ani"){
        cout<<"square1001"<<endl;
    }else{
        cout<<"e869120"<<endl;
    }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_V 5000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long int MOD = 1000000007;
const long long int INF = 10000000000000000;

int n, m;
int e[1000];
vector<int> r[1000];
int id[1000];
bool saw[1000];
ll ans = 1;

bool check(int v, int p){
    if(saw[v]) return true;
    if(e[v] == -1) return true;
    
    bool ret = true;
    saw[v] = true;
    if(e[v] == p){
        ret = false;
        id[v] = p;
        return ret;
    }
    ret = check(e[v],p);
    
    if(!ret) id[v] = p;
    return ret;
}

ll dfs(int v){
    v = id[v];
    ll ret = 1;
    if(r[v].size() == 0){
        return 2;
    }
    rep(i,r[v].size()){
        ret = (ret*dfs(r[v][i]))%MOD;
    }
    return (ret+1)%MOD;
}

int main(){
    cin >> n >> m;
    rep(i,n) id[i] = i;
    memset(e,-1,sizeof(e));
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a] = b;
        r[b].push_back(a);
    }
    rep(i,n){
        memset(saw,0,sizeof(saw));
        if(id[i] != i) continue;
        check(i,i);
    }
    rep(i,n){
        if(id[i] != i){
            copy(r[i].begin(),r[i].end(),back_inserter(r[id[i]]));
            sort(r[id[i]].begin(),r[id[i]].end());
            r[id[i]].erase(unique(r[id[i]].begin(),r[id[i]].end()),r[id[i]].end());
        }
    }
    rep(i,n){
        if(id[i] != i) continue;
        if(id[e[i]] == i) e[i] = -1;
        vector<int> z;
        rep(j,r[i].size()){
            if(id[r[i][j]] != i) z.push_back(r[i][j]);
        }
        r[i] = z;
       
    }
    rep(i,n){
        if(e[i] != -1) continue;
        if(id[i] != i) continue;
        ans = ans*dfs(i)%MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3184
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int ans = Math.min(n * a, b);

            // 出力
            out.println(ans);

        }

    }
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
///////////////////PnC/////////////////////
vl Fac(MAX),Inv(MAX);
void CalcFac()
{
	Fac[0]=Inv[0]=1;
	for(int i=1;i<MAX;i++)
	{
		Fac[i]=(Fac[i-1]*i)%MOD;
		Inv[i]=powN(Fac[i],MOD-2);
	}
}

ll NCR(int n,int r)
{
	if(r>n) return 0;
	return (((Fac[n]*Inv[r])%MOD)*Inv[n-r])%MOD;
}
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000<<endl;
}	

Measured memory_bytes: 22960
def resolve():
    import heapq
    n, m = map(int, input().split())
    a = list(map(lambda x:int(x)*-1, input().split()))
    heapq.heapify(a)
    for i in range(m):
        maxa = heapq.heappop(a) * -1
        maxa //= 2
        heapq.heappush(a, -maxa)
    print(sum(a)*-1)
resolve()

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 999;// 1e25;
static const ll MAX_N = 100001;

ll N, K, t, d;
pair<ll, int> A[100010];
int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> t >> d;
		A[i] = { d,t };
	}
	map<int, ll> m;
	sort(A + 1, A + N + 1);
	ll ans = 0, sum = 0, r = 0;
	for (int i = N; i >= 1; i--) {
		if (i >= N - K + 1) {
			m[A[i].second]++;
			sum += A[i].first;
			if (i == N - K + 1) {
				ll s = m.size();
				ans = sum + s * s;
				r = N - K + 1;
			}
		}
		else {
			if (!m.count(A[i].second)) {
				m[A[i].second]++;
				while (r <= N && m[A[r].second] == 1) r++;
				if (r == N + 1) break;
				sum += A[i].first - A[r].first;
				m[A[r].second]--; r++;
				ll s = m.size();
				ans = max(ans, sum + s * s);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i,0,n){
        cin >> s[i];
    }

    string ans = "";
    for (char c = 'a'; c <= 'z'; c++){
        int small = 100;
        REP(i,0,n){
            int cnt = 0;
            REP(j,0,s[i].size()){
                if (s[i][j] == c) cnt++;
            }
            small = min(small, cnt);
        }
        REP(i,0,small){
            ans += c;
        }
    }

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

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=998244353;
const int maxn=1e6+100;
const int N=2e5+100;
const int M=2e6+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


int main()
{
#ifdef local
      freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    IOS;cout.tie(0);
    int n;cin>>n;
    ll ans=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=i;j<=n;j+=i) ans+=j;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {  //
    int n;
    cin >> n;
    int ans[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ans[a - 1] = i + 1;
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << ' ';
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define vll vector<ll>
#define pll pair<ll ,ll >
#define vpll vector< pll >
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
//#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll modinv(ll a , ll mod = MOD){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll binomialCoeff(ll n,ll k) 
{ 
    ll res = 1; 
    if ( k > n - k ) 
        k = n - k; 

    for (  ll i = 0; i < k; ++i) 
    { 
        res = (res* (n - i))%MOD; 
        res = (res* modinv(i + 1))%MOD; 
    } 
    return res; 
} 

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll t=1;
    // cin>>t;
    while(t--){
        ll n,x,k,c=0,sum=0;
        cin>>n>>k;
        vll a(n),ans(n,MOD);
        forn(i,n) cin>>a[i];
        ans[0]=0;
        forn(i,n){
            for1(j,k){
                if(i-j>=0){
                    // cout<<i<<" "<<j<<endl;
                    ans[i]=min(ans[i],ans[i-j]+abs(a[i]-a[i-j]));
                }
            }
            // if(i-1>=0){
            //     ans[i]=ans[i-1]+abs(a[i]-a[i-1]);
            // }
            // if(i-2>=0){
            //     ans[i]=min(ans[i],ans[i-2]+abs(a[i]-a[i-2]));
            // }
            // cout<<ans[i]<<" ";
        }
        // cout<<endl;
        cout<<ans[n-1]<<endl;
    }
    // #ifndef ONLINE_JUDGE
    //    cout<<endl<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec"<<endl;
    // #endif
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
    int     n;
    int     interval;
    int     c;
    int     t;
    int     mincost = 1001;
    int     i;
    scanf("%d %d", &n, &interval);
    for(i = 0; i < n; i++){
        scanf("%d %d", &c, &t);
        if(t <= interval){
            if(c < mincost){
                mincost = c;
            }
        }
    }
    if(mincost == 1001) printf("TLE\n");
    else{
        printf("%d\n", mincost);
    }

    return (0);
}

Measured memory_bytes: 128
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };
    let (n, m) = {
        let mut ws = s.split_whitespace();
        let n: i32 = ws.next().unwrap().parse().unwrap();
        let m: i32 = ws.next().unwrap().parse().unwrap();
        (n, m)
    };
    println!("{} {}",n*m,2*(m+n));
}


Measured memory_bytes: 5036
import sys


def main():
    n, m = map(int, sys.stdin.readline().split())
    g = [[] for i in range(n)]
    deg = [0] * n
    lines = sys.stdin.read().splitlines()
    for line in lines:
        l, r, d = map(int, line.split())
        g[l - 1].append((r - 1, d))
        deg[r - 1] += 1
    dis = [-1] * n
    for i in range(n):
        if deg[i]:
            continue
        stack = list([i])
        dis[i] = 0
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if dis[u] == -1:
                    dis[u] = dis[v] + d
                    stack.append(u)
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 125496
#include<stdio.h>
#include<algorithm>
using namespace std;
int mod;
pair<double,int> v[131072];
int bit[131072];
int sum(int a,int b){
	if(a==0){
		int ret=0;
		for(b;b>=0;b=(b&(b+1))-1)ret=(ret+bit[b])%mod;
		return ret;
	}return (sum(0,b)-sum(0,a-1)+mod)%mod;
}
void add(int a,int b){
	for(;a<131072;a|=a+1)bit[a]=(bit[a]+b)%mod;
}
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),c){
		mod=c;
		b++;
		for(int i=a;i<b;i++){
			double now=(double)i;
			int keta=-1;
			int t=i;
			while(t){
				now*=0.1;
				keta++;
				t/=10;
			}
			now+=keta*(1e-11);
			v[i-a]=make_pair(now,i-a);
		}
		std::sort(v,v+b-a);
		for(int i=0;i<131072;i++)bit[i]=0;
		for(int i=0;i<b-a;i++){
			add(v[i].second,sum(0,v[i].second)+1);
		}
		printf("%d\n",sum(0,131071));
	}
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
 
void nhi_degi()
{
   int s,w;cin>>s>>w;
   if(s<=w)
   {
       cout<<"unsafe\n";
   }
   else
   {
       cout<<"safe\n";
   }

}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	double r;
	cin >> r;
	double a = r * r * M_PI;
	double e = 2 * r * M_PI;
	cout << fixed << setprecision(6) << a
		<< " " << fixed << setprecision(6) << e << endl;
	return 0;
}


Measured memory_bytes: 3152
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=100000+10;
int S[30];
char s[MAXN];
int main()
{
	scanf("%s",s);
	for(register int i=0;i<strlen(s);++i)S[s[i]-'a'+1]++;
	for(register int i=1;i<=26;++i)
		if(!S[i])
		{
			printf("%c\n",i+'a'-1);
			return 0;
		}
	printf("None\n");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i;
    long long sum=0;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0) sum+=i;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define MOD 1000000007
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int W,a,b;
    cin >> W >> a >> b;
    if(a<=b) cout << max(b-a-W,0) << endl;
    else cout << max(a-b-W,0) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000010,P=998244353;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int L=1,h[N],ne[N],to[N],f[N],sz[N],n,g[N];
void addl(int x,int y){
	ne[++L]=h[x];h[x]=L;to[L]=y;
	ne[++L]=h[y];h[y]=L;to[L]=x;
}
int tp,st[N];
void dfs(int x){
	int k;
	for(k=h[x],h[x]=ne[h[x]];k;k=h[x],h[x]=ne[h[x]])
	if(!f[k/2])f[k/2]=k%2+1,dfs(to[k]);st[++tp]=x;
}
int main(){
	//freopen("1.out","w",stdout);
	int i;
	n=read();
	for(i=1;i<=n+n;i++){
		int x=read();
		if(x<0)x=n+n+1;
		else if(i>n)x+=n;
		sz[x]++;addl(x,i);
	}
	for(i=1;i<=n;i++)if(sz[i]%2!=sz[i+n]%2){
		puts("IMPOSSIBLE");return 0;
	}else{if(sz[i]%2==0)addl(i,n+i),g[i]=L/2;}
	dfs(n+n+1);
	for(i=1;i<=n;i++)
	if(sz[i]%2==0){
		if(f[g[i]]==2)g[i]=-1;else g[i]=1;
		g[i+n]=-g[i];
	}
	puts("POSSIBLE");
	for(i=1;i<=n;i++)printf("%d ",g[i]);
	return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if ((N * A) > B) {
    cout << B << endl;
  }
  else if ((N * A) <= B) {
    cout << N * A << endl;
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
//#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 21474836

int H,W,N;

int main() {	

	cin >> H >> W >> N;

	int ans = 0;
	if (H > W) {
		ans = (N-1) / H + 1;
	}
	else {
		ans = (N-1) / W + 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg = 1000000007;
#define ff(i,n) for(i=0;i<n;i++) 
void dfs(ll i,ll vis[],ll p[],vector<vector<ll> > &adj,ll par)
{
	vis[i] = 1;
	p[i] = par;
	ll j;
	for(j=0;j<adj[i].size();j++)
	{
		if(vis[adj[i][j]]==0)
		{
			dfs(adj[i][j],vis,p,adj,i);
		}
	}
}
int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=0;
	while(b<=a)
	{
		b*=2;
		ans++;	
	}    
	while(c<=b)
	{
		c*=2;
		ans++;
	}
	if(ans<=k)
	   cout<<"Yes";
	else
	   cout<<"No";   
	return 0;
} 

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

int n;
string s;
int maxVal()
{
	int x = 0, val = 0;
	for(int i = 0; i < n; ++i) {
		if(s[i] == 'I')
			++val;
		else
			--val;
		x = max(x, val);
	}
	return x;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> s;

	cout << maxVal() << endl;

	return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  
  int t;
  for(int i = 0; i < 3; i++){
    if(S.at(i) == T.at(i)){
      t++;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 256
import math

a,b,x = map(int,input().split())
case = 0
x = x/a

if x<a*b/2:
  case = 1
  
if case == 0:
  print(math.degrees(math.atan2((a*b-x)*2/a,a)))
else:
  print(90-math.degrees(math.atan2(2*x/b,b)))

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

typedef long long llong;

const int maxn=2*1e5+10;

struct edge{
int x,y,d;
bool operator < (const edge &e) const
{
    return d>e.d;
}
}a[maxn];

int n,h,w,c[maxn],fa[maxn];
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}

int main()
{
    scanf("%d%d%d",&n,&h,&w);
    for(int i=0;i<n;i++)
        scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].d),a[i].y+=h;
    sort(a,a+n);
    for(int i=1;i<=h+w;i++) fa[i]=i,c[i]=1;
    llong ans=0;
    for(int i=0;i<n;i++)
    {
        int x=find(a[i].x),y=find(a[i].y);
        if(x!=y) c[y]+=c[x],fa[x]=y;
        if(c[y]) c[y]--,ans+=a[i].d;
    }
    cout<<ans<<endl;
    return 0;

}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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 long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

long long GCD(long long a, long long b) {
    return b != 0 ? GCD(b, a % b) : a;
}
long long LCM(long long a, long long b) {
    return a * b / GCD(a, b);
}

int main() {
    ll N, M; cin >> N >> M;
    string s, t; cin >> s >> t;
    ll g = GCD(N, M);
    ll n = N / g, m = M / g;
    bool can = true;
    rep(i, g) {
        if (s[n * i] != t[m * i]) {
            can = false;
            break;
        }
    }
    cout << (can ? LCM(N, M) : -1) << endl;
}

Measured memory_bytes: 640
#define FILEIO(a) freopen(a".in", "r", stdin); freopen(a".out", "w", stdout);
#include <cstdio>
#include <algorithm>

typedef long long ll;

const int N = 8005;
const int S = 1 << 17;
const int cIz = 998244353, g_cIz = 3;

inline int Pow(int a, int b) {
	int ans = 1;
	for (; b; b >>= 1) {
		if (b & 1) ans = (ll)ans * a % cIz;
		a = (ll)a * a % cIz;
	}
	return ans;
}
inline int Inv(int a) {
	return Pow(a, cIz - 2);
}

inline int getL(int n) {
	int L = 1;
	while (L < n) L <<= 1;
	return L;
}

int rev[S];
inline void init_rev(int n) {
	rev[0] = 0;
	for (int i = 1; i < n; ++i) {
		rev[i] = rev[i >> 1] >> 1 | ((i & 1) * n) >> 1;
	}
}

void NTT(int *f, int n, bool flag) {
	for (int i = 0; i < n; ++i) {
		if (i < rev[i]) std::swap(f[i], f[rev[i]]);
	}
	const int g = flag ? Inv(g_cIz) : g_cIz;
	for (int i = 1; i < n; i <<= 1) {
		const int e = Pow(g, (cIz - 1) / (i << 1));
		for (int j = 0; j < n; j += i << 1) {
			int w = 1;
			for (int k = 0; k < i; ++k) {
				int tmp = (ll)w * f[j | k | i] % cIz;
				f[j | k | i] = (f[j | k] - tmp + cIz) % cIz;
				f[j | k] = (f[j | k] + tmp) % cIz;
				w = (ll)w * e % cIz;
			}
		}
	}
}

void div_n(const int *A, int *B, int n) {
	const int inv_n = cIz - (cIz - 1) / n;
	for (int i = 0; i < n; ++i) B[i] = (ll)A[i] * inv_n % cIz;
}

void poly_mul(const int *A, const int *B, int *C, int n) {
	static int a[S], b[S];
	init_rev(n);
	std::copy(A, A + n, a);
	std::copy(B, B + n, b);
	NTT(a, n, 0);
	NTT(b, n, 0);
	for (int i = 0; i < n; ++i) a[i] = (ll)a[i] * b[i] % cIz;
	NTT(a, n, 1);
	div_n(a, C, n);
}

int fac[N], ifac[N];

void init_fac(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = (ll)fac[i - 1] * i % cIz;
	ifac[n] = Inv(fac[n]);
	for (int i = n; i; --i) ifac[i - 1] = (ll)ifac[i] * i % cIz;
}
inline int C(int n, int m) {
	if (m < 0 || m > n) return 0;
	return (ll)fac[n] * ifac[m] % cIz * ifac[n - m] % cIz;
}

int main() {
//	FILEIO("matrix")
	static int f[2][S], A[S], B[S];
	int n, m;
	scanf("%d%d", &n, &m);
	init_fac(n + 2);
	int L = getL(2 * n + 1);
	int *pre = f[0], *cur = f[1];
	for (int i = 1; i <= n; ++i) A[i] = ifac[i + 2];
	for (int i = 0; i <= n; ++i) cur[i] = 1;
	for (int i = 2; i <= m; ++i) {
		std::swap(pre, cur);
		for (int j = 0; j <= n; ++j) {
			B[j] = (ll)pre[j] * ifac[j] % cIz;
		}
		std::fill(B + n + 1, B + 2 * n + 1, 0);
		poly_mul(A, B, B, L);
		for (int j = 0; j <= n; ++j) {
			cur[j] = ((ll)pre[j] * (j * (j + 1) / 2 + 1) + (ll)fac[j + 2] * B[j]) % cIz;
		//	printf("f[%d][%d] = %d\n", i, j, cur[j]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; ++i) ans = (ans + (ll)cur[i] * C(n, i)) % cIz;
	printf("%d\n", ans);
	return 0;
}

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

int ans[365],c[26],s[365][26],last[26],csum,nowscore,newscore,RAND;
const int INF=1e9,d=365,starttemp=4000,endtemp=100;
double temperature,prob;

#define REP(i,n) for(int i=0;i<n;i++)

void FIN(bool a){
  if(a){
    ofstream fout("output.txt");
    REP(i,d)fout<<ans[i]+1<<"\n";
    fout.close();
    return;
  }
  REP(i,d)cout<<ans[i]+1<<"\n";
  return;
}
/*
int score(){
  int res=0;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    last[ans[day]]=day;
    REP(i,26)res-=c[i]*(day-last[i]);
  }
  return res;
}
*/
int score(){//上のがO(26*365)、こっちがO(365)のスコア計算
  int res=0,minus=csum;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    minus-=c[ans[day]]*(day-last[ans[day]]);
    last[ans[day]]=day;
    res-=minus;
    minus+=csum;
  }
  return res;
}
void swap(){
  RAND+=abs(newscore);
  RAND=(RAND&256)+(RAND&64)+(RAND&32)+(RAND&4);
  int day=RAND,diff=((RAND^newscore)&7)+1;
  swap(ans[day],ans[day+diff]);
  newscore=score();
  prob=exp((newscore-nowscore)/temperature);
  if(prob>(rand()%INF)/(double)INF)nowscore=newscore;
  else swap(ans[day],ans[day+diff]);
}
void onechange(){
  RAND+=abs(newscore);
  RAND=(RAND&256)+(RAND&64)+(RAND&32)+(RAND&4);
  int day=RAND;
  REP(i,26){
    int tmp=ans[day];
    ans[day]=i;
    newscore=score();
    prob=exp((newscore-nowscore)/temperature);
    if(prob>(rand()%INF)/(double)INF)nowscore=newscore;
    else ans[day]=tmp;
  }
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  clock_t start=clock();
  memset(last,-1,sizeof(last));
  cin>>c[0];
  REP(i,26){cin>>c[i];csum+=c[i];}
  REP(i,d)REP(j,26)cin>>s[i][j];
  REP(day,d){
    int idx,mx=-INF;
    REP(i,26){
      int A=c[i]*(day-last[i])+s[day][i];
      if(mx<A)mx=A,idx=i;
    }
    ans[day]=idx,last[idx]=day;
  }
  nowscore=score();
  while(true){
    clock_t nowt=clock();
    const double Time=static_cast<double>(nowt-start)/CLOCKS_PER_SEC;
    if(Time>1.97)break;
    temperature=starttemp+(double)(endtemp-starttemp)*(nowt-start)/(CLOCKS_PER_SEC*1.97);
    REP(_,50)
      if((_^newscore)&1)swap();
      else onechange();
  }
  FIN(0);
}


Measured memory_bytes: 4324
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007LL
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int h,w;
    cin >> h >> w;
    ll costs[10][10];
    rep(10)repp(j,10) cin >> costs[i][j];
    rep(10)repp(j,10)repp(k,10) costs[j][k] = min(costs[j][k], costs[j][i]+costs[i][k]);

    ll ans = 0, tmp;
    rep(h)repp(j,w){
        cin >> tmp;
        if(tmp != -1 && tmp != 1){
            ans += costs[tmp][1];
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module AGC017 =
    let private ``Moderate Differences`` () =
        let g64 = ReadNextInt >> int64
        let pn = g64 ()
        let diff =
            let a, b = Read2Int ()
            abs (b - a) |> int64
        //printfn "diff %d" diff
        let c, d = g64 (), g64 ()
        let n = pn - 1L
        let rec check i =
            if i + i > n then false
            else
                let dl, du = i * c, i * d
                let ul, uu = (n - i) * c, (n - i) * d
                let rl, ru =
                    let l, u = ul - du, uu - dl
                    if 0L < l then l, u
                    else 0L, max (-l) u
                //printfn "%d : [%d, %d] - [%d, %d] => [%d, %d]" i ul uu dl du rl ru
                if rl <= diff && diff <= ru then true
                else check (i + 1L)
        if check 0L then "YES" else "NO"
        |> printfn "%s"

    let Entry = ``Moderate Differences``

AGC017.Entry ()

Measured memory_bytes: 18136
n, m = gets.chomp.split.map(&:to_i)
cnt = Array.new(n, 1)
visited = Array.new(n) { false }
visited[0] = true

m.times do
  x, y = gets.chomp.split.map(&:to_i)
  x -= 1
  y -= 1
  if visited[x]
    visited[y] = true
  end
  cnt[x] -= 1
  cnt[y] += 1
  if cnt[x] == 0
    visited[x] = false
  end
end

puts (0...n).count{|i| cnt[i] > 0 && visited[i] }

Measured memory_bytes: 15732
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
const int maxn=500010;
int n,m;
bool v[maxn];
struct Interval {
	int l,r;
	bool operator < (const Interval &t) const{
		return l==t.l?r>t.r:l<t.l;
	}
}t[maxn];
int s[maxn<<2],o;
int ad;
int In() {
	register char c;
	for(;c=getchar(),c!='-'&&!isdigit(c););
	register bool f=c=='-';
	register int s=f?0:c-'0';
	for(;c=getchar(),isdigit(c);)s=s*10+c-'0';
	return f?-s:s;
}
int dmin(register int x,register int y) {
	return x<y?x:y;
}
void mdf(register int x,register int v) {
	if(s[x+=o]<=v) return;
	for(s[x]=v;x>>=1;s[x]=dmin(s[x<<1],s[x<<1|1]));
}
int qry(register int l,register int r) {
	register int z=0x3f3f3f3f;
	for(l+=o-1,r+=o+1;l^r^1;l>>=1,r>>=1)~l&1?z=dmin(z,s[l^1]):0,r&1?z=dmin(z,s[r^1]):0;
	return z;
}
int main() {
	n=In();
	for(register int i=1;i<=n;++i)ad+=!(v[i]=In());
	m=In();
	for(register int i=1;i<=m;++i)t[i]=(Interval){In(),In()};
	std::sort(t+1,t+m+1);
	memset(s,63,sizeof s);
	for(o=1;o<=n+1;o<<=1);
	mdf(0,0);
	for(register int i=1,j=1;i<=n;++i) {
		for(;j<=m&&t[j].l==i;++j)mdf(t[j].r,qry(i-1,t[j].r)); 
		mdf(i,s[i-1+o]+(v[i]?1:-1));
	}
	printf("%d\n",s[n+o]+ad);
	return 0;
}

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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int N, i, j, flag;
	bool b = false;
	cin >> N;
	vector<int> v(N);
	REP(i, N) cin >> v[i];

	for(i = 0; i < N; i++){
		for(j = i; j < N; j++){
			flag = 0;
			swap(v[i], v[j]);
			REP(k, N){
				if(v[k] == k+1){
					flag += 1;
				}
				if(flag == N){
					b = true;
					i = N-1;
					j = N-1;
				}
			}
			swap(v[i], v[j]);
			//cout << flag << endl;
		}
	}
	if(b) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string str1,str2;
    unsigned int len_1,len_2,i,phase_1=0,phase_2=1;
    cin>>str1>>str2;
    for(len_1=0;str1[len_1]!='\0';len_1++)
    for(len_2=0;str2[len_2]!='\0';len_2++)
    if(len_1+1 == len_2) phase_1=1;
    for(i=0;i<len_1;i++){
        if(str1[i]!=str2[i]){
            phase_2=0;
            break;
        }
    }
    if(phase_1==1 && phase_2==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

class Node {
public:
    int cost, r, c;
    bool operator > ( const Node right ) const {
        return cost == right.cost ? ( r == right.r ? ( c == right.c ? false : c > right.c ) : r > right.r ) : cost > right.cost;
    }
    Node() {}
    Node( int cost, int r, int c ): cost(cost), r(r), c(c) {}
};

typedef priority_queue <Node, vector <Node>, greater <Node> > QUEUE;
const int size = 51;

int main() {
    int h, w;
    cin >> h >> w;
    int M[size][size];
    for ( int i = 0; i < h; i++ ) {
        for ( int j = 0; j < w; j++ ) {
            char c;
            cin >> c;
            M[i][j] = c - '0';
        }
    }

    int answer = 0;
    QUEUE Q;
    Node start_node( M[0][0], 0, 0 );
    Q.push( start_node );
    int V[size][size];
    for ( int i = 0; i < h; i++ ) {
        for ( int j = 0; j < w; j++ ) {
            V[i][j] = 1<<24;
        }
    }

    while ( !Q.empty() ) {
        Node node = Q.top();
        Q.pop();

        int cost = node.cost;
        int r = node.r;
        int c = node.c;
        if ( r == h-1 && c == w-1 ) {
            answer = cost;
            break;
        }

        int dr[2] = { 0, 1 };
        int dc[2] = { 1, 0 };
        for ( int i = 0; i < 2; i++ ) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if ( nr >= h || nc >= w ) continue;
            int ncost = cost + M[nr][nc];
            if ( ncost >= V[nr][nc] ) continue;
            V[nr][nc] = ncost;
            Node next_node( ncost, nr, nc );
            Q.push( next_node );
        }
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int q,t,f,cnt=0; 
char c;
int main()
{
	cin>>s;
	cin>>q;
	while(q--)
	{
		cin>>t;
		if(t==1) cnt++;
		else
		{
			cin>>f>>c;
			if(cnt%2==0)
			{
				if(f==1) s.insert(s.begin(),c);
				else s.insert(s.end(),c);
			}
			else
			{
				if(f==1) s.insert(s.end(),c);
				else s.insert(s.begin(),c);
			}
		}
	}
	if(cnt%2!=0) reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <math.h>

main(){
    int n,x,i,j,a=0,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        k=(int)sqrt(x);
        j=2;
        while(1){
            if(j>k){
                a++;
                break;
            }
            if(x%j==0){break;}
            if(j==2){j++;}else{j+=2;}
            
        }
    }
    printf("%d\n",a);
}


Measured memory_bytes: 2092
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v : Vec<i32> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let mut ans = 0;
    if v[0] == v[1] {
        ans = v[2];
    }
    else if v[1] == v[2] {
        ans = v[0];
    }
    else {
        ans = v[1];
    }
    println!("{}", ans);
}


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

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

  vector<vector<char>> a(H, vector<char>(W));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a.at(i).at(j);
    }
  }

  vector<int> goodH(110);
  vector<int> goodW(110);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '#') {
        goodH.at(i) = true;
        goodW.at(j) = true;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    if (goodH.at(i)) {
      for (int j = 0; j < W; j++) {
        if (goodW.at(j)) {
          cout << a.at(i).at(j);
        }
      }
       cout << endl;
    }
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
}

Measured memory_bytes: 9680