akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,M=map(int, sys.stdin.readline().split())
al=[ [] for _ in range(N+1) ]   #隣接リスト
rev_al=[ [] for _ in range(N+1) ]   #戻りを調べる用の隣接リスト
edge=[] #辺の集合
for _ in range(M):
    a,b,c=map(int, sys.stdin.readline().split())
    al[a].append(b)
    rev_al[b].append(a) #逆向きにも辺を張る
    edge.append((a,b,c))


go=[0 for _ in range(N+1)]
back=[0 for _ in range(N+1)]

#頂点１からNに行くまでに使用する頂点を調べる
q=deque()
q.append(1) #スタート地点
go[1]=1

while q:
    fro=q.popleft()
    for to in al[fro]:
        if go[to]==0:
            go[to]=1
            q.append(to)


#頂点Nから1に戻る際に使用する頂点を調べる
q=deque()
q.append(N) #スタート地点
back[N]=1

while q:
    fro=q.popleft()
    for to in rev_al[fro]:
        if back[to]==0:
            back[to]=1
            q.append(to)


new_edge=[]     #有効な辺のみ抽出

for a,b,c in edge:
    if go[a]==1 and back[b]==1:
        new_edge.append((a,b,c))


#ベルマンフォード
dp=[ float("-inf") for _ in range(N+1) ]
dp[1]=0

for i in range(N):
    for fro,to,cost in new_edge:
        alt=dp[fro]+cost
        if dp[to]<alt:
            if i==N-1:
                print float("inf")
                quit()
            dp[to]=alt

print dp[N]

Measured memory_bytes: 34024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

bool solve(int h, int w){
    vector<string> v(h);
    for (auto &&i : v) {
        cin >> i;
    }
    int ok = 1;
    while(ok){
        ok = 0;
        for (char i = 'A'; i < 'Z'; ++i) {
            int maxy = 0, miny = h, maxx = 0, minx = w;
            for (int j = 0; j < h; ++j) {
                for (int k = 0; k < w; ++k) {
                    if(v[j][k] == i) {
                        maxy = max(maxy, j);
                        miny = min(miny, j);
                        maxx = max(maxx, k);
                        minx = min(minx, k);
                    }
                }
            }
            if(miny == h) continue;
            int filled = 1;
            for (int j = miny; j <= maxy; ++j) {
                for (int k = minx; k <= maxx; ++k) {
                    if(v[j][k] != i && v[j][k] != '?') filled = 0;
                }
            }
            if(filled){
                ok = 1;
                for (int j = miny; j <= maxy; ++j) {
                    for (int k = minx; k <= maxx; ++k) {
                        v[j][k] = '?';
                    }
                }
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(isalpha(v[i][j])) return false;
        }
    }
    return true;
}

int main() {
    int q; cin >> q;
    while(q--){
        int h, w;
        cin >> h >> w;
        puts(solve(h, w) ? "SAFE" : "SUSPICIOUS");
    }
    return 0;
}


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

int main(){
    long long int a, b, k;
    cin >> a >> b >> k;

    if(a - k >= 0){
        a -= k;
    }else{
        k -= a;
        a = 0;
        b -= k;
        if(b < 0) b = 0;
    }


    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder170
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var rc = input.Split(" ").Select(int.Parse)
                .Select((d, idx) => new {d, idx = idx + 1})
                .Where(arg => arg.d == 0)
                .Select(arg => arg.idx)
                .First();


            Console.WriteLine(rc);
        }
    }
}


