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

int main() {
  int N, K, result=1, ans=1025;
  cin >> N >> K;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < i; j++) {
      result = result * 2;
    }
    for (int a = 0; a < N-i; a++) {
      result = result + K;
    }
    if (result < ans) ans = result;
    result = 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3612
/*
***************************************************************************
 name  : ITP1_05_D.cpp
 title : Structured Programming
 make  : 2018/08/15 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

// Prototype
void Call(int n); // Print multiples of 3 or numbers using "3"

main(void){
  int n; // integer

  std::cin >> n; // input "n"

  Call(n);

  std::cout << std::endl; // new line

}

// +--------------------------------------------------------+
// | name       : Call                                      |
// | obtain     : int n                                     |
// | return     : none                                      |
// | processing : Print multiples of 3 or numbers using "3" |
// +--------------------------------------------------------+
void Call(int n){
  int x; // integer
  int i; // index

  // initialized i = 1 and x = i
  // continue i <= n
  // increment i and x = i at loop update
  for(i = 1,x = i;i <= n;i++,x = i){
    // multiples of 3
    if(x%3 == 0){
      std::cout << " " << i; // output " i"
    }
    else{
      // numbers using "3"
      // continue x != 0
      // x /= 10 at loop update
      for(;x;x /= 10){
        if(x%10 == 3){
          std::cout << " " << i; // output " i"
          break;
        }
      }
    }
  }

}



Measured memory_bytes: 3108
import re
N, Q = map(int, input().split())
S = input()
query = [list(map(int, input().split())) for _ in range(Q)]
s = re.sub(r"AC", "0", S)
accum = [0 for _ in range(N)]
for i in range(1, N):
    accum[i] = accum[i-1]
    if S[i-1]=="A" and S[i]=="C":
        accum[i] += + 1

for l,r in query:
    print(accum[r-1]-accum[l-1])

Measured memory_bytes: 31392
#include <iostream>
#include <cstring>
#include <cmath>
#define mod 1000000007
using namespace std;
typedef long long ll;

int main() {
    int n , m;
    cin >> n >> m;
    if(abs(n - m) > 1) cout << 0 << endl;
    else {
        ll ans1 = 1 , ans2 = 1;
        for(int i = 1 ; i <= n ; i++) {
            ans1 *= i;
            ans1 %= mod;
        }
        for(int i = 1 ; i <= m ; i++) {
            ans2 *= i;
            ans2 %= mod;
        }
        if(n != m) cout << (ans1 * ans2) % mod << endl;
        else cout << (2 * ans1 * ans2) % mod << endl;
    }
    return 0;
}

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

using namespace std;
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif

#define int long long
typedef long long ll;
//constexpr int INF = 1e9;
//constexpr int MOD = 1000000007;

decltype(1) main()
{
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> red(a), green(b), non(c);
    for (int i = 0; i < a; ++i)
    {
        cin >> red[i];
    }
    for (int i = 0; i < b; ++i)
    {
        cin >> green[i];
    }
    for (int i = 0; i < c; ++i)
    {
        cin >> non[i];
    }

    sort(red.begin(), red.end(), greater<int>());
    sort(green.begin(), green.end(), greater<int>());
    for (int i = 0; i < x; ++i)
    {
        non.push_back(red[i]);
    }
    for (int i = 0; i < y; ++i)
    {
        non.push_back(green[i]);
    }
    sort(non.begin(), non.end(), greater<int>());

    int ans = 0;
    for (int i = 0; i < x + y; ++i)
    {
        ans += non[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6256
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
using std::pair;
using std::cin;
using std::cout;
using std::vector;
using std::make_pair;
const int mod = 1e9 + 7;
int n; 
int main( )
{
 std::ios::sync_with_stdio( false ); 
 cin >> n;
 vector < int > a( n + 1, 0 );
 vector < int > flag( n + 1, 0 );
 For( i, 2, n )
 {
  if( !flag[ i ] )
  {
   for( int j = i; j <= n; j += i )
    flag[ j ] = i;
  }
 }
 For( i, 1, n )
 {
  int j = i;
  while( j > 1 )
  {
   int d = flag[ j ], now = 0;
   while( j % d == 0 )
    j /= d,
    now++;
   a[ d ] += now;
  }
 }
 long long ans = 1;
 for( auto &to: a )
  ans = ans * ( to + 1 ) % mod;
 cout << ans << std::endl;
 return 0;
}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

char n[1001];

int main(){
	cin.tie(0);
	
	while(cin>>n,n[0]!='0') {
	    int t=0;
	    for(int i=0;n[i]!='\0';i++) {
	        t += n[i]-'0';
	    }
	    
	    cout<<t<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
int main() {
  int in(N);

  priority_queue<pair<int, int>> q;
  rep(i, N) {
    int in(a);
    q.emplace(a, i);
  }

  vector<vector<ll>> dp(N+1, vector<ll>(N+1, 0));
  rep(i, N) {
    auto [a, idx] = q.top(); q.pop();
    rep(j, i+1) {
      chmax(dp[i+1][j], dp[i][j] + 1ll * a * abs(N-(i-j)-1-idx));
      chmax(dp[i+1][j+1], dp[i][j] + 1ll * abs(idx - j) * a);
    }
  }
  cout << *all(max_element, dp[N]) << endl;

  return 0;
}


Measured memory_bytes: 34672
#include <iostream>

using namespace std;

int main(void){
  int N, H, W, count = 0;
  cin >> N >> H >> W;

  long long a, b;
  for(int i = 0; i < N; i++){
    cin >> a >> b;
    if(H <= a && W <= b){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int sum=0;
  if(N==10||N==100||N==1000||N==10000||N==100000)sum=10;
  else{
    while(N>0){
      sum+=N%10;
      N/=10;
    }
  }
  cout<<sum;
}

Measured memory_bytes: 256
s = list(input())
l = 0
r = len(s)-1
cnt = 0
while r-l >0:
    if s[r] == s[l]:
        l += 1
        r -= 1
    elif s[r] != s[l] and s[r] == "x":
        r -=1
        cnt += 1
    elif s[r] != s[l] and s[l] == "x":
        l += 1
        cnt += 1
    else:
        print(-1)
        exit()
print(cnt)

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  string s, t; std::cin >> s >> t;
  sort(rng(s)), sort(rrng(t));
  std::cout << (s < t ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = 10**9+7
if m > n:
    n,m = m,n
if not (0 <= n-m <= 1):
    print(0)
    exit()
 
if n == m:
    num = 2
    n = 1
else:
    num = 1
t = 1
for i in range(1,m+1):
    t *= i
    t %= a
print(num*t*t*n%a)

Measured memory_bytes: 3064
from itertools import product

H, W = map(int, input().split())
C = ['.' * (W + 2)] + ['.' + input() + '.' for _ in [0] * H] + ['.' * (W + 2)]

ans = True
for i, j in product(range(1, H+1), range(1, W + 1)):
    if C[i][j] == '#' and (
            '#' not in (C[i - 1][j], C[i + 1][j], C[i][j - 1], C[i][j + 1])):
        ans = False
        break

print('Yes' if ans else 'No')


Measured memory_bytes: 3064
// Problem : E - Coprime
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 1e6+10;

bool esPrimo[tam], isPC[tam];
int a[tam], sum[tam];
vi primos[tam];
int freq[tam];
bool isAllPC;

void criba() {
	isAllPC = true;
	fore(i, 2, tam) esPrimo[i] = true;
	fore(i, 2, tam) {
		if (!esPrimo[i]) continue;
		//primos[i].pb(i);
		int cnt = 0;
		for (int j = i; j < tam; j += i) {
			esPrimo[i] = false;
			cnt += freq[j];
			//primos[j].pb(i);
		}
		if (cnt > 1) isAllPC = false;
	}
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    fore(i, 0, n) {
    	cin >> a[i];
    	freq[a[i]]++;
    }
    criba();
    int GCD = a[0];
    fore(i, 1, n) GCD = __gcd(GCD, a[i]);
    if (isAllPC) {
    	cout << "pairwise coprime" << '\n';
    	return 0;
    }
    if (GCD == 1) {
    	cout << "setwise coprime" << '\n';
    	return 0;
    }
    cout << "not coprime" << '\n';
    return 0;
    
    int ite = 1;
    fore(i, 0, n) {
    	bool pc = true;
    	for (int p : primos[a[i]]) {
    		if (sum[p] == ite) pc = false;
    		sum[p] = ite;
    	}
    	isPC[i] |= pc;
    }
	ite++;
    for (int i = n-1; i >= 0; i--) {
		bool pc = true;
    	for (int p : primos[a[i]]) {
    		if (sum[p] == ite) pc = false;
    		sum[p] = ite;
    	}
    	isPC[i] |= pc;
    }
    bool allPC = true;
    fore(i, 0, n) {
    	allPC &= isPC[i];
    }
    if (allPC) {
    	cout << "pairwise coprime" << '\n';
    	return 0;
    }
    if (GCD == 1) {
    	cout << "setwise coprime" << '\n';
    	return 0;
    }
    cout << "not coprime" << '\n';
    return 0;
}
// Dinosaurs are cool!

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

int main()
{
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	bool ng = false;
	for (int i = N - 2; i >= 0; i--) {
		if (H[i] > H[i + 1]) {
			--H[i];
		}
		if (H[i] > H[i + 1]) {
			ng = true;
			break;
		}
	}
	puts(!ng ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 640
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            while(true) {
                string[] input = Console.ReadLine().Split();
                int[] value = new[] { int.Parse(input[0]), int.Parse(input[2]) };
                int output = 0;
                switch (input[1]) {
                    case "+":
                        output = value[0] + value[1];
                        break;
                    case "-":
                        output = value[0] - value[1];
                        break;
                    case "/":
                        output = value[0] / value[1];
                        break;
                    case "*":
                        output = value[0] * value[1];
                        break;
                    case "?":
                        return;
                }
                Console.WriteLine(output);
            }
        }
    }
}

Measured memory_bytes: 5712
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define ll long long
using namespace std;

ll mod=1000000007;
struct UnionFind{
    public:
    vector<int> data;
    UnionFind(ll sz){
        data.assign(sz, -1);
    }
    int find(int p){
        if(data[p]<0) return p;
        return data[p]=find(data[p]);
    }
    bool unite(int X, int Y){
        X=find(X), Y=find(Y);
        if(X==Y) return false;
        if(data[X]>data[Y]) swap(X, Y);
        data[X] += data[Y];
        data[Y]=X;
        return true;
    }
    ll size(int k){
        return -data[find(k)];
    }
};

ll modpow(ll a, ll b, ll m){
    ll res=1, p=0, now=a;
    b %= (m-1);
    for(int i=0; b>p; ++i){
        if(b&((ll) 1<<i)){
            res=(res*now)%m;
            p |= ((ll) 1<<i);
        }
        now=(now*now)%mod;
    }
    return res;
}

int main() {
	int N;
	ll X, Y;
	cin >> N >> X >> Y;
	vector<vector<int>> b(N+1);
	vector<pair<ll, int>> t(N);
	for(int i=0; i<N; ++i){
		int c;
		ll w;
		cin >> c >> w;
		t[i]=make_pair(w, c);
	}
	sort(t.begin(), t.end());
	vector<pair<ll, int>> mn1(N+1, make_pair(1e9, -1)), mn2(N+1, make_pair(1e9, 0));
	UnionFind uf(N);
	for(int i=0; i<N; ++i){
		if(mn1[t[i].second].second<0) mn1[t[i].second]=make_pair(t[i].first, i);
		else if(t[i].first+mn1[t[i].second].first<=X){
			uf.unite(i, mn1[t[i].second].second);
		}
		b[t[i].second].push_back(i);
	}
	for(int i=1; i<=N; ++i){
		if(i!=t[0].second) mn2[i]=make_pair(t[0].first, 0);
	}
	int now=1;
	while(now<N){
		if(t[now].second!=t[0].second) break;
		++now;
	}
	if(now<N) mn2[t[0].second]=make_pair(t[now].first, now);
	for(int i=0; i<N; ++i){
		if(t[i].first+mn2[t[i].second].first<=Y){
			uf.unite(i, mn2[t[i].second].second);
		}
	}
	ll ans=1;
	vector<ll> cnt(N+1, 0);
	vector<int> num(N+1, 0);
	for(int i=0; i<N; ++i) ++cnt[uf.size(i)];
	for(int i=1; i<=N; ++i) cnt[i] /= i;
	for(int i=1; i<=N; ++i){
		vector<int> see;
		for(int j=0; j<b[i].size(); ++j){
			int aa=uf.find(b[i][j]);
			if(num[aa]==0) see.push_back(aa);
			++num[aa];
		}
		for(int j=0; j<see.size(); ++j){
			cnt[num[see[j]]]=(cnt[num[see[j]]]+mod-2)%(mod-1);
			num[see[j]]=0;
		}
	}
	ll frac=1;
	for(int i=1; i<=N; ++i){
		frac=(frac*i)%mod;
		ans=(ans*modpow(frac, cnt[i], mod))%mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 21760
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}, t;
    cin >> t;
    for (int i = 0; i < 7; i++) if (s[i] == t) {
        if (i == 0) cout << 7;
        else cout << 7 - i;
    }
}


Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

struct grid{
    int h;
    int w;
    grid(){
        h = 0;
        w = 0;
    }
    grid(int h, int w){
        this->h = h;
        this->w = w;
    }
    bool operator < (const grid &a) const{
        if(this->h < a.h)   return true;
        if(this->h == a.h && this->w < a.w) return true;
        return false;
    }
    void print(){
        printf("h:%2d w:%2d\n", h, w);
    }
};

int main(){
    int h,w,m;    cin >> h >> w >> m;
    set<grid>bom;
    vector<int>row(h);
    vector<int>col(w);
    int row_max = 0;
    int col_max = 0;
    rep(i, m){
        int h_i, w_i;   cin >> h_i >> w_i;
        h_i--;
        w_i--;
        bom.emplace(h_i, w_i);
        row_max = max(row_max, ++row[h_i]);
        col_max = max(col_max, ++col[w_i]);
    }
    vector<int>row_max_ptr;
    vector<int>col_max_ptr;
    rep(i, h)   if(row[i] == row_max)   row_max_ptr.push_back(i);
    rep(i, w)   if(col[i] == col_max)   col_max_ptr.push_back(i);
    for(int i : row_max_ptr)  for(int j : col_max_ptr){
        if(bom.count(grid(i, j))) continue;
        cout << row_max + col_max << endl;
        return 0;
    }
    cout << row_max + col_max - 1<< endl;
    return 0;
}


Measured memory_bytes: 23712
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	int ansa, ansb, ansc;
	cin >> a >> b >> c;

	ansa = a + b;
	ansb = b + c;
	ansc = c + a;

	if (ansa < ansb && ansa < ansc) cout << ansa << endl;
	else if (ansb < ansc) cout << ansb << endl;
	else cout << ansc << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

		for (int i = 1; i <= 9; i++)
			for (int j = 1; j <= 9; j++)
				if (i * j == n) { System.out.println("Yes"); return; }

		System.out.println("No");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

signed main(){
  int n;
  cin>>n;
  int a[n];
  r(i,n) cin>>a[i];
  stack<int>st;
  st.push(a[0]);

  int sum=0;

  for(int i=1;i<n;i++){
    int x=a[i];
    while(!st.empty() && st.top()>x){
      int t=st.top();st.pop();
      while(!st.empty() && st.top()==t){
	st.pop();
      }
      sum++;
    }
    st.push(x);
  }

  set<int>S;
  while(!st.empty()) S.insert(st.top()),st.pop();

  cout<<S.size()+sum<<endl;
}



Measured memory_bytes: 13104
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

const dp = {};
const memo = (i, m) => {
  dp[m] = true;
  if (i === n) {
    return;
  }
  memo(i + 1, m);
  memo(i + 1, m + Number(A[i]));
}
memo(0, 0);

for (let i = 0; i < q; i++) {
  console.log(dp[mi[i]] ? 'yes' : 'no');
}


Measured memory_bytes: 16840
n = gets.to_i               # 単一整数
ary = gets.split.map(&:to_i)  # スペースで区切られた複数の整数
ary.sort!

ans = "YES"
i = 0

while i < n do
  if ary[i] == ary[i+1] then
    ans = "NO"
    break
  end
  i = i + 1
end

puts ans


Measured memory_bytes: 17508
n = int(input())
list = list(map(int, input().split()))
count = 0
operator = True

while operator:
    for i in range(n):
        if list[i]%2 == 0:
            list[i] = list[i] // 2
            if i == n-1:
                count += 1
        else:
            operator = False
            break

print(count)

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

int main()
{
	int n, k;
	while (scanf("%d%d", &n, &k) != EOF)
	{
		int remind = (n + 1) / 2;
		puts(k <= remind ? "YES" : "NO");
	}
	return 0;
}


Measured memory_bytes: 256
# AOJ 1108: A Long Ride on a Railway
# Python3 2018.7.14 bal4u

def combi(k, a, w):
	global len, ans
	for b in range(1, n+1):
		if b == a: continue
		for i in range(m):
			if not f[i] and ((tbl[i][0] == a and tbl[i][1] == b) or
			                 (tbl[i][0] == b and tbl[i][1] == a)):
				f[i] = 1
				tmp[k] = b
				combi(k+1, b, w + tbl[i][2])
				f[i] = 0
	if w > len:
		len = w
		ans = tmp[:k]	

ans, tmp = [0]*12, [0]*12
while True:
	n, m = map(int, input().split())
	if n == 0: break
	tbl = [list(map(int, input().split())) for i in range(m)]
	f, ans = [0]*m, []
	len = 0
	for a in range(1, n+1):
		for b in range(1, n+1):
			if a == b: continue
			for i in range(m):
				if not f[i] and ((tbl[i][0] == a and tbl[i][1] == b) or
				                 (tbl[i][0] == b and tbl[i][1] == a)):
					f[i] = 1
					tmp[0], tmp[1] = a, b
					combi(2, b, tbl[i][2])
					f[i] = 0
	print(len)
	print(*ans)


Measured memory_bytes: 5616
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    int p[n]; for (int i = 0; i < n; i++) cin >> p[i];
    sort(p, p+n);
    cout << accumulate(p, p+k, 0LL) << endl;
}


Measured memory_bytes: 3644
#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>

using namespace std;

typedef long long LL;

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

const int MOD = 1000000007;
 
char shiftChar(char c, int N)
{
    int i = c - 'A';
    i = (i + N) % 26;
    return ('A' + i);
}

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

    string S;
    int N;
    cin >> N >> S;

    rep(i, S.length()) {
        cout << shiftChar(S[i], N);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

int n,m;
int mod = 1000000007;


int main(){
  cin>>n>>m;
  if(abs(n-m)>1){
    cout<<0<<endl;
    return 0;
  }
  long long tmp1,tmp2;
  tmp1 = n;
  tmp2 = m;
  for(int i = n-1;i>0;i--){
    tmp1 = (tmp1 * i)%mod;
    //tmp1 %= mod;
  }
  for(int i = m-1;i>0;i--){
    tmp2 = (tmp2 * i)%mod;
    //tmp2 %= mod;
  }
  int a = 1;
  if((n %2 == 0 && m % 2 == 0) ||( n%2 == 1 && m%2 == 1))
    a = 2;
  cout<<(tmp1*tmp2*a)%(long long)mod<<endl;
    

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
char board[3][3];

int main()
{
//	cut here before submit 
//	freopen ("testcase.TTT", "r", stdin );
	string str = "";
	while (cin >> str ){
		memset (board, 0, sizeof (board ) );
		rep (i, 9 ) board[i/3][i%3] = str[i];
		char win = 'd';
		rep (i, 3 ){
			if (board[i][0] != 's' && board[i][0] == board[i][1] && board[i][0] == board[i][2] ){
				win = board[i][0];
				break;		
			} //end if
		} // end rep
		rep (j, 3 ){
			if (board[0][j] != 's' && board[0][j] == board[1][j] && board[0][j] == board[2][j] ){
				win = board[0][j];		
				break;
			} //end if
		} // end rep
		if (board[0][0] != 's' && board[0][0] == board[1][1] && board[0][0] == board[2][2] ){
			win = board[0][0];
		} // end if
		if (board[0][2] != 's' && board[0][2] == board[1][1] && board[0][2] == board[2][0] ){
			win = board[0][2];
		} // end if
		cout << win << endl;
	} // end loop

	return 0;
}

Measured memory_bytes: 1180
#include<stdio.h>
int h,H[100];

int making(int,int);

int main(){
  int i,p,Q;

  scanf("%d",&h);
  
  for( i = 0 ; i < h ; i++ ){
    
    scanf("%d",&H[i]);

  }
  
  scanf("%d",&p);
  
  for( i = 0 ; i < p ; i++ ){
    
    scanf("%d",&Q);
    
    if(making(0,Q))printf("yes\n");
    
    else printf("no\n");
    
  }
  
  return 0;
  
}

int making(int x,int y){
  
  int tom;
  
  if( y == 0 )return 1;
  
  if( x >= h )return 0;
  
  tom = making( x + 1 , y )||making( x + 1 , y - H[x] );
  
  return tom;
  
}




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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

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

int main(){
    int a, b, c, x, y, ans = 0;
    cin >> a >> b >> c >> x >> y;

    if(a+b > 2*c) {
        if(x>y) {
            ans += 2*c*y;
            x -= y;
            if(a > 2*c) {
                ans += 2*x*c;
            } else {
                ans += x*a;
            }
        } else {
            ans += 2*c*x;
            y -= x;
            if(b > 2*c) {
                ans += 2*y*c;
            } else {
                ans += y*b;
            }
        }

    } else {
        ans =  a*x + b*y;
    }

    cout << ans << endl;

    return 0;
}


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

public class Main{
    public static void main(String argas[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	int n=Integer.parseInt(br.readLine());


	Map<String,Integer> map=new HashMap<>();
	
	for(int i=0;i<n;i++){
	    map.put(br.readLine(),0);
	}

	int m=Integer.parseInt(br.readLine());

	int count=0;
	for(int i=0;i<m;i++){
	    String s=br.readLine();

	    if(map.containsKey(s)){
		if(count%2==0){
		    System.out.println("Opened by "+s);
		}else{
		    System.out.println("Closed by "+s);
		}
	        count++;
	    }else{
		System.out.println("Unknown "+s);
	    }
	}
    }
}



Measured memory_bytes: 25068
N = int(input())
D, X = map(int, input().split())
a = [int(input()) for i in range(N)]
cnt = N

# print(N)
# print(D)
# print(X)
# print(a)
# print(cnt)

for i in range(1, D):
    # print("%d:" %i)
    for j in range(N): 
     if(i % a[j] == 0):
        #  print("check%d" %j)
         cnt += 1
        #  print(cnt)

cnt += X
print(cnt)

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

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

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;

    int N, K, Q;
    cin >> N >> K >> Q;
    vi A(Q);
    rep(i, Q)
    {
        cin >> A[i];
        A[i]--;
    }

    vi point(N, K - Q); // 持ち点をあらかじめQ点分全員からひいておく

    rep(i, Q)
    {
        point[A[i]]++;
    }

    rep(i, N)
    {
        if(point[i] > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 1408
def main
  s_places = Array.new(26) {|idx| Array.new }
  t_places = Array.new(26) {|idx|  Array.new }
  # pp s_places.length

  # a : 97
  # z : 122
  gets.chomp.chars.each_with_index do |c, i|
    s_places[c.ord - 97] << i
  end
  s_places.sort!
  # pp s_places

  gets.chomp.chars.each_with_index do |c, i|
    t_places[c.ord - 97] << i
  end
  t_places.sort!
  # pp t_places

  if s_places == t_places
    puts 'Yes'
  else
    puts 'No'
  end

end

if __FILE__ == $0
  main
end


Measured memory_bytes: 27256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N, ans = 0;
    cin >> N;
    for(ll i = 1; i <= N; i++) {
        string s = to_string(i);
        ans += (s.size() % 2 == 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 101

int M[N][N] = {};
int d[N];
int f[N];
char color[N];
int n;
int time;

void visit(int u) {
	int i;

	color[u] = 'G';
	d[u] = ++time;
	for (i=1;i<=n;i++) {
		if (M[u][i] == 1 && color[i] == 'W') {
			visit(i);
		}
	}
	color[u] = 'B';
	f[u] = ++time;
}

void dfs() {
	int i;
	for (i=1;i<=n;i++) color[i] = 'W';
	time = 0;
	for (i=1;i<=n;i++) if (color[i] == 'W') visit(i);
}

int main() {
	int i,j;
	int u,k,v;

	scanf("%d", &n);
	for (i=1;i<=n;i++) {
		scanf("%d%d",&u,&k);
		for (j=1;j<=k;j++) {
			scanf("%d",&v);
			M[u][v] = 1;
		}
	}

	dfs();

	for (i=1;i<=n;i++) {
		printf("%d %d %d\n",i,d[i],f[i]);
	}

	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int main() {
	int m1, d1, m2, d2;
	cin >> m1 >> d1;
	cin >> m2 >> d2;
	if (d1 + 1 == d2) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
// Problem : C - Green Bin
// Contest : AtCoder - AtCoder Beginner Contest 137
// URL : https://atcoder.jp/contests/abc137/tasks/abc137_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <unordered_map>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

bool areAnagram(string str1, string str2) 
{ 
    int n1 = str1.length(); 
    int n2 = str2.length(); 

    if (n1 != n2) 
        return false; 
  
    sort(str1.begin(), str1.end()); 
    sort(str2.begin(), str2.end()); 
  
    for (int i = 0; i < n1; i++) 
        if (str1[i] != str2[i]) 
            return false; 
  
    return true; 
} 

int fact(int n) 
{ 
    if (n == 0) 
        return 1; 
    return n * fact(n - 1); 
} 
  

int32_t main() 
{
    fast;
	int t;
    cin >> t;
    vector<string> v;
    for (int i=1;i<=t;i++) {
        string s;
        cin >> s;
        sort (s.begin(),s.end());
        v.pb(s);
    }
    sort (v.begin(),v.end());
    v.pb("*");
    int res=0,count=0;
    for (int i=0;i<v.size()-1;i++) {
        //cout << v[i] << endl;
        if (v[i]==v[i+1]) count++;
        else {
            count++;
            res+=(count)*(count-1)/2;
            count=0;
        }
    }
    cout << res << endl;
	
	
	return 0;
}




Measured memory_bytes: 7436
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,j,m,n,t,s,k,ans = 0;
	scanf("%d%d",&n,&m);
	if(n>=m){
		ans = n;
		n--;
	}
	else{
		ans = m;
		m--;
	}
	if(n>=m){
		ans += n;
		n--;
	}
	else{
		ans += m;
		m--;
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    long N;
    long power = 1;
    cin >> N;

    for(long i = 1; i <= N; ++i){
        power *= i;
        power %= 1000000007;
    }
    cout << power << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
  /*
  int mountains[] = { 1819, 2003, 876, 2840, 1723, 1673, 3776, 2848,
		      1592, 922 };
  */

  int mountains[10];
  int scan = 0;
  for ( scan; scan < 10; ++scan ) {
    scanf("%d", &mountains[scan]);
    // Constraints 0 <= height <= 10000
    if ( mountains[scan] < 0 || mountains[scan] > 10000 ) {
      // Number error
      return -1;
    }
  }

  int first = 0;
  int second = 0;
  int third = 0;

  int x = 0;
  for ( x; x < 10; ++x ) {
    if ( mountains[x] > first ) {
      int old_first = first;
      first = mountains[x];
      if ( old_first > second ) {
	int old_second = second;
	second = old_first;
	if ( old_second > third ) {
	  third = old_second;
	}
      }
    } else if ( mountains[x] > second ) {
      int old_second = second;
      second = mountains[x];
      if ( old_second > third ) {
	third = old_second;
      }
    } else if ( mountains[x] > third ) {
      third = mountains[x];
    }
  }

  printf("%d\n", first);
  printf("%d\n", second);
  printf("%d\n", third);

  return 0;
}

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

