akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    cout << (n+1) / 2 << endl;
}

Measured memory_bytes: 3632
N = int(input())
a = [0, -1] 
for i in range(N):
        tmp = N - i 
        cnt = 0 
        while tmp > 1:
                if tmp % 2 != 0:
                        break
                else:
                        cnt += 1
                        tmp /= 2
        if a[1] < cnt:
                a = [N - i, cnt] 
print(a[0])

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> B(N+1);
    rep(i,N) B[i+1] = A[i] + B[i];
    vector<ll> C;
    rep(i,N) {
        for (int j = i+1; j <= N; j++) C.emplace_back(B[j]-B[i]);
    }

    int M = C.size();
    vector<bool> P(M,true);
    ll ans = 0;
    for (ll i = 50LL; i >= 0LL; i--) {
        int cnt = 0;
        rep(j,M) {
            if (!P[j]) continue;
            if ((C[j] >> i) & 1LL) cnt++;
        }
        if (cnt >= K) {
            ans += (1LL << i);
            rep(j,M) {
                if (!P[j]) continue;
                if (!((C[j] >> i) & 1LL)) P[j] = false;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, x: "List[int]", y: "List[int]"):
    from math import sqrt
    def distance(x1: float, y1: float, x2: float, y2: float):
        return sqrt((x2-x1)**2 + (y2-y1)**2)

    ans = []
    import itertools
    for i in itertools.permutations(list(range(N)), N):
        t = 0
        for j in range(1,N):
            t += distance(x[i[j-1]], y[i[j-1]], x[i[j]], y[i[j]])
        ans.append(t)

    print(sum(ans)/len(ans))
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b > c+d) cout << "Left" << endl;
  if(a+b == c+d) cout << "Balanced" << endl;
  if(a+b < c+d) cout << "Right" << endl;
  
}

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

int main(){
	int odd = 0;
	int cou4 = 0;
	bool ex2 = false;
	int N;
	cin >> N;
	long long int a;
	
	for(int i = 0;i < N;i ++){
		cin >> a;
		if(a % 2 == 1) odd++;
		if(a % 4 == 0) cou4++;
		if(a % 2 == 0 && a % 4 != 0) ex2 = true;
	}
	if((cou4 >= odd && ex2 )|| (cou4 >= odd - 1 && !ex2)){
		cout << "Yes" << endl;
	}
	else {cout << "No" << endl;}
	
	return 0;
}

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

#define ll long long

using namespace std;

int main(){
	string s,p;
	
	cin>>s>>p;
	s=s+s;
	if(s.find(p)!=-1) cout << "Yes" << endl;
	  else cout << "No" << endl;
	
	return 0;
}


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

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, x;
    cin >> n >> m >> x;
    int r = 0;
    int l = 0;
    for (int i = 0; i < m; ++i)
    {
        int a;
        cin >> a;
        if (a < x) ++r;
        else ++l;
    }
    cout << min(r, l) << endl;

    return 0;
}


Measured memory_bytes: 256
n, k = gets.chomp.split(' ').map{|i| i.to_i }
h = gets.chomp.split(' ').map{|i| i.to_i }.sort

amari = h.length - k

if amari <= 0
  puts 0
else
  h2 = h[0 .. amari - 1]
  sum = 0
  h2.each{|i| sum += i }

  puts sum
end


Measured memory_bytes: 21360
h, w = map(int, input().split())
s = []
t = []
for i in range(h):
  s.append(list(input()))

count = 0
for i in s:
  count += i.count('#')

c = 1
queue = []
s[0][0] = c
queue.append((0,0))
while len(queue) != 0:
  v = queue.pop(0)
  c = s[v[0]][v[1]]+1
  if 0 <= v[0]-1:
    if s[v[0]-1][v[1]] == '.':
      s[v[0]-1][v[1]] = c
      queue.append((v[0]-1, v[1]))
  if 0 <= v[1]-1:
    if s[v[0]][v[1]-1] == '.':
      s[v[0]][v[1]-1] = c
      queue.append((v[0], v[1]-1))

  if v[0]+1 < h:
    if s[v[0]+1][v[1]] == '.':
      s[v[0]+1][v[1]] = c
      queue.append((v[0]+1, v[1]))

  if v[1]+1 < w:
    if s[v[0]][v[1]+1] == '.':
      s[v[0]][v[1]+1] = c
      queue.append((v[0], v[1]+1))
if s[h-1][w-1] == '.':
  print(-1)
else:
  print(h*w-count-s[h-1][w-1])


Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
if H == 1 or W == 1:
    print(1)
