akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

int main() {
  long long a,b;
  int k;
  cin >> a >> b >> k;

  int count=0;
  for(int j=a; j <= b; ++j){
    if(j >= a && j <= b){
      if(count < k || count > b-a-k) cout << j << endl;
      count++;
    }
  }
}



Measured memory_bytes: 3640
a,b,c,x,y = map(int,input().split())
if 2*c <= a+b:
    if x<=y:
        if 2*c <= b:
            print(2*c*y)
        else:
            print(2*c*x+b*(y-x))
    else:
        if 2*c <= a:
            print(2*c*x)
        else:
            print(2*c*y+a*(x-y))
else:
    print(a*x+b*y)

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

int main(){
	char str[15];
	scanf("%s",str);
	int l=strlen(str);
	for(int i=0;i<l;i++){
		if(i%2==0&&str[i]!='h'){
			printf("No");
			return 0;
		}else if(i%2==1&&str[i]!='i'){
			printf("No");
			return 0;
		}
	}
	if(l%2==1)printf("No");
	else printf("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;

pii input_time(){
    int a,b,c,d;
    scanf("%d:%d-%d:%d", &a, &b, &c, &d);
    return pii(a*100+b, c*100+d);
}

int main(){
    int t;
    cin >> t;
    vector<pii> a(t);
    for(int i=0; i<t; i++){
        a[i] = input_time();
    }
    int n[2];
    vector<vector<vector<pii>>> b(2);
    for(int d=0; d<2; d++){
        cin >> n[d];
        b[d].resize(n[d]);
        for(int i=0; i<n[d]; i++){
            int num;
            cin >> num;
            for(int j=0; j<num; j++){
                b[d][i].push_back(input_time());
            }         
        }
    }
    vector<vector<int>> count(t, vector<int>(2));
    for(int d=0; d<2; d++){
        for(int i=0; i<n[d]; i++){
            for(int j=0; j<t; j++){
                for(auto p: b[d][i]){
                    if(p.first <= a[j].first and a[j].second <= p.second){
                        count[j][d]++;
                        break;
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i=0; i<t; i++){
        ans += min(count[i][0], count[i][1]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3356
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, m = Is()
A = LI()
B = defaultdict(int)
tmp = 0
for a in A:
    tmp += a
    B[tmp % m] += 1

ans = B[0]
for b in B.values():
    if b >= 2:
        ans += b*(b-1)//2  # bC2

print(ans)

Measured memory_bytes: 87532
n = int(input())
l = list(input())
l += l[0]


check = [[1,1],[1,-1],[-1,1],[-1,-1]]
for j,k in check:
    
    ans=[j,k]
    
    for i in range(1,n+1):
        if ans[i] == 1:
            if l[i] == "o":
                ans.append(ans[i-1])
            else:
                ans.append(-ans[i-1])

        else:
            if l[i] == "o":
                ans.append(-ans[i-1])
            else:
                ans.append(ans[i-1])
    
    if ans[1] == ans[-1] and ans[0] == ans[-2]:
        for i in ans[:-2]:
            if i == 1:
                print("S",end="")
            else:
                print("W",end="")
        exit()  
            
print(-1)

Measured memory_bytes: 6928
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct unionfind {
    vector<int> data;
    unionfind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

struct edge {
    int u, v, cost;
};

int main(){
    int V, E;
    while (cin >> V >> E, V | E){
        vector<int> h(V);
        vector<edge> es(E);
        set<int> hs;
        hs.insert(0);
        rep(i, V){
            cin >> h[i];
            hs.insert(h[i]);
        }

        rep(i, E){
            int a, b, c; cin >> a >> b >> c;
            a--; b--;
            es[i] = { a, b, c };
        }
        sort(all(es), [](edge a, edge b){
            return a.cost < b.cost;
        });

        int ans = 0;
        unionfind uf(V);
        for (auto it = hs.rbegin(); it != hs.rend(); ++it){
            set<int> s;
            rep(i, V){
                if (*it <= h[i]){
                    s.insert(i);
                }
            }
            rep(j, E){
                const edge& e = es[j];
                if (!uf.same(e.u, e.v) && s.count(e.u) && s.count(e.v)){
                    uf.unite(e.u, e.v);
                    ans += e.cost;
                }
            }
            if (s.size() != uf.size(*s.begin())){
                ans = 0;
                uf = unionfind(V);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1468
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	vector<int> science(4);
	for (int i = 0; i < 4; ++i)
	{
		cin >> science[i];
	}
	vector<int> arts(2);
	for (int i = 0; i < 2; ++i)
	{
		cin >> arts[i];
	}
	sort(science.begin(), science.end());
	sort(arts.begin(), arts.end());
	int sum = 0;
	for (int i = 3; i >= 1; --i)
	{
		sum += science[i];
	}
	sum += arts[1];
	cout << sum << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1212
//
// Created by Ciafrino on 1/6/19.
//
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long lint;

vector<vector<int>> adj;
vector<int> dp;
vector<bool> mark;

int dfs(int u) {
    if (dp[u] != 0) return dp[u];
    dp[u] = 1;
    for (vector<int>::iterator it = adj[u].begin(); it < adj[u].end(); ++it) {
        if (dp[u] < dfs(*it) + 1)
            dp[u] = dp[*it] + 1;
    }
    return dp[u];
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    adj.resize(n);
    dp.assign(n, 0);
    mark.assign(n, false);
    for(int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        adj[x-1].emplace_back(y-1);
    }
    int longest_path = 0;
    for (int i = 0; i < n; ++i) {
        longest_path = max(longest_path, dfs(i));
    }
    cout << longest_path-1 << endl;

    return 0;
}

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

// fenwick tree
int f[N];
void init(){for(int i=0;i<=N;i++)f[i]=0;}

void add(int i, int x){for(;i<=N;i+=i&-i)f[i]+=x;}

int sum(int i)
{
    int ret=0;
    for(;i>0;i-=i&-i)ret+=f[i];
    return ret;
}

int rangesum(int l, int r){return sum(r)-sum(l-1);}
// fenwick tree

int c[N];
vector<int> ql[N],qid[N];

int ans[N];

int a[N];

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

    int n,q;
    cin>>n>>q;

    for(int i=0;i<n;i++)cin>>c[i];

    for(int i=0;i<q;i++)
    {
        int l,r;
        cin>>l>>r;

        ql[r].push_back(l);
        qid[r].push_back(i);
    }

    for(int i=1;i<=n;i++)
    {
        if(a[c[i-1]]>0)add(a[c[i-1]],-1);
        add(i,1);
        a[c[i-1]]=i;

        for(int j=0;j<ql[i].size();j++)
        {
            ans[qid[i][j]]=rangesum(ql[i][j],i);
        }
    }

    for(int i=0;i<q;i++)cout<<ans[i]<<"\n";

    return 0;
}



Measured memory_bytes: 53044
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection.Metadata.Ecma335;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 1000000007;
        public static void Main()
        {

            var args = Console.ReadLine().Split(' ').ToArray();
            var A = (decimal)long.Parse(args[0]);
            var B = (decimal)double.Parse(args[1]);

            Console.WriteLine((long)(A * B));

        }

    }

}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

template <class T, class Op>
class SegmentTree {
private:
    const Op op;
    const T ID;
    std::vector<T> vec;
    size_t sz;

public:
    explicit SegmentTree(size_t _n, Op _op, T _identity) noexcept
        : op(_op), ID(_identity) {
        sz = 1;
        while (sz < _n) sz <<= 1;
        vec.resize(sz * 2, ID);
    }
    explicit SegmentTree(const std::vector<T>& _vec, Op _op, T _identity) noexcept
        : op(_op), ID(_identity) {
        size_t n = _vec.size();
        sz = 1;
        while (sz < n) sz <<= 1;
        vec.resize(sz * 2, ID);
        set_array(_vec);
    }
    void set_value(size_t _idx, T _val) noexcept {
        vec[_idx + sz] = _val;
    }
    template <class RandomIt>
    void set_array(RandomIt _begin, RandomIt _end) noexcept {
        std::copy(_begin, _end, vec.begin() + sz);
    }
    void set_array(const std::vector<T>& _newvec) noexcept {
        set_array(_newvec.begin(), _newvec.end());
    }
    void build() noexcept {
        for (size_t i = sz - 1; i > 0; i--) {
            vec[i] = op(vec[i * 2], vec[i * 2 + 1]);
        }
    }
    void update(size_t _idx, T _val) noexcept {
        _idx += sz;
        vec[_idx] = _val;
        for (_idx >>= 1; _idx > 0; _idx >>= 1) {
            vec[_idx] = op(vec[_idx * 2], vec[_idx * 2 + 1]);
        }
    }
    // 区間[_i, _r)に対するクエリを実行する
    T query(size_t _l, size_t _r) const noexcept {
        T l_val = ID, r_val = ID;
        _l += sz, _r += sz - 1;
        for (; _l <= _r; _l >>= 1, _r >>= 1) {
            if (_l & 1) l_val = op(l_val, vec[_l++]);
            if (!(_r & 1)) r_val = op(r_val, vec[_r--]);
        }
        return op(l_val, r_val);
    }
    const T& operator[](size_t _idx) const noexcept {
        return vec[_idx + sz];
    }
};

using Bs = bitset<26>;

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

    int N;
    cin >> N;
    string S;
    cin >> S;
    auto op = [](Bs a, Bs b) {
        return a | b;
    };
    SegmentTree<Bs, decltype(op)> seg(N, op, Bs());
    for (int i = 0; i < N; i++) {
        seg.set_value(i, Bs().set(S[i] - 'a'));
    }
    seg.build();
    int Q;
    cin >> Q;
    while (Q--) {
        int query;
        cin >> query;
        if (query == 1) {
            int idx;
            char c;
            cin >> idx >> c;
            seg.update(idx - 1, Bs().set(c - 'a'));
        }
        else {
            int l, r;
            cin >> l >> r;
            --l, --r;
            cout << seg.query(l, r + 1).count() << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 9116
#include<stdio.h>
int main()
{
	int N,X,i,j,k,r;
	for(;scanf("%d%d",&N,&X),X+N;printf("%d\n",r))
	{
		for(i=1,r=0;i<=N;i++)
			for(j=i+1;j<=N;j++)
			{
				k=X-i-j;
				if(j<k&&k<=N)
					r++;
			}
	}
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  if(n<m)swap(n,m);
  for(int i=0;i<n;i++)cout<<m;
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
def solve(B,H,W):
    tate = [0 for _ in range(H)]
    yoko = [0 for _ in range(W)]

    for b in B:
        tate[b[0]-1] += 1
        yoko[b[1]-1] += 1

    tate_max_kouho,yoko_max_kouho = set(),set()
    tate_max,yoko_max = 0,0
    for i in range(H):
        if tate_max == tate[i]:
            tate_max_kouho.add(i)
        elif tate_max < tate[i]:
            tate_max = tate[i]
            tate_max_kouho.clear()
            tate_max_kouho.add(i)

    for j in range(W):
        if yoko_max == yoko[j]:
            yoko_max_kouho.add(j)
        elif yoko_max < yoko[j]:
            yoko_max = yoko[j]
            yoko_max_kouho.clear()
            yoko_max_kouho.add(j)

    C = set() #置かれている爆破物のうち爆破地点候補にはいっている爆破物
    for b in B:
        if (b[0]-1) in tate_max_kouho and (b[1]-1) in yoko_max_kouho:
            C.add(b)

    if len(tate_max_kouho) * len(yoko_max_kouho) > len(C):
        return tate_max + yoko_max
    else:
        return tate_max + yoko_max - 1

def main():
    H,W,M = map(int,input().split())
    B = set([tuple(map(int,input().split())) for _ in range(M)])

    print(solve(B,H,W))

if __name__ == "__main__":
    main()


Measured memory_bytes: 195644
w,h,n = map(int,input().split())

w0 = 0
h0 = 0

c = [list(map(int,input().split())) for _ in range(n)]

for i in c:
    if i[2] == 2:
        if i[0] < w:
            w = i[0]
    elif i[2] == 1:
        if i[0] > w0:
            w0 = i[0]
    elif i[2] == 4:
        if i[1] < h:
            h = i[1]
    elif i[2] == 3:
        if i[1] > h0:
            h0 = i[1]

w = w - w0 
if w < 0:
    w = 0
h = h - h0
if h < 0:
    h = 0
print(w*h)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef string::const_iterator State;

void assume(State &begin1, State &begin2, char expected, string &s) {
    // cerr << "assume: " << *begin1 << ", " << *begin2 << ", " << expected << ", " << s << endl;

    assert(*begin1 == expected && *begin2 == expected);
    s += *begin1;
    begin1++;   begin2++;
}

string number(State &begin1, State &begin2) {
    // cerr << "number: " << *begin1 << ", " << *begin2 << endl;

    int val1 = 0;
    while (isdigit(*begin1)) {
        val1 *= 10;
        val1 += *begin1 - '0';
        begin1++;
    }
    int val2 = 0;
    while (isdigit(*begin2)) {
        val2 *= 10;
        val2 += *begin2 - '0';
        begin2++;
    }
    return to_string(val1 + val2);
}

string node(State &begin1, State &begin2) {
    // cerr << "node: " << *begin1 << ", " << *begin2 << endl;

    if (*begin1 == ')') {
        int depth = 1;
        for(;;) {
            if (*begin2 == '(') {
                depth++;
            } else if (*begin2 == ')') {
                depth--;
            }
            if (depth == 0) {
                return "";
            }
            begin2++;
        }
    }
    if (*begin2 == ')') {
        int depth = 1;
        for(;;) {
            if (*begin1 == '(') {
                depth++;
            } else if (*begin1 == ')') {
                depth--;
            }
            if (depth == 0) {
                return "";
            }
            begin1++;
        }
    }

    string ret = "";

    assume(begin1, begin2, '(', ret);
    ret += node(begin1, begin2);
    assume(begin1, begin2, ')', ret);
    assume(begin1, begin2, '[', ret);
    ret += number(begin1, begin2);
    assume(begin1, begin2, ']', ret);
    assume(begin1, begin2, '(', ret);
    ret += node(begin1, begin2);
    assume(begin1, begin2, ')', ret);

    return ret;

}

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

    string s1, s2;
    cin >> s1 >> s2;
    State begin1 = s1.begin();
    State begin2 = s2.begin();
    cout << node(begin1, begin2) << endl;
    assert(begin1 == s1.end() && begin2 == s2.end());

}

Measured memory_bytes: 3292
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	int n;
	long mn = 10000000000000000;
	cin >> n;
	vector<long> cs(n);
	cin >> cs[0];
	for (int i = 1; i < n; ++i) {
		long x;
		cin >> x;
		cs[i] = cs[i - 1] + x;
	}
	for (int i = 0; i < n - 1; ++i) {
		mn = min(mn, abs(cs[i] - (cs[n - 1] - cs[i])));
	}
	cout << mn << endl;
}

Measured memory_bytes: 1792
#include<stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>

int main()
{   int a,b,x,y=0,i,n,m=0,p[11];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
        if(m<p[i]){
            m=p[i];
        }
        y+=p[i];
    }
    y-=m/2;
    printf("%d",y);
    

    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        int answer = int.MaxValue;
        for (int i = 0; i < s.Length - 2; i++)
        {
            string str = s.Substring(i, 3);
            int num = int.Parse(str);
            int diff = Math.Abs(num - 753);
            answer = Math.Min(answer, diff);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

string N;

int main() {
    cin >> N;
    int A = N[0] - '0';
    int B = N[1] - '0';
    int C = N[2] - '0';
    int D = N[3] - '0';

    bool f = false;
    char S[3];
    int num;
    for (int op1 = 0; op1 <= 1; op1++) {
        num = 0;
        if (op1) {
            S[0] = '+';
            num = A+B;
        }
        else {
            S[0] = '-';
            num = A-B;
        }

        int pre_num = num;

        for (int op2 = 0; op2 <= 1; op2++) {
            num = pre_num;
            if (op2) {
                S[1] = '+';
                num += C;
            }
            else {
                S[1] = '-';
                num -= C;
            }

            int pre_num2 = num;

            for (int op3 = 0; op3 <= 1; op3++) {
                num = pre_num2;
                if (op3) {
                    S[2] = '+';
                    num += D;
                }
                else {
                    S[2] = '-';
                    num -= D;
                }

                if (num == 7) {
                    f = true;
                    break;
                }
            }

            if (f) break;
        }

        if (f) break;
    }


    cout << A << S[0] << B << S[1] << C << S[2] << D << "=7" << endl;
    

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

a.append(0)

def all_path(a):
    res = 0
    now = 0
    for p in a:
        res += abs(now - p)
        now = p
    return res

def remove(a, i):
    if i == 0:
        prev = 0
    else:
        prev = a[i - 1]
    post = a[i + 1]
    now = a[i]
    orig = abs(now - prev) + abs(now - post)
    skip = abs(prev - post)
    return orig - skip

ap = all_path(a)

for i in range(n):
    print(ap - remove(a, i))



Measured memory_bytes: 14172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X,a=0,b=1;
  cin >> N >> X;
  vector<int> vec(N);
  for(int i=0;i<N;i++){   
  cin >> vec.at(i);
    a = a+vec.at(i);
  if(a<=X){
    b = b+1;
  }
    
  }
    cout << b << endl;
    
}

Measured memory_bytes: 256
using System;

namespace ABC101_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var sn = 0;
            foreach (var nn in n.ToCharArray())
            {
                sn += int.Parse(nn.ToString());
            }
            Console.WriteLine(int.Parse(n) % sn == 0 ? "Yes": "No");
        }
    }
}


Measured memory_bytes: 11092
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        // input
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();
        int Y = scanner.nextInt();
        scanner.nextLine();

        List<Integer> x = Arrays.asList(scanner.nextLine().split(" ")).stream()
                .map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> y = Arrays.asList(scanner.nextLine().split(" ")).stream()
                .map(Integer::parseInt).collect(Collectors.toList());

        // xの最大値
        int xMax = x.get(0);
        for (int xi : x) {
            xMax = Math.max(xMax, xi);
        }

        // yの最小値
        int yMin = y.get(0);
        for (int yi : y) {
            yMin = Math.min(yMin, yi);
        }

        // Zが存在するかどうか
        if ((xMax < yMin) && (X < yMin) && (xMax < Y)) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }

    }
}


Measured memory_bytes: 26964
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int griding[30][30];
int main() {
	int n, d;
	cin >> n >> d;
	REP(i, n) {
		REP(q, d) {
			cin >> griding[i][q];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int q = i + 1; q < n; ++q) {
			int bobo = 0;
			for (int j = 0; j < d; ++j) {
				bobo += (griding[i][j] - griding[q][j]) * (griding[i][j] - griding[q][j]);
			}
			int geko = sqrt(bobo);
			if (geko * geko == bobo)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <queue>
#include <cstring>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
ll graph[105][105];
int V,E;
const ll inf=1e11+5;


void floyd()
{
  for(int k=0;k<V;k++)
    {
      for(int i=0;i<V;i++)
	{
	  for(int j=0;j<V;j++)
	    {
	      if(graph[i][k]==inf || graph[k][j]==inf) continue;
	      graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
	    }
	}
    }
}
int main(int argc,char const* argv[])
{
  cin >> V >> E;
 fill(graph[0],graph[V],inf);
  for(int i=0;i<V;i++)
    {
      graph[i][i]=0;
    }
  for(int i=0;i<E;i++)
    {
      int s,t,cost;
      cin >> s >> t >> cost;
      graph[s][t]=cost;
    }
  floyd();
  for(int i=0;i<V;i++)
    {
      if(graph[i][i]<0)
	{
	  cout << "NEGATIVE CYCLE" << endl;
	  return 0;
	}
    }
  for(int i=0;i<V;i++)
    {
      for(int j=0;j<V;j++)
	{
	  if(graph[i][j]==inf)
	    {
	      cout << "INF";
	    }
	  else
	    {
	      cout << graph[i][j];
	    }
	  if(j!=V-1) cout << ' '; 
	}
      cout << endl;
    }
  return 0;
}



Measured memory_bytes: 3180
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N, M,XX,YY;
	cin >> N >> M >> XX >> YY;
	vector<int> X(N+1), Y(M+1);
	for(int i=0;i<N;++i){
		cin >> X[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> Y[i];
	}
	X[N] = XX;
	Y[M] = YY;
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	if (X[N]  < Y[0]) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int cnt = 0;
    int sum = accumulate(a.begin(), a.end(), 0);
    rep(i, n)
    {
        if (a[i] * 4 * m >= sum)
        {
            cnt++;
            if (cnt == m)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import sys
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
if k ==0:
  print(max(a))
  sys.exit()
def check(t):
  ans = 0
  if t==0:
    return False
  for aa in a:
    if aa > t:
      ans += aa//t
  return ans <= k
max = 10**9+1
min = 0
while max-min>1:
  mid = (max+min)//2
  if check(mid):
    max = mid
  else:
    min = mid
print(math.ceil(max))

Measured memory_bytes: 31088
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();

int32_t main(){
    FAST

    int a,b,v,w,t;cin>>a>>v>>b>>w>>t;
    
    int rel=v-w;
    int dist_travelled = rel*t;

    if(dist_travelled>=abs(a-b)) cout<<"YES\n";
    else cout<<"NO\n";

    return 0;
}

Measured memory_bytes: 3668
#87
#ALDS1_3_B
# キューは最初のやつから参照される

from queue import Queue
n,q=map(int,input().split())
que=Queue()

for i in range(n):
    name,time = input().split()
    que.put((name,int(time)))

total=0
while que.qsize()>0:
    name,time = que.get()
    total += min(q,time)
    if q < time:
        que.put((name,time-q))
    else:
        print(name,total)


Measured memory_bytes: 13632
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    vector<vector<int> > to(m+1);
    vector<int> in(m+1, 0);
    for(int i=0; i<n; ++i){
        int x, y;
        cin >> x >> y;
        to[x].push_back(y);
        ++ in[y];
    }

    queue<int> q;
    for(int i=1; i<=m; ++i){
        if(in[i] == 0)
            q.push(i);
    }

    while(!q.empty()){
        int x = q.front();
        q.pop();
        cout << x << endl;

        for(unsigned i=0; i<to[x].size(); ++i){
            int y = to[x][i];
            if(-- in[y] == 0)
                q.push(y);
        }
    }

    return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
using namespace std;
int main()
{
    int n,t,x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&t,&x,&y);
        if(x+y>t){
            printf("No\n");
            return 0;
        }
        if((x+y)%2==0&&t%2==1){
            printf("No\n");
            return 0;
        }
        if((x+y)%2==1&&t%2==0){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld n,i,j,p,k,m;cin>>n>>m;
    string s[n],st[n];
    rep(i,0,n)
     {
     	cin>>s[i];
     }
     rep(i,0,n)
     {
          rep(k,0,2)
          {
     	rep(j,0,m)
     	{
     		cout<<s[i][j];
     	}
     	cout<<endl;
     }
     }/*
     rep(i,0,2)
     {
     rep(i,0,n)
     {
     	rep(j,0,m)
     	cout<<st[i][j];
     	cout<<endl;
     }
        }*/

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        
        for(int i=1; i<=N; i++){
            if(i%2 == 1 && judge(i) == 8){
                ans++;
            }
        }
        
        System.out.println(ans);
    }
        
    public static int judge(int num){
        int count = 0;
        for(int i=1; i<=num; i++){
        if(num % i == 0){
        count++;
        }
        }
    
        return count;
    
    }
}


Measured memory_bytes: 35640
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int D;
  cin >> D;
  vi c(26);
  cin >> c;
  vector<vector<pair<int, int>>> s(D, vector<pair<int, int>>(26));
  rep(i, D) {
    rep(j, 26) {
      cin >> s[i][j].first;
      s[i][j].second = j;
    }
    sort(rall(s[i]));
  }

  rep(i, D) {
    out(s[i][0].second + 1);
  }
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");

//const ll N=1e5+5;
ll p=1e9+7;
//ll fac[N];

inline ll ceil(ll a,ll b)
{
  return (a+b-1)/b;
}

ll max(ll x,ll y,ll z)
{
  return max(x,max(y,z));
}


ll modpro(ll x,ll y,ll z=1)
{
  x%=p;
  y%=p;
  z%=p;
  ll res=(x*y)%p;
  res=(res*z)%p;
  return res;
}

ll modadd(ll x,ll y,ll z=0)
{
  ll res=(x+y)%p;
  res=(res+z)%p;
  return res;
}


ll pow_mod_p(ll a,ll b)
{
  a=a%p;
  ll res=1;
  while(b>0)
  {
    if(b&1) res=(res*a)%p;
    b=b>>1;
    a=(a*a)%p;
  }
  return res;
}

inline ll mod_inv(ll x)
{
  return pow_mod_p(x,p-2);
}
/*
ll nCr(ll x,ll y)
{
  if(x<y) return 0;
  ll res=fac[x];
  ll den=(fac[y]*fac[x-y])%p;
  ll deni=mod_inv(den);
  res=(res*deni)%p;
  return res;
}
*/

void func()
{
  ll n,m;
  cin>>n>>m;
  vll v(n);
  ll sm=0;
  f(i,0,n) 
  {
    cin>>v[i];
    sm+=v[i];
  }
  sort(ALL(v));
  reverse(ALL(v));
  ll x=ceil(sm,4*m);
  if(v[m-1]>=x)
  {
    cout<<"Yes\n";
  }
  else cout<<"No\n";
} 


int main() 
{
    fast
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/

    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
 
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 20
int n,K;
char str[1<<N|5];
int nxt[1<<N+1][2];
int f[N+1][1<<N+1];
int lg[1<<N+1];
int id(int s,int l){return (1<<n+1)-(1<<l+1)+s;}
pair<int,int> re(int id){
	int l=lg[id^(1<<n+1)-1];
	return {id+(1<<l+1)-(1<<n+1),l};
}
int ans;
void dfs(int w,int s,int cnt){
	if (cnt<K)
		return;
	if (w>re(ans).second)
		ans=id(s,w);
	cnt=0;
	for (int i=0;i<=n-w;++i)
		for (int j=0;j<1<<i;++j){
			int k=id(j,i);
			if (f[w][k]){
				if (nxt[k][0]!=-1){
					f[w+1][id(j&(1<<nxt[k][0])-1,nxt[k][0])]+=f[w][k],cnt+=f[w][k];
				}
			}
		}
	dfs(w+1,s<<1,cnt);
	cnt=0;
	for (int i=0;i<=n-w;++i)
		for (int j=0;j<1<<i;++j){
			int k=id(j,i);
			if (f[w][k]){
				if (nxt[k][0]!=-1)
					f[w+1][id(j&(1<<nxt[k][0])-1,nxt[k][0])]-=f[w][k];
				if (nxt[k][1]!=-1)
					f[w+1][id(j&(1<<nxt[k][1])-1,nxt[k][1])]+=f[w][k],cnt+=f[w][k];
			}
		}
	dfs(w+1,s<<1|1,cnt);
	for (int i=0;i<=n-w;++i)
		for (int j=0;j<1<<i;++j){
			int k=id(j,i);
			if (f[w][k]){
				if (nxt[k][1]!=-1)
					f[w+1][id(j&(1<<nxt[k][1])-1,nxt[k][1])]-=f[w][k];
			}
		}
}
int main(){
	scanf("%d%d",&n,&K);
	lg[0]=-1,lg[1]=0;
	for (int i=2;i<1<<n+1;++i)
		lg[i]=lg[i>>1]+1;
	int cnt=0;
	for (int i=0;i<=n;++i){
		scanf("%s",str);
		for (int j=0;j<1<<i;++j){
			int k=id(j,i);
			if (str[j]=='1')
				f[0][k]=1,++cnt;
			nxt[k][0]=lg[j^(1<<i)-1];
			nxt[k][1]=lg[j];
		}
	}
	ans=id(0,0);
	dfs(0,0,cnt);
	int s=re(ans).first,l=re(ans).second;
	for (int i=l-1;i>=0;--i)
		putchar('0'+(s>>i&1));
	return 0;
}













Measured memory_bytes: 43732
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int b = 0;
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a + SIZE_OF_ARRAY(a));
    for (int i=0; i<n; i++){
        if (a[i]==a[i+1]){
            cout << "NO" << endl;
            b += 1;
            break;
        }
    }
    if (b == 0){
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i >= K) {
      ans += 1.0 / N;
      continue;
    }
    int cnt = 0;
    int t = i;
    while (t < K) t *= 2, cnt++;
    ans += 1.0 / N * pow(0.5, cnt);
  }
  printf("%.15f\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=9223372036854775807ll;
int cl[100005],lst[100005];
vector<int> eds[100005];
int n,m,q;
void dfs(int v,int d,int c)
{
	if(!cl[v])
		cl[v]=c;
	if(lst[v]>=d)
		return ;
	lst[v]=d;
	if(d==0)
		return ;
	for(int u=0;u<eds[v].size();u++)
		dfs(eds[v][u],d-1,c);
}
vector<pair<pair<int,int>,int> > vv;
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		eds[a].push_back(b);
		eds[b].push_back(a);  
	}
	cin>>q;
	for(int i=0;i<q;i++)
	{
		int v,d,c;
		cin>>v>>d>>c;
		v--;
		vv.push_back(make_pair(make_pair(v,d),c)); 
	}
	reverse(vv.begin(),vv.end());
	for(int i=0;i<q;i++)
	{
		int v,d,c;
		v=vv[i].first.first;
		d=vv[i].first.second;
		c=vv[i].second;
		dfs(v,d,c);
	}
	for(int i=0;i<n;i++)
		cout<<cl[i]<<'\n';
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int N; ll M;
	cin>>N>>M;
	vector<int> A(N);
	vector<ll> P(N+1);
	rep(i, 0, N) cin>>A[i];
	sort(begin(A), end(A));
	rep(i, 0, N) P[N-i-1]=P[N-i]+A[N-i-1];
	int l=0, r=A.back()*2;
	auto f=[&](int m) {
		ll n=0, s=0;
		rep(i, 0, N) {
			int k=lower_bound(begin(A), end(A), m-A[i])-begin(A);
			n+=N-k, s+=P[k];
		}
		return make_pair(n, s*2);
	};
	ll n, s;
	while(l<r) {
		int m=l+r+1>>1;
		tie(n,s)=f(m);
		if(n<=M) r=m-1;
		else l=m;
	}
	tie(n,s)=f(r);
	cout<<s-r*(n-M);
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

vector<int> graph[100005];
vector<bool> used(100005);
vector<int> ans;
bool finished = false;

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

  int n, h, w; cin >> n >> h >> w;
  auto ans = 0;
  rep(i, n) {
    int a, b; cin >> a >> b;
    if (a >= h && b >= w) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
c = [None]*n
for i in range(n):
    c[i] = int(input())
    
dp = [0]*(n+1)
dp[0] = 1
M = 10**9+7
# from collections import defaultdict
d = {}
for i,cc in enumerate(c):
    if cc not in d or d[cc]==i-1:
        dp[i+1] = dp[i]
    else:
        dp[i+1] = dp[i] + dp[d[cc]+1]
    d[cc] = i
    dp[i+1] %= M
print(dp[n])

Measured memory_bytes: 111400
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    set<char> st;
    rep(i, N) {
        char s; cin >> s;
        st.insert(s);
    }
    if(st.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    string s;
    cin >> s;
    sort(ALL(s));
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

typedef long long ll;
typedef std::pair<ll, ll> l_l;
typedef std::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;
}

using namespace std;

vector<int> edges[200000];
int64_t num[200000];

void dfs(int i, int p) {
    for (int j : edges[i]) {
        // j(iの葉)がpでないとき
        if (j != p) {
            num[j] += num[i];
            dfs(j, i);
        }
    }
}

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

    // 辺情報入力
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    for (int i = 0; i < Q; ++i) {
        int p, x;
        cin >> p >> x;
        num[p-1] += x;
    }
    dfs(0, -1);
    for (int i = 0; i < N; ++i) {
        cout << num[i] << " ";

    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
string str;
int main()
{
    cin>>str;
    int cnt=1;
    bool two=false;
    for(int i=1 ; i<str.size() ; i++){
        if(two){
            two=false;
            cnt++;
            continue;
        }
        if(str[i]==str[i-1] && i+1<str.size()){
            two=true;
            i++;
        }else if(str[i]==str[i-1]){
            break;
        }
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 640
n=gets.to_i
hate=/AGC|A.GC|AG.C|GAC|ACG/
cu={""=>1}
n.times{
	ne={}
	cu.map{|k,v|
		"ACGT".chars{|a|
			s=(k+a)[/.{,4}$/]
			ne[s]||=0
			ne[s]+=(s=~hate)?0:v
		}
	}
	cu=ne
}
p cu.values.reduce(:+)%(10**9+7)

Measured memory_bytes: 2556