int main() {
	
int n,k;
cin>>n>>k;
int arr[n];
int i,sum=0;
for(i=0;i<n;i++)
{
	cin>>arr[i];
	
	
}
sort(arr,arr+n);
for(i=0;i<k;i++)
sum+=arr[i];
cout<<sum<<"\n";
	return 0;
}

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

int main()
{
    long long n ;
    cin>>n ;
    vector<long long int > arr(n) ;
    for(int i=0;i<n;i++)
        cin>>arr[i] ;
    // sort(arr.begin(),arr.end()) ;
    // unordered_map<long long int ,int> mp1 ;
    // unordered_map<long long int ,int> mp2 ;
    
    vector<pair<int,int>> vec2 ;
    vector<int> vec1 ;
    long long ans=0 ;
    for(int i=0;i<n;i++)
    {
        long long max1=0 ;
        for(auto x:vec2)
        {
           if(x.first!= arr[i] && x.second!=arr[i])
           {
                if(x.first> arr[i] && x.first > x.second)
                    max1=x.first ;
                else if(x.second > arr[i] && x.second>x.first)
                     max1=x.second ;
                else if(arr[i]>x.second && arr[i]>x.first)
                    max1=arr[i] ;
                    
                if(max1==x.first && (x.second +arr[i])>max1)
                ans++ ;
                else if(max1==x.second && (x.first+arr[i])>max1)
                ans++ ;
                else if(max1==arr[i] && (x.first+x.second)>max1)
                ans++ ;
           }
        }
        for(auto x:vec1)
        {
            if(x!=arr[i])
            vec2.push_back({x,arr[i]}) ;
        }
        vec1.push_back(arr[i]) ;
    }
    cout<<ans<<endl ;
    return 0;
}

