akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<vector<int>> treeone;

    void input() {
        cin >> N;
        treeone.resize(N);
        rep(i, 0, N - 1) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            treeone[a].push_back(b);
            treeone[b].push_back(a);
        }


    }

    pair<int, int> dfs(int v, int p = -1) {
        if (p != -1 && treeone[v].size() == 1) {
            return pair<int, int>(1, v);
        }

        int dist = 0;
        int rv = 0;

        for (auto e : treeone[v]) {
            if (e != p) {
                auto tmp = dfs(e, v);
                if (dist < tmp.first + 1) {
                    dist = tmp.first + 1;
                    rv = tmp.second;
                }
            }
        }

        return pair<int, int>(dist, rv);
    }

    void solve() {
        input();
        if (N == 1) {
            cout << "First" << endl;
            return;
        }

        if (N == 2) {
            cout << "Second" << endl;
            return;
        }

        auto tapi = dfs(0);
        auto tapu = dfs(tapi.second);

        int val = tapu.first;
        if (val % 3 == 2) {
            cout << "Second" << endl;
        } else {
            cout << "First" << endl;
        }
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 23680
#![allow(dead_code)]

fn main() {
    let n: Vec<u32> = read_vec();
        let num = n[0];
    if n[1] == 0 {
        println!("{}", num);
    } else {
        let r: Vec<u32> = read_vec();

        //let mut i = 0u32;
        let mut num_d = num;
        let mut num_i = num;
        loop {
            if r.iter().all(|&x| x != num_d) {
                println!("{}", num_d);
                break;
            } else if r.iter().all(|&x| x != num_i) {
                println!("{}", num_i);
                break;
            }
            num_d -= 1;
            num_i += 1;
        }
    }
}

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()
}

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_n<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp  make_pair
#define pb  push_back
#define endl "\n"
#define rep(i,a,n) for(int i=a;i<n;i++)
void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int m1 = 0;
    rep(i, 0, n - m + 1) {
        int j = i, k = 0, m2 = m, c = 0;
        while (m2--) {
            if (s[j] == t[k]) {
                c++;
            }
            j++;
            k++;
        }
        m1 = max(m1, c);
    }
    cout << m - m1 << endl;
    return;
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    int t;
    // cin >> t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
char map[10][10];
void read(int w,int h,char c){
	int i,j;
	scanf("%*c");
	FOR(i,0,h+2) map[0][i]=c,map[w+1][i]=c;
	FOR(i,0,w+2) map[i][0]=c,map[i][h+1]=c;
	FOR(i,1,h+1){
		FOR(j,1,w+1){
			scanf("%c",&map[j][i]);
		}
		scanf("%*c");
	}
    return; 
}
int main(void)
{
	int h,w,x=1,y=1,i,j;
	scanf("%d%d",&h,&w);
	read(w,h,'.');
	map[x][y]='.';
	while(1){
		if(map[x+1][y]=='#') map[++x][y]='.';
		else if(map[x][y+1]=='#') map[x][++y]='.';
		else break;
	}
	FOR(i,1,h+1){
		FOR(j,1,w+1){
			if(map[j][i]=='#'){
				puts("Impossible");
				return 0;
			}
		}
	}
	puts("Possible");
	return 0;
}


