akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const ll N=1100,M=1001001;
ll n,m,T,cnt,f[N][N],p[M],col[N][N],a[N],x,y,z,ans;
string s;
int main() 
{
	cin>>s;
	if (s[2]==s[3]&&s[4]==s[5]) puts("Yes"); else puts("No");
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <limits>
#include <iomanip>

using namespace std;

int main() {
    int maxX = -1000000;
    int minY = 1000000;
    bool flag = false;
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        maxX = max(a, maxX);
    }

    for(int i = 0; i < m; i++) {
        int b;
        cin >> b;
        minY = min(b, minY);
    }

    for(int i = x+1; i <= y; i++) {
        if(maxX < i && i <= minY) flag = true;
    }

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

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	inn(a, b);

	rep(i, lim5) {
		if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
			out(i);
			return 0;
		}
	}

	out(-1);
	return 0;
}


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

long long int h, w;

long long int dfs(long long int h, long long int w, long long int mx, long long int mn, long long int divnum){
        if(divnum==1){
                return max(h*w, mx)-min(h*w, mn);
        }
        if(h%divnum==0) return dfs(h/divnum, w, mx, mn, 1);
        if(w%divnum==0) return dfs(h, w/divnum, mx, mn, 1);
        long long int dif, nb;
        nb=h/divnum;
        dif=dfs(h-nb, w, max(nb*w, mx), min(nb*w, mn), divnum-1);
        nb=h/divnum+1;
        dif=min(dfs(h-nb, w, max(nb*w, mx), min(nb*w, mn), divnum-1), dif);
        nb=w/divnum;
        dif=min(dfs(h, w-nb, max(h*nb, mx), min(h*nb, mn), divnum-1), dif);
        nb=w/divnum+1;
        dif=min(dfs(h, w-nb, max(h*nb, mx), min(h*nb, mn), divnum-1), dif);
        return dif;
}

int main(){
        cin>>h>>w;
        cout<<dfs(h, w, 0, LLONG_MAX, 3)<<endl;
        return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a[5];
    for(ri int i=0;i<3;i++) a[i]=read();
    sort(a,a+3);
    int qwq=1;
    for(ri int i=1;i<3;i++)
    {
        if((a[i]&1ll) != (a[i-1]&1ll)) qwq=0;
    }
    if(qwq)
    {
        int res=(a[1]-a[0])/2;
        res+=(a[2]-a[1]);
        printf("%lld\n",res);
    }
    else
    {
        int b[5];
        for(ri int i=0;i<3;i++) b[i]=(a[i]&1ll);
        int p,q; p=q=0;
        for(ri int i=0;i<3;i++) p+=b[i];
        q=3-p;
        if(p==2)
        {
            for(ri int i=0;i<3;i++) if(a[i]&1ll) a[i]++;
            sort(a,a+3);
            int res=(a[1]-a[0])/2;
            res+=(a[2]-a[1]);
            printf("%lld\n",res+1);
        }
        else
        {
            for(ri int i=0;i<3;i++) if(a[i]%2==0) a[i]++;
            sort(a,a+3);
            int res=(a[1]-a[0])/2;
            res+=(a[2]-a[1]);
            printf("%lld\n",res+1);
        }
    }
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m, Q;
    cin >> n >> m >> Q;

    vvl a(n, vl(n));  // a[i][j] : 始点がi、終点がjの列車の個数
    rep(i, m) {
        ll L, R;
        cin >> L >> R;
        L--;  R--;
        a[L][R]++;
    }

    vvl rui(n+1, vl(n+1));  // rui[i][j] : [0, i) × [0, j) 長方形区域の和
    rep(i, n) {
        rep(j, n) {
            rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] - rui[i][j] + a[i][j];
        }
    }
    
    vl ans(Q);
    rep(i, Q) {
        ll p, q;
        cin >> p >> q;
        p--;  q--;
        ll x1 = p, x2 = n;
        ll y1 = 0, y2 = q+1;
        ans[i] = rui[x2][y2] - rui[x1][y2] - rui[x2][y1] + rui[x1][y1];  // [x1, x2) × [y1, y2) 長方形区域の和
    }
    
    rep(i, Q) {
        out(ans[i]);
    }

    re0;
}