Measured memory_bytes: 3692
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n: usize = read();
    let mut ps = vec![0; n];
    for i in 0..n {
        ps[i] = read::<usize>() - 1;
    }

    let mut pos_map = vec![0; n];
    for i in 0..n {
        pos_map[ps[i]] = i;
    }
    // println!("{:?}", pos_map);

    let mut dp = vec![1; n];
    for i in 0..n {
        if i == 0 {
            continue;
        }
        // println!("{:?}", (ps[i], ps[i] - 1, pos_map[ps[i]], pos_map[ps[i] - 1]));
        if ps[i] != 0 && pos_map[ps[i]] > pos_map[ps[i] - 1] {
            dp[ps[i]] = dp[ps[i] - 1] + 1;
        }
    }
    // println!("{:?}", dp);
    println!("{:?}", n - dp.iter().max().unwrap());
}


Measured memory_bytes: 10492
import math

a,b = map(int,input().split())
er=a/0.08
el=(a+1)/0.08
tr=b/0.1
tl=(b+1)/0.1
le = []
lt = []
for i in range(math.ceil(er),math.ceil(el)):
  le.append(i)
for i in range(math.ceil(tr),math.ceil(tl)):
  lt.append(i)
if list(set(le)&set(lt)) == []:
  print(-1)
