akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c) for (int i = int(a), i##__b = int(b), i##__c = int(c); i < i##__b; i += i##__c)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep3(i, a, b) for (int i = int(b) - 1, i##__a = int(a); i >= i##__a; i--)
#define rrep1(n) rrep3(i, 0, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep4(i, a, b, c) for (int i = int(a + (b - a - 1) / c * c), i##__a = int(a), i##__c = int(c); i >= i##__a; i -= i##__c)
#define RREP(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
template <class T> using vv = vector<vector<T>>;
// clang-format off
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}
// clang-format on


int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<ll, vll, greater<ll>> A;
    REP(N) {
        ll a;
        cin >> a;
        A.push(a);
    }
    priority_queue<pll> CB;
    REP(M) {
        ll B, C;
        cin >> B >> C;
        CB.push(mp(C, B));
    }
    // 書き換えることのできる数を大きい方から最大N個
    vll C;
    int csize = 0;
    for (; !CB.empty(); CB.pop()) {
        if (csize >= N) break;
        auto cb = CB.top();
        // Cにb個のcを追加する
        REP(cb.second) {
            if (csize >= N) break;
            C.pb(cb.first);
            csize++;
        }
    }

    ll ans = 0;

    for (ll c : C) {
        if (A.top() < c) {
            A.pop();
            ans += c;
        } else {
            break;
        }
    }
    for (; !A.empty(); A.pop()) ans += A.top();

    print(ans);
}

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

int toint(string s) {
    int ans = 0;
    for(char x: s) ans = ans * 10 + (x - '0');
    return ans;
}

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

    string s;
    cin>>s;
    int n = s.size();
    int ans = INT_MAX;
    for(int i = 0;i < n-2;i++) {
        ans = min(ans, abs(753 - toint(s.substr(i,3))));
    }
    cout<<ans;
}

Measured memory_bytes: 256
import sys

n = int(input())
w = [input() for i in range(n)]
if len(w) != len(set(w)):
    print("No")
    sys.exit()
for i in range(n - 1):
    if w[i][-1] != w[i + 1][0]:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
maA = max(A) + N -1
for k in range(N):
  if A[k] + k <= maA:
    B.append(A[k]+k)
  if -A[k] + k >0:
    C.append(-A[k]+k)
B.sort()
C.sort()

c = 0
b = 0
while b < len(B) and c < len(C):
  if B[b] == C[c]:
    s = 0
    t = 0
    j = float('inf')
    k = float('inf')
    for j in range(b, len(B)):
      if B[b] == B[j]:
        s += 1
      else:
        break
    for k in range(c, len(C)):
      if C[c] == C[k]:
        t +=1
      else:
        break
    ans += s*t
    b = j
    c = k
    continue
  elif B[b] > C[c]:
    c += 1
  else:
    b += 1
#print(B)
#print(C)
print(ans)


Measured memory_bytes: 113632
a,b=map(int,input().split())
def f(n):
  #XOR from 0 to n
  m=n//2
  if n % 4 == 0:
    return n
  elif n % 4 == 1:
    return (n-1)^n
  elif n % 4 == 2:
    return (n-2)^(n-1)^n
  else:
    return (n-3)^(n-2)^(n-1)^n
print(f(a-1)^f(b))

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

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

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

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

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

const int MAX = 100100;

VI g[MAX];
bool U[MAX];

VI res;

void go(int x)
{
	U[x] = true;
	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (U[to]) continue;
		res.PB(to);
		go(to);
		return;
	}
}

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

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

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

	res.PB(0);
	go(0);

	reverse(ALL(res));
	go(0);

	printf("%d\n", SZ(res));
	FOR (i, 0, SZ(res))
	{
		printf("%d", res[i] + 1);
		if (i != SZ(res) - 1) printf(" ");
	}
	printf("\n");

}


