akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int main() {
	ll X;
	cin >> X;
	ll sum[100000];
	sum[0] = 0;
	for (int i = 1; i <= 100000; ++i) {
		sum[i] = sum[i - 1] + i;
	}
	for (int i = 1; i <= 100000; ++i) {
		if (X <= sum[i]) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
from collections import deque
n,q = map(int,input().split())
v = [0]*n
g = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
for _ in range(q):
    p,x = map(int,input().split())
    v[p-1] += x
que = deque([(0, -1)])
while que:
    now, pre = que.pop()
    for j in g[now]:
        if j==pre:
            continue
        else:
            v[j] += v[now]
            que.append((j, now))
print(*v)

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

#define task "C" //abc136
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit

// Struct

// Variables
int n,a[100005];
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i,1,n) cin >> a[i];
	Rep(i,n,2) if (a[i]<a[i-1]) a[i-1]--;
	rep(i,1,n-1) if (a[i]>a[i+1])
	{
	    cout << "No";
	    return 0;
	}
	cout << "Yes";
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
	"strconv"
)

func main() {
	// Code for B - Guidebook
	var N int
	fmt.Scanf("%d", &N)

	var S string
	var P int
	A := make([]string, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%s", &S)
		fmt.Scanf("%d", &P)
		A[i] = fmt.Sprintf("%s%03d%03d", S, 101-P, i+1)
	}
	sort.Sort(sort.StringSlice(A))

	for i := 0; i < N; i++ {
		S, _ := strconv.Atoi(A[i][len(A[i])-3 : len(A[i])])
		fmt.Printf("%d\n", S)
	}
}


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

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

	vector<int> a( N );
	for( int i = 0; i < N; ++i ) {
		cin >> a.at( i );
	}

	sort( begin(a), end(a) );

	int Alice = 0;
	int Bob = 0;

	for( int i = 0; i < N; ++i ) {
		if( i % 2 == 0 ) {
			Alice += a.at( N-1 - i );
		}
		else {
			Bob += a.at( N-1 - i );
		}
	}

	cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *
def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1/f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

def solve():
    s = input().strip()
    print(s.replace("?", "D"))

def main():
    # n = getN()
    # for _ in range(n):
    solve()
if __name__ == "__main__":
    solve()

"""
    12
    3 2
    3 2
    0 1
    2 -1
    -3 -9
    -8 12
    7 0
    8 1
    8 2
    8 4
    0 0
    0 0
"""

Measured memory_bytes: 73520
A,B = map(int,input().split())
flag = 0
for i in range(10000):
    a = int(i*0.08)
    b = int(i*0.1)
    if A==a and B==b:
        flag = 1
        ans = i
        break
        
if flag == 1:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
using namespace std;
const ll inf = 1e9 + 5;
int n, a[100100], b[100100], c[100100], Dp[100100][3];

int Solve(int i, int Last)
{
    if (i == n) return 0;

    int &ret = Dp[i][Last];
    if (ret != -1) return ret;

    int C1 = 0, C2 = 0, C3 = 0;
    if (Last != 0) C1 = Solve(i+1, 0) + a[i];
    if (Last != 1) C2 = Solve(i+1, 1) + b[i];
    if (Last != 2) C3 = Solve(i+1, 2) + c[i];

    return ret = max(C1, max(C2, C3));
}

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

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

    memset(Dp, -1, sizeof Dp);

    int Answer = Solve(0, 10);

    cout << Answer << '\n';
    return 0;
}


Measured memory_bytes: 7296
n,m=map(int, input().split())
d=[[] for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  d[a].append(b)
for s in d[1]:
  for f in d[s]:
    if f == n:
      print("POSSIBLE")
      exit()
print("IMPOSSIBLE")

Measured memory_bytes: 29076
N, H = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

A.sort()
B.sort()
max_a = A[-1]
ans = 0
b_i = len(B) - 1
while H > 0:
    b = B[b_i]
    if b <= max_a:
        break
    H -= b
    ans += 1
    b_i -= 1
    if b_i < 0:
        break

if H <= 0:
    print(ans)
    exit()

ans += (H + max_a - 1) // max_a
print(ans)


Measured memory_bytes: 46936
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
k=-2
for i in a:
    ans+=b[i-1]
    if i==k+1:
        ans+=c[k-1]
    k=i
print(ans)


Measured memory_bytes: 3060
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/11/20 07:29:11
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll n; cin>>n;
  vector<pair<ll, ll>> ps(n);
  for (int i = 0; i < n; i++) {
    cin >> ps[i].first >> ps[i].second;
  }
  double sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      sum += sqrt(pow(ps[i].first-ps[j].first, 2) + pow(ps[i].second-ps[j].second, 2));
    }
  }
  cout<<fixed<<setprecision(7) << sum/n << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll a[100005];

