akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n;
	cin>>n;
	string s;
	cin>>s;
	ll c=0;
	for(i=0;i<n;i++){
		if(s[i]=='1') c++;
	}
	ll n1=0,n2=0,n3=0;
	for(i=n-1;i>=0;i--){
		if(s[i]=='1'){
			n1=(n1+power(2,n-i-1,c))%c;
			if(c>1)
				n2=(n2+power(2,n-i-1,c-1))%(c-1);
			n3=(n3+power(2,n-i-1,c+1))%(c+1);
		}
	}

	for(i=0;i<n;i++){
		if(s[i]=='1') c--;
		else c++;
		if(c==0) cout<<"0"<<endl;
		else{
			if(s[i]=='1'){
				ll tmp=(n2-power(2,n-i-1,c)+10000*c)%c,an=1;
				while(tmp>0){
					k=__builtin_popcountll(tmp);
					tmp=tmp%k; an++;
				}
				cout<<an<<endl;
			}
			else{
				ll tmp=(n3+power(2,n-i-1,c))%c,an=1;
				while(tmp>0){
					k=__builtin_popcountll(tmp);
					tmp=tmp%k; an++;
				}
				cout<<an<<endl;
			}
		}
		if(s[i]=='1') c++;
		else c--;
	}
	return 0;	
}

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

typedef long long int ll;
typedef vector<int> vi;            
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int>     pii;
typedef vector<bool> vb;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#ifdef LOCAL
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
    ll r, c, k; cin>>r>>c>>k;
    vvl inp(r+1, vl(c+1, 0));
    for(int i = 0; i<k; i++){
        ll r1, c1, v1;
        cin>>r1>>c1>>v1;
        inp[r1][c1] = v1;
    }
    vvl dp(r+1, vl(c+1, 0));
    for(ll i = 1; i<=r; i++){
        vl curr(4, 0);//curr_set_of_values
        for(ll j = 1; j<=c; j++){
            if(inp[i][j]){
                curr[3] = max(curr[3], curr[2] + inp[i][j]);
                curr[2] = max(curr[2], curr[1] + inp[i][j]);
                curr[1] = max(curr[1], curr[0] + inp[i][j]);
                curr[1] = max(curr[1], dp[i-1][j] + inp[i][j]);
            }
            else curr[0] = max(curr[0], dp[i-1][j]);
            dp[i][j] = max({curr[3], curr[2], curr[1], curr[0]});
        }
    }
    cout<<dp[r][c]<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen(".inp.txt", "r", stdin);
        freopen(".out.txt", "w", stdout);
        freopen(".err.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 144180
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

simulate :: [Int] -> Int -> String
simulate [] b = "Yes"
simulate (h:hs) b | h - b >= 2 = simulate hs (h - 1)
                  | h - b == 1 || h - b == 0 = simulate hs b
                  | otherwise = "No"

main = do
  n <- getInt
  hs <- getIntList
  putStrLn $ simulate hs (head hs)


Measured memory_bytes: 7280
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a 
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast(){cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);}
ll power(ll x,ul y,ll p){ll res = 1;x = x % p;if(x == 0)return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
string solve(){
		string a,b;
		cin>>a>>b;
		for(ll i=0;i<(int)a.length();i++){
			if(a[i]!=b[i]) return "No";
		}
		return "Yes";
 }
int main(){
	fast();
	cout<<solve()<<"\n";
	return 0;
}



Measured memory_bytes: 3636
// abc132d.cpp : Blue and Red Balls
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define oute(x) cout<<(x)<<endl

#define MAX 2001
ll inv[MAX];

int main(){
  int N,K; cin>>N>>K;
  int red = N-K, blue = K;

  inv[1] = 1;
  upto(i,2,(red<blue? blue: red)+1,1)
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;

  ll ai = red + 1;
  oute(ai);
  upto(i,2,blue+1,1){
    ai = (ai *  (red-i+2) * (blue-i+1) % MOD) * (inv[i] * inv[i-1] % MOD) % MOD;
    oute(ai);
  }
}

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

int main(void) {
    int n, m;
    cin >> n >> m;
    if (n == 1 && m == 1) cout << 1 << endl;
    else if (n == 1 && m != 1) cout << m - 2 << endl;
    else if (n != 1 && m == 1) cout << n - 2 << endl;
    else if (n == 2 || m == 2) cout << 0 << endl;
    else cout << (long long)(n - 2) * (long long)(m - 2) << endl;
}


Measured memory_bytes: 256
memo = dict()
def num_sequence(sum):
    if sum < 3:
        return 0
    if sum < 6:
        return 1
    if sum in memo.keys():
        return memo[sum]
    num_seq = 0
    for num in range(3, sum-2):
        num_seq += num_sequence(sum - num)
    # +1 はnum=sumの場合を含めるため
    memo[sum] = num_seq + 1
    return num_seq + 1

n = int(input())
print(num_sequence(n) % (10 ** 9 + 7))

Measured memory_bytes: 9684
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define inf 0x3f3f3f3f

const int maxn = 1e6 + 8;

int n,a[maxn],j,v;
stack<int> G;

int intersectSort(int a[],int p)
{
    int num = 0;
    for(int i = p; i < n; ++i) {
        j = i-p;
        v = a[i];
        while(j >= 0 && a[j] > v){
            a[j+p] = a[j];
            j -= p;
            num++;
        }
        a[j+p] = v;
    }
    return num;
}
int main()
{
    fill(a,a+n,0);
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) scanf("%d",&a[i]);

    for(int h = 1; ; ){
        if(h > n) break;
        G.push(h);
        h = h * 3 + 1;
    }

    printf("%d\n",(int)G.size());
    bool first = true;
    int sum = 0;
    while(!G.empty())
    {
        int p = G.top();G.pop();
        if(first)  {first = false; printf("%d",p);}
        else {printf(" %d",p);}
        sum += intersectSort(a,p);
    }
    printf("\n%d\n",sum);
    for(int i = 0; i < n; ++i){
        printf("%d\n",a[i]);
    }

    return 0;
}