else:
  print(min(list(set(le)&set(lt))))

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

ll t(ll x){
  return x>=0?x:INF;
}

int main(){
  ll x,y;
  cin >> x >> y;
  cout << min(t(y-x),min(abs(y+x)+1,t(x-y)+2)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

struct Card{
  char suit;
  char value;
};


int main(){
  struct Card C1[100], C2[100],l;
  int n, i,j,mini,k=0;
  char ch;
  
  scanf("%d%c", &n, &ch);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
  }
  
  for(i=0;i<n;i++){
    C2[i]= C1[i];
  }
  //B
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--)
      {
	if(C1[j].value<C1[j-1].value){
	  l=C1[j];
	  C1[j]=C1[j-1];
	  C1[j-1]=l;
	}
      }
  }
  //S
  for(i=0;i<n;i++){
    mini = i;
    for(j=i;j<n;j++){
      if(C2[j].value<C2[mini].value) mini=j;
    }
    
    l=C2[i];
    C2[i]=C2[mini];
    C2[mini]=l;
  }
  for(i=0;i<n-1;i++){
    printf("%c%c ",C1[i].suit,C1[i].value);
  }
  
  
  printf("%c%c\n",C1[i].suit,C1[i].value);
  printf("Stable\n");
  
 
 for(i=0;i<n-1;i++){
    printf("%c%c ",C2[i].suit,C2[i].value);
  }
  printf("%c%c\n",C2[i].suit,C2[i].value);
  
  
  for(i=0;i<n;i++){
    if(C1[i].suit!=C2[i].suit)k=1;
  }
  
  
  if(k==0)printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}

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