int main()
{
	while (1) {
		cin >> n;
		if (n == 0) {
			return 0;
		} else {
			fill(a, a + 100005, 0);
			int  h, m, s, h1, m1, s1;
			REP(i, n)
			{
				scanf("%d:%d:%d%d:%d:%d", &h, &m, &s, &h1, &m1, &s1);
				a[h * 3600 + m * 60 + s]++;
				a[h1 * 3600 + m1 * 60 + s1]--;
			}
			ll mx = 0;
			REP(i, 100005)
			{
				if (i) {
					a[i] += a[i - 1];
				}
				mx = max<ll>(mx, a[i]);
			}
			cout << mx << endl;
		}
	}
}

Measured memory_bytes: 4000
fun main(args: Array<String>) {
    var (x,y,z) = readLine()!!.split(" ").map(String::toInt)
    // 空白は x/y +1 できるので、端っこの空白を xから引いて、座る幅と空白がxにいくつあるか
    println((x-z)/(y+z)) 
    
}


Measured memory_bytes: 37772
#include <iostream>
#include<bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{
  int k,n,ai,di;
  cin >> k >> n;
  
  vector<int> a;
  vector<int> d;
  
  for(int i=0;i<n;i++){
  	cin >> ai;
  	a.push_back(ai);
  }
  
  for(int i=0;i<n-1;i++){
  	di = a[i+1]-a[i];
  	d.push_back(di);
  	}
  	int m;
  	m = k - (a[n-1]-a[0]);
  	
  	d.push_back(m);
  	
  	
  	
   int max = *max_element(d.begin(), d.end()); 
   
   int ans =(k-max);
   
   cout << ans;
   
   
  return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int a,b,x;
    double ans=0;
    cin>>a>>b>>x;
    if((double)x/(double)a>double(a)*double(b)/2.0){
        double d=(2.0*(double)a*(double)a*(double)b-2*(double)x)/((double)a*(double)a);
        ans=atan2(d,a)*180.0/M_PI;
    }else{
        double d=(2*(double)x)/((double)a*(double)b);
        ans=atan2(b,d)*180.0/M_PI;
    }
    printf("%.15f\n",ans);
    return 0;
}

Measured memory_bytes: 256
r,c=map(int,input().split())
an = [list(map(int,input().split())) for _ in range(r)]
an.append([0]*(c+1))
for i in range(r):
    an[i].append(sum(an[i]))
    print(" ".join(map(str,an[i])))
    for j in range(c+1):
        an[r][j] += an[i][j] 

print(" ".join(map(str,an[r])))


Measured memory_bytes: 5688
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, Q;
int fwd[200000];
int U[200000];
int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}
void unite(int x, int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  U[x]=y;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> Q;
  vector<P2> edges;
  rep(i, N) fwd[i] = INF;
  rep(i, Q) {
    int a, b, c;
    cin >> a >> b >> c;
    edges.pb(P2(c, P(a, b)));
    fwd[a] = min(fwd[a], c+1);
    fwd[b] = min(fwd[b], c+2);
  }
  int e = INF;
  rep(_, 2) rep(i, N) {
    e = min(e+2, fwd[i]);
    edges.pb(P2(e, P(i, (i+1)%N)));
  }
  sort(all(edges));
  long long sum = 0;
  rep(i, N) U[i] = i;
  for (P2 e : edges) {
    int a = e._2._1, b = e._2._2;
    if (find(a) != find(b)) {
      sum += e._1;
      unite(a, b);
    }
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 15340
#include <stdio.h>
#include <stdlib.h>
 
int mas[3][3];
int cpy[3][3];
 
void input() {
  int i, j;
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++)
      scanf("%d", &mas[i][j]);
}
 
void output() {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) printf("%3d", mas[i][j]);
    puts("");
  }
}
 