Measured memory_bytes: 7052
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, T;
  cin >> n >> T;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int prof = 0;
  int mx = 0;
  for (int i = n - 1; i >= 0; i--) {
    prof = max(prof, mx - a[i]);
    mx = max(mx, a[i]);
  }
  int cnt = 0;
  set<int> st;
  for (int i = n - 1; i >= 0; i--) {
    if (st.find(a[i] + prof) != st.end()) {
      cnt++;
    }
    st.insert(a[i]);
  }
  cout << cnt << "\n";
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main() {
    int s;
    cin>>s;

    if(s==25){
        cout<<"Christmas"<<endl;
    }
    else if(s==24){
        cout<<"Christmas Eve"<<endl;
    }
    else if(s==23){
        cout<<"Christmas Eve Eve"<<endl;
    }
    else if(s==22){
        cout<<"Christmas Eve Eve Eve"<<endl;
    }
}


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

using namespace std;
const int max_d = 30;

int sieve(int n) {
    int res = 0;
    bool prime[n + 1];
    for(int i = 0; i <= n; i++) {
        prime[i] = true;
    }
    for(int i = 2; i <= n ; i++) {
        if(prime[i]) {
            res++;
            for(int j = 2 * i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    return res;
}

int main() {
    int n;
    int dc = 0;
    while(cin >> n) {
        dc++;
        if(dc > max_d) break;
        cout << sieve(n) << endl;
    }
    return 0;
}

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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);

    int A, B, M;
    cin >> A >> B >> M;

    vector<int> a(A), b(B);

    for(int i = 0; i < A; i++) cin >> a[i];
    for(int i = 0; i < B; i++) cin >> b[i];

    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());

    for(int i = 0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c;

        ans = min(ans, a[x - 1] + b[y - 1] - c);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1152
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int a=Integer.parseInt(s.substring(5,7));
    // System.out.println(a);
    // int b=Integer.parseInt(s.substring(8));
    // System.out.println(b);

    if(a<=4){
      System.out.println("Heisei");
    }else{
      System.out.println("TBD");
    }
  }
}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

ll saiki(vector<ll> v, ll n, ll m, vector<ll> a,vector<ll> b,vector<ll> c,vector<ll> d)
{
	ll size = v.size();
	ll score = 0;
	if (size == n)
	{
		for (int i = 0; i < a.size(); i++)
		{
			if (v[b[i] - 1] - v[a[i] - 1] == c[i])
				score += d[i];
		}
		return score;
	}
	v.push_back(0);
	for (int i = v[size - 1]; i <= m; i++)
	{
		v[size] = i;
		score = max(score, saiki(v, n, m, a, b, c, d));
	}

	return score;
}