Measured memory_bytes: 28420
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
ll a[100000];
int main(){
	int n,ans=0;
	cin>>n;
	map<int,int>mp;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	for(auto p: mp){
		int x=p.first;
		int y=p.second;
      if (y < x) ans += y;
		else ans += y - x;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
  long long n,a[100010],b[100010],ans;
  
  cin >> n;
  ans=0;
  for (int i=0; i<n+1; i++) cin >> a[i];
  for (int i=0; i<n; i++){
    cin >> b[i];
    for (int d=0; d<=1; d++){
      if (a[i+d]<=b[i]){
        ans += a[i+d];
        b[i]-=a[i+d];
        a[i+d]=0;
      } else {
        ans += b[i];
        a[i+d] -= b[i];
        b[i]=0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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


Measured memory_bytes: 128
#include<string>
#include<stdio.h>
#include<utility>
#include<iostream>
using namespace std;
int main(){
  pair<string,int> p[110];
  int i,n,m,k=0,j,flag=0,ans=0;
  string x;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    cin >> x;
    for(j=0;j<k;j++){
      if(p[j].first==x){
        p[j].second++,flag++;
      }
    }
    if(flag==0){
      p[k].first=x,p[k].second=1;
      k++;
    }
    flag=0;
  }
  scanf("%d\n",&m);
  for(i=0;i<m;i++){
    cin >> x;
    for(j=0;j<k;j++){
      if(p[j].first==x){
        p[j].second--,flag++;
      }
    }
    if(flag==0){
      p[k].first=x,p[k].second=-1;
      k++;
    }
    flag=0;
  }
  for(i=0;i<k;i++){
    if(p[i].second > ans){
      ans=p[i].second;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const double eps = 1e-11;
const int inf = 1ll << 62;

signed main(){
	int n;cin>>n;
	int res=inf;
	rep(i,n){
		int a;cin>>a;
		int cnt=0;
		while(!(a&1)){
			a>>=1;cnt++;
			}
		res=min(res,cnt);	
		}
		cout<<res<<endl;
	}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	string s;

	cin >> s;

	while (s.length() >= 1)
	{

		string s1;

		for (int i = s.length() - 1; i >= 0; i--) {
			s1.insert(0, { s[i] });

			if (s1 == "dream" || s1 == "dreamer" || s1 == "erase" || s1 == "eraser") {
				s.erase(i);
				break;
			}

			if (i == 0) {
				cout << "NO" << endl;
				return 0;
			}
		}

	}

	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 640
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
A=list(map(int,input().split()))
if N==2:
    A.sort()
    print(A[1]-A[0])
    print(A[1],A[0])
else:
    plus= [i for i in A if i>=0]
    minus=[i for i in A if i<0]

    plus.sort(reverse=True)
    minus.sort()
    lst=[]
    if not minus:
        a=plus.pop()
        b=plus.pop()
        minus.append(a-b)
        lst.append([a,b])
    if not plus:
        a=minus.pop()
        b=minus.pop()
        plus.append(a-b)
        lst.append([a,b])

    while len(plus)>1:
        a=plus.pop()
        lst.append([minus[0],a])
        minus[0]-=a

    while len(minus)>1:
        a=minus.pop()
        lst.append([plus[0],a])
        plus[0]-=a

    print(plus[0]-minus[0])
    lst.append([plus[0],minus[0]])
    for a,b in lst:
        print(a,b)


Measured memory_bytes: 96392
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;
 
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()
 
ll n,k;
const ll mod=1e9+7;
const ll kmax=100005;
vll fac(kmax,0);

auto modpow(auto a,auto n){
 long long pow=1;
  while(n){
   if(n&1) pow=pow*a%mod;
   a=a*a%mod;
   n>>=1;    
}  
 return pow;
}


void solve(){
 cin >> n >> k;
 
  ll res=0;
  repr(i,k,1){
   fac[i]=modpow(k/i,n);
   for(ll j=2*i;j<=k;j+=i){
    fac[i]+=mod-fac[j];
    fac[i]%=mod; 
   }
    res+=fac[i]*i;
    res%=mod;
  }

  cout << res << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 3908
#include<iostream>
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
main()
{
	int n;
	while(cin>>n,n)
	{
		int d[10],v[10];
		for(int i=0;i<n;i++)cin>>d[i]>>v[i];
		int a[10];
		for(int i=0;i<n;i++)a[i]=1;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(i==j)continue;
				int now=d[j]*v[i]/gcd(d[j]*v[i],d[i]*v[j]);
				a[i]=lcm(a[i],now);
			}
		}
		for(int i=0;i<n;i++)cout<<a[i]<<endl;
	}
}



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

#define M 50010

int main() {
  bool p[M];
  int sqM = (int)sqrt(M), n;
  for(int i=0; i<M; ++i) p[i] = true;
  p[0] = p[1] = false;
  for(int i=2; i<sqM+1; ++i) {
    if(p[i]) for(int j=i*i; j<M; j+=i) p[j] = false;
  }
  while(cin >> n && n) {
    int ans = 0;
    for(int i=2; i<n/2+1; ++i) {
      if(p[i]&&p[n-i]) ++ans;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int A,B;
    cin >> A >> B;
    if(A<=B) cout << A << endl;
    else cout << A-1 << endl;
}

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, a[MAXN], b[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) cin >> a[i] >> b[i];
    FOR(i,0,999) {
        int p = i;
        vector<int> c;
        while (p) {
            c.push_back(p % 10);
            p /= 10;
        }
        if (i == 0) c.push_back(0);
        reverse(ALL(c));
        if (SZ(c) != n) continue;
        bool co = true;
        FOR(j,1,m) {
            int u = a[j]-1, v = b[j];
            if (c[u] != v) co = false;
        }
        if (co) {
            cout << i;
            return 0;   
        } 
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    if ((a + b) % 2 == 0) {
        printf("%d\n", (a + b) / 2);
    } else {
        printf("IMPOSSIBLE\n");
    } 
    
    return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

int r, c, n;
int f(int y, int x) {
	if (y == r)return r + c + c - x;
	if (y == 0)return x;
	if (x == c)return c + y;
	if (x == 0)return c + c + r + r - y;
	else return -1;
}



int main() {

	
	cin >> r >> c >> n;


	vector<pair<int, int>> v;

	VB used(100005, false);
	

	REP(i, n) {
		int a, b, d, e;
		cin >> a >> b >> d >> e;
		int x = f(a, b);
		int y = f(d, e);

		if (x == -1 || y == -1) continue;

		
		v.push_back({ x,i });
		v.push_back({ y,i });
	}
	sort(ALL(v));

	stack<int> q;

	REP(i, v.size()) {
		if (used[v[i].second]) {
			while (true) {
				if (q.empty()) {
					cout << "NO" << endl;
					return 0;
				}
				int a = q.top();
				q.pop();
				if (a == v[i].second)break;
			}
		}
		else {
			q.push(v[i].second);
			used[v[i].second] = true;
		}
	}

	cout << "YES" << endl;
}

Measured memory_bytes: 3448
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    long long s;
    std::cin >> s;

    if (s == 1e18) {
        std::cout << "0 0 1000000000 0 1000000000 1000000000" << std::endl;
        return 0;
    }

    long long a = s / (long long)1000000000, b = s % (long long)1000000000;

    std::cout << "0 0 1000000000 1 " << (long long)1000000000 - b << " " << a + (long long)1 << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;


struct mint {
    ll x;
    mint(ll x=0):x(x%mod){}

    mint& operator+=(const mint a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator-=(const mint a) {
        if((x -= mod-a.x) >= mod) x -= mod;
        return *this;
    }

    mint& operator*=(const mint a) {
        x = (x * a.x) % mod;
        return *this;
    }

    mint& operator/=(const mint a) {
        *this *= a.inv();
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    mint pow(ll n) const {
        mint a(*this);
        mint res = 1;
        while (n > 0) {
            if (n & 1) res *= a;
            a *= a;
            n >>= 1;
        }
        return res;
    }

    mint inv() const {
        return pow(mod - 2);
    }
};

const int MAX_V = 100005;
vector<int> G[MAX_V];
int n, k;
bool used[MAX_V];

mint dfs(int s, int k_) {
  used[s] = true;
  mint res = k_;
  k_ = k_ == k ? k-1: k-2;
  for(auto i: G[s]) {
    if (used[i]) continue; 
    res *= dfs(i, k_--);
  }
  return res;
}

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

  cin >> n >> k;

  rep(i, n-1){ 
    int a, b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  cout << dfs(0, k).x << endl;
}

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

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<=b){a=b;return 1;}return 0;}

int n;

int main(){
    cin >> n;
    vector<int> h(n);
    REP(i,n){
        cin >> h[i];
    }
    int res = 0;
    int m = 0;
    
    REP(i,n){
        if(chmax(m,h[i])){
            res++;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;

llint x,y;
void solve(){
	cin >> x;
	llint ans=0;
	llint a=x/500;
	a*=1000;
	llint b=x%500;
	b/=5;
	b*=5;
	ans=a+b;
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

int main() {
    // 標準ライブラリからstackを使用
    stack<int> S;
    int a, b, x;
    string s;

    while (cin >> s) {
        if (s[0]=='+') {
            // スタックの頂点の要素を取得し、削除
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b+a);
        }
        else if (s[0]=='-') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b-a);
        }
        else if (s[0]=='*') {
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b*a);            
        }
        else {
            S.push(atoi(s.c_str()));
        }
    }

    cout << S.top() << endl;

    return 0;
}


Measured memory_bytes: 3168
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxx=1e7+10;
int n,ans,vis[maxx],num;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n/2;i++){
		if(i!=n-i) ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
int main(){
	int a, b, c, n;
	cin >> a >> b >> c;
	a *= 100;
	b *= 10;
	n = a + b + c;
	if(n % 4 == 0)cout << "YES" << endl;
	else if(n % 4 != 0)cout << "NO" << endl;
	return 0;
 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
const int maxn=2e5+10;
int v[maxn*2];
struct number
{
    int id,v;
} a[maxn*2];
typedef long long LL;
bool cmpv(const number& A,const number& B)
{
    return A.v<B.v;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i].v,&a[i+n].v);
    for(int i=1;i<=n;i++)
    {
        a[i].id=i;
        a[i+n].id=i+n;
        if(a[i].v>a[i+n].v) swap(a[i].v,a[i+n].v);
    }
    for(int i=1;i<=n+n;i++) v[i]=a[i].v;
    int maxv=v[1],minv=v[1];
    for(int i=1;i<=n;i++)
    {
        maxv=max(maxv,v[i+n]);
        minv=min(minv,v[i]);
    }
    int maxl=v[1],minr=v[1+n];
    for(int i=1;i<=n;i++)
    {
        maxl=max(maxl,v[i]);
        minr=min(minr,v[i+n]);
    }
    LL ans=(1LL*(maxl-minv))*(maxv-minr);
    sort(a+1,a+n+n+1,cmpv);
    int cur=maxl;
    for(int i=1;i<=n+n;i++)
    {
        if(a[i].id>n) break;
        cur=max(cur,v[a[i].id+n]);
        ans=min(ans,(1LL*(maxv-minv))*(cur-a[i+1].v));
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 4992
n=gets.to_i
n.times{
	input=gets.chomp.split(" ")
	a=input[0].to_i
	b=input[1].to_i
	c=input[2].to_i
	if (a*a+b*b==c*c||b*b+c*c==a*a||c*c+a*a==b*b) then
		puts("YES")
	else
		puts("NO")
	end
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B,C,K; cin >>A>>B>>C>>K;
    if(K<=A){
        cout << K << endl;
    }else if(A<K && K<=A+B){
        cout << A << endl;
    }else if(A+B<K && K<=A+B+C){
        cout << 2*A-K+B << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
 
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    /////////////////////
    // Write code below /
    double D,T,S;
    cin >> D >> T >> S;
    if(D/S > T){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    /////////////////////
    return 0;
}

Measured memory_bytes: 3740
def main():
    N, k = (int(i) for i in input().split())
    h = []
    for _ in range(N):
        h.append(int(input()))
    h.sort()
    hdiffmin= 10**10
    for i in range(N - k + 1):
        diff = abs(h[i] - h[i+k-1])
        if diff < hdiffmin:
            hdiffmin = diff
    print(hdiffmin)


main()


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

public class Main {	
	private static void solve(){
		//Implement solution here.
		String S = next();
		int Q = ni();
		boolean reverse= false;
		Deque<Character> left = new ArrayDeque<>();
		Deque<Character> right = new ArrayDeque<>();
		for(int i = 0; i < Q; i++) {
			int T = ni();
			if(T == 1) {
				reverse = !reverse;
			} else {
				int F = ni();
				char c = next().charAt(0);
				if(F == 1) {
					if(!reverse) {
						left.add(c);
					} else {
						right.add(c); 
					}
				} else {
					if(!reverse) {
						right.add(c);
					} else {
						left.add(c); 
					}
				}
			}
		}
		
		if(!reverse) {
			while(!left.isEmpty()) System.out.print(left.pollLast());
			System.out.print(S);
			while(!right.isEmpty())System.out.print(right.pollFirst());
		} else {
			while(!right.isEmpty()) System.out.print(right.pollLast());
			for(int i = S.length() - 1; i >= 0; i--) System.out.print(S.charAt(i));
			while(!left.isEmpty())System.out.print(left.pollFirst());
		}

	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 58668
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int,int>;
const int INF = 1e18;
const int MOD = 1e9+7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

signed main(){
    int N,M;
    cin >> N >> M;
    vector<int> C(M);
    rep(i,M) cin >> C[i];

    sort(rall(C));

    int dp[50500];
    for(int i=0;i<=N;i++) dp[i] = INF;
    dp[0] = 0;

    for(int i=0;i<=N;i++){
        for(int j=0;j<M;j++){
            if(i - C[j] < 0) continue;
            dp[i] = min(dp[i],dp[i-C[j]]+1);
        }
    }

    put(dp[N]);

}



Measured memory_bytes: 3484
from pprint import pprint
from collections import deque, defaultdict


def solve(n, q, edges, p):
    counter = defaultdict(int)

    parents = deque()
    parents.append(0)
    while parents:
        parent = parents.popleft()
        counter[parent] += p[parent]
        # print("parent")
        # print(parent, counter[parent])
        if parent in edges:
            for child in edges[parent]:
                if counter[child] != 0:
                    continue
                counter[child] = counter[parent]
                # print("child")
                # print(child, counter[child])
                parents.append(child)

    print(" ".join(list(map(str, counter.values()))))

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    edges = defaultdict(list)
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        edges[a_i-1].append(b_i-1)

    p = [0] * n
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p[p_i-1] += x_i

    solve(n, q, edges, p)

Measured memory_bytes: 127704
// https://atcoder.jp/contests/agc037/tasks/agc037_a
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s;
  cin >> s;
  a = s.size();
  string t = "", cur = "";
  rep(i, 0, a)
  {
    cur += s[i];
    if (cur != t)
    {
      t = cur;
      cur = "";
      count++;
    }
  }
  cout << count << endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

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

  int n;
  cin >> n;

  vector<int> a(n+5), b(n+1);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];

  i64 ans = 0;
  rep(i, n) {
    i64 x = min(b[i], a[i]);
    ans += x;
    b[i] -= x;
    a[i] -= x;

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

  cout << ans << "\n";

  return 0;
}

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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j,k;
        ll red,green,blue;
        cin >>  red >> green >> blue;
        // ll arr[n];

        ll sum;
        cin >> sum;
        ll flag = 0;
        for(i=0;i<=sum;i++)
        {
            for(j=0;j<=sum;j++)
            {
                for(k=0;k<=sum;k++)
                {
                    ll ops = i + j + k;
                    if(ops <= sum)
                    {
                        ll nr = red,ng = green,nb = blue;
                        if(i > 0)
                        {
                            nr = nr * pow(2,i);
                        }

                        if(j > 0)
                        {
                            ng = ng * pow(2,j);
                        }

                        if(k > 0)
                        {
                            nb = nb * pow(2,k);
                        }

                        if(nb > ng && ng > nr)
                        {
                            flag = 1;
                        }
                    }
                }
            }
        }

        if(flag == 1)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 4092
import sys
input = sys.stdin.readline
S = list(input())[ :-1]
T = S[: : -1]
res = 0
for i in range(len(S)):
  if S[i] != T[i]:
    res += 1
    S[i] = T[i]
    T[-1 - i] = S[i]
  #print(S, T)
print(res)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

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

int main() {
    int n, x;
    cin >> n >> x;
    ll t[n];
    for (int i = 0, y; i < n; i++) {
        cin >> y;
        t[i] = abs(y - x);
    }
    ll ans = t[0];
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, t[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
t = []
for i in range(n):
    tmp = input().split()
    t.append(tuple(tmp))
tmp = sorted(t, key=lambda x: int(x[1]),reverse = True)
res = sorted(tmp, key=lambda x: x[0])
for sp in res:
    print(t.index(sp)+1)
    

Measured memory_bytes: 3060
import java.util.Scanner;
    public class Main{
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long num=in.nextLong();
            long tk=0;
            long pchso=num/500;
            tk=pchso*1000;
            int baki=(int) (num%500);
            long pach=baki/5;
            tk=tk+(pach*5);
            System.out.println(tk);
        }
    }

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	int t;
	while(cin>>t,t){
		cin>>n;
		rep(i,n){
			int a,b;
			cin>>a>>b;
			t-=b-a;
		}
		if(t<=0){
			cout<<"OK\n";

		}
		else cout<<t<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
typedef long long int ll;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    ll ans=1e12;
    for(ll k=1;k<=a;k++){
        ll c=(b*k+a-1)/a*a;
        if(c/a<c/b+c%b){
            ans=min(ans,c);
            break;
        }
    }
    if(ans==1e12){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 3212
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B) {
  cout << 6-A-B << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
const ll INF=1e17;
using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  ll a,b,q,x,y;
  cin>>a>>b>>q;
  // vector<ll> s,t;
  // map<ll,ll> m;
  // rep(i,0,a) {cin>>y; if(m.find(y)==m.end()) s.pb(y),m[y]=1;}
  // m.clear();
  // rep(i,0,b) {cin>>y; if(m.find(y)==m.end())t.pb(y),m[y]=1;}

  vector<ll> s(a),t(b);
  rep(i,0,a) cin>>s[i];
  rep(i,0,b) cin>>t[i];
  
  sort(all(s));
  sort(all(t));

  rep(i,0,q){
    cin>>x;
    ll ans=INF;
    ll si,tj,tj1,idx= lower_bound(all(t),x)-t.begin();

    if(idx==t.size()) tj1=INF;
    else tj1=t[idx];
    if(idx==0) tj=-INF;
    else tj=t[idx-1];
    // cout<<tj<<" "<<tj1<<endl;

    ll idx1=lower_bound(all(s),x)-s.begin(),idx2=lower_bound(all(s),x)-s.begin();
    if(idx1==s.size()) si=s[idx1-1];
    else si=s[idx1];

    if(si>=tj1) ans=min(ans,si-x);
    else if(x<=si) ans=min(ans,tj1-x),ans=min(ans,min(abs(x-tj),abs(x-si))+abs(si-tj));
    else if(si>=tj )ans=min(ans,min(abs(x-si),abs(x-tj1))+abs(si-tj1)),ans=min(ans,min(abs(x-tj),abs(x-si))+abs(si-tj));
    else ans=min(ans,abs(x-si));

      // cout<<si<<"...."<<ans<<endl;

    if(idx2==s.size()) si=s[idx2-1];
    else if(idx2>=1 )si=s[idx2-1];
    else si=s[idx2];

    if(si>=tj1) ans=min(ans,si-x);
    else if(x<=si) ans=min(ans,tj1-x),ans=min(ans,min(abs(x-tj),abs(x-si))+abs(si-tj));
    else if(si>=tj )ans=min(ans,min(abs(x-si),abs(x-tj1))+abs(si-tj1)),ans=min(ans,min(abs(x-tj),abs(x-si))+abs(si-tj));
    else ans=min(ans,abs(x-si));


    // cout<<si<<"...."<<ans<<endl;
    cout<<ans<<endl;
  }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 4792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
using ll = long long;

int main() {
  ll n,k;
  cin >> n >> k;
  ll h[10000000];
  ll dp[10000000];
  ll x = 1000000000000;
  
  REP(i,n){
    cin >> h[i];
  }
  REP(i,k+1){
    dp[i] = abs(h[0] - h[i]);
  }
  for (int i = k; i < (n); i++){
    
    REPS((j),1,k+1){
            if(x>abs(h[i]-h[i-j])+dp[i-j])
            {
                x=abs(h[i]-h[i-j])+dp[i-j];
            }        
    }
    dp[i] = x;
    x = 1000000000000;
  }
  
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 5072
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N, A, B, C;
    cin >> N >> A >> B >> C;

    cout << N - (A + B - C) << endl;

}












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

int main(){
    double n,t,a,ans;
    cin >> n >> t >> a;
    vector<int> h;
    int b;
    for(int i=0; i<n; i++){
        cin >> b;
        h.push_back(b);
    }
    
    double mint = 500;

    for(int i = 0; i < n; i++){
        if((max(a,(t-h[i]*0.006)) - min(a,(t-h[i]*0.006))) < mint){
            ans = i;
            mint = (max(a,(t-h[i]*0.006)) - min(a,(t-h[i]*0.006)));
        }
    }
    cout << ans + 1 << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

struct Edge{
  int to;
  long long cost;
};

struct NODE{
  int pos;
  long long cost;
};
bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
vector<Edge> g[100000],rg[100000];
const int MAX_V = 105;
//inf??§?????????
vector<vector<ll>> cost;
ll mincost[MAX_V];
bool used[MAX_V];
ll V,path;
ll prim(){
  ll res = 0;
  path = 0;
  for(ll i = 0; i < V; ++i){
    mincost[i] = inf;
    used[i] = false;
  }
  priority_queue<NODE> q;
  q.push({0,0});
  while(q.size()){
    auto v = q.top();q.pop();
    if(mincost[v.pos] == inf){
      mincost[v.pos] = v.cost;
      res += v.cost;
      if(v.cost)
        path += v.cost/100 - 1;
      for(auto n : g[v.pos]){
        q.push({n.to,n.cost});
      }
    }
  }
  while(q.size()){
    q.pop();
  }
  rep(i,V){
    g[i].clear();
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n && n){
    V = n;
    cin >> m;
    int a,b,c;
    char d;
    rep(i,m){
      cin >> a >> d >> b >> d >> c;
      g[a].push_back({b,c});
      g[b].push_back({a,c});
    }
    ll ans = prim();
    cout << ans/100-n+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 8080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int N = 1005;
int a[N],b[N*N];
bool judge(int n)
{
    int tmp = n % 10;
    n /= 10;
    while(n > 0)
    {
        if(n % 10 != tmp-1)
            return false;
        tmp = n % 10;
        n /= 10;
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    int num = 0;
    for(int i = 1;i <= n-1;i++)
        for(int j = i+1;j <= n;j++)
            b[num++] = a[i]*a[j];

    sort(b,b+num);
    int nu = unique(b,b+num)-b;
    for(int i = nu-1;i >= 0;i--)
    {
        if(judge(b[i]))
            return 0*printf("%d\n",b[i]);
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 5176
import numpy as np
x,n =map(int,input().split())

if  n==0:
 print(x)
else:
 P =list(map(int,input().split()))
 for i in range(100):
  if  (x-i) not in P:
   print(x-i)
   break
  elif (x+i) not in P:
   print(x+i)
   break

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

int s_index[100];
int t_index[100];

int main()
{
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) ++s_index[s[i] - 'a'];
    for(int i = 0; i < t.size(); ++i) ++t_index[t[i] - 'a'];
    string sd, td;
    for(int i = 0; i < 100; ++i) 
        for(int j = 0; j < s_index[i]; ++j) sd.push_back((char)i + 'a');
    for(int i = 99; i >= 0; --i)
        for(int j = 0; j < t_index[i]; ++j) td.push_back((char)i + 'a');
    if(sd < td) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
a=0
for i in range(n):
    A=list(map(int,input().split()))
    x=0
    for j in range(m):
        x+=A[j]*B[j]
    if x+c>0:
        a+=1
print(a)


Measured memory_bytes: 3060
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def dfs(v, graph, cur=0):
        color[v] = cur
        for u in graph[v]:
            if color[u] != -1:
                if color[u] == cur:
                    return False
                continue
            if not dfs(u, graph, 1 - cur):
                return False
        return True

    n = int(input())
    S = [list(input()) for _ in range(n)]
    edge = [[] for _ in range(n)]
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if i == j:
                cost[i][j] = 0
            if S[i][j] == "1":
                edge[i].append(j)
                cost[i][j] = 1

    color = [-1] * n
    if not dfs(0, edge):
        print(-1)
        exit()

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = 0
    for i in range(n):
        res = max(res, max(cost[i]))
    print(res + 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 71236
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


n,k=map(int,input().split())
l=list(map(int,input().split()))
for li in l:
    count+=li
    if count<=k:
        ans+=1
print(ans+1)

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] val = new int[n];
            for(int i = 0; i < n; ++i)
            {
                val[i] = int.Parse(str[i]);
            }
            if (val.Max() < (val.Sum() - val.Max()))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int N, K, Q, A;
	cin >> N >> K >> Q;
	vector<int> num;
	vector<int> vec(N, K);
	for (int i = 0; i < Q; ++i)
	{
		cin >> A;
		vec[A-1]++;
	}
	for (int i = 0; i < N; ++i)
	{
		if (vec[i]>Q ) 
			cout << "Yes" << endl;
		else 
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import sys
import numpy as np

readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]

n, m = readIntN()
ps = [readIntN() for _ in range(n)]

ret = 0
for i in range(8):
    a = -1 if (i & 4) else 1
    b = -1 if (i & 2) else 1
    c = -1 if (i & 1) else 1
    ret = max(ret, sum(sorted([a * p0 + b * p1 + c * p2 for p0, p1, p2 in ps], reverse=True)[:m]))
print(ret)

Measured memory_bytes: 12444