void copy(int m[3][3], int t[3][3]) {
  int i, j;
 
  for(i = 0; i < 3; i++)
    for(j = 0; j < 3; j++) m[i][j] = t[i][j];
}
 
int calc() {
  int i, sum = 0;
  for(i = 0; i < 9; i++) {
    int v = mas[i/3][i%3];
    if(v) {
      v--;
      sum += abs(i/3-v/3)+abs(i%3-v%3);
    }
  }
  return sum;
}
 
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
 
void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
 
int is_in(int x, int y) {
  return 0<=x&&x<3&&0<=y&&y<3;
}
 
int dfs(int x, int y, int p, int dep, const int lim) {
  int i, h = calc();
  //output();
  if(h == 0) return dep;
  //printf("%d %d %d\n", h, lim, p);
  if(dep+h > lim) return -1;
 
  for(i = 0; i < 4; i++) {
    int nx = x+dx[i], ny = y+dy[i], res;
    if(~p && i == (p+2)%4) continue;
    if(!is_in(nx, ny)) continue;
    swap(&mas[y][x], &mas[ny][nx]);
    res = dfs(nx, ny, i, dep+1, lim);
    if(~res) return res;
    swap(&mas[y][x], &mas[ny][nx]);
  }
 
  return -1;
}
 
void get_empty(int *x, int *y) {
  int i, j;
  for(i = 0; i < 3; i++) {
    for(j = 0; j < 3; j++) {
      if(!mas[i][j]) {
    *x = j;
    *y = i;
    return;
      }
    }
  }
}
 
int solve() {
  int x, y, lim, ans;
  get_empty(&x, &y);
  for(lim = 0; lim < 50; lim++) {
    copy(cpy, mas);
    if((ans = dfs(x, y, -1, 0, lim)) != -1) return ans;
    copy(mas, cpy);
  }
  return -1;
}
 