using namespace std;

int main(void){
  int a,b;
  int k;
  vector<int> array;
  cin >> a>>b>>k;
  int k_0=k-1;

  for (int i = 1; i <= 100; ++i) {
    if (a%i==0 && b%i==0) { array.push_back(i); }
  }
  cout<<array[array.size() -k]<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int N,H[105],i,j,p,r,d;

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<=N;i++)
			scanf("%d",&H[i]);
		for(i=0;i<=N;i++)
		{
			d=(i<2)?H[3]-H[2]:H[1]-H[0];
			for(j=0;j<=N;j++)
			{
				if(j==i)continue;
				p=j-1==i?j-2:j-1;
				if(p>=0&&H[j]-H[p]!=d)break;
			}
			if(j==N+1)
			{
				r=H[i];
				break;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> s(h, vector<int>(w));
	vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}
	
	for (int i = 0; i < h; i++) dp[i][0] = (s[i][0] ^ 1);
	for (int i = 0; i < w; i++) dp[0][i] = (s[0][i] ^ 1);
	
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (s[i][j]) continue;
			int val = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]});
			dp[i][j] = max(dp[i][j], val + 1);
		}
	}
	
	int ans = 0;
	for (vector<int> &v : dp) {
		ans = max(ans, *max_element(v.begin(), v.end()));
	}
	
	cout << ans * ans << '\n';
	
	return 0;
}


