akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <unordered_map>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <limits.h>
#include <tgmath.h>

using namespace std;

typedef uint16_t ui16;
typedef uint32_t ui32;
typedef uint64_t ui64;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef long double ld;
typedef pair<int, int> pr;

//template<typename T> inline T abs(T a) { return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a) { return a * a; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) {for (int i = 0; i < v.size(); ++i) cout << v[i] << " "; cout << endl; return cout; }
void print() { cout << endl; }
template<typename T, typename... Ts> void print(T x, Ts... xs) { cout << x << " "; print(xs...); };
template<typename T> void read(vector<T>& v) { for (int i = 0; i < v.size(); ++i) cin >> v[i]; };


int main() {
    ui32 N;
    cin >> N;
    vector<vector<int>> v(N + 1, vector<int>(3, 0));
    for (int i = 1; i <= N; ++i) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    vector<vector<int>> dp(N + 1, vector<int>(3, 0));
    dp[1] = v[1];
    for (int i = 2; i <= N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) {
                    continue;
                }
                dp[i][j] = max(dp[i][j], v[i][j] + dp[i - 1][k]);
            }
        }
    }

    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;

    return 0;
}











Measured memory_bytes: 11136
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N, K; cin >> N >> K;
    vector<int>A(N);
    rep(i, N) {
        cin >> A[i];
        if (i < K)continue;
        cout << (A[i] > A[i - K] ? "Yes" : "No") << endl;
    }
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[105];
ll dp[105][405][105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, W;
    cin >> N >> W;
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
    }
    memset(dp, 0, sizeof(dp));
    REP(i, N) {
        REP(j, 4 * N + 1) {
            REP(k, N + 1) {
                dp[i + 1][j][k] = std::max(dp[i + 1][j][k], dp[i][j][k]);
                ll d = A[i].first - A[0].first;
                ll w = k * A[0].first + j + A[i].first;
                if (w <= W) {
                    dp[i + 1][j + d][k + 1] = std::max(dp[i + 1][j + d][k + 1], dp[i][j][k] + A[i].second);
                }
            }
        }
    }

    ll ans = 0;
    REP(i, 4 * N + 1) {
        REP(j, N + 1) {
            ans = std::max(ans, dp[N][i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35200
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;


int mem[1000006];

int main() {
	ll s; cin >> s;
	int cnt = 1;
	while (true) {
		if (mem[s] != 0) {
			cout << cnt << endl;
			return 0;
		}
		mem[s] = cnt;
		ll nxt;
		if (s & 1) {
			nxt = 3 * s + 1;
		}
		else {
			nxt = s / 2;
		}
		cnt++;
		s = nxt;
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll solve(ll x, ll p){
	ll ret = 0ll,y;
	if(x%2){
		y = x;
		while(y){
			ret += y/p;
			y /= p;
		}
		ret -= solve(x-1,p);
	}else{
		y = x/2;
		while(y){
			ret += y/p;
			y /= p;
		}
		if(p==2){
			ret += x/2;
		}
	}
	return ret;
}

int main(void){
	ll n;
	cin >> n;
	cout << min(solve(n,2ll),solve(n,5ll)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;


int main()
{
	long N;
	cin >> N;
	
	long t[N + 1], x[N + 1], y[N + 1];
	t[0] = x[0] = y[0] = 0;
	for(long i = 1; i < N + 1; i++){
		cin >> t[i] >> x[i] >> y[i];
	}	
	
	bool root = true;
	for(long i = 0; i < N; i++){
		long dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		long dt = t[i + 1] - t[i];
		if(dt < dist) root = false;
		else if(dt % 2 == 0){
			if(dist % 2 == 1) root = false;  
		}
		else if(dist % 2 == 0) root = false; 
	}
	
	if(root) cout << "Yes" << endl;
	else cout << "No" << endl; 
	
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define f(i,a,n)        for(int i=a;i<n;i++)
#define ve              vector
#define ss              second 
#define ff              first
#define pf              pop_front
#define pob             pop_back
#define psf             push_front
#define res(x)          cout<<x<<'\n'
#define read(t)         ll t;cin>>t


int main(){
    int n;
    cin>>n;
    map<string,int>mp;
    f(i,0,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3584
def count_left1(s)
  len = 0
  s.each_char{|c|
    if c == '1'
      len += 1
    else
      break
    end
  }
  return len
end

def find_first_non1(s)
  s.each_char{|c|
    if c != '1'
      return c
    end
  }
  return '1' # strange
end

s = gets.chomp!
k = gets.to_i

n_left1 = count_left1(s)
if k <= n_left1
  puts 1
else
  c = find_first_non1(s)
  puts c
end


Measured memory_bytes: 1788
N = int(input())

four = int(N/4)
seven = int(N/7)

flag=0

for i in range(1,four+1):
    sum = 4*i
    while(sum<=N):
        if(sum==N):
            flag=1
        sum+=7

for i in range(1,seven+1):
    sum2 = 7*i
    while(sum2<=N):
        if(sum2==N):
            flag=1
        sum2+=4
    
if(flag==1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	int a,b,c,x= 0,i=0;
	while(1){
scanf("%d %d", &a,&b);
if(a==0 && b==0) break;
if (x != 0) printf("\n");
else x = 1;
		for(c=a;c<=b;c++){
			if((c%4==0 && c%100!=0) || c%400==0){
				printf("%d\n",c);
				i +=1;
			}
		}
		if (i==0){
			printf("NA\n");
		}
					i=0;
	}
	return 0;
}

Measured memory_bytes: 616
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
const ll MOD = 998244353;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;
int n, k;
ll ans;

int main() {
	INIT
	cin >> n >> k;
	VI A(n);
	vector<vector<ll>> dp(n + 1, vector<ll>(3030));
	rep (i, 0, n) {
		cin >> A[i];
	}
	rep (i, 0, n) {
		dp[i + 1] = dp[i];
		(dp[i + 1][A[i]] += i + 1) %= MOD;
		for (int j = 0; j + A[i] <= k; ++j) {
			(dp[i + 1][j + A[i]] += dp[i][j]) %= MOD;
		}
		(ans += dp[i + 1][k]) %= MOD;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 71424
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;
    VEC(bool) empty(N, true);
    FOR(i, 0, K) {
        int d;
        cin >> d;
        while (d--) {
            int id;
            cin >> id;
            empty[id - 1] = false;
        }
    }

    int ret = 0;
    FOR(i, 0, N)
        ret += empty[i];
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 3660
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int n, k, i, tmp, j, tmpa;
	cin >> n >> k;
	vector<bool> have(n, false);
	int answer = 0;
	for (i = 0; i < k; i++) {
		cin >> tmp;
		for (j = 0; j < tmp; j++) {
			cin >> tmpa;
			tmpa--;
			have[tmpa] = true;
		}
	}
	for (i = 0; i < n; i++) {
		if (!have[i])
			answer++;
	}
					 
	cout << answer << endl;
	return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n,k;
    cin >> n >> k;
    ll ok = 1,ng = k+1;
    while (ng-ok > 1) {
        ll mid = (ok+ng)/2,sum = 0;
        for (int i = 0;i < n;++i) {
            sum += mid;
            mid /= 2;
            if (mid == 0) break;
        }
        (sum > k ? ng : ok) = (ok+ng)/2;
    }
    cout << ok << endl;
}


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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
ball = defaultdict(int)
count = defaultdict(int)
ball[1] = 1
for i in range(1,n+1):
    count[i] = 1

for _ in range(m):
    x, y = LI()
    if ball[x] and count[x] > 1:
        ball[y] = 1
        count[x] -= 1
        count[y] += 1
    elif ball[x] and count[x] == 1:
        ball[x] = 0
        ball[y] = 1
        count[x] = 0
        count[y] += 1
    elif not ball[x]:
        count[x] -= 1
        count[y] += 1

ans = 0
for i in range(1,n+1):
    if ball[i]:
        ans += 1
print(ans)



Measured memory_bytes: 62564
S;main(n){for(;scanf("%d",&n)*n;printf("%d\n",S)){int d[]={S=1,2,3},s[2],a,b,t;for(;n--;S+=*d)scanf("%s",s),t=d[a=*s%265%3],d[a]=d[b=*s%1668%5],d[b]=7-t;}}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

void solve(){
    int a;
    cin >> a;
    string s;
    cin >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
}

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

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

#define MAX 100

int main() {
	int N, x, A[MAX];
	long long sum = 0;
	cin >> N >> x;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	if (sum == x) {
		cout << N << endl;
	} else if (x > sum) {
		cout << N - 1 << endl;
	} else {
		sort(A, A + N);
		for (int i = 0; i < N; i++) {
			if (x >= A[i]) {
				x -= A[i];
			} else {
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
int cnt = 0;

void insertionSort(vector<int> &A, int g) {
	int i, j, v, n = A.size();
	REP(i,g,n) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j+g] = A[j];
			j = j - g;
			cnt++;
			// if (cnt > ceil(pow(n,1.5))) break;
		}
		A[j+g] = v;
	}
}
void shellSort(vector<int> &A) {
	int i, cnt = 0, n = A.size();
	vector<int> G;
	for(i=1;i<=n;i=3*i+1) G.push_back(i);
	reverse(G.begin(), G.end());
	int m = G.size();
	printf("%d\n",m);
	rep(i,m) printf(i < m-1 ? "%d ":"%d\n",G[i]);
	rep(i,m) insertionSort(A, G[i]);
}
int main() {
	int n,i,x;
	scanf("%d", &n);
	vector<int> A;
	rep(i,n) scanf("%d",&x),A.push_back(x);
	shellSort(A);
	printf("%d\n",cnt);
	rep(i,n) printf("%d\n",A[i]);
}

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

int main() {
	
	string a, b, c;
	cin >> a >> b >> c;
	
	cout << (char)(a[0] - 'a' + 'A') << (char)(b[0] - 'a' + 'A') << (char)(c[0] - 'a' + 'A') << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using state = string::const_iterator;
int p;

template<typename T>
T mod_inv(T x, T M){
   T u = 1, t = 1, v = 0, s = 0, m = M;
   while (x) { T q = m/x; swap(s -= q*u, u); swap(t -= q*v, v); swap(m -= q*x, x); }
   if(s < 0) s += M;
   return s;
}

int expr(state &cur);

int num(state &cur){
    if(isdigit(*cur)){
        int res = 0;
        while(isdigit(*cur)) res = res*10+(*(cur++)-'0');
        return res;
    }else if(*cur == '('){
        cur++;
        int res = expr(cur);
        if(!~res) return -1;
        cur++;
        return res;
    }
    exit(1);
}

int term(state &cur){
    auto res = num(cur);
    if(!~res) return -1;
    while(true){
        if(*cur == '*'){
            cur++;
            auto y = num(cur);
            if(!~y) return -1;
            (res *= y) %= p;
        }else if(*cur == '/'){
            cur++;
            auto y = num(cur);
            if(!~y || !y) return -1;
            (res *= mod_inv(y, p)) %= p;
        }else break;
    }
    return res;
}

int expr(state &cur) {
    auto res = term(cur);
    if(!~res) return -1;
    while(true){
        if(*cur == '+'){
            cur++;
            auto y = term(cur);
            if(!~y) return -1;
            res += y;
            if(res >= p) res -= p;
        }else if(*cur == '-'){
            cur++;
            auto y = term(cur);
            if(!~y) return -1;
            res -= y;
            if(res < 0) res += p;
        }else break;
    }
    return res;
}

int main() {
    string s;
    while(getline(cin, s), s != "0:"){
        string t;
        p = 0;
        int f = 0;
        for (auto &&i : s) {
            if(i == ':') f = 1;
            else if(!f) {
                p = p*10+(i-'0');
            }else if(i != ' ') t += i;
        }
        state cur = t.begin();
        auto ans = expr(cur);
        if(!~ans) puts("NG");
        else cout << t << " = " << ans << " (mod " << p << ")\n";
    }
    return 0;
}


Measured memory_bytes: 3324
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  string s;
  cin >> s;

  cout << count(s.begin(), s.end(), '1') << endl;
  return 0;
}

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

int main() {
  string c;
  cin >> c;

  if (c == "a"|c == "e"|c == "i"|c == "o"|c == "u") {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<int>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

int popHeap(vector<int>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  int i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=1;
  for(auto i:g[v]){
    if(ver[i]!=1)continue;
    dfs(g,i);
  }
}

int main(){
  int i,j,k,p,cnt=0;
  int n;
  cin>>n;
  vector<int> c(n),v;
  for(i=0;i<n;i++)cin>>c[i];
  c.erase(unique(c.begin(),c.end()),c.end());
  int b[200001];
  for(i=0;i<=200000;i++)b[i]=0;
  for(i=0;i<c.size();i++)b[c[i]]++;
  for(i=0;i<c.size();i++){
    if(b[c[i]]>=2){
      v.push_back(c[i]);
    }
  }
  if(v.empty()){
    cout<<1<<endl;
    return 0;
  }
  graph g(200001);
  for(i=0;i<v.size();i++){
    g[v[i]].push_back(i);
  }
  ll d[200001];
  d[0]=1;
  for(i=1;i<v.size();i++){
    d[i]=d[i-1];
    for(j=g[v[i]].size()-1;j>=0;j--){
      if(g[v[i]][j]<i){
        break;
      }
    }
    if(j!=-1){
      d[i]+=d[g[v[i]][j]];
    }
    if(d[i]>=MOD)d[i]%=MOD;
  }
  cout<<d[v.size()-1]<<endl;
}


Measured memory_bytes: 12020
from collections import deque
n = int(input())
w = deque([])
r = deque([])
s = input()
for i in range(n):
  if s[i] =="W":
    w.append(i)
  else:
    r.append(i)

ans = 0
if len(r)==0 or len(w)==0:
  print(0)
  quit()
  
while r[-1]>w[0]:
  rtemp = r.pop()
  wtemp = w.popleft()
  r.appendleft(wtemp)
  w.append(rtemp)
  ans += 1
  #print(r)
  #print(w)
  #print(" ")
print(ans)

Measured memory_bytes: 74780
#include <stdio.h>
#include <string.h>

#define MAX 1000

void LCSLength(char *X, char *Y){

    int i,j;
    int m = strlen(X);
    int n = strlen(Y);
    int c[m+1][n+1];

    for( i = 0 ; i <= m ; i++ ){
        c[i][0] = 0;
    }
    for( j = 0 ; j <= n ; j++ ){
        c[0][j] = 0;
    }

    for( i = 1 ; i <= m ; i++ ){
        for( j = 1 ; j <= n ; j++ ){
            if( X[i-1] == Y[j-1] ){
                c[i][j] = c[i-1][j-1] + 1;
            }else if( c[i-1][j] >= c[i][j-1] ){
                c[i][j] = c[i-1][j];
            }else{
                c[i][j] = c[i][j-1];
            }
        }
    }
    

    printf("%d\n",c[i-1][j-1]);

    
}



int main(){

    int n;
    int i;
    char line1[MAX],line2[MAX];

    scanf("%d",&n);

    for( i = 0 ; i < n ; i++ ){
        scanf("%s",line1);
        scanf("%s",line2);
        LCSLength(line1,line2);
    }

    return 0;
}

Measured memory_bytes: 4524
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int main(void)
{
  string s;
  cin >> s;
  cout << (s.size() >= 4 && string(s.begin(), s.begin()+4) == "YAKI" ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	var price float64
	for i := 0; i < N; i++ {
		x := nextFloat()
		u := nextString()
		if u == "JPY" {
			price += x
		} else {
			price += x * 380000
		}
	}

	fmt.Println(price)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        String s1 = obj.next(),s2 = obj.next();
        int sn1 = obj.nextInt(),sn2 = obj.nextInt();
        String t = obj.next();
        if(t.equals(s1)) sn1--;
        else sn2--;
        System.out.println(sn1+" "+sn2);
    }
}


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

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000009
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

struct ST {
    vector<int> to;
    int c1 = INF, c2 = INF, c3 = INF;
};

int main() {
    int N, M, S, T;
    cin >> N >> M;
    vector<ST> v(N + 1, ST());
    int eu, ev;
    REP(i, M) {
        cin >> eu >> ev;
        v[eu].to.push_back(ev);
    }
    cin >> S >> T;

    v[S].c1 = 0;
    deque<int> q;
    q.push_back(S);
    while(true) {
        if(q.empty())
            break;
        int s = q.front();
        q.pop_front();

        for(int e : v[s].to) {
            if(v[s].c1 + 1 < v[e].c2) {
                int aa = v[s].c1 + 1;
                v[e].c2 = v[s].c1 + 1;
                q.push_back(e);
            }
            if(v[s].c2 + 1 < v[e].c3) {
                v[e].c3 = v[s].c2 + 1;
                q.push_back(e);
            }
            if(v[s].c3 + 1 < v[e].c1) {
                v[e].c1 = v[s].c3 + 1;
                q.push_back(e);
            }
        }
    }

    if(v[T].c1 == INF) {
        cout << -1;
        return 0;
    }
    cout << v[T].c1 / 3;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,a,b) for (int i = a; i < (b); i++)
#define sz(t) int(t.size())
#define INF 1000000000
const int DIV = 1000000000 + 7;
using namespace std;
typedef long long ll;

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<bool> checked(n, false);

    REP(i, 0, k) {
        int d;
        cin >> d;

        REP(j, 0, d) {
            int tmp;
            cin >> tmp;
            checked[tmp - 1] = true;
        }
    }

    int res;
    REP(i, 0, n) {
        if (!checked[i]) {
            res++;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3636
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[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 ) * } } ; }
#[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 , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:i64, b:i64};
    println!("{}", if a+b>=10 {"error".to_string()} else {(a+b).to_string()});
}


Measured memory_bytes: 4476
from collections import deque

s = deque(input())
q = int(input())

flag = True
for _ in range(q):
    temp = input().split()
    if len(temp) == 1:
        flag = not flag
    else:
        if flag:
            if temp[1] == "1":
                s.appendleft(temp[2])
            else:
                s.append(temp[2])
        else:
            if temp[1] == "1":
                s.append(temp[2])
            else:
                s.appendleft(temp[2])

if flag:
    print("".join(s))
else:
    print("".join(list(s)[::-1]))

Measured memory_bytes: 15780
using System;
using System.Linq;
using System.Collections.Generic;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').Select(x => int.Parse(x)).ToList();

            var n = list[0];
            var a = list[1];
            var b = list[2];

            var taxi = n * a;

            if (taxi < b){
                Console.WriteLine(taxi.ToString());
            }
            else{
                Console.WriteLine(b.ToString());
            }
        }
    }
}


Measured memory_bytes: 11220
class Card {
  constructor(mark, value) {
    this.mark = String(mark);
    this.value = Number(value);
  }

  equals(other) { return this.value === other.value && this.mark === other.mark; }

  compareTo(other) {
    if (this.value === other.value) return 0;
    else if (this.value < other.value) return -1;
    else return 1;
  }

  toString() { return `${this.mark} ${this.value}` }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.map(r => r.split(' ')).map(c => new Card(c[0], c[1]));
  const quick_arr = Array.from(arr);

  quickSort(quick_arr, 0, n - 1);
  const isStable = arr.map((e, idx) => ({val: e, idx: idx}))
      .sort((a, b) => a.val.compareTo(b.val) || a.idx - b.idx)
      .every((card, i) => card.val.equals(quick_arr[i]));

  console.log(isStable ? 'Stable' : 'Not stable');
  console.log(quick_arr.join('\n'));
})();

function quickSort(arr, p, r) {
  const partition = function(arr, p, r) {
     let x  = arr[r];
     let i = p - 1;
     for (let j = p; j < r; j++) {
       if (arr[j].compareTo(x) <= 0) {
         i++;
         [arr[i], arr[j]] = [arr[j], arr[i]];
       }
     }
     [arr[i + 1], arr[r]] = [arr[r], arr[i + 1]];
     return i + 1;
  }

  quickSort = function(arr, p, r) {
    if (p < r) {
      let q = partition(arr, p, r);
      quickSort(arr, p, q - 1);
      quickSort(arr, q + 1, r);
    }
  }
  quickSort(arr, p, r);
}



Measured memory_bytes: 75256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using ll = long long;
using vll = std::vector<ll>;


ll pp(ll p)
{
	return p * (p - 1) / 2;
}


ll count_le(const vll& plus, const vll& minus, ll T)
{
	size_t m = minus.size();
	ll count = 0ll;
	for (size_t p = 0; p < plus.size(); p++)
	{
		for (; m > 0; m--)
		{
			if (plus[p] * minus[m-1] <= T) break;
 		}
		count += m;
	}
	return count;
}

ll count_le(const vll& plus, ll T)
{
	size_t m = plus.size();
	ll count = 0ll;
	for (size_t p = 0; p < plus.size(); p++)
	{
		for (; m > p + 1; m--)
		{
			if (plus[p] * plus[m-1] <= T) break;
 		}
		if (p == m) m++;
		count += (m - p - 1);
	}
	return count;
}

ll search_min_minus(const vll& plus, const vll& minus, ll K)
{
	if (K == 1)
	{
		return plus[0] * minus[0];
	}
	else if (plus.size() <= 1)
	{
		return plus[0] * minus[K - 1];
	}
	else if (minus.size() <= 1)
	{
		return plus[K - 1] * minus[0];
	}

	ll left = -1e18, right = 0;
	while (left + 1 < right)
	{
		ll center = (left + right) / 2;
		ll c = count_le(plus, minus, center);
		if (c < K)
		{
			left = center;
		}
		else
		{
			right = center;
		}
	}
	return right;
}

ll search_min_plus(const vll& plus, const vll& minus, ll K)
{
	if (K == 1)
	{
		if (plus.size() <= 1)
		{
			return minus[0] * minus[1];
		}
		else if (minus.size() <= 1)
		{
			return plus[0] * plus[1];
		}
		else
		{
			return std::min(plus[0] * plus[1], minus[0] * minus[1]);
		}
	}

	ll left = 0, right = 1e18;
	while (left + 1 < right)
	{
		ll center = (left + right) / 2;
		ll c = count_le(plus, center) + count_le(minus, center);
		if (c < K)
		{
			left = center;
		}
		else
		{
			right = center;
		}
	}
	return right;
}


ll f(const std::vector<ll>& A, int N, ll K)
{
	std::vector<ll> plus, minus;
	ll zero = 0;
	plus.reserve(N);
	minus.reserve(N);

	for (int i = 0; i < N; i++)
	{
		if (A[i] > 0ll)
		{
			plus.push_back(A[i]);
		}
		else if (A[i] < 0ll)
		{
			minus.push_back(A[i]);
		}
		else
		{
			zero++;
		}
	}

	std::sort(begin(plus), end(plus), std::greater<ll>());
	std::sort(begin(minus), end(minus), std::less<ll>());

	ll pp_minus = (ll)plus.size() * minus.size();
	ll pp_zero = pp(zero) + zero * ((ll)plus.size() + minus.size());

	if (K <= pp_minus)
	{
		return search_min_minus(plus, minus, K);
	}
	K -= pp_minus;
	if (K <= pp_zero)
	{
		return 0ll;
	}
	K -= pp_zero;

	std::reverse(begin(plus), end(plus));
	std::reverse(begin(minus), end(minus));
	return search_min_plus(plus, minus, K);
}

int main()
{
	int N;
	ll K;
	std::cin >> N >> K;
	vll A(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> A[i];
	}

	std::cout << f(A, N, K);
	
}

Measured memory_bytes: 3200
# include <string.h>
# include <iostream>

using namespace std;

int main() {
	char temp[120] = "";
	cin >> temp;
	int len = strlen( temp );
	bool sit = true;
	for ( int i = 0; i < len && sit == true; i++ ) {
		if ( i % 2 == 0 ) {
			if ( temp[i] == 'L' )
				sit = false;
		} // if
		
		else {
			if ( temp[i] == 'R' )
				sit = false;
		} // else
	} // for
	
	if ( sit == false )
		cout << "No";
	else
		cout << "Yes";
}// main

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord
import qualified Data.Vector.Unboxed                   as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [n, k] <- readIntList
  arr <- UV.fromList <$> readIntList
  let expects = UV.map (\x -> (fromIntegral ((x * (x + 1)) `div` 2) :: Double) / fromIntegral x) arr
      cumsum = UV.scanl' (+) 0.0 expects
      ans = maximum $ map (\i -> cumsum UV.! (i + k) - cumsum UV.! i) [0..(n - k)]
  print ans

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

int main(){
	/*
	int a,b,c,d,e;

	cin >> a >> b >> c >> d >> e;

	int x;

	if(a > 0){
		x = e*(b-a);
	}
	if(a == 0){
		x = e*b + d;
	}
	if(a < 0){
		x = -c*a + e*b + d;
	}

	cout << x <<endl;
	*/

	/*
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	int m,n;
	int x = a + b + c + d + e + f;


	
	if(e<f)
	{
		x = x - e;
		if(a<b)
		{
			if(a<c)
			{
				if(a<d)
				{
					cout << x-a << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
		else
		{
			if(b<c)
			{
				if(b<d)
				{
					cout << x-b << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
	}
	else
	{
		x = x - f;
		if(a<b)
		{
			if(a<c)
			{
				if(a<d)
				{
					cout << x-a << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
		else
		{
			if(b<c)
			{
				if(b<d)
				{
					cout << x-b << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
			else
			{
					if(c<d)
				{
					cout << x-c << endl;
				}
				else
				{
					cout << x-d << endl;
				}
			}
		}
	}
	*/
/*
	int n;
	cin >> n;
	int a;
	cin >> a;
	int max = a,min = a;
	int i = 1;
	while(i<n){
		cin >> a;
		if(a > max){
			max = a;
		}
		if(a < min){
			min = a;
		}
		i++;
	}
	cout << max << endl << min << endl;
	*/
	/*
	string s;
	cin >> s;
	int j,o,i;
	for(int i;i < s.size;i++){
		
	}
	*/
	/*
	int n;
	cin >> n;
	int A;
	int X[100000];
	int n=0;
	for(int i=0;i<n;i++){
		cin >> A;
		
	}
	*/
	/*
	int a,b,c,d,p;
	cin >> a >> b >> c >> d >> p;
	int X,Y=b;

	X = a*p;
	
	if(p>c){
		Y += d*(p-c);
	}

	if(X > Y){
		cout << Y << endl;
	}
	else{
		cout << X << endl;
	}
	*/ 

	int l,a,b,c,d;
	cin >> l >> a >> b >> c >> d;

		int Jap = a/c;
		if(a%c != 0){
			Jap += 1;
		}
		int Math = b/d;
		if(b%d != 0){
			Math += 1;
		}

	int day = Jap;
	if(Jap < Math) {
		day = Math;
	}

	cout << l - day << endl;

	return 0;
}



Measured memory_bytes: 3092
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;

// typedef vector<vector<P> > Graph;
vector<int> dijkstra(int s, Graph &G){
    priority_queue<P, vector<P>, greater<P> > que;
    int n = G.size();
    vector<int> dist(n);
    dist.assign(n, INF);
    dist[s] = 0;
    que.push(P(0, s));

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        rep(i,G[v].size()) {
            if(dist[G[v][i].first] > dist[v]+G[v][i].second){
                dist[G[v][i].first] = dist[v]+G[v][i].second;
                que.push(P(dist[G[v][i].first],G[v][i].first));
            }
        }
    }
    return dist;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    Graph G(n);
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    rep(_, m) {
        int node_x, node_y, cost = 1;
        cin >> node_x >> node_y;
        cin >> cost;	// 重みなしなら削除
        node_x--, node_y--;
        a[_]=node_x;
        b[_]=node_y;
        c[_]=cost;
        G[node_x].push_back(mp(node_y, cost));
        G[node_y].push_back(mp(node_x, cost));
    }
    vector<vector<int>> dist(n);
    rep(i,n){
        dist[i]=dijkstra(i,G);
    }
    vector<int> ans(m);
    rep(i,n){
        rep(j,m){
            // a[j] b[j] c[j]
            if(dist[i][a[j]]+c[j]==dist[i][b[j]]){
                ans[j]++;
            }
        }
    }
    ll ji=0;
    rep(i,m){
        if(ans[i]==0){
            ji++;
        }
    }
    cout<<ji<<endl;
    
    
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
using namespace  std;
int arr[3][3];
bool b[3][3];
int main() {

for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        cin>>arr[i][j];
        b[i][j]=true;

    }

}

int x;
cin>>x;
for(int i=0;i<x;i++){

    int y;
    cin>>y;
    for(int i=0;i<3;i++){

        for(int j=0;j<3;j++){

            if(arr[i][j]==y){b[i][j]=false;}

        }

    }

}

int counter=0;
for(int i=0;i<3;i++)
{
    for(int k=0;k<3;k++){
        if(b[i][k]==false)counter++;

    }
    if(counter==3){cout<<"Yes";
        return  0;}
    counter=0;
}
counter=0;
for(int i=0;i<3;i++){

    for(int j=0;j<3;j++){

        if(b[j][i]==false )counter++;


    }
    if(counter==3) {cout<<"Yes";
        return  0;}
    counter=0;
}
counter=0;
for(int i=0,j=0;i<3,j<3;i++,j++)
{
    if(b[i][j]==false)counter++;
}
if(counter==3){cout<<"Yes";
    return  0;}

counter=0;
for(int i=2,j=0;i>=0,j<3;i--,j++){
    if(b[j][i]==false)counter++;

}

if(counter==3){cout<<"Yes";
    return  0;}
cout<<"No";
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int s=S.size();
  string ans="Good";
  for(int i=0;i<s-1;i++){
    if(S[i]==S[i+1])ans="Bad";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	char b;
	cin >> b;
	if (b == 'A') cout << 'T';
	if (b == 'C') cout << 'G';
	if (b == 'G') cout << 'C';
	if (b == 'T') cout << 'A';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const double pi = 3.14159265359;
 
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    double n;
    cin >> n;
    cout << setprecision(6) << fixed << 2.0 * pi * n << "\n";
}

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

typedef long long ll;

struct Shop {
	int price, num;
} shop[100010];

int n, m, cnt; ll ans;

bool cmp(Shop a, Shop b) { return a.price < b.price; }

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &shop[i].price, &shop[i].num);
	}
	sort(shop + 1, shop + 1 + n, cmp);
	for (int i = 1; i <= n; ++i) {
		if (cnt + shop[i].num <= m) {
			cnt += shop[i].num;
			ans += (ll)shop[i].num * shop[i].price;
		}
		else {
			ans += ((ll)m - cnt) * shop[i].price;
			break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
N, A, B = gets.split.map(&:to_i)

if N < A + B - 1
  puts -1
  exit
end

loop_cnt = Rational(N, A).ceil

if loop_cnt > B
  puts -1
  exit
end

len = (0...B).find { |x|
  lc = Rational(N - x, A).ceil

  lc + x == B
}

ans = []
remain = N

max = N
min = len + 1

tail = [*1...min].reverse

while min <= max
  from = [max - A + 1, min].max
  to = max

  # p [:from, from, :to, to]

  from.upto(to) do |n|
    ans << n
  end

  max = from - 1
end

ans += tail
puts ans.join(' ')


Measured memory_bytes: 21384
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<u8> = read::<String>().bytes().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut mat: Vec<Vec<i32>> = vec![vec![0; 26]; 26];

    for i in 0..s.len() {
        mat[(s[i] as usize) - ('a' as usize)][(t[i] as usize) - ('a' as usize)] = 1;
    }

    let mut ng = false;
    for i in 0..26 {
        ng |= (0..26).map({|j: usize| mat[i][j]}).sum::<i32>() >= 2;
        ng |= (0..26).map({|j: usize| mat[j][i]}).sum::<i32>() >= 2;
    }
    println!("{}", if ng { "No" } else { "Yes" });
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X,Y,A,B,C; cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A),q(B);
    priority_queue<ll> pq;
    for (int i=0;i<A;++i) cin >> p[i];
    for (int i=0;i<B;++i) cin >> q[i];
    for (int i=0;i<C;++i){
        ll r; cin >> r;
        pq.emplace(r);
    }
    sort(p.begin(),p.end()); reverse(p.begin(),p.end());
    sort(q.begin(),q.end()); reverse(q.begin(),q.end());
    for (int i=0;i<X;++i) pq.emplace(p[i]);
    for (int i=0;i<Y;++i) pq.emplace(q[i]);
    ll ans=0;
    for (int i=0;i<X+Y;++i) ans+=pq.top(),pq.pop();
    cout << ans << '\n';
}


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

int n, m;
vector<int> adj[100005][2];
ll dp[100005][2];

ll sol(ll a, ll b)
{
  if (dp[a][b] != -1)
    return dp[a][b];

  dp[a][b] = 0;

  for (auto x : adj[a][b])
  {
    dp[a][b] = max(dp[a][b], 1 + sol(x, b));
  }

  return dp[a][b];
}

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

  int a, b;
  cin >> n >> m;

  for (ll i = 0; i < 100005; i++)
  {
    dp[i][0] = -1;
    dp[i][1] = -1;
  }

  for (ll i = 0; i < m; i++)
  {
    cin >> a >> b;
    adj[a][0].push_back(b);
    adj[b][1].push_back(a);
  }

  ll mx = 0;

  for (ll i = 0; i < n; i++)
  {
    mx = max(mx, sol(i, 0) + sol(i, 1));
  }

  cout << mx << "\n";

  return 0;
}


Measured memory_bytes: 17280