akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAXN 200200
#define ll long long
using namespace std;
 

ll qtd[MAXN], v[MAXN];

int main(){
    int n;

    cin>>n;

    for(int i=0; i<n; i++){
        cin >> v[i];
        qtd[v[i]]++;
    }

    ll total = 0;

    for(int i=1; i<=n; i++){
        total += (qtd[i])*(qtd[i]-1)/2;
    }


    for(int i=0; i<n; i++){
        ll q = qtd[v[i]];
        ll res = total - (q*(q-1))/2 + (q-1)*(q-2)/2;
        cout << res << endl;
    }

    return 0;
}

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

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

    vector<long long> h(n);

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

    long long delta_min = 1e9;

    sort(h.begin(), h.end(), greater<long long>());

    for(long long i = 0; i <= n-k; i++){
        delta_min = min(h[i] - h[i+k-1], delta_min);
    }

    cout << delta_min << endl;

    return 0;

}

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

int main(){
    int H, W;
    string S[51];
    cin >> H >> W;
    for(int i=0; i<H; i++){
        cin >> S[i];
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int bom_count = 0;
            if(S[i][j] == '.'){
                // 周囲8マスを調べる
                if(i-1>=0 && j-1>=0){
                    if(S[i-1][j-1]    == '#'){
                        bom_count++;
                    }
                }
                if(j-1>=0){
                    if(S[i][j-1] == '#'){
                        bom_count++;
                    }
                    if(S[i+1][j-1]    == '#'){
                        bom_count++;
                    }
                }
                
                if(i-1>=0){
                    if(S[i-1][j]      == '#'){
                        bom_count++;
                    }
                    if(S[i-1][j+1]    == '#'){
                        bom_count++;
                    }
                }
                if(S[i+1][j]      == '#'){
                    bom_count++;
                }
                
                if(S[i][j+1]      == '#'){
                    bom_count++;
                }
                if(S[i+1][j+1]    == '#'){
                    bom_count++;
                }
                cout << bom_count;
            }
            else{
                cout << "#";
            }
        }
        cout << endl;
    }
    return 0;
}

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

const int INF = 1001001001;

int main(){
    int n;
    cin>>n;
    vector<char> cn(n);
    rep(i,n)cin>>cn[i];
    int cw=0,cr=0;
    rep(i,n){
        if(cn[i]=='W'){
            cw++;
        }else{
            cr++;
        }
    }
    int c3=0;
    rep(i,cr){
        if(cn[i]=='W'){
            c3++;
        }
    }
    cout<<c3;

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long int
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define LN outchar('\n')
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}


int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	inpos(n);
	inpos(k);
	int dp[n] = {0};
	int arr[n];
	for (int i = 0; i<n;i++) {
		inpos(arr[i]);
	}
	dp[0] = 0;
	
	for (int i = 1; i<n;i++) {
		int mini= INT_MAX;
		for (int j = max (i-k, 0) ; j<i;j++ ) { 
			mini = min (dp[j] + abs(arr[j] - arr[i]) , mini);
		} 
		dp[i] = mini;
	}
	outpos(dp[n-1]);LN;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int w, m;
   while(cin >> w && w > -1){
       if(w > 30){
           m = 1150 + 1250 + 1400 + 160*(w - 30);
       }else if(w > 20){
           m = 1150 + 1250 + 140*(w - 20);
       }else if(w > 10){
           m = 1150 + 125*(w - 10);
       }else{
           m = 1150;
       }
       cout << 4280 - m << endl;
   }
}


Measured memory_bytes: 3004
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String s = sc.next();

		String ab = "abcdefghijklmnopqrstuvwxyz";

		int i = ab.indexOf(s) + 1;

		// 出力
		System.out.println(ab.charAt(i));
	}
}

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll)4000000000000000000;
const ll MOD = (ll)1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(), v.end())
#define smaller_queue priority_queue<ll, vector<ll>, greater<ll>>
//------------------------------------------------------