Measured memory_bytes: 5632
def enq(a,x)
  b = a[i=-1]
  until b.frozen?
    return a << x  if x >= (a=b)[-1]
    return a.unshift x  if x <= a[0]
    b = a[i = a.bsearch_index{|y| x < (y.frozen? ? y: y[0])}-1]
  end  if b && b=a
  a[i+9] or return a.insert i+1, x
  i>0 ? a[i]=[b,x] : enq(a[i+=1].to_a,x)  rescue a[i]=[x,a[i]]
end
def deq(a) r=a.shift; a[0].frozen? or a.unshift *a.shift; r end
def poq(a) r=a.pop; a[-1].frozen? or a.push *a.pop; r end
N,M,*A = $<.read.split.map{|x| x.to_i}
A.sort!
M.times { break if A[-1]==0; enq A, (poq A)/2 }
p A.flatten.inject(0,:+)

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  vector<pair<int,int>> p(N);
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i];
    p[i]=make_pair(B[i],A[i]);
  }
  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=p[i].second;
    if(sum>p[i].first){cout << "No" << endl; return 0;}
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main() {   
    int a, b; cin >> a >> b;
    cout << a * b << ln;
}



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

int main()
{
  int a,b,c,d;
  string ans;
  cin >>a >>b >>c >>d;

  int left=a+b;
  int right=c+d;

  if(left>right)
    ans ="Left";
  else if(left<right)
    ans ="Right";
  else
    ans ="Balanced";

  cout << ans <<endl;

  return 0;

}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
    int x,k,d;
    cin>>x>>k>>d;
    if(x<0)x*=-1;
    int mn = x/d;
    
    
    if(k<=mn){
        x-=k*d;
        cout<<x<<"\n";
    }
    else{
        x-=mn*d;
        int left = k-mn;
        if(left%2==0){
            // cout<<abs(x)<<"\n";
            cout<<x<<"\n";
        }
        else{
            cout<<abs(x-d)<<"\n";
        }
    }
}

Measured memory_bytes: 5988
use std::io::BufRead;
use std::str::FromStr;
use std::fmt::Debug;

struct Scanner<R: BufRead> {
    buf_reader: R,
}

impl<R: BufRead> Scanner<R> {
    // 値を作成するコンストラクタ
    fn new(buf_reader: R) -> Self {
        Scanner {buf_reader: buf_reader}
    }
    // １行を読み取りベクタを作成する
    fn read_line<T>(&mut self) -> Vec<T> where T: FromStr, <T as FromStr>::Err: Debug {
        let mut line = String::new();
        self.buf_reader.read_line(&mut line).unwrap();
        line.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut scanner = Scanner::new(stdin.lock());

    let l1 = scanner.read_line::<u32>();
    let n = l1[0];

    let mut seq = scanner.read_line::<i32>();
    let mut cnt = 0;

    for i in 0..n {
        for j0 in i..n-1 {
            let j = n + i - 1 - j0;
            if seq[j as usize] < seq[(j-1) as usize] {
                let tmp = seq[j as usize];
                seq[j as usize] = seq[(j-1) as usize]; 
                seq[(j-1) as usize] = tmp;
                cnt += 1;
            } 
        }
    }

    let mut out: String = String::new();
    out.push_str(&seq[0].to_string());
    for i in 1..n {
        out.push(' ');
        out.push_str(&seq[i as usize].to_string());
    }
    println!("{}", out);
    println!("{}", cnt);
}


Measured memory_bytes: 5040
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

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


signed main(void) {
	ll n, k;

	cin >> n >> k;

	vector<ll> a(n), f(n);

	REP(i, n)
		cin >> a[i];
	REP(i, n)
		cin >> f[i];

	sort(ALL(a), greater<ll>());
	sort(ALL(f));

	ll l = -1, r = 1000000000001;
	while (r - l > 1) {
		ll mid = (l + r) / 2;
		ll sum = 0;

		REP(i, n) {
			sum += max(a[i] - mid / f[i],0LL);
		}

		if (sum > k)
			l = mid;
		else
			r = mid;
	}


	cout << r << endl;
	return 0;
}
 

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 100007
using namespace std;


int main(){
    int n,x,y;
    cin>>n>>x>>y;
    int d[n+1][n+1],ans[n+1];
    memset(ans,0,sizeof(ans));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            ans[min({abs(j-i),abs(x-i)+1+abs(j-y),abs(x-j)+1+abs(i-y)})]++;
        }
    }
    for(int j=1;j<n;j++) cout<<ans[j]/2<<endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int M = 1e9 + 7;

int f[5003], inv[5003], fi[5003];