Measured memory_bytes: 9720
'use strict';
var NS = {};
function addProps(ns) {
    var isBrowser = function() {
        return typeof window !== 'undefined';
    }
    ns.isBrowser = isBrowser;
    
    var isNodejs = function() {
        return ! isBrowser();
    }
    ns.isNodejs = isNodejs;
    
    if (isBrowser()) {
        var getHtmlEncoded = function(string0) {
            return String(string0)
                    .replace(/&/g, '&amp;')
                    .replace(/"/g, '&quot;')
                    .replace(/'/g, '&#39;')
                    .replace(/</g, '&lt;')
                    .replace(/>/g, '&gt;');
        }
        ns.getHtmlEncoded = getHtmlEncoded;
        
        var outputCode = function() {
            document.getElementById('code').innerHTML = '<pre><code>' + getHtmlEncoded(addProps) + '</code></pre>';
        }
        ns.outputCode = outputCode;
    }
    
    var getInput = function() {
        var inputLines = [];
        if (isBrowser()) {
            var html = document.getElementById('input').innerHTML;
            inputLines = html.split('<br>');
        }
        if (isNodejs()) {
            inputLines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
        }
        return inputLines;
    }
    
    var doOutput = function(outputLines) {
        if (isBrowser()) {
            document.getElementById('output').innerHTML = outputLines.map(getHtmlEncoded).join('<br>\n');
        }
        if (isNodejs()) {
            for (var i = 0; i < outputLines.length; i++) {
                console.log(outputLines[i]);
            }
        }
    }
    ns.doOutput = doOutput;
    
    var getArea = function(a, b) {
        return a * b;
    }

    var getPerimeter  = function(a, b) {
        return a + b + a + b;
    }
    
    var main = function() {
        var inputLines = getInput();
        var line0 = inputLines[0];
        var numStrings = line0.split(' ');
        var nums = [];
        for (var i = 0; i < numStrings.length; i++) {
            nums.push(Number(numStrings[i]));
        }
        var a = nums[0];
        var b = nums[1];
        var area = getArea(a, b);
        var perimeter = getPerimeter(a, b);
        var outputLine0 = area + ' ' + perimeter;
        doOutput([outputLine0]);
    }
    ns.main = main;
}
addProps(NS);
if (NS.isBrowser()) {
    window.onload = function() {
        NS.outputCode();
    }
}
NS.main();

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

int main()
{
  int count;
  string name;

  count = 0;
  getline(cin, name);

 /*  if(name[0] != 'C')
  {
    count += 1;
    cout << count << endl;
    if(name[1] != 'O')
    count += 1;
  }
  else if(name[1] != 'O')
  count += 1;

  cout << count << endl;
*/
    if(name[0] != 'C')
    count += 1;
    if(name[1] != 'O')
    count += 1;
    if(name[2] != 'D')
    count += 1;
    if(name[3] != 'E')
    count += 1;
    if(name[4] != 'F')
    count += 1;
    if(name[5] != 'E')
    count += 1;
    if(name[6] != 'S')
    count += 1;
    if(name[7] != 'T')
    count += 1;
    if(name[8] != 'I')
    count += 1;
    if(name[9] != 'V')
    count += 1;
    if(name[10] != 'A')
    count += 1;
    if(name[11] != 'L')
    count += 1;
    if(name[12] != '2')
    count += 1;
    if(name[13] != '0')
    count += 1;
    if(name[14] != '1')
    count += 1;
    if(name[15] != '6')
    count += 1;

    cout << count << endl;

}


Measured memory_bytes: 3624
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####
def solve(N, M, graph):
    dist = {0: 0}
    queue = [0]
    parent = {}
    for node in queue:
        for nei in graph[node]:
            if nei not in dist:
                dist[nei] = dist[node] + 1
                parent[nei] = node
                queue.append(nei)

    if len(parent) != N - 1:
        return
    return [parent[i] for i in xrange(1, N)]

N, M = rrm()
graph = [[] for _ in xrange(N)]
for _ in xrange(M):
    u,v = rrm()
    u -= 1;v-=1
    graph[u].append(v)
    graph[v].append(u)
ans= solve(N,M,graph)
if ans is None:
    print "No"
else:
    print "Yes"
    for x in ans: print x+1


Measured memory_bytes: 143580
#include <iostream>
#include <vector>
#include <numeric>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;

using Flow = int;

template<typename Flow = int>
struct PrimalDual {

    struct Edge {
        int dst;
        Flow cap, cap_orig;
        Flow cost;
        int revEdge; 
        bool isRev;
        Edge(int dst, Flow cap, Flow cost, int rev, bool isRev)
            :dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(rev), isRev(isRev) {
        }
    };

    int n;
    vector<vector<Edge> > g;
    PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
    void addEdge(int src, int dst, Flow cap, Flow cost) {
        g[src].emplace_back(dst, cap, cost, g[dst].size(), false);
        g[dst].emplace_back(src, 0, -cost, g[src].size() - 1, true);
    }
    Flow solve(int s, int t, int f) {
        constexpr Flow inf = numeric_limits<Flow>::max();
        Flow res = 0;
        vector<Flow> h(g.size()), dist(g.size());
        vector<int> prevv(g.size()), preve(g.size());
        while (f > 0) {
            priority_queue<pair<Flow, int>> q;
            fill(dist.begin(), dist.end(), inf);
            dist[s] = 0;
            q.emplace(0, s);
            while (q.size()) {
                int d, v;
                tie(d,v) = q.top();
                q.pop();
                d = -d;
                if (dist[v] < d) continue;
                for(int i = 0; i < (int)g[v].size(); ++i){
                    Edge &e = g[v][i];
                    if (e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
                        dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
                        prevv[e.dst] = v;
                        preve[e.dst] = i;
                        q.emplace(-dist[e.dst], e.dst);
                    }
                }
            }
            if (dist[t] == inf) {
                return -1;
            }
            for (int i = 0; i < n; ++i) {
                h[i] += dist[i];
            }
            Flow d = f;
            for (int v = t; v != s; v = prevv[v]) {
                d = min(d, g[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * h[t];
            for (int v = t; v != s; v = prevv[v]) {
                Edge &e = g[prevv[v]][preve[v]];
                e.cap -= d;
                g[v][e.revEdge].cap += d;
            }
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, f;
    cin >> n >> m >> f;
    PrimalDual<int> pd(n);
    for (int i = 0; i < m; i++) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        pd.addEdge(u, v, c, d);
    }
    cout << pd.solve(0, n - 1, f) << endl;
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
int siro[1000][1000][3];
int main(){
  int m,n;
  char str[1000][1001],flag[5];
  cin >> m >> n;
  for(int i=0;i<m;i++){
    scanf("%s",str[i]);
  }
  scanf(" %c %c %c %c",&flag[0],&flag[1],&flag[2],&flag[3]);
  int ans = 0,ma = 0;
  fill_n(**siro,1000*1000*3,0);
  for(int i=0;i<m-1;i++){
    for(int j=0;j<n-1;j++){
      if(str[i][j]==flag[0] && str[i][j+1]==flag[1] && str[i+1][j]==flag[2] && str[i+1][j+1]==flag[3]){
	ans++;
      }
      if(str[i][j]!=flag[0] && str[i][j+1]==flag[1] && str[i+1][j]==flag[2] && str[i+1][j+1]==flag[3]){
	if(flag[0] == 'J'){
	  siro[i][j][0]++;
	  ma = max(ma,siro[i][j][0]);
	}
	if(flag[0] == 'O'){
	  siro[i][j][1]++;
	  ma = max(ma,siro[i][j][1]);
	}
	if(flag[0] == 'I'){
	  siro[i][j][2]++;
	  ma = max(ma,siro[i][j][2]);
	}
      }
      if(str[i][j]==flag[0] && str[i][j+1]!=flag[1] && str[i+1][j]==flag[2] && str[i+1][j+1]==flag[3]){
	if(flag[1] == 'J'){
	  siro[i][j+1][0]++;
	  ma = max(ma,siro[i][j+1][0]);
	}
	if(flag[1] == 'O'){
	  siro[i][j+1][1]++;
	  ma = max(ma,siro[i][j+1][1]);
	}
	if(flag[1] == 'I'){
	  siro[i][j+1][2]++;
	  ma = max(ma,siro[i][j+1][2]);
	}
      }
      if(str[i][j]==flag[0] && str[i][j+1]==flag[1] && str[i+1][j]!=flag[2] && str[i+1][j+1]==flag[3]){
	if(flag[2] == 'J'){
	  siro[i+1][j][0]++;
	  ma = max(ma,siro[i+1][j][0]);
	}
	if(flag[2] == 'O'){
	  siro[i+1][j][1]++;
	  ma = max(ma,siro[i+1][j][1]);
	}
	if(flag[2] == 'I'){
	  siro[i+1][j][2]++;
	  ma = max(ma,siro[i+1][j][2]);
	}
      }
      if(str[i][j]==flag[0] && str[i][j+1]==flag[1] && str[i+1][j]==flag[2] && str[i+1][j+1]!=flag[3]){
	if(flag[3] == 'J'){
	  siro[i+1][j+1][0]++;
	  ma = max(ma,siro[i+1][j+1][0]);
	}
	if(flag[3] == 'O'){
	  siro[i+1][j+1][1]++;
	  ma = max(ma,siro[i+1][j+1][1]);
	}
	if(flag[3] == 'I'){
	  siro[i+1][j+1][2]++;
	  ma = max(ma,siro[i+1][j+1][2]);
	}
      }
    }
  }
  cout << ans+ma << endl;
  return (0);
}

Measured memory_bytes: 15904
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

typedef pair<int, int> P;

int main () {

    int N,M;
    cin >>N>>M;
    vector<vector<char> > maze(N, vector<char>(M));
    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> maze[i][j];
            if(maze[i][j] == '#') {
                count += 1;
            } 
        }
    }

    int sx = 0, sy = 0; //スタート
    int gx = N-1, gy = M-1; //ゴール

    vector<vector<int> > d(N, vector<int>(M, INF));
    vector<int> dx(4); dx[0] = 1; dx[1] = 0; dx[2] = -1; dx[3] = 0; 
    vector<int> dy(4); dy[0] = 0; dy[1] = 1; dy[2] = 0; dy[3] = -1; //→↑←↓の順に見る

    queue<P> que;
    que.push(P(sx, sy));
    d[sx][sy] = 1;

    while (que.size()) {
        P p = que.front(); que.pop();
        if(p.first == gx && p.second == gy) {
            break;
        } 
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' && d[nx][ny] == INF)  {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            } 
        }
    }

    if(d[gx][gy] == INF) {
        cout << -1 << endl;
    } else {
        cout << N*M - count - d[gx][gy] << endl;
    }

    return 0;
}

Measured memory_bytes: 768
from itertools import accumulate


def main():
    n, k = [int(x) for x in input().split()]
    dice = [int(x) for x in input().split()]

    expected_accum = list(accumulate((1 + p) / 2 for p in dice))

    def gen():
        for start in range(n - k + 1):
            if start == 0:
                yield expected_accum[k - 1]
            else:
                yield expected_accum[start + k - 1] - expected_accum[start - 1]

    print(max(gen()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 25148
#include <stdio.h>

int main(int argc, char *argv[])
{
  int a, b, sum[1024], i, j;
  char op[10] = "";

  a = b = 1;

  for (i = 0; i < 1024 && (strcmp(op, "") == 0 || strcmp(op, "?") != 0) ; i++) {
    scanf("%d %s %d", &a, op, &b);
    
    if (strcmp(op, "*") == 0)
      sum[i] = a * b;
    else if (strcmp(op, "-") == 0)
      sum[i] = a - b;
    else if (strcmp(op, "+") == 0)
      sum[i] = a + b;
    else if (strcmp(op, "/") == 0)
      sum[i] = a / b;
  }

  for (j = 0; j < i - 1;j++)
    printf("%d\n", sum[j]);

  return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  string ans = "AC";
  
  if(S.at(0) != 'A'){
    ans = "WA";
  }
  int count_c = 0;
  for(int i=2; i<S.size()-1; i++){
    if(S.at(i) == 'C'){
      count_c++;
    }
  }
  if(count_c != 1){
    ans = "WA";
  }
  for(int j=1; j<S.size(); j++){
    if(S.at(j) != 'C' && (S.at(j) < 'a' || S.at(j) > 'z')){
     ans = "WA";
    }
  } 
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.array, std.range, std.algorithm, 
  std.string, std.math;

void main(){
    auto n =  readln.chomp.to!long;
    auto as = [0L] ~ readln.chomp.split.to!(long[]) ~ [0L];

    long[] ans = [];
    long s = 0;
  	foreach(i; 0 .. n + 1) s += abs(as[i] - as[i + 1]);
    foreach(i; 1 .. n + 1){
        auto d = abs(as[i] - as[i - 1]) + abs(as[i] - as[i + 1])
          - abs(as[i - 1] - as[i + 1]);
        ans ~= s - d;
    }
    foreach(a; ans) a.writeln;
}

Measured memory_bytes: 5496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////
signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int q;
	cin>>q;
	set<pair<pair<int,int>,int>> s;
	map<int,int> m;
	for(int i=0;i<n;++i)
	{
		int  st,t,x;
		cin>>st>>t>>x;
		m[i]=x;
		s.insert({{st-x,0},i});
		s.insert({{t-x-1,2},i});
	}
	for(int i=0;i<q;++i)
	{
		int d;
		cin>>d;
		s.insert({{d,1},i});
	}
	int ans[q];
	multiset<int> w; 
	for(auto r:s)
	{
		// cout<<r.F.F<<" "<<r.F.S<<endl;
		// for(auto rr:w)
			// cout<<rr<<" ";
		// cout<<endl;
		if(r.F.S==0)
		{
			w.insert(m[r.S]);
		}
		if(r.F.S==1)
		{
			if(w.size()==0)
			{
				ans[r.S]=-1;
			}
			else
			{
				ans[r.S]=*w.begin();
			}
		}
		if(r.F.S==2)
		{
			w.erase(w.find(m[r.S]));
		}
	}
	for(int i=0;i<q;++i)
	{
		cout<<ans[i]<<"\n";
	}
}

Measured memory_bytes: 62208
#include<cstdio>

using namespace std;

int main(){
	int n; scanf("%d", &n);
	int t[100], sum = 0;
	for(int i = 0; i < n; i++){ scanf("%d", &t[i]); sum += t[i]; }
	int m; scanf("%d", &m);
	for(int i = 0; i < m; i++){
		int p, x; scanf("%d %d", &p, &x);
		printf("%d\n", sum - t[p - 1] + x);
	}
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var p, q, r int
	fmt.Scan(&p, &q, &r)
	if p+q <= q+r && p+q <= p+r {
		fmt.Println(p + q)
	} else {
		if q+r <= p+r {
			fmt.Println(q + r)
		} else {
			fmt.Println(p + r)
		}
	}
}

Measured memory_bytes: 512
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

n = int(input())
s = input()

ans = 0
aDec = False
bDec = False

for i in range(n):
    if s[i] == "A":
        aDec = True
        bDec = False
    elif s[i] == "B":
        if (aDec):
            bDec = True
        else:
            bDec = False
        aDec = False
    elif s[i] == "C":
        if (bDec):
            ans += 1
        bDec = False
        aDec = False
    else:
        bDec = False
        aDec = False
print(ans)


Measured memory_bytes: 9096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();

		String line;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				break;
			}
			int a = Integer.MAX_VALUE;
			int sum = 0;
			for (int i = 0; i < line.length(); i++) {
				int b = getNum(line.charAt(i));
				if (a >= b) {
					sum += b;
				} else {
					sum = sum - a * 2 + b;
				}
				a = b;
			}
			builder.append(sum).append('\n');
		}
		System.out.print(builder);
	}

	private static int getNum(char charAt) {
		switch (charAt) {
		case 'I':
			return 1;
		case 'V':
			return 5;
		case 'X':
			return 10;
		case 'L':
			return 50;
		case 'C':
			return 100;
		case 'D':
			return 500;
		default:
			return 1000;
		}
	}
}

Measured memory_bytes: 16864
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int n=in(),i,j,c[500],s[500],f[500];
	rep(i,n-1){
		c[i]=in();
		s[i]=in();
		f[i]=in();
	}
	rep(i,n-1){
		int ans=0;
		for(j=i;j<n-1;j++){
			int x=s[j];
			while(x<ans){
				x+=f[j];
			}
			ans+=x-ans;
			ans+=c[j];
			//printf("%d %d %d\n",i,j,ans);
		}
		print(ans);
	}
	print(0);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;

int main (){
	string s;
	stack<int> A;
	int a,b;
	while(cin>>s){
		if(s[0]=='+'){
			a=A.top();A.pop();
			b=A.top();A.pop();
			A.push(a+b);
		}
		else if(s[0]=='-'){
			a=A.top();A.pop();
			b=A.top();A.pop();
			A.push(b-a);
		}
		else if(s[0]=='*'){
			a=A.top();A.pop();
			b=A.top();A.pop();
			A.push(a*b);
		}
		else {
			A.push(atoi(s.c_str()));
		}
	}
	cout<<A.top()<<endl;
	return 0;
}


Measured memory_bytes: 3204
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var abk = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => long.Parse(number));

		var answers = new List<long>();
		for (long i = abk[0]; i < abk[0] + abk[2] && i <= abk[1]; ++i) {
			answers.Add(i);
		}

		for (long i = abk[1] - abk[2] + 1; i <= abk[1]; ++i) {
			if (i >= abk[0] + abk[2]) {
				answers.Add(i);
			}
		}

		answers.ForEach(answer => Console.WriteLine(answer));

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
#define p(dis) cout << dis << endl

int func(int a, int b){
	int f = 1;
	for(int i = a;i <= b;i++){
		if(i % 4 == 0){
			if(i % 100 == 0){
				if(i % 400 == 0)p(i), f = 0;
				continue;
			}
			p(i), f = 0;
		}
	}
	return f;
}

int main(){
	int a, b, f = 0;
	while(cin >> a >> b, a+b){
		if(f)cout << endl;f = 1;
		if(func(a, b))cout << "NA" <<endl;
	}
	return 0;
}

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

int main()
{
    string s, t;
    cin >> s >> t;

    bool ans = false;
    for (int i = 0; i < s.size(); i++){
        if (s == t){
            ans = true;
            break;
        }
        s = s.back() + s.substr(0, s.size() - 1);
    }

    if (ans) cout << "Yes" << endl;
    else    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c, d, e, f = map(int, input().split())
max_concentration = 0
for i in range(0, f + 1, 100 * a):
    for j in range(0, f - i + 1, 100 * b):
        if i == 0 and j == 0:
            continue
        y = min((i + j) * e // 100, f - i - j)
        for k in range(0, y + 1, c):
            for l in range(0, y - k + 1, d):
                concentration = 100 * (k + l) / (i + j + k + l)
                if max_concentration <= concentration:
                    max_concentration = concentration
                    res1 = i + j + k + l
                    res2 = k + l
print(str(res1) + ' ' + str(res2))


Measured memory_bytes: 3064
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

int n, k;
vi as, d;
map<int, int> cnt;

int main(){
    R(n, k);
    as.assign(n+1, 0);
    FORI(i, n) R(as[i]);

    d.assign(n+1, 0);
    FORI(i, n)
        d[i] = (as[i] + d[i-1] - 1) % k;

    ll ans = 0;
    FOR(i, SZ(d)){
        if(i >= k) cnt[d[i-k]]--;
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }

    W(ans);

    return 0;
}


Measured memory_bytes: 11136
def prime_check x
    prime = true
    2.upto(Math.sqrt(x)){|i|
        if x % i == 0
            prime = false
            break
        end
    }
    return prime
end

while true
    a, d, n = gets.chomp.split.map(&:to_i)
    break if [a, d, n] == [0, 0, 0]
    primes, x = [], a - d
    while primes.length < n
        x += d
        primes << x if x != 1 && prime_check(x)
    end
    puts primes.last
end


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

using namespace std;

int main(void) {
  int i, N, tmp, K, count, median;
  vector<int> d;
  cin >> N;
 
  for(i = 0; i < N; i++) {
    cin >> tmp;
    d.push_back(tmp);
  }
  sort(d.begin(), d.end());
  median = (int)((d[N/2] + d[N/2 - 1])/2);
  count = 0;
  for(K = median; K > d[N/2 - 1]; K--) count++;
  for(K = median; K < d[N/2]; K++) count++;
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	int K;
	int R;
	int* a;
	int i;
	int total = 0;
	

	cin >> K;
	cin >> R;
	
	a = new int[R];
	
	for (i = 0; i < R; i++) {
		cin >> a[i];
	}

	for (i = 0; i < R; i++) {
		K -= a[i];
	}
	if (K >= 0) {
		cout << K;
	}
	else {
		cout << -1;
	}
	return 0;
}

Measured memory_bytes: 3196
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

S = list(str(input()))

if len(S) == 3:
    S.reverse()

print("".join(S))

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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define llong long long
#define P (1000000007)

llong mpow(llong a,llong b){
	llong ans = 1;
	while(b){
		if(b&1) ans = ans*a%P;
		b = b>>1; a = a*a%P;
	}
	return ans;
}

int main(){
	llong N,K; scanf("%lld %lld",&N,&K);
	llong a = K-N-2;
	llong b = ((2*K*K%P)-(K*(N+2))%P-(N*N+N+6)%P)%P;
	if( a<0 ) a+=P;
	if( b<0 ) b+=P;
	llong ans = ((a*b)%P*mpow(6,1000000005))%P;
	printf("%lld",ans);
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
 int main(){
  string S,T;
   cin >> S >> T;
   bool ans = false;
   
   for(int i=0;i<S.size();i++){
     if(S == T){
       ans = true;
       break;
     }
     S = S.back() + S.substr(0,S.size()-1);
   }
   if(ans) cout << "Yes" << endl;
   else cout << "No" << endl;
 }

Measured memory_bytes: 256
import Control.Monad

calc 'a' ["", _, _] = "A"
calc 'a' [a:as, bs, cs] = calc a [as, bs, cs]
calc 'b' [_, "", _] = "B"
calc 'b' [as, b:bs, cs] = calc b [as, bs, cs]
calc 'c' [_, _, ""] = "C"
calc 'c' [as, bs, c:cs] = calc c [as, bs, cs]

main = replicateM 3 getLine >>= putStrLn . calc 'a'

Measured memory_bytes: 508
#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;

int main(){
	ll K,a,b;cin>>K>>a>>b;
	if(a+1>=b||1+K<=a){
		cout<<1+K<<endl;
	}
	else{
		K-=(a-1);
		cout<<K/2*(b-a)+a+(K%2)<<endl;
	}
}

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

int main(){

  vector<string> holiday(8);
  holiday.at(1) = "SAT";
  holiday.at(2) = "FRI";
  holiday.at(3) = "THU";
  holiday.at(4) = "WED";
  holiday.at(5) = "TUE";
  holiday.at(6) = "MON";
  holiday.at(7) = "SUN";
  string s; cin >> s;
  for(int i=1;i<8;i++){
    if(holiday.at(i) == s){ cout << i << endl; break;}
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<int> P(N); for (auto &p : P) cin >> p, p--;
    vector<int> A(N, 1), B(N, 1);
    for (int i = 0; i < N; i++) {
        A[P[i]] += i;
        B[P[i]] += i;
    }
    for (int i = 1; i < N; i++) A[i] += A[i-1];
    for (int i = N-2; i >= 0; i--) B[i] += B[i+1];
    for (int i = 0; i < N; i++) cout << A[i] << " \n"[i == N-1];
    for (int i = 0; i < N; i++) cout << B[i] << " \n"[i == N-1];
    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

#define DIM 16

const long long Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int solve_mod(long long A[][DIM], long long b[], long long x[])
{
	int i, j, k, tmp;
	for (i = 0; i < DIM; i++) {
		if (A[i][i] == 0) {
			for (j = i + 1; j < DIM; j++) if (A[j][i] != 0) break;
			if (j == DIM) return -1;
			b[i] ^= b[j];
			b[j] ^= b[i];
			b[i] ^= b[j];
			for (k = 0; k < DIM; k++) {
				A[i][k] ^= A[j][k];
				A[j][k] ^= A[i][k];
				A[i][k] ^= A[j][k];
			}
		}
		
		for (j = i + 1; j < DIM; j++) {
			if (A[j][i] == 0) continue;
			tmp = div_mod(A[j][i], A[i][i], Mod);
			b[j] = (b[j] - b[i] * tmp % Mod + Mod) % Mod;
			for (k = i; k < DIM; k++) A[j][k] = (A[j][k] - A[i][k] * tmp % Mod + Mod) % Mod;
		}
	}
	
	for (i--; i >= 0; i--) {
		for (j = DIM - 1; j > i; j--) b[i] = (b[i] - A[i][j] * x[j] % Mod + Mod) % Mod;
		x[i] = div_mod(b[i], A[i][i], Mod);
	}
	return 0;
}

int main()
{
	int t, T, N;
	scanf("%d", &T);
	
	int i, j, k, l, m;
	long long A[DIM][DIM], b[2][DIM] = {}, x[2][DIM] = {}, tmp[DIM * 2];
	for (i = 1; i < DIM * 2; i++) {
		if (i % 2 == 1) tmp[i] = (i + 1) * (i + 1) / 4;
		else tmp[i] = i * (i + 2) / 4;
	}
	for (N = 0; N < DIM * 2; N++) {
		for (i = 1; i <= N - 4; i++) {
			for (j = 1; j <= N - 3 - i; j++) {
				for (k = 1; k <= N - 2 - i - j; k++) {
					for (l = 1; l <= N - 1 - i - j - k; l++) {
						for (m = 1; m <= N - i - j - k - l; m++) b[N%2][N/2] = (b[N%2][N/2] + tmp[i] * tmp[j] * tmp[k] * tmp[l] * tmp[m]) % Mod;
					}
				}
			}
		}
	}
	
	for (i = 0; i < DIM; i++) {
		for (j = 1, A[i][0] = 1; j < DIM; j++) A[i][j] = A[i][j-1] * i % Mod;
	}
	solve_mod(A, b[0], x[0]);
	for (i = 0; i < DIM; i++) {
		for (j = 1, A[i][0] = 1; j < DIM; j++) A[i][j] = A[i][j-1] * i % Mod;
	}
	solve_mod(A, b[1], x[1]);
	
	long long ans;
	for (t = 1; t <= T; t++) {
		scanf("%d", &N);
		for (i = DIM - 1, ans = 0; i >= 0; i--) ans = (ans * (N / 2) + x[N%2][i]) % Mod;
		printf("%lld\n", ans);
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int A[3][3];
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> A[i][j];
    int N; cin >> N;
    vector<int> B(N);
    for (auto &b : B) cin >> b;
    for (int b : B) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (A[i][j] == b) { A[i][j] = -1; }
            }
        }
    }
    bool ok = false;
    for (int i = 0; i < 3; i++) {
        if (A[i][0] < 0 && A[i][1] < 0 && A[i][2] < 0) ok = true;
        if (A[0][i] < 0 && A[1][i] < 0 && A[2][i] < 0) ok = true;
    }
    if (A[0][0] < 0 && A[1][1] < 0 && A[2][2] < 0) ok = true;
    if (A[0][2] < 0 && A[1][1] < 0 && A[2][0] < 0) ok = true;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=1e5+5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n1,n2;
	string str1,str2,str3;
	cin>>str1;
	for(int i=0;i<str1.length();i++){
		cout<<"x";
	}
	return 0;
}

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


int main() {
	string S;
    cin >> S;
    int c0 = 0,c1 = 0;
    for (int i = 0; i < S.size(); ++i){
    	if (S[i] == '0') c0++;
    	else c1++;
	}
    cout << (c0 < c1 ? 2 * c0 : 2 * c1 ) << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var S = ReadLine();
            var revS = S.Reverse().ToArray();
            var dsts = new List<long>();
            var current = 0L;
            while (current < N)
            {
                var n = Min(N, current + M);
                while (revS[n] == '1' && current < n)
                    --n;
                if (n == current)
                {
                    WriteLine(-1);
                    return;
                }
                var d = n - current;
                current = n;
                dsts.Add(d);
            }
            dsts.Reverse();
            WriteLine(string.Join(" ", dsts));
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

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

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7

int main() {
    int N, D, cnt = 0;
    double X, Y;
    cin >> N >> D;
    rep(i, N) {
        cin >> X >> Y;
        if (D >= sqrt(pow(X, 2.0) + pow(Y, 2.0))) {
            cnt++;
        }
    }

    cout << cnt << endl;
}


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

int main() {
	// your code goes here
	int n,i,c;
	c=0;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;s[i];i++)
	{
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
		{
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

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

    bool ok = false;
    reps(i, 100000)
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i << endn;
            ok = true;
            break;
        }

    if (!ok) cout << -1 << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;

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

const ll INF = 1e15;
const int MAX_V = 1e5;
const int MAX_E = 1e5;
struct edge{
    int to;
    ll c;
    edge(int _t, ll _c){
        to = _t;
        c = _c;
    };
};

vector<edge> g[MAX_V];
vector<bool> check(MAX_V,false);
vector<ll> dis(MAX_V,INF);

//深さ優先探索を利用する
void dfs(int s){
    if(check[s])return;
    check[s] = true;
/*
現在iへの最小移動コスト
sへの最小移動コスト + s->iへの移動コストを比べる
*/
    rep(i,g[s].size()){
        if(dis[g[s][i].to] > g[s][i].c + dis[s]){
            dis[g[s][i].to] = g[s][i].c + dis[s];
            dfs(g[s][i].to);
        }
    }
}

int main(){
    int n;
    cin >> n;
    int a,b;
    ll c;
    rep(i,n-1){
        cin >> a >> b >> c;
        a--;b--;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }

    int q,k;
    cin >> q >> k;
    k--;
    dis[k] = 0;//初期値
    //dfsを使ってkから各頂点への距離を求めておく
    dfs(k);

    int x,y;
    rep(i,q){
        cin >> x >> y;
        x--;y--;
        cout << dis[x] + dis[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 14336
def gcd(a, b):
    if 0 == b:
        return a
    r = a % b
    return b if 0 == r else gcd(b, r)


def gcd_list(lst):
    a = lst[0]
    for i in lst[1:]:
        a = gcd(a, i)
    return a


n = int(input())
a = list(map(int, input().split()))
l = [0 for _ in range(n)]
r = [0 for _ in range(n)]
for i in range(n-1):
    l_i = 0 if 0 == i else l[i]
    l[i+1] = gcd(l_i, a[i])
for i in range(n)[::-1]:
    r_i1 = 0 if i == n-1 else r[i+1]
    r[i] = gcd(r_i1, a[i])
m = []
for i in range(n):
    r_i1 = 0 if i == n-1 else r[i+1]
    m.append(gcd(l[i], r_i1))
print(max(m))


Measured memory_bytes: 14428
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,V,a[200];
int main()
{
	scanf("%d%d",&n,&V);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans=0;
	for (int i=1;i<n;i++)
		if (V>=a[i]) V-=a[i],ans++;
	if (V==a[n]) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define rp(i,n) for(long long i=1;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 1000000007;
vel rui(19, 1);
vel par;
int root(int ser) {
	if (par[ser] == -1) { return ser; }
	int ans = root(par[ser]);
	par[ser] = ans;
	return ans;
}
bool marge(pin a) {
	int x = root(a.first);
	int y = root(a.second);
	if (x != y) {par[x] = y;}
	return x != y;
}
signed main() {
	int n; cin >> n;
	vel x(n), y(n);
	V<pair<pin, int>> xy(n);
	V<pair<pin, int>> yx(n);
	rep(i, n) { 
		cin >> x[i] >> y[i]; 
		xy[i] = mkp(mkp(x[i], y[i]), i);
		yx[i] = mkp(mkp(y[i], x[i]), i);
	}
	sor(xy); sor(yx);
	V<pair<int, pin>> way(0);
	rep(i, n - 1) {
		int diff = xy[i + 1].first.first - xy[i].first.first;
		pin path = mkp(xy[i].second, xy[i+1].second);
		way.push_back(mkp(diff, path));
	}
	rep(i, n - 1) {
		int diff = yx[i + 1].first.first - yx[i].first.first;
		pin path = mkp(yx[i].second, yx[i + 1].second);
		way.push_back(mkp(diff, path));
	}
	sor(way);
	int ans = 0;
	par = vel(n, -1);
	rep(i, way.size()) {
		if (marge(way[i].second)) { ans += way[i].first; }
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    vector<int> a(4);
    rep(i,4) cin >> a[i];
    
    sort(a.begin(), a.end());
    
    if(a[0] == 1 and a[1] == 4 and a[2] == 7 and a[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let mut vs = scan!(usize,usize;n);
    vs.sort_by_key(|&(_, b)| b);
    let mut time = 0;
    for (a, b) in vs.into_iter() {
        time += a;
        if b < time {
            println!("No");
            return;
        }
    }
    println!("Yes")
}


Measured memory_bytes: 10492