Measured memory_bytes: 18072
n ,y = map(int,input().split())
list = [-1,-1,-1]
for i in range(n+1):
    for j in range(n+1 - i):
        if (j *10000 + i * 5000 + (n-i-j)* 1000) == y:
                list = [i,j,(n-i-j)]
                break
        elif j*10000 > y:
                break
        
    if (j *10000 + i * 5000 + (n-i-j)* 1000) == y:
        break
    elif i*5000 > y:
        break
print(list[1],list[0],list[2])    

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

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

using namespace std;
using ll = long long;

const int INF = INT_MAX;

struct Card {
    char suit;
    int value;
    Card();
    Card(char, int);
    inline void print();
    const bool operator==(const Card) const;
};
Card::Card() {};
Card::Card(char suit, int value) : suit(suit), value(value) {};
inline void Card::print() {printf("%c %d\n", suit, value);}
const bool Card::operator==(const Card a) const {
    return (*this).suit == a.suit && (*this).value == a.value ? true : false;
}

int partition(vector<Card> &a, int p, int r) {
    int bdry = p;
    for(int i = p; i <= r; ++i) {
        if(a[i].value <= a[r].value) {
            swap(a[i], a[bdry]);
            bdry++;
        }
    }
    return bdry - 1;
}

void quick_sort(vector<Card> &a, int p, int r) {
    if(p >= r) return;
    int idx = partition(a, p, r);
    quick_sort(a, p, idx - 1);
    quick_sort(a, idx + 1, r);
}

