akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;


typedef long long       ll;
struct edge { ll to; ll cost; };
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX numeric_limits<ll>::max()
#define INT_MAX numeric_limits<int>::max()
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}



int main()
{
	int N, K;
	cin >> N >> K;
	vll h(N);
	cin >> h;

	sortall(h);

	ll ans = LLONG_MAX;

	rep(i, N) {
		if (i + K - 1 < N) {
			ans = min(ans, h[i + K - 1] - h[i]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[103];
    while(scanf("%s",&s)!=EOF){

          int i,j,l=strlen(s)-1,cont=0;
    for(i=0,j=l;j>=i;i++,j--){
        if(s[i]!=s[j]){
            cont++;
        }
    }
    printf("%d\n",cont);




          }



    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    private void rightTriangle() {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int e = sc.nextInt();
            int f = sc.nextInt();
            float x = (float)(c * e - b * f) / (a * e - b * d);
            float y = (float)(c * d - a * f) / (b * d - a * e);
            System.out.println(String.format("%.3f %.3f",
                                             x == 0 ? 0 : x ,
                                             y == 0 ? 0 : y));
        }
    }

    public static void main(String[] args) {
        (new Main()).rightTriangle();
    }
}

Measured memory_bytes: 12000
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a=II()
    print(a**3+a**2+a)

main()

Measured memory_bytes: 9188
#include <stdio.h>
int main (){
  int x,y;
  for(;;){
  scanf("%d%d", &x,&y);
  if (x==0&&y==0) break;
  if ( x > y){
  printf("%d %d\n", y, x);
  }else{
    printf("%d %d\n", x, y);
  }
  }
  return 0;
}



Measured memory_bytes: 2032
l,r=map(int,input().split())
if r-l>=2018:
  print(0)
else:
  m=2019
  l=l%m
  r=r%m
  if r>l:
    x=m
    for i in range(l,r):
      for j in range(i+1,r+1):
        x=min(x,(i*j)%m)
    print(x)
  else:
    print(0)

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> ans = new ArrayList<Integer>();
		char ch[] = new char[1000];
		int len, sum;
		String str;
		
		while(true){
			str = br.readLine();
			if(str.equals("0")){
				break;
			}
			
			sum = 0;
			len = str.length();
			ch = str.toCharArray();
			
			for(char c : ch){
				sum += Character.digit(c, 10);
			}
			
			ans.add(sum);
		}
		
		for(int i : ans){
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 24304
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MAX (ll(1e6)+7)
#define MOD (ll(1e9)+7)
#define INF (ll(1e18)+7)

#define elif else if
#define def inline auto
#define for(a,b) for(ll a=0;a<(b);++a)
#define array_size(a) ll(sizeof(a)/sizeof(a[0]))
#define ios_boost cin.tie(0);ios::sync_with_stdio(false)
#define digit(a) to_string(a).length()
#define lcm(a,b) a*b/gcd(a,b)
char N='\n',S=' ';
def gcd(ll a,ll b){ll c;while(a){c=a;a=b%a;b=c;}return b;}

ll check[100+100];
int main(){
	ios_boost;
	ll H,W;
	cin>>H>>W;
	string A[H];
	for(i,H)cin>>A[i];
	for(i,H){
		for(j,W){
			if(A[i][j]=='#')goto rapid;
		}
		check[i]=-1;
		rapid:;
	}
	for(i,W){
		for(j,H){
			if(A[j][i]=='#')goto express;
		}
		check[H+i]=-1;
		express:;
	}
	for(i,H){
		for(j,W){
			if(check[i]!=-1 && check[H+j]!=-1){
				cout<<A[i][j];
			}
		}
		if(check[i]!=-1)cout<<"\n";
	}
}

//for compilation: g++ -o _ _.cpp -std=c++14 (or 17)
//
//for fastening: g++ -O2 -o _ _.cpp -std=c++14 (or 17)
//for fastening: g++ -O3 -mtune=native -march=native -o _ _.cpp -std=c++14 (or 17)


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

struct S{
    int l;
    int r;
    int c;
};

constexpr ll Inf = 1e18;

struct BIT{
    const int n;
    vector<ll> a;
    BIT(int n) : n(n), a(vector<ll>(n+1, Inf)){}
    // void add(int i, int x){ if(i <= n) a[i] += x, add(i + (i & -i), x); }
    // ll sum(int i){ return (i == 0) ? 0ll : a[i] + sum(i - (i & -i)); }
    void minim(int ub, ll val){
        for(int i = ub; i > 0; i -= i & -i) Mini(a[i], val);
    }
    ll get(int x){
        ll ret = Inf;
        for(int i = x; i <= n; i += i & -i) Mini(ret, a[i]);
        return ret;
    }
};

int main(void){
    Cin(int, n, m);
    vc<S> s(m);
    For(i, m){
        cin >> s[i].l >> s[i].r >> s[i].c;
    }
    sort(Range(s), [](auto &a, auto &b){ return a.l < b.l; });
    
    BIT d(n);
    d.a[1] = 0;
    
    For(i, m){
        // s[i].r 以前にはコスト min d[s[i].l 以降] + s[i].c で行ける
        // Cout(s[i].l, " ", s[i].r);
        d.minim(s[i].r, d.get(s[i].l) + s[i].c);
    }
    // Couts(d.a);
    Cout((d.a[n] == Inf) ? -1 : d.a[n]);
}




Measured memory_bytes: 2176
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	grid := make([][]byte, h)
	color := make([][]int, h)
	sum := 0
	for i := 0; i < h; i++ {
		grid[i] = make([]byte, w)
		color[i] = make([]int, w)
		s := getNextString(scanner)
		for ii := 0; ii < w; ii++ {
			grid[i][ii] = s[ii]
			if s[ii] == '.' {
				sum++
			}
		}
	}

	ans := -1

	q := make([]*Point, 0)
	q = append(q, &Point{
		c: 0,
		x: 0,
		y: 0,
	})
	dy := []int{0, 1, 0, -1}
	dx := []int{1, 0, -1, 0}
	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		if p.x == w-1 && p.y == h-1 {
			ans = sum - p.c - 1
			break
		}
		color[p.y][p.x] = 2
		for i := 0; i < 4; i++ {
			if p.x+dx[i] < 0 {
				continue
			}
			if p.x+dx[i] >= w {
				continue
			}
			if p.y+dy[i] < 0 {
				continue
			}
			if p.y+dy[i] >= h {
				continue
			}
			if color[p.y+dy[i]][p.x+dx[i]] != 0 {
				continue
			}
			if grid[p.y+dy[i]][p.x+dx[i]] == '#' {
				continue
			}
			q = append(q, &Point{
				c: p.c + 1,
				x: p.x + dx[i],
				y: p.y + dy[i],
			})
			color[p.y+dy[i]][p.x+dx[i]] = 1
		}

	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}

// Point ...
type Point struct {
	c, x, y int
}


Measured memory_bytes: 896
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = String.valueOf(n);
		
		int sum = 0;
		String sub = new String();
		for (int i = 0; i < s.length(); i++) {
			sub = s.substring(i, i + 1);
			sum += Integer.valueOf(sub);
		}
		
		if (n % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-

y,m,d = map(int,input().split("/"))
if y < 2019:
    print("Heisei")
    print("Heisei")
elif y == 2019 and m < 4:
    print("Heisei")
elif y == 2019 and m == 4 and d <= 30:
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 3060
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = input()
    ans, i, j = 0, 0, 0
    while i < len(s):
        if s[i] == '<':
            j = 0
            while i<len(s) and s[i] == '<':
                ans += j
                j += 1
                i += 1
        else:
            k = 1
            while i<len(s) and s[i] == '>':
                ans += k
                k += 1
                i += 1
            if j > k - 1:
                ans = ans - (k - 1) + j
    if s[-1] == '<':
        ans += j
    print(ans)
                
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 9976
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for idx, num in enumerate(A):
    a.append(a[idx] + num)
for idx, num in enumerate(B):
    b.append(b[idx] + num)

ans = 0
j = M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47444
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.size()==2){
    cout << s << endl;
  }else if(s.size()==3){
    for(int i=s.size()-1;i>=0;i--){
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N,Y = map(int,input().split())
flag = False
for x in range(N+1):
    t_t = x
    for y in range(N+1 - x):
        f_t = y
        o_t = (N -x -y)
        if Y == 10000*t_t + 5000*f_t + 1000*o_t:
            flag = True
            break
    if flag == True:
        break
if flag == True:
    print(t_t,f_t,o_t)
else :
    print(-1,-1,-1)

Measured memory_bytes: 3064
//
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <numeric>
#include <functional>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <complex>

using namespace std;

#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<int, int> pii;

const double eps = 1e-10;
const double pi = acos(-1.0);
const int di[][2] = {{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};

int main(){

	int n, a, tmp, sum=0;
	cin >> n;
	vector<int> v,c;
	rep(i,n){
		cin >> a;
		v.push_back(a);
	}
	rep(i,n){
		cin >> a;
		c.push_back(a);
	}
	rep(i,n){
		tmp = v[i] - c[i];
		if(tmp > 0) sum += tmp;
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int L;
	cin >> L;
	double div3 = L / 3.;
	double ans = pow(div3, 3);
	printf("%.15f\n", ans);
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main()
{
  long double a, b, c;
  scanf("%Lf%Lf%Lf", &a, &b, &c);
  if(c <= (a + b)){
    printf("No\n");
    return 0;
  }
  if(4 * a * b < c * c + (a + b) * (a + b) - 2 * c * (a + b)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, l = rm()
li = np.arange(n) + l
if l > 0:
  print(sum(li[1:]))
elif l <= -n:
  print(sum(li[:-1]))
else:
  print(sum(li))









Measured memory_bytes: 27140
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int n, a, b, x = 0, y = 0, z = 0, p;
	cin >> n >> a >> b;
	for (int i = 0; i < n; ++i) {
		cin >> p;
		if (p <= a) {
			++x;
		} else if (p <= b) {
			++y;
		} else {
			++z;
		}
	}
	int ans = min({ x, y, z });
	cout << ans << endl;
	return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 M = 1000000007;
signed main() {
  i64 N, M;
  cin >> N >> M;
  priority_queue<i64> que;
  REP(_, N) {
    i64 a;
    cin >> a;
    que.push(a);
  }
  REP(_, M) {
    i64 a = que.top();
    que.pop();
    que.push(a / 2);
  }
  i64 s = 0;
  while (!que.empty()) {
    s += que.top();
    que.pop();
  }
  cout << s << endl;
}


Measured memory_bytes: 1400
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int n = scanInt();
		if ((n & -n) == n) {
			out.print("No");
			return;
		}
		out.println("Yes");
		int m = n + (n & 1) - 1;
		for (int i = 2; i <= m; i++) {
			out.println("1 " + i);
			out.println(i + " " + (n + (i ^ 1)));
		}
		out.println((n + 1) + " " + (n + 3));
		if (n != m) {
			int x = Integer.lowestOneBit(n) + 1, y = n - x + 1;
			out.println(n + " " + x);
			out.println((2 * n) + " " + y);
		}
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 42892
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  int n;
  ll aback=0,btop=0,katu=0,pa=0,ans=0;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s[i];

  for(int i=0;i<n;i++){
    if(s[i][0] == 'B' && s[i][s[i].length()-1] == 'A')katu++;
    else if(s[i][0] == 'B')btop++;
    else if(s[i][s[i].length()-1] == 'A')aback++;
    for(int j=0;j<s[i].length()-1;j++){
      if(s[i][j] == 'A' && s[i][j+1] == 'B')pa++;
    }
  }
  if(katu>=1){
  ans+=katu-1;
  if(btop>=1){
    ans++;btop--;
  }
  if(aback>=1){
    ans++;aback--;
  }
  ans+=min(aback,btop);
  cout << ans+pa;
  return 0;
  }
  else{
    cout << pa+min(aback,btop);
    return 0;
  }
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int a[200000];
	rep(i, n) {
		cin >> a[i];
	}
	ll sum = 0;
	bool f = true;
	per(i, n) {
		if (a[i] > i) {
			f = false; break;
		}
		if (i == n - 1) {
			sum += (ll)a[i];
		}
		else {
			if (a[i+1]-a[i]>=2) {
				f = false; break;
			}
			else if (a[i + 1] <= a[i]) {
				sum += (ll)a[i];
			}
		}
	}
	if (f) {
		cout << sum << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
C = list(map(int, input().split()))
C.sort()
mod = 10**9+7

def power(a, n, mod):
    """
    a >= 1, n >= 0の場合のみに対応
    """
    if n == 0:
        return 1
    elif n == 1:
        return a % mod
    elif n % 2 == 0:
        num = power(a, n // 2, mod)
        return num ** 2 % mod
    elif n % 2 == 1:
        num = power(a, (n - 1) // 2, mod)
        return a * num ** 2 % mod

"""
ans = ¥Sum_{S, T} ¥Sum_i C_i * (S[i:] ¥xorSum T[i:])
    = ¥Sum_i C_i ¥Sum_{S, T} (S[i:] ¥xorSum T[i:])

¥Sum_{S, T} (S[i:] ¥xorSum T[i:])について考える。
添字iからN-1までの中にk箇所S[j] != T[j]なるjが存在したとすると、
この時C_iが足される回数は
    cmb(N-i-1, k-1) * 2^{N-i} * k * 4^i
これをkについて総和を取れば、C_iの足される回数は
    2^{N+i} * ¥Sum_{k=1}^{N-i} k * cmb(N-i-1, k-1)
        = 2^{N+i} * ¥Sum_{k=0}^{N-i-1} (k+1) * cmb(N-i-1, k)
        = 2^{N+i} * {¥Sum_{k=0}^{N-i-1} cmb(N-i-1, k) + (N-i-1) * ¥Sum_{k=1}^{N-i-1} cmb(N-i-2, k-1)}
        = 2^{N+i} * {2^{N-i-1} + (N-i-1) * ¥Sum_{k=0}^{N-i-2} cmb(N-i-2, k)}
        = 2^{N+i} * {2^{N-i-1} + (N-i-1) * 2^{N-i-2}}
        = 2^{2N-1} + (N-i-1) * 2^{2N-2}
        =4^{N-1} * (N-i+1)
"""
ans = 0
for i in range(N):
    ans += C[i] * (N - i + 1) * power(4, N - 1, mod)
    ans %= mod
print(ans)


Measured memory_bytes: 97996
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

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



signed main(){

	int a[5], k;
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

	if (a[4] - a[0] > k) { cout << ":(" << endl; return 0; }
	cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a,b,c;
  cin >> a>>b>>c;
  
  vector<int> iro = {a, b, c};
  sort(all(iro));
  
  int ans = 1;
  repo(i,3) {
    if (iro.at(i)!=iro.at(i-1)) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
A - Measure
https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_a

"""
import sys


def solve(S):
    return S if len(S) == 2 else S[::-1]


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


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

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
#define int long long

int MOD = 1000 * 1000 * 1000 + 7;

vector<vector<int> > mul(vector<vector<int> > a, vector<vector<int> > b) {
	int n = a.size();
	vector<vector<int> > ans(n, vector<int>(n, 0));
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			for (int k=0; k<n; k++) {
				ans[i][j] += (a[i][k] * b[k][j]);
				ans[i][j] %= MOD;
			}
		}
	}
	return ans;
}

int ex(vector<vector<int> > vc, int po) {
	int n = vc.size();
	vector<vector<int> > t;
	
	for (int i=0; i<60; i++) {
		if (po & (1ll << i)) {
			if (t.empty()) t = vc;
			else t = mul(t, vc);
		}
		vc = mul(vc, vc);
	}
	
	if (t.empty()) return 0;
	
	int x = 0;
	for (int i=0; i<n; i++) for (int j=0; j<n; j++) {
		x += t[i][j];
		x %= MOD;
	}
	
	return x;
	
}

int nex(vector<vector<int> > x, int po) {
	int n = x.size();
	vector<vector<int> > res = x;
	for (int i=1; i<po; i++) {
		res = mul(res, x);
	}
	int X = 0;
	for (int i=0; i<n; i++) for (int j=0; j<n; j++) X += res[i][j];
	return X;
}

signed main() {
	
	int n, m;
	cin >> n >> m;
	vector<vector<int> > vc(n, vector<int>(n));
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) cin >> vc[i][j];
	}
	
	cout << ex(vc, m) << endl;
	
}



Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 999999999

#define llong long long

#define pb(a) push_back(a)

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  int n=0;
  int l;
  vector<int> L;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;

  for(int i=0;i<2*n;i++){
    cin >>l;
    L.pb(l);;
  }
  VSORT(L);
  int ans = 0;
  for(int i=0;i<2*n;i+=2){
    ans += L[i];
  }

  printf("%d \n",ans);
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
t_list = gets.split.map(&:to_i)
M = gets.to_i
px_list = M.times.map { gets.split.map(&:to_i) }

sum = t_list.reduce(&:+)
px_list.each do |(p, x)|
  ans = sum + (x - t_list[p - 1])
  puts ans
end


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

int main() {
  int n,q;
  	cin>>n>>q;
  string S;
 	cin >>S;
	vector<int>vec(n);
  
  for(int i=1;i<n;i++){
    if(S.at(i)=='C'&&S.at(i-1)=='A'){
		vec[i]+=1+vec[i-1];
    }
    else{
        vec[i]+=vec[i-1];
  }
  }
    int l=0;
    int r=0;
  for(int j=0;j<q;j++){
	cin>>l>>r;
    cout<<vec[r-1]-vec[l-1]<<endl;
  }
}


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

int main() {
    int N,cnt;
    cin >> N;
    cnt=0;
    for (int i=0; i < N; i++) {
        string S;
        cin >> S;
        if (S == "Y") {
            cnt=1;
            break;
        }
    }
    if (cnt == 0) {
        cout << "Three" << endl;
    }
    else {
        cout << "Four" << endl;
    }
}


Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
rsp = [[R,'r'],[S,'s'],[P,'p']]
rsp.sort(key=lambda x:x[0], reverse=True)
dics = {'r':'s','s':'p','p':'r'}
out = ['0' for i in range(N)]
tot = 0
for i in range(3):
    for j in range(N):
        if j < K:
            if T[j] == dics[rsp[i][1]]:
                out[j] = rsp[i][1]
                tot += rsp[i][0]
        elif out[j-K] != rsp[i][1] and T[j] == dics[rsp[i][1]]:
            out[j] = rsp[i][1]
            tot += rsp[i][0]
print(tot)

Measured memory_bytes: 4212
/* Insert Sort(挿入ソート) */
/* N 個の要素を含む数列 A を昇順に並び替える挿入ソートのプログラム */
/* 入力: 入力の最初の行に、数列の長さを表す整数 N が与えられます。2 行目に、N 個の整数が空白区切りで与えられます。 */
/* 出力: 出力は N 行からなります。挿入ソートの各計算ステップでの途中結果を 1 行に出力してください。配列の要素は１つの空白で区切って出力してください。最後の要素の後の空白など、余計な空白や改行を含めると Presentation Error となりますので注意してください。 */

#include <stdio.h>

void insertionSort(int *,int);
void abc(int *,int);

int main()
{
  
  int i,N,A[1000];

  scanf("%d",&N);
    
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  abc(A,N);
  insertionSort(A,N);
    
  return 0;
}


void abc(int *A,int N)
{
  int i;
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}


void insertionSort(int *A,int N)
{
  
  int i,j,k;

  for(i=1;i<N;i++){
    k=A[i];
    j=i-1;
    
    while(j>=0&&A[j]>k){
      A[j+1]=A[j];
    j--;
    }
    A[j+1]=k;
    abc(A,N);
  }
}



Measured memory_bytes: 2148
N = int(input())
for n in range(N):
	str = input().split()
	list = []
	for i in str:
		list.append(int(i))
	b = []
	c = []
	ans = True

	for a in list:
		bLen = len(b)
		cLen = len(c)
		bLast = bLen - 1 if bLen > 0 else 0
		cLast = cLen - 1 if cLen > 0 else 0
		if bLen == 0 or b[bLast] < a:
			b.append(a)
			continue
		if b[bLast] > a:
			if cLen == 0 or c[cLast] < a:
				c.append(a)
				continue
			else:
				ans = False
				break
	print('YES' if ans is True else 'NO')

Measured memory_bytes: 7564
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10);

    var Str = N.toString();
    var ans = 0;

    // console.log(Str.length)

    for (var i = 0; i < Str.length; i++) {
        if (Str.charAt(i) === '2') {
            ans++;
        }
        // console.log(Str.charAt(i))
    }

    console.log(ans);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
int a[100100];
int ans;

int solve(){
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);
    if(a[0] != (n % 2 == 0)) return 0;
    int st = n % 2 == 0 ? 2 : 1;
    for(int i = n % 2, st = 2 - !(n % 2); i < n; i += 2, st += 2){
        if(a[i] == st && a[i + 1] == st) continue;
        else return 0;
    }
    
    ans = 1;
    for(int i = 0; i < n / 2; ++i){
        ans *= 2;
        ans %= mod;
    }
    return ans;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

int n;

map<int, vector<pair<int, int>>> uvw;
int col[100000];

void color(int i, int c)
{
    if (col[i] != -1) return;

    col[i] = c;

    for (auto vw : uvw[i])
    {
        color(vw.first, c ^ vw.second);
    }
}

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

    cin >> n;

    for (int i = 0; i < n - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        uvw[u - 1].insert(uvw[u - 1].end(), make_pair(v - 1, w % 2));
        uvw[v - 1].insert(uvw[v - 1].end(), make_pair(u - 1, w % 2));
    }

    for (int i = 0; i < n; i++)
    {
        col[i] = -1;
    }
    
    color(0, 0);

    for (int i = 0; i < n; i++)
    {
        cout << col[i] << "\n";
    }
    
    
    return 0;
}

Measured memory_bytes: 13312
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,c[505]={},s[505]={},f[505]={},ans;
  cin >> n;
  for(int i=0; i<n-1; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }
  for(int i=0; i<n; i++) {
    ans=0;
    for(int j=i; j<n-1; j++) {
      if(ans<=s[j]) {
        ans=s[j];
      }
      else {
        ans=((ans-1)/f[j]+1)*f[j];
      }
      ans+=c[j];
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();
        int a = 0;
        int b = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == '0') {
                a++;
            } else {
                b++;
            }
        }
        System.out.println(Math.min(a, b) * 2);
    }
}

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

public class Main {
	public static void main(String srgs[]) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try {
			int N = Integer.parseInt(reader.readLine());
			String[] str = reader.readLine().split(" ");
			int[] H = new int[N+1];
			H[0] = Integer.parseInt(str[0]);
			int j = 0;
			int tmpcount = 0;
			int maxcount = 0;
			for(int i=1;i<N+1;i++) {
				if(i==N) {
					H[i] = H[i-1] + 1;
				}else {
					H[i] = Integer.parseInt(str[i]);					
				}
				if(H[i]>H[i-1]) {
					tmpcount = i - j - 1;
					if(tmpcount > maxcount) {
						maxcount = tmpcount;
					}
					j = i;
				}
				
			}
									
			System.out.println(maxcount);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}


Measured memory_bytes: 46676
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

ans = len(set(A))
C = Counter(A)
Even = 0
for v in C.values():
    if v % 2 == 0:
        Even += 1

if Even % 2 == 1:
    ans -= 1

print(ans)


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

int main()
{
 int a1,b1,c1,d1,a2,b2,c2,d2,x,y;
 cin>>a1>>b1>>c1>>d1;
 cin>>a2>>b2>>c2>>d2;
 x=a1+b1+c1+d1;
 y=a2+b2+c2+d2;

 if(x>=y)cout<<x<<"\n";
 else cout<<y<<"\n";

 return 0;
}
 

Measured memory_bytes: 1164
#include <stdio.h>
#include <vector>

using namespace std;

static long long cnt = 0;
static vector<int> G;

static void insertionSort(int A[], int n, int g)
{
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;

        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }

        A[j + g] = v;
    }
}

static void shellSort(int A[], int n)
{
    for (int h = 1; h <= n;) {
        G.push_back(h);
        h = 3 * h + 1;
    }

    for (int i = (int)G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main()
{
    int n;
    int A[1000000];

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    shellSort(A, n);

    printf("%d\n", (int)G.size());
    for (int i = (int)G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if (i > 0) {
            printf(" ");
        }
    }
    printf("\n");

    printf("%lld\n", cnt);

    for (int i = 0; i < n; i++) {
        printf("%d\n", A[i]);
    }
    
    return 0;
}



Measured memory_bytes: 6652
from itertools import accumulate

N = int(input())

while N:
  al = [0]*86400
  for i in range(N):
    l,r = input().split()
    hh,mm,ss = map(int,l.split(":"))
    al[hh*3600+mm*60+ss] += 1
    hh,mm,ss = map(int,r.split(":"))
    al[hh*3600+mm*60+ss] -= 1
  print(max(accumulate(al)))
  N = int(input())


Measured memory_bytes: 6840
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		String s = sc.next();
		sc.close();
		int ans = 0;
		char prev = '1';
		int cnt[] = new int[n + 2 * k + 1];
		int j = 0;
		for(int i = 0; i < n; ++i) {
			if(s.charAt(i) == prev)cnt[j]++;
			else {
				prev = s.charAt(i);
				cnt[++j]++;
			}
		}
		int tmp = 0;
		for(int i = 0; i < 2 * k; ++i)
			tmp += cnt[i];
		for(int i = 2 * k; i < cnt.length; ++i) {
			tmp += cnt[i];
			if(i % 2 == 0)ans = Math.max(ans, tmp);
			tmp -= cnt[i - 2 * k];
		}
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 27500
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B, X,ans=0;
	cin >> A >> B >> X;
	int L = min(A, B * 2);
	int M = min(A, B);
	while (X>0) {
		if (X > 500) {
			ans += L;
			X -= 1000;
		}
		else {
			X -= 500;
			ans += M;
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 3216
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [x,y] <- getIntList
    let try a b = if b >= a then b - a else 10^10
    print $ minimum [try x y, try (-x) y + 1, try x (-y) + 1, try (-x) (-y) + 2]

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
long long n,dem,a[1000];
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int i=1; i<=n-2; i++)
        for(int j=i+1; j<=n-1; j++)
            for(int k=j+1; k<=n; k++)
                if((a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i])&&(a[i]+a[j]>a[k])&&(a[j]+a[k]>a[i])&&(a[i]+a[k]>a[j]))
                    dem++;
    cout<<dem;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
#include <complex>
using namespace std;
int main()
{
    long long m,n,i;
    cin>>m>>n;
    if((n/2)<=m)
    {
        cout<<n/2;
        system ("pause");
        return 0;
    }
    n-=2*m;
    cout<<m+(n/4);
    system ("pause"); 
    return 0;
}

Measured memory_bytes: 504
def resolve():
    a, b, c = map(int, input().split())
    k = int(input())
    for _ in range(k):
        if b <= a:
            b *= 2
        elif b > a and c <= b:
            c *= 2
    if a < b < c:
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main() {
  vector<vector<int>> c(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> c[i][j];
  int dif21 = c[1][0] - c[0][0], dif22 = c[1][1] - c[0][1],
      dif23 = c[1][2] - c[0][2];
  int dif31 = c[2][0] - c[0][0], dif32 = c[2][1] - c[0][1],
      dif33 = c[2][2] - c[0][2];
  if(dif21 == dif22 && dif22 == dif23 && dif31 == dif32 && dif32 == dif33)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll x, y; cin >> x >> y;
    ll count = 0;
    while (x <= y) {
        x *= 2;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n;
    ll d, x, y;
	cin >> n >> d;
    int ans = 0;
    rep(i,n) {
        cin >> x >> y;
        if (d*d >= x*x + y*y) ans++;
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3612
/*input
abracadabra
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll cnt[26];

int main()
{
	//IOS;
	string s;
	cin>>s;
	for(char c:s) cnt[c-'a']++;
	ll n=SZ(s);
	ll ans=n*(n-1)/2+1;
	REP(i,26) ans-=cnt[i]*(cnt[i]-1)/2;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main() {
  int lim;
  std::cin >> lim;  // lim <- N

  int ans = 0;
  for (int n = 1; n <= lim; n += 2) {
    int num_of_divisors = 0;
    for (int i = 1; i <= n; i++)
      if (n % i == 0) num_of_divisors++;

    if (num_of_divisors == 8) ans++;
  }

  std::cout << ans << std::endl;

  return 0;
}


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

int main() {
  int W, H;
  cin >> W >> H;
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if (W%2 == 0 && H%2 == 0 && x == W/2 && y == H/2) ans = 1;
  printf("%.10lf %d\n", (double)W*(double)H/2.0, ans);
}

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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
toInt :: (String -> Int)
toInt x = read x ::Int

getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y


range x y
  | x > y = [y..x]
  | otherwise = [x..y]
main :: IO ()
main = do
  a_c <- getInts
  if (filter (== (a_c !! 2)) (range (a_c !! 0) (a_c !! 1))) == [] then putStrLn "No"
        else putStrLn "Yes"


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#define MN 42

typedef long long ll;

ll s[MN][MN][MN], f[MN][MN][MN], g[MN][MN][MN][MN];
int a[MN][MN];

int main()
{
	int n; scanf("%d", &n); n *= 2;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) scanf("%1d", &a[i][j]);
	for(int len = 1; len <= n; len++)
		for(int l = 1; l + len - 1 <= n; l++)
		{
			int r = l + len - 1;
			if(l == r) f[l][r][l] = 1;
			for(int i = l; i <= r; i++)
			{
				for(int j = i + 1; j <= r; j++)
				{
					if(!g[l][i][j][r]) continue;
					for(int k = i + 1; k < j; k++)
						f[l][r][k] += f[i + 1][j - 1][k] * g[l][i][j][r];
				}
			}
			
			for(int k = l; k <= r; k++)
			{
				if(!f[l][r][k]) continue;
				for(int k2 = 1; k2 <= n; k2++)
					if(a[k2][k]) s[l][r][k2] += f[l][r][k];
			}
			
			for(int LEN = 1; LEN <= len; LEN++)
				for(int L = 1; L + LEN - 1 < l; L++)
				{
					int R = L + LEN - 1;
					for(int k = L; k <= R; k++)
						g[L][R][l][r] += f[L][R][k] * s[l][r][k];
				}
			
			for(int LEN = 1; LEN < len; LEN++)
				for(int L = r + 1; L + LEN - 1 <= n; L++)
				{
					int R = L + LEN - 1;
					for(int k = L; k <= R; k++)
						g[l][r][L][R] += f[L][R][k] * s[l][r][k];
				}
		}
	ll ans = 0;
	for(int k = 2; k <= n; k++) if(a[1][k]) ans += f[2][n][k];
	printf("%lld\n", ans);
}

Measured memory_bytes: 24320
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
l=make_divisors(n)
print(len(str(max(l[len(l)//2],l[len(l)//2-1]))))


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
string s,t;
int main()
{
    cin>>s>>t;
    if(s.size()>t.size()){cout<<"No";}
    else{
     for(int i=0;i<s.size();++i)if(s[i]!=t[i]){cout<<"No";return 0;}
      cout<<"Yes";
   }
   return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main(){
    while(true){
        int x,y;cin>>x>>y;
        if(x==0&&y==0)break;
        cout<<min(x,y)<<" "<<max(x,y)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
import numpy as np
n=int(input())
h=list(map(int,input().split()))
h.insert(0,0)
h.append(0)
p=max(h)
arr=np.array(h)
cnt=0
for i in range(p,0,-1):
    x=np.copy(arr)
    x[x!=i]=0
    x[x==i]=1
    temp=np.arange(len(x))
    temp[x>0]=0
    np.maximum.accumulate(temp,out=temp)
    left=temp
    x_reversed=x[::-1]
    temp=np.arange(len(x))
    temp[x_reversed>0]=0
    np.maximum.accumulate(temp,out=temp)
    right=len(x)-1-temp[::-1]
    y=right-left-1
    y[x==0]=0  
    z=np.nonzero(np.diff(np.nonzero(x==0)[0])-1)
    cnt+=len(z[0])
    arr=arr-x
print(cnt)

    
    

Measured memory_bytes: 12524