akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
p = list(map(int, input().split()))

S = [0]*N

for i in range(K):
    S[0] += p[i]

for i in range(1,N-K+1):
    S[i] = S[i-1] - p[i-1] + p[i+K-1]

print((max(S)+K)/2)

Measured memory_bytes: 71792
#include <stdio.h>
#include <stdlib.h>

int selectionSort(int*, int);
void printArray(int*, int);

int main(void) {
    int n, *a, i = 0, count;
    scanf("%d", &n);
    a = malloc(sizeof(int) * n);
    while (i < n) {
        scanf("%d", &a[i]);
        i++;
    }
    count = selectionSort(a, n);
    printArray(a, n);
    printf("%d\n", count);
    return 0;
}

int selectionSort(int *a, int n) {
    int i, j, minj, w, count = 0;
    for (i = 0; i < n; i++) {
        minj = i;
        for (j = i; j < n; j++) {
            if (a[j] < a[minj])
                minj = j;
        }
        if (a[i] != a[minj]) {
            count++;
            w = a[i];
            a[i] = a[minj];
            a[minj] = w;
        }
    }
    return count;
}

void printArray(int *a, int n) {
    int i = 0;
    while (i < n - 1) {
        printf("%d ", a[i]);
        i++;
    }
    printf("%d\n", a[i]);
}

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

int main () {
  int h,w;
  cin >> h >> w;
  vector<string>S(h);
  for (int i = 0; i < h; i++) {
    cin >> S.at(i);
  }
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; 
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (S.at(i).at(j) == '#') continue;
      else {
       int num = 0;
       for (int d = 0; d < 8; d++) {
         const int nx = i + dy[d];
         const int ny = j + dx[d];
         if (0 > nx || h <= nx || 0 > ny || w <= ny) continue;
         else if (S.at(nx).at(ny) == '#') num++;
       }
      S.at(i).at(j) = char(num + '0');
      }
    }
  }
  for (int i = 0; i < h; i++) {
    cout << S.at(i) << endl;
  }
}

Measured memory_bytes: 256
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	var dp [100001]int

	for i := 1; i <= K; i++ {
		for _, v := range a {
			if i >= v {
				if dp[i-v] == 0 {
					dp[i] = 1
				}
			}
		}
	}

	ans := "First"
	if dp[K] == 0 {
		ans = "Second"
	}

	out(ans)
}