void merge_sort(vector<Card> &a) {
    if(a.size() == 1) return;
    int mid = a.size() / 2;
    vector<Card> sorted1(mid), sorted2(a.size() - mid);
    copy(a.begin(), a.begin() + mid, sorted1.begin());
    copy(a.begin() + mid, a.end(), sorted2.begin());
    merge_sort(sorted1);
    merge_sort(sorted2);
    sorted1.emplace_back(Card('X', INF));
    sorted2.emplace_back(Card('X', INF));
    auto itr1 = sorted1.begin(), itr2 = sorted2.begin();
    rep(i, a.size()) {
        if((*itr1).value <= (*itr2).value) {
            a[i] = *itr1;
            itr1++;
        } else {
            a[i] = *itr2;
            itr2++;
        }
    }
}

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

    int n;
    cin >> n;
    vector<Card> a(n);
    rep(i, n) cin >> a[i].suit >> a[i].value;
    vector<Card> a_ = a;

    merge_sort(a_);
    quick_sort(a, 0, a.size() - 1);

    printf(a == a_ ? "Stable\n" : "Not stable\n");
    rep(i, n) a[i].print();

    return 0;
}


Measured memory_bytes: 6112
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int[] a = new int[3];
        a[0] = scan.nextInt();
        a[1] = scan.nextInt();
        a[2] = scan.nextInt();
        Arrays.sort(a);
        System.out.println(a[2] - a[0]);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 35800
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }


