akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline


N = int(input())
A = [int(input()) for _ in range(N)]

mod = 10**9+7

dp = [0]*(N+1)
last_ind = [-1]*(2*10**5+1)

for i, a in enumerate(A):
    ind = last_ind[a]
    if ind == -1 or ind == i-1:
        dp[i+1] = dp[i]
    else:
        dp[i+1] = (dp[i] + dp[ind+1] + 1) % mod
    last_ind[a] = i

print((dp[N]+1)%mod)


Measured memory_bytes: 20528
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

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

    static class CPyramid {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Vec3i> xyh = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                xyh.add(new Vec3i(in.nextInt(), in.nextInt(), in.nextInt()));
            }
            xyh.sort(Comparator.comparing(v -> -v.z));


            for (int i = 0; i <= 100; i++) {
                for (int j = 0; j <= 100; j++) {
                    int h = Math.abs(i - xyh.get(0).x) + Math.abs(j - xyh.get(0).y) + xyh.get(0).z;
                    boolean f = true;
                    for (int k = 1; k < n; k++) {
                        f = f && (Math.max(h - Math.abs(i - xyh.get(k).x)
                                - Math.abs(j - xyh.get(k).y), 0) == xyh.get(k).z);
                    }
                    if (f && h > 0) {
                        out.println(i + " " + j + " " + h);
                        return;
                    }
                }
            }
        }

    }

    static class Vec3i {
        public int x;
        public int y;
        public int z;

        public Vec3i(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public String toString() {
            return "Vec3i{" +
                    "x=" + x +
                    ", y=" + y +
                    ", z=" + z +
                    '}';
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Vec3i vec3i = (Vec3i) o;
            return x == vec3i.x &&
                    y == vec3i.y &&
                    z == vec3i.z;
        }

        public int hashCode() {
            return Objects.hash(x, y, z);
        }

    }
}



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

int main(){
	string s;
 	cin >> s;
  
  	int n = s.size();
  	char a, b;
  	int c;
  	a = s[0];
  	b = s[n-1];
  	c = (n - 2);
  
  	cout << a << c << b << endl;
}

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

#define ll long long int

	
	