int main()
{
    int ans = 0;
    rep(i, 4)
    {
        char c;
        cin >> c;
        c == '+' ? ans++ : ans--;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  std::string S;
  std::cin >> S;
  int n = S.length();
  std::vector<int > L(n);
  for (int i=0; i<n; i++){
    L[i]=int(S[i])-int('0');
  }
  std::reverse(L.begin(), L.end());
  long long mod = 1e9+7;
  std::vector<std::vector<long long > > dp(n+4, std::vector<long long > (2));
  dp[0][0]=1;
  dp[0][1]=1;
  for (int i=0; i<n; i++){
    if (L[i]==1){
      dp[i+1][0] = dp[i][1] + (2*dp[i][0])%mod;
    } else {
      dp[i+1][0] = dp[i][0];
    }
    dp[i+1][1] = dp[i][1] * 3;
    dp[i+1][0] %= mod;
    dp[i+1][1] %= mod;
    //printf("%lld, %lld\n", dp[i+1][0], dp[i+1][1]);
  }
  long long ans = dp[n][0];
  std::cout << ans << std::endl;
  return 0;
}
 

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

int main()
{
	int N, K;
	scanf("%d%d", &N, &K);
	std::vector<int64_t> p(N);
	for (auto& e: p) scanf("%lld", &e);
	std::vector<int64_t> sum(N + 1);
	for (int i{}; i < N; i++)
		sum[i + 1] = sum[i] + p[i];
	int64_t max{};
	for (int i{}; i + K <= N; i++)
		max = std::max(max, sum[i + K] - sum[i]);
	printf("%Lf\n", (long double)(max + K) / 2);

	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 long long int m[1000001] = { 0 };
 	long long int n;
long long int f(long long int x)
{
	long long int i;
	long long int br = 0;
	if(x == 1)
	br+=m[1];
	else
	{
	for(i=1;i<=sqrt(x);i++)
	{
		if(x%i==0 )
		{
		 br+=m[i];
		 br+=m[x/i];
		 } 
	}
      }
	if(br == 1)
	return 1;
	else
	return 0;
}
main()
{
	cin >> n;
	long long int a[n];
	long long int i, ans = 0;
	for(i=0;i<n;i++)
	{
	cin >> a[i];
	m[a[i]]++;
	}
	for(i=0;i<n;i++)
	{
	ans+=f(a[i]);
    }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12812
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
        
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;

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

int H, W; cin >> H >> W;
VS S(H); rep(i, 0, H) cin >> S[i];

VVI lcnt(H, VI(W, 0)); // 照らすマスの数
// 横方向に集計
rep(h, 0, H){
    int rowlen = 0;
    rep(w, 0, W){
        if (S[h][w] == '.') 
            ++rowlen;
        else {
            rep(l, w - rowlen, w) lcnt[h][l] = rowlen;
            rowlen = 0;
        }
    }
    rep(l, W - rowlen, W) lcnt[h][l] = rowlen;
}
// 縦方向に集計
rep(w, 0, W){
    int collen = 0;
    rep(h, 0, H){
        if (S[h][w] == '.') 
            ++collen;
        else {
            rep(l, h - collen, h) lcnt[l][w] += collen;
            collen = 0;
        }
    }
    rep(l, H - collen, H) lcnt[l][w] += collen;
}
i64 maxi = 0;
rep(h, 0, H) maxi = max(maxi, *max_element(ALL(lcnt[h])));

// 十字の重なり部分がある．
cout << maxi - 1 <<  endl;

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,k;
  cin>>n>>k;

  n%=k;
  cout<<min(n,k-n)<<newl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define maxn 200005
#include<map>
#define int long long
int arra[maxn];
map<int,int>ma;
signed main()
{
	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
	cin>>arra[i];
	ma[arra[i]]++;
	}
	int res=0;	
	for(auto i:ma)
	{
		int n=i.second;
		res+=(n)*(n-1)/2;
	}
	for(int i=1;i<=N;i++)
	{
		int ans=res;
		int n=ma[arra[i]];
		ans-=n*(n-1)/2;
		ans+=(n-1)*(n-2)/2;
		cout<<ans<<endl;
	}
	return 0;
} 

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

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

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (auto& x : A) cin >> x;
    bool res = true;
    for (int x : A) {
      if (x % 2 == 0) {
        res &= (x % 3 == 0) || (x % 5 == 0);
      }
    }
    cout << (res ? "APPROVED" : "DENIED") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int time = scanner.nextInt();
    int addTime = scanner.nextInt();
    int startTime = time + addTime;

    if(startTime > 23) {
      System.out.println(startTime - 24);
    } else {
      System.out.println(startTime);
    }
  }
}


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

#define rep( i, n ) for( int i = 0; i < ( n ); i++ )
#define PI 3.14159265
typedef long long ll;