int dp[2001][2001];

int main() {
  memset(dp, 0, sizeof(dp));

  vector<string> grid;
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    grid.push_back(s);
  }

  int from, to;
  for (int h = 0; h < H; ++h) {
    from = to = -1;
    for (int w = 0; w < W; ++w) {
      if (grid[h][w] == '#') {
        if (to == -1) continue;
        for (int i = from; i <= to; ++i) {
          dp[h][i] += to-from+1;
        }
        from = to = -1;
      }
      else {
        if (from == -1) from = w;
        to = w;
      }
    }
    if (to == -1) continue;
    for (int i = from; i <= to; ++i) {
      dp[h][i] += to-from+1;
    }
  }

  for (int w = 0; w < W; ++w) {
    from = to = -1;
    for (int h = 0; h < H; ++h) {
      if (grid[h][w] == '#') {
        if (to == -1) continue;
        for (int i = from; i <= to; ++i) {
          dp[i][w] += to-from+1;
        }
        from = to = -1;
      }
      else {
        if (from == -1) from = h;
        to = h;
      }
    }
    if (to == -1) continue;
    for (int i = from; i <= to; ++i) {
      dp[i][w] += to-from+1;
    }
  }
  int ans = 0;
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      chmax(ans, dp[h][w]);
    }
  }
  cout << ans-1 << endl;
}


Measured memory_bytes: 19968
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A = sorted(A)

ll = []
for i in range(M):
    B, C = (int(i) for i in input().split())
    ll.append((C,B))

slst = sorted(ll,reverse=True)

#print(A)
#print(slst)

res = []
for ss in slst:
    res.extend([ss[0]] * ss[1])
    if len(res) >= N:
        break

#print(res)

bb = []
for i in range(N):
    if i < len(res):
        if A[i] < res[i]:
            bb.append(res[i])
        else:
            bb.append(A[i])
    else:
        bb.append(A[i])


#print(bb)
print(sum(bb))



Measured memory_bytes: 80920
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define FINF DBL_MAX/3
#define EPS 1e-7
#define OUT1(n1) cout<<n1<<endl
#define OUT2(n1,n2) cout<<n1<<" "<<n2<<endl
#define OUT3(n1,n2,n3) cout<<n1<<" "<<n2<<" "<<n3<<endl
#define OUT4(n1,n2,n3,n4) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<endl
#define OUT5(n1,n2,n3,n4,n5) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<endl
#define OUT6(n1,n2,n3,n4,n5,n6) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<endl
#define OUT(n, ...) OUT##n(__VA_ARGS__)

/*
 *
 */

int main(){
  ll n;
  ll a[100001];
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }

  // sort
  sort(a, a+n);

  // 累積
  ll s[100001]; // s[i] = a[0]+...+a[i]
  s[0]=a[0];
  rep(i,n-1) s[i+1]=s[i]+a[i+1];


  // 判定
  bool ok[100001];
  repl(i,1,n){
    ok[i] = (a[i] <= 2*s[i-1]) ? true : false;
  }
  ll j=n-1;
  while(j>=0){
    if(ok[j]) j--;
    else break;
  }
  cout<<n-j<<endl;
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    if(s == "Sunny") { cout << "Cloudy" << endl; }
    else if(s == "Cloudy") { cout << "Rainy" << endl; }
    else if(s == "Rainy") { cout << "Sunny" << endl; }

    return 0;
}


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

using namespace std;



int main(){

        double a;
        scanf("%lf", &a);
        double b = a/3.0;
        double c = a-b-b;
        // cout<<b<<" "<<c<<" ";
        double ans = b*b*b;
        // cout<<b*b*b<< " ";
        printf("%.7f",ans);

        return 0;

}


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

int N, M, dp[100009];
vector<int> G[100009];

int solve(int u) {
    if(dp[u] == -1) {
        dp[u] = 0;
        for(int v : G[u])
            dp[u] = max(dp[u], solve(v) + 1);
    }
    return dp[u];
}

int main() {
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
    }

    for(int i = 1; i <= N; i++)
        dp[i] = -1;

    int res = -1;
    for(int i = 1; i <= N; i++)
        res = max(res, solve(i));

    cout << res << endl;
}

Measured memory_bytes: 7424