int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll n, m, q;
	cin >> n >> m >> q;
	vector<ll> a(q), b(q), c(q), d(q);
	rep(i, q)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	ll ans = 0;
	vector<ll> v(1);
	for (int i = 1; i <= m; i++)
	{
		v[0] = i;
		ans = max(ans, saiki(v, n, m, a, b, c, d));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3668
mod = 998244353
n = gets.to_i
ds = gets.split.map(&:to_i)

if ds[0] != 0
  puts 0
  exit
end

h = Hash.new(0)
mx = -1
ds.map do |d|
  h[d] += 1
  mx = d if d > mx
end

ans = 0
(0..mx).map do |i|
  if i == 0
    if h[0] != 1
      puts 0
      exit
    end
  elsif i == 1
    ans = 1
  else
    ans *= (h[i - 1] ** h[i])
    ans %= mod
  end
end
p ans


Measured memory_bytes: 16324
n,l=map(int,input().split())

taste=[l+i-1 for i in range(1,n+1)]
best=sum(taste)
ans=100000
for i in range(n):
  ans=min(ans,abs(taste[i]))
if best>=0:
  print(best-ans)
else:
  print(-(abs(best)-ans))

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

using namespace std;

int main(){

    vector<vector<int>> c(3,vector<int>(3));

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c.at(i).at(j);
        }
    }

    bool ans = false;

    for(int a1=0; a1<=c.at(0).at(0); a1++){
        for(int a2=0; a2<=c.at(1).at(1); a2++){
            for(int a3=0; a3<=c.at(2).at(2); a3++){
    
            int b1 = c.at(0).at(0) - a1;
            int b2 = c.at(1).at(1) - a2;
            int b3 = c.at(2).at(2) - a3;

        
            if(c.at(0).at(1) != a1+b2)
                continue;
            if(c.at(0).at(2) != a1+b3)
                continue;
            if(c.at(1).at(0) != a2+b1)
                continue;
            if(c.at(1).at(2) != a2+b3)
                continue;
            if(c.at(2).at(0) != a3+b1)
                continue;
            if(c.at(2).at(1) != a3+b2)
                continue;
            
            ans = true;
            break;
            }
        }
    }

    if(ans)
    cout << "Yes" <<endl;
    else
    cout << "No" << endl;
    
}