int main( void ) {

    double a, b, c;
    scanf( "%lf%lf%lf", &a, &b, &c );
   
   //三角形の面積、2辺×sinΘ/2
    double cs = sin( c * PI / 180.0 );
    double cc = cos( c * PI / 180.0 );
    double s  = a * b *cs / 2.0;
    double l  = a + b + sqrt( pow( a, 2 ) + pow( b, 2 ) - 2.0 * a * b * cc );
    double h  = s * 2.0 / a;

    printf( "%.8lf\n%.8lf\n%.8lf\n", s, l, h );

    return 0;
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 105;
struct point {
    double x, y;
    bool operator < (const point &a) const {
        return atan2(y, x) < atan2(a.y, a.x);
    }
}p[N];
int n;
double ans;

int main() {
    cin >> n;
    rep(i, 1, n) cin >> p[i].x >> p[i].y;
    sort(p + 1, p + n + 1);
    rep(i, 1, n) {
        double x = 0, y = 0;
        int j = i;
        do {
            x += p[j].x, y += p[j].y;
            ans = max(ans, x * x + y * y);
            j = j % n + 1;
            // printf("%d %d\n", i, j);
        } while (j != i);
    }
    printf("%.15lf\n", sqrt(ans));
    return 0;
}


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

int main(){
    int n,x;
    cin >> n >> x;
    int nmin = 1000;
    for(int i = 0; i < n; i++){
        int m; cin >> m;
        x -= m;
        nmin = min(nmin, m);
    }
    cout << n + x/nmin << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const ll N = 1e6, inf = 1e9;
ll tree[2 * N], lazy[2 * N], ar[N];
void pushDown(ll node, ll s, ll e)
{
    if(lazy[node])
    {
        ll l = 2 * node, r = 2 * node + 1;
        if( s != e)
        {
            ll mid = (s + e)/2;
            tree[l] += lazy[node];
            tree[r] += lazy[node];
            lazy[l] += lazy[node];
            lazy[r] += lazy[node];
        }
        lazy[node] = 0;
    }
}
void build(ll node, ll s, ll e)
{
    lazy[node] = 0;
    if(s == e)
    {
        tree[node] = ar[s];
        lazy[node] = 0;
        return;
    }
    ll l = 2 * node, r = 2 * node + 1, m = (s + e)/2;
    build(l, s, m);
    build(r, m + 1, e);
    tree[node] = min(tree[l], tree[r]);
}
void update(ll node, ll s, ll e, ll i, ll j, ll val)
{
    pushDown(node, s, e);
    if(e < i || s > j) return ;
    if(s >= i && e <= j)
    {
        lazy[node] += val;
        tree[node] += val;
        cerr<<i<<" "<<j<<" "<<s<<" "<<e<<" "<<node<<" "<<tree[ node ]<<"\n";
        pushDown(node, s, e);
        return;
    }
    ll l = 2 * node, r = 2 * node + 1, m = (s + e)/2;
    update(l, s, m, i, j, val);
    update(r, m + 1, e, i, j, val);
    tree[node] = min(tree[l], tree[r]);
}
ll query(ll node, ll s, ll e, ll i, ll j)
{
    pushDown(node, s, e);
    if(e < i || s > j) return inf;
    if(s >= i && e <= j)
    {
        return tree[node];
    }
    ll l = 2 * node, r = 2 * node + 1, m = (s + e)/2;
    ll x = query(l, s, m, i, j);
    ll y = query(r, m + 1, e, i, j);
    return min(x, y);
}
int main()
{

    ll n, k;
    cin>>n>>k;
    if(k == 1)
    {
        cout<<0<<"\n";
    }
    else
    {
        cout<<n - k<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

long int a[1001];

void fact(long int x){
    long int t = x;
    for (long int i = 2; i * i <= x; i++){
        while (t % i == 0){
            a[i]++;
            t =  t / i;
        }
    }
    if (t > 1){
        a[t]++;
    }
    
    
}

int main(){
    long int const mod = 1000000007;
    long int n;
    cin >> n;
    for (int i = 2; i <= n; i++){
        fact(i);
    }
    long int ans = 1;
    for (int i = 2; i <= 1000; i++){
        ans *= a[i] + 1;
        ans %= mod;
    }
    cout << ans << endl;
    // rep(i, 20) cout << a[i] << " ";
    // cout << endl;

}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $n);
$input = [];
for ($i = 0;$i < $n; $i++){
    $input[] = explode(' ',rtrim(fgets(STDIN), PHP_EOL));
}

$before_t = 0;
$before_x = 0;
$before_y = 0;


foreach ($input as $value) {
    $diff_t = abs($value[0] - $before_t);
    $diff_p = abs(($value[1]+$value[2]) - ($before_x + $before_y));

//    var_dump($diff_t, $diff_p,$diff_t < $diff_p);
    if ($diff_t < $diff_p) {
        echo 'No' . PHP_EOL;
        return;
    }
    
    if ($diff_t % 2 !== 0 && $diff_p %2 === 0) {
        echo 'No'.PHP_EOL;
        return;
    } elseif ($diff_t %2 === 0 && $diff_p %2 !== 0) {
        echo 'No'.PHP_EOL;
        return;
    }

    $before_t = $value[0];
    $before_x = $value[1];
    $before_y = $value[2];
}
echo 'Yes'.PHP_EOL;


Measured memory_bytes: 54132
n = int(input())
s = []

for i in range(int(n ** (1 / 2))):
    if i > n:
        break
    elif n % (i + 1) == 0:
        j = int(n / (i + 1)) 
        s.append(i + j - 1)

s.sort()                
print(s[0])
              

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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	
	int sum = 0;
	rep(i, 0, n) {
		if (i < k) sum += x;
		else sum += y;
	}
	cout << sum << endl;
	


	return 0;
}

Measured memory_bytes: 256
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.

*/

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef unsigned long long ull;

const int mod = 1000007;
const int high = 100;

int main()
{
	fast;
	string s;
	while(cin >> s)
	{
		int len = s.length() , i;

		for(i=0; i<len; i++)
		{
			if(s[i] == ',') s[i]=' ';
		}

		outn(s);
	}

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>

int N,Y;
int x,y,z,min;
bool dp[20001]={};
void solve(int sx,int sy,int sz,int sum){
	//std::cout<<sx<<sy<<sz<<std::endl;
	dp[sum]=true;
	if(sum==Y){
		printf("%d %d %d\n",sx,sy,sz);
		//std::cout << sum<<std::endl;
		exit(0);
	}else{
		if(sum<Y&&sz-1>=0){
			int m1=sum;
			int m2=sum;
			m1+=9; if(dp[m1]==false) solve(sx+1,sy,sz-1,m1);
			m2+=4; if(dp[m2]==false) solve(sx,sy+1,sz-1,m2);
		}
		if(sum<Y && sy-1>=0){
			int m3=sum;
			m3+=5; if(dp[m3]==false) solve(sx+1,sy-1,sz,m3);
		}
	}
}
int main(void){
	scanf("%d%d",&N,&Y);
	Y=Y/1000;
	solve(0,0,N,N);
	std::printf("-1 -1 -1\n");
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull dp[100001][101];
ull weight[101],val[101];
ull n,w;
ull solve(ull w,ull i)
{
    if(i==n)
        return 0;
    if(dp[w][i]!=-1)
        return dp[w][i];
    if(w>=weight[i])
        return dp[w][i]=max(val[i]+solve(w-weight[i],i+1),solve(w,i+1));
    else
        return dp[w][i]=solve(w,i+1);
}
int main()
{
    
    memset(dp,-1,sizeof(dp));
    cin>>n>>w;
    for(int i=0;i<n;i++)
        cin>>weight[i]>>val[i];
    solve(w,0);
    cout<<dp[w][0];
    return 0;
}

Measured memory_bytes: 79104
X, Y, A, B, C = map(int, input().split())
Red = sorted(list(map(int, input().split())), reverse=True)
Grn = sorted(list(map(int, input().split())), reverse=True)
Wht = sorted(list(map(int, input().split())), reverse=True)

Mix = Red[:X] + Grn[:Y] + Wht
Mix = sorted(Mix, reverse=True)
ans = sum(Mix[:X+Y])
print(ans)

Measured memory_bytes: 22460
using System;
using System.Text;

namespace AtCoder
{
	public class ProblemA
	{
		public static void Main(string[] args)
		{
			string[] line = Console.ReadLine().Split(' ');
			int n = int.Parse(line[0]);
			int l = int.Parse(line[1]);
			int t = int.Parse(line[2]);

			int[] ants = new int[n];

			long count = 0;

			for (int i = 0; i < n; i++)
			{
				line = Console.ReadLine().Split(' ');
				int pos = int.Parse(line[0]);
				bool toClockwise = line[1] == "1";

				if (toClockwise)
					ants[i] = (pos + t) % l;
				else
					ants[i] = ((pos - t) % l + l) % l;

				if (toClockwise)
					count += (pos + t) / l;
				else
					count -= (l - pos - 1 + t) / l;
			}

			Array.Sort(ants);

			count = (count % n + n) % n;

			var sb = new StringBuilder();
			for (int i = 0; i < n; i++)
			{
				int idx = (int)((i + count) % n);
				sb.AppendLine(ants[idx].ToString());
			}

			Console.Write(sb.ToString());
		}
	}
}


Measured memory_bytes: 48424
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;


using Graph=vector<vector<int>>;//グラフ型
void dfs(const Graph &G,int v/*根*/,vector<bool> &seen){
    seen[v]=true;  //vを訪問済にする
    for(auto next_v:G[v]){ //訪問済にしたvとつながっている場所を順番に探す
        if(seen[next_v]) continue; //もし探索済みならスルー
        dfs(G,next_v,seen); //再帰的に探索
    }
}

void bfs(const Graph &G,queue<int> &que/*発見したが訪問はしていない*/,vector<int> &dist/*開始地点からの距離*/){
    while(!que.empty()){
        int v=que.front();//queのうち先頭のものからスタート
        que.pop();//先頭を削除

        for(int nv :G[v]){//vとつながっている点を列挙
            if(dist[nv]!=-1) continue;//発見済(=距離が格納されている)であればスルー
            dist[nv]=dist[v]+1;//vとつながっている点に距離の情報を追加
            que.push(nv);//vとつながっている点を発見済にする
        }
    }
}

string swap_s(string &s){
    for(int i=0;i<s.length()/2;++i){
        swap(s[i],s[s.length()-i-1]);
    }
    return s;
}

int main(void){
    string s;
    char c;
    int q,t,f;
    bool turn=false;
    cin>>s>>q;
    deque<char> d;

    for(int i=0;i<s.length();++i){
        d.push_back(s[i]);
    }
    for(int i=0;i<q;++i){
        cin>>t;
        if(t==1){
            turn=!turn;
        }
        else{
            cin>>f>>c;
            if(f==1){
                if(turn)d.push_back(c);
                else d.push_front(c);
            }
            else{
                if(turn)d.push_front(c);
                else d.push_back(c);
            }
        }
    }
    
    if(turn){
        for(int i=d.size()-1;i>=0;--i){
            cout<<d[i];
        }
    }
    else{
        for(int i=0;i<d.size();++i){
            cout<<d[i];
        }
    }
}


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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    lli n, k, x, ans=INF ;
    vlli left, right ;
    cin>> n >> k ;
    for(int i=0 ; i<n ; i++)
      {
        cin>> x ;
        if(x>0) right.pb(x) ;
        else left.pb(-x) ;
      }
    reverse(all(left)) ;
    if(left.size()>=k) ans=min(ans, left[k-1]) ;
    if(right.size()>=k) ans=min(ans, right[k-1]) ;
    for(int i=0 ; i<right.size() ; i++) if(k-i-2>=0 && k-i-2<left.size()) ans=min({ans, 2*right[i]+left[k-i-2], right[i]+2*left[k-i-2]}) ;
    cout<< ans ;
  }


Measured memory_bytes: 1656
s = input()
t = input()

def z_algorithm(s):
    n = len(s)
    res = [0] * n
    i = 1
    j = 0
    while i < n:
        # i番目以降の一致文字数
        while i + j < n and s[j] == s[i + j]:
            j += 1
        res[i] = j

        # 一文字も一致しない場合，次の文字へ
        if j == 0:
            i += 1
            continue

        # 一致したところまでを埋める
        k = 1
        while i + k < n and k + res[k] < j:
            res[i + k] = res[k]
            k += 1
        
        i += k
        j -= k
        
    return res


n = len(t)
if n > len(s):
    ss = s * (n // len(s) + 1)
else:
    ss = s * 2

z = z_algorithm(t + ss * 2)
z = [min(z[i], n) for i in range(n, len(z))]

ans = 0
for i in range(n):
    c = 0
    for v in z[i::n]:
        if v == n:
            c += 1
        else:
            c = 0
        ans = max(ans, c)
        
if ans <= len(ss) // n:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 151400
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int x, y, z, e;
        int min;

        Scanner sc = new Scanner(System.in);
        while ((e = Integer.parseInt(sc.next())) != 0) {
            min = e;
            for (int i = 0; i * i * i <= e; i++) {
                for (int j = 0; j * j <= e; j++) {
                    x = e - i * i * i - j * j;
                    if (x < 0) continue;
                    if (x + i + j < min) {
                        min = x + i + j;
                    }
                }
            }
            System.out.println(min);
        }
    }
}



Measured memory_bytes: 35332
#include<iostream>
using namespace std;
int main(){
	unsigned long long a,b[100],n,m;
	cin>>a;
	for(int i=1;i<=a;i++){
		cin>>b[i-1];
	}
	unsigned long long stage=b[0];
	for(int i=1;i<=a;i++){
		if(stage<b[i-1]){
			stage=b[i-1];
		}
	}
	n=stage;
	for(int i=0;i<a;i++){
		m=n;
		while(n%b[i]!=0){
			n+=m;
		}
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    LL ans = 0;
    for (int y: b) {
        auto ia = lower_bound(a.begin(), a.end(), y);
        LL ac = ia - a.begin();
        auto ic = upper_bound(c.begin(), c.end(), y);
        LL cc = c.end() - ic;
        ans += ac * cc;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

const int N = 401;
ll dp[N][N];

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

    int n;
    cin >> n;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    partial_sum(a.begin(), a.end(), a.begin());

    for (int i = 2; i <= n; ++i) {
        for (int l = 0, r = i; r <= n; ++l, ++r) {
            dp[l][r] = LLONG_MAX;
            for (int k = l + 1; k < r; ++k) {
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r]);
            }
            dp[l][r] += a[r] - a[l];
        }
    }

    cout << dp[0][n] << endl;

    return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		double x = 0;
		
		while(true) {
	        int a = scan.nextInt();
	        String op = scan.next();
	        int b = scan.nextInt();
	        
			if (op.equals ("?")){
				break;
			}
			else if(op.equals ("+")) {
				x = a+b;
			}
			else if(op.equals ("-")) {
				x = a-b;
			}
			else if(op.equals ("*")) {
				x = a*b;
			}
			else if(op.equals ("/")) {
				double A = a;
				x = A/b;
			}
			System.out.println((int) x);
		}
		
	}

}

Measured memory_bytes: 26324
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C;
int a[N];
int main(){
#ifdef LOCAL
	freopen("D.in","r",stdin);//freopen("D.out","w",stdout);
#endif
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]);
	int ans=0;
	rep(i,2,n+1){
		if(a[i]==i&&a[i-1]==i-1)a[i]=0,ans++;
		else if(a[i-1]==i-1)ans++;
	}
	printf("%d\n",ans);
	return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------

