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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, D, A;
    cin >> N >> D >> A;

    vector<Pll> XH(N);
    for (int i = 0; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        XH[i] = make_pair(a, b);
    }

    sort(XH.begin(), XH.end());

    Vl xs(N);
    Vl hs(N);
    for (int i = 0; i < N; i++) {
        xs[i] = XH[i].first;
        hs[i] = XH[i].second;
    }

    ll ans = 0;
    Vl dredus(N);
    ll redu = 0;
    for (int cur = 0; cur < N; cur++) {
        redu += dredus[cur];
        if (hs[cur] - redu <= 0) continue;
        int right = upper_bound(xs.begin(), xs.end(), xs[cur] + 2 * D) - xs.begin();
        ll cnt = (hs[cur] - redu + A - 1) / A;
        ll r = cnt * A;
        ans += cnt;
        redu += r;
        if (right < N) dredus[right] -= r;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8064
include Math

n = gets.to_i

Point = Struct.new(:x, :y)

def koch(n, a, b)
  return if n == 0
  th = PI * 60 /180
  
  s = Point.new
  t = Point.new
  u = Point.new
  
  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0
  u.x = s.x + (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th)
  u.y = s.y + (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th)
  
  koch(n-1, a, s)
  puts "#{s.x} #{s.y}"
  koch(n-1, s, u)
  puts "#{u.x} #{u.y}"
  koch(n-1, u, t)
  puts "#{t.x} #{t.y}"
  koch(n-1, t, b)
end

a = Point.new(0, 0)
b = Point.new(100, 0)

puts "#{a.x} #{a.y}"
koch(n, a, b)
puts "#{b.x} #{b.y}"


Measured memory_bytes: 6940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

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

const int MAX = 128;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

vector <P> v;
int ans [MAX][MAX];

void solve(void){
    int H, W, N;
    cin >> H >> W >> N;
    rep(N, i) {
        int A; cin >> A;
        v.pb(P(A, i+1));
    }
    int h = 0, w = 0;
    for (P a : v) {
        int cnt = a.first;
        while (cnt) {
            if (h < H) {
                ans[h][w] = a.second;
                h++;
                cnt--;
            }
            if (h == H) {
                h = 0;
                w++;
            }
        }
    }
    rep(H, i) {
        rep(W, j) {
            if (j%2) printf("%d ", ans[H-i-1][j]);
            else printf("%d ", ans[i][j]);
        }
        putchar('\n');
    }
}

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


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

int main() {
	int t,k,X,Y,j;
	cin>>X>>Y;
  	k=X;
  	j=0;
  	for(int i=0;i<X+1;i++){
     	 if(4*k-2*i==Y){
          j=1; 
         }
    }
  	if(j==0){
     	cout<<"No"<<endl; 
    }
  	else{
     	cout<<"Yes"<<endl; 
    }
}


Measured memory_bytes: 3664
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ok = True

d_max = max(a)
if n > 2 and d_max == 1:
	ok = False
if c[d_max] == 1:
	ok = False
else:
	if d_max % 2 == 0:
		d_min = d_max // 2
		if min(a) < d_min:
			ok = False
		if c[d_min] != 1:
			ok = False
		for d in range(d_min + 1, d_max):
			if c[d] < 2:
				ok = False

	else:
		d_min = (d_max + 1) // 2
		if min(a) < d_min:
			ok = False
		if c[d_min] != 2:
			ok = False
		for d in range(d_min + 1, d_max):
			if c[d] < 2:
				ok = False

if ok:
	print("Possible")
else:
	print("Impossible")

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

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

    int sum = 0;
    for (int i = 0; i < n; ++i){
        if (v[i] - c[i]>=0){
            sum += v[i] - c[i];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, M; cin >> N >> M;
  vector<pair<ll,ll>> p(N);
  rep(i,N) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  ll ans = 0;
  rep(i,N) {
    if (p[i].second >= M) {
      ans += p[i].first * M;
      break;
    }
    else {
      ans += p[i].first * p[i].second;
      M -= p[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4376
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
//#define int long long
#define pipii pair<int, pair<int, int> >

int32_t main(){
    int k;
    string s;
    cin >>s >>k;
    for(int i = 0; i < SZ(s) && k > 0; i ++){
        if(s[i] > 'a' && ('z' - s[i]) + 1 <= k){
            k -= ('z' - s[i]) + 1;
            s[i] = 'a';
        }
    }
    int n = SZ(s) - 1;
    s[n] = 'a' + (((s[n] - 'a') + (k% 26))% 26);
    cout <<s <<endl;
    return false;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){

	int n,tmp,c=0;
	bool flag=true;
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	while(flag){
		flag=false;
		for(int j=n-1;j>0;j--){
			if(A[j]<A[j-1]){
				tmp=A[j];
				A[j]=A[j-1];
				A[j-1]=tmp;
				flag=true;			
				c++;
				}
		}
	}
	for(int i=0;i<n-1;i++){
		cout<<A[i]<<" ";
	}
	cout<<A[n-1]<<endl<<c<<endl;

	return 0;
}

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

int main()
{
    int a,b;
    cin>>a>>b;
    int c=0,d=0,e=0;
    c=a+b;
    d=a-b;
    e=a*b;
    cout<<max(c,max(d,e))<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
int main()
{
    ll h,ans=0,curr=1;
    cin>>h;
    while(h>1)
    {
        h=h/2;
        ans+=curr;
        curr*=2;
    }
    cout<<ans+curr;
}

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

int main()
{
	int a, b;
	

	cin >> a >> b;
	if (a+a-1>=b+b-1&&a+a-1>=a+b) cout << a+a-1;
	else  if (b+b-1>=a+a-1&&b+b-1>=a+b) cout << b+b-1;
	else  cout << a+b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

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

ll a[100001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	ll ans = 0;
	for(int i = 0; i < n - 1; i++)
	{
		if(a[i] > 0 && a[i + 1] > 0)
		{
			if(a[i]%2==1 && a[i+1]%2==1)
			{
				a[i]--; a[i+1]--; ans++;
			}
			else if(a[i]%2==1)
			{
				a[i]--; a[i+1]--; ans++;
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		ans += a[i]/2;
	}
	cout << ans;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include<bits/stdc++.h>
typedef long long int ll;
const int maxn=1e6+7;
using namespace std;
//四步走，
//确定状态 1、最后一步2、化成子问题
//转移方程
//初始条件和边界情况
//计算顺序，确保要用到的都算过
int main()
{
   ll n;
   cin>>n;
   ll aa[105];
   int i,j,k;
   for(int i=0;i<n;i++)
    cin>>aa[i];
    ll sum=0;
   for(i=0;i<n;i++)
   {
       for(j=i+1;j<n-1;j++)
       {
           if(i==j)continue;
           if(aa[i]==aa[j])continue;
           for(k=j+1;k<n;k++)
           {
               if(k==i||k==j)continue;
                if(aa[k]==aa[i])continue;
               if(aa[k]==aa[j])continue;
               if(aa[i]+aa[j]>aa[k]&&aa[i]+aa[k]>aa[j]&&aa[j]+aa[k]>aa[i])
                {sum++;}
           }
       }
   }
   printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

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

void solve(){

}

int main(void){
  string in;//ツ探ツつキツ個ウツづ個閉カツ篠堋療ア
  string target;//ツ探ツつキツタツーツゲツッツト
  int n; //ツ閉カツ篠堋療アツづ個青?
  cin>>in;
  cin>>n;

  int cnt=0;//ツ個ゥツづつつッツつスツ青?
  for(int i=0;i<n;i++){
    cin>>target;
    target+=target;
    if(target.find(in)!=string::npos){
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, 0, n) cin >> h[i];

  sort(h.begin(), h.end());

  ll ans = 1e18;
  rep(i, k - 1, n) 
    chmin(ans, h[i] - h[i - k + 1]);
  cout << ans << endl;
}


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

// 入力
string f[10];
int n, w[10], s[10]; 
// used[i] := i番目を選んだかどうか
bool used[10];
// 今まで見つかった中で一番重心が低いもの
double ans_g;
// 解
vector<int> ans;

// 重さに耐えられるかチェック
bool check(vector<int>& v){
	for(int i=0 ; i < v.size() ; i++ ){
		int weight = 0;
		for(int j=i+1 ; j < v.size() ; j++ ){
			weight += w[v[j]];
		}
		if( s[v[i]] < weight )
			return false;
	}
	return true;
}

// 重心を計算
double gravity(vector<int>& v){
	double a = 0, b = 0;
	for(int i=0 ; i < v.size() ; i++ ){
		a += (i+1) * w[v[i]];
		b += w[v[i]];
	}
	return a / b;
}

// 順列生成して解を探す (最大で 10! 通り)
void solve(){
	vector<int> v(n);
	for(int i=0 ; i < n ; i++ ) v[i] = i;
	// 順列生成してチェック
	do{
		double g = gravity(v);
		// 重心が低い かつ 重さに耐えられるとき
		if( check(v) && g < ans_g ){
			ans_g = g;
			ans = v;
		}
	}while( next_permutation(v.begin(),v.end()) );
}

// 探索
void dfs(vector<int>& v, int num){
	// 重さに耐えられるかチェック, 耐えられないときは探索打ち切り
	if( !check(v) ) return;
	
	if( num == n ){
		double g = gravity(v);
		if( g < ans_g ){ // 重心が低いとき
			ans_g = g;
			ans = v;
		}
		return;
	}
	
	for(int i=0 ; i < n ; i++ ){
		if( used[i] ) continue;
		
		used[i] = true;
		v.push_back( i );
		dfs( v , num+1 );
		v.pop_back();
		used[i] = false;
	}
}

int main(){
	while( cin >> n , n ){
		// 初期化
		for(int i=0 ; i < 10 ; i++ ) used[i] = false;
		
		for(int i=0 ; i < n ; i++ ){
			cin >> f[i] >> w[i] >> s[i];
		}
		
		ans_g = 1e+9;
		vector<int> v;
		dfs( v , 0 );
		//solve();
		
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << f[ans[i]] << endl;
		}
	}
}

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

int main() {
	int n, m, s;
	cin >> n >> m >> s;
	vector<vector<pair<int, int>>> cm(n * 2501);
	rep(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u = (u - 1) * 2501; v = (v - 1) * 2501;
		rep(i, 2501) if (i >= a) {
			cm[u + i].emplace_back(v + i - a, b);
			cm[v + i].emplace_back(u + i - a, b);
		}
	}
	rep(i, n) {
		int c, d, vi = i * 2501;
		cin >> c >> d;
		rep(j, 2500) cm[vi + j].emplace_back(vi + min(j + c, 2500), d);
	}
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
	vector<bool> visited(n * 2501);
	vector<ll> ans(n * 2501);
	q.emplace(0, min(s, 2500));
	while(!q.empty()) {
		auto p = q.top();
		q.pop();
		ll time = p.first;
		int dest = p.second;
		if (visited[dest]) continue;
		visited[dest] = true;
		ans[dest] = time;
		for(auto x: cm[dest]) {
			int nxt = x.first, len = x.second;
			q.emplace(time + len, nxt);
		}
	}
	for(int i = 1; i < n; i++) {
		ll res = LLONG_MAX;
		rep(j, 2501) {
			int vi = i * 2501 + j;
			if (visited[vi]) res = min(res, ans[vi]);
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 19728
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

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

    int K, S;
    cin >> K >> S;
    long long ans = 0;
    for(int X=0; X<=K; X++){
        for(int Y=0; Y<=K; Y++){
            int Z = S - X - Y;
            if(0 <=Z && Z <=K)
                ans++;
        }
    }
    cout << ans << endl;


    return 0;
}


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

ll max(ll a, ll b){
    return  (a > b)? a : b;
}

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

    ll n,m;
    cin >> n >> m;
    
    ll ans = max(0, (ll) (n-2) * (m-2));
    
    if(n == 1){
        ans += max(0, m - 2);
    }else if(m == 1){
        ans += max(0, n - 2);
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

void solve(){
    ll n,m;cin>>n>>m;
    vll h(n);
    vvll g(n);
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    for(ll i=0;i<m;i++){
        ll x,y;cin>>x>>y;
        x--;y--;
        g[x].pb(y);g[y].pb(x);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        bool f=0;
        for(auto pp:g[i]){
            if(h[pp]>=h[i]){
                f=1;
                break;
            }
        }
        if(!f) ans++;
    }
    cout<<ans<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 9844
n, m = map(int,input().split())
sum = 0
list = []
for i in input().split():
    sum += int(i)
    list.append(int(i))
judge = 1 / (4 * m)
count = 0
for i in list:
    if i >= sum * judge:
        count += 1
    if count == m:
        print('Yes')
        break
if count < m:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;
 
typedef long long ll;
typedef double db;
typedef long double ldb;
 
template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}
 
const int inf=1e9+10;
const int maxn=5e5+10;
 
int bit[maxn],n,pos[maxn],q,a[maxn];
vector <pair<int,int> > v[maxn];
map <int,int> Map;
int ans[maxn];
 
void add(int i,int val){
	while(i<=n){
		bit[i]+=val;
		i+=i&-i;
	}
}
 
int sum(int i){
	int ans=0;
	while(i){
		ans+=bit[i];
		i-=i&-i;
	}
	return ans;
}
 
int main(){
	cin>>n>>q;
	for(int i=0;i<n;i++) cin>>a[i],Map[a[i]]=1;
	int k=0;
	for(map<int,int>::iterator it=Map.begin();it!=Map.end();it++){
		it->second=k++;
	}
	for(int i=0;i<n;i++) a[i]=Map[a[i]];
	for(int i=0;i<q;i++){
		int l,r;
		cin>>l>>r;
		l--; r--;
		v[r].pb(mp(l,i));
	}
	for(int i=0;i<maxn;i++) pos[i]=-1;
	int now=0;
	for(int i=0;i<n;i++){
		if(pos[a[i]]==-1) now++;
		else{
			add(pos[a[i]]+1,-1);
		}
		pos[a[i]]=i;
		add(i+1,1);
		for(int j=0;j<v[i].size();j++){
			int l=v[i][j].fst,id=v[i][j].snd;
			ans[id]=now-sum(l);
		//	cout<<sum(l)<<endl;
		}
	//	cout<<now<<" ";
	}
//	cout<<endl;
	for(int i=0;i<q;i++) cout<<ans[i]<<endl;
	cout<<endl;
	return 0;
}

Measured memory_bytes: 56660
#include <iostream>
#include <cstdlib>
#include <stack>
using namespace std;


int main(){
	stack<int> S;
	int a,b;
	string s;
	while(cin>>s){
		if(s[0]=='+'){
			a=S.top();S.pop();
			b=S.top();S.pop();
			S.push(a+b); 
		}else if(s[0]=='-'){
			b=S.top();S.pop();
			a=S.top();S.pop();
			S.push(a-b); 
		}else if(s[0]=='*'){
			a=S.top();S.pop();
			b=S.top();S.pop();
			S.push(a*b); 
		}else{
			S.push(atoi(s.c_str()));
		}
	}
	cout<<S.top()<<endl;
	return 0;
}


Measured memory_bytes: 3204
def solve():
  N,Y = map(int,input().split())
  total = 0
  x = -1
  y = -1
  z = -1
  for i in range(N+1):
    for j in range(N+1-i):
      k = N - i - j
      total = 10000*i + 5000*j + 1000*k
      if total == Y and k >= 0:
        x = i
        y = j
        z = k
  print(str(x) + " " + str(y) + " " + str(z) + " ")
solve()
        

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
   
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    
    
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        var n = Read();
        var x = Reads();
        long ans =(long)Math.Pow(10,9);
        for(int i = 1; i <= 100; i++)
        {
            long h = 0;
            for(int j = 0; j < n; j++)
            {
                h += (x[j] - i) * (x[j] - i);
            }
            ans = Math.Min(ans, h);

        }
        Console.WriteLine(ans);
        
       
        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),count=0;
    int[] a=new int[n];
    for(int i=0;i<n;i++) {
    	a[i]=sc.nextInt();
    }
    for(int i=0;i<n;i++) {
    	if(a[a[i]-1]==i+1) {
    		count++;
    		a[i]=-1;
    	}
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 50448
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

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

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

#define all(x) x.begin(), x.end()
#define all_r(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, n) for(int i = n; i >= 0; --i)
#define f first
#define s second

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	const int MAXN = 3163;
	bitset<MAXN> S;
	vi F(n + 1, 1), X(n + 1, 1), Z(n + 1);
	S.set();
	for(int k = 4; k < MAXN; k += 2) S[k] = 0;
	for(int k = 3; k < MAXN; k += 2)
		if(S[k]) for(int i = 2 * k; i < MAXN; i += k) S[i] = 0;
	for(int k = 2; k * k <= n; ++k) {
		if(S[k]) {
			Z[k] = X[k] = 1;
			for(int i = k, j = 1, z = 1; i <= n; ++j, ++z, i += k) {
				if(j == k) {
					int y = Z[z] + 1;
					F[i] *= y + 1;
					Z[i] = y;
					X[i] = X[z] * k; 
					j = 0;
				}
				else {
					F[i] <<= 1;
					Z[i] = 1;
					X[i] *= k;
				}
			}
		}
	}
	ll ans = 0;
	for(int k = 1; k <= n; ++k) {
		if(X[k] != k)
			ans += 2LL * F[k] * k;
		else
			ans += 1LL * F[k] * k;
	}
	cout << ans << '\n';
 	return 0;
}

Measured memory_bytes: 120384
def main():
  n,m=map(int,input().split())
  a=[0 for i in range(m)]
  b=[0 for i in range(m)]
  c=[[] for i in range(m)]
  for i in range(m):
    a[i],b[i]=map(int,input().split())
    c[i]=list(map(int,input().split()))
  
  dp=[float("inf") for i in range(2**n)]
  dp[0]=0
  for i in range(m):
    now=0
    for j in c[i]:
      jj=1<<j-1
      now|=jj
    for k in range(2**n):
      kk=k|now
      dp[kk]=min(dp[kk],dp[k]+a[i])
    
 
  if dp[-1]==float("inf"):
    print(-1)
  else:
    print(dp[-1])
    
if __name__ == '__main__':  
  main()

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
ll n,m,x;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m>>x;
  std::vector<ll> v(n);
  ll cnt = 0,cnt2=0;
  rep(i,m) cin>>v[i];
  rep(i,m) if(x < v[i]) cnt++;
  rep(i,m) if(x > v[i]) cnt2++;
  cout<<MIN(cnt2,cnt)<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, k, s;
	cin >> n >> k >> s;
	vector<int> v(n);
	rep(i, k) {
		v[i] = s;
	}
	int cur = s - 1;
	if (cur == 0) cur = INF;
	for (int i = k; i < n; i++) v[i] = cur;
	rep(i,n) {
		if (i != 0) cout << " ";
		cout << v[i];
	}
}

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

Measured memory_bytes: 3788
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;


int vs[510][510];

struct Op {
  int i1, j1, i2, j2;
};

int main(void) {
  int nRow, nCol;
  scanf("%d%d", &nRow, &nCol);
  REP(i, nRow) REP(j, nCol) {
    scanf("%d", &vs[i][j]);
  }

  vector<Op> ans;

  REP(i, nRow) {
    REP(j, nCol) {
      if(vs[i][j] % 2 == 1) {
        if(j+1 < nCol) {
          ans.push_back((Op){i+1, j+1, i+1, j+2});
          vs[i][j+1]++;
        } else if(i+1 < nRow) {
          ans.push_back((Op){i+1, j+1, i+2, j+1});
          vs[i+1][j]++;
        }
      }
    }
  }

  printf("%d\n", (int)ans.size());
  REP(i, ans.size()) {
    printf("%d %d %d %d\n", ans[i].i1, ans[i].j1, ans[i].i2, ans[i].j2);
  }
  return 0;
}



Measured memory_bytes: 5232
def solve():
    from collections import deque
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    
    brd = '#' * (W + 2)
    for i in range(H):
        brd += '#' + f_i.readline().rstrip() + '#'
    brd += '#' * (W + 2)
    
    INF = W * H
    move = (1, -1, W + 2, -W - 2)
    start = W + 3
    goal = (W + 2) * (H + 1) - 2
    distance = [INF] * ((W + 2) * (H + 2))
    distance[start] = 0
    q = deque()
    q.append(start)
    
    while q:
        pos = q.popleft()
        
        if pos == goal:
            black_cell = brd.count('#') - W * 2 - H * 2 - 4
            ans = H * W - black_cell - distance[pos] - 1
            print(ans)
            break
        
        for mv in move:
            next_pos = pos + mv
            if brd[next_pos] == '.' and distance[next_pos] == INF:
                q.append(next_pos)
                distance[next_pos] = distance[pos] + 1
    else:
        print(-1)

solve()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, s;
	cin>>n>>k>>s;
	if(s == 1){
		for(int i = 1; i <= k; i++){
			cout<<1<<" ";
		}
		for(int i = k + 1; i <= n; i++){
			cout<<2<<" ";
		}
		cout<<endl;
		return 0;
	}
	if(k < n){
		int num = 1;
		for(int i = 1; i <= k + 1; i++){
			cout<<num<<" ";
			num = s - num;
		}
		for(int i = k + 2; i <= n; i++){
			if(s == 1000000000){
				cout<<2<<" ";
			}
			else{
				cout<<1000000000<<" ";
			}
		}
	}
	else{
		for(int i = 1; i <= n; i++){
			cout<<s<<" ";
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cassert>
#include <list>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <limits>
using namespace std;
typedef long long          ll;
typedef unsigned long long ull;
typedef long double        ld;
typedef pair<int,int>      pii;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;
typedef vector<long long>  vll;
#define left(x)		   (x << 1)
#define right(x) 	   (x << 1) + 1
#define mid(l, r) 	   ((l + r) >> 1)
#define mp                 make_pair
#define pb                 push_back
#define all(a)             a.begin(),a.end()
#define debug(x)	   {cerr <<#x<<" = " <<x<<"\n"; }
#define debug2(x, y)       {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";}
#define debug3(x, y, z)    {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
#define debug4(x, y, z, w) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#w << " = " <<w <<"\n";}
#define ss                 second
#define ff                 first
#define m0(x) 		   memset(x,0,sizeof(x))

template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T >T max_ ( T a , T b ) { return a > b ? a : b ; }
template < typename T ,  typename... Ts > T max_( T first , Ts... last ){ return  max_(first, min_(last...)); }

template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<typename T> ostream& operator<< (ostream& out, const vector<T>& v) {
    out << "["; size_t last = v.size() - 1; for(size_t i = 0; i < v.size(); ++i) {
    out << v[i]; if (i != last) out << ", "; } out << "]"; return out;
}

ll pwr(ll base, ll p, ll mod){
ll ans = 1; while(p) { if(p&1) ans=(ans*base)%mod; base=(base*base)%mod; p/=2; } return ans;
}
ll gcd(ll a, ll b) {  return b == 0 ? a : gcd(b,a%b); }
ll lcm(ll a, ll b) {  return a*(b/gcd(a,b)); }

const long double PI = (long double)(3.1415926535897932384626433832795);
const ll  mx_ll   = numeric_limits<ll> :: max();
const int mx_int  = numeric_limits<int> :: max();
const int mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef __APPLE__
    freopen("test.in", "rb", stdin);
    //freopen("  .out", "wb", stdout);
#endif

    int n; cin >> n;
    string s; cin >> s;
    int k; cin >> k;

    char ch = s[k-1];

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == ch)
        {
            cout << ch;
        }
        else
        {
            cout << "*";
        }   
    }
    return 0;
}



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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	for(int i = 0; i < s.size(); ++i) {
		if( s[i] - '0' == 1 ) cout << 9;
		if( s[i] - '0' == 9 ) cout << 1;
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
        var n, x int
        fmt.Scan(&x, &n)
        if n == 0 {
                fmt.Println(x)
                return
        }
        s := make([]int, n)
        for i := 0; i < n; i++ {
                fmt.Scan(&s[i])
        }
        var i = 0
        for {
                if !contains(s, x-i) {
                        fmt.Printf("%v", x-i)
                        return
                }
                if !contains(s, x+i) {
                        fmt.Printf("%v", x+i)
                        return
                }
          i++
        }
        return
}

func contains(s []int, i int) bool {
        for _, item := range s {
                if item == i {
                        return true
                }
        }
        return false
}


Measured memory_bytes: 1824
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>

using namespace std;

typedef long long ll;


#define  kak 1000000000000;



int main(){
    ll N;
    ll M;
    ll B;
    ll C;





    cin >> N;
    cin >> M;
    vector<ll> A(N,1);
    vector<pair<ll,ll>> BC(M);

    ll bt  = 0;
    ll ct = 0;

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    for (int j = 0; j < M ; ++j) {
        cin >> bt;
        cin >> ct;
        BC[j].first = ct;
        BC[j].second = bt;
    }
    sort(A.begin(),A.end());

    sort(BC.begin(),BC.end());



    ll temp = 0;
    ll i;
    for (int k = M-1; k >=0; --k) {
        //cout<< BC[k].second << " "<<BC[k].first<<endl;
        for (i = temp; i < temp + BC[k].second ; i++) {
            //cout<<" "<<i<<" "<< A[i]<< " "<<BC[k].first<<endl;
            if(BC[k].first > A[i]) A[i] = BC[k].first;
            else break;
        }
        temp = i;
    }

    ll sum = 0;
    for (int l = 0; l <N ; ++l) {
        sum += A[l];
    }

    cout << sum << endl;






    return 0;
}




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

int main() {
  long long int A, B, C, ans = 0;
  cin >> A >> B >> C;

  if(A==B&&B==C&&A%2==0) {
    cout << -1 << endl;
    return 0;
  }
  
  while (A%2==0&&B%2==0&&C%2==0) {
    int a = A;
    int b = B;
    int c = C;
    A = (b + c)/2;
    B = (a + c)/2;
    C = (a + b)/2;
    ans++;
  }

  cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD =1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll t[5] = {};
	repn(i, 6) {
		ll a;
		cin >> a;
		t[a]++;
	}

	if (t[1] * t[2] * t[3] * t[4] == 3) { cout << "NO"; }
	else { cout << "YES"; }

	system("PAUSE");
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=998244353;
const long long maxn=2e5+5;
const long long inf=99999999999;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); }

ll power(ll x, ll y){  
	ll p=mode, res=1;
    x = x % p;
    while (y > 0) {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}


void solve(){
	
	ll n,s;
	cin>>n>>s;
	vector<ll> v(n+1);
	for (int i=1;i<=n;i++) cin>>v[i];
	vector<vector<ll>> dp(n+1, vector<ll> (s+1, 0));
	dp[0][0]=1;
	
	for (int i=1;i<=n;i++){
		for (int j=0;j<=s;j++){
			dp[i][j]=(2*dp[i-1][j])%mode;
			if (j>=v[i]) dp[i][j]=(dp[i][j]+dp[i-1][j-v[i]])%mode;
		}
	}
	cout<<dp[n][s]<<endl;
	
	return;
}

 
int main(){ 
    
    #ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 	
	//T{ solve(); }
	solve();
	
	
	
	return 0;
	
}

Measured memory_bytes: 73680
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(2e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
map<int,int> cnt;
int a[N],b[N];
int ans[N];
void solve(){
    int n;
    cin >> n;
    for(int i= 1;i<=n;i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i =1;i<=n;i++){
        cin >> b[i];
        cnt[b[i]]++;
    }
    for(auto x:cnt){
        if(x.s > n){
            cout << "No\n";
            return;
        }
    }
    reverse(b+1,b+n+1);
    int l = 1,r = n;
    for(int i = 1;i<=n;i++){
        if(a[i] == b[i]){
            if(a[l] != b[i] && a[i] != b[l]){
                swap(b[l],b[i]);
                l++;
            }
            else{
                swap(b[r],b[i]);
                r--;
            }
        }
    }



    cout << "Yes\n";
    for(int i=1;i<=n;i++){
        cout << b[i] << " ";
    }
    cout << endl;

}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 19276
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> ans(n + 1, 0);
    FOR(i, 1, n + 1)
    {
        FOR(j, i + 1, n + 1)
        {
            int mn = min({abs(i - j), abs(i - x) + abs(j - y) + 1,
                          abs(i - y) + abs(j - x) + 1});
            ++ans[mn];
        }
    }
    FOR(i, 1, n) { cout << ans[i] << "\n"; }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+5,mo=1e9+7;
LL a[N],sia,sib;
int main(){
	int n,k,x;scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld",a+i),sia+=a[i]>=0;
	LL ans=1;
	sort(a,a+n,greater<int>());
	if(!sia && k&1){
		for(int i=0;i<k;i++)(ans*=a[i])%=mo;
		return printf("%lld",ans+mo),0;
	}
	int l=0,r=n-1;
	if(k&1)ans*=a[l++];
	for(int i=k/2;i;i--){
		if(a[l]*a[l+1]>=a[r]*a[r-1])ans=ans*a[l]%mo*a[l+1]%mo,l+=2;
		else ans=ans*a[r]%mo*a[r-1]%mo,r-=2;
	}
	printf("%lld",(ans+mo)%mo);
	return 0;
}

Measured memory_bytes: 5300
#include <cstdio>
#include <algorithm>
#define LL long long
#define num (LL)1000000000000000000
using namespace std;
LL a[100010];
 
int main(){
	int n,i;
	LL ans=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	if(a[1]==0){printf("0\n");return 0;}
	for(i=1;i<=n;i++)
		if(a[i]>num/ans){printf("-1\n");return 0;}
		else ans*=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2504
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef vector<int> vi;
typedef vector<double> di;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vi A(N);
  int sum = 0;
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  float share = (float)sum/(4*M);
  if(A.at(M-1) < share){
      cout << "No" << endl;
  }
  else{
      cout << "Yes" << endl;
  }
}

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

using namespace std;

string s;
int n,m,minn=0x3f3f3f3f,ans,sum;

int main(){
	scanf("%d%d",&n,&m);int x;
	for(int i=1;i<=n;i++) scanf("%d",&x),minn=min(x,minn),sum+=x;
	m-=sum;
	ans=n+m/minn;
	printf("%d",ans);
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool c(int x,int y){
    return y<x;
}
int main() {
    int n;cin>>n;
    vector<int > p;
    for (int i = 0; i < n; ++i){
        int a;cin>>a;
        p.push_back(a);
    }
    int q;cin>>q;
    while(q--){
        vector<int > v(p);
        int com,b,e;
        cin>>com>>b>>e;
        if(com==0){
            sort(&v[b],&v[e]);
            cout<<v[b]<<endl;
        }
        else if(com==1){
            sort(&v[b],&v[e],c);
            cout<<v[b]<<endl;

        }
    }
    return 0;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,c1=0;
    cin>>n;
    string s;
    cin>>s;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='.')
            c1++;
    }
    ll black=0;
    ll cnt=c1;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='#')
            black++;
        else
            c1--;
        cnt = min(cnt,c1+black);
    }
    cout<<cnt<<'\n';
    return 0;
}


Measured memory_bytes: 640
a = []
for i in range(3):
    a.append([int(i) for i in input().split()])
N = int(input())
for i in range(N):
    b = int(input())
    for j in range(3):
        if b in a[j]:
            num = a[j].index(b)
            a[j][num] = 0
f = a
flag = False
#横の確認
for i in f:
    if i[0] == 0 and i[1]==0 and i[2]==0:
        flag = True
#縦の確認
for i in range(3):
    if f[0][i] == 0 and f[1][i]==0 and f[2][i]==0: 
        flag = True
#斜めの確認
if f[0][0] == 0 and f[1][1]==0 and f[2][2]==0: 
    flag = True 
elif f[0][2] ==0 and f[1][1]==0 and f[2][0]==0:
    flag = True
print('Yes' if flag==True else 'No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main(){
   ll n;
   cin>>n;
   bool a[1010101]={};
   ll n2=(ll)sqrt(n),ans=0;
   for(ll i=2;i<=n2;i++){
      ll f=n;
      while(f%i==0)f/=i; 
      if(f%i==1){ans++;}
      //else{a[i]=1;}
   }
   ll z=n;
   for(ll i=2;(n)/i>n2;i++){
       if((n)%i==1)ans++;
   }
   if(n==2)cout<<1<<endl;
   else cout<<ans+2<<endl;
   
   

}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a;  //動的配列aを宣言
	vector<int> b;
	a.resize(n);    //aのサイズをｎに変更
	b.resize(n);
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
		b[i] = 0;
	}

	int count = 0,num=0;

	for (int i = 0;i < n;i++)
	{
		count++;
		if (a[num] == 2)
		{
			cout << count << endl;
			break;
		}
		else if (b[num] == 0)
		{
			b[num] = 1;
			num = a[num]-1;
		}
		else
		{
			cout << "-1" << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{int N,K,S,X,Y,Z,k,l,i,m,tmp;
	scanf("%d%d",&K,&S);
	tmp=0;
for(X=0;X<=K;X++){
	if((S-X>=0)&&(S-X<=2*K+1)){
	if(S-X<=K){
	tmp+=S-X+1;}
	else
	tmp+=2*K+X-S+1;}}
	printf("%d",tmp);



	return 0;
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c)cout<<1<<endl;
  if(a==b && b!=c)cout<<2<<endl;
  if(b==c && a!=b)cout<<2<<endl;
  if(c==a && b!=c)cout<<2<<endl;
  if(c!=a && b!=a && b!=c)cout<<3<<endl;
}

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

int n;
vector<int> p;
vector<int> j;

int main(){
	while(scanf("%d",&n),n != 0){
		p = vector<int>(n);
		j = vector<int>(n-1);
		for(int i = 0; i < n; i++){
			scanf("%d",&p[i]);
		}
		for(int i = 0; i < n-1; i++){
			scanf("%d",&j[i]);
		}
		sort(j.begin(),j.end());
		unsigned int sum = accumulate(p.begin(),p.end(),0) + accumulate(j.begin(),j.end(),0);
		unsigned int ans = sum;
		for(int i = 0; i < n-1; i++){
			sum -= j[i];
			unsigned int tmp = sum * (i+2);
			ans = max(ans,tmp);
		}
		printf("%u\n",ans);
	}
	return 0;
}



Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll N;
    cin>>N;
    if(N<=999)cout<<"ABC";
    else cout<<"ABD";
    return 0;
}

Measured memory_bytes: 256
program walk_on_multiplication_table
    implicit none
    integer(8):: n
    integer(8)::a,b, i
    read*, n

    do i=1, nint(sqrt(dble(n)))
        if (mod(n,i) == 0) then
            a = i
            b = n/i
        end if
    end do

    print*, a+b-2

end program walk_on_multiplication_table

Measured memory_bytes: 768
import Data.Char
import Control.Monad

main :: IO ()
main = do
  s <- getLine
  putStrLn $ solve s

solve :: String -> String
solve s = showFormula digits cleared
  where
    digits = map digitToInt s
    candidates = replicateM 3 ["+", "-"]
    cleared = head $ filter (\c -> doOps c digits == 7) candidates
    showFormula [d] [] = show d ++ "=7"
    showFormula (d:ds) (c:cs) = show d ++ c ++ showFormula ds cs

doOps :: (Num a) => [String] -> [a] -> a
doOps _ [a] = a
doOps [] (a:as) = a
doOps (f:fs) (a:b:as) = doOps fs (op f a b:as)
  where
    op "+" a b = a + b
    op "-" a b = a - b


Measured memory_bytes: 380