int main() {
  input();
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 600
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int A, B, K;
    cin >> A >> B >> K;
    int i = 0;
    int current = 100;
    int ans = 0;
    while(i < K){
        if((A%current==0)&&(B%current==0)){
            i++;
            if(i == K){
                ans = current;
            }
        }
        current--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  string str[n];
  for(int i = 0; n > i; i++){
    cin>>str[i];
  }
  for(int i = 1; n > i; i++){
    if(str[i][0] != str[i-1][str[i-1].length()-1]){
      cout << "No" << endl;
      return 0;
    }
    for(int j = 0; i > j; j++){
      if(str[j] == str[i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int head;
    int leg;
    int ans = 0;
    cin >> head >> leg ;
    for(int i = 0;i<=head;i++){
        if(2*i+ 4*(head - i) == leg){
            ans = 1;
        }
    }
    if(ans == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>
#include <cstring>
#define INF 0x3f3f3f3f
using namespace std;
int num[30];
char ar[105];

int main()
{
    while(~scanf(" %s",ar)){
        int len = strlen(ar);
        for(int i=0;i<len;i++){
            num[ar[i]-'a']++;
        }
        bool flag = true;
        for(int i=0;i<26;i++){
            if(num[i]%2 != 0){
                flag = false;
                break;
            }
        }
        if(flag){
            printf("Yes\n");
        }
        else
            printf("No\n");

    }
    return 0;
}


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

using namespace std;

long knapsack(long long wt[],long long val[],long long N,long long W){
	long long dp[N+1][W+1];
  	
    for(long long i=0;i<=N;i++){
    	for(long long w=0;w<=W;w++){
        	if(i==0 || w==0)
              dp[i][w]=0;
          	else if(wt[i-1]<=w)
              dp[i][w]=max(dp[i-1][w],dp[i-1][w-wt[i-1]] + val[i-1]);
          	else 
              dp[i][w]=dp[i-1][w];
        }
    }
  	return dp[N][W];
}

int main(){
	long long N,W;
  	cin>>N;
  	cin>>W;
  	long long wt[N];
  	long long val[N];
  	for(long long i=0;i<N;i++){
    	cin>>wt[i];
      	cin>>val[i];
    }
  	cout<<knapsack(wt,val,N,W);

}

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

int main(){


	string s;
	getline(cin,s);

	long long index = s.length()-1;
	while(s[index] != 'Z'){

		index--;
	}

	long long i = 0;
	while(s[i] != 'A'){

		i++;
	}
	cout << index - i + 1 << endl;
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define INF 1e16
#define mod 1e9+7


int main() {
  str s;
  cin>>s;
  vll count(s.sz);
  bool D=false;
  FOR(i,0,s.sz){
    count[s[i]-'a']++;
  }
  FOR(i,0,s.sz){
    if(count[i]!=1){
      D=true;
      break;
    }
  }
  if(D)co("No");
  else co("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  vector<int> A(100009,0);
  rep(i,n){
    int a;
    cin>>a;
    if(a>0) A[a-1]++;
    A[a]++;
    A[a+1]++;
  }
  
  int ans=0;
  rep(i,100009) if(ans<A[i]) ans=A[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.ABC124.B
{
    class Program
    {
        static void Rep(long n, Action<long> action) { for (var i = 0; i < n; ++i) { action(i); } }
        static void Rep(long n, long s, Action<long> action) { for (var i = s; i < n; ++i) { action(i); } }


        public static void Main()
        {
            // Solve(4, new int[] { 6, 5, 6, 8 });
            // Solve(5, new int[] { 4, 5, 3, 5, 4 });
            // Solve(5, new int[] { 9, 5, 6, 8, 4 });
            // return;
            var N = int.Parse(Console.ReadLine());
            var str = Console.ReadLine().Split(' ');
            var H = new int[N];
            Rep(N, i =>
             {
                 H[i] = int.Parse(str[i]);
             });
            Solve(N, H);
        }

        static void Solve(int N, int[] H)
        {
            var count = 0;
            var max = H[0];
            Rep(N, i =>
            {
                if (H[i] >= max)
                {
                    ++count;
                    max = H[i];
                }
            });

            Console.WriteLine(count);
        }
    }
}



Measured memory_bytes: 11092
#include <iostream>
 
 
using namespace std;
int main(){
    int a,n,ok=1;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a;
        if(a%2==0){
            if(!(a%3==0||a%5==0)){
                ok=0;
            }
        }
    }
    if(ok==1){
        cout<<"APPROVED";
    }
    else{
        cout<<"DENIED";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define ALL(V) V.begin(),V.end()
#define f1(a,b) for(int a=1;a<=b;a++)
#define f0(a,b) for(int a=0;a<b;a++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define de(x) cout<<#x<<": "<<x<<endl
using namespace std;
const LL N=1e6+69, base=1024*1024,mod=1e9+7;
LL wynik,t[N],n,a;
vector <LL> vek;
int32_t main(void) {
    boost;
    cin>>n;
    f1(i,n) {
        cin>>a;
        a-=i;
        vek.PB(a);
    }
    sort(ALL(vek));
    LL zm=vek[n/2];
    f0(i,n) wynik+=abs(zm-vek[i]);
    cout<<wynik<<endl;
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;


class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();

        var ret = "Yes";
        for (var i = 0; i < s.Length; i++)
        {
            if ((i + 1) % 2 != 0)
            {
                if (s[i] == 'L')
                {
                    ret = "No";
                    break;
                }
            }
            else
            {
                if (s[i] == 'R')
                {
                    ret = "No";
                    break;
                }
            }
        }

        Console.Write(ret);
    }
}




Measured memory_bytes: 13140
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, K;
int A[501];

int func(int n)
{
	int a[501];
	for (int i = 0; i < N; i++)
	{
		a[i] = A[i] % n;
	}
	ARY_SORT(a, N);

	int cnt = 0;
	int end = N - 1;
	for (int i = 0; i <= end; i++)
	{
		int end_rest = n - a[end];

		if (a[i] == end_rest)
		{
			cnt += a[i];

			a[end] += a[i];
			a[i] = 0;
			end--;
		}
		else if (a[i] < end_rest)
		{
			cnt += a[i];

			a[end] += a[i];
			a[i] = 0;
		}
		else if (a[i] > end_rest)
		{
			int sub = n - a[end];
			cnt += sub;
			a[i] -= sub;
			a[end] += sub;
			end--;
			i--;
		}
	}

	return cnt;
}

signed main()
{
	cin >> N >> K;

	int sum = 0;
	REP(i, N)
	{
		cin >> A[i];
		sum += A[i];
	}

	int num = sum;
	int max = 0;
	for (int i = 1; i <= num; i++)
	{
		if (sum % i == 0)
		{
			num = sum / i;

			int a = func(i);
			int b = func(num);

			if (a <= K) max = MAX(max, i);
			if (b <= K)
			{
				cout << num << endl;
				return 0;
			}
		}
	}

	cout << max << endl;
}











Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


int main(){
  int n,k;
  cin>>n>>k;
  int ans;
  vector<int>d(k);
  bool judge;
  rep(i,k)cin>>d[i];
  for(int i=n;;++i){
    string s=to_string(i);
    judge=true;
    rep(j,s.size()){
      rep(l,d.size())
      if((s[j]-'0')==d[l]){
        judge=false;
      }
    }
    if(judge){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();

		E[] G = new E[n];
		for(int i=0;i<n;i++) G[i] = new E();

		for(int i=0;i<m;i++) {
			int a = sc.nextInt() - 1, b = sc.nextInt() - 1, l = sc.nextInt();
			G[a].add(new V(b, 2*l));
			G[b].add(new V(a, 2*l));
		}

		int[] sp = new int[k];
		int[] dist = new int[n]; fill(dist, INF);

		PriorityQueue<S> que = new PriorityQueue<S>();
		int max = 0;

		for(int i=0;i<k;i++) {
			sp[i] = sc.nextInt() - 1;
			dist[sp[i]] = 0;

			for(V v: G[sp[i]]) if(dist[v.t] > v.l){
				que.add(new S(v.t, v.l));
			}
		}

		for(;!que.isEmpty();) {
			S cur = que.remove();
			if(dist[cur.p] == INF) {
				dist[cur.p] = cur.c;
				max = max(max, cur.c);
			} else {
				max = max(max, ( dist[cur.p] + cur.c ) / 2);
				continue;
			}

			for(V v: G[cur.p]) if(dist[v.t] > v.l){
				que.add(new S(v.t, cur.c + v.l));
			}
		}

		System.out.println((max+1) / 2);
	}

	class S implements Comparable<S>{
		int p, c;
		S(int p, int c){
			this.p = p;
			this.c = c;
		}

		public int compareTo(S arg0) {
			// TODO Auto-generated method stub
			return c - arg0.c;
		}
	}

	class V {
		int t, l;
		V(int t, int l) {
			this.t = t; this.l = l;
		}
	}

	class E extends ArrayList<V> {}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 109032
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    vector<pair<double , string> > input(n);
    for (int i = 0; i < n; ++i) {
        cin >> input[i].first >> input[i].second;
    }

    double sum = 0.0;

    for (int i = 0; i < n; ++i) {
        if (input[i].second == "BTC") {
            sum += input[i].first * 380000.0;
        } else {
            sum += input[i].first;
        }
    }
    cout << sum;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int64_t sum=0; int mx=-1e9,mn=1e9;
	for(int i=0;i<n;++i){
		int a; cin>>a;
		sum+=a,mx=max(mx,a),mn=min(mn,a);
	}
	cout<<mn<<" "s<<mx<<" "s<<sum<<"\n"s;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAXN=55;
const int MOD=1e9+7;
int n,sol;
ll K;
int mat[MAXN][MAXN],mat_p[MAXN][MAXN];
int add(int x,int y){
	return (x+y)%MOD;
}
int mul(int x,int y){
	return ((ll)x*y)%MOD;
}
void mnozi(int a[MAXN][MAXN],int b[MAXN][MAXN]){
	int c[MAXN][MAXN];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			c[i][j]=0;
			for(int k=0;k<n;k++){
				c[i][j]=add(c[i][j],mul(a[i][k],b[k][j]));
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			a[i][j]=c[i][j];
		}
	}
}
void bp(ll x){
	if(x==1) return;
	bp(x/2);
	mnozi(mat,mat);
	if(x%2) mnozi(mat,mat_p);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n>>K;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>mat[i][j];
			mat_p[i][j]=mat[i][j];
		}
	}
	bp(K);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			sol=add(sol,mat[i][j]);
		}
	}
	cout<<sol<<"\n";
	return 0;
}

Measured memory_bytes: 256
n=int(input())
d=[list(map(int,input().split())) for i in range(n)]
for i in range(n-2):
    if d[i][0]==d[i][1] and d[i+1][0]==d[i+1][1] and d[i+2][0]==d[i+2][1]:
        print("Yes")
        break
else:
    print("No")

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    char c = 'A';
    for(int i=0;i<n;i++){
        if(s.at(i) != c) cnt++;
        c = s.at(i);
    }
    cout << cnt << endl;
}

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

using namespace std;

#define ll long long
#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())

char buff[(int) 2e7 + 17];
const ll inf = (ll) 1e9 + 7ll;

const int maxn = (int) 1e4 + 17;

int n;
string s;
int cnt[maxn];

bool read() {
    if (scanf("%s", buff) != 1)
        return false;

    return true;
}

void solve() {
    s = buff;
    n = sz(s);

    for (int i = 0; i < n; ++i)
        ++cnt[s[i] - 'a'];

    ll ans = 1ll * n * (n + 1) / 2;

    for (int i = 0; i < 26; ++i)
        ans -= 1ll * cnt[i] * (cnt[i] + 1) / 2;

    printf("%lld\n", ans + 1);
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int A, B, C, D, ans;
  cin >> A >> B >> C >> D;
  for (;;) {
    C -= B;
    if (C <= 0) {
      ans = 0;
      break;
    }
    A -= D;
    if (A <= 0) {
      ans = 1;
      break;
    }
  }
  if (ans == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 3636
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, k; cin >> n >> k;
    vector<int> a(n);
    //UnionFind uf(n);
    rep(i, n) {
        cin >> a[i];
        -- a[i];
        //uf.merge(i, a[i]);
    }
    vector<bool> used(n, 0);
    int cur = 0;
    int cnt = 0;
    used[0] = 1;
    vector<int> bf(1, 0);
    while(!used[a[cur]]) {
        cur = a[cur];
        bf.push_back(cur);
        used[cur] = 1;
        ++ cnt;
        if(cnt == k) {
            cout << cur + 1 << endl;
            return;
        }
    }
    int nxt = a[cur];
    //cerr << nxt << endl;
    vector<int> loop;
    for(int i = (int)bf.size() - 1; i >= 0; -- i) {
        if(bf[i] != nxt) {
            loop.push_back(bf[i]);
        } else {
            break;
        }
    }
    loop.pb(nxt);
    int sz = loop.size();
    reverse(all(loop));
    //cerr << cnt << endl;
    ++ cnt;
    if(cnt == k) {
        cout << nxt + 1 << endl;
        return;
    }
    k = k - cnt;
    k %= sz;
    cout << loop[k] + 1 << endl;
}

void solve1() {
    int n, k; cin >> n >> k;
    static int dp[65][200200];
    rep(i, n) {
        int a; cin >> a; --a;
        dp[0][i] = a;
    }
    rep(i, 64) {
        rep(j, n) {
            dp[i + 1][j] = dp[i][dp[i][j]];
        }
    }
    int now = 0;
    rep(i, 64) {
        if(k & (1LL<<i)) now = dp[i][now];
    }
    cout << now + 1 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve1();
    return 0;
}

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

namespace ConsoleApp92 {
    class Program {
        static void Main(string[] args) {
            string s = Console.ReadLine();
            int len = s.Length;
            int K = int.Parse(Console.ReadLine());

            var S_array = s.ToCharArray();

            Array.Sort(S_array);

            //Console.WriteLine(string.Join(" ", S_array));

            //先頭の文字候補が、今、何文字目か？
            int index = 0;

            //Console.WriteLine(string.Join(" ", S_array.Distinct()));

            var st_list = new List<string> { };


            while (true) {
                for (int i = 0; i < len; i++) {
                    if (s[i] == S_array.Distinct().ToArray()[index]) {
                        for (int j = 1; (i + j <= len && j <= 5); j++) {
                            st_list.Add(s.Substring(i, j));
                        }
                    }
                }

                st_list = st_list.Distinct().OrderBy(x => x).ToList();
                if (st_list.Count() < K) {
                    index++;
                } else {
                    break;
                }
            }


            //Console.WriteLine(string.Join(" ", st_list));

            Console.WriteLine(st_list[K - 1]);

        }
    }
}


Measured memory_bytes: 19036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
 cin >>N>>S>>K ;
for (int i = 0; i < N ; i++) {
  if (S.at(K-1) != S.at(i)) {
    S.at(i) = '*';
  }
    }
cout << S << endl;
  return 0 ;
}

Measured memory_bytes: 256
function main()
    h, w, k = parse.(Int, split(readline()))
    c = Vector{String}(undef, h)
    for i in 1:h
        c[i] = readline()
    end

    ans = 0
    for i in 0:2^(h+w)-1
        b = digits(i, base=2, pad=(h+w))
        sr = b[1:h]
        sc = b[h+1:end]
        x = f(c, sr, sc)
        if x == k
            ans += 1
        end
    end
    println(ans)
end

function f(c, sr, sc)
    ans = 0
    for i in 1:length(c)
        for j in 1:length(c[1])
            sr[i] == 1 && continue
            sc[j] == 1 && continue
            if c[i][j] == '#'
                ans += 1      
            end
        end
    end  
    ans
end

main()

Measured memory_bytes: 186820
#include <bits/stdc++.h>
using namespace std;
#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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    ll ok = 2 * INF, ng = 0, mid;
    while (ok - ng > 1) {
        mid = (ok + ng) / 2;
        ll cnt = 0;
        rep(i, n) {
            ll hp = h[i] - b * mid;
            if (hp <= 0) continue;
            cnt += (hp + (a - b) - 1) / (a - b);
        }
        (cnt <= mid ? ok : ng) = mid;
    }
    cout << ok << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<limits.h>

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

int main(){
  int p[101],m[100][100];
  int n,e,i,l,j,k,q;
  
  scanf("%d",&n);
  scanf("%d %d",&p[0],&p[1]);
  for(i = 2; i <= n; i++) scanf("%d %d",&e,&p[i]);

  for(i = 1; i <= n; i++) m[i][i] = 0;
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1 ; i++){
      j = i + l -1;
      m[i][j] = INT_MAX;
      for(k = i ; k <= j-1;k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j],q);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
 }



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

int main() {
  string s, t;

  cin >> s >> t;

  int ans = INT_MAX;

  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != t[j]) cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint a(N);
    rep(i, N) cin >> a[i];
    auto max_a = *max_element(a.begin(), a.end());
    int max_num = 0, second_num = 0;
    rep(i, N) {
        if (max_a == a[i]) max_num++;
        else if (max_a - 1 == a[i]) second_num++;
        else {
            cout << "No" << endl;
            return 0;
        }

    }
    if (max_a == N - 1 && max_num == N) {
        cout << "Yes" << endl;
        return 0;
    }
    if ((max_a - second_num) >0 && (max_a - second_num) * 2 <= max_num ) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

typedef struct P {
	int x, y;
	bool ok;
	bool operator==(P other) {
		return x == other.x && y == other.y;
	}
	P operator+=(P other) {
		x += other.x;
		y += other.y;
		return{ x + other.x,y + other.y };
	}
}P;
typedef struct D {
	char d;
	int l;
}D;

int n, m;
P loc, p[20];
D o;

P get_e(D a) {
	P e = { 0,0 };
	switch (a.d) {
	case 'W':e = { -1,0 }; break;
	case 'N':e = { 0,1 }; break;
	case 'E':e = { 1,0 }; break;
	case 'S':e = { 0,-1 }; break;
	default:break;
	}
	return e;
}

int find() {
	for (int i = 0; i < n; i++) {
		if (loc == p[i]) {
			p[i].ok = true;
		}
	}
	return 0;
}

int move(D a) {
	P e = get_e(a);
	for (int i = 0; i < a.l; i++) {
		loc += e;
		find();
	}
	return 0;
}

bool check() {
	for (int i = 0; i < n; i++) {
		if (!p[i].ok)
			return false;
	}
	return true;
}

int main(){
	while (cin >> n && n != 0) {
		loc = { 10,10,false };
		for (int i = 0; i < n; i++) {
			cin >> p[i].x >> p[i].y;
			p[i].ok = false;
		}
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> o.d >> o.l;
			move(o);
		}
		if (check()) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N;
    cin>>N;
    vector<pair<int,int>> A;
    rep(n,0,N){
        int a; cin>>a;
        A.push_back(make_pair(a,n+1));
    }
    sort(ToEnd(A));

    for(auto a:A) cout<<a.second<<" ";
    cout<<endl;
}

Measured memory_bytes: 1780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();

			int[] m = new int[n];
			for (int i = 0; i < n; i++) {
				m[in.nextInt()-1] = i;
			}

			long ans = 0;
			TreeSet<Integer> set = new TreeSet<>();
			set.add(-1);
			set.add(n);
			for (int i = 0; i < n; i++) {
				ans += (long)(m[i]-set.lower(m[i])) * (long)(set.higher(m[i])-m[i]) * (i+1);
				set.add(m[i]);
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 54248
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
ll N ;
void solve() {
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;return;
  }
  string s = "";
  while (N) {
    ll r = N % -2;
    if (r<0) r+=2;
    s += to_string(r);
    N = (N-r) / -2;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}
int main () {
    solve() ;

    return 0 ;
}

 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    string ans;
    if (n == 0) ans += '0';
    while (n != 0){
        if (n % 2 == 0) ans += '0';
        else ans += '1';
        if (n > 0) n = -n / 2;
        else {
            if (n % 2 == 0) n = -n / 2;
            else n = (-n + 1) / 2;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

using namespace std;

const int maxn = 200010;

int n,a[maxn];
queue<int> h;
ll res;

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    h.push(a[1]);
    int now = 2,msk=a[1],base=0;
    res=1;
    while (now <= n) {
        base = h.size();
        bool hv = false;
        while (now<=n && (a[now]&msk) ==0) {
            hv = true;
            msk|=a[now];
            h.push(a[now]);
            now++;
        }
        //if (hv) cout<<h.front()<<" "<<h.back()<<" "<<" "<<h.size()<<" "<<  base<<endl;
        if (hv) res += 1ll*h.size()*(h.size()+1)/2 - 1ll*base*(base+1)/2;
        else {
            while (!h.empty() && (a[now]&msk) != 0) {
                msk ^= h.front();
                h.pop();
            }
           // h.push(a[now]);
           // res += 1ll*h.size()*(h.size()+1)/2;
            //now++;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

char chmap[6][6],tmpmap[6][6];
int main(){
    int H,W,K;
    cin>>H>>W>>K;
    int res=0;
    REP(h,H)REP(w,W)cin>>chmap[h][w];
    for (int bitw = 0; bitw < (1<<W); ++bitw){
        for (int bith = 0; bith < (1<<H); ++bith){
            REP(h,H)REP(w,W)tmpmap[h][w]=chmap[h][w];
            REP(w,W)if(bitw&(1<<w)){
                REP(h,H)tmpmap[h][w]='0';
            }
            REP(h,H)if(bith&(1<<h)){
                REP(w,W)tmpmap[h][w]='0';
            }
            int cnt=0;
            REP(h,H)REP(w,W)if(tmpmap[h][w]=='#')cnt++;
            if(cnt==K)res++;
        }
    }
    cout<<res<<endl;
    return 0;
}


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

int main()
{
    int a,b; cin >> a >> b;
    int pro = a*b;
    if(pro%2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;
}

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

using namespace std;

int main()
{
    
    int n,m;
    cin >> n >> m;
    queue<long long> lane[11];

    for(int i=0;i<m;i++)
    {

        int count=1;
        for(int j=1;j<=n;j++)
        {
            if(lane[j].size()<lane[count].size())
            {
                count=j;   
            }
        }


        int op;
        cin >> op;
        if(op==1)
        {
            int num;
            cin >> num;
            lane[count].push(num);
        }
        else if(op==0)
        {
            int l;
            cin >> l;
            cout << lane[l].front() << endl;
            lane[l].pop();
        }
    }
    return(0);
}


Measured memory_bytes: 3220
#include<stdio.h>
main(){
  double a,b,c,d,e,f,x,y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
      x=(b*f-e*c)/(b*d-a*e);
      y=(c-a*x)/b;
      if(x==-0){
	x=0;
      }
      if(y==-0){
	y=0;
      }
      printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 652