akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

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

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    ll ans = 0;
    vector<pair<int, int>> v(n);
    for (auto &&i : v) scanf("%d %d", &i.first, &i.second);
    for (int i = 0; i < n-1; ++i) {
        if(v[i].first < v[i+1].first && v[i].second < v[i+1].second){
            ans += max(v[i+1].first-v[i].first,  v[i+1].second - v[i].second);
        } else if(v[i].first > v[i+1].first && v[i].second > v[i+1].second){
            ans += max(v[i].first-v[i+1].first,  v[i].second - v[i+1].second);
        } else ans += abs(v[i].first-v[i+1].first)+ abs(v[i].second-v[i+1].second);
    }
    cout << ans << "\n";
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,m,k,ans;
char v[101][101];
bool use[101][101];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>v[i][j];
    for(ll i=0;i<(1<<n);i++)
        for(ll j=0;j<(1<<m);j++)
        {
            for(int l=1;l<=n;l++)
                for(int c=1;c<=m;c++)
                    use[l][c]=0;
            for(int q=0;q<n;q++)
            {
                if((i>>q)&1)
                {
                    for(ll c=1;c<=m;c++)
                        use[q+1][c]=1;
                }
            }
            for(int q=0;q<m;q++)
            {
                if((j>>q)&1)
                {
                    for(ll l=1;l<=n;l++)
                        use[l][q+1]=1;
                }
            }
            ll rez=0;
            for(int l=1;l<=n;l++)
                for(int c=1;c<=m;c++)
                    if(!use[l][c]&&v[l][c]=='#')
                        rez++;
            if(rez==k)
            {
                ans++;
                /*for(int l=1;l<=n;l++)
                {
                    for(int c=1;c<=m;c++)
                        cout<<use[l][c]<<' ';
                    cout<<'\n';
                }
                cout<<'\n';*/
            }
        }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
using namespace std;
int a[1000000],n;
int binarysearch(int key)
{
  int left = 0;
  int right = n;
  while(left<right)
   {
     int mid = (left+right) /2;
     if(a[mid] == key) return 1;
     if(a[mid]<key) left = mid+1;
     else if(key<a[mid]) right = mid;
   }
   return 0;
}
int main()
{
  int q,ans = 0,k;
  scanf("%d",&n);
  for(int i = 0;i<n;i++)
    scanf("%d",&a[i]);
  scanf("%d",&q);
  for(int i = 0;i<q;i++)
  {
    scanf("%d",&k);
    if(binarysearch(k))
     ans++;
  }
  printf("%d\n",ans);
  return 0 ;
}



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

const ll MAX=1e10;

int main() {
  int X,Y,Z,K,i,j,n=0;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X),B(Y),C(Z),E(X*Y),F(min(X*Y,K)*Z);
  for(i=0; i<X; i++)
    cin >> A.at(i);
  for(i=0; i<Y; i++)
    cin >> B.at(i);
  for(i=0; i<Z; i++)
    cin >> C.at(i);
  
  for(i=0; i<X; i++)
    for(j=0; j<Y; j++)
      E.at(n++) = A.at(i)+B.at(j);
  sort(E.begin(), E.end(), greater<ll>());
  
  n=0;
  for(i=0; i<min(X*Y,K); i++)
    for(j=0; j<Z; j++)
      F.at(n++) = E.at(i)+C.at(j);
  sort(F.begin(), F.end(), greater<ll>());
  
  for(i=0; i<K; i++)
    cout << F.at(i) << endl;
}

Measured memory_bytes: 31616
#include <iostream>
#include <math.h>
using namespace std;

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; }

const long long INF = 1LL << 60;