Measured memory_bytes: 128
/*
*
*   解説見てないお
*
*/
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int n, m; cin >> n >> m;
    vector<int> x(n),y(m,0),z(100001,0);
    REP(i, n) {
        scanf("%d", &x[i]);
        y[x[i] % m]++;
        z[x[i]]++;
    }
    ll ans = 0;
    REP(i, m/2 + 1) {
        if (i == m - i || i == 0) {
            ans += y[i] / 2;
            y[i] %= 2;
        }
        else {
            int a = min(y[i], y[m - i]);
            ans += a;
            y[i] -= a;
            y[m - i] -= a;
        }
    }
    REP(i, 100001) {
        if (z[i] > 1 && y[i % m]) {
            int a = min(z[i] / 2, y[i % m] / 2);
            y[i % m] -= a * 2;
            ans += a;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

s = s()
a = ["SAT", "FRI", "THU","WED","TUE","MON","SUN"]
x = a.index(s) + 1
print(x)


Measured memory_bytes: 9900
#include<iostream>
#include<vector>
#include<math.h>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
  	string s;
  	cin>>s;
  	int i;
  	for(i=0;i<s.length();i++)
  		cout<<"x";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)
        
        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,q;
        ll mod = 998244353;

        
        void solve(){
            cin >> n;
            map<int,int> mp;
            for(int i=2;i<=n;i++){
                int a; cin >> a;
                mp[a]++;
            }
            for(int i=1;i<=n;i++){
                cout << mp[i] << endl;
            }
            
        }
            
        int main(){
        ios_base::sync_with_stdio(false);
      
        int cases = 1;
        //cin >> cases;
    
        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 13004
import math

#x = int(input())
#a = int(input())
a,b,k = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b,c = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]

if b - a < 2 * k:
  for i in range(a,b+1):
    print(i)
  quit()

for i in range(a,a+k):
  print(i)
for i in range(b-k+1,b+1):
  print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<ll> p;
vector<ll> c;
ll D,G;

int main() {
    cin >> D >>G;
    p.resize(D);
    c.resize(D);
    for(int i=0;i<D;i++){
        cin >> p[i] >> c[i]; 
    }
    vector<ll> ans;
    for(int bit=0;bit<(1<<D);++bit){
        ll sum =0;
        ll used =0;
        for(int i=0;i<D;i++){
            if(bit & (1<<i)){
                used += p[i];
                sum += (c[i] + p[i] * 100*(1+i));
            }
        }
        if(sum >= G){
            ans.push_back(used);
            continue;
        }
        for(int i=D-1;i>=0;--i){
            // cerr << sum << endl;
            if(!(bit & (1<<i))){
                ll n = min(p[i]-1,(ll)ceil(((long double) (G-sum))/(100*(1+i))));
                // cerr << "n="<<n << endl;
                sum += n*100*(1+i);
                used += n;
                if(sum>=G){
                    ans.push_back(used);
                    break;
                }
            }
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;

    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mod = 1000000007;
const int N = 100005;
#define ll long long 
#define fr(b) for (int i = 0; i < b; ++i)
int abs(int x){
	if (x < 0) return -x;
	return x;
}
int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	int dx = abs(tx-sx);
	int dy = abs(ty-sy);
	if (sx <= tx && sy <= ty){
		fr(dx) printf("R");
		fr(dy) printf("U");
		fr(dx) printf("L");
		fr(dy) printf("D");
		printf("D");
		fr(dx+1) printf("R");
		fr(dy+1) printf("U");
		printf("LU");
		fr(dx+1) printf("L");
		fr(dy+1) printf("D");
		printf("R\n");
	}
	if (sx <= tx && sy >= ty){
		fr(dx) printf("R");
		fr(dy) printf("D");
		fr(dx) printf("L");
		fr(dy) printf("U");
		printf("U");
		fr(dx+1) printf("R");
		fr(dy+1) printf("D");
		printf("LD");
		fr(dx+1) printf("L");
		fr(dy+1) printf("U");
		printf("R\n");
	}
	if (sx >= tx && sy <= ty){
		fr(dx) printf("L");
		fr(dy) printf("U");
		fr(dx) printf("R");
		fr(dy) printf("D");
		printf("D");
		fr(dx+1) printf("L");
		fr(dy+1) printf("U");
		printf("RU");
		fr(dx+1) printf("R");
		fr(dy+1) printf("D");
		printf("L\n");
	}
	if (sx >= tx && sy >= ty){
		fr(dx) printf("L");
		fr(dy) printf("D");
		fr(dx) printf("R");
		fr(dy) printf("U");
		printf("U");
		fr(dx+1) printf("L");
		fr(dy+1) printf("D");
		printf("RD");
		fr(dx+1) printf("R");
		fr(dy+1) printf("U");
		printf("L\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

int n, k;
vector<int> x(0);

int main(){
    int a;
    int l, r;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> a;
        x.push_back(a);
    }
    l = 0;
    r = k-1;
    long long min_ = pow(2, 31) - 1;
    while(r != n){
        long long cost = min(abs(x[l]) + abs(x[r]-x[l]), abs(x[r]) + abs(x[r] - x[l]));
        if(cost < min_) min_ = cost;
        l++;
        r++;
    }
    cout << min_ << endl;

	return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
int main(void)
{
	int a[51][11],ti[51],tt[51],pp[51];
	int i,k,j;
	char buf[10];
	int t,p,t1,p1,tim,r;
	P ppp[51];
	while(1)	{
		scanf("%d %d %d",&t,&p,&r);
		if(t==0 && p==0 && r==0)	break;
		for(i=1;i<=t;i++)	{
			for(j=1;j<=p;j++)	{
				a[i][j]=0;
			}
			tt[i]=i;	pp[i]=0;	ti[i]=0;
		}
		for(i=0;i<r;i++)	{
			scanf(" %d %d %d",&t1,&p1,&tim);
			scanf("%s",buf);

			if(strcmp(buf,"WRONG")==0)	{
				a[t1][p1]++;
			}
			else {
				pp[t1]++;
				ti[t1]=ti[t1]+tim+a[t1][p1]*1200;
			}
		}
		
		for(i=1;i<=t;i++)	{
			ppp[i].first=-pp[i];
			ppp[i].second=ti[i]*100+tt[i];
		}
		sort(ppp+1,ppp+t+1);
		for(i=1;i<=t;i++)	{
			pp[i]=-ppp[i].first;
			ti[i]=ppp[i].second%100;
			tt[i]=ppp[i].second/100;
			printf("%d %d %d\n",ti[i],pp[i],tt[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll mod = 998244353;
const ll N = 2e5 + 1;
const ll inf = 1e18;

ll modfac[N];
ll modfacinv[N];
ll invsi[N];

ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {
    return power(n, mod-2, mod);
}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

void simake(){
	invsi[0]=1;
	invsi[1]=1;

	modfac[0]=1;
	modfac[1]=1;

	modfacinv[0]=1;
	modfacinv[1]=1;

	for(ll i=2;i<N;i++)
	{
		invsi[i] = mul(invsi[mod%i], (mod-(mod/i)));
		modfac[i] = mul(i, modfac[i-1]);
		modfacinv[i] = mul(invsi[i], modfacinv[i-1]);
	}
}

ll nCrm(ll n,ll r){
	if(n==r||r==0) return 1;
	if(n<r) return 0;
	return mul(mul(modfac[n], modfacinv[r]), modfacinv[n-r]);
}
//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	ll n, k, m;
	cin>>n>>m>>k;
	ll ans=0;
	for(int i=0;i<=k;i++){
		ll x = mul(power(m-1, n-i-1, mod), nCrm(n-1, i));
		//cout<<x<<" ";
		ans = add(ans, x);
	}
	cout<<(ans*m)%mod;

	return 0;
}


Measured memory_bytes: 8344
N, M = map(int, input().split())
Xlist = sorted(list(map(int, input().split())))
sbn = [Xlist[i+1]-Xlist[i] for i in range(M-1)]
sbn.sort()
# print(sbn)
ans = 0
if N < M:
    for i in range(M-N):
        ans += sbn[i]
print(ans)

Measured memory_bytes: 57512
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    map<ll, ll> mpd, mpt;
    ll n, m;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        mpd[temp]++;
    }
    cin >> m;
    vector<ll> t(m);
    for (ll i = 0; i < m; i++)
    {
        ll temp;
        cin >> temp;
        t[i] = temp;
        mpt[temp]++;
    }

    for (ll i = 0; i < m; i++)
    {
        ll x = t[i];
        if (mpt[x] > mpd[x])
        {
            cout << "NO" << endl;
            exit(0);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0; i<(n); i++)
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int main(){
    string N; cin >> N;
    if (N[0]=='7' || N[1]=='7' || N[2]=='7'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    int n, a[2][100];
    int dp[3][101] = {};

    cin >> n;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= 2; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i - 1][j - 1];
        }
    }
    cout << dp[2][n] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
const long long MOD = 1000000007;
using namespace std;
int f[2005];
ll mul(ll a,ll b){
	return ((a%MOD) * (b%MOD))%MOD;
}
ll add(ll a,ll b){
	return ((a%MOD)+(b%MOD))%MOD;
}
int main(){
	int S;cin>>S;
	f[0]=0;f[1] = f[2] = 0;f[3] =1;
	for(int i=4;i<=2004;i++){
		f[i] = add(f[i],1);
		for(int j=3;j<=i-3;j++){
			f[i]= add(f[i],f[i-j]);
		}
	}
	cout<<f[S];
	return 0;
}

Measured memory_bytes: 3608
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long K) {
  queue<ll> q;
  rep1(i, 9) q.push(i);
  ll x;
  rep(i, K) {
    x = q.front();
    q.pop();
    if (x % 10 != 0)
      q.push(x * 10 + x % 10 - 1);
    q.push(x * 10 + x % 10);
    if (x % 10 != 9)
      q.push(x * 10 + x % 10 + 1);
  }
  ANS(x);
}

// clang-format off
int main() {
  long long K;
  scanf("%lld",&K);
  solve(K);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <forward_list>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// sanitize: shift + f11
// debug: shift + f9

void A() {
}

void B() {
}

void C() {
    ll N;
    cin >> N;
    vi xis(N);
    R1(N)
        cin >> xis[i];

    ll minVal = 0;
    ll minSum = mal()/2;

    R1(100) {
        ll P = i+1;
        ll currSum = 0;
        for(auto XI : xis) {
            currSum += (XI - P)*(XI-P);
        }
        if(currSum < minSum) {
            minSum = currSum;
            minVal = P;
        }
    }

    cout << minSum << endl;
}

void D() {
}

void E() {
}

int main()
{
    C();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

priority_queue<int> pq_left;
priority_queue<int, vector<int>, greater<int>> pq_right;
ll sum_left = 0, sum_right = 0;
ll sum_b = 0;

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

  pq_left.push(a);
  sum_left += a;

  pq_right.push(pq_left.top());
  sum_right += pq_left.top();
  sum_left -= pq_left.top();
  pq_left.pop();

  if (pq_left.size() < pq_right.size()) {
    pq_left.push(pq_right.top());
    sum_left += pq_right.top();
    sum_right -= pq_right.top();
    pq_right.pop();
  }

  sum_b += b;
}

void output() {
  ll x = pq_left.top();
  ll min_fx = (x * pq_left.size() - sum_left) + (sum_right - x * pq_right.size()) + sum_b;
  cout << x << ' ' << min_fx << endl;
}

int main() {
  int Q; cin >> Q;
  rep(i,Q) {
    int n; cin >> n;
    if (n == 1) update();
    else output();
  }
  return 0;
}


Measured memory_bytes: 3452
input_str = input().split()

input_nums=[]

for i in range(5):
    input_nums.append(int(input_str[i]))


diff_hour = input_nums[2] - input_nums[0]
diff_hour_to_min = diff_hour * 60
 
diff_min = input_nums[3] - input_nums[1]

total_wake_min = diff_hour_to_min + diff_min

print(total_wake_min - input_nums[4])

Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}
ll modexpo(ll a, ll b, ll m) {if (b == 0) {return 1;} else if (a == 1) {return 1;} if (b % 2 == 0) {ll t = modexpo(a, b / 2, m); t = (t * t) % m; return t;} else {ll t = modexpo(a, b / 2, m); t = (t * t) % m; t = (t * a) % m; return t;}}


int dp[3001][3001];

// int fn(string s, string t, int idx1, int idx2) {
//     if (idx1 == 0) {
//         return 0;
//     }
//     if (idx2 == 0) {
//         return 0;
//     }

//     if (dp[idx1][idx2] != -1) {
//         return dp[idx1][idx2];
//     }

//     int ans = 0;
//     if (s[idx1 - 1] == t[idx2 - 1]) {
//         ans = fn(s, t, idx1 - 1, idx2 - 1) + 1;
//     }
//     else {
//         ans = max(fn(s, t, idx1 - 1, idx2), fn(s, t, idx1, idx2 - 1));
//     }

//     dp[idx1][idx2] = ans;
//     return ans;

// }


// void dfs(stack<char> &ans, string s, string t, int idx1, int idx2) {

//     if (idx1 == 0 || idx2 == 0) {
//         return;
//     }

//     if (s[idx1 - 1] == t[idx2 - 1] ) {
//         ans.push(s[idx1 - 1]);
//         dfs(ans, s, t, idx1 - 1, idx2 - 1);
//     }
//     else {
//         int op1 = dp[idx1 - 1][idx2];
//         int op2 = dp[idx1][idx2 - 1];
//         if (op1 >= op2) {
//             dfs(ans, s, t, idx1 - 1, idx2);
//         }
//         else {
//             dfs(ans, s, t, idx1, idx2 - 1);
//         }
//     }
// }



int main() {

    // taskkill /IM "cp.exe" /F
    fast



    memset(dp, -1, sizeof(dp));
    string s, t;
    cin >> s >> t;
    // fn(s, t, s.length(), t.length() );

    for (int i = 0; i <= s.length(); i++) {
        for (int j = 0; j <= t.length(); j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = 0;
            }
            else if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    // cout << dp[s.length()][t.length()] << endl;



    string ans = "";
    // stack<char> ans;
    // dfs(ans, s, t, s.length(), t.length());
    // // reverse(ans.begin(), ans.end());
    // // cout << ans << endl;
    // while (!ans.empty()) {
    //     cout << ans.top(); ans.pop();
    // }
    // cout << endl;

    int i = s.length(), j = t.length();

    while (i > 0 && j > 0) {
        if (s[i - 1] == t[j - 1]) {
            ans += s[i - 1];
            i--; j--;
        }
        else if (dp[i - 1][j] >= dp[i][j - 1]) {
            i--;
        }
        else {
            j--;
        }

    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

}

Measured memory_bytes: 38816
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long LL;
double n,m,d;
int main(){
	scanf("%lf%lf%lf",&n,&m,&d);
	if(d!=0) printf("%lf\n",(m-1)*2*(n-d)*(1/(n*n)));
	else printf("%lf\n",(m-1)*2*(n-d)*(1/(n*n))/2);
}

Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-18.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, M;
priority_queue<ll> que;

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        que.push(a);
    }

    for (int i = 0; i < M; ++i) {
        ll a = que.top();
        que.pop();
        que.push(a / 2);
    }

    ll ans = 0;
    while (!que.empty()) {
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
long long int powmod(long long int a, long long int b, long long int p){
  if( b == 0 ) return 1;
  if( b%2 == 0 ){
    long long int d = powmod(a, b/2, p);
    return ((d%p) * (d%p)) % p;
  }
  return ( (a%p) * (powmod(a, b-1, p)%p) ) % p;
}
int main(void) {
  int m, n;
  cin >> m >> n;
  cout << powmod(m, n, 1000000007) << endl;

  return 0;
}





// EOF

Measured memory_bytes: 3100
N, K = list(map(int,input().split()))
move_list = list(map(int,input().split()))
 
  
test = 1
find_f = {}
for i in range(N):
  find_f[i+1]=[]
 
find_f[1].append(0)
for i in range(K):
  test = move_list[test-1]
  find_f[test].append(i+1)
  if len(find_f[test]) == 2 and find_f[test][1]-find_f[test][0]<=1000000:
    state ,f = test, find_f[test]
    break
try:
  K = K-f[0]
  f = f[1]-f[0]
  remain = K%f
  for i in range(remain):
    state = move_list[state-1]
 
  print(state)
except:
  print(test)
#state = 1

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

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if ((S[i] - '0') == now) cnt++;
        else {
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0)
        nums.push_back(cnt);
    if (nums.size() % 2 == 0)
        nums.push_back(0);

    int res = 0;
    int add = 2 * K + 1;

    int left = 0;
    int right = 0;
    int sum = 0;

    for (int i = 0; i < nums.size(); i += 2) {
        int next_left = i;
        int next_right = min(i + add, (int)nums.size());

        while (next_left > left) {
            sum -= nums[left];
            left++;
        }
        while (next_right > right) {
            sum += nums[right];
            right++;
        }
        res = max(res, sum);
    }

    cout << res << endl;
    return 0;
}

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

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

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

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

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

const int MAX = 100100;

VI g[MAX];

int go(int x, int p)
{
	int s = 0;
	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (to == p) continue;

		int v = go(to, x) + 1;

		s ^= v;
	}

	return s;
}

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

	int n;
	scanf("%d", &n);
	FOR (i, 0, n-1)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		g[x].PB(y);
		g[y].PB(x);
	}

	int v = go(0, -1);

	if (v == 0) cout<<"Bob"<<endl;
	else cout<<"Alice"<<endl;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  vector<int> p(n),ptoi(n);
  for(int i=0;i<n;i++){
    cin >> p[i];
    ptoi[--p[i]]=i;
  }
  int ans=1,tmp=1;
  for(int i=1;i<n;i++){
    if(ptoi[i]>ptoi[i-1]) tmp++;
    else{
      ans=max(ans,tmp);
      tmp=1;
    }
  }
  ans=max(ans,tmp);
  cout << n-ans << endl;
  return 0;
}


Measured memory_bytes: 1792
# D Knapsack 1

from collections import deque

n, w = map(int,input().split())
wv_list = deque([[int(x) for x in input().split()] for y in range(n)])

dp = [[float("-Inf")] * (w+1) for _ in range(n+1)]
dp[0] = [0]*(w+1)

for i in range(n):
    _w,_v = wv_list.popleft()
    for j in range(w+1):
        if j-_w < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-_w]+_v)

print(dp[n][w])

Measured memory_bytes: 305896
from collections import Counter
N = int(input())
if N == 1:
    print(1)
else:
    X = []
    for i in range(N):
        xi,yi = map(int,input().split())
        X.append((xi,yi))
    L = []
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            x,y = X[i][0]-X[j][0],X[i][1]-X[j][1]
            L.append((x,y))
    m = Counter(L).most_common()[0][1]
    print(N-m)


Measured memory_bytes: 39664
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000000000000000
typedef long long ll;

int main() {
  int N;
  bool of = false;
  cin >> N;
 
  vector<ll> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    if(A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
 
  ll ans = A[0];
  for(int i = 1; i < N; i++) {
    if(A[i] <= MAX/ans)
      ans *= A[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, k;
vector<pair<long long, long long>> v;

long long solve();

int main() {
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    long long x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 5000000000000000000;
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      for(int m = 0; m < n; ++m)
        for(int l = 0; l < n; ++l) {
          long long ld, rd, ud, dd, cnt = 0;
          ld = min(min(v[i].fi, v[j].fi),
                   min(v[m].fi, v[l].fi));
          rd = max(max(v[i].fi, v[j].fi),
                   max(v[m].fi, v[l].fi));
          ud = max(max(v[i].se, v[j].se),
                   max(v[m].se, v[l].se));
          dd = min(min(v[i].se, v[j].se),
                   min(v[m].se, v[l].se));
          for(int o = 0; o < n; ++o)
            if(ld <= v[o].fi && v[o].fi <= rd &&
               dd <= v[o].se && v[o].se <= ud)
              ++cnt;
          if(cnt >= k)
            ans = min(ans, (rd - ld) * (ud - dd));
        }
  return ans;
}

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

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

    int a[M];
    for(int i = 0; i < M; i++) {
        cin >> a[i];
        if(i != 0 && a[i] - a[i-1] <= 1){
            cout << 0 << endl;
            return 0;
        }
    }

    long long num[N+1];
    num[0] = 1;
    num[1] = 1;
    for(int i = 2; i < N+1; i++) {
        num[i] = (num[i-1] + num[i-2]) % 1000000007;
    }

    int now = 0;
    long long ans = 1;
    int i=0;
    for(int i = 0; i < M; i++) {
        ans = (ans * num[a[i] - now - 1]) % 1000000007;
        now = a[i]+1;
    }
    ans = (ans * num[N - now]) % 1000000007;
    
    cout << ans << endl;
    

    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> S>>N;

    ll size = S.size();
    ll flag = 0;

    ll count = 0;
    if(size==1){
        cout << S << endl;
    }
    
    else
    {
        REP(i, size)
        {
            if (!(S.at(i) == '1'))
            {
                cout << S.at(i) << endl;
                flag = 1;
                break;
            }
            else{
                count++;
                if(N<=count){
                    cout << 1 << endl;
                    flag = 1;
                    break;
                }
            }
        }
        if (flag == 0)
        {
            cout << 1 << endl;
        }
    }
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	string s;
	cin>>s;
	bool f=0;
	if(s[0]=='7'||s[1]=='7'||s[2]=='7')f=1;
	cout<<(f?"Yes":"No");
	return 0;
}


Measured memory_bytes: 3596
//Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define deb(x)          cout << #x << " = " << x << endl
int main()
{
    start;
    ll i,j,k,n,m;
    cin>>n;
    if(n<3)
        cout<<0<<endl;
    else
    {
        ll dp[n]={0};
        for(i=3;i<=n;i++)
        {
            dp[i]=1;
            for(j=3;j<i;j++)
            {
                    dp[i]+=dp[i-j];
                    dp[i]%=mod;
            }
        }
        cout<<dp[n]<<endl;
    }
    rr;
}


Measured memory_bytes: 3640
a=int(input())
b=int(input())
c=int(input())
x=int(input())
n=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                n+=1
print(n)


Measured memory_bytes: 9044
import heapq

n = int(input())
*arr, = map(int, input().split())


right = [0] * 3 * n


def build_prefix(arr):
    left = [0] * 3 * n
    h = []
    s = 0
    for i in range(len(arr)):
        if len(h) < n:
            heapq.heappush(h, arr[i])
            s += arr[i]
        else:
            heapq.heappush(h, arr[i])
            removed = heapq.heappop(h)
            s = s - removed + arr[i]
        left[i] = s
    return left

left = build_prefix(arr)
right = build_prefix([-v for v in arr][::-1])[::-1]

ans = -sum(arr)
for i in range(n - 1, 2 * n):
    ans = max(ans, left[i] + right[i + 1])
print(ans)






Measured memory_bytes: 141392
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int N,ans=0;
  cin>>N;
  vector <int> s(N);
  for(int i=0;i<N;i++){
    cin>>s[i];
    ans+=s[i];
  }
  sort(s.begin(),s.end());
  if(ans%10==0){
    for(int i=0;i<N;i++){
      if(s[i]%10==0){
        continue;
      }else{
        ans-=s[i];
        break;
      }
    }
  }

  if(ans%10==0) ans=0;

  cout<<ans<<endl;

}


Measured memory_bytes: 256
//
//  main.cpp
//  ALDS1_7_B
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
#define MX 100000
#define NIL -1
using namespace std;
using P=pair<int,int>;
using ll = long long;
const ll INF=1e18;
struct Node { int parent,left,right; };
Node T[MX]; // 節
int D[MX],H[MX]; // D:深さ（根からの距離）　H:高さ（葉からの距離）
void setDepth(int u,int d){
    if(u==NIL)return;
    D[u]=d;
    setDepth(T[u].left, d+1); // 左の子があるなら、左の子の深さ（根からの距離）は今の深さ+1
    setDepth(T[u].right, d+1); // 右の子があるなら、右の子の深さ（根からの距離）は今の深さ+1
}
int setHeight(int u){
    int h1=0;
    int h2=0;
    if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;//左の子があるなら、左の子の高さ+1が私の高さの候補
    if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;//右の子があるなら、左の子の高さ+1が私の高さの候補
    return H[u]=max(h1,h2); // 大きい方が自分の高さ
}
int getSibling(int u){ // 自分の兄弟を探す
    if (T[u].parent==NIL) return NIL; // 根はひとつ、兄弟はいない
    if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL) {
        return T[T[u].parent].left;
        // 自分の兄弟は、自分の親の左の子が自分じゃないなら左の子が自分の兄弟
    }
    if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) {
        return T[T[u].parent].right;
        // 自分の兄弟は、自分の親の右の子が自分じゃないなら右の子が自分の兄弟
    }
    return NIL; // 自分の親に自分以外に子がいない時（兄弟がいない時）
}
void print(int u){
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg=0; // 二分木なので子の数は、０〜２
    if(T[u].left!=NIL) deg++;
    if(T[u].right!=NIL) deg++;
    printf("degree = %d, ",deg); // 子の数
    printf("depth = %d, ",D[u]); // 深さ
    printf("height = %d, ",H[u]); // 高さ
    if (T[u].parent==NIL) {
        printf("root\n");
    }else if(T[u].left==NIL&&T[u].right==NIL){
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}
int main(int argc, const char * argv[]) {
    int v,l,r;
    int n;
    scanf("%d",&n);
    rep(i,n)T[i].parent=NIL; // T[*]は節の情報　parent left right
    rep(i,n){
        scanf("%d %d %d",&v,&l,&r); // v:節番号　l:左の子　r:右の子
        T[v].left=l;
        T[v].right=r;
        if (l!=NIL) T[l].parent=v;
        if(r!=NIL) T[r].parent=v;
    }
    int root=0;
    rep(i,n){ // 根を探す
        if(T[i].parent==NIL){
            root=i;
        }
    }
    setDepth(root, 0); // 根から順番に深さをセット
    setHeight(root); // 根から順番に高さをセット
    rep(i,n) print(i);
    
    return 0;
}



Measured memory_bytes: 3236
// ?????§???????±??????? ?????§???????????????F??¨????????????O(F|E|) ?????????????????¨??????????????????:max_flow()
// ?????¬p.190
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

#define INF INT_MAX
// ????????°????????§??°
#define MAX_V 100000
// ??°????????????????????°
int V;
// ??°?????????edge?????????????????¨????????????????????¨?????¨???
vector <int> graph[MAX_V];
int match[MAX_V];
bool vis[MAX_V];

// 
void add_edge(int u, int v) {
  graph[u].push_back(v);
  graph[v].push_back(u);
}

bool dfs(int v) {
  vis[v] = true;
  for (int i = 0; i < graph[v].size(); i++) {
    int u = graph[v][i], w = match[u];
    if (w < 0 || !vis[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int ret = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(vis, false, sizeof(vis));
      if (dfs(v)) {
	ret++;
      }
    }
  }
  return ret;
}

int main() {
  int x, y, e;
  cin >> x >> y >> e;
  V = x+y;
  for (int i = 0; i < e; i++) {
    int s, t;
    cin >> s >> t;
    add_edge(s, x+t);
  }

  cout << bipartite_matching() << endl;
}

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

main() {
  int N, M; cin >> N >> M;;
  vvi graph(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  bool ans = false;
  for (auto&& i : graph[0]) {
    if (count(graph[i].begin(), graph[i].end(), N - 1) != 0) ans = true;
  }
  cout << ((ans) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 12016
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<ctime>
#include<string>
#include<cstring>
#define ll long long
#define inf 0x7fffffff
using namespace std;
int main(){
	char s[1000];
	cin>>s;
	int len=strlen(s);
	printf("%c%d%c",s[0],len-2,s[len-1]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,ans=0,memo=-1;
  cin>>N;
  REP(i,1,N){
    int X;
    cin>>X;
    if(X==i){
      if(memo!=i-1){
        ans++;
        memo=i;
        }
      }
    }
  cout<<ans;
  }


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
   int n,g=0;
   string s;
   cin >>n>>s;
   for(int i = 0; i < n; i++){
       if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')g++;
   }
    cout << g;
    return 0;
}


Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
# 終端でソート、昇順
ab = sorted([list(map(int,input().split())) for _ in [0]*M],key=lambda x:x[1])
x = cnt = 0
for(a,b)in ab:
  #終端ノードを超える始端ノードがあれば、カバー外なので追加
   if x < a:
      x = b - 1
      cnt += 1
print(cnt)

Measured memory_bytes: 29668
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <vector>

#define MAX_N (200000)
#define INF (1000000000)

using namespace std;

// int is_possible(const int *as, int N, int K) {
//   map<int, int> cs;
//   int a_prev = 0;
//   for (int i = 0; i < N; i++) {
//     const int a = as[i];
//     if (a > a_prev) {
//       // 'a's are added to the back of the string.
//       // don't need to do anything.
//     } else {
//       // letter at position a - 1 must be incremented.
//       int j = a - 1, c = ++cs[j];
//       while (c >= K) {
//         if (j > 0) {
//           // increment the letter before
//           c = ++cs[j - 1];
//           cs.erase(j);
//           j--;
//         } else {
//           // impossible
//           return 0;
//         }
//       }
//       // also, letters at position a and beyond are deleted.
//       cs.erase(cs.find(a), cs.end());
//     }
//     a_prev = a;
//   }
//   return 1;
// }

int is_possible(const int *as, int N, int K) {
  int idxs[MAX_N], cnts[MAX_N], tail = 0;
  int a_prev = 0;
  for (int i = 0; i < N; i++) {
    const int a = as[i];
    if (a > a_prev) {
      // 'a's are added to the back of the string.
      // don't need to do anything.
    } else {
      // letters at position a and beyond are deleted.
      tail = lower_bound(idxs, idxs + tail, a) - idxs;
      // letter at position a - 1 must be incremented.
      if (!(tail > 0 && idxs[tail - 1] == a - 1)) {
        // add entry for position a - 1 if it doesn't exist.
        idxs[tail] = a - 1;
        cnts[tail] = 0;
        tail++;
      }
      cnts[tail - 1]++;
      a_prev = a;
      while (cnts[tail - 1] >= K) {
        if (idxs[tail - 1] > 0) {
          // increment the letter before
          if (tail - 1 > 0 && idxs[tail - 2] == idxs[tail - 1] - 1) {
            cnts[tail - 2]++;
            tail--;
          } else {
            idxs[tail - 1]--;
            cnts[tail - 1] = 1;
          }
        } else {
          // impossible
          return 0;
        }
      }
    }
    // printf("i = %d, tail = %d\n", i, tail);
    // for (int j = 0; j < tail; j++) {
    //   printf("j = %d, idxs[j] = %d, cnts[j] = %d\n", j, idxs[j], cnts[j]);
    // }
    a_prev = a;
  }
  return 1;
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // solve binary search
  int le = 0, ri = N;
  while (ri - le > 1) {
    const int m = (le + ri) / 2;
    if (is_possible(as, N, m)) {
      ri = m;
    } else {
      le = m;
    }
  }
  printf("%d\n", ri);

  return 0;
}


Measured memory_bytes: 896
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, M = MAP()
PY = [LIST() for _ in range(M)]

for i in range(M):
	PY[i].append(i)

PY.sort(key = lambda x: (x[0], x[1]))

tmp = 0
cnt = 0
for i in range(M):
	if PY[i][0] != tmp:
		cnt = 1
		tmp = PY[i][0]
	else:
		cnt += 1
	PY[i].append(str(PY[i][0]).zfill(6)+str(cnt).zfill(6))

PY.sort(key = lambda x:x[2])

print(*[PY[i][3] for i in range(M)], sep = "\n")


Measured memory_bytes: 42068
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)


minval=9999999999;
minuscount=0;
(0..n-1).each do |i|
	aaa=a[i]<0 ? -a[i] : a[i]
	if aaa<minval
		minval=aaa
	end
	if a[i]<0 
		minuscount+=1
		a[i]*=-1
	end
end

sumval=a.inject(:+)

if minuscount%2==0
	puts sumval
else
	puts sumval-minval*2
end


Measured memory_bytes: 9732