int main(){
	
	int n;
	cin>>n;
	
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	
	int min = *min_element(arr,arr+n);
	int max = *max_element(arr,arr+n);
	
	int min_cost=  INT_MAX;
	int temp = 0;
	for(int i=min;i<=max;i++){
			temp =0;
			for(int j=0;j<n;j++){
				temp += (i - arr[j]) * (i - arr[j]);
				} 
			if(temp < min_cost)
				min_cost = temp;
	}
	
	cout<<min_cost<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;
 
ll H,W;
 
ll maxfun(ll a, ll b , ll c){
  ll  result;
  a>b? (result = a):(result =b);
  return (result >c)? (result):c;
}
ll minfun(ll a, ll b , ll c){
  ll result;
  a<b? (result = a):(result =b);
  return   (result <c)? (result):c;
}
 
ll solve(ll h, ll w){
  ll result;
  for(int i = h/3; i < h/2+1;i++){
    int j= w/2;
    ll s1 = i*w;
    ll s2 = j*(h-i);
    ll s3 = (h-i)*(w-j);
    result = min(result,(maxfun(s1,s2,s3)-minfun(s1,s2,s3)));
  }
  return result;
}
 
int main(){
  ll result=100000;
 
  
  cin >> H >> W;
 
  if((H%3)*(W%3)==0){
    cout << "0" << endl;
    return 0;
  }
 
  else result = H<W? H:W;
  cout << minfun(solve(H,W),solve(W,H),result) << endl;
  return 0;
 
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;
  char c = S.at(0);
  for (int i = 1; i < (int)S.length(); ++i) {
    if (c == S.at(i)) {
      cout << "Bad" << endl;
      return 0;
    }
    c = S.at(i);
  }

  cout << "Good" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    int cnt = 1;

    while(s != 4 && s != 1 && s != 2){
        if(s%2==0) s/=2;
        else s = 3*s+1;
        cnt++;
    }

    dunk(cnt+3);
}

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

#mylist = [map(int,input().split())]
mylist = list(map(int,input().split()))


mymax = 0
mycnt = 0
myval = mylist[0]

for i in range(1,N):
    if myval >= mylist[i]:
        mycnt += 1
        
    elif myval < mylist[i]:
        
        mycnt = 0
        
    myval = mylist[i]
    if mymax < mycnt:
            mymax = mycnt
    #print(mylist[i], mymax, mycnt)


print(mymax)

Measured memory_bytes: 14252
#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 s; cin >> s;
  vector<int> a(1000010);
  ++a[s];
  int i = 1;
  while (true) {
    ++i;
    if (s%2==0) s /= 2;
    else s = 3 * s + 1;
    ++a[s];
    if (a[s] >= 2) break;
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 6804
#include <cstdio>

#include <cmath>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <queue>

#include <vector>

#include <map>



using namespace std;



typedef long long LL;


LL n;
LL len,a[1000005];
LL sum;
LL l,r;
int pos=-1;
LL ans[1000005];

int main()

{
	cin>>n>>len;
	for (int i=1;i<=n;++i) cin>>a[i];
	for (int i=1;i<n;++i) if (a[i]+a[i+1]>=len) pos=i;
	if (pos==-1)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
	for (int i=1;i<=pos-1;++i) cout<<i<<endl;
	for (int i=n-1;i>=pos;--i) cout<<i<<endl;
	return 0;

}

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

const long long INF = 0x3f3f3f3f3f3f3f3f;

int main () {
	long long a[2], b[2]; cin >> a[0] >> a[1] >> b[0] >> b[1];
	long long ans = -INF;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			ans = max(ans, a[i] * b[j]);
		}
	}
	if (a[0] <= 0 && a[1] >= 0) ans = max(ans, 0ll);
	if (b[0] <= 0 && b[1] >= 0) ans = max(ans, 0ll);
	cout << ans << endl;
	return 0;
}


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

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

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	scanf("%lld",&n);
	if(n==2){
		printf("1\n");
		return 0;
	}
	ll ans=0;
	for(ll i=1;i*i<=n-1;i++){
		if(i==1){
			ans+=1;continue;
		}
		if(!((n-1)%i)&&i*i!=n-1)ans+=2;
		if(i*i==n-1)ans++;
	}
	ll tmp=n;ll ops;
	for(ll i=1;i*i<=n;i++){
		if(i==1){
			ans++;
			continue;
		}
		if(!(n%i)){
			tmp=n;
			while(!(tmp%i)){
				tmp/=i;
			}
			if(tmp%i==1)ans++;
			if(i*i==n)continue;
			tmp=n;
			ops=n/i;
			while(!(tmp%ops)){
				tmp/=ops;
			}
			if(tmp%ops==1)ans++;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()
 
int main() {
  int N;
  cin >> N;
  if(N >= 1000){
    cout << "ABD" << endl;
  }else cout << "ABC" << endl;
}

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

void Main() {
  int n, m;
  cin >> n >> m;
  int lb = 0, ub = n;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    lb = max(lb, l);
    ub = min(ub, r);
  }
  if (ub >= lb) cout << ub - lb + 1 << endl;
  else cout << 0 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=set(LIST())
    if len(s)==2:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
loop do
  l = gets.to_i
  break if l.zero?
  sum=0
  1.upto(12) do |i|
    m,n = gets.split.map(&:to_i)
    sum+=m-n
    if sum>=l
      puts i
      (12-i).times{gets}
      break
    end
    puts :NA if i==12
  end
end

Measured memory_bytes: 2796
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 1000000000
using ll=long long;
using Graph=vector<vector<ll>>;

int main(){
  int X;
  cin>>X;
  int ans=0;
  int angle=0;
  while(true){
    angle+=X;
    ans++;
    angle%=360;
    if(angle==0){
      break;
    }
  }
  cout<<ans<<endl;
}


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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

#define int long long

void solve()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (auto& e : a)
		cin >> e;

	sort(a.begin(), a.end(), greater<ll>());
	vector<ll> left(n, -1), right(n, -1);
	left[0] = 1;
	right[0] = 1;
	left[1] = 0;
	right[1] = 0;

	ll ans = a[0];
	set<tuple<ll, ll, bool>> open; // false - left, true - right
	open.insert({a[1], -1, false});
	open.insert({a[1], -1, true});

	if (a[0] == a[1])
	{
		open.insert({a[0], 0, false});
		open.insert({a[0], 0, true});
	}

	for (ll i = 2; i < n; ++i)
	{
		auto it = --open.end();
		auto [val, idx, dir] = *it;
		idx *= -1;
		open.erase(it);

		ll otherIdx = dir ? right[idx] : left[idx];
		if (a[otherIdx] == a[idx])
			open.erase(open.find({a[otherIdx], -otherIdx, !dir}));

		if (dir)
		{
			left[i] = idx;
			right[i] = otherIdx;
			right[idx] = i;
			left[otherIdx] = i;

			open.insert({a[i], -i, false});
			open.insert({a[i], -i, true});

			if (a[idx] == a[i])
				open.insert({a[idx], -idx, true});
			if (a[otherIdx] == a[i])
				open.insert({a[otherIdx], -otherIdx, false});
		}
		else
		{
			left[i] = otherIdx;
			right[i] = idx;
			left[idx] = i;
			right[otherIdx] = i;

			open.insert({a[i], -i, false});
			open.insert({a[i], -i, true});

			if (a[idx] == a[i])
				open.insert({a[idx], -idx, false});
			if (a[otherIdx] == a[i])
				open.insert({a[otherIdx], -otherIdx, true});
		}

		ans += val;
	}

	cout << ans << '\n';
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 32992
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll gya[1000010];
ll kai[1000010];
void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,k;cin>>n>>k;
    if(k>n-1)k=n-1;
    nckinit(2*n,mod);
    ll ans=0;
    rep(i,0,k+1){
        ans+=nck(n,i,mod)%mod*nck(n-1,i,mod)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
}





Measured memory_bytes: 10496
N=int(input())
a=[int(i) for i in input().split()]

f=True

for i in range(N):
    if a[i]%2==0:
        if (a[i]%3!=0) and (a[i]%5!=0):
            f=False

if f:
    print("APPROVED")
else:
    print("DENIED")

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

#define l_ength size

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

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

int main(void){
	int h,n,i,a;
	cin >> h >> n;
	for(i=0; i<n; ++i){
		cin >> a;
		h -= a;
	}
	cout << ((h>0)?"No":"Yes") << endl;
	return 0;
}


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

using namespace std;

int n, a;

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 2 == 0)
            if((a % 3 != 0)&&(a % 5 != 0)){
                cout << "DENIED";
                return 0;
            }
    }
    cout << "APPROVED";
    return 0;
}


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