Measured memory_bytes: 3516
/**
 *      ABc 47 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-20 07:18:58
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c; cin >> a >> b >> c;
    if ((a + b == c || a + c == b) || b + c == a){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
map<int,int> m;
int A[100005];
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for( int i=0; i<N; i++ ){
    cin >> A[i];
    m[A[i]] = i;
  }
  sort( A, A+N );
  int ret = 0;
  for( int i=0; i<N; i++ ){
    if( (m[A[i]] - i + 1000000) % 2 > 0 ){
      ret++;
    }
  }
  cout << ret / 2 + ret % 2 << endl;
}

Measured memory_bytes: 5376
S = input()
p1,p2=0,0
for i,s in enumerate(S):
    if i%2==0:
        if s=="0":
            p1+=1
        else:
            p2+=1
    else:
        if s=="0":
            p2+=1
        else:
            p1+=1
print(min(p1,p2))

Measured memory_bytes: 3188
#include <stdio.h>

int main(){
	int i, j, prm[1000000];
	
	for(i = 0; i < 1000000; i++) prm[i] = 1;
	
	for(i = 4; i < 1000000; i += 2) prm[i] = 0;
	
	prm[0] = prm[1] = 0;
	
	for(i = 3; i * i < 1000000; i += 2)
		if(prm[i])
			for(j = i + i; j < 1000000; j += i) prm[j] = 0;
				
	for(i = j = 0; i < 1000000; i++){
		if(prm[i]) j++;
		
		prm[i] = j;
	}
	
	while(scanf("%d", &i) != EOF) printf("%d\n", prm[i]);
	
	return 0;
}

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

#define sz(x) (int) x.size()

using namespace std;
using pii = pair<int, int>;

const int N = 1e5+5;

int dp[N], was[N];

vector<int> top, adj[N];

void dfs(int x) {
    was[x] = 1;
    for (int to : adj[x])
        if (!was[to])
            dfs(to);    
    top.push_back(x);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int u, v; m--;) {
        cin >> u >> v;
        adj[u].push_back(v);
    }
    for (int i = 0; i < n; ++i)
        if (!was[i + 1])
            dfs(i + 1);
    reverse(top.begin(), top.end());
    for (int x : top)
        for (int to : adj[x])
            dp[to] = max(dp[to], dp[x] + 1);
    cout << *max_element(dp, dp+N);
    return 0;
}

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

vector<long long> v;
void dfs(ll x, ll num, ll st, ll cc){
	if(v.size() > 100050) return;
	if(num == 0) num += x;
	else {
		num *= 10;
		num += x;
	}
	if(cc > st) return;
	if(cc == st){
		v.push_back(num);
		return;
	}
	if(x-1 >= 0) dfs(x-1,num,st,cc+1);
	if(x+1 <= 9) dfs(x+1,num,st,cc+1);
	dfs(x,num,st,cc+1);
	return;
}

int main(){
	
	ll k; cin>>k;
	for(int i = 1; i <= 10; i++){
		for(int j = 1; j <= 9; j++){
			dfs(j,0,i,1);
		}
	}
	sort(v.begin(),v.end());
	cout<<v[k-1]<<"\n";
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int mod = 1e9+7;
int main(){
  cin >> n >> m;
  int dp[n];
  vector<int> a(m);
  const int INF = mod;
  fill(dp, dp+n+1, INF);
  for(int i=0 ; i<m ; i++){
    int x; cin >> x;
    dp[x] = 0;
  }
  dp[0] = 1;
  for(int i=1 ; i<=n ; i++){
    if(dp[i] == INF){
      if(i == 1){
        dp[i] = dp[i-1];
      }else{
        if(dp[i-1]!=INF && dp[i-2]!=INF)
          dp[i] = dp[i-1] + dp[i-2];
      }
    }
    dp[i] %= mod;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;


#define FOR(i,a,b) for(LL i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

using namespace std;

const LL MOD = 1000000007;



int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<LL> arr(n);
	LL sum = 0;
	FOR(i,0,n) {
		cin >> arr[i];
		sum += arr[i];
		
	}

	LL ans = 0;

	FOR(i,0,n) {
		sum -= arr[i];
		ans += (arr[i]*(sum%MOD)) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}









Measured memory_bytes: 4776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		String[] ab = sc.nextLine().split(" ");
		int a = Integer.parseInt(ab[0]);
		int b = Integer.parseInt(ab[1]);

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}

}

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

struct Process{
  string name;
  int time;
};

int main(){

  int n,qtime,ttime=0;
  Process ps;
  queue<Process> qu;
  scanf("%d%d",&n,&qtime);
  for(int i=0;i<n;i++){
    cin>>ps.name>>ps.time;
    qu.push(ps);
  }
 
  while(!qu.empty()){
    ps=qu.front();
    if(ps.time<=qtime){
      ttime+=ps.time;
      cout<<ps.name<<" "<<ttime<<endl;
      qu.pop();
    }else{
      ttime+=qtime;
      ps.time-=qtime;
      qu.pop();
      qu.push(ps);
    }
  }
  return 0;
}

Measured memory_bytes: 4452
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T,A;
  cin >> N >> T >> A;
  int n = 0;
  double d = 100000; 
  
  for (int i = 0; i < N; i++) {
    int H;
    cin >> H;
    double t = T - H * 0.006;
    if (abs(A - t) < d) {
      n = i + 1;
      d = abs(A - t);
    }
  }
    
    

  cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll A[100100];
vector<int> g[100100];
int par[100100];
int deg[100100];
ll c[100100];
ll csum[100100];
void dfs(int v,int p){
	par[v]=p;
	int cnt = 0;
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		if(u==p)continue;
		cnt++;
		dfs(u,v);
		csum[v]+=c[u];
	}
	if(cnt>0)c[v]=2ll*A[v]-csum[v];
	else c[v]=A[v];
}
void fail(int x=-1){
	//cout << "fail: " << x << endl;
	cout << "NO" << endl;
	exit(0);
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> A[i];
	for(int i=0;i<N-1;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		deg[a]++;
		deg[b]++;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0,-1);
	for(int i=0;i<N;i++){
		//cout << i << ' ' << c[i]  << ' ' << csum[i] << endl;
		if(i>0&&c[i]<0ll)fail();
	}
	if(deg[0]==1){
		if(c[g[0][0]]!=A[0])fail(0);
	}else{
		if(c[0]!=0)fail();
		for(int i=0;i<g[0].size();i++){
			int u = g[0][i];
			if(c[u]>A[0])fail();
		}
	}
	for(int i=1;i<N;i++){
		if(deg[i]>1&&c[i]>csum[i])fail(1);
		ll rem = 0ll;
		ll h = (csum[i]-c[i])/2ll;
		for(int j=0;j<g[i].size();j++){
			int u = g[i][j];
			if(par[i]==u)continue;
			rem += max(0ll,c[u]-h);
		}
		if(rem>c[i])fail(2);
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 15488
#include<cstdio>
int main(){
    char s[3][101];
    int p[3]={0,0,0},n=0,m;
    for(int i=0;i<3;i++)scanf("%s",s[i]);
    while(true){
        if(s[n][p[n]]=='\0'){
            printf("%c",'A'+n);
            return 0;
        }else{
            m=n;
            n=s[n][p[n]]-'a';
            p[m]++;
        }
    }
}


Measured memory_bytes: 128
Imports System

Module Program
    Sub Main(args As String())

        Dim NMK() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
        Dim A() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
        Dim B() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()

        Dim ReadA(NMK(0)) As Long
        ReadA(0) = 0
        For i As Integer = 0 To NMK(0) - 1
            ReadA(i + 1) = ReadA(i) + A(i)
        Next
        Dim ReadB(NMK(1)) As Long
        ReadB(0) = 0
        For i As Integer = 0 To NMK(1) - 1
            ReadB(i + 1) = ReadB(i) + B(i)
        Next

        Dim ans As Integer = 0

        Dim iB As Integer = NMK(1)
        For i As Integer = 0 To NMK(0)      ' 0 - N books on desk A
            Dim NokoriJikan As Integer = NMK(2)
            If i <> 0 Then
                NokoriJikan -= ReadA(i)
            End If
            If NokoriJikan < 0 Then Exit For

            Dim ReadCount As Integer = i

            For j As Integer = iB To 0 Step -1      ' M - 0 books on desk B
                If ReadB(j) <= NokoriJikan Then
                    NokoriJikan -= ReadB(j)
                    iB = j
                    ReadCount += j
                    Exit For
                End If
            Next
            If ans < ReadCount Then
                ans = ReadCount
            End If
        Next

        Console.WriteLine(ans)

    End Sub

End Module


Measured memory_bytes: 71528
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	string s;cin>>s;
	s[3]='8';
	cout<<s<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
  for(int i=0;i<4;i++){
    int t,n;
    scanf("%d %d",&t,&n);
    if(t==1) printf("%d\n",n*6000);
    else if(t==2) printf("%d\n",n*4000);
    else if(t==3) printf("%d\n",n*3000);
    else if(t==4) printf("%d\n",n*2000);
  }
 
  return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>
long long a [100010];
int main (){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%lld",&a[i]);
  int zero =0;
  for(int i=0;i<n;i++)if(a[i]==0) zero ++;
  if(zero >0){
  // a[i] contains 0
    printf("0\n");
    return 0;
  }
  long long prod =1;
  for(int i=0;i<n;i++){
    if(a[i ] <=1000000000000000000/ prod ){
      // This condition is equivalent to prod*a[i] <=10ˆ18
      prod *=a[i];
    }else{
    printf("-1\n");
    return 0;
    }
  }
  printf("%lld\n",prod );
}

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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int label(int x)
{
    if (x==4 || x==6 || x==9 || x==11) return 1;
    else if (x==2) return 2;
    else return 3;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    int x, y; cin >> x >> y;

    if (label(x) == label(y)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int n,q; cin >> n >> q;
    queue<int> que[n];
    for(int i = 0; i < q; i++){
        int num; cin >> num;
        if (num == 0){
            int t,x; cin >> t >> x;
            que[t].push(x);
        } else if (num == 1){
            int t; cin >> t;
            if (que[t].size()){
                cout << que[t].front() << endl;
            }
        } else if (num == 2){
            int t; cin >> t;
            if (que[t].size()){
                que[t].pop();
            }
        }
    }
}
  




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

ll gcd(ll x, ll y){return y ? gcd(y, x%y) : x;};
ll lcm(ll a, ll b){return a/gcd(a, b) * b;};


int main(){
  int a, b;
  cin >> a >> b;
  
  cout << lcm(a, b) << endl; 
  return 0;
}

Measured memory_bytes: 256
////////////////////////    W H I T E C L O U D    ////////////////////////
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main()
{
    FAST();
    ll a,b,c,d,maxx=-1000000000000000000,zero=0;
    cin>>a>>b>>c>>d;
    maxx=max(maxx,a*c);
    maxx=max(maxx,b*d);
    maxx=max(maxx,b*c);
    maxx=max(maxx,a*d);
    if((a<=0 && 0<=b) || (c<=0 && 0<=d))maxx=max(zero,maxx);
    cout<<maxx<<endl;


    return 0;
}







Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;


const int MOD=1000000007;

int main(int argc, char**argv){
    // int a, b, c, d, e;
    // int k;
    // cin >> a;
    // cin >> b;
    // cin >> c;
    // cin >> d;
    // cin >> e;
    // cin >> k;
    int a[5];
    int k;

    int t = 0;
    int min = 99;
    for (int i=0; i < 5; i++){
      cin >> a[i];
      if (a[i]%10 < min && a[i]%10 > 0){
        // cout << "a[i]% is ";
        // cout << a[i]%10 << endl;
        t = i;
        min = a[i]%10;
      }
    }
    // cin >> k;
    // cout << "t";
    // cout << t << endl;
    // cout << "min";
    // cout << min << endl;

    int sum = 0;
    for (int i = 0; i < 5; i++){
      if (i == t){
        sum += a[i];
        continue;
      }
      if (a[i]%10 == 0){
        sum += ((a[i]/10)) * 10;
      }else{
        sum += ((a[i]/10)+1) * 10;
      }
      // sum += ((a[i]/10)+1) * 10;
      // sum += a[i] + (10-a[i]%10);
    }

    //
    // for (int i=0; i<5; i++){
    //   for (int j=0; j<5; j++){
    //     if (abs(a[i]-a[j]) > k){
    //       cout << ":(" << endl;
    //       return 0;
    //     }
    //   }
    // }
    //
    // cout << "Yay!" << endl;

    // for int
    cout << sum << endl;

    // cout << a << endl;
    // cout << b << endl;

    // cout << "Test program for dbg" << endl;
    // int a[100];
    //
    // rep (i, 1000){
    //     cout << a[i] << endl;
    // }


	return 0;
}


Measured memory_bytes: 256
// C - Dice and Coin
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k;
	cin >> n >> k;
	double ans = 0;

	for (int i = 1; i <= min(k - 1, n); i++) {
		double t = 1.0;
		for (int c = 0; (i << c) < k; c++) t *= 0.5;
		ans += t / n;
	}
	for (int i = k; i <= n; i++) ans += 1.0 / n;

	cout << setprecision(12) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int Min=b-a,Max=b+a;
    Min++;
    if(b-a<-1000000)
    {
        Min=-1000000;
    }
    if(b+a>1000000)
    {
        Max=1000000;
    }
    //cout<<Min<<Max<<endl;
    for(int i=Min;i<Max;i++)
    {
        cout<<i<<" ";
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 int search(int A[],int n, int key)
{
  int i = 0;
   A[n] = key;
   while( A[i] != key) i++;
   return i != n;
}

  int main(){
  int i,n,A[10000+1],q,key,sum = 0;

  scanf("%d",&n);
  for(i = 0; i < n;i++)
  scanf("%d", &A[i]);
  
  scanf("%d", &q);
  for(i = 0; i < q;i++){
  scanf("%d",&key);
  if(search(A,n,key)) sum++;
}
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 1800
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    char c;
    int ans = 0, i = 0;
    char num[6] = {'\0'};
    while( cin.get(c) ){
        if(c >= '0' && c <= '9'){
            num[i++] = c;
        }else if(i != 0){
            ans += stoi(num);
            i = 0;
            char *b = num;
            rep(j,6)
                *b++ = '\0';
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("mmx,avx,fma")
//#pragma GCC optimize ("unroll-loops")

using namespace __gnu_pbds;
using namespace std;

#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);

template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, set<T>& v){ for(auto& e : v){ out << e << d; } return out; }

#define pb push_back
#define mk make_pair
#define X first
#define Y second
#define cont continue
#define ret return
#define For(i, a, b) for (int i = a; i < b;i++)
#define forn(i, a) for (int i = 0;i < a;i++)
#define ford(i, a, b) for (int i = b - 1;i >= a;i--)
#define fordn(i, a) for (int i = a - 1;i >= 0;i--)
#define forr(x, arr) for(auto &x: arr)
#define all(x) x.begin(),x.end()
#define REE(s_) {cout << (s_) << '\n';return 0;}
#define endl '\n'
#define makeunique(x) sort(all(x)), (x).resize(unique(all(a)) - (x).begin())
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef long double ldd;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_tree;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
////const int mod = 1e9 + 7;
//const int mod = 998244353;
ll powq(ll a, ll n) {
    ll res = 1;
    while (n){
        if (n & 1) {
            res *= a;
//            res %= mod;
            --n;
        }
        else {
            a *= a;
            n >>= 1;
//            a %= mod;
        }
    }
    return res;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, p;
    cin >> n >> p;
    mii mp;
    For(i, 2, sqrt(p) + 1){
        if (p % i == 0){
            while(p % i == 0) {mp[i]++; p /= i;}

        }
    }
    if (p != 1) mp[p]++;

    int ans = 1;
    forr(i, mp){
        ans *= powq(i.X, (i.Y / n));
    }
    cout << ans;
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

ll dp[1010][1010];

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

    string t, b;
    cin >> t >> b;

    dp[0][0] = 1;

    REP(i, t.size())
    {
        REP(j, b.size() + 1)
        {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;

            if(j != b.size() && t[i] == b[j])
            {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
            }
        }
    }

    cout << (dp[t.size()][b.size()] % MOD) << endl;

    return 0;
}


Measured memory_bytes: 11060
N = int(input())
data = []
for _ in range(N):
	A = int(input())
	items = []
	for __ in range(A):
		x, y = map(int, input().split())
		items.append((x - 1, y))
	data.append(items)


best = 0

def check(state):
	for i in range(N):
		if state[i] == 1:
			for x, y in data[i]:
				if y != state[x]:
					return False
	return True

def combination(state):
	global best
	if len(state) == N:
		if check(state):
			count = sum(state)
			if count > best:
				best = count
	else:
		combination(state + [0])
		combination(state + [1])

combination([])

print(best)


Measured memory_bytes: 3064
N=int(input())
A = list(map(int,input().split()))
B=[]
total=0
count=0
zero=0
flag=0
for i in range(N):
  total+=A[i]
  if total==0:
    zero+=1
  B.append(total)
total=0

B.sort()
B.append(1000000000)
for i in range(N):
  count+=1
  if B[i]!=B[i+1]:
    if count>=2:
        total+=count*(count-1)//2
    count=0
#print(B)
print(total+zero)


Measured memory_bytes: 26136
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (mut n, k) = (v[0], v[1]);
    n %= k;
    println!("{}", min(n, k - n));
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        map<char, int> mp;
        bool finished = false;
        for(int i = 1; i <= n; i++) {
            char in;
            cin >> in;
            if(finished) continue;
            mp[in]++;
            vector<int> v(26);
            for(int i = 0; i < 26; i++) {
                v[i] = mp[(char)('A' + i)];
            }
            sort(v.begin(), v.end(), greater<int>());
            if(v[1] + (n - i) >= v[0]) continue;
            //cout << n << " " << i << " " << v[0] << " " << v[1] << endl;
            char ans = 'A';
            for(char now = 'B'; now <= 'Z'; now++) {
                if(mp[now] >= mp[ans]) ans = now;
            }
            cout << ans << " " << i << endl;
            finished = true;
            //break;
        }
        if(!finished) cout << "TIE" << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
using P = pair<int, int>;

vector<vector<int>> edge;

stack<int> hist;
vector<bool> seen;

bool dfs(int p, int t){
    for(auto nt: edge[t]){
        if (nt == p){
            return true;
        }
        else if (seen[nt])continue;

        hist.push(nt);
        seen[nt] = true;
        bool ans = dfs(p, nt);

        if (ans)return true;
        hist.pop();
    }
    return false;
}


int main(){
    int n, m;
    cin >> n >> m;
    edge.resize(n+1);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
    }

    vector<int> cp;
    for(int p = 1; p <= n; p++){
        seen.assign(n+1, false);
        while(!hist.empty())hist.pop();
        hist.push(p);
        seen[p] = true;
        bool ok = dfs(p, p);
        if (ok){
            while(!hist.empty()){
                cp.push_back(hist.top());
                hist.pop();
            }
            reverse(cp.begin(), cp.end());
            break;
        }
    }
    if (cp.empty()){
        cout << -1 << endl;
        return 0;
    }
    vector<int> path(n+1, -1);
    for(int i = 0; i < cp.size(); i++){
        path[cp[i]] = i;
    }
    while(true){
        bool cut = false;
        path.assign(n+1, -1);
        for(int i = 0; i < cp.size(); i++){
            path[cp[i]] = i;
        }
        for(int i = 0; i < cp.size(); i++){
            for(auto nt: edge[cp[i]]){
                if (path[nt] != (i+1)%cp.size() && path[nt] > 0){
                    cut = true;
                    int from = i;
                    int to = path[nt];
                    vector<int> ncp;
                    if (from < to){
                        for(int j = to; j < cp.size(); j++){
                            ncp.push_back(cp[j]);
                        }
                        for(int j = 0; j <= from; j++){
                            ncp.push_back(cp[j]);
                        }
                    }
                    else {
                        for(int j = to; j <= from; j++){
                            ncp.push_back(cp[j]);
                        }
                    }
                    cp = ncp;
                    break;
                }
            }
            if (cut)break;
        }
        if (!cut)break;
    }

    cout << cp.size() << endl;
    for(auto p: cp)cout << p << endl;
    return 0;
}

Measured memory_bytes: 3288
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
    int W, H, N;
    cin >> W >> H >> N;
    int xm, xM, ym, yM;
    xm = 0;
    xM = W;
    ym = 0;
    yM = H;
    for(int i = 0; i < N; i++){
        int xx, yy, aa;
        cin >> xx >> yy >> aa;
        switch(aa){
            case 1: xm = max(xm, xx);
            break;
            case 2: xM = min(xM, xx);
            break;
            case 3: ym = max(ym, yy);
            break;
            case 4: yM = min(yM, yy);
            break;
        }
    }
    int w = max(0, xM - xm);
    int h = max(0, yM - ym);
    cout << w * h << endl;
    return 0;
}

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

int main(){
  int n, i, s, ans;
  cin >> n;
  vector<pair<int , int>> a(n);
  vector<pair<int , int>> b(n);

  for(i=0; i<n; i++){
    cin >> s;
    a[i] = make_pair(s, i);
  }
  sort(a.begin(), a.end());

  for(i=0; i<n; i++){
    if(a[i].first==a[n-1].first && a[i].second!=a[n-1].second) ans = a[n-1].first;
    else if(a[i].first==a[n-1].first  &&  a[i].second==a[n-1].second) ans = a[n-2].first;
    else ans = a[n-1].first;

    b[i] = make_pair(a[i].second, ans);
  }

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

  for(i=0; i<n; i++) cout << b[i].second << endl;

  return 0;
}


Measured memory_bytes: 4736
def resolve():
    N, A, B = map(int, input().split())
    S = input()
    count = 1
    sabetu = 1
    for i in range(N):
        if S[i] == "a" and count <= A+B:
            count += 1
            print("Yes")
        elif S[i] == "b" and sabetu <= B and count <= A+B:
            sabetu += 1
            count += 1
            print("Yes")
        else:
            print("No")
resolve()

Measured memory_bytes: 4016
/*
ID: dorijan1
TASK: tu napisi ime zadatka molim te molim te ali samo ako si na usaco training
LANG: C++11
*/
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define rand rund
#define pb push_back

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
const int MOD=1000000007;
const int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

ll raand()
{
	ll a=rand();
	a*=RAND_MAX;
	a+=rand();
    return a;
}

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

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

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

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

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

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

int sub(int a,int b)
{
	return (a-b+MOD)%MOD;
}

int add(int a,int b)
{
	return (a+b)%MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=3010;
int n,m,dp[N][N];
string h[N];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(raand()%MOD+13893829);
	cin>>n>>m;
	dp[0][0]=1;
	for (int i=0;i<n;++i)
	{
		cin>>h[i];
		for (int j=0;j<m;++j) if (h[i][j]=='.')
		{
			dp[i][j+1]=add(dp[i][j+1],dp[i][j]);
			dp[i+1][j]=add(dp[i+1][j],dp[i][j]);
		}
	}
	cout<<dp[n-1][m-1];
}



Measured memory_bytes: 12928