//int->string型の桁数
int digit(ll a){
    int digitA;
    digitA = to_string(a).length();
    return digitA;
}

void split_int(vector<int> &v,string s){
    for(auto item:s){
        v.emplace_back(item-'0');
    }
}

ll sum;
void dfs(ll num,string str){
    for(ll i=0; i<str.size()-1;i++){
        sum+=num+stoll(str.substr(0,i+1))+stoll(str.substr(i+1,str.size()-i-1));
        dfs(num+stoll(str.substr(0,i+1)),str.substr(i+1,str.size()-i-1));
    }
}

signed main(){
    SCIN(s);
    sum=stoll(s);
    dfs(0,s);
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

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

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

bool f[100010];

signed main()
{
    int N, A, B; cin >> N >> A >> B;

    string S; cin >> S;

    int al = 0;
    int kai = 0;

    rep(i, N) {
        if (S[i] == 'c') continue;

        if (al >= A + B) break;

        if (S[i] == 'a') {
            f[i] = true;
            al++;
        } else {
            if (kai < B) {
                f[i] = true;
                kai++;
                al++;
            }
        }
    }

    rep(i, N) {
        cout << (f[i] ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 100000000000009;
ll i;

int main(){
    ll a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k)cout<<":(";
    else cout<<"Yay!";
    cout<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#define MAX_A 1'000'001

using namespace std;

bool A[MAX_A]{};

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

int main() {
  int s;
  cin >> s;
  int cnt = 1;
  A[s] = true;
  while (true) {
    s = f(s);
    ++cnt;
    if (A[s]) {
      printf("%d\n", cnt);
      return 0;
    } else {
      A[s] = true;
    }
  }
}

Measured memory_bytes: 3156
#include <stdio.h>
char mp[100][101];
char serchFlag[100][100];
void serch(int x, int y, int H, int W, char f) {
	if(0 <= x && x < H && 0 <= y && y < W && !serchFlag[x][y] && mp[x][y] == f) {
		serchFlag[x][y] = 1;
		serch(x + 1, y, H, W, f);
		serch(x - 1, y, H, W, f);
		serch(x, y + 1, H, W, f);
		serch(x, y - 1, H, W, f);
	}
}
int solve(int H, int W) {
	int i, j, num;
	for(i = 0; i < H; ++ i) for(j = 0; j < W; ++ j) serchFlag[i][j] = 0;
	num = 0;
	for(i = 0; i < H; ++ i) {
		for(j = 0; j < W; ++ j) {
			if(!serchFlag[i][j]) {
				serch(i, j, H, W, mp[i][j]);
				num ++;
			}
		}
	}
	return num;
}
int main() {
	int i, H, W;
	while(1) {
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i = 0; i < H; ++ i) scanf("%s", mp[i]);
		printf("%d\n", solve(H, W));
	}
	return 0;
}

Measured memory_bytes: 1088
import itertools

N = int(input())
P = tuple([int(i) for i in input().split()])
Q = tuple([int(i) for i in input().split()])

permutations = list(itertools.permutations(range(1, N + 1)))

p_num = permutations.index(P) + 1
q_num = permutations.index(Q) + 1

print(abs(p_num - q_num))

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    VVI A(N,VI(N-1)); REP(i,N)REP(j,N-1){cin >> A[i][j]; A[i][j]--;}
    map<P,int> m;
    int t = 0;
    REP(i,N-1)FOR(j,i+1,N){
        m[P(i,j)] = t++;
    }

    VI deg(N*(N-1),0);
    VI edge[N*(N-1)];
    REP(i,N)REP(j,N-2){
        edge[m[P(min(i,A[i][j]),max(i,A[i][j]))]].push_back(m[P(min(i,A[i][j+1]), max(i,A[i][j+1]))]);
        deg[m[P(min(i,A[i][j+1]), max(i,A[i][j+1]))]]++;
    }

    queue<int> q;
    REP(i,N*(N-1)){
        if(deg[i] == 0) q.push(i);
    }

    int day = 0;
    queue<int> q2;
    while(q.size()){
        day++;
        while(q.size()){
            for(int n : edge[q.front()]){
                deg[n]--;
                if(deg[n] == 0) q2.push(n);
            }
            q.pop();
        }
        if(q2.empty()) break;
        swap(q,q2);
    }
    REP(i,N*(N-1)){
        if(deg[i] ){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
    return 0;
}

Measured memory_bytes: 80384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

ll INF = 1000000007;
ll MAX = 200000;
ll fac[200001];
ll inv[200001],finv[200001];

ll njo(ll a, ll n, ll mod){
  ll res = 1;
  while(n > 0){
    if(n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void COMinit(){
  inv[1] = 1;
  finv[0] = finv[1] = 1;
  for(int i  =2; i <= MAX; i++){
    inv[i] =INF - inv[INF%i]*(INF/i)%INF;
    finv[i] = finv[i-1]*inv[i]%INF;
  }
}

void faccul(ll n){
  fac[1] = n%INF;
  for(int i = 2; i <= MAX; i++){
    fac[i] = fac[i-1]*(n-i+1)%INF;
  }
}

ll COM(ll n, ll k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[k]*finv[k]%INF;
}

int main(void){
  ll n,a,b; cin >> n >> a >> b;
  ll ans = njo(2,n,INF)-1;
  COMinit();
  faccul(n);
  ans -= COM(n,a) + COM(n,b);
  while(1){
    if(ans < 0){
      ans += INF;
    }
    else break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	
	public static void Main(string[] args)
	{
 		var n = Console.ReadLine().ToInt();
 		var ds = Input();
 		var m = Console.ReadLine().ToInt();
 		var ts = Input();
 		var d = new Dictionary<long, int>(n);
 		var t = new Dictionary<long, int>(n);
 		for(int i = 0; i < n; i++)
 		{
 			var key = ds[i].ToLong();
 			if(!d.ContainsKey(key))
 				d.Add(key, 0);
 			d[key]++;
 		}
 		
 		for(int i = 0; i < m; i++)
 		{
 			var key = ts[i].ToLong();
 			if(!t.ContainsKey(key))
 				t.Add(key, 0);
 			t[key]++;
 		}
 		
 		
 		foreach(var k in t.Keys)
 		{
 			if(!d.ContainsKey(k) || d[k] < t[k])
 			{
 				Console.WriteLine("NO");
 				return;
 			}
 		}
 		Console.WriteLine("YES");
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 49156
#include <iostream>
#include <vector>


int main()
{
    int N;
    std::cin >> N;
    
    std::vector<int> P(N);
    for(int i = 0; i < N; ++i)
    {
        std::cin >> P[i]; 
    }
    
    
    int min = 200000;
    int ans = 0;
    for(int i = 0; i < N; ++i)
    {
        if(min >= P[i])
        {
            ans++;
            min = P[i];
        }
    }
    
    std::cout << ans;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
  public static void main(String[] args) {
    int sum = 0;
    int i = 0;
    int sw = 0;
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int stb[] = new int[N];
    while(sc.hasNextInt()){ 
      int s = sc.nextInt();
      stb[i] = s;
      i++;
      sum = sum + s;
      if (!(numplace(s) == 0)) {      //一の位がゼロ以外
        sw = 1;
      }
    }
    if (sw == 0)  {
      System.out.println(0);
      System.exit(0);
    } else if (numplace(sum) == 0) {
      Arrays.sort(stb);
      for (i = 0; i < N ; i++) {
        //System.out.println(Arrays.toString(stb));
        int num = stb[i];
        if (!(numplace(sum-num) == 0)) {
          sum = sum - num;
          break;
        }
      }
    }
    System.out.println(sum);
  }
  private static int numplace(int numchk) {
     return numchk % 10;
  }
}

Measured memory_bytes: 21844
H, W = map(int, input().split())
s = []
for _ in range(H):
    s += [list(input())]

ls = [[0]*W for _ in range(H)]
ls[0][0] = int(bool(s[0][0]=="#"))

for i in range(1,W):
    ls[0][i] = ls[0][i-1]+ int(bool(s[0][i]=="#" and s[0][i-1]=="."))
    
for j in range(1,H):
    ls[j][0] = ls[j-1][0]+ int(bool(s[j][0]=="#" and s[j-1][0]=="."))

for i in range(1,W):
    for j in range(1,H):
        ls[j][i] = min(ls[j][i-1]+ int(bool(s[j][i]=="#" and s[j][i-1]==".")),
                       ls[j-1][i]+ int(bool(s[j][i]=="#" and s[j-1][i]==".")))
        
print(ls[-1][-1])


Measured memory_bytes: 3316
#include<stdio.h>
int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    if(a > b){
        printf("a > b\n");
    }else if(a == b){
        printf("a == b\n");
    }else{
        printf("a < b\n");
    }
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define ull unsigned long long int
#define ll long long int
#define pb push_back
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MOD 1000000007 
                                 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

 
int main() {
    
    fastio;
    ll n;
    cin >> n;
    ll ans = exp(10, n, MOD);
    ans += exp(8, n, MOD);
    ans %= MOD;
    ans -= (2 * exp(9, n, MOD));
    ans += MOD;
    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout << ans ;
 
    return 0; 
}

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

import sys, math
sys.setrecursionlimit(300000)


def solve(N: int, A: int, B: int):
    tmp = math.floor(N / (A + B))
    ret = tmp * A
    ret += min(A, N - tmp * (A + B))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//
//  main.cpp
//  contest
//
//  Created by TmpGuest on 2020/4/18.
//  Copyright © 2020 TmpGuest. All rights reserved.
//

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
int main() {
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,x;
    cin>>n;
    vector<int> v(n,0);
    for(int i=0;i<n-1;i++) {
        cin>>x;
        v[x-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<v[i]<<endl;
    }
        
    
    return 0;
}


Measured memory_bytes: 3984
// vim: foldmethod=marker
#include <iostream> // cout, endl, cin{{{
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;/*}}}*/


bool isPrimeNumber(int x) 
{
  for (int i = 2; i < x; ++i) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main(int argc, char *argv[])
{
  int x;
  int ans;
  cin >> x;

  while(true) {
    if (isPrimeNumber(x)) {
      ans = x;
      break;
    }
    x++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 888