int main() {
	
	int q;
	cin >> q;
	
	vector<long long> v;
	
	for(int i = 0; i < q; ++i){
		int order;
		cin >> order;
		if(order == 0){
			long long num;
			cin >> num;
			v.push_back(num);
		}else if(order == 1){
			int index;
			cin >> index;
			cout << v[index] << endl;
		}else{
			v.pop_back();
		}
	}
	
	return 0;
}


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

int n,m;
int fin = 1;
vector<int> v[10];

int dfs(int a,int bit){
  if(bit == fin){
    return 1;
  }

  int ans = 0;
  for(int i = 0;i < v[a].size();i++){
    if((bit & (1 << v[a][i])) == 0){
      ans += dfs(v[a][i],bit | (1 << v[a][i]));
    }
  }
  return ans;
}

int main(){
  cin >> n >> m;
  for(int i = 0;i < n;i++) fin*= 2;
  fin--;
  int a,b;
  for(int i = 0;i < m;i++){
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  cout << dfs(0,1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////
#define N 100005
int n;
vector<int>c[N];
int dp[N];

int dfs(int s){
    if(dp[s]!=-1)return dp[s];
    if(c[s].size()==0) return dp[s]=0;
    vector<int>v;
    for(int x:c[s]){
        v.pb(dfs(x));
    }
    sort(v.begin(),v.end());
    int m=v.size();
    int res=0;
    rep(i,0,m-1){
        res=max(res,v[i]+m-i);
    }
    return dp[s]=res;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    cin>>n;
    rep(i,1,n-1){
        int p;cin>>p;p--;
        c[p].pb(i);
    }
    fill(dp,dp+N,-1);
    cout<<dfs(0)<<endl;
    
    return 0;
}

Measured memory_bytes: 15488
import sys
readline = sys.stdin.readline

N, W = map(int, readline().split())
inf = float("inf")
dp = [inf]*(N*100+1)
dp[0] = 0
s = {0}

for i in range(N):
    v, w = map(int, readline().split())
    for _v in sorted(s, reverse=True):
        new_w = dp[_v] + w
        if new_w <= W:
            new_v = v + _v
            dp[new_v] = new_w if new_w < dp[new_v] else dp[new_v]
            s.add(new_v)

for i in range(N*100, -1, -1):
    if dp[i] < inf:
        print(i)
        break

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

int main() {
    int N, Y;
    cin >> N >> Y;

    for (int i=0; i <= Y/10000; i++) {
        int res1 = Y - 10000*i;
        for (int j=0; j <= res1/5000; j++) {
            int res2 = res1 - 5000*j;
            int k = res2/1000;
            if (i+j+k == N) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    ans = [None] * len(S)
    for i in range(len(S)):
        c = S[i]
        x = (ord(c) - ord("A") + N) % 26 + ord("A")
        ans[i] = chr(x)
    print("".join(ans))


if __name__ == "__main__":
    main()


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

#define MAX_V 100005

using namespace std;

struct Edge {
  int dst, cost;
  Edge() {}
  Edge(int b, int c) : dst(b), cost(c) {}
};

vector<Edge> tree[MAX_V];
int ans[MAX_V];

void dfs(int cur_v, int par_v, int cost) {
  if (par_v == -1) {
    ans[cur_v] = 0;
  } else {
    ans[cur_v] = (ans[par_v]+cost)%2;
  }
  for (int i = 0; i < tree[cur_v].size(); i++) {
    Edge e = tree[cur_v][i];
    if ( e.dst == par_v ) { continue; }
    dfs(e.dst, cur_v, e.cost);
  }
}

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

  for (int i = 0; i < n-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    tree[u].push_back( Edge(v, w) );
    tree[v].push_back( Edge(u, w) );
  }
  
  dfs(0, -1, 0);

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 8320
@s=gets.chomp

def f(t, i)
  if i>=@s.size
    t+'=7' if eval(t)==7
  else
    res=[f(t+'+'+@s[i], i+1), f(t+'-'+@s[i], i+1)]
    res.reject{|r| r.nil?}[0]
  end
end

puts f(@s[0], 1)


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
	string s;
	int n=0, w=0, e=0, a=0;
	cin >> s;
	for (int i = 0; i < 1000; i++) {
		if (s[i] == 'N') {
			n++;
		}
		if (s[i] == 'W') {
			w++;
		}
		if (s[i] == 'E') {
			e++;
		}
		if (s[i] == 'S') {
			a++;
		}
	}
	if ((n >= 1 && a >= 1 || n == 0 && a == 0) && (w >= 1 && e >= 1 || w == 0 && e == 0)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
 long long X, K,D;
  cin >>X >>K >>D;
  if(X<0){
    X=X*(-1);
  }
  if(X/D>=K){
    cout <<X-D*K;
  }
  else{
    long long A,B,C;
    A=X/D;
    B=X-D*A;
    C=D-B;
     if((K-A)%2==0){
        cout <<B;
     }
       else{
         cout <<C;
       }
  }
}


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

int main() {

    int N, M;
    cin >> N >> M;

    vector<int> ac(N), wa(N);

    rep(i, M) {
        int p;
        string s;
        cin >> p >> s;
        p--;

        if (ac[p] == 1)
            continue;

        if (s == "AC") {
            ac[p]++;
        } else {
            wa[p]++;
        }
    }

    int ans_ac = 0, ans_wa = 0;
    rep(i, N) {
        if (ac[i] == 1) {
            ans_ac++;
            ans_wa += wa[i];
        }
    }

    cout << ans_ac << " " << ans_wa << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const double EPS = 1e-3;
const double PI = 3.1415926535897932384626433832795028841971;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(ALL(a));
    sort(ALL(b));
    if (n % 2 == 1)
    {
        cout << b[n / 2] - a[n / 2] + 1 << endl;
    }
    else
    {
      	int ma=a[n/2]+a[n/2-1];
      	int mb=b[n/2]+b[n/2-1];
      	int cur=(mb-ma);
        cout << cur+1 << endl;
    }

    return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(){
#define int ll
  int n; cin >> n;
  map<int, int> mp;
  rep(i,n){
    int a; cin >> a;
    mp[a]++;
  }
  bool f = true;
  if(n % 2 == 0){
    for(int i = 1; i < n; i += 2)
      if(mp[i] != 2)
	f = false;
  }else{
    if(mp[0] != 1) f = false;
    for(int i = 2; i < n; i += 2)
      if(mp[i] != 2)
	f = false;
  }
  if(f){
    int mod = 1000000007;
    int ans = 1;
    rep(i,n/2){
      ans *= 2;
      ans %= mod;
    }
    cout << ans << endl;
  }else
    cout << 0 << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
template<typename T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

void RE(){cout<<1/0;}
void TLE(){sleep(100);}
void WA(){cout<<char(0);exit(0);}

const int N = 1e5;
int n;
ll s, a[N], ans;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> a[i];
    s ^= a[i];
  }
  FOR(i, 0, n) a[i] &= ~s;
  int p = 0;
  FOR(i, 0, 60){
    ll b = bit(59-i);
    FOR(j, p, n) if(a[j]&b){
      swap(a[p], a[j]);
      break;
    }
    if(a[p]&b){
      FOR(j, 0, n) if(p!=j && a[j]&b) a[j] ^= a[p];
      if(++p==n) break;
    }
  }
  FOR(i, 0, n) ans ^= a[i];
  cout << ans*2+s << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int n, k;
    cin >> n >> k;
    int points[100000] ={0};
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a;
        points[a-1]++;
    }
    
    int border = q - k;
    for (int i = 0; i < n; i++) {
        if (points[i] > border) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    
    return 0;
}


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

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

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    rep (i, mat.size()) {
      rep (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    rep (i, v.size()) cout << v[i] << ' ';
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m+1);
  for (int i=1; i<=m; i++) cin >> c[i];

  vector<vector<int>> dp = utils::empty<int>(m+1, n+1);
  rep (i, m+1) fill(dp[i].begin(), dp[i].end(), 0);
  rep (i, n+1) dp[0][i] = 1<<28;

  for (int i=1; i<=m; i++) {
    for (int j=1; j<=n; j++) {
      if (j-c[i] < 0) {
        dp[i][j] = dp[i-1][j];
      }
      else {
        dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1);
      }
    }
  }

  // utils::print(dp);
  cout << dp[m][n] << endl;
}

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

constexpr int MAX_N = 300;
int n;
int a[MAX_N];
int memo[MAX_N][MAX_N + 1];
int sum[MAX_N + 1];

int calc(int x, int y) {
	int res = 0;
	int carry = 0;
	while(x > 0 || y > 0) {
		const int xi = x % 10;
		const int yi = y % 10;
		res += xi * yi + carry;
		carry = (xi + yi + carry) / 10;
		x /= 10;
		y /= 10;
	}
	return res + carry;
}

int dfs(int l, int r) {
	if(r - l == 1) return 0;

	auto &res = memo[l][r];
	if(res != -1) return res;

	res = INT_MAX;
	for(int i = l + 1; i < r; ++i) {
		res = min(res, dfs(l, i) + dfs(i, r) + calc(sum[i] - sum[l], sum[r] - sum[i]));
	}

	return res;
}


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

	cin >> n;

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

	partial_sum(a, a + n, sum + 1);
	memset(memo, -1, sizeof(memo));
	cout << dfs(0, n) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1576
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;


signed main() {
    int n;
    double ans = 0;
    double x;
    string y;
    
    cin >> n;
    rep (i, n) {
        cin >> x >> y;
        if (y == "JPY") {
            ans += x;
        } else if (y == "BTC") {
            ans += x * 380000;
        }
    }
    printf("%.5f\n", ans);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [0]
for x in map(int, input().split()):
    A.append(x)
    A[-1] += A[-2]
ans = int(1e18)
for i in range(N - 1):
    ans = min(ans, abs(A[i+1] - (A[N] - A[i+1])))
print(ans)


Measured memory_bytes: 75856
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n);
        for(i =0; i < n; i++){
            cin >> v[i];
        }
        for(i = 0; i < n; i++){
            ll x;
            cin >> x;
            v[i] = v[i] - x;
        }
        sort(v.begin(), v.end());
        ll ans = 0;
        for(i = n - 1 ;i >= 0; i--){
            if(v[i] > 0){
                ans += v[i];
            }
        }
        cout << ans;
    }

    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++) {
        int tmp = i;
        double now_prob = 1.0 / N;
        while (tmp < K) {
            tmp *= 2;
            now_prob /= 2.0;
        }
        ans += now_prob;
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
    return 0;
}

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


int bfs(string& S, string& T)
{
  queue< string > que;
  map< string, int > v;
  que.push(S);
  v[S] = 0;
  while(!que.empty()) {
    string& p = que.front();
    int now = v[p];
    if(p == T) return(now);
    int match = 0;
    while(p[match] == T[match]) ++match;
    int ptrr = (T[match] - p[match] + 10) % 10;
    for(int j = match; j < p.size(); j++) {
      (p[j] += ptrr) %= 10;
      if(v.find(p) == v.end()) {
        v[p] = now + 1;
        que.push(p);
      }
    }
    que.pop();
  }
}
int main()
{
  int K;
  while(cin >> K, K) {
    string S, T;
    cin >> S >> T;
    for(int i = 0; i < K; i++) {
      S[i] -= '0';
      T[i] -= '0';
    }
    cout << bfs(S, T) << endl;
  }
}

Measured memory_bytes: 2644
while True:  
  H, W = map(int, input().split()) 
  c = W
  if W == 0 and H == 0:
    break
  elif W % 2 == 0:
    for i in range(H):
      if c % 2 == 0:
        print("#." * (W // 2))
      elif c % 2 == 1:
        print(".#" * (W // 2)) 
      c += 1

  elif W % 2 == 1:
    for i in range(H):
      if c % 2 == 0:
        print(".#" * (W // 2) + ".")
      elif c % 2 == 1:
        print("#." * (W // 2) + "#") 
      c += 1

  print()


Measured memory_bytes: 5608
from collections import deque
import sys;input=sys.stdin.readline

h,w=map(int,input().split())
grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

stack=deque()
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x]=="#":
            #grid[y][x]=0
            stack.append((y,x))

for i in range(h*w):
    tmp=deque()
    while stack:
        my,mx=stack.pop()
        for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
            if grid[my+y][mx+x]==".":
                #grid[my+y][mx+x]=i+1
                grid[my+y][mx+x]="#"
                tmp.append([my+y,mx+x])
    stack=tmp
    if not tmp:
        print(i)
        break

Measured memory_bytes: 129884
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main()
{
	long long A, B, C;
	cin >> A >> B >> C;
	map<int, bool>used;
	long long cnt = 0;
	while (1) {
		if (A % 2 || B % 2 || C % 2)break;
		if (used.find(A) != used.end() && used.find(B) != used.end() && used.find(C) != used.end()) {
			cnt = -1;
			break;
		}
		used[A] = true;
		used[B] = true;
		used[C] = true;

		long long tmpA = A / 2, tmpB = B / 2, tmpC = C / 2;
		A = tmpB + tmpC;
		B = tmpA + tmpC;
		C = tmpA + tmpB;

		cnt++;
	}

	cout << cnt << 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++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

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

   if (n <= 999) {
       cout << "ABC" << endl;
   } else {
       cout << "ABD" << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define PII pair<int,int>
#define s second
#define f first
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x)%MOD;
        }
        p = p >> 1;
        x = (x*x)%MOD;
    }
    return res;
}
void add_self(ll &a, ll b){
    a += b;
    if(a >= MOD){
        a -= MOD;
    }
}
vector<vector<ll>> v;
vector<ll> cost;
vector<ll> dp;
ll solve(int idx, int mask, int curmask, vector<int> &v){
    if(idx == v.size()){
        if(!curmask){
            return -INT_MAX;
        }
        return cost[curmask] + dp[curmask^mask];
    }
    return max(solve(idx+1, mask, curmask | v[idx], v), solve(idx+1, mask, curmask, v));
}
int main() {
    IO;
    int n;
    cin >> n;
    v.resize(n, vector<ll>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> v[i][j];
        }
    }
    cost.resize(1LL << n, 0);

    for(int i = 0; i < (1LL << n); i++){
        for(int j = 0; j < n; j++){
            if(i & 1 << j){
                for(int k = 0; k < j; k++){
                    if(i & 1 << k){
                        cost[i] += v[j][k];
                    }
                }
            }
        }
    }
    dp.resize(1 << n, 0);
    for(int i = 1; i < (1 << n); i++){
        vector<int> on;
        for(int j = 0; j < n; j++){
            if(1 << j & i){
                on.push_back(1 << j);
            }
        }
        dp[i] = solve(0, i, 0, on);
    }
    cout << dp[(1 << n)-1];



    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include <cmath>

using namespace std;

int main(){
	int w, g[10];
	vector<int> ans;
	
	for(int i=0; i<10; i++) g[i] = pow(2,i);
	
	while(cin >> w){
		ans.clear();
		for(int i=9; i>=0; i--){
			if(w<=1){
				if(w==1)ans.push_back(w);
				break;
			}
			else if(g[i]<=w){
				w -= g[i];
				ans.push_back(g[i]);
			}
						
		}
		for(int i=ans.size()-1; i>=0; i--){
			cout << ans[i];
			(i==0)? cout << endl : cout << " ";
		}
	}


	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, y;
    cin >> n >> y;
    rep(i, n+1) rep(j, n+1) {
        if (i+j > n) break;
        int k = n - i - j;
        if (i*10000+j*5000+k*1000 == y) {
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

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

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

const ll INF = 1LL << 60;

int main(){

  int n,k;
    cin >> n >> k;
    int h[10000000];
    FOR(i,n){
      cin >> h[i];
    }
    ll dp[10000000],a;
    FOR(i,n){
      dp[i]=INF;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
      for(int j=1;j<=k;j++){
        chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
      }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 6656
n,l=map(int,input().split())
a=[]
cnt=101
index=-1
for i in range(n):
  a.append(l+i)
for i in range(n):
  if cnt>=abs(0-a[i]):
    cnt=abs(0-a[i])
    index+=1
print(sum(a)-a[index])

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

ll n, q, a, b, p, x;
vector<ll> g[200005];
vector<ll> arr(200005, 0), ans(200005, 0);

void dfs(ll node, ll parent, ll val) {
    ans[node] = val;
    for (auto adj : g[node]) {
        if (adj != parent) {
            dfs(adj, node, val + arr[adj]);
        }
    }
}

int main() {
    cin >> n >> q;
    for (int i = 0; i < n - 1; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 0; i < q; i++) {
        cin >> p >> x;
        arr[p] += x;
    }

    dfs(1, -1, arr[1]);

    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " ";
    }
}

Measured memory_bytes: 25856
package main

import (
	"fmt"
	"math"
)

func main() {
	var x1, y1, x2, y2 float64
	_, _ = fmt.Scan(&x1, &y1, &x2, &y2)
	a := x2 - x1
	b := y2 - y1
	c := a*a + b*b
	fmt.Println(math.Sqrt(c))
}



Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
vector<char> add[2]; // 0 앞, 1 뒤
int main() {
	int rev = 0;
	string s;
	int q;
	cin >> s >> q;
	while (q--) {
		int t, f; char c;
		cin >> t;
		if (t == 1) {
			rev ^= 1;
		}
		else {
			cin >> f >> c;
			add[(f - 1) ^ rev].push_back(c);
		}
	}
	reverse(add[rev].begin(), add[rev].end());
	for (char c : add[rev]) {
		cout << c;
	}
	if (rev) {
		reverse(s.begin(), s.end());
	}
	cout << s;
	for (char c : add[!rev]) {
		cout << c;
	}
}

Measured memory_bytes: 1024
def main():
    N, *A = map(int, open(0).read().split())

    A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for l in range(N):
        for r in range(N - l):
            p, a = A[l + r]

            dp[l + 1][r] = max(
                dp[l + 1][r],
                a * (p - l) + dp[l][r]
            )
            dp[l][r + 1] = max(
                dp[l][r + 1],
                a * (N - 1 - r - p) + dp[l][r]
            )

    print(max(dp[l][N - l] for l in range(N)))

main()

Measured memory_bytes: 124776
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  //  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
    if ( size > 1000000 ) { printf("error"); }
  }

  
  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}



Measured memory_bytes: 36096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int f[10];
	int n=0;
	int s[500];
	int x=0;
	int y=0;
	int i=0;
	int j=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x>>y>>f[0]>>f[1];
		if(f[0]<5){
			f[2]=5;
		}else{
			f[2]=f[0];
		}
		if(f[1]<2){
			f[3]=2;
		}else{
			f[3]=f[1];
		}
		f[4]=f[0]*x+f[1]*y;
		f[5]=f[2]*x+f[3]*y;
		f[5]=f[5]*0.8;
		s[i]=min(f[4],f[5]);
	}
	for(i=0;i<n;i++){
		cout<<s[i]<<endl;
	}
}
		

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;cin>>a>>b;
    if (a>9 || b>9) cout << -1 << endl;
    else cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int i, j, n, a[100], temp, flag = 1, count = 0;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
	}
	
	while (flag)
	{
		flag = 0;
		
		for (j = n - 1; j > 0; --j)
		{
			if (a[j] < a[j-1])
			{
				temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
				flag = 1;
				++count;
			}
		}
	}
	
	for (i = 0; i < n; ++i)
	{
		printf("%d", a[i]);
		if (i != n-1) printf(" ");
	}
	printf("\n");
	printf("%d\n", count);
	
	return 0;
}

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

bool solve() {
    string S;
    cin >> S;
    for ( int i = 0; i < (S.size()+1)/2; i++ ) {
        if ( S.substr(i*2,2) != "hi") return false;
    }
    return true;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
l=r=x=s=ans=0
while l<n:
	while r<n and x^a[r]==s+a[r]:
		x^=a[r]
		s+=a[r]
		r+=1
		ans+=1
	x^=a[l]
	s-=a[l]
	l+=1
	ans+=r-l
print(ans)

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

int main(){
  int N;
  int A[100000];
  int M[100000];
  cin >> N;

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


  M[1] = A[0];

  for(int i = 1; i < N; i++){
    if(i%2 == 0){
      M[1] -= A[i];
    } else{
      M[1] += A[i];
    }
  }

  M[0] = 2 * A[0] - M[1];

  cout << M[0] << " " << M[1];

  for (int i = 2; i< N; i++){
    M[i] = 2 * A[i-1] - M[i-1];
    cout << " " << M[i];
  }

  cout << endl;


  return 0;
}


Measured memory_bytes: 1664
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize
    }
    
    let flag = {
        let mut flag = false;
        for i in 0..=n {
            for j in 0..=m {
                if j*(n-i)+i*(m-j) == k {
                    flag = true;
                }
            }
        }
        flag
    };

    if flag {
        println!("Yes")
    } else {
        println!("No")
    }
    
}

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

typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const ll N=2e5 + 5;
const ll mod=1e9 + 7;

int main()
{
    fast();
    ll n;
    cin>>n;

    priority_queue<ld ,vector<ld> , greater<ld> >pq;
    ld ans = 0;

    for(ll i=0;i<n;i++)
    {
        ld val;
        cin>>val;
        pq.push(val);
    }

    while(pq.size()>1)
    {
        ld val1 = pq.top();
        pq.pop();
        ld val2 = pq.top();
        pq.pop();

        ld ans = (val1+val2)/2;
        pq.push(ans);
    }

    cout<<fixed<<setprecision(10)<<pq.top();




}


Measured memory_bytes: 256