int32_t main()
{
	IO_OP;
	
	f[0] = 1;
	for(int i=1;i<5003;i++)
		f[i] = f[i-1] * i % M;
	inv[1] = 1;
	for(int i = 2; i < 5003; ++i)
	    inv[i] = (M - (M/i) * inv[M%i] % M) % M;
	fi[0] = 1;
	for(int i=1;i<5003;i++)
		fi[i] = fi[i-1] * inv[i] % M;
	
	int n, k;
	cin >> n >> k;
	cout << n-k+1 << endl;
	for(int g=2;g<=k;g++) {
		int ans = 0;
		if(g-1 <= n-k){
			int j = g-1;
			ans += f[k-1] * fi[g-1] % M * fi[k-g] % M * f[n-k-1] % M * fi[j-1] % M * fi[n-k-j] % M;
		}
		if(g <= n-k){
			int j = g;
			ans += 2 * f[k-1] * fi[g-1] % M * fi[k-g] % M * f[n-k-1] % M * fi[j-1] % M * fi[n-k-j] % M;
		}
		if(g+1 <= n-k){
			int j = g+1;
			ans += f[k-1] * fi[g-1] % M * fi[k-g] % M * f[n-k-1] % M * fi[j-1] % M * fi[n-k-j] % M;
		}
		cout << ans % M << endl;
	}
}



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

int main()
{
    int N;
    cin >> N;
    vector<ll> H(N), diff(N - 1);
    rep(i, N)
    {
        cin >> H.at(i);
    }
    rep(i, N - 1)
    {
        if (H.at(i) - H.at(i + 1) < 0)
        {
            diff.at(i) = 0;
        }
        else
        {
            diff.at(i) = 1;
        }
    }
    int ans = 0;
    int count = 0;
    rep(i, N - 1)
    {
        if (diff.at(i) == 1)
        {
            count++;
        }
        else
        {
            if (ans < count)
            {
                ans = count;
            }
            count = 0;
        }
    }
    if (ans < count)
    {
        ans = count;
    }
    cout << ans << endl;
}

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

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

    if((int)str.length() <= k)
    {
        cout << str << endl;
        return 0;
    }

    for(int i = 0; i < k; ++i)
    {
        cout << str[i];
    }
    cout << "..." << endl;
}

Measured memory_bytes: 3628
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
    if a[i] == a[i+1]:
        ans += 1
        a[i+1] = (a[i+1] + 1) % 10000
        if i != (n-2) and a[i+1] == a[i+2]:
            a[i+1] = (a[i+1] + 1) % 10000

print(ans)


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, l := intScanner(), intScanner()
	as := intSliceScanner(n)
	idx := -1
	for i := 0; i < n-1; i++ {
		if as[i]+as[i+1] >= l {
			idx = i
		}
	}
	if idx >= 0 {
		fmt.Println("Possible")
		for i := 0; i < idx; i++ {
			fmt.Println(i + 1)
		}
		for i := n - 2; i > idx; i-- {
			fmt.Println(i + 1)
		}
		fmt.Println(idx + 1)
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 5104
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define PI acos(-1)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

ll n,m,v,p;
bool sortbysec(const ll &a,const ll &b) 
{ 
	return (a>b);
} 

bool binary_search(ll pos,ll *a)
{
	ll sum=0,i;
	if((a[pos]+m)<a[p-1])
		return false;
	else
	{
		sum=m*(p-1)+(n-pos-1)*m+m;

		for(i=p-1;i<pos;++i)
		{
			sum+=min(m,a[pos]+m-a[i]);
		}			
	}

	if(sum<(m*v))
		return false;
	else
		return true;

}

int main()
{
	ll i,ans=0,l,r,mid;
	cin>>n>>m>>v>>p;

	ll a[n];
	rep(i,0,n)
		cin>>a[i];
	sort(a,a+n,sortbysec);

	l=0;
	r=n-1;
	mid=(l+r+1)/2;

	while(l<=r)
	{
		if(binary_search(mid,a))
		{
			ans=mid;
			l=mid+1;
			mid=(l+r+1)/2;
		}
		else
		{
			r=mid-1;
			mid=(l+r+1)/2;
		}
	}


	cout<<ans+1<<"\n";

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 1<<17;
const int MM = 1000000007;

t3 A, B;

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	int vst[MX] = {};
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		vst[a]++; vst[b]++;
	}
	for(int i = 1; i <= N; i++){
		if( vst[i]%2 == 1 ) return !printf("NO\n");
	}
	printf("YES\n");
}


