akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

typedef long long  Weight;
struct Edge {
	int src, dest;
	int cap, rev;
	Weight weight;
	bool operator < (const Edge &rhs) const { return weight > rhs.weight; }
};

const int V = 4000;
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
Weight h[V];                //ポテンシャル
Weight dist[V];             //最短距離
int prevv[V], preve[V];  //直前の辺と頂点

void add_edge(Graph &g, int src, int dest, int cap, Weight weight) {
	g[src].push_back(Edge{ src, dest, cap, (int)g[dest].size(), weight });
	g[dest].push_back(Edge{ dest, src, 0, (int)g[src].size() - 1, -weight });
}
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const Weight INF = 2147483647;
const Weight ZERO = 0;
int eps=0;
//コストがdoubleの時はeps使おう
int min_cost_flow(Graph &g, int s, int t, int f) {
	Weight res = ZERO;
	memset(h, ZERO, sizeof(h));
	typedef pair<Weight, int> P;
	while (f > 0) {
		priority_queue<P, vector<P>, greater<P> > que;
		fill(dist, dist + V, INF);
		dist[s] = 0;
		que.push(P(ZERO, s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			const int v = p.second;
			if (dist[v] < p.first) continue;
			REP(i, g[v].size()) {
				Edge &e = g[v][i];
				if (e.cap > 0 && dist[e.dest] > dist[v] + e.weight + h[v] - h[e.dest] + eps) {
					dist[e.dest] = dist[v] + e.weight + h[v] - h[e.dest];
					prevv[e.dest] = v;
					preve[e.dest] = i;
					que.push(P(dist[e.dest], e.dest));
				}
			}
		}
		if (dist[t] == INF) return f;
		for (int v = 0; v < V; ++v) h[v] = h[v] + dist[v];

		int d = f;
		for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap);
		f -= d;
		res = res + d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			Edge &e = g[prevv[v]][preve[v]];
			e.cap -= d;
			g[v][e.rev].cap += d;
		}
	}
	return f;
}

int main() {
	int N; cin >> N;
	vector<pair<int, int>>ps;
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b;
		ps.push_back(make_pair(a, b));
	}
	const int start = 0;
	const int t_in = 1;
	const int t_out = t_in + N;
	const int goal = t_out + N;
	Graph g(goal + 1);

	for (int i = 0; i < N; ++i) {
		add_edge(g, start, t_in + i, 1, 0);
		add_edge(g,t_out+i,goal,1,0);
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			auto pi(ps[i]);
			auto pj(ps[j]);
			if ((pi.first < pj.first&&pi.second < pj.second) ||
				(pi.first < pj.second&&pi.second < pj.first)) {
				add_edge(g, t_in + i, t_out + j, 1, 0);
			}
		}
	}

	auto cost=min_cost_flow(g,start,goal,N);
	cout<<cost<<endl;
	return 0;
}


Measured memory_bytes: 3356
# 入力値の取得
n = gets.chomp.to_i
cards = gets.chomp.split(" ").map(&:to_i)

# 制約のチェック
raise "Nは1以上、100以下" unless n.between?(1, 100)
raise "カードはN枚" unless cards.size == n
raise "カードの数値は1以上、100以下" unless cards.select { |num| num.between?(1, 100) }.size == n

# 計算
cards.sort! { |a, b| b <=> a }
alice = cards.select.with_index { |card, index| index.even? }.inject(:+)
bob = cards.select.with_index { |card, index| index.odd? }.inject(:+)

puts alice - bob


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define N 100000
using namespace std;

long par[N];
long p_rank[N];

void init(long n) {
    for (long i = 0; i < n; ++i) {
        par[i] = i;
        p_rank[i] = 0;
    }
}

long find(long x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(long x, long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (p_rank[x] < p_rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (p_rank[x] == p_rank[y]) p_rank[x]++;
    }
}

bool same(long x, long y) {
    return find(x) == find(y);
}

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

    long n, m;
    cin >> n >> m;
    init(n);
    long p[n];
    for (int i = 0; i < n; ++i) cin >> p[i];
    
    int first, second;
    for (int i = 0; i < m; ++i) {
        cin >> first >> second;
        unite(first - 1, second - 1);
    }

    long sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += same(i, p[i] - 1);
    }
    
    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 2560
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		log.Fatal(e)
	}
	return i
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}
func main() {
	sc.Split(bufio.ScanWords)

	s := getString()
	if s == "ABC" {
		out("ARC")
	} else {
		out("ABC")
	}
}


