akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
int h,w,cont;
char map[55][55];
int d[55][55];
int x[4]={1,0,-1,0},y[4]={0,1,0,-1};
void dfs(int a,int b,int pr)
{
	for(int i=0;i<=3;i++)
	{
		int nx=a+x[i],ny=b+y[i];
		if(map[nx][ny]=='#')continue;
		if(d[nx][ny]<=pr+1)continue;
		//printf("%d %d %d\n",nx,ny,pr+1);
		d[nx][ny]=pr+1;
		dfs(nx,ny,pr+1);
	}
}
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			d[i][j]=INT_MAX;
	for(int i=1;i<=h;i++)
	{
		scanf("%s",map[i]+1);
		for(int j=1;j<=w;j++)
			if(map[i][j]=='#')cont++;
	}
	d[1][1]=1;
	dfs(1,1,1);
	if(d[h][w]==INT_MAX)printf("-1\n");
	else printf("%d",h*w-d[h][w]-cont);
}

Measured memory_bytes: 384
import math

def resolve():
    
    N=int(input())
    A=list(map(int,input().split()))

    # dp=[1]*202020
    # for i in range(K):
    #     dp[K]*=A[i]

    List = [[0 for j in range(N)] for i in range(N)]

    for i in range(N):
        for j in range(i,N):
            List[i][j]=A[j]-A[i]

    buy=False
    Kabu=0
    Yen=1000
    for i in range(N):
        isUp=True
        UpCnt=0
        DownStart=0
        for j in range(i+1,N):
            if(A[j]>A[i]):
                UpCnt+=1
            else:
                if(UpCnt==0):
                    DownStart=j
                    isUp=False
                    break
        if(i+1==N):
            isUp=False
        if(isUp and i!=DownStart-1):
            if(buy==False):
                buy=True
                Kabu+=Yen//A[i]
                Yen-=A[i]*(Yen//A[i])
            # else:
            #     buy=False
            #     Yen+=A[i]*Kabu
            #     Kabu=0

        else:
            if(buy):
                buy=False
                Yen+=A[i]*Kabu
                Kabu=0




    print(Yen)

resolve()


Measured memory_bytes: 9248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<char> c(n);
  bool flag = false;
  REP(i, n) {
    cin >> c.at(i);
    if (i >= 1) {
      if (c[i - 1] == 'W' && c[i] == 'R') flag = true;
    }
  }
  if (!flag) {
    cout << 0 << endl;
    return;
  }
  // operation
  vector<int> w(n), r(n);
  REP(i, n) {
    if (c[i] == 'W') {
      w[i] = 1;
    }
    if (c[n - i - 1] == 'R') {
      r[n - i - 1] = 1;
    }
  }
  REP(i, n) {
    if (i >= 1) w[i] += w[i - 1];
    if (i <= n - 2) r[n - i - 2] += r[n - i - 1];
  }
  int ans = INF;
  REP(i, n) {
    if (w[i] == r[i]) {
      ans = min(ans, w[i]);
    }
    if (i >= 1) {
      if (w[i - 1] == r[i] && w[i] == r[i - 1] && (w[i] - r[i]) == 1) {
        ans = min(ans, r[i]);
      }
    }
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 5000
#include<stdio.h>
int main(void){
    int i,n;
    double x[4],y[4],ab,cd;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]);
        ab=(y[0]-y[1])/(x[0]-x[1]);
        cd=(y[2]-y[3])/(x[2]-x[3]);
        if(ab==cd){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    int sum=0;
    for(int i=1;i<=x;i++){
        sum+=i;
        if(sum>=x){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
A_list1 = list(map(int, input().split()))
A_list2 = list(map(int, input().split()))
A_list3 = list(map(int, input().split()))
N = int(input())
B_list = []
for i in range(N):
    B_list.append(int(input()))

A_list1_c = []
A_list2_c = []
A_list3_c = []
for i in B_list:
    if i in A_list1:
        A_list1_c.append(A_list1.index(i))
    if i in A_list2:
        A_list2_c.append(A_list2.index(i))
    if i in A_list3:
        A_list3_c.append(A_list3.index(i))

for i in A_list1_c:
    if i in A_list2_c and i in A_list3_c:
        print("Yes")
        exit()
    if i == 0:
        if 1 in A_list2_c:
            if 2 in A_list3_c:
                print("Yes")
                exit()
    if i == 2:
        if 1 in A_list2_c:
            if 0 in A_list3_c:
                print("Yes")
                exit()
if len(A_list1_c) == 3 or len(A_list2_c) == 3 or len(A_list3_c) == 3:
    print("Yes")
    exit()

print("No")


Measured memory_bytes: 3064
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 200111;
int n;
vector<int> con[maxn];
pair<int,int> mx;
void dfs(int x, int pre, int l)
{
	mx = max(mx, MP(l, x));
	for (auto u : con[x])
	{
		if (u==pre) continue;
		dfs(u, x, l+1);
	}
}
int main()
{
	geti(n);
	for (int i=1; i<n; i++)
	{
		int x, y;
		getii(x, y);
		con[x].PB(y);
		con[y].PB(x);
	}
	dfs(1, 0, 0);
	int x = mx.SS;
	mx = MP(0, 0);
	dfs(x, 0, 0);
	if (mx.FF%3==1) puts("Second");
	else puts("First");
	return 0;
}


Measured memory_bytes: 20608
n=int(input())
p = list(map(float,input().split()))
dp = [[0 for _ in range(n+1)] for __ in range(n+1)]
dp[0][0] = 1
for i in range(n+1):
    for j in range(n+1):
        cnt = i + j
        if cnt == 0 or cnt > n:
            continue
        if j == 0:
            dp[i][j] = dp[i-1][0] * p[cnt-1]
        elif i == 0:
            dp[i][j] = dp[i][j-1] * (1 - p[cnt-1])
        else:
            dp[i][j] = dp[i-1][j]*p[cnt-1] + dp[i][j-1]*(1-p[cnt-1])
        
ans = 0
for i in range((n+1)//2, n+1):
    ans += dp[i][n-i]
print(ans)

Measured memory_bytes: 257672
import java.util.Scanner;
public class Main {
	public static int div2(int a) {
		int div2 = 0;
		if(a != 0) {
			while(a % 2 == 0) {
				div2 += 1;
				a /= 2;
			}
		}
		return div2;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		for(int i = 0; i < N; i++) {
			ans += div2(sc.nextInt());
		}
		System.out.println(ans);	

	}

}

Measured memory_bytes: 34392
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

signed main() {
  int N, D, A;
  cin >> N >> D >> A;

  vector<pair<int, int>> vec(N);
  REP(i, N) cin >> vec[i].first >> vec[i].second;

  sort(ALL(vec));

  vector<int> h(N+1, 0);
  int ans = 0, j = 0;
  REP(i, N){
    if(i != 0) h[i] += h[i-1];
    int cnt = (max(vec[i].second-h[i], 0ll)+A-1)/A;
    while(j != N && vec[j].first <= vec[i].first+2*D) j++;
    h[i] += cnt*A;
    h[j] -= cnt*A;

    ans += cnt;
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    int i,K;
    scanf("%d",&K);
    char S[100];
    scanf("%s",S);
    int length = strlen(S);
    
    if(length <= K){
        printf("%s\n",S);
    }else{
        for(i=0;i<K;i++) printf("%c",S[i]);
        printf("...\n");
    }
    return 0;
}

Measured memory_bytes: 1644
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = [-1]*(2*(10**5)+1)
prevIdx = [0] * N
for i in range(N):
    C[i] = int(input())
    if i > 0 and C[i] == C[i-1]:
        continue
    prevIdx[i] = dic[C[i]]
    dic[C[i]] = i

dp = [0] * N
dp[0] = 1
acc = [0] * N
acc[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1] or prevIdx[i] == -1:
        acc[i] = dp[i-1]
        continue
    
    dp[i] += acc[prevIdx[i]]
    acc[i] = acc[prevIdx[i]] + dp[i-1]
    acc[i] %= mod
    dp[i] %= mod

print(dp[N-1] % mod)

Measured memory_bytes: 52824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll M;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(all(A));
  vector<ll> sum(N+1);
  rep(i, N) sum[i+1] = sum[i] + A[i];

  if(M == N*N) {
    cout << sum[N] * 2 * N << endl;
    return 0;
  }

  ll val = 0;
  map<ll, int> mp;
  ll cnt = 0;
  auto test = [&](ll t) {
    cnt = 0;
    mp = map<ll, int>();
    val = 0;
    rep(i, N) {
      auto j = lower_bound(all(A), t-A[i]) - begin(A);
      if(j != 0) {
        if(i < j-1) mp[A[i]+A[j-1]] += 2;
        else if(i == j-1) mp[A[i]+A[j-1]]++;
      }
      val += (sum[N]-sum[j]) + A[i] * (N-j);
      cnt += (N-j);
    }
    return cnt <= M;
  };
  auto binary_search = [&]() {
    ll ng = 0, ok = 200005;
    while(abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      if(test(mid)) ok = mid;
      else ng = mid;
    }
    return ok;
  };
  ll mx = binary_search();
  test(mx);
  cout << val+(M-cnt)*(mp.size() != 0 ? (--mp.end())->first : 0) << endl;
  return 0;
}


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

int main()
{
    int A, B;
    cin >> A >> B;
    if ((A + B) % 3 == 0 || A % 3 == 0 || B % 3 == 0)
    {
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
a = [[], [], []]
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if b == a[j][k]:
                a[j][k] = 0
flag = False
for i in range(3):
    if sum(a[i]) == 0 or a[0][i] + a[1][i] + a[2][i] == 0:
        flag = True
if a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0:
    flag = True
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),M=in();
	map<int,int> C;
	REP(i,M){
		C[in()]++;
		C[in()]++;
	}
	
	for(auto& x:C){
		if(x.second%2){
			out("NO");
			return 0;
		}
	}

	out("YES");
	return 0;
}


Measured memory_bytes: 4352
#include <stdio.h>

#define MAX_NUMBER	( 9 )

int main( void )
{
	int a;
	int b;
	int c;
	int d;
	
	int n;
	
	int numOfPattern;
	
	while( scanf( "%d", &n ) != EOF )
	{
		numOfPattern = 0;
		for( a = 0; a <= MAX_NUMBER; a++ )
		{
			for( b = 0; b <= MAX_NUMBER; b++ )
			{
				for( c = 0; c <= MAX_NUMBER; c++ )
				{
					for( d = 0; d <= MAX_NUMBER; d++ )
					{
						if( a + b + c + d == n )
						{
							numOfPattern++;
						}
					}
				}
			}
		}
		printf( "%d\n", numOfPattern );
	}
	
	return (0);
}

Measured memory_bytes: 596
n, x, y = map(int, input().split())

edges = [[] for _ in range(n)]
for i in range(n-1):
   edges[i].append(i+1)
   edges[i+1].append(i)

edges[x-1].append(y-1)
edges[y-1].append(x-1)

def bfs(v):
   dist = [-1] * n
   dist[v] = 0
   visit = [v]
   c = 1
   while visit:
      next = []
      for i in visit:
         for j in edges[i]:
            if dist[j] == -1:
               dist[j] = c
               next.append(j)
      visit = next
      c += 1

   return dist

minpath = []
for i in range(n):
   minpath.extend(bfs(i))

from collections import Counter
cnt = Counter(minpath)

for k in range(1, n):
   print(cnt[k]//2)


Measured memory_bytes: 114660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    ll K, cnt=0;; cin >> K;
    queue<ll> Q;
    for(int i = 1; i < 10; i++)Q.push(i);
    while(1){
        ll x = Q.front(); Q.pop(); cnt++;
        //cout << x << endl;
        if(cnt==K){cout << x << endl; return 0;}
        if(x%10!=0)Q.push(10*x+x%10-1);
        Q.push(10*x+x%10);
        if(x%10!=9)Q.push(10*x+x%10+1);
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
	#define hell                         1000000007 
	#define M                            1000000007
	#define Maxi                      10000000000000000
	#define lcm(a,b)                     (a*b)/__gcd(a,b)
	#define ll                           long long

	#define vll                          vector<ll>
	#define vi                           vector<long long>
	#define pll                          vector< pair<ll,ll> >
	#define pb                           push_back
	//#define mp                           make_pair
	#define all(v)                       v.begin(),v.end()
	#define lbnd                         lower_bound
	#define ubnd                         upper_bound
	#define bs                           binary_search
	#define F                            first
	#define S                            second
	#define rep(i,a,b)                   for(i=a;i<b;i++)
	#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
	#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
	#define ret(x)                       return cout<<x,0;
	#define dbg(x)                       cout << #x << " is " << x << endl;
	//#define endl                           '\n'


	// Debug //

	#define trace(x)                 cerr << #x << ": " << x << endl;
	#define trace1(x)                cerr << #x << ": " << x << endl;
	#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
	#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
	#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
	#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
	#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;


	using namespace std;

	int main()
	{

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

	
	ll n;
	cin>>n;
	ll a[n];
	ll i,j;

	map<ll,ll>m1;
	rep(i,0,n)
	{
		cin>>a[i];
		m1[a[i]]=i;
	}
	set<ll>st;
	ll ans=0;
	for(i=n;i>=1;i--)
	{
		if(st.size()!=0)
		{
			j=m1[i];
			ll x1,x2,x3,x4;
			x1=-1;x2=-1;x3=n;x4=n;

			auto temp=st.lower_bound(j);

			if(temp!=st.begin())
			{
				temp--;
				{
					x1=*(temp);
					//x2=x1;
				}

				if(temp!=st.begin())
				{
					temp--;
					x2=*(temp);
				}
				
			}
			auto temp2=st.lower_bound(j);
			if(temp2!=st.end())
			{
				x3=*(temp2);
				//x4=*(temp2);
				temp2++;

				if(temp2!=st.end())
				{
					x4=*(temp2);
				}
			}
			//cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl;
			ans+=i*((x1-x2)*(x3-j)+(j-x1)*(x4-x3));

		}

		st.insert(m1[i]);
	}

	cout<<ans<<endl;


		
		
		

		return 0;
		}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a, b, e;
	int c, d;
	cin>>a>>b>>c>>d>>e;
	if (e == a) c--;
	else d--;
	cout<<c<<' '<<d<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500001

int A[MAX];
int n;

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i+1;
}

void maxHeapify(int *A, int i){

    int l,r;
    int largest;

    l = left(i);
    r = right(i);

    if( l <= n && A[l] > A[i] ){
        largest = l;
    }else{
        largest = i;
    }

    if( r <= n && A[r] > A[largest] ){
        largest = r;
    }

    if( largest != i ){

        int temp = A[i];
        A[i] = A[largest];
        A[largest] = temp;
        maxHeapify(A,largest);
    }

}

void buildMaxHeap(int *A){
    
    int i;

    for( i = n/2 ; i > 0 ; i-- ){
        maxHeapify(A,i);
    }

}

int main(){

    int i;

    scanf("%d",&n);

    for( i = 1 ; i <= n ; i++ ){
        scanf("%d",&A[i]);
    }

    buildMaxHeap(A);

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

    printf("\n");

    return 0;
}

Measured memory_bytes: 2552
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstring>
using namespace std;
char s[200100];
char t[200100];
char sc[26]={0};
bool bj[26]={0};
int main()
{
	scanf("%s", s);
	scanf("%s", t);
	int l,i,j;
	l = strlen(s);
	for(i=0;i<26;i++)
		sc[i] = 'a'+i; 
	for(i=0;i<l;i++)
	{
		if(sc[s[i]-'a'] == t[i])
			bj[t[i]-'a'] = 1;
		else
		{
			if(bj[t[i]-'a']==1 || bj[sc[s[i]-'a']-'a']==1)
				break;
			int w;
			for(j=0;j<26;j++)
			{
				if(sc[j] == t[i])
				{
					w = j;
					break;
				}
			}
			
			sc[w] = sc[s[i]-'a'];
			sc[s[i]-'a'] = t[i];
			
			bj[t[i]-'a'] = 1;
		}
	}
	if(i < l)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long n,k,a[200005],dp[200005][100];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		dp[i][0]=a[i];
	for(int i=0;i<=70;i++)
	{
		for(int j=1;j<=n;j++)
			dp[j][i+1]=dp[dp[j][i]][i];
	}
	long long p=k,t=0,res=1;
	while(p)
	{
		if(p%2)
			res=dp[res][t];
		t++;
		p/=2;
	}
	cout<<res;

	return 0; 
}

Measured memory_bytes: 161436
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
int main() {
	int n;
	long long int B,ans=0;
	int A[200000];
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		A[i]= A[i] - i - 1;
	}

	sort(A, A + n);

	if (n % 2 == 0) {
		B = (A[n / 2 - 1] + A[n / 2])/2;
	}
	else if (n % 2 == 1) {
		B = A[n / 2];
	}
	rep(i, n) {
		ans += abs(A[i] - B);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>s(n);
	for(int i = 0; i < n; i++) cin >> s[i];
	
	int q;
	cin >> q;
	int answer = 0;
	for(int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if(s[lower_bound(s.begin(), s.end(), t) - s.begin()] == t) answer++;
	}
	
	cout << answer << endl;
	return 0;
}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a;
	map<int, int> mp;
	REP(i, 3)
	{
		cin >> a;
		mp[a]++;
	}
	print(SIZE(mp));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int N,K; cin >>N >>K;
  vector<bool> kirai(10);
  rep(i,0,K) {
    int D; cin >>D;
    kirai[D]=true;
  }
  while (true) {
    string check_val=to_string(N);
    bool flag=true;
    rep(i,0,10) {
      int result=check_val.find(to_string(i));
      if (kirai[i]==true && result!=-1) {flag=false; break;}
    }
    if (flag) break;
    N++;
  }
  cout <<N <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  cin >> n;
  cout << (n - 1) / 2 << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int tmp,min=1000,max=-1;
	for (int i=0;i<5;i++){
		cin>>tmp;
		min=(min>tmp)?tmp:min;
		max=(max>tmp)?max:tmp;
	}
	int k;
	cin>>k;
	if(k<(max-min))cout<<":("<<endl;
	else cout<<"Yay!"<<endl;
	return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll d, g;
    cin >> d >> g;
    ll p[d], c[d];
    rep(i, d) { cin >> p[i] >> c[i]; }

    bool all[d];
    ll ans = mod;
    rep(i, 1 << d) {
        ll cost = 0;
        ll point = 0;
        rep(j, d) { all[j] = i & (1 << j); }
        rep(j, d) {
            if (all[j]) {
                cost += p[j];
                point += 100 * (j + 1) * p[j] + c[j];
            }
        }
        if (point < g) {
            ll index = -1;
            rep(j, d) {
                if (!all[j]) {
                    index = j;
                }
            }
            ll diff = g - point;
            ll one = 100 * (index + 1);
            ll num = (diff + one - 1) / one;
            if (num >= p[index]) {
                cost = mod;
            } else {
                cost += num;
            }
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include"string"
#include"math.h"
#include <algorithm>
#include<vector>
using namespace std;
bool m;
void m_sort(int a[], int tmp[], int left, int right);
void m_sort(int a[], int tmp[], int left, int right);
void sort(int a[], int total) {
	int tmp;
	for (int i = 0; i < total; i++) {
		for (int j = i + 1; j < total; j++) {
			if (a[i] < a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
 
}
 
void mergeSort(int a[], int tmp[], int size)
{
	m_sort(a, tmp, 0, size - 1);
}
void merge(int a[], int tmp[], int left, int mid, int right)
{
	int i, left_end, num_elements, tmp_pos;
 
	left_end = mid - 1;
	tmp_pos = left;
	num_elements = right - left + 1; // 要素 
 
	while ((left <= left_end) && (mid <= right))
	{
		if (a[left] <= a[mid])
		{
			tmp[tmp_pos] = a[left];
			tmp_pos = tmp_pos + 1;
			left = left + 1;
		}
		else
		{
			tmp[tmp_pos] = a[mid];
			tmp_pos = tmp_pos + 1;
			mid = mid + 1;
		}
	}
 
 
	while (left <= left_end)
	{
		tmp[tmp_pos] = a[left];
		left = left + 1;
		tmp_pos = tmp_pos + 1;
	}
 
	while (mid <= right)
	{
		tmp[tmp_pos] = a[mid];
		mid = mid + 1;
		tmp_pos = tmp_pos + 1;
	}
 
 
	for (i = 0; i <= num_elements; i++)
	{
		a[right] = tmp[right];
		right = right - 1;
	}
}
void m_sort(int a[], int tmp[], int left, int right)
{
	int mid;
 
	if (right > left)
	{
		mid = (right + left) / 2; 
		m_sort(a, tmp, left, mid);
		m_sort(a, tmp, mid + 1, right);
 
		merge(a, tmp, left, mid + 1, right);
	}
}

int abs(int a){
	if(a<0)return -a;
	return a;
}

int N,x[100000],y[100000],t[100000],bx[100000],by[100000],bt[100000];
int ans,C[501],S[501],F[501],ti[501],blank;
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>t[i]>>x[i]>>y[i];
		if(i>0){
			bx[i]=abs(x[i]-x[i-1]);
			by[i]=abs(y[i]-y[i-1]);
			bt[i]=abs(t[i]-t[i-1]);
		}
	}
	bx[0]=x[0];
	by[0]=y[0];
	bt[0]=t[0];
	for(int i=0;i<N;i++){
		if(abs(bt[i]-bx[i]-by[i])%2!=0||bt[i]<bx[i]+by[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

const int N=100100;
string s;

int main(int argc, char *argv[])
{

  cin >> s;
  string p = s;
  std::reverse(p.begin(), p.end());
  int i=0;
  int length = s.size();
  while (s[i]!='\0'|| p[i]!='\0') {
    if(s[i]==p[i]){i++;continue;}
    else if(s[i]=='x'){p.insert(p.begin() + i, 'x');i++;}
    else if(p[i]=='x'){s.insert(s.begin() + i, 'x');i++;}
    else{printf("-1\n");return 0;}
  }
  printf("%d\n",s.size()-length);
  return 0;
}


Measured memory_bytes: 772
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, x, y = map(int, input().split())
ans = [0]*(n)

for i in range(1,n+1):
    for j in range(i+1,n+1):
        num = j-i
        num = min(num, abs(x-i)+abs(y-j)+1 )
        ans[num] += 1


print(*ans[1:], sep='\n')



Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll H,W; cin >> H >> W;
	vector<vector<char>>s(H+2,vector<char>(W+2,'#'));
	int cnt = 0;
	for(int i = 1; i <= H;i++)for(int j = 1; j <= W;j++){
			char c; cin >> c; s[i][j] = c;
			if(c=='#') cnt++;
	}
	int dx[4] = {0,1,0,-1},dy[4] = {1,0,-1,0};
	vector<vector<int>> dist(H+2,vector<int>(W+2,INF));
	dist[1][1] = 0;
	queue<pii> q; q.push({1,1});
	while(q.size()){
		auto p = q.front(); q.pop();
		int x = p.first,y = p.second;
		for(int k = 0; k < 4;k++){
			int nx = x + dx[k],ny = y + dy[k];
			if(s[nx][ny] =='#') continue;
			if(dist[nx][ny] > dist[x][y] + 1){
				dist[nx][ny] = dist[x][y] + 1;
				q.push({nx,ny});
			}
		}
	}
	if(dist[H][W] == INF) cout << -1 << endl;
	else cout << H*W - dist[H][W] - 1 - cnt << endl;
	return 0;
}

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

using namespace std;
const int maxn = 1E3 + 5;
int maze[maxn][maxn];
int pos[maxn];
int notOk[maxn];
int main()
{
    int n;
    cin >> n;
    for( int i = 1; i <= n; ++ i )
    {
        pos[i] = 1;
        for( int j = 1; j < n; ++ j )
            cin >> maze[i][j];
    }
    int ans = 0;
    int cmp = 0;
    while( cmp != n )
    {
        bool ok = 0;
        for( int i = 1; i <= n; ++ i )
        {
            if( pos[i] <= n - 1 )
            {
                int v = maze[i][pos[i]];
                if( maze[v][pos[v]] == i )
                {
                    //cout << ans << " " <<  i << " " << v << endl;
                    int t = max( notOk[i], notOk[v] ) + 1;
                    notOk[i] = notOk[v] = t;
                    pos[i] ++;
                    pos[v] ++;
                    if( pos[i] == n )
                    {
                        cmp ++;
                    }
                    if( pos[v] == n )
                    {
                        cmp ++;
                    }
                    ok = 1;
                }
            }
        }
        if( !ok )
        {
            cout << -1 << endl;
            return 0;
        }
    }
    for( int i = 1; i <= n; ++ i )
        ans = max( ans, notOk[i] );
    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	int one_submission = 1900 * m + (n - m) * 100;
	cout << one_submission * (1 << m) << "\n";

	return 0;

}

Measured memory_bytes: 256
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
ans = 0
for i in range(n):
    if a[i] <= b[i]:
        ans += a[i]
        leftover = b[i] - a[i]
        if a[i + 1] <= leftover:
            ans += a[i + 1]
            a[i + 1] = 0
        else:
            ans += leftover
            a[i + 1] = a[i + 1] - leftover
    elif a[i] > b[i]:
        ans += b[i]
print(ans)

Measured memory_bytes: 18696
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val r = sc.nextInt
    val d = sc.nextInt
    val x2000 = sc.nextInt


    val resl = (1 to 10).foldLeft((Seq.empty[Int], x2000) ){case ((seq, pre), k) =>
      val now = r * pre - d
      (seq :+ now, now)
    }._1
    resl.foreach(println)
  }
}


Measured memory_bytes: 25656
# include <iostream>
# include <string>
using namespace std;
string S, T;
int hit_day = 0;

int main() {
  cin >> S >> T;
  for (int i = 0; i < 3; i++) if (S[i] == T[i]) hit_day++;
  cout << hit_day << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll L = 0;
	ll P = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S[50],T[50],U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 1;
	ll dist1 = 0;
	ll dist2 = 0;
	ll now = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	
	
	
	cin >>temp;
	vector<int> tr(3);
	
	
	if(temp == 'a' || temp == 'i' || temp == 'u' || temp == 'e' || temp == 'o')
	cout << "vowel" << endl;
	else
		cout << "consonant" << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

Measured memory_bytes: 256
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
tempd = []
for hill in h:
  b = abs((t - hill*0.006)-a)
  tempd.append(b)
good = min(tempd)
ho = tempd.index(good)+1
print(ho)

Measured memory_bytes: 3064
s = input()
if s[:2] == "00" and s[2:] == "00":
  print("NA")
  exit()
elif s[:2] == "00" and int(s[2:]) > 12:
  print("NA")
  exit()
elif s[:2] == "00" and int(s[2:]) <= 12:
  print("YYMM")
  exit()
elif int(s[:2]) > 12 and s[2:] == "00":
  print("NA")
  exit()
elif int(s[:2]) <= 12 and s[2:] == "00":
  print("MMYY")
  exit()
if int(s[:2]) > 12 and int(s[2:]) > 12:
  print("NA")
  exit()
elif int(s[:2]) <= 12 and int(s[2:]) <= 12:
  print("AMBIGUOUS")
  exit()
elif int(s[:2]) <= 12:
  print("MMYY")
  exit()
elif int(s[2:]) <= 12:
  print("YYMM")
  exit()

Measured memory_bytes: 3064
n = gets.to_i
a = gets.split.map(&:to_i)

h = Hash.new(0)
sum = 0
a.each do |x|
  h[x] += 1
  sum += x
end


q = gets.to_i
q.times.each do
  b, c = gets.split.map(&:to_i)
  
  if h.key?(b)
    n = h[b]
    h.delete(b)
    h[c] += n

    sum += (c-b)*n
  end

  puts sum
end



Measured memory_bytes: 25732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    string s;
    cin >> s;
    int a=0,b=0;
    int ansa=0,ansz=0;
    bool j =false;
    for(int i=0;i<s.length();i++){
       if(s.at(i)=='A'){
           if(j==false){a=i;j=true;}
       } 
       if(s.at(i)=='Z'){
           if(i>=b)b=i;
       } 

    }
    cout << b-a+1 << endl;

    return 0;
}



Measured memory_bytes: 640
def solve():
 n = int(input())
 c = [int(input()) for _ in range(n)]
 mod = 10**9 +7
 dp = [1]*n
 dp[0] = 1
 place = [-1]*200001

 for i in range(n):    
    if place[c[i]-1] != -1:
      if place[c[i]-1] == i-1:
        dp[i] = dp[i-1]
      else:
        dp[i] = (dp[i-1]+dp[place[c[i]-1]])%mod
        
    else:
     dp[i] = dp[i-1]
    place[c[i]-1] = i
 #print(dp)
 #print(place)
 return dp[-1]%mod

print(solve())

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

#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define mod 1e9 + 7
#define inf 99999999999
#define neginf -9999999999
#define vi vector<int>
#define vchar vector<char>
#define vstr vector<string> 
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b,c,d,e;
    cin>>a>>b>>c;
    d=b-a;
    e=c-b;
    if(d==e){cout<<"YES";return 0;}
    cout<<"NO";
   
    return 0;
}






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

int main(){
  int ans=0,n;
  string s;cin>>s;
  n=s.size();
  REP(i,n) if(i%2!=s.at(i)-'0') ans++; 
  cout<<((ans>n-ans)?n-ans:ans);
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;
 
class Main {
	int n;
	int k;
	int[] l;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		k = sc.nextInt();
		l = new int[n];
		for(int i=0;i<n;i++){
			l[i] = sc.nextInt();
		}
	}
	void solve(){
		Arrays.sort(l);
		int sum = 0;
		for(int i=0;i<k;i++){
			sum += l[n-1-i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define l first
#define r second
#define int long long

using namespace std;

const int maxn = 1e6 + 1;

int a[maxn], cnt[maxn];
int ans = 0;

void add_ball(int i) {
    ans += cnt[a[i]];
    ++cnt[a[i]];
}

void del_ball(int i) {
    --cnt[a[i]];
    ans -= cnt[a[i]];
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++)
        add_ball(i);
    cout << ans << '\n';
    for (int i = 1; i < n; i++) {
        add_ball(i - 1);
        del_ball(i);
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#define MOD(x) (x + 1000000007) % (1000000007)

using namespace std;

template <class t>
using vec = vector<t>;
using ll = long long;

const int MAX = numeric_limits<int>::max();

template <class t>
ostream &operator<<(ostream &out, vec<t> &v)
{
    for (auto &e : v)
        out << e << " ";
    out << "\n";
    return out;
}

template <class t>
istream &operator>>(istream &in, vec<t> &v)
{
    for (auto &e : v)
        in >> e;
    return in;
}

int main()
{
    int n;
    cin >> n;
    vec<vec<int>> can(n, vec<int>(n));
    cin >> can;
    vec<ll> dp(1 << n);
    dp[0] = 1;
    for (ll mask = 0; mask < (1 << n); mask++)
    {
        for (int b = 0; b < n; b++)
        {
            if (!(mask & (1 << b)))
            {
                int a = __builtin_popcountll(mask | (1 << b));
                if (can[a - 1][b])
                    dp[mask | (1 << b)] = MOD(dp[mask | (1 << b)] + dp[mask]);
            }
        }
    }
    cout << dp[(1 << n) - 1];
    return 0;
}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	if((b-a)%2==0){
		cout << "Alice" << endl;
	}else{
		cout << "Borys" << endl;
	}
	return 0;
}

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

int W, H;
char b[20][20];
int ans;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void dfs(int x, int y) {
	ans++;
	b[y][x] = '#';
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx && nx < W && 0 <= ny && ny < H && b[ny][nx] == '.') {
			dfs(nx, ny);
		}
	}
}

int main() {
	while (cin >> W >> H , W) {
		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				cin >> b[y][x];
			}
		}

		ans = 0;

		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				if (b[y][x] == '@') {
					dfs(x, y);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1168
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int N;
    while (cin >> N) {
        int cnt2,cnt4; cnt2 = cnt4 = 0;
        FOR(_,0,N) {
            int a; cin >> a;
            if (a % 4 == 0)
                cnt4++;
            else if (a % 2 == 0)
                cnt2++;
        }
        N -= 2*cnt4;
        const string ans = (N == 1 || cnt2 >= N) ? "Yes" : "No";
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256