/*
var dp [100001][2]int

func loop(k, j int, a []int) int {
	if dp[k][j] != -1 {
		return dp[k][j]
	}
	ret := 0
	for _, v := range a {
		if k-v >= 0 {
			if loop(k-v, (j+1)%2, a) == 0 {
				ret = 1
			}
		}
	}
	dp[k][j] = ret
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	for i := 0; i <= 100000; i++ {
		dp[i][0] = -1
		dp[i][1] = -1
	}

	ret := loop(K, 0, a)

	ans := "First"
	if ret == 0 {
		ans = "Second"
	}

	out(ans)
}
*/


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  if(a.at(N/2-1)==a.at(N/2))cout<<0<<endl;
  else cout<<a.at(N/2)-a.at(N/2-1);
}

Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Edge{
        int cost, dest;
        Edge(int cost, int dest): cost(cost), dest(dest){ }
        ostream& operator >> (ostream& out){
            return out << '(' << cost << ':' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
        ll height = 0;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    // vector<Edge> edges;
    // Graph(int nn, int en = 10): nodes(nn){
    //     edges.reserve(en);
    // }
    // void addEdge(int from, int dest, ll cost = 1){
    //     nodes[from].outEdges.emplace_back(edges.size());
    //     edges.emplace_back(from, dest, limit);
    // }
    void addEdge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void addEdge2(int from, int dest, int cost = 1){
        addEdge(from, dest, cost);
        addEdge(dest, from, cost);
    }
    void dfs(int idx, ll height, int from = -1){
        nodes[idx].height = height;
        for(auto& e : nodes[idx].edges){
            if(e.dest == from){ continue; }
            dfs(e.dest, height + e.cost, idx);
        }
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        // scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        g.addEdge2(a, b, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    g.dfs(k, 0);
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        // scanf("%d %d", &x, &y);
        x--; y--;
        cout << g.nodes[x].height + g.nodes[y].height << '\n';
    }
}


Measured memory_bytes: 11392
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>

using namespace std;

int main(){
	int A;
	int B,C,D,P;

	cin>>A>>B>>C>>D>>P;
	int a=0,b=0;
	a=A*P;
	b=B;
	if(P>C)b+=D*(P-C);

	int max=a;
	if(a>b)max=b;
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(void) {
  
  int k;
  cin >> k;
  
  vector<long long> l;
  for (int i = 0; i < 9; i++) {
    l.push_back(i+1);
  }
  
  while (1) {
    
    if (k < l.size()) {
      printf("%lld\n", l[k-1]);
      return 0;
    }
    k -= l.size();
    
    vector<long long> old;
    swap(old, l);
    for (long long x : old) {
      for (int i = -1; i <= 1; i++) {
        int d = x%10 + i;
        if (d < 0 || d > 9) continue;
        long long nx = x*10 + d;
        l.push_back(nx);
      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 1712
#include<cstdio>
#include<iostream>
using namespace std;
int a[11],f;
int main(){
	for(int i=1;i<=3;i++){
		scanf("%d",&f);
		a[f]++;
	}
	if(a[5]==2&&a[7]==1)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll x, y, z;
  cin >> x >> y >> z;
  
  cout << (x - z) / (y + z) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm> 
#include<string>
#include<vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int n, k, m; vector<int> p(100010); 
vector<string> s(100100); vector<bool> c(100010); int a = 0; int b = 0;
vector<int> q(100010);
int main()
{
    fill(c.begin(), c.end(), true);
    fill(q.begin(), q.end(), -1);
    cin >> n >> m;
    rep(i, m) {
        cin >> p[i] >> s[i];
    }
    rep(j, m) {
        int z = p[j];
        if (s[j] == "WA" && c[p[j]]) {
            q[z] += 1;
        }
        else {
            if (c[p[j]]) {
                ++a;
                b += q[z] + 1;
                c[p[j]] = false;
            }
        }
    }
    cout << a << " "  << b << endl;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

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

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int w, h, n;
    cin >> w >> h >> n;
    bool str[w][h] = {0};
    rep(i, n)
    {
        int x, y, a;
        cin >> x >> y >> a;
        switch (a)
        {
        case 1:
            rep(j, x)
            {
                rep(k, h)
                {
                    str[j][k] = 1;
                }
            }
            break;

        case 2:
            for (int j = x; j < w; j++)
            {
                rep(k, h)
                {
                    str[j][k] = 1;
                }
            }
            break;

        case 3:
            rep(j, w)
            {
                rep(k, y)
                {
                    str[j][k] = 1;
                }
            }
            break;

        case 4:
            rep(j, w)
            {
                for (int k = y; k < h; k++)
                {
                    str[j][k] = 1;
                }
            }
            break;

        default:
            break;
        }
    }
    int count = 0;
    rep(i, w)
    {
        rep(j, h)
        {
            if (str[i][j] == 0)
            {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-05 18:56:19
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    int l[k], r[k];
    int x = 0;
    int h = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'o' && h == 0) {
            if (x < k) l[x++] = i;
            h = c;
        } else if (h > 0) {
            h--;
        }
    }

    x = k-1;
    h = 0;
    for (int i = n-1; i > -1; i--) {
        if (s[i] == 'o' && h == 0) {
            if (x >= 0) r[x--] = i;
            h = c;
        } else if (h > 0) {
            h--;
        }
    }

    for (int i = 0; i < k; i++) {
        if (l[i] == r[i]) cout << l[i] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3332
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int D = sc.nextInt();
        int N = sc.nextInt();

        int answer = 0;
        if (N == 100) { N += 1; }
        if (D == 0) { System.out.println(N); }
        else if (D == 1) { System.out.println(100 * N); }
        else if (D == 2) { System.out.println(10000 * N); }
    }
}


Measured memory_bytes: 23636
fun search(state: Array<BooleanArray>, memo: Array<IntArray>, position:Int = 0, prev: Int = 0): Int{
    if (state.size - position <= 1) return 0
    if (memo[position][prev] >= 0) return memo[position][prev]
    val coord = (0..1).flatMap{i -> (0..1).map{j -> Pair(i, j)}}
    if ((prev and 1) != 0 || prev == 4) {
        state[position][1] = false
    }
    if ((prev and 2) != 0 || prev == 4){
        state[position][2] = false
    }
    if (coord.all{state[position + it.first][it.second]} || coord.all{state[position + it.first][it.second + 2]}) {
        val current = (if (coord.all{state[position + it.first][it.second]}) 1 else 0) + (if (coord.all{state[position + it.first][it.second + 2]}) 2 else 0)
        memo[position][prev] = search(state, memo, position + 1, current) + if (current == 3) 2 else 1
    } else if (coord.all{state[position + it.first][it.second + 1]}){
        memo[position][prev] = maxOf(search(state, memo, position + 1, 4) + 1, search(state, memo, position + 1, 0))
    }else {
        memo[position][prev] = search(state, memo, position + 1, 0)
    }
    if ((prev and 1) != 0 || prev == 4) {
        state[position][1] = true
    }
    if ((prev and 2) != 0 || prev == 4){
        state[position][2] = true
    }
    return memo[position][prev]
}
fun main(args:Array<String>): Unit {
    val (h, n) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(h){BooleanArray(4){true}}
    val memo = Array(h){IntArray(5){-1}}
    repeat(n){
        val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        state[y][x] = false
    }
    for (i in h downTo 0 step 100) search(state, memo, i)
    println(search(state, memo))
}


Measured memory_bytes: 73264
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <cfloat>
#include <cmath>
#include <functional>
#include <forward_list>
#include <list>


#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define EPS 1e-9

#define MAX_N 

using namespace std;



class Edge {
public:
	int lv;
	int rv;
	double w;
	Edge(int lv, int rv, double w) {
		this->lv = lv;
		this->rv = rv;
		this->w = w;
	}

	Edge(int r, int l) : Edge(r, l, 1) {}
};

class Graph {
public:
	vector<double> vs;
	vector<vector<Edge> > es;

	Graph(vector<double>& vs, vector<vector<Edge> >& es) {
		this->vs = vs;
		this->es = es;
	}

	Graph(int n, vector<vector<Edge> >& es) {
		this->vs = vector<double>(n, 0);
		this->es = es;
	}

	Graph(int n, vector<Edge>& es, bool isBidirectional) {
		this->vs = vector<double>(n, 0);
		this->es = vector<vector<Edge> >(n, vector<Edge>());

		for (int i = 0;i < es.size();i++) {
			this->es[es[i].lv].push_back(es[i]);
		}

		if (isBidirectional) {
			for (int i = 0;i < es.size();i++) {
				this->es[es[i].rv].push_back(Edge(es[i].rv, es[i].lv, es[i].w));
			}
		}
	}

	Graph(int n) {
		this->vs = vector<double>(n, 0);
		this->es = vector<vector<Edge> >();
	}

};


class Main {
public:

	void preprocessRec(Graph& g, int root) {
		vector<Edge> es;
		for (auto it = g.es[root].begin();it != g.es[root].end();++it) {
			if (it->rv != root) {
				es.push_back(*it);
			}
		}

		g.es[root] = es;

		for (auto it = g.es[root].begin();it != g.es[root].end();++it) {
			preprocessRec(g, it->rv);
		}
	}

	void preprocess(Graph& g) {
		preprocessRec(g, 0);
	}

	void pairing(Graph& g, vector<bool>& paired, int root, int parent) {
		if (g.es.size()==1) {
			return;
		} else {
			for (auto it = g.es[root].begin();it != g.es[root].end();++it) {
				if (it->rv != parent) {
					pairing(g, paired, it->rv, root);
				}
			}

			for (auto it = g.es[root].begin();it != g.es[root].end();++it) {
				if (it->rv != parent && !paired[it->rv]) {
					paired[root] = true;
					paired[it->rv] = true;
					break;
				}
			}
			return;
		}
	}

	bool firstWins(Graph& tree) {
		vector<bool> paired(tree.vs.size(), false);
		//preprocess(tree);
		pairing(tree, paired, 0, -1);

		rep(i, paired.size()) {
			if (!paired[i]) {
				return true;
			}
		}
		return false;
	}
};

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

	vector<Edge> es;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		int s = min(a, b);
		int l = max(a, b);
		es.push_back(Edge(s, l));
	}
	Graph g(n, es, true);

	string ans = main.firstWins(g) ? "First" : "Second";
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10224
N=input()
T,A=map(int, raw_input().split())
H=map(int, raw_input().split())

T2=[]
for x in H:
	T2.append(T-x*0.006)


ans=""
diff=10**8
for idx,x in enumerate(T2):
	t=abs(A-x)
	if t<diff:
		diff=t
		ans=idx+1

print ans


Measured memory_bytes: 29164
# -*- coding: utf-8 -*-
"""
C - X: Yet Another Die Game
https://atcoder.jp/contests/arc068/tasks/arc068_a

"""
import sys


def solve(x):
    q, r = divmod(x, 11)
    ans = q * 2
    if r:
        ans += 1 if r <= 6 else 2
    return ans


def main(args):
    x = int(input())
    ans = solve(x)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
/***
 @ Author       : RobsonChen
 @ Date         : 2020-09-20 19:35:23
 @ LastEditTime : 2020-09-20 22:40:03
 @ Got AC       : Σ(っ °Д °;)っ
*/
#include <bits/stdc++.h>

using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 998244353;
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define FW freopen("data2.txt", "w", stdout);

//快速读入输出，只适用于整数，使用时流同步打开，C语言不准关流
// getchar()<<cin(关流)<<scanf()<<cin
template <class T>
inline bool Read(T& ret)
{
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF)
        return 0;
    while (c != '-' && (c < '0' || c > '9'))
        c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
        ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//输出只能用于整数
template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}

void slove(int qnum)
{
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(max(a * c, b * d), a * d), b * c);
}

int main()
{
    int qnum = 1;
    // cin >> num;
    for (int i = 1; i <= qnum; ++i) {
        slove(i);
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 3596
function main(input) {
    var n = input[0]-0;
    var ans = 0;
    for(var i=~~Math.sqrt(n);i>0;i--){
        if(n%i==0){ ans = (~~Math.log10(n/i))+1; break;}
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int d[310][310], d2[310][310];
    rep(i, N) {
        rep(j, N) {
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    rep(i, N) {
        rep(j, N) {
            cin >> d[i][j];
        }
    }
    rep(i, N) rep(j, N) d2[i][j] = d[i][j];
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    rep(i, N) {
        rep(j, N) {
            if(d[i][j] != d2[i][j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    int sum = 0;
    rep(i, N) rep(j, N) d2[i][j] = d[i][j];
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                if(i == k || j == k) continue;
                if(d[i][j] == d[i][k] + d[k][j]) d2[i][j] = 0;
            }
        }
    }
    rep(i, N) rep(j, N) sum += d2[i][j];
    cout << sum / 2 << endl;



    return 0;
}


Measured memory_bytes: 5080
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a, b = readmi()

if 9 >= a >= 1 and 9 >= b >= 1:
    print(a * b)
else:
    print(-1)


Measured memory_bytes: 7880
N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

xyh = [[int(j) for j in input().split()] for i in range(N)]

div = 0

for Cx in range(101):
    for Cy in range(101):
        for i in range(N):

            xi, yi, hi = xyh[i]

            if 0 < hi:
                h = abs(xi - Cx) + abs(yi - Cy) + hi
                if div in [0, 2]:
                    H = h
                    div = 1
                else:
                    if (H != h):
                        div = 2
                        break

        if div == 2:
            continue

        for i in range(N):
            xi, yi, hi = xyh[i]

            if 0 == hi:
                h = abs(xi - Cx) + abs(yi - Cy)
                if h < H:
                    div = 2
                    break

        if div == 2:
            continue

        print(Cx, Cy, H)
        break

    if div == 1:
        break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int r;
    cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}

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

int main()
{
  int n;
  std::cin >> n;
  const int64_t mod = 1000000007;
  int64_t ans = 1;
  for (int i = 1; i <= n; ++i)
  {
    ans *= i;
    ans %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main(void) {
	int n;
	scanf("%d", &n);
	int m;
	scanf("%d", &m);
	int a[m];
	int b[m];
	int mina = 100000;
	int minb = 100000;
	int maxa = 0;
	int count = 0;
	for (int i = 0; i < m; i++) {
		scanf("%d", &a[i]);
		scanf("%d", &b[i]);
		if (mina > a[i]) {
			mina = a[i];
		}
		if (maxa < a[i]) {
			maxa = a[i];
		}
		if (minb > b[i]) {
			minb = b[i];
		}
	}
	while (mina <= maxa) {
		int cut = minb - 1;
		mina = 100000;
		minb = 100000;
		for (int i = 0; i < m; i++) {
			if (cut < a[i]) {
				if (mina > a[i]) {
					mina = a[i];
				}
				if (minb > b[i]) {
					minb = b[i];
				}
			}
		}
		count++;
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define endl "\n"

using namespace std;

string s;

int main(){

    cin >> s;

    if(s[0] == s[1]){
        cout << "Bad";
    } else if (s[1] == s[2]){
        cout << "Bad";
    } else if (s[2] == s[3]){
        cout << "Bad";
    } else {
        cout << "Good";
    }

}

//g++ -std=c++14 comp.cpp; ./a.exe


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef map<int, int> MI;
typedef set<int> SI;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl

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; }

char in[120];
pair<pair<string, int>, int> p[110];

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

    int a; scanf("%d", &a);
    rep(i, a) {
        int t; scanf("%s%d", in, &t);
        string tmp = in;
        p[i] = make_pair(make_pair(in, -t), i);
    }
    sort(p, p+a);
    rep(i, a) printf("%d\n", p[i].second+1);
}

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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int main() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vi l(Q), r(Q);
    REP(i, Q) {
        cin >> l[i], cin >> r[i];
        l[i]--;
    }

    vi c(N+1, 0);
    vi b(N+1, 0);
    REP(i, N+1) {
        if (i >= 2 && S[i-2] == 'A' && S[i-1] == 'C') {
            c[i] = c[i-1] + 1;
        } else {
            c[i] = c[i-1];
        }
        if (i <= N-2 && S[i-1] == 'A' && S[i] == 'C') {
            b[i] = 1;
        }
    }

    REP(i, Q) {
        int ans = c[r[i]] - c[l[i]] - b[l[i]];
        cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tp, T)
	{
		//cout << "Case #" << tp << ": ";
		string s, t;
		cin >> s >> t;
		int n = s.length();
		int cnt = 0;
		FOR(i, n){
			if(s[i] != t[i]) cnt++;
		}
		cout << cnt;
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3820
str_S = input()

int_a = [0]
cnt = 0

for i in range(len(str_S)):
	if str_S[i] == "<":
		if cnt != 0:
			int_a[i - cnt] = max(int_a[i - cnt], cnt)
			for j in range(cnt):
				int_a[i - j] = j

		int_a.append(int_a[i] + 1)
		cnt = 0
	
	else:
		if i == len(str_S) -1 :
			if int_a[i] == 0:
				int_a[i - cnt] = max(int_a[i - cnt], cnt+1)
				for j in range(cnt):
					int_a[i - j] = cnt - j
		else:
			int_a.append(0)
			cnt += 1		



ans = 0

for k in range(len(int_a)):
	ans += int_a[k]

print(ans)

Measured memory_bytes: 25244
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int N,A;
    while (cin >> N >> A) {
        while (N >= 500)
            N -= 500;
        if (A >= N)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
var s,t:String;
    i,x:longint;
 
begin
  readln(s);
  if s[length(s)]<>'A' then s:=s+'A';
  t:='AKIHABARA';
  x:=1;
  for i:=1 to length(s) do
  begin
    if t[x]=s[i] then inc(x) else
    begin
      if (t[x]='A')and(t[x+1]=s[i]) then inc(x,2) else
      begin
        writeln('NO');
        exit;
      end;
    end;
    if (i=length(s))and(x=length(t)+1) then
    begin
      writeln('YES');
      exit;
    end;
  end;
  writeln('NO');
end.

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

typedef long long ll;
int main(){
    int N,M;
    cin >> N >> M;
    int N_min=1;
    int N_max=N;
    for(int i=0;i<M;i++){
        int l,r;
        cin >> l >> r;
        N_min=max(N_min,l);
        N_max=min(N_max,r);
    }
    if(N_max>=N_min){
        cout << N_max-N_min+1 <<endl;
    }else{
        cout << 0 << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
    int N,M;
    cin >> N >> M;
    string data;
    data += '1';
    for(int i =0; i < N-1; i++){
        data += '0';
    }

    if(N == 1){
        data[0] = '0';
    }
    vector<int> insert(N,0);
    for(int i =0; i < M; i++){
        int s, c;
        cin >> s >> c;

        if(s == 1 && c == 0 && N != 1){
            cout << -1 << endl;
            return 0;
        }else if(insert[s-1] == 0 || data[s-1] == (char)('0' + c)){
            data[s-1] = (char)('0' + c);
            insert[s-1] = 1;
        }else{
            cout << -1 << endl;
            return 0;
        }
        //cout << data <<endl;

    }
    cout << data <<endl;
}

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

inline bool is_happy(char cur,char lat)
{
	if (cur != '\0' && cur == lat)
		return true;
	else
		return false;
}

int main()
{
	int n, k, sum_happy = 0;
	string str;
	cin >> n >> k >> str;
	str.push_back('\0');
	for (int i = 0, j = 1; str[i] != '\0'; ++i, ++j)
		if (is_happy(str[i], str[j]))
			sum_happy++;
	cout << min(sum_happy + 2 * k, n - 1) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
	string s, t;
	int ans = 0;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3548
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int A ,B;
  cin >> A >> B;
  cout << (A-1) * (B-1) << endl;
  return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
ans = 0
SQRT = int(n ** 0.5)
for m in range(1,int(n ** 0.5) + 1):
    ans += m * (m + int(n/m)) * (int(n/m) + 1 - m)
ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6
print(ans)


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int h, w, D;
    cin >> h >> w >> D;
    vector< pair<int ,int> > m(h * w + 1);
    int a;
    rep (i, h)
    {
        rep (j, w)
        {
            cin >> a;
            m[a] = make_pair(i, j);
        }
    }

    vector< vs32 > d(h, vs32(w));
    rep (i, D)
    {
        int sx = m[h * w - i].second;
        int sy = m[h * w - i].first;
        d[sy][sx] = 0;
        for (int j = h * w - i - D; j > 0; j -= D)
        {
            int tx = m[j].second;
            int ty = m[j].first;
            d[ty][tx] = d[sy][sx] + abs(sx - tx) + abs(sy - ty);
            sx = tx;
            sy = ty;
        }
    }

    int q;
    cin >> q;
    int l, r;
    rep (i, q)
    {
        cin >> l >> r;
        int sx = m[l].second;
        int sy = m[l].first;
        int tx = m[r].second;
        int ty = m[r].first;
        cout << d[sy][sx] - d[ty][tx] << "\n";
    }

    return 0;
}



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

    int a,b,c,d;
    l1 e,f,g,h;
    string k;
    cin>>k;

    if(k == "ABC"){
        cout<<"ARC";
    }else{
        cout<<"ABC";
    }

    return 0;
}

Measured memory_bytes: 3596
n = int(input())
li = [list(str(input())) for i in range(n)]
#print(li)
for i in range(n):
    li[i].sort()
#print(li)
li.sort()
# print(li)
now = 0
count = 0
res = 0
for i in range(1,n):
    if li[now] == li[i] and i == n-1:
        count += 1
        res += count*(count+1)/2
    elif li[now] == li[i]:
        count += 1
    else:
        now = i
        res += count*(count+1)/2
        count = 0

print(int(res))

Measured memory_bytes: 24652
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,k;
	cin>>n>>k;
	vl h(n);
	rep(i,n)cin>>h[i];
	sort(all(h));
	ll ans=INF;
	rep(i,n-k+1){
	    ans=min(ans,h[i+k-1]-h[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
program b1

 implicit none

 integer :: a,b,c,d,i,x,y

 read*,a,b,c,d

 do i=1,1000 
   x=c-b
   if(x<=0) print*,"Yes"
   if(x<=0) exit
   y=a-d 
   if(y<=0) print*,"No"
   if(y<=0) exit
   c=x
   a=y
 end do
 

end program b1

Measured memory_bytes: 2832
#include<stdio.h>
#include<math.h>
int main()
{
    int s;
    double a[1000],b=0;
  scanf("%d",&s);
  for(int i=1;i<=s;i++){
      scanf("%lf",&a[i]);
  }
for(int i=1;i<=s;i++){
    b+=1/a[i];
}
printf("%lf",1/b);

return 0;
}

Measured memory_bytes: 128
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <tuple>
#include <map>

int main() {
  size_t n;
  intmax_t k;
  scanf("%zu %jd", &n, &k);

  std::vector<intmax_t> a(n);
  for (auto& ai: a) scanf("%jd", &ai);

  std::sort(a.begin(), a.end());

  auto f = [&](intmax_t x) -> bool {
    intmax_t k0 = 0;
    // fprintf(stderr, "x: %jd\n", x);
    // 積が x 以下のペアはいくつ？
    for (size_t i = 0; i+1 < n; ++i) {
      if (a[i] == 0) {
        if (x >= 0) k0 += n-i-1;
        // fprintf(stderr, "zero, += %jd\n", intmax_t(n-i-1));
        continue;
      }

      if (a[i] < 0) {
        size_t lb = i;
        size_t ub = n;
        while (ub-lb > 1) {
          size_t mid = (lb+ub) >> 1;
          // fprintf(stderr, "%jd ([%zu]) * %jd ([%zu]): %jd\n", a[i], i, a[mid], mid, a[i]*a[mid]);
          ((a[i] * a[mid] > x)? lb: ub) = mid;
        }
        // fprintf(stderr, "lb|ub: %zu, %zu\n", lb, ub);
        // fprintf(stderr, "neg: += %jd\n", intmax_t(n-ub));
        k0 += n - ub;
      } else {
        size_t lb = i;
        size_t ub = n;
        while (ub-lb > 1) {
          size_t mid = (lb+ub) >> 1;
          ((a[i] * a[mid] <= x)? lb: ub) = mid;
        }
        // fprintf(stderr, "lb|ub: %zu, %zu\n", lb, ub);
        // fprintf(stderr, "pos: += %jd\n", intmax_t(ub-i-1));
        k0 += ub - i - 1;
      }
    }
    // fprintf(stderr, "k0: %jd\n\n", k0);
    return k0 <= k;
  };

  intmax_t lb = -1e18-1;
  intmax_t ub = 1e18+1;
  --k;
  while (ub-lb > 1) {
    intmax_t mid = (lb+ub) >> 1;
    (f(mid)? lb: ub) = mid;
  }
  printf("%jd\n", ub);
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int r,d,x;cin>>r>>d>>x;
    VLL y(10);
    y[0]=r*x-d;cout<<y[0]<<endl;
    rep(i,9){
        y[i+1]=r*y[i]-d;
        cout<<y[i+1]<<endl;
    }
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

N,M = map(int,input().split())
u = UnionFind(N)
for _ in range(M):
    a,b = [int(i)-1 for i in input().split()]
    u.union(a,b)

print(max([u.size(i) for i in range(N)]))

Measured memory_bytes: 22352
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<vector<ll>> matrix;

constexpr ll MOD = 1e9 + 7;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<matrix> doubling(70, matrix(n, vector<ll>(n)));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> doubling[0][i][j];
        }
    }

    for (int t = 1; t < 70; t++) {
        for (int from = 0; from < n; from++) {
            for (int mid = 0; mid < n; mid++) {
                for (int to = 0; to < n; to++) {
                    doubling[t][from][to] += doubling[t - 1][from][mid] * doubling[t - 1][mid][to];
                    doubling[t][from][to] %= MOD;
                }
            }
        }
    }

    vector<ll> ret(n, 1);
    for (int t = 0; t < 70; t++) {
        if (k & 1) {
            vector<ll> after(n);
            for (int from = 0; from < n; from++) {
                for (int to = 0; to < n; to++) {
                    after[to] += ret[from] * doubling[t][from][to];
                    after[to] %= MOD;
                }
            }
            ret = after;
        }
        k >>= 1;
    }

    ll ans = 0;
    for (auto x:ret)ans += x, ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(3, len(S_str) + 1):
        bfs(i, '')
    print(len(results))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()


Measured memory_bytes: 44632
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	vector<ll>a(n),sum(n-1);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n - 1) {
		sum[i] =(a[i] + a[i + 1])-x;

	}
	ll count = 0;
	ll tmp = 0;
	ll zero = 0;
	rep(i, n - 1) {
		count += max(sum[i] - tmp,zero);
		if (sum[i] - tmp > 0) {
			tmp = min(sum[i] - tmp,a[i+1]);
		}
		else {
			tmp = 0;
		}
		//cout << count << endl;
	}
	cout << count << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <utility>
#define ll long long
using namespace std;
int a[2010],c[2020];
vector<int> b,ans;
int main() {
    int n;
    ll sum=0;
    cin>>n;
    for(int k,i=0;i<n;i++){
        cin>>k;
        sum+=k;
    }
    cout<<sum-n;
}



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


int main() {
	string s;
	cin >> s;
	vector<int> counter(26,0);

	for (auto i = 0; i < s.size(); i++) {
		int idx = int(s.at(i)-'a');
		counter.at(idx) += 1;
	}

	for (auto i = 0; i < counter.size(); i++) {
		if (counter.at(i) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if( n>=s.size() )
        cout<< s <<endl;
     else
    {
        for( ll i =0 ; i < n ; i++ )
        {
            cout << s[i];
        }
        cout << "..." <<endl;
    }
}



Measured memory_bytes: 3620
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
cnt = 0

for i in range(n):
    d1, d2 = d[i]
    if d1 == d2:
        cnt += 1
        if cnt == 3:
            print("Yes")
            exit(0)
    else:
        cnt = 0

print("No")

Measured memory_bytes: 9132
#include <iostream>
#define rep(i,q) for(int i = 0; q > i; i++)
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  int x[N];
  int sum = 0;
  rep(i,N) cin >> x[i];
  rep(i,N) sum += (x[i] > K - x[i] ? K - x[i] : x[i]);
  cout << sum * 2 << endl;
  return 0;
}

Measured memory_bytes: 256