Measured memory_bytes: 1756
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    vector<ll>a(n);
    REP(i,n)cin >> a[i];
    
    
    REP(i,n-k){
        if(a[i] < a[i+k])cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4792
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n, k = LI()

counts = 0
for b in range(1, n+1):
    p, r = divmod(n, b)
    counts += max(0, p*(b-k)) + max(0, r-k+1)
    if k == 0:
        counts -= 1

    #print("mid: ", counts)

print(counts)

Measured memory_bytes: 6736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

struct LazySegmentTree{//区間加算,区間和クエリ,0オリジン
    private:
        int n;
        vector<ll>node,lazy;
    
    public:
        LazySegmentTree(vector<ll>v){
            int sz=(int)v.size();
            n=1;
            while(n<sz)n*=2;
            node.resize(2*n-1);
            lazy.resize(2*n-1,0);

            for(int i=0;i<sz;i++)node[i+n-1]=v[i];
            for(int i=n-2;i>=0;--i)node[i]=node[2*i+1]+node[2*i+2];
        }

        //k番目のノードについて遅延評価
        void eval(int k,int l,int r){
            //遅延配列が空でなければ値の伝播が起こる
            if(lazy[k]!=0){
                node[k]+=lazy[k];

                if(r-l>1){//最下段かどうかの確認
                    lazy[2*k+1]+=lazy[k]/2;
                    lazy[2*k+2]+=lazy[k]/2;
                    //子ノードは親ノードの半分の範囲なので値も半分
                }

                lazy[k]=0;//空にする
            }
        }

        void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
            if(r<0)r=n;

            //k番目のノードに遅延評価
            eval(k,l,r);

            //範囲外
            if(b<=l||r<=a)return;

            //完全に被覆しているなら遅延配列に代入した後に評価
            if(a<=l&&r<=b){
                lazy[k]+=(r-l)*x;
                eval(k,l,r);
            }

            //それ以外なら子ノードを再帰的に計算
            else{
                add(a,b,x,2*k+1,l,(l+r)/2);
                add(a,b,x,2*k+2,(l+r)/2,r);
                node[k]=node[2*k+1]+node[2*k+2];
            }
        }

        ll getsum(int a,int b,int k=0,int l=0,int r=-1){//区間和の取得
            if(r<0)r=n;
            if(b<=l||r<=a)return 0;

            eval(k,l,r);
            if(a<=l&&r<=b)return node[k];
            ll vall=getsum(a,b,2*k+1,l,(l+r)/2);
            ll valr=getsum(a,b,2*k+2,(l+r)/2,r);
            return vall+valr;
        }
};

void solve(){
    int n,q;
    cin>>n>>q;
    vector<ll>v(n);
    LazySegmentTree seg(v);
    while(q--){
        int query;
        cin>>query;
        if(query==0){
            int s,t,x;
            cin>>s>>t>>x;
            s--;t--;
            seg.add(s,t+1,x);//半開区間
        }
        else {
            int s,t;
            cin>>s>>t;
            s--;t--;
            cout<<seg.getsum(s,t+1)<<"\n";//半開区間
        }
    }
}
 
 
signed main(){
	ios::sync_with_stdio(false);
        cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 8656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int res=0;
    int n,m;
    cin>>n>>m;
    long long a[n+2];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
       cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]*4*m>=sum)   res++;
    }
    if(res>=m)  cout<<"Yes";
    else    cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<limits>
#include<stack>
#include<queue>
#include<math.h>
#include <iomanip>

#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+(A%B==0?0:1)
#define maximize(A,B) A=max((A),(B))
#define read(type,name) type name;cin>>name
#define ll long long

using namespace std;
template<typename T>
T MAX() { return numeric_limits<T>::max(); }

//二次元テーブル
template<typename T>
class Table {
public:
	Table(int height, int width, T value) {
		if (width < 0)throw out_of_range("Width should be >=0");
		if (height < 0)throw out_of_range("Height should be >=0");
		this->wid = width;
		this->hgt = height;
		vs = new T[width * height];
		for (auto i = 0; i < width * height; i++)vs[i] = value;
	}
	Table(const Table& table) {
		hgt = table.hgt;
		wid = table.wid;
		vs = new T[hgt * wid];
		for (size_t i = 0; i < table.size(); i++) {
			vs[i] = table.vs[i];
		}
	}
	Table(Table&& table) {
		hgt = table.hgt;
		wid = table.wid;
		swap(vs, table.vs);
	}
	~Table() {
		if (vs)delete[] vs;
	}
	Table& operator=(const Table& table) {
		if (table == *this)return *this;
		this->wid = table.wid;
		this->hgt = table.hgt;
		if (vs)delete[] vs;
		vs = new T[wid * hgt];
		for (auto i = 0; i < wid * hgt; i++)vs[i] = table.vs[i];
	}
	Table& operator=(Table&& table) {
		wid = table.wid;
		hgt = table.hgt;
		swap(vs, table.vs);
	}
	inline T& at(int y, int x) {
		if (wid > x)throw out_of_range("x>width.");
		if (hgt > y)throw out_of_range("y>height.");
		return vs[x + y * wid];
	}
	int size()const { return wid * hgt; }
	int width()const { return wid; };
	int height()const { return hgt; };
	T* begin() { return vs; }
	T* end() { return vs + wid * hgt; }
	T& operator()(int y, int x) { return vs[x + y * wid]; }
	const T& operator()(int y, int x)const { return vs[x + y * wid]; }
private:
	int wid, hgt;
	T* vs;
};
//Nが偶数であれば偶奇が同じ数だけあるので0.5である。
//Nが奇数2k+1である場合はk+1個の奇数とk個の偶数が存在する
void A() {
	read(int, N);
	if (N % 2 == 0)cout << 0.5 << endl;
	else cout << (double)(N / 2 + 1) / N << endl;
}