Measured memory_bytes: 768
num = gets.to_i
num.times do
  left, right = [], []
  arr = gets.chomp.split(' ').map(&:to_i)
  arr.each do |a|
    if (left.last || 0) < a
      left << a
    elsif (right.last || 0) < a
      right << a
    else
      break
    end
  end
  puts (arr.size == (left.size + right.size)) ? 'YES' : 'NO'
end

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

public class Main {

    int[] a;

    void solve() {
	String s = sc.next();
	StringBuilder sb = new StringBuilder(s);
	sb.insert(4," ");

	System.out.println(sb);
    }

    void print(int[] a) {
	out.print(a[0]);
	for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
	out.println();
    }

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

    MyScanner sc = null;
    PrintWriter out = null;
    public void run() throws Exception {
	sc = new MyScanner(System.in);
	out = new PrintWriter(System.out);
	for (;sc.hasNext();) {
	    solve();
	    out.flush();
	}
	out.close();
    }

    class MyScanner {
	String line;
	BufferedReader reader;
	StringTokenizer tokenizer;

	public MyScanner(InputStream stream) {
	    reader = new BufferedReader(new InputStreamReader(stream));
	    tokenizer = null;
	}
	public void eat() {
	    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
		try {
		    line = reader.readLine();
		    if (line == null) {
			tokenizer = null;
			return;
		    }
		    tokenizer = new StringTokenizer(line);
		} catch (IOException e) {
		    throw new RuntimeException(e);
		}
	    }
	}
	public String next() {
	    eat();
	    return tokenizer.nextToken();
	}
	public String nextLine() {
	    try {
		return reader.readLine();
	    } catch (IOException e) {
		throw new RuntimeException(e);
	    }
	}
	public boolean hasNext() {
	    eat();
	    return (tokenizer != null && tokenizer.hasMoreElements());
	}
	public int nextInt() {
	    return Integer.parseInt(next());
	}
	public long nextLong() {
	    return Long.parseLong(next());
	}
	public double nextDouble() {
	    return Double.parseDouble(next());
	}
	public int[] nextIntArray(int n) {
	    int[] a = new int[n];
	    for (int i = 0; i < n; i++) a[i] = nextInt();
	    return a;
	}
    }
}


Measured memory_bytes: 8276
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;

void update(int& x, int y) { if(x < y) x = y; }

