akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<complex>
#include<array>
#include<vector>
#include<cstdio>
using namespace std;

const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef  complex<double> point;

double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}
typedef array<point, 2> line;

point projection(const line& l, const point& p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}

point reflection(const line& l, const point& p) {
	return p + 2. * (projection(l, p) - p);
}
 typedef array<point, 2> line;
//using line = array<point, 2>;
/*
 * 平行かどうか
 */
bool is_parallel(const line& s, const line& t) {
	return eq(cross(s[0] - s[1], t[0] - t[1]), 0.0);
}

bool is_orthogonal(const line& s, const line& t) {
	return eq(dot(s[0] - s[1], t[0] - t[1]), 0.0);
}



int main()
{
  int q;
  cin>>q;
  for(;q--;)
    {
      line l1,l2;
      double x,y;
      cin>>x>>y;
      l1[0]=point(x,y);
      cin>>x>>y;
      l1[1]=point(x,y);

      cin>>x>>y;
      l2[0]=point(x,y);
      cin>>x>>y;
      l2[1]=point(x,y);

      int ans=0;
      if(is_parallel(l1,l2))
	ans=2;
      else if(is_orthogonal(l1,l2))
	ans=1;
      cout<<ans<<endl;
      //      printf("%.10lf %.10lf\n",ans.real(),ans.imag());
    }
}

Measured memory_bytes: 1236
#define P(x) cout << #x" = " << x << endl
#define PP(x, y) cout << "("#x", "#y") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "("#x", "#y", "#z") = (" << x << ", " << y << ", " << z << ")" << endl

#include <iostream>
#include <vector>
#include <set>

using namespace std;
using PA = pair<int, int>;
using ll = long long;

int pre[100000];
int last[100000];
int n, k;
vector<PA> arr;
set<int> used;

int main(){
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int t, d;
        cin >> t >> d;
        t--;
        arr.push_back(make_pair(d, t));
        last[i] = -1;
    }
    sort(arr.begin(), arr.end(), greater<PA>());

    for (int i = 0; i < n; i++) {
        // int d = arr[i].first;
        int t = arr[i].second;
        pre[i] = last[t];
        last[t] = i;
        // PPP(i, t, pre[i]);
    }
    int nex = k - 1;
    ll types = 0;
    ll sm = 0;
    for (int i = 0; i < k; ++i) {
        int d = arr[i].first;
        if (pre[i] == -1) {
            types++;
        }
        sm += d;
    }
    ll ans = sm + types * types;
    int i = k;
    while(true) {
        if (nex == -1) {
            break;
        }
        if (pre[nex] == -1) {
            nex--;
            continue;
        }
        while (i < n && pre[i] != -1) {
            i++;
        }
        if (i == n) break;
        types += 1;
        sm -= arr[nex].first;
        sm += arr[i].first;
        ans = max(ans, sm + types * types);
        nex -= 1;
        i += 1;
    }
    cout << ans << endl;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int main(){
  string a;
  int cp = 0;
  int countc = 0;
  cin >> a;

  if(a[0] == 'A') cp++;
  
  int as = a.size() - 1;
  FOR(i, 2, as) {
    if(a[i] == 'C') countc++;
  }
    if(countc == 1) cp++;
    
    int cw = 0;
    REP(j, a.size()){
      if(a[j] < 97) cw++;
      }

      if(cw == 2) cp++;

      if(cp == 3){
        cout << "AC" << endl;
        }else{
          cout << "WA" << endl;
          }
    return 0;
        
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![macro_use]
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::ops::*;
use std::rc::*;
use std::str::*;
use std::string::*;
use std::*;

const MOD: usize = 1000000007;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    // ========================================= //
    let N: usize = sc.read();
    let A: Vec<isize> = sc.vec(N);

    // i < j について
    // j-i = A[i] + A[j]
    // i + A[i] = j - A[j]
    let mut ans = 0usize;
    let mut mp = HashMap::new();
    for (i, &v) in A.iter().enumerate() {
        let k = i as isize - v;
        ans += mp.get(&k).map_or(0, |x| *x);
        *mp.entry(i as isize + v).or_insert(0) += 1;
    }
    sc.write(ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);
impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
  int n;
  cin >> n;
  int sum1,sum2;
  vector<int> v1(n);
  vector<int> v2(n);
  rep(i,n){
    cin>>v1.at(i);
  }
  rep(i,n){
    cin>>v2.at(i);
  }
  vector<int> a1(n);
  vector<int> a2(n);
  if (v1<v2){
    a1 = v2;
    a2 = v1;
  }
  else{
    a1 = v1;
    a2 = v2;
  }
  bool ok1 = true;
  while(ok1){
    if (a2 == a1){
      ok1 = false;
    }
    else {
      sum1++;
      next_permutation(a2.begin(),a2.end());
    }
  }
  cout << sum1 << endl;
}

Measured memory_bytes: 256
n=int(input())
Alist=[0]+[int(input()) for i in range(n)]