//前から順に操作すればよい。
//空間量としてはO(1)である。
void B() {
	read(int, N);
	read(int, K);
	int h; int result = 0;
	for (auto i = 0; i < N++; i++) {
		cin >> h; if (h >= K)result;
	}
	cout << result << endl;
}


//人数を時刻と読み替えてもよい。
//ソートの問題と考えることもできる。ソート前の位置を出力すればいい。
//優先度キューで出してもよい。N個の配列で時刻の位置に格納してもよい。
void C() {
	read(int, N);
	auto timeLine = vector<int>(N);
	int time;
	for (size_t i = 0; i < N; i++) {
		cin >> time;
		timeLine[time - 1] = i + 1;
	}
	for (auto i : timeLine)cout << i << " ";
	cout << endl;
}

void D() {

}

void E() {}
void F() {}

int main() {
	C();
}

Measured memory_bytes: 3656
#include<stdio.h>

int main(){
int N;
int c=0;
char S[51];
	scanf("%d",&N);
	scanf("%s",&S);
	for(int i=0;i<N-2;i++){
		if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C')c++;
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 128
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 1e5 + 10;
int A[MAXN],B[MAXN];


void solve(){
    int a,b,m; cin>>a>>b>>m;

    FOR(i,1,a) cin>>A[i];
    FOR(i,1,b) cin>>B[i];

    int miniA = *min_element(A+1,A+a+1);
    int miniB = *min_element(B+1,B+b+1);
    
    int ans = miniA + miniB;

    FOR(i,1,m){
        int x,y,c; cin>>x>>y>>c;
        ans = min(ans,A[x] + B[y] - c);
    }

    cout<<ans<<endl;
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871;
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> ll(n);
    for(int i = 0; i < n; i++) cin >> ll[i];
    sort(ll.begin(), ll.end());
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                if(ll[i] == ll[j]) continue;
                if(ll[j] == ll[k]) continue;
                if(ll[i] == ll[k]) continue;
                if(ll[k] < ll[i] + ll[j]) ans++;
            }
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3648
import collections

n = int(input())
a_list = list(map(int, input().split()))
a_counter = collections.Counter(a_list)

# print(a_counter)

sum = 0
for value in a_counter.values():
  if value == 1:
    continue
  sum += int(value * (value - 1) / 2)
  
# print(sum)

ans = 0
for a in a_list:
  ans = sum - (a_counter[a] - 1)
  print(ans)

Measured memory_bytes: 26772
import math
# import datetime

def s(n):
	sum = 0
	for c in str(n):
		sum += int(c)
	return sum

k = int(input())
found=0

def next_sunuke(n, s_n, s_n_div):

	global found

	if n == 1:
		return

	log_n = int(math.log(n,10))
	m = n - 10 ** int(log_n // 1.25)

	while m >= 1:
		s_m = s(m)
		s_mplus1 = s(m + 1)

		if (s_m < s_mplus1 or (s_n - s_m != 1 and s_n - s_m != -8 and s_n - s_m != -17)) and m > 9:
			m -= 10 ** int(log_n // 1.25)
			continue

		# print("check: " + str(m))

		s_m_div = m / s(m)

		if s_m_div <= s_n_div:
			next_sunuke(m, s_m, s_m_div)
			if found >= k:
				return

			found += 1
			# print("{0:d}".format(m), "{0:+d}".format(n-m), "{0:d}".format(s_m), s_m_div)
			print(m)
			break


		m -= 10 ** int(log_n // 1.25)


# 適当な大きいスヌケ数
current_sunuke = 999999999999999
s_current_sunuke = s(current_sunuke)
s_current_sunuke_div = current_sunuke / s_current_sunuke

# start = datetime.datetime.now()
next_sunuke(current_sunuke, s_current_sunuke, s_current_sunuke_div)
if found < k:
	print(current_sunuke)
# end = datetime.datetime.now()
# print(str(end-start))


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (k >= a) {
    if (k - a >= b) {
      b = 0;
    } else {
      b = b - (k - a);
    }
    a = 0;
  } else {
    a -= k;
  }
  cout << a << " " << b << endl;

  return 0;
}





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

int main() {
    string s;
    cin >> s;
    int len = s.length();

    vector<int> letter(26);
    for (int i = 0; i < len; i++) {
        letter[s[i] - 'a'] = 1;
    }

    for (int i = 0; i < 26; i++) {
        if(!letter[i]) {
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<map>

const int mod1=998244353,g1=504510733,ig1=799218450;
const int mod2=1000000009,g2=486738396,ig2=567937635;

int n;
char C[600000];

int fha1,fha2,pw1[600000],pw2[600000],ipw1[600000],ipw2[600000];
inline void chkinc(int &C,int P){C+=C>>31&P;}
long long ans;

void solve(int L,int R){
	if (L==R){
		switch (C[L]){
			case '<':
				ans+=!fha1&&!fha2;
				break;
			case '>':
				ans+=!fha1&&!fha2;
				break;
			case '-':
				ans+=(mod1-pw1[250000]==fha1&&mod2-pw2[250000]==fha2);
				break;
			case '+':
				ans+=(pw1[250000]==fha1&&pw2[250000]==fha2);
				break;
		}
	}
	else{
		int mdl=(L+R)>>1;
		solve(L,mdl);
		solve(mdl+1,R);
		int ha1=0,ha2=0,pos=250000;
		std::map<std::pair<int,int>,int> M;
		for (int i=mdl+1;i<=R;i++){
			switch (C[i]){
				case '<':
					pos--;
					break;
				case '>':
					pos++;
					break;
				case '-':
					chkinc(ha1-=pw1[pos],mod1);
					chkinc(ha2-=pw2[pos],mod2);
					break;
				case '+':
					chkinc(ha1+=pw1[pos]-mod1,mod1);
					chkinc(ha2+=pw2[pos]-mod2,mod2);
					break;
			}
			M[std::make_pair(ha1,ha2)]++;
		}
		ha1=0,ha2=0,pos=0;
		for (int i=mdl;i>=L;i--){
			switch (C[i]){
				case '<':
					pos--;
					ha1=static_cast<long long>(ha1)*ig1%mod1;
					ha2=static_cast<long long>(ha2)*ig2%mod2;
					break;
				case '>':
					pos++;
					ha1=static_cast<long long>(ha1)*g1%mod1;
					ha2=static_cast<long long>(ha2)*g2%mod2;
					break;
				case '-':
					chkinc(ha1-=pw1[250000],mod1);
					chkinc(ha2-=pw2[250000],mod2);
					break;
				case '+':
					chkinc(ha1+=pw1[250000]-mod1,mod1);
					chkinc(ha2+=pw2[250000]-mod2,mod2);
					break;
			}
			if (pos>=0){
				int a1=static_cast<long long>(fha1-ha1+mod1)*ipw1[pos]%mod1;
				int a2=static_cast<long long>(fha2-ha2+mod2)*ipw2[pos]%mod2;
				ans+=M[std::make_pair(a1,a2)];
			}
			else{
				int a1=static_cast<long long>(fha1-ha1+mod1)*pw1[-pos]%mod1;
				int a2=static_cast<long long>(fha2-ha2+mod2)*pw2[-pos]%mod2;
				ans+=M[std::make_pair(a1,a2)];
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	scanf("%s",C);
	pw1[0]=pw2[0]=ipw1[0]=ipw2[0]=1;
	for (int i=1;i<=500000;i++){
		pw1[i]=static_cast<long long>(pw1[i-1])*g1%mod1;
		pw2[i]=static_cast<long long>(pw2[i-1])*g2%mod2;
		ipw1[i]=static_cast<long long>(ipw1[i-1])*ig1%mod1;
		ipw2[i]=static_cast<long long>(ipw2[i-1])*ig2%mod2;
	}
	for (int i=0,P=250000;i<n;i++){
		switch (C[i]){
			case '<':
				P--;
				break;
			case '>':
				P++;
				break;
			case '-':
				chkinc(fha1-=pw1[P],mod1);
				chkinc(fha2-=pw2[P],mod2);
				break;
			case '+':
				chkinc(fha1+=pw1[P]-mod1,mod1);
				chkinc(fha2+=pw2[P]-mod2,mod2);
				break;
		}
	}
	solve(0,n-1);
	printf("%lld\n",ans);
}


Measured memory_bytes: 24960
using System;
using System.Linq;

class Test {
	static void Main(string[] args) {
      var inputs = System.Console.ReadLine()
    	.Split(' ')
    	.Select(s => int.Parse(s))
    	.ToArray();
      int N = inputs[0];
      int D = inputs[1];
	  var X = new System.Collections.Generic.List<int[]>(N);
      for(int i = 0; i < N; i++){
        var values = System.Console.ReadLine().Split(' ').Take(2);
   		X.Add(values.Select(v => System.Int32.Parse(v)).ToArray());
      }
      int cnt = 0;
      for(int i = 0; i < N; i++){
        if(Math.Sqrt(Math.Pow(X[i][0],2) + Math.Pow(X[i][1],2)) <= D)
          cnt++;
      }
      Console.WriteLine(cnt);
	}
}

Measured memory_bytes: 32248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
       
        LinkedList<Integer> list = new LinkedList<Integer>();
//        int index = 0;
        ListIterator<Integer> it = list.listIterator();
        for(int i = 0; i < n; i++){
        	String[] tmpArray = br.readLine().split(" ");
        	
        	//insert
        	if(tmpArray[0].equals("0")){
//        		list.add(index, Integer.parseInt(tmpArray[1]));
        		it.add(Integer.parseInt(tmpArray[1]));
        		it.previous();
        	}
        	//move
        	else if(tmpArray[0].equals("1")){
//        		index += Integer.parseInt(tmpArray[1]);
        		int x = Integer.parseInt(tmpArray[1]);
        		
        		if(x > 0){
        			for(int j = 0; j < x; j++){
        				it.next();
        			}
        		}
        		else {
        			for(int j = 0; j < -x; j++){
        				it.previous();
        			}
        		}
        	}
        	//remove
        	else {
//        		list.remove(index);
        		it.next();
        		it.remove();
        	}
//        	printList(list);
//        	System.out.println("------");
        }
        
        printList(list);
    }
    
    static void printList(List list){
    	Iterator it = list.listIterator(0);
        
        while(it.hasNext()){
        	System.out.println(it.next());
        }
    }
    
}


Measured memory_bytes: 123296
# solution

import io
import math
import scipy.sparse
import numpy
from collections import deque

q = deque();K=int(input());q+=[(1,1)];m={}

while len(q):
	n,s=q.pop()
	if not n in m:m[n]=s;q+=[(n*10%K,s)];q.appendleft(((n+1)%K,s+1))

print(m[0])

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

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

  int64_t ans= 0;
  for(int div= Rmin+1; div<=N; div++){
    ans+= (N/div)*((div-1)- (Rmin-1)) + max(N%div- max(Rmin-1,0), 0);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
/*=================================
# Created time: 2017-04-02 19:53
# Filename: a.cpp
# Description: 
=================================*/
#include <bits/stdc++.h> 
 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define pii pair<int, int> 
#define ls(a,b) (((a)+(b)) << 1) 
#define rs(a,b) (((a)+(b)) >> 1) 
#define fin(a) freopen(a,"r",stdin); 
#define fout(a) freopen(a,"w",stdout); 
#define FORP(i,a,b) for(int i=(a);i<=(b);i++) 
#define FORM(i,a,b) for(int i=(a);i>=(b);i--) 
 
#define maxn 300005 
#define maxm 100005 
#define MOD 1000000007 
#define INF 1070000000 
using namespace std; 
typedef long long ll; 
typedef unsigned long long ull; 
 
template<class T> inline   
void read(T& num){   
    num = 0; bool f = 1;char ch = getchar();   
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}   
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}   
    num = f ? num: -num;   
}  
template<class T> inline 
void write(T x,char ch){ 
	int s[100]; 
	if (x==0) {putchar('0'); putchar(ch); return;} 
	if (x<0) {putchar('-'); x=-x;} int num=0; 
	while (x){ s[num++]=(x%10); x=x/10;} 
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch); 
} 
/*==================split line==================*/ 
const double pi = acos(-1); 
const double eps = 1e-8; 
int n, a[maxn];
ll ans;
int main(){ 
	read(n);
	FORP(i, 1, n + n + n) read(a[i]);
	sort(a + 1, a + n * 3 + 1);
	for (int i = n * 3 - 1, t = 0; t < n; t++, ans += a[i], i -= 2);
	write(ans,'\n');
}


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

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sull(x) scanf("%llu",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf
#define clean fflush(stdout)

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}

ll bigmod(ll a,ll b)
{
    if(b==0)return 1;
    ll x=bigmod(a,b/2)%mod;
    x=(x*x)%mod;
    if(b%2)x=(x*a)%mod;
    return x;
}


ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}

/**
double cosine_rule(double a,double b,double c)
{
    double res=(a*a+b*b-c*c)/(2*a*b);
    res=acos(res);
    return res;
}
*/

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    /** Use "long double"(%Lf) instead of double for precision safety*/
    ll tst,a,b,c,k,n,m,res=0,ans=0,t=0;
    sl(n),sl(m);
    res=ceil((double)n/m);
    cout<<res<<endl;



    return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n;
    ll t[n];
    REP(i,n)cin >> t[i];
    cin >> m;
    ll p[m],x[m];
    REP(i,m)cin >> p[i] >> x[i];

    ll answer;
    REP(i,m){
        answer = 0;
        REP(j,n){
            if(p[i]-1 == j){
                answer+=x[i];
            }
            else{
                answer+=t[j];
            }
        }
        cout << answer << endl;
    }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,D,H;
ll mo=1000000007;

template<class V, int ME> class BIT_mod {
public:
	V bit[1<<ME];
	BIT_mod(){ZERO(bit);};
	V operator()(int e) {ll s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s%mo;}
	V add(int e,V v) { e++; while(e<=1<<ME) { bit[e-1]+=v; bit[e-1] -= (bit[e-1]>=mo)?mo:0; e+=e&-e;}}
};
BIT_mod<ll,20> bt;
ll fact[1010101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	
	cin>>N>>H>>D;

	fact[0]=1;
	for(i=0;i<=1010000;i++) fact[i+1]=fact[i]*(i+1)%mo;
	
	ll sum=0;
	for(i=1;i<=N;i++) sum+=fact[i];
	sum%=mo;
	
	
	bt.add(1,fact[N]);
	bt.add(D+1,mo-fact[N]);
	for(i=1;i<=H-1;i++) {
		ll cur=bt(i)%mo;
		bt.add(i+1,cur*sum%mo);
		bt.add(i+D+1,mo-cur*sum%mo);
	}
	
	cout<<bt(H)%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 16384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <cinttypes>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

typedef pair<ll, ll> P;
inline P operator+(const P& p1, const P& p2) {
  return P(p1.first + p2.first, p1.second + p2.second);
}

enum DISK {
  WHITE_THIN, DARK_THIN, DARK_THICK
};

bool IsOK(vector<DISK> disk) {
  if (disk.size() == 0) {
    return false;
  }
  if (disk.front() == WHITE_THIN || disk.back() == WHITE_THIN) {
    return false;
  }

  for (int i = 0; i < disk.size() - 1; i++) {
    if (disk[i] == WHITE_THIN && disk[i + 1] == WHITE_THIN) {
      return false;
    }
    if (disk[i] == DARK_THIN && disk[i + 1] == DARK_THIN) {
      return false;
    }
    if (disk[i] == DARK_THIN && disk[i + 1] == DARK_THICK) {
      return false;
    }
    if (disk[i] == DARK_THICK && disk[i + 1] == DARK_THICK) {
      return false;
    }
    if (disk[i] == DARK_THICK && disk[i + 1] == DARK_THIN) {
      return false;
    }
  }

  return true;
}

int main() {
  int l, k;
  cin >> l >> k;
  ull dp[102][112];
  fill(dp[0], dp[102], 0);
  dp[0][0] = 1;
  for (int i = 0; i <= l; i++) {
    for (int j = 0; j <= min(l - 1, k * i); j++) {
      if(dp[i][j] == 0) continue;
      if (i % 2 == 0) {
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + k] += dp[i][j];
      } else {
        dp[i + 1][j + 1] += dp[i][j];
      }
    }
  }
  ull ans = 0;
  for (int i = 1; i <= l + 1; i++) {
    for (int j = 0; j <= l; j++) {
//      cerr << dp[i][j] << ' ';
      if (i % 2 == 1)
        ans += dp[i][j];
    }
//    cerr << endl;
  }
  cout << ans << endl;
  return 0;
}

/* */

Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
  int x, n;
  cin >> x >> n;
  vector<int> m(102);
  rep(i,n) {
    int tmp;
    cin >> tmp;
    m[tmp]++;
  }

  int count = 0;
  int result = INF;
  int num = INF;
  while (x + count <= 100) {
    int tmp = m[x + count] == 0 ? count : INF;
    result = min(result, tmp);
    if (result == tmp) num = x + count;
    count++;
  }

  count = 0;
  while (x - count >= 0) {
    int tmp = m[x - count] == 0 ? count : INF;
    result = min(result, tmp);
    if (result == tmp) num = x - count;
    count++;
  }

  if (result != 101 - x) {
    result = min(result, 101 - x);
    if (result == 101 - x) num = 101;
  }
  result = min(result, x + 1);
  if (result == x + 1) num = -1;

  cout << num << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>

using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll mod=1e9+7;

int main(void){
    ll N;
    cin>>N;
    if(N==1) {
        cout<<1<<endl;
        return 0;
    }
    vector<ll> x(N),y(N);
    rep(i,N) cin>>x.at(i)>>y.at(i);
    vector<pair<ll,ll>> kyori(N*(N-1));
    ll kyorinum=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j) continue;
            kyori.at(kyorinum)=make_pair(x.at(i)-x.at(j),y.at(i)-y.at(j));
            kyorinum++;
        }
    }
    
    sort(kyori.begin(),kyori.end());
    kyorinum=1;
    ll ans=1,nowx=kyori.at(0).first,nowy=kyori.at(0).second,sum=1;
    while(kyorinum<N*(N-1)){
        if(nowx==kyori.at(kyorinum).first && nowy==kyori.at(kyorinum).second) sum++;
        else{
            ans=max(ans,sum);
            nowx=kyori.at(kyorinum).first;
            nowy=kyori.at(kyorinum).second;
            sum=1;
        }
        kyorinum++;
    }
    ans=max(ans,sum);
    cout<<N-ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = [int(_) for _ in input().split()]
bef = 0
for i in range(k, n):
    val = a[i]
    bef = a[i-k]
    if val > bef:
        print('Yes')
    else:
        print('No')
    bef = val


Measured memory_bytes: 31744
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int dp[N], go[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	string s;
	
	cin >> s;

	go[0] = -1;

	deque<pair<int,int>> dq;
	dq.push_back(make_pair(n, 0));
	

	for(int i = n - 1; i >= 0; i--) {
		if(s[i] == '1') continue;
		while(dq.size() && dq.front().first > i + m) dq.pop_front();
		if(dq.empty()) {
			cout << -1;
			exit(0);
		}
		go[i] = dq.front().first;
		int now = dq.front().second + 1;
		while(dq.size() && dq.back().second >= now) dq.pop_back();
		dq.push_back(make_pair(i, now));
	}

	if(go[0] == -1) {
		cout << -1;
		exit(0);
	}

	int now = 0;
	while(now != n) {
		cout << go[now] - now << " ";
		now = go[now];
	}
	return 0;
}


Measured memory_bytes: 1104
def mover(H,W):
    k=1
    x,y=0,0
    v=1
    while k<H*W:
        old_x,old_y=x,y

        if not((v==1 and x==W-1) or (v==-1 and x==0)):
            x+=v
        else:
            v*=-1
            y+=1
        yield ((old_x,old_y),(x,y))
        k+=1
#------------------------------------------------
H,W=map(int,input().split())
A=[]
for _ in range(H):
    A.append(list(map(int,input().split())))

Mode=0
D=[]
for ((ox,oy),(x,y)) in mover(H,W):
    if (Mode==0 and A[oy][ox]%2==1) or Mode==1:
        A[oy][ox]-=1
        A[y][x]+=1
        D.append(((ox,oy),(x,y)))
        Mode=A[y][x]%2

print(len(D))
for ((ox,oy),(x,y)) in D:
    print(oy+1,ox+1,y+1,x+1)


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

int main(void){
	int N,A,B;
	cin>>N>>A>>B;
	//vector<int> t(N)
	int tmp;
	int result=0;
	for(int i=0; i<N; ++i){
		cin>> tmp;
		if(tmp<A||tmp>=B){
			result++;
		}
	}
	cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cout<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}


typedef long long int64;


int main() {
    int h,w,n;
    cin >> h >> w >> n;
    cout << (n+max(h,w)-1) / max(h,w) << endl;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

struct BigInt {
	vector<int>nums;
	BigInt(const int m, const int n):nums(18) {
		nums[0] = 1;
		for (int i = 0; i < n; ++i) {
			for (auto &num: nums) {
				num *= m;
			}
			for (int j = 0; j < 17; ++j) {
				nums[j + 1] += nums[j] / 10000;
				nums[j] %= 10000;
			}
		}
	}
	void output() {
		map<int, string>mp;
		mp[0] = "";
		mp[1] = "Man";
		mp[2] = "Oku";
		mp[3] = "Cho";
		mp[4] = "Kei";
		mp[5] = "Gai";
		mp[6] = "Jo";
		mp[7] = "Jou";
		mp[8] = "Ko";
		mp[9] = "Kan";
		mp[10] = "Sei";
		mp[11] = "Sai";
		mp[12] = "Gok";
		mp[13] = "Ggs";
		mp[14] = "Asg";
		mp[15] = "Nyt";
		mp[16] = "Fks";
		mp[17] = "Mts";
		for (int i = 17; i >= 0; --i) {
			if (nums[i]) {
				cout << nums[i];
				cout << mp[i];
			}
		}
		cout << endl;
	}
};

int main() {
	while (1) {

		int m, n; cin >> m >> n;
		if (!m&&!n)break;
		BigInt bi(m, n);
		bi.output();
	}
	return 0;
}

Measured memory_bytes: 3160
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define NO cout << "NO" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define Yes cout << "Yes" << endl;
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100000;
queue< int > q, sf;
vector< vector< int > > vr(maxn);
bool used[maxn];
int n;
int pre[maxn];

void road(int s = 0) {
  fill(used, used + n, false);
  used[0] = true;
  pre[0] = -1;
  q.push(s);
  bool key = false;
  //点を詰めて、そこからのばす
  while(!key) { //点n-1を含むまで続ける
    int v = q.front();
    q.pop();
    for(int i = 0; i < vr[v].size(); i++) {
      if(!used[vr[v][i]]) { //行先の頂点は未使用
        used[vr[v][i]] = true;
        q.push(vr[v][i]);       //点vからのびる点を詰める
        pre[vr[v][i]] = v;      //詰められた点は点vから伸びている
        if(vr[v][i] == n - 1) { //のびた点がn-1の時に終わり
          key = true;
          break;
        }
      }
    }
  }

  return;
}

int main() {
  cin >> n;

  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vr[a].push_back(b); //頂点aは頂点bへの道をもつ、その逆も
    vr[b].push_back(a);
  }

  //頂点0から頂点n-1への頂点の個数を数える(頂点0,n-1も含める)
  // 0からn-1への道順
  road();
  // 0からn-1にc個の点があるかを調べる
  int c = 0, s = n - 1;
  while(pre[s] != -1) {
    c++;
    s = pre[s];
  }
  c++;

  // Snukeは0からn-1のうち最後からc(下で更新)個の点を塗る

  if(c % 2 == 0) {
    c = c / 2;
  } else {
    c = (c - 1) / 2;
  }

  //後ろからc個をsfにつめる
  s = n - 1;
  int att;
  fill(used, used + n, false);
  for(int i = 0; i < c; i++) {
    sf.push(s);
    used[s] = true; // NOTE : ここでおらないと
    s = pre[s];
    if(i == c - 1) att = s;
  }
  //後ろから詰めた点から派生する点はSnukeが塗る 得点sp
  //点attはフェネックが塗るから含んではいけない
  used[att] = true;
  int sp = 0;
  while(sf.size()) {
    int v = sf.front();
    sf.pop();
    sp++; // NOTE : 同じ点がここで二回数えられるかもしれない
    for(int i = 0; i < vr[v].size(); i++) {
      if(!used[vr[v][i]]) {
        used[vr[v][i]] = true;
        sf.push(vr[v][i]);
      }
    }
  }

  if(sp < n - sp) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }

  return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;cin >> s;
  ll n = s.size(),i,b = 0,ans = 0;
  for(i=0;i<n;i++){
    if(s[i]=='B') b++;
    else ans += b;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  if(n<=999) pr("ABC");
  else pr("ABD");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<fstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include<sstream>
#include<ctime>
using namespace std;
string s; 
int main(){
	cin>>s;
	s.erase(s.size()-8,s.size()-1);
	cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    cout<<n/3<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;
const int mo = 1e9 + 7;

int n, m, h[maxn], f[maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> h[i];

    for (int i = 2; i <= n; ++i) {
        f[i] = INT_MAX;
        for (int j = 1; j <= m && j < i; ++j)
            f[i] = min(f[i], f[i-j] + abs(h[i] - h[i-j]));
    }

    cout << f[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    mylist = []
    for i in range(2):
        mylist.append(input())
    N, M = list(map(int, mylist[0].split()))
    votes = list(map(int, mylist[1].split()))

    v_sum = sum(votes)

    votes.sort(reverse=True)

    flag = True
    for i in range(M):
        if votes[i] < v_sum / (4 * M):
            flag = False

    if flag:
        print("Yes")
    else:
        print("No")    



if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants ---------- */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    int s[n];
    int l[n];
    int p[n];
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> l[i] >> p[i];
    }

    int N = 0;
    for (int i = 0; i < n; i++) {
        N += l[i] - s[i] + 1;
    }

    int weights[N];
    int values[N];
    int pnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = s[i]; j <= l[i]; j++) {
            values[pnt] = p[i];
            weights[pnt++] = j;
        }
    }

    int M;
    cin >> M;

    int W[M];
    for (int m = 0; m < M; m++) {
        cin >> W[m];
    }

    int dp[400];
    fill(dp, dp + 400, 0);
    for (int i = 0; i < N; i++) {
        for (int j = weights[i]; j < 400; j++) {
            dp[j] = max(dp[j], dp[j - weights[i]] + values[i]);
        }
    }

    int ret[M];
    fill(ret, ret + M, 0);

    for (int m = 0; m < M; m++) {
        if (dp[W[m]] == 0) {
            cout << -1 << endl;
            return 0;
        } else {
            ret[m] = dp[W[m]];
        }
    }

    for (int m = 0; m < M; m++) {
        cout << ret[m] << endl;
    }

    return 0;
}


Measured memory_bytes: 4240
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, H, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

l = []
heapify(l)
for _ in range(N):
     x, y = map(int, input().split())
     heappush(l, (-x, -1))
     heappush(l, (-y, 1))

c = 0
while H > 0:
     d, cc = heappop(l)
     d = d * -1
     if cc == 1:
          H -= d
          c += 1
     elif cc == -1:
          c += ceil(H / d)
          H = 0

print(c)

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    ll A, B, C; cin >> A >> B >> C;
    map<ll, bool> m;
    FOR(i, 1, 101) {
        ll x = A * i % B;
        if (x == C) {
            cout << "YES" << "\n";
            return 0;
        }
        if (m[x]) {
            cout << "NO" << "\n";
            return 0;
        }
        m[x] = true;
    }
}

Measured memory_bytes: 3644