int main(){
  int T;
  cin >> T;
  while(T --){
    int L; cin >> L;
    vector<int> A(L);
    REP(i, L) cin >> A[i];
    int dp[100][400] = {}; // 0からiまでのEa鎖で、i - 1の基がjのとき、iの基の最大値はdp[i][j]
    REP(i, L)REP(j, 400) dp[i][j] = -INF;
    dp[0][0] = A[0]; // L = 1の例外
    dp[1][A[0]] = A[1]; //初期値
    // (現在のEa鎖のindex, 一つ前の基の値, 現在の基の値) = (i, j, k)
    // (i, j, k) -> (i + 1, k, A[i + 1]) (伝播しない)
    //           -> (i + 1, k - 1, j + A[i + 1]) (伝播した)
    for(int i = 1; i + 1 < L; i++){
      for(int j = 0; j <= 4 * i; j++){
        if(dp[i][j] >= 0) update(dp[i + 1][dp[i][j]], A[i + 1]);
        if(dp[i][j] >= 1) update(dp[i + 1][dp[i][j] - 1], j + A[i + 1]);
      }
    }
    int ans = 0;
    for(int i = 0; i < 4 * L; i++) update(ans, dp[L - 1][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1356
import sys
sys.setrecursionlimit(10**9)
graph={}
n,m=map(int,input().split())
for i in range(1,n+1):
    graph[i]=[]
for _ in range(m):
    u,v=map(int,input().split())
    graph[u].append(v)

def dfs(i,dp):
    temp=0
    if dp[i]!=-1:
        return dp[i]
    for nvr in graph[i]:
        temp=max(temp,dfs(nvr,dp)+1)
    dp[i]=temp
    return temp 

dp=[-1]*(n+1)
res=0
for i in range(1,n+1):
    res=max(res,dfs(i,dp))
print(res)

Measured memory_bytes: 163728
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000

int N,num_query;
queue<int> Q[NUM];

int main(){

	scanf("%d %d",&N,&num_query);

	int command,A,B;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		switch(command){
		case 0:

			scanf("%d %d",&A,&B);
			Q[A].push(B);
			break;

		case 1:

			scanf("%d",&A);
			if(!Q[A].empty()){
				printf("%d\n",Q[A].front());
			}
			break;

		case 2:

			scanf("%d",&A);
			if(!Q[A].empty()){
				Q[A].pop();
			}
			break;
		}
	}
	return 0;
}




Measured memory_bytes: 4436
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]
        self.siz = [1 for i in range(n)]
    
    def find(self, x):
        if self.par[x] == x:
            return x
        return self.find(self.par[x])
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
            self.siz[x] += self.siz[y]
        else:
            self.par[x] = y
            self.siz[y] += self.siz[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.siz[self.find(x)]
    
def kruskal(n, m):
    res = 0
    uf = UnionFind(n)
    for i in range(m):
        w, s, t = es[i]
        if uf.same(s, t):
            continue
        uf.unite(s, t)
        res += w
    return res

V, E = map(int, input().split())
es = []
for i in range(E):
    s, t, w = map(int, input().split())
    es.append([w, s, t])

es.sort(key=lambda x: x[0])
res = kruskal(V, E)
print(res)


Measured memory_bytes: 25824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		double a,b,h,m;
		cin>>a>>b>>h>>m;
		h*=60;
		h+=m;
		h/=double(2);
		m*=6;
		double angle = max(h,m) - min(h,m);
		angle = min(angle , 360 - angle);
		double pi = 3.141592653589793;
		angle = (angle*pi)/double(180);
		a = (a*a) + (b*b) - (2*a*b*cos(angle));
		a = sqrt(a);
		cout<<fixed<<setprecision(10)<<a;
	}
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int i, j;
  int ch = 0;
  for(i = 97; i <= 122; i++)
  {
    for(j = 0; j < s.size(); j++)
    {
      if(s.at(j) == i)
      {
        ch = 1;
        break;
      }
    }
    if(ch == 0)
    {
      ch = 2;
      break;
    }
    else
    {
      ch = 0;
    }
  }
  char ii = i;
  if(ch == 2)
  {
    cout << ii << endl;
  }
  else
  {
    cout << "None" << endl;
  }
}

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

using ll = long long;
#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 INF 1e9
const ll INF = 1LL << 60;


int main(){
  int n;
  cin >> n;
  cout << n << ":";
  for(int i = 2; i * i <= n; i++){
    while(n % i == 0){
      cout << " " << i;
      n /= i;
    }
  }
  if(n != 1){
    cout << " " << n;
  }
  cout << endl;
  return 0;
}




Measured memory_bytes: 3100
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[int]"):
    sum = 0
    count = 0
    for i in A:
        sum += i


    for a in A:
        if a >= sum / (4 * M):
            count += 1

    if count >= M:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
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 int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;
int A[MAX];
int n;

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

bool isWin()
{
	int cnt0 = 0, cnt1 = 0;
	FOR(i, 0, n)
	{
		if (A[i] % 2) cnt1++;
		if (A[i] % 2 == 0) cnt0++;
	}

	if (cnt0 % 2) return true;
	if (cnt0 % 2 == 0 && cnt1 >= 2) return false;

	int ind = -1;
	FOR(i, 0, n)
	{
		if (A[i] == 1) continue;
		if (A[i] % 2)
		{
			ind = i;
			break;
		}
	}

	if (ind == -1) return false;
	A[ind]--;
	int g = A[0];
	FOR(i, 0, n)
	{
		g = gcd(A[i], g);
	}

	FOR(i, 0, n)
	{
		A[i] /= g;
	}

	return !isWin();
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	LL s = 0;
	FOR(i, 0, n)
	{
		cin >> A[i];
	}

	if (isWin())
	{
		cout << "First" << endl;
		return 0;
	}

	cout << "Second" << endl;
}


Measured memory_bytes: 640
//******\\
||udc321||	 
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#include<cstring>
#define ll long long
#define fr(e,r,v) for(ll e=r;e<v;e++)
#define bc(e,r,v) for(ll e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define mpr make_pair
#define db  double
using namespace std;
ll mod=1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main()
{
	ll n,k;
	cin>>n>>k;
	ll h[n];
	fr(j,0,n)
	{
		cin>>h[j];
	}
	vector<ll> dp(n,mod);
	dp[0]=0;
	fr(j,1,n)
	{
		ll p=min(j,k);
		fr(i,1,p+1)
		{
			dp[j]=min(dp[j],abs(h[j]-h[j-i])+dp[j-i]);
		}
			
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int main(){
  int N,M;
  cin >> N >> M;
  ll A[N];
  rep(i,N) cin >> A[i];
  vector<pair<ll,ll>> p(M);
  rep(i,M){
    ll a,b;
    cin >> a >> b;
    p[i] = make_pair(-b,a);
  }
  int pos = 0;
  sort(A,A+N);
  sort(p.begin(),p.end());
  rep(i,N){
    if(-p[pos].first > A[i]) A[i] = -p[pos].first,p[pos].second--;
    else break;

    if(p[pos].second == 0) pos++;
  }
  ll ans = 0;
  rep(i,N) ans += A[i];
  
  cout << ans << endl;
  
  return 0;
}







Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
ll mod = 1000000007;

ll pask[101][101];

void calcpask() {
    REP(i, 1, 101) {
        pask[i][i] = 1;
        pask[i][0] = 1;
    }
    REP(i, 1, 101) {
        REP(j, 1, i) {
            if(pask[i][j] == 0)pask[i][j] = pask[i - 1][j - 1] + pask[i-1][j];
        }
    }
}

int main() {
    //入力
    int N, P;
    int odd = 0;//奇数
    int even = 0;//偶数
    cin >> N >> P;
    calcpask();
    REP(i,0,N){
        int tmp;
        cin >> tmp;
        if(tmp % 2 == 0){
            even++;
        }else{
            odd++;
        }
    }

//    REP(i, 1, 101) {
//        REP(j, 0, i) {
//            cout << pask[i][j] << " ";
//        }
//        cout << endl;
//    }

    ll ans = 0;
    if(odd == 0){
        if(abs(odd-P) % 2 == 0){
            cout << (ll)pow(2,even) << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }
    if(abs(odd-P) % 2 == 0){
        for(int i = 0; i <= odd; i+=2){
            ans += (pask[odd][i]);
        }
    }else{
        for(int i = 1; i <= odd; i+=2){
            ans += (pask[odd][i]);
        }
    }

    ans *= pow(2,even);
    cout << ans << endl;

}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


const ll md = 998244353;
ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % md, e /= 2)
    if (e & 1) ans = ans * b % md;
  return ans;
}

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
  ll n;
  cin>>n;

  int N = n+10;
  vector<ll> inv(N,1), fac(N, 1), ifac(N, 1);
  rep(i,2,N) {
    inv[i] = md - (md / i) * inv[md % i] % md;
    fac[i] = fac[i-1] * i % md;
    ifac[i] = ifac[i-1] * inv[i] % md;
  }
  auto binom = [&](ll n, ll k) {
    if(k < 0 || k > n) return 0LL;
    return fac[n] * ifac[k] % md * ifac[n-k] % md;
  };

  ll ans = modpow(3, n);
  rep(i,0,n) {
    if(2*i <= n) continue;
    ll cur = modpow(2, n-i) * binom(n,i) % md;
    ans = (ans - 2*cur + 2*md) %md;
  }

  ans = (ans-2 + md) % md; // why?

  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  int n= s.size();
  int a=0;
  int b=0;
  for(int i=0;i<n;i++){
    if(s.at(i)=='0')a++;
	else b++;
	
  }
 
  
  
  cout << min(a,b)*2 <<endl;
  
}


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

vector<vector<ll>> v(200000);
vector<ll> ans(200000);

void dfs(int i, int p=-1){
    for(auto j: v.at(i)){
        if(j!=p){
            ans.at(j) += ans.at(i);
            //cout << j << ' ' << ans.at(j) << endl;
            dfs(j, i);
        }
    }
}


int main(){
    int n, q;   cin >> n >> q;
   
    for(int i=0; i<n-1; i++){
        int a, b;   cin >> a >> b;
        a--; b--;
        v.at(a).push_back(b);
        v.at(b).push_back(a);
        ans.at(i) = 0;
    }

    for(int i=0; i<q; i++){
        ll p, sum; cin >> p >> sum;
        p--;
        ans.at(p) += sum;
    }
    dfs(0);
    for(int i=0; i<n; i++)
        cout << ans.at(i) << endl;
    
}


Measured memory_bytes: 27392
#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);
    sort(d.begin(),d.end());
    int count=0;
    for(int i=0;i<N-1;i++){
        if(d.at(i)==d.at(i+1))count++;
    }
    cout << N-count << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int kind,i,sum,temp;
    while (1) {
        scanf("%d",&kind);
        if (kind==0) break;
        sum=0;
        for (i=0; i<kind*(kind-1)/2; i++) {
            scanf(" %d",&temp);
            sum+=temp;
        }
        printf("%d\n",sum/(kind-1));
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<int> num;
bool flag;

void init(){
  for(int i=0;i<n;i++){
    num[i]=-1;
  }
}

void calc(){
  for(int i=1;i<n;i++){
    if(s[i]=='o'){
      if(num[i]==0){
        if(i==n-2){
          if(num[n-1]!=num[n-3]) return ;
        }
        if(i+1!=n) num[i+1]=num[i-1];
        else{
          if(num[0]==num[n-2]){
            for(int j=0;j<n;j++){
              if(num[j]==0){
                cout<<'S';
              }else{
                cout<<'W';
              }
            }
            cout<<endl;
            flag=true;
          }
        }
      }else{
        if(i==n-2){
          if(num[n-1]==num[n-3]) return;
        }
        if(i+1!=n){
          if(num[i-1]==0) num[i+1]=1;
          else num[i+1]=0;
        }else{
          if(num[0]!=num[n-2]){
            for(int j=0;j<n;j++){
              if(num[j]==0){
                cout<<'S';
              }else{
                cout<<'W';
              }
            }
            cout<<endl;
            flag=true;
          }
        }
      }
    }
    
    else{
      if(num[i]==1){
        if(i==n-2){
          if(num[n-1]!=num[n-3]) return;
        }
        if(i+1!=n) num[i+1]=num[i-1];
        else{
          if(num[0]==num[n-2]){
            for(int j=0;j<n;j++){
              if(num[j]==0){
                cout<<'S';
              }else{
                cout<<'W';
              }
            }
            cout<<endl;
            flag=true;
          }
        }
      }else{
        if(n-2==i){
          if(num[n-1]==num[n-3]) return ;
        }
        if(i+1!=n){
          if(num[i-1]==0) num[i+1]=1;
          else num[i+1]=0;
        }else{
          if(num[0]!=num[n-2]){
            for(int j=0;j<n;j++){
              if(num[j]==0){
                cout<<'S';
              }else{
                cout<<'W';
              }
            }
            cout<<endl;
            flag=true;
          }
        }
      }
    }
  }
}

int main(){
  cin>>n>>s;
  num.resize(n,-1);
  num[0]=0;
  flag=false;
  if(s[0]=='o'){
    num[1]=0; num[n-1]=0;
  }else{
    num[1]=0; num[n-1]=1;
  }
  calc();
  if(flag) return 0;
  init();
  num[0]=0;
  if(s[0]=='o'){
    num[n-1]=1; num[1]=1;
  }else{
    num[n-1]=0; num[1]=1;
  }
  calc();
  if(flag) return 0;
  init();
  num[0]=1;
  if(s[0]=='o'){
    num[1]=1; num[n-1]=0;
  }else{
    num[1]=0; num[n-1]=0;
  }
  calc();
  if(flag) return 0;
  init();
  num[0]=1;
  if(s[0]=='o'){
    num[1]=0; num[n-1]=1;
  }else{
    num[1]=1; num[n-1]=1;
  }
  calc();
  if(flag) return 0;
  cout<<-1<<endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
 
ans = 1
mode = 0
for i in range(N-1):
  if mode == 0:
    if A[i] < A[i+1]:
      mode = 1
    elif A[i] > A[i+1]:
      mode = -1
    else:
      mode = 0
  if mode == 1:
    if A[i] > A[i+1]:
      ans += 1
      mode = 0
  elif mode == -1:
    if A[i] < A[i+1]:
      ans += 1
      mode = 0
  else:
    pass
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>


int main(int argc,char *argv[]){
	int a[400],d[200][2],i,j,k,ansWidth,ansHeight,N;
	int right,left,up,bottom;
	while(1){
		right = 0;
		left = 0;
		up = 0;
		bottom = 0;
				
		scanf("%d",&N);
		if(N == 0){
			break;
		}			
		for(i = 0;i < N-1;i++){
			scanf("%d %d",&a[i*2],&a[i*2+1]);			
		}
		//printf("%d\n",N);
		//for(i = 0;i < N-1;i++){
		//	printf("%d %d\n",a[i*2],a[i*2+1]);
		//}

		//????\?
		d[0][0] = 0;
		d[0][1] = 0;
		for(i = 0;i < N-1;i++){
			switch(a[i*2+1]){
				case 0:
					d[i+1][0] = d[a[i*2]][0]-1;
					d[i+1][1] = d[a[i*2]][1];
					break;
				case 1:
					d[i+1][0] = d[a[i*2]][0];
					d[i+1][1] = d[a[i*2]][1]-1;
					break;
				case 2:
					d[i+1][0] = d[a[i*2]][0]+1;
					d[i+1][1] = d[a[i*2]][1];
					break;
				case 3:
					d[i+1][0] = d[a[i*2]][0];
					d[i+1][1] = d[a[i*2]][1]+1;
					break;
								
			}
			
		}
			
		for(i = 0;i < N;i++){
			//printf("(%d,%d)\n",d[i][0],d[i][1]);
			if(d[i][0] > right){
				right = d[i][0];
			}else if(d[i][0] < left){
				left = d[i][0];
			}else if(d[i][1] > up){
				up = d[i][1];
			}else if(d[i][1] < bottom){
				bottom = d[i][1];
			}
		
		}
		printf("%d %d\n",right - left+1,up-bottom+1);
		//????\??????????
		
	}



	return 0;
}

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



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

    int n,m; cin >> n >> m;
    vector<int> a(m); rep(i,m) cin >> a[i];
    int res = n;
    rep(i,m) res -= a[i];
    if(res < 0) cout << -1 << endl;
    else cout << res << endl; 
}

Measured memory_bytes: 3632
#include<stdio.h>
main(){
int s[9000],n,m,t,f,i;
while(scanf("%d%d",&n,&m),i=0,t=f=1,n){
	while(++i<=n+m){
		if(scanf("%d",&s[i]),i>n)if(t+=s[t+=s[i]],t>=n&f==1)
			printf("%d\n",i-n,f=0);
			//i++;
		}
	}
}

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

int main() {
  int a;
  int b;
  int c;
  int d;

  cin >> a >> b >> c >> d;
  int L = a+b;
  int R = c+d;

if(L>R){
    cout << "Left" << endl;

 }else  if(L<R){
        cout <<"Right" << endl;
 }else if(L==R){
     cout <<"Balanced"<< endl;

    }
}

Measured memory_bytes: 3628
fun main(args: Array<String>) = itp1_7_b()

fun itp1_7_b() {
    var (n, x) = readLine()!!.split(' ').map { it.toInt() }

    val answer = StringBuilder()

    while (!(n == 0 && x == 0)) {
        val list = (1..n).toList()
        var count = 0L

        for (fi in list.indices) {
            val first = list[fi]
            for (si in fi + 1..list.lastIndex) {
                val second = list[si]
                val third = x - (first + second)
                if (third > second && third in 1..n) count++
            }
        }

        answer.appendln(count)

        readLine()!!.split(' ').map { it.toInt() }.let {
            n = it[0]
            x = it[1]
        }

    }


    print(answer)
}



Measured memory_bytes: 31736
import java.util.Scanner;
import java.util.Arrays;

public class Main {

	static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {
		String str = s.next();

		for (int i = 0; i < str.length(); i = i + 2) {
			System.out.print(str.charAt(i));
		}

	}
}

Measured memory_bytes: 28512
x,y,a,b,c=map(int,input().split())
aka,ao,musyoku=[sorted(list(map(int,input().split())),reverse=1) for i in range(3)]
ans=0
A,B,C=0,0,0
while C+A+B<x+y and x>A and y>B and c>C:
    q,w,e=aka[A],ao[B],musyoku[C]
    ans+=max(q,w,e)
    if max(q,w,e)==e:C+=1
    elif q>w:A+=1
    else:B+=1
if C+A+B==x+y:print(ans);exit()
  
if x<=A:
    cnt=x+y-A-B-C
    CC=y-B
    while cnt and CC:
        ans+=max(ao[B],musyoku[C])
        if max(ao[B],musyoku[C])==ao[B]:B+=1
        else:C+=1;CC-=1
        cnt-=1
    if cnt:
        ans+=sum(ao[B:B+cnt]) 
elif y<=B:
    cnt=x+y-A-B-C
    CC=x-A
    while cnt and CC:
        ans+=max(aka[A],musyoku[C])
        if max(aka[A],musyoku[C])==aka[A]:
            A+=1
        else:C+=1;CC-=1
        cnt-=1
    if cnt :
        ans+=sum(aka[A:A+cnt])
else:
    cnt=x+y-A-B-C
    while cnt:
        ans+=max(aka[A],ao[B])
        if max(aka[A],ao[B])==aka[A]:A+=1
        else:B+=1
        cnt-=1

print(ans)


Measured memory_bytes: 22620