now=1
Hist={1}

for i in range(n):
    now=Alist[now]
    if now==2:
        print(i+1)
        break
    if now in Hist:
        print(-1)
        break
    Hist.add(now)

Measured memory_bytes: 13724
/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                   ____/`---'\____
                  /  \\|     |//  \
                 / \\||| /:\ |||// \
                / _||||| -:- |||||- \
               |   | \\\ \-/ /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
            ____'. .'  /--.--\  `. .'_____
          /"" '<  `.___\_<|>_/___.' >' "" \
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` / _/
          `-.____`.___ \_____/___.-`___.-'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    I_LOVE_ADITI_GOEL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define LIM 100005


#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define deb(a) cerr << #a << ": " << a << endl
#define ftt cin>>t;for(int tt=1;tt<=t;++tt)
#define forr(i,n) for((i)=1;(i)<=(n);(i)++)
#define Rev(v) reverse(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define mem(a,b) memset(a,b,sizeof(a))
#define umii unordered_map<int,int>
#define all(a) a.begin() , a.end()
#define vvi vector<vector<int>>
#define pq priority_queue<int>
#define sqr(a) (((a) * (a)))
#define double long double
#define dbg cout<<"\nhi\n"
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define eb emplace_back
#define vi vector<int>
#define nl cout<<"\n"
#define pb push_back
#define int long long
#define sp <<" "<<
#define se second
#define fi first
 
int fpow(int x,int y,int m) {
     int temp;
     if( y == 0 || x == 1)
          return 1;
     temp = fpow(x, y/2,m);
     if (y % 2 == 0)
          return ((temp)*(temp)) % m;
     else
          return (((x) % m)*((temp*temp) % m)) % m;
}
int gcd(int a,int b)
{
    if(b == 0)return a;
    return gcd(b,a % b);
}
void sieve(int n)
{
     bool prime[5*LIM];
     memset(prime, true, sizeof(prime));
      int rootn = (int)sqrt(n);
     for (int p = 2; p <= rootn; p++)
          if (prime[p] == true)
               for (int i = p*p; i <= n; i += p)
                    prime[i] = false;
     prime[1] = 0;

}

int cnt, sum, mid, mx = -1e17, mn = 1e17;
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;
vi a(2*LIM);
//*************************************************************************************************************************


int32_t main()
{     fio;
      cin>>n;
      forr(i,n)cin>>a[i];
      vi pre(2*LIM,0),suff(2*LIM,0);
      x=0;
      forr(i,n)
      {
            pre[i]=x;
            x^=a[i];
      }
      x=0;
      for(i=n;i>0;i--)
      {
            suff[i]=x;
            x^=a[i];
      }
      forr(i,n)
      {
            cout<<(pre[i]^suff[i])<<" ";
      }
}


Measured memory_bytes: 7984
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 100010
namespace uf{
  ll p[N],s[N];
  void init(){
    for(int i=0;i<N;i++)p[i]=i,s[i]=1;
  }
  ll par(ll x){
    ll y=x,z;
    while(x!=p[x])x=p[x];
    while(y!=x)z=p[y],p[y]=x,y=z;
    return x;
  }
  ll unite(ll a,ll b){
    a=par(a); b=par(b);
    if(a==b)return 0;
    ll res=s[a]*s[b];
    p[b]=a,s[a]+=s[b];
    return res;
  }
};
ll n,m,a[N],b[N],ans[N];
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++)cin>>a[i]>>b[i];
    uf::init();
    ll cur=n*(n-1)/2;
    for(int i=m-1;~i;i--){
      ans[i]=cur;
      cur-=uf::unite(a[i],b[i]);
    }
    for(int i=0;i<m;i++)cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));

  double before = v[0];
  for (int i = 1; i < n; i++)
  {
    before = (v[i] + before) / 2;
  }
  printf("%.7lf\n", before);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int count = 0;
		int[] nums = new int[n];
		boolean end = false;
		
		for(int i=0; i<n ;i++) {
			nums[i] = sc.nextInt();
		}
		
		while(true) {
			for(int i=0; i<n ;i++) {
				if(nums[i] % 2 == 0) {
					nums[i] = nums[i] / 2;
				}else {
					end = true;
					break;
				}
			}
			if(end) {
				break;
			}
			
			count++;
		}
		
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a+b>a-b)&&(a+b>a*b))
	cout<<a+b;
	else if(a-b>a*b)
	cout<<a-b;
	else
	cout<<a*b;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }



    private void solve() {
        try {
            int n = sc.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = sc.nextInt();
            }

            int count = 0;

            for (int i = 1; i < n-1; i++) {
                int a = p[i-1];
                int b = p[i];
                int c = p[i+1];
                if (a < b && b < c) {
                    count ++;
                } else if (a > b && b > c) {
                    count ++;
                }
            }

            System.out.println(count);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22996
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, M;
    cin >> N >> M;

    vector<pair<ll, ll>> v(N); // duration, reward
    REP(i, N) {
        ll a, b; cin >> a >> b;
        v[i] = {a, b};
    }

    sort(ALL(v));
    priority_queue<ll> q;

    int j = 0;
    ll ans = 0;
    FOR(i, 1, M + 1) {

        for(; j < N && i >= v[j].fi; ++j) {
            q.push(v[j].se);
        }


        if (q.empty()) continue;
        ans += q.top(); q.pop();
    }

    print(ans);
    
}


Measured memory_bytes: 5852
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
	int n;
    cin >> n;
    vector<int> x(n);
    int mx = -1;
    int mn = 2001;
    rep(i,0,n){
        cin >> x[i];
        if(mx < x[i]){
            mx = x[i];
        }
        if(mn > x[i]){
            mn = x[i];
        }
    }

    if((mx - mn)%2 == 0){
        cout << (mx - mn) / 2 << endl;
        return 0;
    }else{
        cout << (mx - mn) / 2 + 1 << endl;
        return 0;
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n;i++) cin >> v.at(i);
  //1番目を正にする場合
  int64_t sum1 = 0,ans1 = 0;
  for(int i = 0; i < n; i++){
    sum1 += v.at(i);
    if(i % 2 == 0){
      if(sum1 <= 0) {
        ans1 += 1-sum1;
        sum1 += 1-sum1;
      }
    }else {
      if(sum1 >= 0) {
        ans1 += 1 + sum1;
        sum1 -= 1 + sum1;
      }
    }
  }
  //1番目を負にする場合
  int64_t sum2 = 0,ans2 = 0;
  for(int i = 0; i < n; i++){
    sum2 += v.at(i);
    if(i % 2 == 0){
      if(sum2 >= 0) {
        ans2 += 1+sum2;
        sum2 -= 1+sum2;
      }
    }else {
      if(sum2 <= 0) {
        ans2 += 1 - sum2;
        sum2 += 1 - sum2;
      }
    }
  }
  cout << min(ans1,ans2) << endl;
}

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

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

const int MOD = 1e9+7;

void prime_fact(int n, map<int,int>& A){
    if (n <= 1) return;
    int n_origin = n;
    for(int i=2; i<=(int)sqrt(n_origin); i++){
        if (n%i == 0){
            int count = 0;
            while(n%i == 0){
                n/=i;
                count ++;
            }
            A[i] += count;
        }
    }
    if (n!=1){
        A[n] += 1;
    }
    return;
}

int main() {
    int n; cin >> n;
    map<int,int> A;
    FOR(i,1,n+1){
        prime_fact(i, A);
    }
    ll ans = 1;
    for(auto a: A){
        ans *= a.second+1;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3696
#include <algorithm>
#include <cstdio>
#include <vector>
#define pb push_back
std::vector<int> vec, adj[100005]; 
int dp[100005]; 
bool dfs(int u, int lim, int fa = -1)
{
	for (int v : adj[u])
	{
		if (v != fa && !dfs(v, lim, u))
			return false; 
	}
	vec.clear(); 
	for (int v : adj[u])
	{
		if (v != fa)
			vec.pb(dp[v] + 1); 
	}
	if (vec.size() & 1 ^ (fa != -1))
		vec.pb(0); 
	std::sort(vec.begin(), vec.end()); 
	if (~fa)
	{
		int l = 0, r = vec.size() - 2; 
		while (l < r)
		{
			if (vec[l++] + vec[r--] > lim)
				return false; 
		}
		int idx = vec.size() - 1; 
		while (idx && vec[idx] + vec[vec.size() - 1 - idx + (idx << 1 < vec.size())] <= lim)
			idx--; 
		dp[u] = vec[idx]; 
	}
	else
	{
		int l = 0, r = vec.size() - 1; 
		while (l < r)
		{
			if (vec[l++] + vec[r--] > lim)
				return false; 
		}
	}
	return true; 
}
int main()
{
	// freopen("ARC088-F.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 1; i < n; i++)
	{
		int u, v; 
		scanf("%d%d", &u, &v); 
		adj[--u].pb(--v);
		adj[v].pb(u); 
	}
	int a = 0, l = 0, r = n - 1, ans; 
	for (int i = 0; i < n; i++)
		a += adj[i].size() & 1;
	while (l <= r)
	{
		int m = l + r >> 1; 
		if (dfs(0, m))
		{
			ans = m; 
			r = m - 1; 
		}
		else
			l = m + 1;
	}
	printf("%d %d\n", a + 1 >> 1, ans);
	return 0; 
}


Measured memory_bytes: 14080
// solv_B.cpp : 
//

#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define PRICE_MAX 100000

int main()
{
    int i, j, k;
    int x, y, c;

    int A, B, M;
    scanf("%d %d %d", &A, &B, &M);

    int* prices_A = new int[A];
    int* prices_B = new int[B];

    int price_A_min, price_B_min;

    price_A_min = PRICE_MAX;
    price_B_min = PRICE_MAX;
    

    for (i = 0; i < A; i++) {
        scanf("%d", &prices_A[i]);
        if (price_A_min > prices_A[i]) price_A_min = prices_A[i];
    }
    for (i = 0; i < B; i++) {
        scanf("%d", &prices_B[i]);
        if (price_B_min > prices_B[i]) price_B_min = prices_B[i];
    }

    int min_p = price_A_min + price_B_min;
    int p;

    for (k = 0; k < M; k++) {
        scanf("%d %d %d", &x, &y, &c);

        p = prices_A[x - 1] + prices_B[y - 1] - c;
        if (min_p > p) min_p = p;
    }

    printf("%d\n",min_p); 
    fflush(stdout);
    

    delete[] prices_A, prices_B;
    return 0;
}


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

namespace ABC_152c
{
    class Program
    {
        static void Main(string[] args)
        {
            int first = int.Parse(Console.ReadLine());
            int[] second = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int count = 0;
            
            for(int i = 0; i < first; i++)
            {
                if(second[i] <= second[0])
                {
                    count++;

                    second[0] = second[i];
                }
            }

            Console.WriteLine(count);

            Console.Read();
        }
    }
}


Measured memory_bytes: 31068
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  105
#define K  100005

ll n,k;
ll a[N];
ll dp[N][K];
ll pre[K];

ll solve(){
	rep(i,0,a[0]+1){
		dp[0][i]=1;
	}
	pre[0]=dp[0][0];
	rep(i,1,k+1)pre[i]=pre[i-1]+dp[0][i];
	rep(i,1,n){
		rep(j,0,k+1){
			ll mn = max(0LL,j-a[i]);
			if(mn>0){
				dp[i][j]=(pre[j]-pre[mn-1]+hell)%hell;
			}
			else{
				dp[i][j]=pre[j];
			}
		}
		pre[0]=dp[i][0];
		rep(j,1,k+1)pre[j]=(pre[j-1]+dp[i][j])%hell;
	}
	return dp[n-1][k];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
			cin>>n>>k;
			rep(i,0,n)cin>>a[i];
			cout<<solve()<<endl;
	}
	return 0;
}

Measured memory_bytes: 82476
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vector<ll>count(26,INF);
  rep(i,n){
    string s;cin>>s;
    vector<ll>part(26,0);
    for(int j=0;j<26;j++){
      for(int k=0;k<s.size();k++){
        if(abc[j]==s[k])part[j]++;
      }
    }
    for(int j=0;j<26;j++){
      count[j]=min(count[j],part[j]);
    }
  }
  rep(i,26){
    if(count[i]==INF)continue;
    rep(j,count[i])cout<<abc[i];
  }
  cout<<endl;
}
  

Measured memory_bytes: 256
using System;
using System.Linq;
class program{
  static void Main(){
    long n = long.Parse(Console.ReadLine());
    string ans = "";
    while(n > 0){
      ans = (char)((n-1)%26+97)+ans;
      n = (n-1)/26;
    }
    Console.Write(ans);
  }
}

Measured memory_bytes: 27492
//CODEFORCES:-
//coded by AMAN BHARTI NIT PATNA
//ALL RIGHTS RESERVED
//ECE 2K18

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

//#define home
#define TASK "soln"
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define pb push_back
#define ll long long int
#define br cout<<endl;
#define fo for(int i=0;i<n;i++)
#define foo for(int i=1;i<=n;i++)
#define mod 1000000007


void solve(){
    string s;
    cin>>s;

    if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR")cout<<1<<endl;
    else if(s=="RRS"||s=="SRR")cout<<2<<endl;
    else if(s=="RRR")cout<<3<<endl;
    else cout<<0<<endl;
}

int main(){
	#ifdef home
        assert(freopen(TASK".in","r",stdin));
        assert(freopen(TASK".out","w",stdout));
    #endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    // int t;
    // cin>>t;
    // while(t-->0)
    solve();

    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif

    return 0;
}

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


			

int main(){
	
	int N;
	cin>>N;
	vector<pair<pair<string,int>,int>> V(N);
	
	for(int i=0;i<N;i++){
		cin>>V[i].first.first>>V[i].first.second;
		V[i].first.second*=-1;
		V[i].second=i+1;
	}
	
	sort(V.begin(),V.end());
	
	for(int i=0;i<N;i++){
		cout<<V[i].second<<endl;
	}
		
	
	
	
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	ans := 0

	num := make(map[int]int)
	for i := 1; i <= N; i++ {
		num[i%K]++
	}

	for a := 0; a < K; a++ {
		b := (K - a) % K
		c := (K - a) % K
		if (b+c)%K != 0 {
			continue
		}

		ans += num[a] * num[b] * num[c]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 6528
#include<vector>
template<typename T> class SegmentTree {
 public:
  SegmentTree(int n) : size_(1) {
    while(size_ < n) size_ <<= 1;
    node_.assign(size_ << 1, 0);
    lazy_.assign(size_ << 1, 0);
  }
  T find(int left, int right) {return find(left, right + 1, 1, 0, size_);}
  void add(int left, int right, T value) {add(left, right + 1, value, 1, 0, size_);}
 private:
  int left_child(int node) const {return node << 1;}
  int right_child(int node) const {return (node << 1) + 1;}
  T find(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) return 0;
    if(a <= l && r <= b) return node_.at(k) + (r - l) * lazy_.at(k);
    lazy_.at(left_child(k)) += lazy_.at(k);
    lazy_.at(right_child(k)) += lazy_.at(k);
    node_.at(k) += (r - l) * lazy_.at(k);
    lazy_.at(k) = 0;
    auto vl = find(a, b, left_child(k), l, (l + r) / 2);
    auto vr = find(a, b, right_child(k), (l + r) / 2, r);
    return vl + vr;
  }
  T add(int a, int b, T value, int k, int l, int r) {
    if(b <= l || r <= a) return node_.at(k) + (r - l) * lazy_.at(k);
    if(a <= l && r <= b) return node_.at(k) + (r - l) * (lazy_.at(k) += value);
    lazy_.at(left_child(k)) += lazy_.at(k);
    lazy_.at(right_child(k)) += lazy_.at(k);
    lazy_.at(k) = 0;
    auto vl = add(a, b, value, left_child(k), l, (l + r) / 2);
    auto vr = add(a, b, value, right_child(k), (l + r) / 2, r);
    return node_.at(k) = vl + vr;
  }
  int size_;
  std::vector<T> node_;
  std::vector<T> lazy_;
};

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

const int C = 26;

void solve(auto s, auto k) {
  vector<queue<int>> q(C);
  for(auto i = 0; i < s.size(); ++i) q[s[i] - 'a'].emplace(i);

  SegmentTree<int> cost(s.size());
  for(auto i = 0; i < s.size(); ++i) cost.add(i, i, i);

  for(auto i = 0; i < s.size(); ++i) {
    for(auto c = 0; c < 26; ++c) {
      if(q[c].empty()) continue;
      if(k < cost.find(q[c].front(), q[c].front())) continue;
      printf("%1c", c + 'a');
      k -= cost.find(q[c].front(), q[c].front());
      cost.add(q[c].front(), s.size() - 1, -1);
      q[c].pop();
      break;
    }
  }

  puts("");
}

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

  solve(s, k);
}

Measured memory_bytes: 8224
n = gets.to_i
t,x,y = 0,0,0

ans = 'Yes'
n.times do
  nt,nx,ny = gets.split.map(&:to_i)
  dt = nt-t
  dx = nx-x
  dy = ny-y
  if dx+dy > dt
    ans = 'No'
    break
  elsif (dx+dy-dt).odd?
    ans = 'No'
    break
  end
  t,x,y = nt,nx,ny
end

puts ans

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b,h;
  cin >> a >> b >>  h;
  cout << (a+b)*h/2 << endl;
}


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

typedef unsigned long long Hash;
template<class T>
class RollingHash{
public:
	T src;
	vector<Hash> harr,p;
	
	RollingHash(T src,Hash w=8999):src(src){
		p.resize(src.size()+1);
		Hash sum = 0;
		for(int i = 0 ; i < src.size() ; i++){
			sum = sum * w + src[i];
			harr.push_back(sum);
		}
		p[0] = 1;
		for(int i = 1 ; i < p.size() ; i++){
			p[i] = p[i-1] * w;
		}

	}
	// [l,r)
	Hash sub(int l,int r) const{
		if( l >= r ) return 0;
		return harr[r-1] - (l?harr[l-1] * p[r-l]:0);
	}
};

struct Node{
	Hash val;
	int width;
	int center;
};
bool operator < (const Node &a,const Node &b){
	if( a.width != b.width ) return a.width > b.width;
	return a.val < b.val;
}


string fix(string s){
	string r = "$";
	for(auto c : s ){
		r += c;
		r += "$";
	}
	return r;
}

Node reduce(Node node,const RollingHash<string> &s_hash){
	node.width -= 2;
	if( node.width < 0 ) return node;
	node.val = s_hash.sub(node.center-node.width,node.center+node.width+1);
	return node;
}

int main(){
	string S,T;
	cin >> S >> T;
	S = fix(S);
	T = fix(T);
	RollingHash<string> s_hash(S,10007);
	RollingHash<string> t_hash(T,10007);
	// cout << S << endl;
	auto f = [](string S){
		RollingHash<string> s_hash(S,10007);
		reverse(S.begin(),S.end());
		RollingHash<string> sr_hash(S,10007);
		reverse(S.begin(),S.end());
		map<Node,int> res;
		for(int i = 0 ; i < S.size() ; i++){
			int i2 = S.size() - i - 1;
			int l = 0;
			int r = min<int>(i,S.size()-i-1);
			while( l != r ){
				int m = (l+r+1) /2;
				if( sr_hash.sub(i2-m,i2+m+1) == s_hash.sub(i-m,i+m+1) ){
					l = m;
				}else{
					r = m-1;
				}
			}
			if( S[i-l] == '$' ){
				l--;
			}
			if( l >= 0 ){
				res[{s_hash.sub(i-l,i+l+1),l,i}]++;
			}
		}
		return res;
	};
	auto sCount = f(S);
	auto tCount = f(T);
	long long ans = 0;
	for(int i = 100001 ; i >= 0 ; i--){
		while( (*tCount.begin()).first.width > i ){
			auto nextNode = reduce(tCount.begin()->first,t_hash);
			tCount[nextNode] += (*tCount.begin()).second;
			tCount.erase((*tCount.begin()).first);
		}
		while( (*sCount.begin()).first.width > i ){
			auto nextNode = reduce(sCount.begin()->first,s_hash);
			sCount[nextNode] += (*sCount.begin()).second;
			sCount.erase((*sCount.begin()).first);
		}
		auto it = sCount.begin();
		while( it != sCount.end() && (*it).first.width == i ){
			if( tCount.count((*it).first)){
				ans += 1ll * tCount[(*it).first] * it->second;
			}
			it++;
		}
	}
	cout << ans << endl;
	
	
}

Measured memory_bytes: 15812
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll s = 1000001;
static const ll MOD = 1e9 + 7;

ll r_x[100001] = {};
ll r_v[100001] = {};
ll l_x[100001] = {};
ll l_v[100001] = {};
ll r_cal[100001] = {};
ll l_cal[100001] = {};
ll r_max[100001] = {};
ll l_max[100001] = {};

int main()
{
	ll n, c; cin >> n >> c;
	repe(i, 1, n) {
		ll X, V; cin >> X >> V;
		r_x[i] = X;
		r_v[i] = V;
		l_x[n - i + 1] = c - X;
		l_v[n - i + 1] = V;
	}

	repe(i, 1, n) {
		r_cal[i] = r_v[i] - (r_x[i] - r_x[i - 1]);
		r_cal[i] += r_cal[i - 1];
		l_cal[i] = l_v[i] - (l_x[i] - l_x[i - 1]);
		l_cal[i] += l_cal[i - 1];
	}

	repe(i, 1, n) {
		r_max[i] = max(r_max[i - 1], r_cal[i]);
		l_max[i] = max(l_max[i - 1], l_cal[i]);
	}

	// right
	ll ans = 0;
	repe(i, 1, n) {
		ll cal_r = r_cal[i];
		ll cal_l = cal_r - r_x[i] + l_max[n - i];
		ll cal = max(cal_r, cal_l);

		ans = max(ans, cal);
	}

	// left
	repe(i, 1, n) {
		ll cal_l = l_cal[i];
		ll cal_r = cal_l - l_x[i] + r_max[n - i];
		ll cal = max(cal_r, cal_l);

		ans = max(ans, cal);
	}
	cout << ans << endl;

	return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//
int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int xmax = INF32 * -1;
    int ymin = INF32;
    for(int i = 0; i < n; ++i){
        int tmp; cin >> tmp;
        xmax = max(xmax, tmp);
    }
    for(int i = 0; i < m; ++i){
        int tmp; cin >> tmp;
        ymin = min(ymin, tmp);
    }
    bool flag = false;
    for(int i = x + 1; i <= y; ++i){
        if(xmax < i && i <= ymin){
            flag = true;
            break;
        }
    }

    if(flag){
        cout << "No War" << endl;
    }
    else{
        cout << "War" << endl;
    }
    return 0;
}



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

using namespace std;

void poss(void){
  cout << "Possible" << endl;
  return;
}

void imp(void){
  cout << "Impossible" << endl;
  return;
}

int main(void){
  int a, b;
  cin >> a >> b;

  if(a % 3 == 0){
    poss();
  } else if(b % 3 == 0){
    poss();
  }else if((a + b) % 3 == 0){
    poss();
  }else imp();
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
import re
#solve
def solve():
    s = S()
    if re.match("(A?)KIH(A?)B(A?)R(A?)", s) and len(s) <= 9:
        print("YES")
    else:
        print("NO")
    return


#main
if __name__ == '__main__':
    solve()


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

int sum(int a){
  int ans = 0;
  while(a != 0) {
    ans += a%10;
    a = a/10;
  }
  return ans;
}


int main() {
  int N;
  cin >> N;
  if (N%sum(N) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);

		String line = stdin.nextLine();
		stdin.close();
		String[] input = line.split(" ");
		int num = Integer.parseInt(input[0]);
		int not = Integer.parseInt(input[1]);

		if(num == not || (num % 2 == 0 && not  == 2) || not == 1 || not == 0 || num % not == 0){
			System.out.println(-1);
			return;
		}else if(num < not){
			System.out.println(num);
			return;
		}
		for(long i = 0; i < 1000000000000000000l; i += num){
			if(i % not != 0){
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}

}


Measured memory_bytes: 21844
def main():
  n = int(input())
  hs = list(map(int, input().split(' ')))
  l = [hs[i+1] - hs[i] for i in range(n-1)]
  ans = 0
  count = 0
  for i in l:
    if i <= 0:
      count += 1
      if count > ans:
        ans = count
    else:
      count = 0
  print(ans)

if __name__ == '__main__':
  main()


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

int main() {
  int N;

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

  int count=0;
  for(int i=0; i<N; i++){
    int mochi=0;
    if(d.at(i)>0){
      count++;
      mochi = d.at(i);
      for(int j=0; j<N; j++){
        if(d.at(j)==mochi){
          d.at(j)=0;
        }
      }
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
A, B, C, K = gets.strip.split(/ /).collect{|n| n.to_i}

#x = 2 ** K

if K % 2 == 1
#	k1 = x / 3
	k1_k3 = -1
	k2_k1 = 1
else
#	k1 = x / 3 + 1
	k1_k3 = 1
	k2_k1 = -1
end
#k2 = k3 = (x - k1) / 2

k3_k2 = 0

#diff = (k1 * A + k2 * B + k3 * C) - (k3 * A + k1 * B + k2 * C)
#diff = (k1 - k3) * A + (k2 - k1) * B + (k3 - k2 * C)
diff = (k1_k3) * A + (k2_k1) * B + (k3_k2) * C

if diff > 10 ** 18
	puts "Unfair"
else
	puts diff
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define maxn 100005

int out_degree[maxn],in_degree[maxn];

ll result, path[maxn];
vector<ll> edge[maxn];

ll dfs(ll from) {
	ll longest = 0;


	if (!out_degree[from]) {
		return 0;
	}

	if (path[from]) {
		return path[from];
	}


	for (auto each : edge[from]) {

		longest = max(longest, dfs(each) + 1);

	}

	return path[from] = longest;
}

int main()
{
	ll N, M, x, y;
	cin >> N >> M;

	for (int i = 0; i < M; ++i) {
		cin >> x >> y;
		out_degree[x]++;
		in_degree[y]++;
		edge[x].push_back(y);
	}
	for (int i = 0; i < N; ++i) {
		if (out_degree[i + 1] && !in_degree[i + 1]) {
			result = max(dfs(i + 1), result);
		}
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 15228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		
		int n=scan.nextInt();
		
		if(n%10==0 || n%10==1 ||n%10==6 || n%10==8) {
			System.out.println("pon");
		}else if(n%10==3) {
			System.out.println("bon");
		}else {
			System.out.println("hon");
		}
			
		}

	}



Measured memory_bytes: 35668
A,B,K = map(int, input().split())
if B - A + 1> 2*K:
    a = list(range(A, A+K))
    b = list(range(B-K+1,B+1))
    c = sorted(set(a+b))
    print(*c, sep="\n")
else:
    print(*range(A,B+1), sep="\n")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
	long long k=9,n;
struct node
{
	long long a,b;
};
	queue<node>Q;
int main()
{
	cin>>n;
	for(int i=1;i<=9;i++)
	{
		node tmp;
		tmp.a=tmp.b=i;
		Q.push(tmp);
	}
	while(!Q.empty())
	{
		node tmp=Q.front();
		Q.pop();
		long long a=tmp.a,b=tmp.b,t=tmp.a%10;
		if(b==n)
		{
			cout<<a;
			return 0;
		}
		for(int i=0;i<=9;i++)
		{
			if(abs(i-t)<=1)
			{
				node cur;
				cur.a=a*10+i;
				cur.b=++k;
				Q.push(cur);
			}
		}
	}
	return 0;
}

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

int A,B,C,X;

int main() {
  cin>>A>>B>>C>>X;
  int count = 0;
  for(int i=0;i<=A;i++) {
    for(int j=0;j<=B;j++) {
      for(int k=0;k<=C;k++) {
        if(500*i+100*j+50*k==X) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    const int base=-2;
    vector<int>v;
    while(n!=0){
        int rem=n%base;
        n/=base;
        if(rem<0){
            rem+=(-base);
            ++n;
        }
        v.emplace_back(rem);
    }
    reverse(all(v));
    if(int(v.size())>0)
    for(auto &x:v)cout<<x;
    else cout<<0;
    
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back

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

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

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

    string     op = "+-*";
    stack<int> st;
    string     s;
    while (cin >> s) {
        if (op.find(s) != string::npos) {
            int r = st.top();
            st.pop();
            int l = st.top();
            st.pop();
            if (s == "+") st.push(l + r);
            if (s == "-") st.push(l - r);
            if (s == "*") st.push(l * r);
        } else {
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;

    return 0;
}



Measured memory_bytes: 3212
/**
 *   author: Shubham Srivastava
 *   created: 18 August 2019  17:45:32
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector <int> node[200005];
vector <int> pre;
vector <int> lev(200005,1),pos(200005,0);
int timer=1;
void dfs(int a, int p)
{
    pos[a] = timer++;
    for(auto i : node[a])
        if(i != p){
            dfs(i,a);
            lev[a] += lev[i];
        }
}

int main(){
    int n,q;cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        node[a].push_back(b);
        node[b].push_back(a);
    }   
    dfs(1,1);
    vector <int> ans(200005,0);
    for(int i=0;i<q;i++){
        int x,y;cin>>x>>y;

        int sz = lev[x];
        ans[pos[x]] += y;
        ans[pos[x]+sz] -= y;
    }
    for(int i=2;i<=n;i++)
        ans[i] += ans[i-1];
    for(int i=1;i<=n;i++)
        cout<<ans[pos[i]]<<" ";
return 0;
}

Measured memory_bytes: 28288
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
ll x[200];
int main() {
	ios_base::sync_with_stdio(false);
	ll n; cin>>n;
	for (ll i=0;i<n;i++) {
		cin>>x[i];
	}
	ll ans=INF;
	for (ll y=-100;y<=100;y++) {
		ll cand=0;
		for (ll i=0;i<n;i++) {
			ll d=(y-x[i]);
			cand+=d*d;
		}
		chkmin(ans,cand);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

vl R, C;

vector<vl> dp;

ll calc(int l, int r) {
    if(dp[l][r] != INF) return dp[l][r];
    auto& ret = dp[l][r];
    if(r - l == 1) return ret = 0;
    if(r - l == 2) return ret = R[l] * C[l] * C[l+1];
    for(int m = l + 1; m < r; ++m) {
        chmin(ret, R[l] * C[m-1] * C[r-1] + calc(l, m) + calc(m, r));
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    R.resize(n);
    C.resize(n);
    rep(i, n) cin >> R[i] >> C[i];
    dp = vector<vl>(n+1, vl(n+1, INF));
    cout << calc(0, n) << endl;
    return 0;
}


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

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

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

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

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

const int MAX = 100100;

int A[MAX];

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);


	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
	}

	sort(A, A + n);

	int x = n-1;
	int y = 1;
	while(true)
	{
		if (x < 0 || A[x] < y)
		{
			x++;
			y--;

		//	cout<<x<<' '<<y<<endl;

			int v1 = A[x] - y ;
			if (v1 % 2 == 1)
			{
				cout<<"First"<<endl;
				return 0;
			}

			if (x && A[x-1] == y)
			{
				int v2 = 0;
				FOR (i, 0, x)
				{
					if (A[i] == y) v2++;
				}

				if (v2 % 2 == 1)
				{
					cout<<"First"<<endl;
					return 0;
				}
			}
			cout<<"Second"<<endl;
			return 0;
		}

		x--;
		y++;
	}

	throw -1;


}


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

namespace English_Sentence
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine().ToLower();
            string[] words = input.Split(' ');

            int max = 0;
            List<int> idx = new List<int>();
            List<int> cnt = new List<int>();
            for (int i = 0; i < words.Length; ++i)
            {
                int count = 0;
                for (int j = i+1; j < words.Length; ++j)
                {
                    if (words[i].Equals(words[j]))
                    {
                        count++;
                    }
                }
                if (count > max)
                {
                    max = count;
                    cnt.Add(count);
                    idx.Add(i);
                }
            }
            int ansIdx = idx[cnt.IndexOf(cnt.Max())];
            string ans1 = words[ansIdx];
            string ans2 = "";
            int maxC = 0;
            foreach (string item in words)
            {
                if (item.Length > maxC)
                {
                    maxC = item.Length;
                }
            }
            foreach (string item in words)
            {
                if (item.Length == maxC)
                {
                    ans2 = item;
                }
            }

            Console.WriteLine(ans1 + " " + ans2);
        }
    }
}



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

ll inf = 1000000LL * 1000000LL * 1000000LL;

int main(){
	string s,t;
	cin >> s >> t;
	vector<vector<int>> dp(s.length() + 1,vector<int>(t.length() + 1 , 0));
	for(int i = 0 ; i < s.length() ; ++i){
		for(int j = 0 ; j < t.length() ; ++j){
			if(s[i] == t[j]){
				dp[i+1][j+1] = 1 + dp[i][j];
			}
			else {
				dp[i+1][j+1] = max(dp[i][j+1] , dp[i+1][j]);
			}
		}	
	}
	string ans;
	int x = s.length() , y = t.length() , cnt = dp[x][y];
	while(cnt){
		if(dp[x][y] == dp[x-1][y])x--;
		else if(dp[x][y] == dp[x][y-1])y--;
		else {
			ans.push_back(t[y-1]);
			x--,y--,cnt--;	
		}	
	}
	reverse(ans.begin() , ans.end());
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long maxn = 1000000000000000000;
    long long ans = 1;
    for(int i = 0; i < N; i++) {
        if(A[i] > maxn / ans) {
            cout << -1 << endl;
            return 0;
        } else {
            ans *= A[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4060