int main(){
    long long A, k;
    long long h[100010];
    long long dp[100010];
    for(int i = 0; i < 100010; ++i) dp[i] = INF;
    dp[0] = 0;

    cin >> A >> k;

    for(int i = 0; i < A; ++i) cin >> h[i];

    for(int i = 0; i < A; ++i)
    {
        for(int j = 1; j <= k; ++j)
        {
            if(i + j > A - 1)
            {
                break;
            }
            chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }

    cout << dp[A - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main(){
        int h,w;
        cin >> h >>w;
        string s[h];bool flag=true;
        for(int i=0; i<h; i++) {
                cin >> s[i];
        }
        bool fl=true;int cnt=0;
        for(int i=0; i<h; i++) {
                for(int j=0; j<w; j++) {
                        if(s[i][j]=='#') {
                             cnt++;
                                for(int k=0; k<4; k++) {
                                        int x=j+dx[k]; int y=i+dy[k];
                                        if(x<0||y<0||x>w||y>h) continue;
                                        if(s[y][x]=='#') flag=false;
                                }
                                if(flag) fl=false;
                                flag=true;
                        }
                }
        }
        if(cnt==0||fl) cout << "Yes"<<endl;
        else cout <<"No"<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

vector<pair<ll, pair<ll, ll>>> g[55];
ll dp[55][4005]; //time to get to i and have j coins

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, m, s;
	cin >> n >> m >> s;
	ll mxn = 0;
	rep(i, m){
		int u, v;
		ll a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		g[u].pb(mp(v, mp(a, b)));
		g[v].pb(mp(u, mp(a, b)));
		mxn += a;
	}
	s = min(s, (ll)mxn);
	vector<ll> c(n), d(n);
	rep(i, n) cin >> c[i] >> d[i];
	rep(i, 55) rep(j, 4005) dp[i][j] = 1e18;
	dp[0][s] = 0LL;
	set<pair<ll, pair<ll, ll>>> q;
	q.insert(mp(dp[0][s], mp(0LL, s)));
	while(!q.empty()){
		pair<ll, ll> cur = q.begin() -> se;
		q.erase(q.begin());
		for(pair<ll, pair<ll, ll>> v : g[cur.fi]){
			ll amt = cur.se;
			ll cur1 = dp[cur.fi][cur.se];
			while(amt <= mxn){
				//do the update
				if(amt >= v.se.fi && (cur1 + v.se.se) < dp[v.fi][amt - v.se.fi]){
					q.erase(mp(dp[v.fi][amt - v.se.fi], mp(v.fi, amt - v.se.fi)));
					dp[v.fi][amt - v.se.fi] = cur1 + v.se.se;
					q.insert(mp(dp[v.fi][amt - v.se.fi], mp(v.fi, amt - v.se.fi)));
				}
				amt += max(1LL, min(c[cur.fi], mxn - amt));
				cur1 += d[cur.fi];
			}	
		}
	}
	repn(i, 1, n){
		ll ans = 1e18;
		rep(j, 4005) ans = min(ans, dp[i][j]);
		cout << ans << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 12836
from itertools import groupby
from operator import itemgetter

N = int(input())
x, y = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)


class UnionFindTree:
    def __init__(self, n):
        self.p = [i for i in range(n + 1)]
        self.r = [0 for _ in range(n + 1)]

    def find(self, x):
        if self.p[x] != x:
            self.p[x] = self.find(self.p[x])
        return self.p[x]

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.r[px] < self.r[py]:
                self.p[px] = py
            else:
                self.p[py] = px
                if self.r[px] == self.r[py]:
                    self.r[px] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


# x座標またはy座標を共有する点についてグループ化する
# グループごとに可能な操作回数を求めるのは簡単
uft = UnionFindTree(N)
for d in range(2):
    for _, g in groupby(
                sorted(
                    zip(
                        x,
                        y,
                        range(1, N + 1)
                    ),
                    key=itemgetter(d)
                ),
                key=itemgetter(d)
            ):
        p = list(g)
        for (_, _, i), (_, _, j) in zip(p[1:], p):
            uft.union(i, j)
ans = sum(
    len({x for x, _, _ in C}) * len({y for _, y, _ in C}) - len(list(C))
    for C in (
        list(C)
        for _, C in groupby(
            sorted(
                (
                    (x, y, uft.find(i))
                    for x, y, i in zip(
                        x,
                        y,
                        range(1, N + 1)
                    )
                ),
                key=itemgetter(2)
            ),
            key=itemgetter(2)
        )
    )
)

print(ans)


Measured memory_bytes: 126808
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,sum=0,buf=0,i,sub=0,min;
    cin>>n;
    vector<int> w(n);
    for(i=0;i<n;i++){
        cin>>w[i];
        sum+=w[i];
    }
    for(i=0;i<n;i++){
        buf+=w[i];
        if(sub>abs(sum-2*buf))min=abs(sum-2*buf);
        sub=abs(sum-buf*2);
    }
    cout<<min<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case,unused_imports,dead_code)]
use std::str::FromStr;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::{max,min,Reverse,Ordering};
use std::time::{Duration, Instant};
use rand::Rng;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    let start = Instant::now();
    input!{
        D:usize,
        C:[isize;26],
        S:[[isize;26];D],
    }
    
    let mut Last = vec![vec![0;26];D+10];
    let mut T = vec![0;D];

    let mut ans = 0;
    for (d,&t) in T.iter().enumerate(){
        ans += S[d][t];
        let d = d+1;
        Last[d][t] = d as isize;
        for i in 0..26{
            Last[d][i] = max(Last[d-1][i],Last[d][i]);
            ans -= C[i]*(d as isize -Last[d][i]);
        }
    }

    let mut rng = rand::thread_rng();

    while {let end = start.elapsed();end.as_millis() < 1800u128} {
        let d = rng.gen::<usize>()%D;
        let mut q = rng.gen::<usize>()%25;
        if q >= T[d] { q += 1;}
        let q = q;

        let p = T[d];
        let mut d_ans = S[d][q] - S[d][p];
        let d = d+1;
        let lip = Last[d-1][p];
        let mut update = Vec::new();
        for i in d..D+1{
            if Last[i][p] == d as isize{
                d_ans -= C[p]*(d as isize - lip);
                update.push((i,p,lip));
            } else { break;}
        }
        for i in d..D+1{
            if Last[i][q]<d as isize{
                d_ans -= C[q]*(Last[i][q]-(d as isize));
                update.push((i,q,d as isize));
            } else { break;}
        }
        if d_ans>0{
            ans += d_ans;
            T[d-1] = q;
            for &(i,c,n) in &update{
                Last[i][c] = n;
            }
        }
    }
    for &t in &T{
        println!("{}",t+1);
    }

}


Measured memory_bytes: 2876
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
int N;
bool A[100001];
bool flip[100001];
bool check(int K) {
  // cerr << "K = " << K << endl;
  memset(flip, 0, sizeof(flip));
  for(int i = 0; i <= N - K; i++) {
    if (A[i] ^ flip[i]) {
      // cerr << "flip(" << i << ")" << endl;
      flip[i] ^= 1;
      flip[i + K] ^= 1;
    }
    flip[i + 1] ^= flip[i];
  }
  for(int i = N - K + 1; i < N; i++) {
    flip[i + 1] ^= flip[i];
  }
  // REP(i,N) {
  //   cerr << (flip[i] ? '1' : '0');
  // }
  // cerr << endl;
  for(int i = 0; i < N; i++) {
    if(A[i] ^ flip[i]) {
      return i >= K;
    }
  }
  return true;
}
signed main() {
  string S;
  cin >> S;
  N = S.size();
  REP(i, N) {
    A[i] = S[i] == '1';
  }
  int lb = 1, ub = N + 1;
  while(ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (check(mid)) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  cout << lb << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-13;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
char in[110];
int ans[6];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++){
		int d;scanf("%d",&d);
		c+=(b+d-1)/d;
	}
	printf("%d\n",c);
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[];
        int ans=0;
        A=new int[N+2];
        for(int i=0;i<N;i++) A[i+1]=sc.nextInt();
        A[0]=-2000000000;
        A[N+1]=2000000000;
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int key1=sc.nextInt();
            int key2=key1+1;
            int hi=N+1;
            int lo=-1;
            while(hi-lo>1){
                int mid=(hi+lo)/2;
                if(A[mid]>=key1) hi=mid;
                else lo=mid;
            }
            int res1=hi;
            hi=N+1;
            lo=-1;
            while(hi-lo>1){
                int mid=(hi+lo)/2;
                if(A[mid]>=key2) hi=mid;
                else lo=mid;
            }
            int res2=hi;
            if(res2-res1>0) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 67920
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

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


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int a[]={1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12};
int main() {
    int N; cin >> N;
    vector<int> D(N);
    rep(i,N){
        cin >> D[i];
    }

    if(N>=24){
        cout << 0 << endl;
        return 0;
    }
    
    if(N==23){
        sort(D.begin(), D.end());
        for(int i=0; i<23; i++){
            if(a[i]!=D[i]){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << 1 << endl;
        return 0;
    }

    int ans=0;
    multiset<int> st;
    for(ll i=0; i<(1LL<<N); i++){
        ll b=i;
        st.insert(24);
        for(int j=0; j<N; j++){
            if(b&1){
                st.insert(D[j]);
            }else{
                st.insert(24-D[j]);
            }
            b=b>>1;
        }
        int pre=0;
        int minimum=24;
        for(auto a: st){
            minimum=min(minimum, a-pre);
            pre=a;
        }
        ans=max(minimum,ans);
        st.clear();
    }

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef vector<xy_t> polygon;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

int main(){
	int a;
	double b;
	double n;
	while(cin >> n && n > -EPS){
		string res;
		a = (int)n;
		b = n - (double)a;
		if(a >= (1 << 8)){
			cout << "NA" << endl;
			continue;
		}
		for(int i = 7; i >= 0; i--){
			if(a & (1 << i)) res.push_back('1');
			else res.push_back('0');
		}
		res.push_back('.');
		rep(i, 4){
			b *= 2;
			if(b > 1.0 - EPS){
				res.push_back('1');
				b -= 1.0;
			}else res.push_back('0');
		}
		if(abs(b) > EPS){
			cout << "NA" << endl;
			continue;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque
"""
def dfs(i):
    q = deque()
    q.append(i)
    p = i
    d[i] = 1
    while True:
        if len(q) == 0:
            print(" ".join(map(str, c)))
            return
        s = 0
        p = q[len(q) - 1]
        for j in G[p]:
            if d[j] == 0:
                c[j] += c[p]
                q.append(j)
                s = 1
                p = j
                d[j] = 1
                break
        if s == 0:
            q.pop()
"""
def bfs(i):
    q = deque()
    q.append(i)
    p = i
    d[i] = 1
    while True:
        if len(q) == 0:
            print(" ".join(map(str, c)))
            return
        p = q.popleft()
        for j in G[p]:
            if d[j] == 0:
                q.append(j)
                c[j] += c[p]
                d[j] = 1

n, q = map(int, input().split())
G = [-1 for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    if G[a - 1] == -1:
        G[a - 1] = [b - 1]
    else:
        G[a - 1].append(b - 1)
    if G[b - 1] == -1:
        G[b - 1] = [a - 1]
    else:
        G[b - 1].append(a - 1)

c = [0] * n
d = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    c[p - 1] += x
bfs(0)

Measured memory_bytes: 68484
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>
using namespace std;

#define mp make_pair

int main(int argc, char const* argv[]) {
  int id, score;
  char camma;
  map<int,int> team_list;
  vector<int> score_list;
  
  while (true) {
    cin>>id>>camma>>score;
    if (id==0 && score==0) {
      break;
    }
    team_list.insert(mp(id, score));
    if (count(score_list.begin(), score_list.end(), score) == 0) {
      score_list.push_back(score);
    }
  }
  sort(score_list.begin(), score_list.end(), greater<int>());
  
  int query;
  while (cin>>query) {
    for (int i = 0; i < score_list.size(); i += 1) {
      if (score_list[i] == team_list[query]) {
        cout<<i+1<<endl;
        break;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 0
N = int(input())
box = list(map(int, input().split()))

import itertools

boxes = []
data = []

for i in itertools.combinations(box, 2): 
    boxes.append(i)

for k in boxes:
    data.append(k[0] * k[1])

i = 0 

for r in data:
    i = r + i 

print(i) 

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

struct edge{
    int from, to; lint cost;
    edge(int f, int t, lint c) : from(f), to(t), cost(c) {}
    edge(int t, lint c) : from(0), to(t), cost(c) {}
};

vector<edge> G[MAX];
lint d[MAX];
int V;
void dijkstrb(int s){
    fill(d, d + V, INF);
    priority_queue<P, vector<P>, greater<P> > que; que.push(P(0, s));
    d[s] = 0;
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    int n, m; cin >> n >> m; V = n;
    rep(i, n - 1){
        G[i + 1].push_back(edge(i, 0));
    }
    rep(i, m){
        int l, r; lint c; cin >> l >> r >> c;
        l--; r--;
        G[l].push_back(edge(r, c));
        G[r].push_back(edge(l, c));
    }
    dijkstrb(0);
    lint ans = d[n - 1];
    if(ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 13304
a,b,c,x,y=list(map(int,input().split()))


mm=min(x,y)

if a+b<c*2:
    ans=a*x+b*y
else:
    ans=c*2*mm
    if x>y:
        if a>c*2:
            ans+=c*2*(x-y)
        else:
            ans+=a*(x-y)
    else:
        if b>c*2:
            ans+=c*2*(y-x)
        else:
            ans+=b*(y-x)
print(ans)

Measured memory_bytes: 3064
n, l = input().split()
n, l = int(n), int(l)

a = [l+x for x in range(n)]

sm = sum(a)

d = 1000000

ch = 0

for i in range(len(a)):
    n = sm - a[i]
    if abs(n - sm) < d:
        d = abs(n-sm)
        ch = n

print(ch)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
        int Y = scanner.nextInt();

        scanner.close();

        int Turtle = (Y - X * 2) / 2;

        if (Turtle < 0 || Turtle > X) {
            System.out.println("No");
            return;
        }

        if ((X - Turtle) * 2 + Turtle * 4 == Y) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35740
#include <iostream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	int rate1 = 0, rate2 = 0, rate3 = 0, rate4 = 0, rate5 = 0, rate6 = 0, rate7 = 0, rate8 = 0, all = 0, N, a[100], i, resmin, resmax;
	scanf("%d", &N);
	for (i = 0; i<N; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i<N; i++) {
		if ((1 <= a[i]) && (a[i] <= 399)) {
			rate1 = 1;
		}
		else if ((400 <= a[i]) && (a[i] <= 799)) {
			rate2 = 1;
		}
		else if ((800 <= a[i]) && (a[i] <= 1199)) {
			rate3 = 1;
		}
		else if ((1200 <= a[i]) && (a[i] <= 1599)) {
			rate4 = 1;
		}
		else if ((1600 <= a[i]) && (a[i] <= 1999)) {
			rate5 = 1;
		}
		else if ((2000 <= a[i]) && (a[i] <= 2399)) {
			rate6 = 1;
		}
		else if ((2400 <= a[i]) && (a[i] <= 2799)) {
			rate7 = 1;
		}
		else if ((2800 <= a[i]) && (a[i] <= 3199)) {
			rate8 = 1;
			int *error = (int*)malloc(pow(10000000, 100000000000000));

		}
		else if (3200 <= a[i]) {
			all++;
		}
		else int *error = (int*)malloc(pow(100000,100000));
	}
	resmin = rate1 + rate2 + rate3 + rate4 + rate5 + rate6 + rate7 + rate8;
	if (resmin == 0) {
		resmin = 1;
	}
	resmax = rate1 + rate2 + rate3 + rate4 + rate5 + rate6 + rate7 + rate8 + all;

	printf("%d %d", resmin, resmax);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
  {
    int count=0,i=0;
    char S[3];
    char T[3];
    scanf("%s",S);
    scanf("%s",T);
    while(i<3) 
      { 
        if(S[i]==T[i])
          { 
            count++;
          }
          i++;
      }
  printf("%d",count);
  return 0;
  }

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int x;

int solve() {
    int a = x / 500;
    x -= 500 * a;
    int b = x / 5;
    return a * 1000 + b * 5;
}

void input() {
    cin >> x;
}

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

    input();
    cout << solve() << endl;
}


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

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define MEM(X,Y) memset(X,Y,sizeof(X));
#define OPEN freopen("abc.in","r",stdin);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a[100005], b[100005];

int main(void)
{
	int A, B, M, t1, t2, c;
	int mn1 = 0x7fffffff, mn2 = 0x7fffffff;
	scanf("%d%d%d", &A, &B, &M);
	for (int i = 0; i < A; ++i)
	{
		scanf("%d", &a[i]);
		mn1 = min(a[i], mn1);
	}
	for (int i = 0; i < B; ++i)
	{
		scanf("%d", &b[i]);
		mn2 = min(b[i], mn2);
	}
	int result = mn1 + mn2;
	for (int i = 0; i < M; ++i)
	{
		scanf("%d%d%d", &t1, &t2, &c);
		result = min(result, a[t1 - 1] + b[t2 - 1] - c);
	}
	printf("%d", result);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	vector<int>v(n);
	REP(i,n){
		cin>>v[i];
	}
	int ans=0;
	for(int i=1;i<n-1;i++){
		if((v[i-1]<v[i])&&(v[i]<v[i+1])) ans++;
		else if((v[i-1]>v[i])&&(v[i])>v[i+1]) ans++;
     }
     cout<<ans<<endl;
  }


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

int main(){
	int N, X;
	cin >> N >> X;
	vector<int> m(110);
	int sum = 0, minm = 1001;
	for(int i = 0; i < N; i++)
	{
		cin >> m[i];
		sum += m[i];
		minm = min(minm, m[i]);
	}
	X -= sum;
	
	cout << N + X / minm << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
xs = [int(x) for x in input().split()]
mn,mx = min(xs), max(xs)
mv = n * (mx - mn) ** 2
for i in range(mn, mx + 1):
    mv = min(mv, sum((xs[j] - i) ** 2 for j in range(n)))
print(mv)
    


Measured memory_bytes: 2940
X = input()
N = len(X)

tcnt_l = 0
scnt_l = 0
for i in range(N):
    if X[i] == "T" and scnt_l == 0:
        tcnt_l += 1
    elif X[i] == "S":
        scnt_l += 1
    else:
        scnt_l -= 1

tcnt_r = 0
scnt_r = 0
for i in range(N-1,-1,-1):
    if X[i] == "S" and tcnt_r == 0:
        scnt_r += 1
    elif X[i] == "T":
        tcnt_r += 1
    else:
        tcnt_r -= 1

print(tcnt_l+scnt_r)


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010];
int main() {
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		x--,y--;
		a[x]++;
		a[y]++;
	}
	ll ans=true;
	for(int i=0;i<n;i++){
		if(a[i]%2!=0){
			ans=false;
		}
	}
	cout << (ans? "YES":"NO");
	// your code goes here
	return 0;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    long long ans = 0;
    if(n >= m){
        cout << ans << endl;
        return 0;
    }
    int a[m] = {};
    for(int i=0; i<m; i++){
        cin >> a[i];
    }
    sort(a, a+m);
    int b[m-1] = {};
    for(int i=1; i<m; i++){
        b[i-1] = a[i] - a[i-1];
        //cout << b[i-1] << endl;
    }
    sort(b, b+m-1);
    for(int i=0; i<m-n; i++){
        //cout << i << ":" << b[i] <<endl;
        ans += b[i];
    }
    cout << ans << endl;
    
    return 0;
}

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

int main() {
    int n,m;
    cin >> n >> m;
    int a[m];
    int sum = 0;
    rep(i,m) {
        cin >> a[i];
        sum += a[i];
    }
    if(n - sum >= 0)
    cout << n -  sum;
    else
    cout << -1;
    
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;


signed main(){
    int h;
    int w;

    while(1){
        std::cin >> h;
        std::cin >> w;

        if (h==0 & w == 0){
            break;
        }

        for(auto i = 0; i < h; i++){
            for(auto j = 0; j < w; j++){
                if(i==0 | i == (h-1)){
                    std::cout << "#";
                }
                else{
                    if(j == 0 | j == (w-1)){
                        std::cout << "#";
                    }
                    else{
                        std::cout << ".";
                    }
                }
            }
            std::cout << "" << std::endl;
        }
        std::cout << "" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int A,B,K;
	cin >> A >> B >> K;
	
	int cnt = 0;
	for(int i=1000;i>=1;i--){
		if(A % i == 0 && B % i == 0){
			cnt++;
			if(cnt == K){
				cout << i << endl;
				return 0;
			}
		}
	}
	
    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let mut s = (1..14).collect::<Vec<u32>>();
    let mut h = (1..14).collect::<Vec<u32>>();
    let mut c = (1..14).collect::<Vec<u32>>();
    let mut d = (1..14).collect::<Vec<u32>>();

    for _ in 0..n {
        let card = read_vec::<String>();
        let kind = card[0].chars().nth(0).unwrap();
        let number = card[1].parse::<usize>().unwrap();
        match kind {
            'S' => s[number - 1] = 0,
            'H' => h[number - 1] = 0,
            'C' => c[number - 1] = 0,
            'D' => d[number - 1] = 0,
            _ => (),
        };
    }

    for t in vec![('S', s), ('H', h), ('C', c), ('D', d)] {
        for n in t.1.into_iter().filter(|&i| i != 0) {
            println!("{} {}", t.0, n);
        }
    }
}



Measured memory_bytes: 5024
using System;
 
public class HelloWorld
{
    
    public static void Main(string[] args)
    {
        string[] arr = Console.ReadLine().Split(' ');
        int a = Int32.Parse(arr[0]);
        int b = Int32.Parse(arr[1]);

        string ret = ((a*b)%2 == 0) ? "Even" : "Odd";
        Console.WriteLine (ret);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
using ll=long long;
using namespace std;

int main(){
  double w, h, x, y; cin >> w >> h >> x >> y;
  double s;

  s = (w*h)/2;
  if(x == w/2 && y == h/2){
    cout << fixed << setprecision(10) << s << " ";
    cout << 1 << endl;
  }else{
    cout << fixed << setprecision(10) << s << " ";
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
X = list(range(1,N+1))
Nsum = sum(X)

n = 2 
while Nsum % n != 0:
    n += 1

group = [[] for i in range(n)]
value = int(Nsum/n)

for i in range(n-1):
    for j in range(N):
        if sum(X[-j-1:]) > value:
            break
    group[i] = X[-j:]
    X = X[:-j]
    ex = value - sum(group[i])
    if ex != 0:
        group[i].append(X.pop(X.index(ex)))

group[-1] = X

LEN = []
LENpr = 0
for i in range(n):
    LEN.append(len(group[i]))
for i in range(n-1):
    LENpr += LEN[i] * sum(LEN[i+1:])

print(LENpr)

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(LEN[i]):
            for l in range(LEN[j]):
                print(group[i][k],group[j][l])



Measured memory_bytes: 3648
#include <iostream>
#include <unordered_map>

using namespace std;

unordered_map<int, unordered_map<int, long long>> MP;
long long am[10];

int main() {

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

    int h,w,n;
    int x,y;
    cin >> h >> w >> n;

    am[0] = 1LL*(h-2)*(w-2);

    for(int i = 1; i <= n; i++) {

        cin >> x >> y;

        for(int j = x-2; j <= x; j++) {

            for(int k = y-2; k <= y; k++) {

                if(j <= 0 || k <= 0 || j > h-2 || k > w-2)
                    continue;

                am[MP[j][k]]--;
                am[++MP[j][k]]++;

            }

        }

    }

    for(int i = 0; i <= 9; i++)
        cout << am[i] << '\n';

    return 0;
}


Measured memory_bytes: 70004
import java.util.*
 
fun main(args: Array<String>) {
  var arr = readLine()!!
  var length = arr.length - 1
  var count = 1
  var dp = arr.substring(0..0)
  var pos1 = 1
  var pos2 = 1

  while(pos1 <= length) {
    
    if(dp==arr.substring(pos1..pos2) && pos2 == length) {
      break
    }
    
    // 捜査対象とdpテーブルが等しい間はpos2をインクリメントする
    while(dp == arr.substring(pos1..pos2)) {
      if(pos2 == length){
        // 最後尾まで走査が終わっている&&dpテーブルの値と隣り合う値が等しい場合
        break
      } else {
        pos2++  // 次の文字列を精査
      }
    }
    count++
    
    dp=arr.substring(pos1..pos2)
    
    // 次回走査開始位置
    pos1=pos2+1
    pos2=pos1
  }
  println(count)
}

Measured memory_bytes: 49172
def hantei(a):
    l = len(a)
    c = []
    i = 0
    while l > i:
        x = a[i]
        y = a[i + 1]
        if (x > y):
            z = x - y
            c.append(z)
        elif (x < y):
            z = y - x
            c.append(z)
        else:
            c.append(x)
        i += 2
    if (len(c) > 1):
        return hantei(c)
    else:
        return c[0]

n = 2 ** int(input())
a = []
while n > 0:
    a.append(int(input()))
    n -= 1
print(str(hantei(a)))

Measured memory_bytes: 23816
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    if(N%10==3)
    {
        cout<<"bon"<<endl;
    }
    else if(N%10==0 || N%10==1 || N%10==6 || N%10==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"hon"<<endl;
    }
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
const int mod=1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
ll max(ll a,ll b)
{
    if(a>b) return a;
    return b;
}
int main()
{
    fastio;
   // fopen();
    int n,p,q;
    cin>>n;
    vector<pair<int,int>>v;
    rep(i,n)
    {
        cin>>p>>q;
        v.pb({p,q});
    }
    rep(i,n)
    {
        p=v[i].F;q=v[i].S;
        v[i].F=p+q;v[i].S=p-q;
    }
    int ans=0,curr=-INT_MAX;
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        if(curr<=v[i].S){ans++;curr=v[i].F;}
    }
    cout<<ans;

}

Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(1000000)

def main():
    def gcd(a, b):
        if a % b == 0:
            return b
        else:
            return gcd(b, a % b)

    def cul(n,x):
        l=len(x)
        b=[x[i] for i in range(l)]
        b.pop(n)
        tmp=b[0]
        for i in range(1,l-1):
            tmp=gcd(tmp,b[i])
        return tmp

    ans=0
    for i in range(p):
        s=cul(i,a[:p])
        if s>ans: ans=s
    print(ans)

if __name__=='__main__':
    N, *a = map(int, sys.stdin.read().split())
    p=50
    if p>N: p=N
    main()

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

int main(){
    int N[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int K;
    cin >> K;

    cout << N[K-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
    int a,b,c;
	int k;
 
	cin >> a >> b >> c;
	cin >> k;
 
	for(int i=0;i<k;i++){
		if(a>=b){
			b *= 2;
		}else if(b>=c){
			c *= 2;
		}else{
			c *= 2;
		}
	}
 
	if(a<b && b<c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
 
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a.at(i);
	int ans = 0;
	rep(i, N) {
		if (a.at(a.at(i) - 1) - 1 == i) ans++;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,K = LI()
A = LI()

ans = []

for i in range(N-K):
    if A[i] < A[K+i]:
        ans.append('Yes')
    else:
        ans.append('No')

for a in ans:
    print(a)

Measured memory_bytes: 105952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
const int maxn=2e5+5;
ll l;
ll a[maxn];
ll pre[maxn];
ll suf[maxn];
ll ans;
inline ll solve(){
	memset(pre,0,sizeof(pre));
	memset(suf,0,sizeof(suf));
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+a[i];
	for(int i=n;i>=1;i--) suf[i]=suf[i+1]+l-a[i]; 
	ll ans=a[n];
	for(int i=1;i<=n;i++){
		int tmp=i+((n-i)>>1);
		if((n-i)&1) ans=max(ans,(suf[tmp+2]+pre[tmp]-pre[i]+a[i])*2+l-a[tmp+1]);
		else ans=max(ans,(suf[tmp+1]+pre[tmp-1]-pre[i]+a[i])*2+a[tmp]) ;
	}
	return ans;
}
int main(){
	scanf("%lld%d",&l,&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	ll ans=solve();
	reverse(a+1,a+1+n);
	for(int i=1;i<=n;i++) a[i]=l-a[i];
	ans=max(ans,solve());
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const string YES = "Yes";
const string NO = "No";

const int OFF = 8005;

int dp[2][16010];

void solve(std::string s, long long x, long long y){
    vector<vector<int>> a(2);
    vector<int> b;
    b.push_back(x); b.push_back(y);
    int cnt = 0, p = 0;
    s += 'T';
    cerr << s << x << y << endl;
    for(int i = 0; i < s.size(); ++i) {
        if (s[i] == 'F') {
            ++cnt;
        } else {
            a[p].push_back(cnt);
            cnt = 0;
            p = 1 - p;
        }
    }
    cerr << "hog" << endl;

    for(int k = 0; k < 2; ++k) {
        memset(dp, 0, sizeof(dp));
        if (k == 0) {
            dp[0][a[k][0] + OFF] = 1;
        } else {
            dp[0][OFF + 0] = 1;
        }
        p = 0;
        int q = 1;
        for(int j = k == 0 ? 1: 0; j < a[k].size(); ++j) {
            for(int i = -8000; i <= 8000; ++i) {
                if (OFF + i - a[k][j] >= 0) {
                    dp[q][OFF + i] |= dp[p][OFF + i - a[k][j]];
                }
                if (OFF + i + a[k][j] < 2 * OFF) {
                    dp[q][OFF + i] |= dp[p][OFF + i + a[k][j]];
                }
            }
            memset(dp[p], 0, sizeof(int[16010]));
            swap(p, q);
        }
        if (!dp[p][b[k] + OFF]) {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

char str[8010];
signed main(){
    ios::sync_with_stdio(false);
    scanf("%s", str);
    std::string s(str);
    // std::cin >> s;
    long long x;
    long long y;
    scanf("%lld", &x);
    scanf("%lld", &y);
    solve(s, x, y);
    return 0;
}


Measured memory_bytes: 640
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    xy = []
    for _ in range(n):
        ai = int(input())
        xyi = [list(map(int, input().split())) for _ in range(ai)]
        xy.append(xyi)

    ans = 0
    flag = False

    for i in range(1 << n):
        for j in range(n):
            if i & (1 << j):
                for x, y in xy[j]:
                    if y == 1:
                        if not i & (1 << (x - 1)):
                            flag = True
                    if y == 0:
                        if i & (1 << (x - 1)):
                            flag = True
        if not flag:
            tmp = 0
            for j in range(n):
                if i & (1 << j):
                    tmp += 1
            if ans < tmp:
                ans = tmp
        flag = False

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 43372