akhauriyash/Code-Regression huggingface dataset:
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	static final String YES = "YES";
	static final String NO = "NO";

	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			int countDataset = sc.nextInt();
			int[] ballNums = new int[10];

			for (int i = 0; i < countDataset; i++) {
				for (int j = 0; j < 10; j++) {
					ballNums[j] = sc.nextInt();
				}

				System.out.println(push(ballNums) ? YES : NO);
			}
		} finally {
			sc.close();
		}
	}

	public static boolean push(int[] nums) {
		Deque<Integer> list1 = new LinkedList<Integer>();
		;
		Deque<Integer> list2 = new LinkedList<Integer>();
		list1.add(0);
		list2.add(0);
		for (int number : nums) {
			if (list1.peek() < number) {
				list1.push(number);
			} else if (list2.peek() < number) {
				list2.push(number);
			} else {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 26280
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val K = ni()
    val evens = (K - 1) / 2 + 1
    val odds = K / 2
    out.println(evens * odds)
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int N; cin >> N;
    int cnt[4] = {};
    REP(i,N){
        string s;
        cin >> s;
        if (s == "AC") cnt[0]++;
        if (s == "WA") cnt[1]++;
        if (s == "TLE") cnt[2]++;
        if (s == "RE") cnt[3]++;
    }

    cout << "AC x " << cnt[0] << "\n";
    cout << "WA x " << cnt[1] << "\n";
    cout << "TLE x " << cnt[2] << "\n";
    cout << "RE x " << cnt[3] << "\n";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
	char output[6]={'A','B','C','D','E'};
	int a,b;
	while(cin>>a>>b&&a!=0&&b!=0){
		vector<pair<int,int> > data;
		data.push_back(make_pair(a+b,0));
		for(int i=1;i<5;i++){
			cin>>a>>b;
			data.push_back(make_pair(a+b,i));
		}
		sort(data.begin(),data.end());
		cout<<output[data[4].second]<<" "<<data[4].first<<endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define PI 3.141592653589793

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

struct point{
		double x;
		double y;
};

void coho(int d, point a, point b){
	double p6 = 60 * PI /180.0;
	if(d == 0) return;
	double x1 = (b.x -a.x)/3;
	double y1 = (b.y -a.y)/3;
	point s, t, u;
	s.x = x1 +a.x;
	s.y = y1 + a.y;
	u.x = x1*2 + a.x;
	u.y = y1*2 + a.y;
	t.x = (u.x - s.x)*cos(p6) - (u.y - s.y)*sin(p6) + s.x;
	t.y = (u.x - s.x)*sin(p6) + (u.y - s.y)*cos(p6) + s.y;
	coho(d-1, a, s);
	cout << s.x <<" "<< s.y << endl;
	coho(d-1, s, t);
	cout << t.x <<" "<< t.y << endl;
	coho(d-1, t, u);
	cout << u.x << " " << u.y << endl;
	coho(d-1, u, b);
}

int main(){
	int n;
	cin >> n;
	point a, b;
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	cout << a.x << " " << a.y << endl;
	coho(n, a, b);
	cout << b.x << " " << b.y << endl;
}



Measured memory_bytes: 3264
<?php

fscanf(STDIN, '%d %d', $n,$k);

$d = explode(' ', trim(fgets(STDIN)));

for ($i=$n;$i<=100000;$i++) {

    $na = str_split($i);
    $cnt = 0;

    foreach($na as $value){

        if(in_array($value, $d)){
            continue 2;
        };

        $cnt += 1;

        if($cnt == count($na)){
            print($i);
            exit;
        }

    }
}



Measured memory_bytes: 4984
#include<iostream>
#include<stack>
#include<map>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    stack<pair<int,int> > back;
    int a = 0,b = 0,row[10];
    bool f = true;
    for(int i=0; i<10; i++){cin >>row[i];}
    a = row[0];
    for(int i=1; i<10; i++){
      if(a < row[i] && b > row[i]){a = row[i];}
      else if(a > row[i] && b < row[i]){b = row[i];}
      else if(a < row[i] && b < row[i]){
	back.push(make_pair(a,i));
	a = row[i];
      }
      else if(a > row[i] && b > row[i]){
	if(back.empty()){cout <<"NO"<<endl;f = false;break;}
	else{
	  i = back.top().second;
	  a = back.top().first;
	  b = row[i];
	  back.pop();
	}
      }
    }
    if(f){cout <<"YES"<<endl;}
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <vector>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	ll n;
	cin>>n;
	vector<ll> v;
	ll temp;
	for(int i=0;i<n;i++){
		cin>>temp;
		v.push_back(temp);
	}
	sort(v.begin(),v.end());
	vector<ll>::iterator end=unique(v.begin(),v.end());
	vector<ll>::iterator it;
	ll sum=0;
	for(it=v.begin();it!=end;it++){
		sum++;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
# Aizu Problem 0241: Quaternion Multiplication

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    for k in range(n):
        a1, a2, a3, a4, b1, b2, b3, b4 = [int(__) for __ in input().split()]
        p1 = a1 * b1 - a2 * b2 - a3 * b3 - a4 * b4
        p2 = a1 * b2 + a2 * b1 - a4 * b3 + a3 * b4
        p3 = a1 * b3 - a2 * b4 + a3 * b1 + a4 * b2
        p4 = a1 * b4 + a2 * b3 - a3 * b2 + a4 * b1
        print(p1, p2, p3, p4)

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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

typedef unsigned int uint;
typedef long long ll;
typedef pair<int,int> pii;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

vector<int> tree[100000];
int ans,k;

int dfs(int v,int p){
	int md=0;
	for(auto c:tree[v])
		md=max(dfs(c,v),md);
	md++;
	if(md==k){
		if(p!=0)
			ans++;
		md=0;
	}
	return md;
}

int main(){
	int n=read();
	k=read();
	REP(i,n){
		int a=read()-1;
		if(i==0){
			if(a!=0)
				ans++;
		}else{
			tree[a].PB(i);
		}
	}
	for(auto c:tree[0])
		dfs(c,0);
	cout<<ans<<endl;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    int n, m;
    cin >> n >> m;
    vector<int> adj[n+1];
    for(int i=1, u, v; i<=m; i++){
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int> dist(n+1, -1);
    dist[1]=0;
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int v: adj[u]){
            if(dist[v]==-1){
                dist[v]=dist[u]+1;
                q.push(v);
            }
        }
    }
    vector<int> ans(n+1, -1);
    for(int i=2; i<=n; i++){
        for(int child: adj[i]){
            if(dist[child]==dist[i]-1){
                ans[i]=child;
                break;
            }
        }
        if(ans[i]==-1){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for(int i=2; i<=n; i++)
        cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 10644
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;
const double PI=3.14159265358979323846;

int main (){
    ll N;
    cin >> N;
    ll X[N],L[N];
    vector<vector<ll>> A(N,vector<ll>(2));
    rep(i,0,N) {
        cin >> X[i] >> L[i];
        A[i][1] = X[i]-L[i];
        A[i][0] = X[i]+L[i];
    }

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

    ll tmp = A[0][1];

    ll ans = 0;
    rep(i,0,N) {
        if (A[i][1]>=tmp) {
            ans++;
            tmp = A[i][0];
        }
    }

    cout << ans << endl;

}





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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    int ans = 0;
    for(int s = 0; s < (1<<n); s++){
        int x = 0;
        int y = 0;
        for(int i = 0; i < n; i++){
            if((s>>i) & 1){
                x += v[i];
                y += c[i];
            }
        }
        ans = max(ans, x-y);
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()

int main() {

  for(int N, D; cin >> N >> D && (N|D);) {
    vector<vector<int>> C(N);
    vector<int> idx(N), curr(N);
    rep(i, N) {
      int M; cin >> M;
      C[i].resize(M);
      rep(j, M) cin >> C[i][j], curr[i] += C[i][j];
      reverse(all(C[i]));
    }

    auto getMaxValExceptMe = [&](int idx) {
      int ret = 0;
      rep(i, N) {
        if(i == idx) continue;
        ret = max(ret, curr[i]);
      }
      return ret;
    };

    while(1) {
      int maxMin = -1, maxMinIdx = -1;
      bool ok = 0;
      rep(i, N) {
        if(idx[i] < C[i].size()) {
          ok = 1;
          if(curr[i] - C[i][idx[i]] > maxMin && getMaxValExceptMe(i) - (curr[i] - C[i][idx[i]]) <= D) {
            maxMin = curr[i] - C[i][idx[i]];
            maxMinIdx = i;
          }
        }
      }

      if(!ok) break;

      if(maxMinIdx == -1) {
        cout << "No" << endl;
        goto next;
      }

      curr[maxMinIdx] -= C[maxMinIdx][idx[maxMinIdx]];
      idx[maxMinIdx] ++;
    }

    cout << "Yes" << endl;

    next:;
  }
  
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// pow mod
mint powm(ll a, ll n) {
  mint res = 1;
  mint x = a;
  while (n > 0) {
    if (n & 1) res *= x;
    x *= x;
    n >>= 1;
  }
  return res;
}

int main() {
  int n; cin >> n;
  vector<int> a(n);
  ll sum = 0;
  rep (i, n) {
    cin >> a[i];
    sum += a[i];
  }

  mint ans = 0;
  rep (i, n) {
    sum -= a[i];
    ans += a[i] * (sum % MOD) % MOD;
  }

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


Measured memory_bytes: 4056
#include <stdio.h>

int main(){
 int a,b;

 scanf("%d %d\n",&a,&b);

 if(a > b)
  printf("a > b\n");
 else if(a < b)
  printf("a < b\n");
 else if(a == b)
  printf("a == b\n");

 return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if ((N * 100) % 108 == 0) {
	cout << (N * 100) / 108 << endl;
  }
  else if ((N * 100) / 108 == ((N + 1) * 100) / 108) {
	cout << ":(" << endl;
  }
  else if (((N + 1) * 100) % 108 == 0) {
    cout << ":(" << endl;
  }
  else {
    cout << ((N + 1) * 100) / 108 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long a[n];
	long long sum =0 ;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		sum+= a[i];
	}
	long long ans = 0;
	for(int i=0;i<n;i++){
		sum -= a[i];
		ans += ((sum%mod)*a[i])%mod;
		ans = ans%mod;
	}
	cout<<ans<<endl;
	 return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static const double swap_rate=0.5;
static const double change_rate=1.0-swap_rate;
static int ans[D+1];
static int max_score=0;
static const int t=1100000;
static const int last_swap=100000;

class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int Score(int type){
    int sum=0;
    contest[type].last=0;
    for(int day=1;day<=D;++day){
        if(ans[day]==type){
            sum+=contest[type].s[day];
            int n=day-contest[type].last;
            sum-=contest[type].c*(n*(n-1)/2);
            contest[type].last=day;
        }
    }
    if(ans[D]!=type){
        int n=D-contest[type].last;
        sum-=contest[type].c*(n*(n+1)/2);
    }
    return sum;   
}

void Output(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int d=1;d<=D;++d) cout<<ans[d]<<'\n';
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int before=ans[p];
    int after=rand()%ntype+1;
    int before_score=Score(before)+Score(after);
    ans[p]=after;
    int delta=Score(before)+Score(after)-before_score;
    if(delta>0){ 
        max_score+=delta;
    }
    else ans[p]=before;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp_score=Score(ans[p1])+Score(ans[p2]);
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int delta=Score(ans[p2])+Score(ans[p1])-temp_score;
    if(delta>0){
        max_score+=delta;
    }
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void Solve(int times){
    Greedy();
    for(int i=1;i<=ntype;++i) max_score+=Score(i);
    for(int i=0;i<times;++i){
        double p=(double)rand()/RAND_MAX;
        if(p<swap_rate) swap();
        else change();
    }
    for(int i=0;i<last_swap;++i) swap();
}

int main(){
    srand(seed);
    Input();
    Solve(t);
    Output();
}


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

    int n,a,k=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(a==k) k++;
    }
    if(k==1) cout<<-1;
    else cout<<n-k+1;
}


Measured memory_bytes: 256
# l <= x <= rのIDで通る
n,m = map(int, input().split())
tmp = []
tip = [0] * 10 ** 7
ma = 0
for i in range(m):
    x,y = map(int, input().split())
    ma = max(ma, y)
    tip[x] += 1
    tip[y + 1] -= 1

for i in range(1, ma + 1):
    tip[i] += tip[i - 1]

print(tip.count(m))


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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(N);
    }
}

class Solver {
    public void solve(long N) {
        int min = (int) N;
        for (int i = 0; i <= N; i++) {
            int c = 0;

            int t = i;
            while (t > 0) {
                c += t % 6;
                t /= 6;
            }

            t = (int) (N - i);
            while (t > 0) {
                c += t % 9;
                t /= 9;
            }

            min = Math.min(min, c);
        }
        System.out.println(min);
    }
}



Measured memory_bytes: 23124
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;



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

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

int main() {
	ll i, j, k;
	ll N, M, K;
	ll ans = 0;

	vector<int> A;
	cin >> N;
	rep(i, 0, N) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	int MIN = 2 * 1000000;
	
	rep(i, 0, N) {
		if (MIN >= A[i])ans++;
		MIN = min(MIN, A[i]);

	}
	cout << ans;
	return 0;




}


Measured memory_bytes: 1400
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
 
int main(){
int H,W ;
 
while(1){
     cin >> H >> W;
     if(H == 0 && W == 0){
         break;
     }
 
     for(int j = 0; j< H; j++){
          for(int i = 0; i< W; i++){
               if((i+j)%2 == 0 ){
                    cout << "#";
               }else{
                    cout << ".";
               }
    }cout << endl;
}cout << endl;
}
return 0;
}


Measured memory_bytes: 3088
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll N, M, TSum;
ll T[101];

int main() {
	rd(N);
	repi(i, 0, N) {
		rd(T[i]);
		TSum += T[i];
	}
	rd(M);
	repi(i, 0, M) {
		ll ans, P, X;
		cin >> P >> X;
		ans = TSum - T[P - 1] + X;
		wrln(ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int m, f, r;

    while(1) {
        scanf("%d%d%d", &m, &f, &r);

        if(m == -1 && f == -1 && r == -1) break;

        if(m == -1 || f == -1) printf("F\n");
        else if(m + f >= 80) printf("A\n");
        else if(m + f >= 65) printf("B\n");
        else if(m + f >= 50) printf("C\n");
        else if(m + f >= 30) {
            if(r >= 50) printf("C\n");
            else printf("D\n");
        }else printf("F\n");

        scanf("\n");
    }
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
int INF = 1e18, MOD = 1e9 + 7;
map<int, int> factorization(int n) {
    map<int, int> res;
    rep(i, 2, sqrt(n) + 1) {
        if(i > 3) i++;
        while(!(n%i)) res[i]++, n /= i;
    }
    if(n > 1) res[n]++;
    return res;
}
signed main() {
    INCANT;
    int a, b, res = 0;
    cin>>a>>b;
    int n = gcd(a, b);
    cout<<factorization(n).size() + 1<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>



int main(void){
    int n , i , j , k , m ;
    char a[101][2] , b[101][2] , tmp[2] ;
    scanf("%d" , &n) ;
    for(i = 0 ; i < n ; i++){
        scanf("%s" , a[i]);
        for(k = 0 ; k < 2 ; k++)b[i][k] = a[i][k] ;
    }
    for(i = 0 ; i < n ; i++){
        for(j = n - 1 ; j > i ; j--){
            if(a[j][1] < a[j - 1][1]){
                for(k = 0 ; k < 2 ; k++)tmp[k] = a[j][k] ;
                for(k = 0 ; k < 2 ; k++)a[j][k] = a[j - 1][k] ;
                for(k = 0 ; k < 2 ; k++)a[j - 1][k] = tmp[k] ;
            }
        }
    }
    for(i = 0 ; i < n ;i++){
        m = i ;
        for(j = i + 1 ; j < n ; j++){
            if(b[j][1] < b[m][1]) m = j ;
        }
        if(b[m][1] < b[i][1]){
            for(k = 0 ; k < 2 ; k++) tmp[k] = b[i][k] ;
            for(k = 0 ; k < 2 ; k++) b[i][k] = b[m][k] ;
            for(k = 0 ; k < 2 ; k++) b[m][k] = tmp[k] ;
        }
    }
    int ck = 1 ;
    for(i = 0 ; i < n ; i++){
        if(a[i][0] != b[i][0]) ck = 0 ;
    }
    for(i = 0 ; i < n ; i++){    
        if(i)printf(" ") ;
        printf("%c%c" , a[i][0] , a[i][1]);
    }
    printf("\nStable\n") ;
    for(i = 0 ; i < n ; i++){
        if(i)printf(" ") ;
        printf("%c%c" , b[i][0] , b[i][1]) ;
    }
    if(ck)printf("\nStable\n") ;
    else printf("\nNot stable\n") ;
    return 0 ;
}


Measured memory_bytes: 2132
#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[i];
  vector<int> B = A;
  sort(A.begin(), A.end());

  int half = A[N/2];

  for(int i=0;i<N;i++) {
    if(B[i] < half) cout << half << endl;
    else cout << A[N/2-1] << endl; 
  }
}

Measured memory_bytes: 3712
prime = [True for i in range(1300001)]
prime[0] = prime[1] = False
for i in range(2, 1200):
    if prime[i]:
        for j in range(2, 1300000 // i + 1):
            prime[i * j] = False

while True:
    n = int(input())
    if n == 0:
        break

    nl = nu = n
    while not prime[nl]:
        nl -= 1
    while not prime[nu]:
        nu += 1
    print(nu - nl)


Measured memory_bytes: 15712
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <ctime>

using namespace std;

const int INF = 1e9 + 9;
const int MOD = 1e9 + 7;
const int kek = 1;

int main() {
	//#ifdef _DEBUG
	//	freopen("input.txt", "r", stdin);
	//#endif

	int n, ans = 0;
	scanf("%d", &n);
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &v[i]);
	}
	sort(v.begin(), v.end());
	for (int i = n - 1; i >= 0; i -= 2) {
		ans += v[i];
	}
	for (int i = n - 2; i >= 0; i -= 2) {
		ans -= v[i];
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() 
{
	int x;
	cin >> x;
	cout << x*x*x << endl;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int top = 0;
int st[1000];
void push(int x);
int pop();

int main(){
    int ans = 0;
    while(1){
        char c[100]; 
        if(scanf("%s" , &c) == EOF) break;
        if(c[0] == '+'){
            int a = pop(); int b = pop();
            push(a+b);
        }else if(c[0] == '-'){
            int a = pop(); int b = pop();
            push(b-a);
        }else if(c[0] == '*'){
            int a = pop(); int b = pop();
            push(a*b);
        }else{
            push(atoi(c));
        }

    }
    cout << pop() << endl;
}

void push(int x){
    st[++top] = x;
}

int pop(){
    int x = st[top];
    top--;
    return x;
}


Measured memory_bytes: 3248
import java.util.Scanner;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] road;
	static int v1, v2;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		if(!sc.hasNext())return false;
		road = new int[10];
		String[] in = sc.next().split(",");
		for(int i = 0; i < road.length; i++){
			road[i] = Integer.parseInt(in[i]);
		}
		v1 = Integer.parseInt(in[10]);
		v2 = Integer.parseInt(in[11]);
		return true;
	}
	
	static void solve(){
		int road_length = 0;
		for(int i = 0; i < road.length; i++){
			road_length += road[i];
		}
		double per = (v1 + 0.0)/(v1+v2 + 0.0);
		int res = 0;
		double per_length = 0.0;
		for(int i = 0; i < road.length; i++){
			per_length += (road[i]+0.0)/(road_length+0.0);
			//System.out.println(per_length);
			if(per_length >= per){res = i+1;break;}
		}
		//System.out.println("road length = " + road_length + " per = " + per + " v1 = " + v1 + " v2 = " + v2);;
		System.out.println(res);
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#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 each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

vi countAlpha(string s){
  vi res(26,0);
  rep(i,s.size()) res[s[i]-'a']++;
  return res;
}

int main(){
  int n;
  cin >> n;
  vs s(n);
  rep(i,n) cin >> s[i];

  vi res = countAlpha(s[0]);
  rep(i,n){
    vi tmp = countAlpha(s[i]);
    rep(j,26) chmin(res[j], tmp[j]);
  }

  string x;
  rep(j,26){
    rep(k,res[j]) x += (char)('a' + j);
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
	ll N;
	cin >> N;
	ll num = 0;
	if (N < 105){
		cout << 0 << endl;
	}
	else{
		ll cnt = 0;
		rep(ii, 105, N + 1){
			if (0 == ii % 2) continue;
			rep(i, 1, N + 1){
				if (0 == ii % i) cnt++;
			}
			if (cnt == 8){
				num++;
			}
			cnt = 0;
		}
	cout << num << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int A, B;
  std::cin >> A >> B;
  (A%2==1&&B%2==1)?std::cout << "Yes" << '\n':std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall sound_hound_A.cpp.cpp -o ./out/sound_hound_A.cpp.out
./out/sound_hound_A.cpp.out
*/

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

typedef long long ll;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}



int main(){
//  freopen("./input/input.txt", "r", stdin);
//  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a + b == 15) cout << "+\n";
  else if (a * b == 15) cout << "*\n";
  else cout << "x\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    string acl = "ACL";
    int k;
    cin >> k;
    rep(i, k){
        cout << acl;
    }
    cout << endl;
    return 0;
}

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

int main(void){
    int n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n) cin>>v[i];
    int num4=0;
    int num2=0;
    int num1=0;
    rep(i, n){
        if(v[i]%4==0) num4++;
        else if(v[i]%2==0) num2++;
        else num1++;
    }
    bool ok;
    if(num1>num4+1) ok=false;
    else if(num1==num4+1){
        if(num2==0) ok=true;
        else ok=false;
    }
    else  ok=true;
    if(ok) {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 1024
a=input()
op=['+','-']

for i in op:
    for j in op:
        for k in op:
            if eval(a[0]+i+a[1]+j+a[2]+k+a[3])==7:
                print(a[0]+i+a[1]+j+a[2]+k+a[3]+"=7")
                exit()


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    string s;
    cin >> n >> s;

    int max_val = 0, x = 0;
    rep(i, s.size()){
        if(s[i] == 'I') ++x;
        else --x;

        max_val = max(max_val, x);
    }

    cout << max_val << endl;
}

Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._



  val n = readInt
  val wise = readLine.trim.split(' ').map(_.toInt == 0).zip(readLine.trim.split(' ').map(_.toInt)).map(it ⇒ Wise(it._1, it._2))
  var min = Int.MaxValue
  for (w ← wise.permutations){
    var sum = 0
    for (i ← w.indices){
      if (w(i).right) {
        if (!w((i + 1) % n).right) {
          sum += w(i).hate
          sum += w((i + 1) % n).hate
        }
      }
    }
    if (min > sum) min = sum
  }
  println(min)
  case class Wise(right: Boolean, hate: Int)
}



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

typedef long long int ll;

int main()
{
	ll a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	if(v==w)
		printf("NO\n");
	else
	{
/*		ll ans;
		if(b>a)
			ans=(b-a)/(v-w);
		else
			ans=(a-b)/(v-w);
//		cout<<ans;
		if(ans<=t && ans>0)
			printf("YES\n");
		else
			printf("NO\n");*/
		ll A,B;
		if(b>a)
		{
			B=b+w*t;
			A=a+v*t;
			if(A>=B)
				cout<<"YES\n";
			else
				cout<<"NO\n";
		}
		else
		{
			B=b-w*t;
			A=a-v*t;
			if(A<=B)
				cout<<"YES\n";
			else
				cout<<"NO\n";
		}
	}
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S; 
	int K = S.size(); int count = 15 - K; 
	for(int i = 0; i < K; i++){
		if(S[i] == 'o') count ++; 
	}
	if(count >= 8) cout << "YES" << endl; 
	else cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> // accumulate
#include <queue>
#include <string>
#include <cmath> // sqrt
#include <map>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod-2, mod);
}

ll dp[5010][5010];  //dp[キーを押す回数][文字列の長さ]

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

    int m = s.size();

    dp[0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0) {
                dp[i+1][j+1] += dp[i][j] * 2LL;
                dp[i+1][j+1] %= mod;
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
            }
            else {
                dp[i+1][j+1] += dp[i][j] * 2LL;
                dp[i+1][j+1] %= mod;
                dp[i+1][j-1] += dp[i][j];
                dp[i+1][j-1] %= mod;
            }
        }
    }

    cout << dp[n][m] * modinv(modpow(2, m, mod), mod) % mod << endl;
}

Measured memory_bytes: 194176
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	// cin.tie(nullptr);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	bool flag = false;
	int con = 0;
	vector<int> a;
	int N;
	
	cin>>N;
	
	a.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
		a[i]--;
	}
	
	for(int now = 0;;con++){
		// cout<<"now = "<<now<<endl;
		if(now == -1) break;
		
		if(now == 1) {
			// con++;
			flag = true;
			break;
		}
		int temp = now;
		now = a[now];
		
		a[temp] = -1;
	}
	
	if(flag) cout<<con<<endl;
	else cout<<-1<<endl;
	
	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int UB = 110;
int N;
int rs[UB];
vector<vector<PII>> xs(3, vector<PII>(UB));

bool check(vector<vector<PII>> ss){
  vector<PII> score(N);
  REP(i,N) score[i].SS = i;
  REP(i,3)
	sort(RALL(ss[i]));
  REP(j,3){
	int rank = 0;
	REP(i,N){
	  if(i>0 && ss[j][i].FF != ss[j][i-1].FF)
		rank = i;
	  score[ss[j][i].SS].FF += rs[rank];
	}
  }

  sort(RALL(score));
  int rank = 0;
  for(int i=0;i<N;++i){
	if(i>0 && score[i].FF != score[i-1].FF)
	  rank = i;
	if(score[i].SS == 0)
	  break;
  }

  return rank+1 < 9;
}

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

  cin >> N;
  REP(i,N) cin >> rs[i];
  REP(i,N)
	cin >> xs[0][i].FF >> xs[1][i].FF >> xs[2][i].FF;
  REP(i,N) REP(j,3)
	xs[j][i].SS = i;

  REP(k,101){
	auto tmp = xs;
	REP(j,3){
	  tmp[j][0].FF += k;
	  if(check(tmp)){
		cout << k << endl;
		return 0;
	  }
	  tmp[j][0].FF -= k;
	}
  }
  cout << "Saiko" << endl;

  return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <string.h>
#define MN 100000
#define MM 200000
int n,a,b,c1=0,c2=0;
int p[MN+5],pn=0,col[MN+5];
int hd[MN+5],nxt[MM+5],to[MM+5],rn=0;
void add(int u,int v){
	++rn;
	nxt[rn]=hd[u];
	hd[u]=rn;
	to[rn]=v;
}
bool dfs(int u){
	p[++pn]=u;
	if(u==n) return true;
	for(int i=hd[u];i!=-1;i=nxt[i])
		if(p[pn-1]!=to[i])
			if(dfs(to[i]))
				return true;
	--pn;
	return false;
}
void spr(int u){
	for(int i=hd[u];i!=-1;i=nxt[i])
		if(col[to[i]]==0){
			col[to[i]]=col[u];
			spr(to[i]);
		}
}
int main(){
	memset(hd,0xff,sizeof(hd));
	memset(col,0,sizeof(col));
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		scanf("%d%d",&a,&b);
		add(a,b),add(b,a);
	}
	dfs(1);
	for(int i=1;i<=pn;i++)
		if(i<=((pn+1)>>1)) col[p[i]]=1;
		else col[p[i]]=2;
	for(int i=1;i<=pn;i++) spr(p[i]);
	for(int i=1;i<=n;i++){
		if(col[i]==0) return 1;
		if(col[i]==1) c1++;
		if(col[i]==2) c2++;
	}
	if(c1<=c2) puts("Snuke");
	else puts("Fennec");
}

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

int main()
{
  int n;
  cin >> n;
  
  int x[n];
  int tmp[n];
  rep(i,n)
  {
    cin >> x[i];
    tmp[i] = x[i];
  }
  sort(tmp,tmp+n);
 
  int mid1 = tmp[n/2-1];
  int mid2 = tmp[n/2];
  int ans[n];
  rep(i,n)
  {
    if(x[i] <= mid1) ans[i] = mid2;
    else if(x[i] >= mid2) ans[i] = mid1;
  }
  
  rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 5844
#include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> pii;
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=2e3+50;
int n,pre[N],suf[N];
char a[N],b[N];
inline int dis(int a,int b) {
	if(a<=b) return b-a;
	else return b+n-a;
}
inline int solve(int p) {
	vector <pii> vec;
	for(int i=0;i<n;i++) {
		int tar=(i+p)%n;
		if(a[tar]^b[i]) 
			vec.push_back(pii(dis(pre[tar],tar),dis(tar,suf[tar])));
	}
	if(!vec.size()) return min(dis(0,p),dis(p,0));
	int ans=1e9;
	sort(vec.begin(),vec.end(),[](const pii &a,const pii &b) {return a.first<b.first || (a.first==b.first && a.second>b.second);});
	for(int i=vec.size()-1,mx=0;~i;i--) {
		mx=max(mx,vec[i].second);
		int mx2=(i==0) ? 0 : vec[i-1].first;
		ans=min(ans,mx2+mx2+mx+min(dis((p+mx)%n,0),dis(0,(p+mx)%n)));
		ans=min(ans,mx+mx+mx2+min(dis((p-mx2+n)%n,0),dis(0,(p-mx2+n)%n)));
	} return ans+vec.size();
}
int main() {
	scanf("%s%s",a,b);
	n=strlen(a);
	int s1=0, s2=0;
	for(int i=0;i<n;i++)
		s1+=a[i]-'0', s2+=b[i]-'0';
	if(s1 && !s2) {return puts("-1"),0;}
	
	if(b[0]=='1') pre[0]=0;
	else {
		for(int i=n-1;~i;i--)
			if(b[i]=='1') {pre[0]=i; break;}
	}
	for(int i=1;i<n;i++)
		pre[i]=(b[i]=='1' ? i : pre[i-1]);
	if(b[n-1]=='1') suf[n-1]=n-1;
	else {
		for(int i=0;i<n;i++) 
			if(b[i]=='1') {suf[n-1]=i; break;} 
	}
	for(int i=n-2;~i;i--)
		suf[i]=(b[i]=='1' ? i : suf[i+1]);
	int ans=1e9;
	for(int i=0;i<n;i++)
		ans=min(ans,solve(i));
		
	reverse(a,a+n); reverse(b,b+n);
	if(b[0]=='1') pre[0]=0;
	else {
		for(int i=n-1;~i;i--)
			if(b[i]=='1') {pre[0]=i; break;}
	}
	for(int i=1;i<n;i++)
		pre[i]=(b[i]=='1' ? i : pre[i-1]);
	if(b[n-1]=='1') suf[n-1]=n-1;
	else {
		for(int i=0;i<n;i++) 
			if(b[i]=='1') {suf[n-1]=i; break;} 
	}
	for(int i=n-2;~i;i--)
		suf[i]=(b[i]=='1' ? i : suf[i+1]);
	for(int i=0;i<n;i++)
		ans=min(ans,solve(i));
	
	cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

ll how_many[51]; //バーガーの段数

void init_how_many() {
    how_many[0] = 1;
    for (int i = 1; i <= 50; i++) {
        how_many[i] = 3 + 2 * how_many[i - 1];
    }
}

ll count_func(ll l, ll x) {
    if (x == 1) return (l == 0 ? 1 : 0);
    else if (x == how_many[l]) return 1 + 2 * count_func(l - 1, how_many[l - 1]);
    else if (x == (how_many[l] + 1) / 2) return 1 + count_func(l - 1, how_many[l - 1]);
    else if (1 < x && x < (how_many[l] + 1) / 2) {
        return count_func(l - 1, x - 1);
    } else if ((how_many[l] + 1) / 2 < x && x < how_many[l]) {
        return 1 + count_func(l - 1, how_many[l - 1])
                + count_func(l - 1, x - 2 - how_many[l - 1]);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, x;
    cin >> n >> x;
    init_how_many();
    cout << count_func(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
int main()
{
  int H,N;
  cin >> H >> N;
  int A[N];
  rep(i,N) cin >> A[i];
  rep(i,N) H = H - A[i];
  
  if(H <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 640