else:
    print((H // 2 + H % 2) * (W // 2 + W % 2) + (H // 2) * (W // 2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    vector<int> check(n);
    int cnt = 0;
    int num = 1;
    rep(i, n) {
        if (cnt > 0) {
            cnt--;
        } else {
            if (s[i] == 'o') {
                check[i] = num++;
                cnt = c;
            }
        }
        if (num == k+1) break;
    }
    cnt = 0;
    num = k;
    vector<int> ans;
    rrep(i, n) {
        if (cnt > 0) {
            cnt--;
        } else {
            if (s[i] == 'o') {
                if (check[i] == num) ans.push_back(i+1);
                num--;
                cnt = c;
            }
        }
        if (num == 0) break;
    }
    reverse(ans.begin(), ans.end());
    rep(i, ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll A,B;
  cin >> A >> B;

  ll x=(A/4+1)*4;
  ll y = B/4*4-1;
  if(x>y){
    ll ans=A;
    FOR(i,A+1,B+1){
      ans^=i;
    }
    cout << ans << endl;
  }else{
    ll ans = A;
    FOR(i,A+1,x){
      ans^=i;
    }
    FOR(i,y+1,B+1){
      ans^=i;
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 3600
N = int(input())
B = list(map(int, input().split()))
A = [0] * N
for i in range(N):
    first = B[i] if 0 <= i < len(B) else float('inf')
    second = B[i-1] if 0 <= i-1 < len(B) else float('inf')
    A[i] = min(first, second)
print(sum(A))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  vector<string> A,B;
  for(int i=0;i<N;i++){
    string temp;
    cin>>temp;
    A.push_back(temp);
  }
  for(int i=0;i<M;i++){
    string temp;
    cin>>temp;
    B.push_back(temp);
  }
  bool check=false;
  for(int i=0;i<(N-M+1);i++){
    for(int j=0;j<(A[0].size()-B.size()+1);j++){
      bool icheck=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<B[0].size();l++){
          if(A[i+k][j+l]!=B[k][l]){icheck=false; break;}
        }
      }
      if(icheck) check=true;
    }
  }
  if(check) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 384
x = gets.to_i
l = 0
d = [][2]
while x != 0
  d = [l+1,x]
  puts "Case" + " " + d[0].to_s + ":" + " " + d[1].to_s

  unless (d.count <= 10000) || (1 <= x || x <= 10000  )
    return
  end

  l += 1
  x = gets.to_i
end


Measured memory_bytes: 6844
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
	int i, len, count = 0;
	char c[201], p[101], ccc[101];
	scanf("%s", c);
	strcpy(ccc,c);
	scanf("%s", p);
	strcat(c, ccc);
	if(strstr(c, p) == NULL) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 540
from itertools import accumulate
N, W = map(int, input().split())
xs = [[0] for _ in range(4)]
for i in range(1, N+1):
    w, v = map(int, input().split())
    if i == 1:
        cc = w
    xs[w-cc].append(v)
A, B, C, D = map(len, xs)
As, Bs, Cs, Ds = map(lambda x: list(accumulate([0]+sorted(x)[::-1])), xs)

def f(a, b, c, d):
    return As[a] + Bs[b] + Cs[c] + Ds[d]

def main():
    r = 0
    for a in range(A):
        for b in range(B):
            for c in range(C):
                for d in range(D):
                    w = cc*(a+b+c+d)+b+c*2+d*3
                    if w > W:
                        break
                    r = max(f(a,b,c,d), r)
    print(r)

main()



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

vector<vector<int>> G;

void create_two_uni(int l, int r){
  // cout << l << " " << r << endl;
  if(r - l <= 1) return;
  int med = (l+r)/2;
  for(int i = l+1; i < med; i++){
    G.at(l).at(i) = true;
    G.at(i).at(l) = true;
  }
  for(int i = med+1; i < r; i++){
    G.at(med).at(i) = true;
    G.at(i).at(med) = true;
  }

  create_two_uni(l+1, med);
  create_two_uni(med + 1, r);
}

int num_of_edge(){
  int res = 0;
  for(int i = 0; i < (int)G.size(); i++){
    for(int j = 0; j < i; j++){
      if(G.at(i).at(j) == true) res++;
    }
  }
  return res;
}

int main(void){
  int N, K; cin >> N >> K;

  G = vector<vector<int>>(N, vector<int>(N, false));

  create_two_uni(0, N);

  // for(const auto& gg: G){
  //   for(const auto& g: gg){
  //     cout  << g << ' ';
  //   }
  //   cout << '\n';
  // }

  int E = num_of_edge();
  cout << E << '\n';
  for(int i = 0; i < N; i++){
    for(int j = 0; j < i; j++){
      if(G.at(i).at(j) == true) cout << i+1 << " " << j+1 << '\n';
    }
  }
  fflush(stdout);

  for(int loop = 0; loop < K; loop++){
    int cnt = 0;
    int l = 0, r = N;
    bool YES = false;
    vector<int> history;
    while(1){
      // cout << l << " " << r << endl;
      // if(cnt >=  10) while(1);
      if(r - l <= 0) break;
      cout << l+1 << endl;
      cnt++;
      string res; cin >> res;
      if(res == "Yes"){
        YES = true;
        break;
      }
      if(r - l <= 1) break;
      if(res == "Near"){
        r = (l + r) / 2;
        l = l + 1;
      }else if(res == "No"){
        if(r - l == 2){
          l = (l + r) / 2;
        }else{
        l = (l + r) / 2 + 1;
        }
        history.push_back(l);
      }else{
        // assert(false);
      }
    }
    if(YES == false){
      int p = history.back();
      // if(cnt >= 9) while(1);
      cout << p << endl;
      string str; cin >> str;
      // assert(str == "Yes");
    }
  }
}



Measured memory_bytes: 3320
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
res = 0
for a in A:
    x -= a
    res += 1
    if x < 0:
        x = abs(x)
        break
    elif x == 0:
        break

print(max(res-1, 0) if x>0 else res)


Measured memory_bytes: 8800
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <functional>
#include <chrono>
#include <time.h>
using namespace std;

int main()
{
	int n, k; cin >> n >> k;
	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long ans = 0;

	vector<int>see(n);
	int minH = a[0];
	int cnt = 1;
	for (int i = 0; i < n; i++){
		if (minH < a[i]) {
			minH = a[i];
			cnt++;
		}
		see[i] = minH;
	}

	while (cnt > k) {
		int index = 0;
		vector<pair<int, int>>b;
		for (int i = 0; i < n- 1; i++) {
			if (see[i] < see[i + 1]) {
				b.push_back(make_pair(see[i + 1] - see[i], index));
				index = i + 1;
			}
		}
		sort(b.begin(), b.end());
		a[b[0].second] += b[0].first;
		ans += b[0].first;

		int minH = a[0];
		cnt = 1;
		for (int i = 0; i < n; i++) {
			if (minH < a[i]) {
				minH = a[i];
				cnt++;
			}
			see[i] = minH;
		}
		cerr << cnt << endl;
	}

	while (cnt < k) {
		vector<pair<int, int>>b;
		vector<int>bias(n);
		for (int i = n - 1; i > 0; i--) {
			if (i < n - 1)bias[i] = bias[i + 1];
			if (see[i] == see[i - 1]) {
				b.push_back(make_pair(see[i] + 1 + bias[i] + - a[i], n - i));
			}
			else if(see[i]-see[i-1]==1){
				bias[i]++;
			}
			else bias[i] = 0;
		}
		sort(b.begin(), b.end());
		a[n-b[0].second] += b[0].first - bias[n - b[0].second];
		ans += b[0].first - bias[n - b[0].second];

		int minH = a[0];
		cnt = 1;
		for (int i = 0; i < n; i++) {
			if (minH < a[i]) {
				minH = a[i];
				cnt++;
			}
			see[i] = minH;
		}
	}

	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const [n, k] = inputs[0].split(' ').map(Number);
const wi = inputs.slice(1).map(Number);

const isAllocatable = (list, maxWeight, units) => {
  let weight = 0;
  for (let i = 0; i < list.length; i++) {
    if (list[i] > maxWeight) {
      return false;
    }
    if (weight + list[i] > maxWeight) {
      if (--units <= 0) {
        return false;
      }
      weight = list[i];
    } else {
      weight += list[i];
    }
  }
  return true;
}

let l = 0;
let r = wi.reduce((a, b) => a + b) + 1;
while (l + 1 < r) {
  const index = Math.floor((l + r) / 2);
  if (!isAllocatable(wi, index, k)) {
    l = index;
  } else {
    r = index;
  }
}
const p = r;
console.log(p);



Measured memory_bytes: 33144
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	if a < b {
		fmt.Printf("%s\n", strings.Repeat(strconv.Itoa(a), b))
	} else {
		fmt.Printf("%s\n", strings.Repeat(strconv.Itoa(b), a))
	}
}


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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rrep(i,n) for(ll i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(ll i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  vector<ll> a(n);
  rep(i, n)cin>>a[i];

  // n==k
  if(n==k){
    ll result=1;
    for(auto c:a){
      result*=(c+MOD);
      result %= MOD;
    }
    cout<<result<<endl;

    return 0;
  }

  vector<ll> ma, pa, za;
  for(auto c:a){
    if(c<0)ma.push_back(c);
    else if(c>0)pa.push_back(c);
    else if(c==0)za.push_back(0);
  }

  // 0
  if(za.size()>n-k){cout<<0<<endl; return 0; }

  sort(ma.begin(), ma.end());
  sort(pa.begin(), pa.end());

  // -
  if(k%2==1 && pa.size()==0){
    if(za.size()>0){cout<<0<<endl; return 0; }

    ll result = 1;
    rep(i, k){
      ll idx = ma.size()-1-i;
      result *= (ma[idx]+MOD);
      result%=MOD;
    }
    cout<<result<<endl;

    return 0;
  }
  
  // +
  if(ma.size()==0){
    rep(i, za.size())pa.push_back(0);
    sort(pa.begin(), pa.end());

    ll result=1;
    rep(i, k){
      result *= pa.back(); pa.pop_back();
      result %= MOD;
    }
    cout<<result<<endl;

    return 0;
  }


  vector<ll> results;
  rep(i, ma.size())ma[i]=-ma[i];
  sort(ma.begin(), ma.end());

  //for(auto c:ma)cout<<c<<' ';cout<<endl;for(auto c:pa)cout<<c<<' ';cout<<endl;

  while(results.size()<k){
    ll pamax = -1;
    if(pa.size()) pamax = pa[pa.size()-1] * pa[pa.size()-2];
    ll mamax = -1;
    if(ma.size()>=2)mamax = ma[ma.size()-1] * ma[ma.size()-2];

    // maの最大2つの乗算の方がpaの最大2つの乗算よりもデカイ、かつ結果格納先の余裕が2個以上あるなら、負の配列から2つ取り出して格納する、2個以上無いと入らないので。
    if(mamax > pamax && k-results.size()>=2){
      results.push_back(ma.back());
      ma.pop_back();
      results.push_back(ma.back());
      ma.pop_back();
    }else{
      results.push_back(pa.back());
      pa.pop_back();
    }
  }

//  for(auto c: results)cout<<c<<' ';cout<<endl;

  ll result=1;
  for(auto c: results){
    result *= c;
    result %= MOD;
  }
  cout<<result<<endl;

  return 0;
}


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

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int k;
	cin>>k;
	int ans=0;
	for(int a=1;a<=k;++a){
		for(int b=1;b<=k;++b){
			for(int c=1;c<=k;++c){
				ans+=gcd(a,gcd(b,c));
			}
		}
	}
	cout<<ans<<"\n"s;
}

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

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

  vector<long long> a(N);
  for(auto& x: a){
    cin >> x;
  }

  long long ans = 0;
  while(true){
    bool ok = true;
    for(int i = 0; i < N; i++){
      if(a[i] >= N){
        ok = false;
        long long cnt = a[i] / N;
        for(int j = 0; j < N; j++){
          if(j != i){
            a[j] += cnt;
          }
        }
        a[i] -= N * cnt;
        ans += cnt;
      }
    }
    if(ok){
      break;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

int n, k;
int ans, now;
bool v, v2;
int a[200005];
set<int> se;

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    ans = n - k + 1;
    for(int i = 0; i < k - 1; i++) if(a[i] < a[i + 1]) now++;
    for(int i = k - 1; i <= n - 1; i++)
    {
        if(now == k - 1 && !v) ans--, v2 = true, v = true;
        else if(now == k - 1) v = true;
        else v = false;
        if(a[i] < a[i + 1]) now++;
        if(a[i - k + 1] < a[i - k + 2]) now--;
    }
    if(v2) ans++;
    for(int i = 0; i < k; i++) se.insert(a[i]);
    for(int i = k; i < n; i++)
    {
        se.insert(a[i]);
        if(*se.begin() == a[i - k] && *se.rbegin() == a[i]) ans--;
        se.erase(a[i - k]);
    }
    printf("%d", ans);
    return 0;
}


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

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

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	vector<int> list;
	int n = read<int>();
	rep(i,n){
		list.push_back(read<int>()*60+read<int>());
	}
	int m = read<int>();
	rep(i,m){
		list.push_back(read<int>()*60+read<int>());
	
	}
	int prev = -1;
	sort(list.begin(), list.end());
	for(vector<int>::iterator it=list.begin(); it!=list.end(); it++){
		int a = *it;
		if(a!=prev){
		if(prev!=-1) 
			cout << " ";
			int h = a/60, m=a%60;
			cout << h << ":";
			if(m<10) cout << "0" << m;
			else     cout <<        m;
		}
		prev=a;
	}
	
	cout << endl;
}

Measured memory_bytes: 1220
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double xa, ya, ra, xb, yb, rb, distance, x, y;
	int i = 0, j = 0;

	cin >> i;
	while ( j < i )
	{
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		x = xa - xb;
		y = ya - yb;
		distance = sqrt( x*x + y*y );

		if ( ra >= rb )
		{ // circle a bigger than circle b
			if ( distance > ra + rb )
			{ // circle b in circle a 
				cout << 0 << endl;
			}
			else if ( distance <= ra + rb && distance >= ra - rb )
			{
				cout << 1 << endl;
			}
			else if ( distance < ra - rb )
			{
				cout << 2 << endl;
			}
		}

		if ( rb > ra )
		{ // circle b bigger than circle a
			if ( distance > rb + ra )
			{ // circle a in circle b
				cout << 0 << endl;
			}
			else if ( distance <= ra + rb && distance >= rb - ra )
			{
				cout << 1 << endl;
			}
			else if ( distance < rb - ra )
			{
				cout << -2 << endl;
			}
		}

		j = j + 1;
	}

	return 0;
}

Measured memory_bytes: 3220
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    irep(i, v) { cout << i->first << " " << i->second << '\n'; }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}


int main() {
    
    ll ans=1;
    int n;
    cin>>n;
    if(n==1){
        fin(0);
        return 0;
    }
    ans=mod_pow(10,n);
    ans%=MOD;
    ans-=mod_pow(9,n);
    ans+=MOD;
    ans%=MOD;
    ans-=mod_pow(9,n);
    ans+=MOD;
    ans%=MOD;
    ans+=mod_pow(8,n);
    ans%=MOD;
    fin(ans);
}



Measured memory_bytes: 3620
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] b = new int[]{5,4,3,2,1,0,1,2,3,4,5,6,7,8,9};
		int n = sc.nextInt();
		int x, y;
		int z = 0;
		boolean flag = false;
		
		for(int i=0;i<n;i++){
			x = sc.nextInt();
			y = sc.nextInt();
			flag = false;
			z = 0;
			ArrayDeque<Integer> listA = new ArrayDeque<Integer>();
			ArrayDeque<Integer> listB = new ArrayDeque<Integer>();
			for(int j=0;;j++){
				if(flag==true && b[j]==y){
					listA.add(b[j]);
					break;
				}
				if(flag==false && b[j]==x){
					flag = true;
					z = j;
				}
				if(flag==true) listA.add(b[j]);
				if(j==14) j = -1;
			}

			if(x>0 && x<6){
				flag = false;
				for(int j=0;;j++){
					if(flag==true && b[j]==y){
						listB.add(b[j]);
						break;
					}
					if(flag==false && j!=z && b[j]==x) flag = true;
					if(flag==true) listB.add(b[j]);
					if(j==14) j = -1;
				}
			}
			
			if(listB.size()==0 || listB.size()>listA.size()){
				while(listA.size()>1){
					System.out.print(listA.pop() + " ");
				}
				System.out.println(listA.pop());
			}else{
				while(listB.size()>1){
					System.out.print(listB.pop() + " ");
				}
				System.out.println(listB.pop());
			}
		}
	}	
}

Measured memory_bytes: 15348
#include "bits/stdc++.h"
using namespace std;

string l("qwertasdfgzxcvb");

int main() {
	while (1) {
		string st; cin >> st;
		if (st == "#") {
			break;
		}
		else {
			bool a = true;
			int ans = 0;
			for (int i = 0; i < st.size(); ++i) {
				if ((l.find(st[i]) != string::npos) != a&&i != 0) {
					ans++;
				}
				if (l.find(st[i])!=string::npos) {
					a = true;
				}
				else {
					a = false;
				}
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
# coding:utf-8

import itertools

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def dijkstra(graph, start):
    MAX_SIZE = len(graph)
    visited = [False for _ in range(MAX_SIZE)]
    cost = [INF for _ in range(MAX_SIZE)]
    prev = [None for _ in range(MAX_SIZE)]

    cost[start] = 0
    prev[start] = start
    path = [start + 1]
    while True:
        min_cost = INF
        next = -1
        visited[start] = True
        # 頂点の選択
        for i in range(MAX_SIZE):
            if visited[i]: continue  # 探索済みの頂点は飛ばす
            if graph[start][i]:  # 頂点startと接続されているか判定
                dist = cost[start] + graph[start][i]
                if dist < cost[i]:
                    cost[i] = dist
                    prev[i] = start

            if cost[i] < min_cost:
                min_cost = cost[i]
                next = i

        start = next
        path.append(next + 1)
        if next == -1: break

    # print(cost)
    # print(path)
    return cost


def main():
    N, M, R = inpl()
    r = inpl()

    G = [[None for _ in range(N)] for _ in range(N)]
    for i in range(M):
        a, b, c = inpl()
        G[a - 1][b - 1] = c
        G[b - 1][a - 1] = c

    min_cost = {}
    for s in r:
        min_cost[str(s)] = dijkstra(G, s - 1)

    ans = INF
    for root in itertools.permutations(r, R):
        dist = 0
        for i in range(R - 1):
            s = str(root[i])
            dist += min_cost[s][root[i + 1] - 1]
        ans = min(ans, dist)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <map>
#define DEBUG
#undef DEBUG
using namespace std;
typedef long long ll;

ll N;
ll midn;
ll a[100005];

ll func(ll x){
    ll b[100005]; //x以下なら1、そうでなければ0という数列の累積和
    ll BIT[(1<<18)+1]; //累積和のBinary Index Tree
    for(ll i=0;i<=(1<<18);i++){
        BIT[i]=0;
    }
    b[0]=1e5+1;
    for(int i=1;i<=N;i++){
        b[i]=b[i-1];
        if(a[i-1]<=x){b[i]++;}
        else{b[i]--;}
    }
#ifdef DEBUG
#endif
    
    //
    ll ans=0;
    int j = b[0];
    while(j<=(1<<18)){
        BIT[j]++;
        j=j+((-j)&j);
    }
    for(int i=1;i<=N;i++){
        int j = b[i]-1;
        while(j>0){
            ans += BIT[j];
            j=j-((-j)&j);
        }
        j = b[i];
        while(j<=(1<<18)){
            BIT[j]++;
            j=j+((-j)&j);
        }
    }
    return ans;
}

int main(){
    cin>>N;
    midn = N*(N+1)/4+1;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    ll left=0,right=1e9,mid;
    while(right-left>1){
        mid=(left+right)/2;
#ifdef DEBUG
        cout<<mid<<endl;
#endif
        if(func(mid)<midn){
            left=mid;
        }else{
            right=mid;
        }
    }
    cout<<right<<endl;
    return 0;
}


Measured memory_bytes: 3840
from heapq import heapify, heappush, heappop
N = int(input())
heap = []
heapify(heap)
for i in range(1, int(N**(0.5)) + 1):
    if N % i == 0:
        heappush(heap, i - 1 + N // i - 1)
print(heappop(heap))

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

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

int gcd_tri(int a, int b, int c) {
  return gcd(gcd(a, b), c);
}

int main() {
  int k;
  cin >> k;
  ll sum = 0;
  for(int i=1; i<=k; i++) for(int j=i; j<=k; j++) for(int l=j; l<=k; l++) {
    int g = gcd_tri(i, j, l);
    if ((i == j) && (j == l)) {
      sum += g;
    } else if ((i == j) && (j != l)) {
      sum += 3 * g;
    } else if ((i != j) && (j == l)) {
      sum += 3 * g;
    } else if ((i != j) && (j != l)) {
      sum += 6 * g;
    }
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

int f(int x) {
    if (x % 2 == 0) {
        return x / 2;
    } else {
        return 3 * x + 1;
    }
}

int main() {
    unsigned int s;
    cin >> s;

    set<int> st;
    int x = s;
    while (st.count(x) == 0) {
        st.insert(x);
        x = f(x);
    }

    cout << st.size() + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100

int main(){
    int n, a[MAX];
    cin >> n;
    int p1=0, p2;
    int sum1=0, sum2=0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        p1 += a[i];
    }
    p1 /= n;
    p2 = p1+1;
    for(int i=0; i<n; i++){
        sum1 += (a[i] - p1) * (a[i] - p1);
        sum2 += (a[i] - p2) * (a[i] - p2);
    }
    int ans = min(sum1, sum2);
    cout << ans << endl;
}

Measured memory_bytes: 384
a = int(input())
b = [input() for i in range(a)]
c = int(input())
d = [input() for j in range(c)]
g = [0]*a
t = 0
for k in b:
    e = b.count(k)
    f = d.count(k)
    g[t] = e - f
    t +=1
if max(g) < 0:
    print(0)
else:
    print(max(g))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

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

int main(){
	int c[3][3];
	REP(i,3){
		REP(j,3){
			cin>>c[i][j];
		}
	}
	int x[3][2];
	REP(k,2){
		REP(l,3){
			x[l][k]=c[k][l]-c[k+1][l];
		}
	}
	if(x[0][0]==x[1][0]&&x[1][0]==x[2][0]&&x[0][1]==x[1][1]&&x[1][1]==x[2][1]){
	}
	else{
		cout<<"No";
		return 0;
	}
	REP(k,2){
		REP(l,3){
			x[l][k]=c[l][k]-c[l][k+1];
		}
	}
	if(x[0][0]==x[1][0]&&x[1][0]==x[2][0]&&x[0][1]==x[1][1]&&x[1][1]==x[2][1]){
		cout<<"Yes";
		return 0;
	}
	else{
		cout<<"No";
		return 0;
	}
}

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

signed main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	bool f = 0;
	while (A > 0 && C > 0) {
		if (f) {
			A -= D;
		} else {
			C -= B;
		}
		f ^= 1;
	}
	if (A > 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,l;
    cin >> n >> l;
    string s[n];
    for(int i = 0;i < n;i++)
    {
        cin >> s[i];
    }
    sort(s,s + n);
    for(int i = 0;i < n;i++)
    {
        cout << s[i];
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        const bool IsTest = false;

        const string t1 = "119";
        const string t2 = "999";
        public static void Main(string[] args)
        {
            if (!IsTest) {
                new Program().Solve(new ConsoleInput(Console.In));
            } else {
                new Program().Solve(new ConsoleInput(new StringReader(t1)));
                new Program().Solve(new ConsoleInput(new StringReader(t2)));
            }
        }

        public void Solve(ConsoleInput cin)
        {
            cin.ReadLine();
            Console.WriteLine(cin.ReadString().Replace('1', 'a').Replace('9', '1').Replace('a', '9'));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private string _curLine;
        private string[] _curLineSplitted;
        private int _curItemIndex;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
        }
        public T Read<T>()
        {
            var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T));
            if (converter == null) {
                throw new Exception(string.Format("TypeDescriptor.GetConverter {0}", typeof(T).Name));
            }
            return (T)converter.ConvertFromString(ReadString());
        }
        public T[] ReadArray<T>(long N)
        {
            var ret = new T[N];
            for (long i = 0; i < N; i++) {
                ret[i] = Read<T>();
            }
            return ret;
        }
        public Tuple<T> ReadLineAs<T>()
        {
            ReadLine();
            return new Tuple<T>(Read<T>());
        }
        public Tuple<T, S> ReadLineAs<T, S>()
        {
            ReadLine();
            return new Tuple<T, S>(Read<T>(), Read<S>());
        }
        public Tuple<T, S, U> ReadLineAs<T, S, U>()
        {
            ReadLine();
            return new Tuple<T, S, U>(Read<T>(), Read<S>(), Read<U>());
        }
        public Tuple<T, S, U, V> ReadLineAs<T, S, U, V>()
        {
            ReadLine();
            return new Tuple<T, S, U, V>(Read<T>(), Read<S>(), Read<U>(), Read<V>());
        }
        public Tuple<T, S, U, V, R> ReadLineAs<T, S, U, V, R>()
        {
            ReadLine();
            return new Tuple<T, S, U, V, R>(Read<T>(), Read<S>(), Read<U>(), Read<V>(), Read<R>());
        }

        public string ReadString()
        {
            return _curLineSplitted[_curItemIndex++];
        }
        public void ReadLine()
        {
            _curLine = _stream.ReadLine();
            if (_curLine == null) {
                throw new System.Exception("No more lines");
            }
            _curLineSplitted = _curLine.Split(_separator);
            _curItemIndex = 0;
        }
    }
}



Measured memory_bytes: 11092
n = int(input())
p = list(map(int, input().split()))

s = ""
for i, e in enumerate(p, 1):
    if i == e:
        s += "1"
    else:
        s += "0"

s = s.split("0")
ans = 0
for e in s:
    q, r = divmod(len(e), 2)
    ans += q + r

print(ans)


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

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

	int ans = 0;
	int cur_H = 0;
	rep(i, n){
		int a;
		cin >> a;
		cur_H = max(cur_H, a);
		if(a == cur_H) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=3000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 1000000007
#define inv2 500000004
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
    #define N 100000

    int fac[N+100],invfac[N+100];

    int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
    int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
    int mul(int x,int y) {return 1ll*x*y%maxd;}
    ll qpow(ll x,int y)
    {
        ll ans=1;
        while (y)
        {
            if (y&1) ans=mul(ans,x);
            x=mul(x,x);y>>=1;
        }
        return ans;
    }
    int getinv(int x) {return qpow(x,maxd-2);}

    int C(int n,int m)
    {
        if ((n<m) || (n<0) || (m<0)) return 0;
        return mul(mul(fac[n],invfac[m]),invfac[n-m]);
    }

    void math_init()
    {
        fac[0]=invfac[0]=1;
        rep(i,1,N) fac[i]=mul(fac[i-1],i);
        invfac[N]=getinv(fac[N]);
        per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
    }
    #undef N
}
using namespace My_Math;

int n,q,a[N],f[N][N];

int main()
{
    n=read();q=read();
    rep(i,1,n) a[i]=read();
    rep(i,1,n) rep(j,1,n) f[i][j]=(a[i]<a[j]);
    rep(i,1,q)
    {
        int x=read(),y=read();
        f[x][y]=f[y][x]=mul(inv2,add(f[x][y],f[y][x]));
        rep(j,1,n)
        {
            if ((j==x) || (j==y)) continue;
            f[x][j]=f[y][j]=mul(inv2,add(f[x][j],f[y][j]));
            f[j][x]=f[j][y]=mul(inv2,add(f[j][x],f[j][y]));
        }
    }
    int ans=0;
    rep(i,1,n) rep(j,1,i-1) ans=add(ans,f[i][j]);
    ans=mul(ans,qpow(2,q));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 40104
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        l = n - i - j
        total = 10000 * i + 5000 * j + 1000 * l
        if i + j + l == n and total == y:
            print('{} {} {}'.format(i, j, l))
            exit()
print('-1 -1 -1')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int main()
{
	char S[4];
	cin >> S;
	int ans = 700;
	for (int i = 0; i < 3; i++)
	{
		if (S[i] == 'o')
			ans += 100;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)
#define MOD (1000000007LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

#define vv(t) vector< vector< T > >
#define pb push_back
#define pu push
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define EQ(a,b) (abs((a)-(b))<EPS)


int main(void){
  ios_base::sync_with_stdio(0);
  int x, y;
  while(cin >> x >> y, x || y){
    int dp[17][17] = {};
    map<pii, int> c;
    int n;  cin >> n;
    for(int i = 0; i < n; i++){
      int a, b; cin >> a >> b;
      c[pii(a, b)] = 1;
    }
    dp[1][1] = 1;
    for(int i = 1; i <= y; i++){
      for(int j = 1; j <= x; j++){
        if((i == 1 && j == 1) || c[pii(j, i)]) continue;
        dp[i][j] = dp[i][j-1] + dp[i-1][j];
      }
    }
    cout << dp[y][x] << endl;
  }
  return 0; 
}

Measured memory_bytes: 1216
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){
    vector<pair<T,T>> out(input.size()-1);
    rep(i,input.size()-1){
        out[i].first =input[i  ];
        out[i].second=input[i+1];
    }
    return(out);
}
vector<char> String_to_vector_char(const string& input){
    vector<char> out(input.size());
    rep(i,input.size()){
        out[i]=input[i];
    }
    return out;
}

int n,m;
vector<ll> avec;
vector<pii>bc;
priority_queue<ll,vector<ll>,greater<ll>> a;
void input(){
    cin>>n>>m;
    avec.resize(n);
    rep(i,n){
        cin>>avec[i];
        a.push(avec[i]);
    }
    bc.resize(m);
    ll b,c;
    rep(i,m){
        cin>>b>>c;
        bc[i]={b,c};
    }
}
void src(){
    ll sum = accumulate(avec.begin(),avec.end(),0ll);
    sort(bc.rbegin(),bc.rend());
    rep(i,m){
        rep(j,bc[i].first){
            if(bc[i].second>a.top()){
                sum += bc[i].second-a.top(); 
                a.pop();a.push(bc[i].second);
            }else{
                break;
            }
        }
    }
    cout<<sum;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 3572
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = 10 ** 10
nega = sorted(-x for x in X if x < 0)
posi = sorted(x for x in X if 0 < x)
if 0 in X:
    K -= 1

if 0 < K <= len(posi):
    t = posi[K - 1]
    ans = min(ans, t)
if 0 < K <= len(nega):
    t = nega[K - 1]
    ans = min(ans, t)

if 0 < K:
    for np in range(1, len(posi) + 1):
        if 0 <= K - np - 1 < len(nega):
            t = posi[np - 1] * 2 + nega[K - np - 1]
            ans = min(ans, t)
    for nn in range(1, len(nega) + 1):
        if 0 <= K - nn - 1 < len(posi):
            t = nega[nn - 1] * 2 + posi[K - nn - 1]
            ans = min(ans, t)
else:
    ans = 0
print(ans)

Measured memory_bytes: 20180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const ll inf = 1e18 ;

int main(){
    ll n , m ;
  	cin >> n >> m ;
  	rep(i,m){
        ll a ; cin >> a ;
        n -= a ;
    }
    cout << max(n,(ll)-1) << endl ;
}


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


int main() {
  const int n_day[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  const string week_name[] = {
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday",
    "Monday",
    "Tuesday"
  };


  int m, d, sum=0;
  cin >> m >> d;
  while(m != 0 && d != 0) {
    m--;
    for(int i=0; i<m; i++) {
      sum += n_day[i];
    }
    sum += d;
    cout << week_name[sum%7] << endl;
    sum = 0;
    cin >> m >> d;
  }
  return 0;
}

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


def solve(A: int, B: int):
    print(lcm(A, B))
    return


def lcm(x, y):
    return (x * y) // gcd(x, y)


def gcd(x: int, y: int):
    """xとyの最大公約数を求める"""
    return gcd(y, x % y) if y else x


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int k,n;
    cin>>k>>n;
    vector<int> hoge(n);
    
    for(int i=0;i<n;i++) cin>>hoge.at(i);
    
    priority_queue<int> aida;
    
    for(int i=0;i<n-1;i++) aida.push(hoge.at(i+1)-hoge.at(i));
    aida.push(hoge.at(0)+k-hoge.at(n-1));
    aida.pop();
    
    int ans=0;
    
    while(!aida.empty()){
        ans+=aida.top();
        aida.pop();
    }
    
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
  string s,t;
  int count = 0;
  while(cin>>s) {
    t = string(s);
    reverse(s.begin(), s.end());
    if(s == t) count++;
  }
  cout<<count<<endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
string s;
/******* define variable end *******/
ll solve()
{
    cin >> s;
    ll length = s.size();
    REP(i, length / 2)
    {
        if (s.substr(i, 1) != s.substr(length - i - 1, 1))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    ll len2 = (length - 1) / 2;
    REP(i, len2)
    {
        if (s.substr(i, 1) != s.substr(len2 - i - 1, 1))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    ll len3 = (length + 3) / 2 - 1;
    for (ll i = len3; i < length; i++)
    {
        if (s.substr(i, 1) != s.substr(length - i - 1, 1))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 256