akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i
s = Array.new
ac = 0
wa = 0
tle = 0
re = 0
i = 0
for i in 1..n do
    r = gets.chomp.to_s
    i +=1
    case r
    when "AC" then
        ac +=1
    when "WA" then
        wa +=1
    when "TLE" then
        tle +=1
    when "RE" then
        re +=1
    end
end
printf("AC x %d\n",ac)
printf("WA x %d\n",wa)
printf("TLE x %d\n",tle)
printf("RE x %d\n",re)

Measured memory_bytes: 14364
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long MOD = (long) (Math.pow(10, 9) + 7);
        int n = sc.nextInt();
        long ans = 1;
        while (n-- > 0) {
            long a = sc.nextLong();
            ans = lcm(ans, a);
        }
        System.out.println(ans);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

    public static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }
}


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

using namespace std;

int main()
{
    long long X, Sum = 100, A = 100;
    cin >> X;

    for (int i = 1; i <= 1000000; i++)
    {
        A = Sum * 0.01;
        Sum += A;
        if (Sum >= X)
        {
            cout << i;
            break;
        }
    }
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}

constexpr int mod = 1e9 + 7;
template <class T> T modpow(T a, T b) {
    if (b == 0) return T(1);
    if (b % 2 == 0) {
        long long d = modpow(a, b / T(2));
        return (d * d) % mod;
    } else {
        return (a * modpow(a, b - 1) % mod );
    }
}
template<class T> T mod_nCr(T n, T r, T mod ) {
    T denom = 1;
    T numer = 1;
    for (T i = 1; i <= r; i++) numer = (numer * i) % mod;
    for (T i = n - r + 1; i <= n; i++) denom = (denom * i) % mod;
    return (denom * modpow(numer, mod - 2) % mod);
}
signed main(){
    int n,a,b; cin >> n >> a >> b;
    
    cout << ((( mod + modpow(2LL,n) - mod_nCr(n, a, mod)) % mod + mod) - mod_nCr(n, b, mod)) % mod - 1 << endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

N=input()
C=map(int, sys.stdin.readline().split())
C.sort()

mod=10**9+7
D=[]
d0=pow(2,N-1,mod)

#D：係数の配列の作成
for i in range(N):
    if i==0:
        D.append(d0)
    else:
        next=(2*D[-1]-d0)*pow(2,mod-2,mod)+d0
        D.append(next%mod)

#Ci*Diを最小にするため、最小のCiに最大のDiを掛けるため、Dは配列を逆順にしたものを足し合わせる
#modを取っているので、Dを降順ソートすると順番が崩れる
ans=0
for c,d in zip(C,D[::-1]):
    ans+=c*d
    ans%=mod

ans=ans*pow(2,N,mod)

print ans%mod


Measured memory_bytes: 66108
k = int(input())
dic = dict()
cnt = 1
num1 = 7 % k
num2 = 70 % k
while True:
    if dic.get(num1):break
    if (num1) == 0:
        print(cnt)
        exit()
    
    dic[num1] = 1
    num1 = (num1 + num2) %k
    num2 = (num2 * 10) %k
    cnt += 1
    #print(num1, num2)
print(-1)

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

int main(){
  vector<int> bell(3);
  for(int i = 0; i < 3; i++){
    cin >> bell.at(i);
  }
  
  sort(bell.begin(), bell.end());
  
  cout << bell.at(0) + bell.at(1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int vec[200004],vv[200004];
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  for (int X=0; X<N-1; X++){
    cin >> vec[X];
    vv[vec[X]]++;
  }
  for (int X=1; X<=N; X++){
    cout << vv[X] << endl;
  }
}


Measured memory_bytes: 5160
import numpy as np
S = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
    S = np.where(S==int(input()), 0, S)
    HBingo = min(np.sum(S, axis=0)) == 0
    WBingo = min(np.sum(S, axis=1)) == 0
    SBingo = S[2][0] == 0 and S[1][1] == 0 and S[0][2] == 0
    BSBingo = S[0][0] == 0 and S[1][1] == 0 and S[2][2] == 0
if HBingo or WBingo or SBingo or BSBingo:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 14448
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int hed[N],to[N<<1],nxt[N<<1],cnt;
inline void adde(int u,int v){
	++cnt;to[cnt]=v,nxt[cnt]=hed[u];hed[u]=cnt;
}
char s[N];
int f[N][2],n;
int siz[N],g[N];

inline void dfs1(int x,int pre){
	siz[x] = s[x]=='1';
	g[x] = s[x]=='1'?0:0x3f3f3f3f;
	for(int i=hed[x];i;i=nxt[i]){
		int v=to[i];if(v==pre)continue;
		dfs1(v,x);
		if(f[v][0]+1>f[x][0]){
			f[x][1]=f[x][0];
			f[x][0]=f[v][0]+1;
		}
		else if(f[v][0]+1>f[x][1]){
			f[x][1]=f[v][0]+1;
		}
		siz[x]+=siz[v];
		if(siz[v])g[x]=min(g[x],f[v][0]+1);
	}
}
typedef long long ll;
ll ans;
inline void dfs2(int x,int pre){
	ans+=max(min(f[x][0],f[x][1]+2)-g[x],0);
	for(int i=hed[x];i;i=nxt[i]){
		int v=to[i];if(v==pre)continue;
		int tmp = (f[x][0]==f[v][0]+1?f[x][1]:f[x][0])+1;
		if(tmp+1>f[v][0]){
			f[v][1]=f[v][0];
			f[v][0]=tmp;
		}
		else if(tmp+1>f[v][1]){
			f[v][1]=tmp;
		}
		if(siz[v]!=siz[1])g[v]=min(g[v],tmp);
		dfs2(v,x);
	}
}

int main()
{
	cin >> n;
	for(int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		adde(u,v),adde(v,u);
	}
	scanf("%s",s+1);
	dfs1(1,0);
	dfs2(1,0);
	cout << ans+1 << endl;
}

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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
        return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/

ll GCD(ll a ,ll b){
    return (a%b == 0) ? b : GCD(b , a%b);
}

ll LCM(ll a , ll b){
    return (a * b)/GCD(a , b);
}

int main()
{
    ll a , b;

    cin >> a >> b;

    cout << LCM(a , b) << "\n";

    return 0;
}


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

ll binary_serch(vector<ll> a, ll x, ll l, ll r) {
  ll lb = l-1; ll ub = r;
  while(ub - lb > 1) {
    ll m = (lb + ub) / 2;
    if (a[m] >= x) ub = m;
    else lb = m;
  }
  return ub;
}

int main() {
  int n;
  cin >> n;
  vector<ll> L(n);
  rep(i,n) cin>>L[i];
  sort(L.begin(), L.end());
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      int k = binary_serch(L, L[j]+L[i], j, n);
      ans += k - j - 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def gen_graph(input_list):
    graph = {}

    for item in input_list:
        if not item[0] in graph:
            graph[item[0]] = {}
        if not item[1] in graph:
            graph[item[1]] = {}
        graph[item[0]][item[1]] = item[2]
        graph[item[1]][item[0]] = item[2]

    return graph


def get_lowest_cost_vertex(costs, processed):
    lowest_cost = float("inf")
    lowest_cost_node = None
    for node in costs:
        cost = costs[node]
        if cost < lowest_cost and node not in processed:
            lowest_cost = cost
            lowest_cost_node = node
    return lowest_cost_node


def get_best_routes(graph, start):
    costs = {}
    parents = {}
    processed = []

    costs[start] = 0
    parents[start] = None
    processed.append(start)

    for item in graph[start].keys():
        costs[item] = graph[start][item]
        parents[item] = start

    for item in graph.keys():
        if not (item in costs.keys() or item == start):
            costs[item] = float("inf")
            parents[item] = None

    node = get_lowest_cost_vertex(costs, processed)

    while node is not None:
        cost = costs[node]
        neighbors = graph[node]

        for n in neighbors.keys():
            new_cost = cost + neighbors[n]
            if costs[n] > new_cost:
                costs[n] = new_cost
                parents[n] = node
        processed.append(node)
        node = get_lowest_cost_vertex(costs, processed)

    routes = []
    for item in graph.keys():
        if item != start:
            route = []
            route.append(item)
            parent = parents[item]
            while 1:
                route.append(parent)
                if parent == start:
                    break
                parent = parents[parent]
            route.reverse()
            routes.append(route)
    return routes


def main(vertex_count, input_list):
    graph = gen_graph(input_list)

    routes = []
    for start in range(1, vertex_count+1):
        for route in get_best_routes(graph, start):
            routes.append(route)

    route_sides = []
    for route in routes:
        for i, vertex in enumerate(route):
            if i == len(route)-1:
                break
            route_side = [route[i], route[i+1]]
            route_side_sorted = sorted(route_side)
            if not route_side_sorted in route_sides:
                route_sides.append(route_side_sorted)

    sides = []
    for item in input_list:
        side = [item[0], item[1]]
        side_sorted = sorted(side)
        sides.append(side_sorted)

    count = 0
    for side in sides:
        if not side in route_sides:
            count += 1

    return count


if __name__ == "__main__":
    input_1 = input()
    vertex_count, sides_count = list(map(int, input_1.split()))
    input_list = []
    for _ in range(sides_count):
        vertex_1, vertex_2, distance = list(map(int, input().split()))
        input_list.append((vertex_1, vertex_2, distance))
    print(main(vertex_count, input_list))


Measured memory_bytes: 7012
ND=input().split()
ND[0]=int(ND[0])
ND[1]=int(ND[1])
ls=[]
for i in range(ND[0]):
    ls.append(input().split())
    for j in range(ND[1]):
        ls[i][j]=int(ls[i][j])

ans=0

for i in range(ND[0]):
    X=ND[0]-1-i
    for j in range(X):
        nijo=0
        for k in range(ND[1]):
            nijo+=int((ls[i][k]-ls[i+j+1][k])**2)
        root=nijo**0.5
        if root.is_integer():
            ans+=1

print(ans)


Measured memory_bytes: 3064
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h, w = li()
grid = [lc() for _ in range(h)]

# 左側の照らせるマス
left = [[0]*w for _ in range(h)]
for row in range(h):
    cur = 0
    for col in range(w-1, -1, -1):
        if grid[row][col] == ".":
            cur += 1
            left[row][col] = cur
        else:
            cur = 0

# 右側の照らせるマス
right = [[0]*w for _ in range(h)]
for row in range(h):
    cur = 0
    for col in range(w):
        if grid[row][col] == ".":
            cur += 1
            right[row][col] = cur
        else:
            cur = 0

# 上側の照らせるマス
up = [[0]*w for _ in range(h)]
for col in range(w):
    cur = 0
    for row in range(h-1, -1, -1):
        if grid[row][col] == ".":
            cur += 1
            up[row][col] = cur
        else:
            cur = 0

# 下側の照らせるマス
down = [[0]*w for _ in range(h)]
for col in range(w):
    cur = 0
    for row in range(h):
        if grid[row][col] == ".":
            cur += 1
            down[row][col] = cur
        else:
            cur = 0

# 最大値
ans = 0
for row in range(h):
    for col in range(w):
        ans = max(ans, left[row][col] + right[row][col] + up[row][col] + down[row][col])

print(ans-3)


Measured memory_bytes: 307976
n = int(input())
A = list(map(int, input().split()))

if n == 1:
    print(A[0])
    exit()

elif n % 2 == 0:
    l1 = [str(A[n - 2 * i - 1]) for i in range(n//2)]
    l2 = [str(A[2 * j]) for j in range(n//2)]

else:
    l1 = [str(A[n - 2 * i - 1]) for i in range(n//2 + 1)]
    l2 = [str(A[2 * j + 1]) for j in range(n//2)]

print(" ".join(l1), " ".join(l2))

Measured memory_bytes: 31780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b,c; cin >> a >>b;
	cout << a * a - b;
	


	cout << endl;
	return 0;
}

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

int main() {
	int a[55], n, maxi = 0, cur = 0; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (abs(a[i]) > maxi) { maxi = abs(a[i]); cur = i; }
	}
	cout << n * 2 - 1 << endl;
	for (int i = 0; i < n; i++)cout << cur + 1 << ' ' << i + 1 << endl;
	if (a[cur] >= 0)for (int i = 0; i < n - 1; i++)cout << i + 1 << ' ' << i + 2 << endl;
	else for (int i = n - 1; i; i--)cout << i + 1 << ' ' << i << endl;
	return 0;
}

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

using namespace std;

int n, sum[1500];
vector<int> data;

int solve(){
  int sum_=0;
  for(int i=0; i<n; ++i) sum_ += data[i];
  for(int i=0; i<1500; ++i){
    if(sum_ == sum[i]) break;
    if(sum_ < sum[i]) return -1;
  }
  int ans=0;
  while(ans <= 10000){
    bool flag=true;
    int size=data.size();
    for(int i=0; i<size; ++i){
      if(data[i] != i+1) flag=false;
    }
    if(flag) return ans;
    for(int i=0; i<data.size(); ){
      if(data[i] == 1){
	data.erase(data.begin()+i);
      }else{
	--data[i]; ++i;
      }
    }
    data.push_back(size);
    ++ans;
  }
  return -1;
}

int main(){
  for(int i=0; i<1500; ++i) sum[i] = i*(i+1)/2;
  while(1){
    cin >> n;
    if(!n) break;
    data = vector<int>(n);
    for(int i=0; i<n; ++i) cin >> data[i];
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
class BIT():

    __slots__ = ["n", "data"]

    def __init__(self, li):
        self.n = len(li) + 1
        self.data = [0] + li
        for i in range(1, self.n):
            if i + (i & -i) < self.n:
                self.data[i + (i & -i)] += self.data[i]

    def add(self, i, a):
        i += 1
        while i < self.n:
            self.data[i] += a
            i += i & -i
        
    def acc(self, i):
        res = 0
        while i > 0:
            res += self.data[i]
            i -= i & -i
        return res
    
    def fold(self, l, r):
        return self.acc(r) - self.acc(l)

import sys
input = sys.stdin.buffer.readline
n, q = map(int, input().split())
A = list(map(int, input().split()))
bit = BIT(A)
for _ in range(q):
    t, p, x = map(int, input().split())
    if t == 0:
        bit.add(p, x)
    else:
        print(bit.fold(p, x))

Measured memory_bytes: 126908
@L=1..($z=<>)+2;
$-=--$L[$_]and$z-=!$B[$-]++for@A=glob<>;
map{
	$-=$L[$A[$`-/ /]]++and$z+=!--$B[$-];
	$-=--$L[$A[$`-1]=$']and$z-=!$B[$-]++;
	print$z,$/
}<>


Measured memory_bytes: 84964
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 202;

ll d[MAX_N][MAX_N];
ll dp[(1 << 8)][8];

void warshall_floyd(int V)
{
    rep(i,V){
        rep(j,V){
            rep(k,V){
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,r;
    cin >> n >> m >> r;
    vector<ll> vec(r);
    rep(i,r){
        cin >> vec[i];
        vec[i]--;
    }
    rep(i,n){
        rep(j,n){
            d[i][j] = INF;
        }
    }
    rep(i,n){
        d[i][i] = 0;
    }
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        d[a][b] = d[b][a] = c;
    }
    warshall_floyd(n);
    rep(i,(1 << r)){
        rep(j,r){
            dp[i][j] = INF;
        }
    }
    rep(i,r){
        dp[(1 << i)][i] = 0;
    }
    for(int i=1;i<(1 << r);i++){
        if(__builtin_popcount(i) == 1){
            continue;
        }
        rep(j,r){
            if(i & (1 << j)){
                rep(k,r){
                    if((i ^ (1 << j)) & (1 << k)){
                        dp[i][j] = min(dp[i][j],dp[i^(1 << j)][k] + d[vec[j]][vec[k]]);
                    }
                }
            }
        }
    }
    ll ans = INF;
    rep(i,r){
        ans = min(ans,dp[(1 << r)-1][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
def resale(V, C):

    result = 0
    for v, c in zip(V, C):
        if v > c:
            result += v - c
            
    return result


if __name__ == '__main__':
    
#    print('Input: ')
    n = int(input())
    v = list(map(int, input().split()))
    c = list(map(int, input().split()))
    
#    print('---------------------')
#    print('Output: ')
    print(resale(v,c))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int t = K;
  int c = 0;
  
  while (t > 0) {
    c++;
    t /= 2;
    if (c >= N) {
      break;
    }
  }
  
  int x = 1;
  
  for (int i = 0; i < c; i++) {
    x *= 2;
  }
  
  for (int i = 0; i < N - c; i++) {
    x += K;
  }
  
  cout << x << endl;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	string s;
	cin>>s;
	rep(i,s.size()){
		if(i==s.size()-1)continue;
		if(s[i]=='A'&&s[i+1]=='C'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

int main() {
	vector<int> furui(101000, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i * i <= 101000; i++) {
		if (furui[i] == 0) {
			for (int j = 2; j < 101000/i; j++) {
				furui[i*j] = 1;
			}
		}
	}
	int n, p;
	while (cin >> n >> p) {
		if (n == -1 && p == -1) {
			break;
		}
		int a = n+1;
		int counter = 0;
		while (counter == 0) {
			if (furui[a] == 0) {
				counter = a*2;
				break;
			} else {
				a++;
			}
		}
		int limit;
		int j = a;
		for (int i = 1; i < p; i++) {
			if (j == a) {
				counter++;
			}
			limit = counter/2;
			while (j <= limit) {
				if (furui[j] == 0 && furui[counter-j] == 0) {
					break;
				} else {
					j++;
				}
			}
			if (j > limit) {
				j = a;
				i--;
			} else {
				j++;
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;


int main() {
	int N;
	cin >> N;
	vector<ll>a(3*N);
	rep(i, 0, 3 * N) {
		cin >> a[i];
	}

	vector<vector<ll>>sumdata(2);

	priority_queue<ll,vector<ll>,greater<ll>>pre;
	ll sm = 0LL;
	for (int i = 0; i < N;i++) {
		pre.push(a[i]);
		sm += a[i];
	}
	sumdata[0].push_back(sm);

	for (int i = N; i < 2 * N;i++) {
		sm += a[i];
		pre.push(a[i]);
		sm -= pre.top();
		pre.pop();
		sumdata[0].push_back(sm);
	}


	reverse(a.begin(), a.end());
	priority_queue<ll>post;
	sm = 0LL;
	for (int i = 0; i < N; i++) {
		post.push(a[i]);
		sm += a[i];
	}
	sumdata[1].insert(sumdata[1].begin(),sm);

	for (int i = N; i < 2 * N; i++) {
		sm += a[i];
		post.push(a[i]);
		sm -= post.top();
		post.pop();
		sumdata[1].insert(sumdata[1].begin(),sm);
	}


	vector<ll>temp;
	rep(i, 0, sumdata[0].size()) {
		temp.push_back(sumdata[0][i]-sumdata[1][i]);
	}
	sort(temp.begin(), temp.end());
	reverse(temp.begin(), temp.end());
	cout << temp[0] << endl;

	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int xs[1100], dp[5100][5100];
vector<int> G[1100];

int difference(const P& p){
    return snd(p) - fst(p);
}

int rec(int v){
    if(G[v].empty()){return 0;}
    
    vector<P> ve;
    for(int w : G[v]){
        int a = xs[w], b = rec(w);
        if(b == -1){return -1;}
        ve.emplace_back(a, b);
    }

    int m = ve.size();
    std::fill(&dp[0][0], &dp[0][0]+(m+1)*5100, 252521);
    dp[0][0] = 0;
    
    for(int i=0;i<m;++i){
        for(int j=0;j<=xs[v];++j){
            if(j > 0){
                dp[i][j] = min(dp[i][j], dp[i][j-1]);
            }
            if(j + fst(ve[i]) <= xs[v]){
                dp[i+1][j + fst(ve[i])] = min(dp[i+1][j + fst(ve[i])], dp[i][j] + snd(ve[i]));
            }
            if(j + snd(ve[i]) <= xs[v]){
                dp[i+1][j + snd(ve[i])] = min(dp[i+1][j + snd(ve[i])], dp[i][j] + fst(ve[i]));
            }
        }
    }

    return dp[m][xs[v]] < 252521 ? dp[m][xs[v]] : (-1);
}

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

    std::cin >> N;
    
    for(int i=2;i<=N;++i){
        int p;
        std::cin >> p;

        G[p].emplace_back(i);
    }

    for(int i=1;i<=N;++i){
        std::cin >> xs[i];
    }

    int res = rec(1);
    const string POSSIBLE[2] = {"IMPOSSIBLE", "POSSIBLE"};
    std::cout << POSSIBLE[res >= 0] << std::endl;
}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
void display(vector<int> v) {
  for (size_t i = 0; i < v.size(); i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int sum = 1;
  for (int i = 1; i <= n; i++) {
    v.push_back(i);
    sum *= i;
  }
  int cnt = 0;
  do {
    display(v);
    next_permutation(v.begin(), v.end());
    cnt++;
  } while (cnt < sum);
}


Measured memory_bytes: 3160
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] w = new int[n];
		int a = 0;
		int sum = 0;
		for(int i=0; i<n; i++) {
			w[i] = sc.nextInt();
			if(w[i] > a) {
				a = w[i];
			}
			sum += w[i];
		} 
		int b = sum;
		while(true) {
//			System.out.println(a + " " + b);
			
			int c = (a + b) / 2; //???????????§?????????
			
			int track = 0;
			int amount = 0;
			boolean can = true;
			for(int i=0; i<n; i++) {
				if(amount + w[i] > c) {
					track++;
					amount = 0;
				}
				
				if(track == k) {
					a = c + 1;
					can = false;
					break;
				}
				
				amount += w[i];
			}
			
			if(can) {
				b = c - 1;
			}
			
			if(a > b) {
				if(can) {
					System.out.println(c);
				} else {
					System.out.println(c+1);
				}
				break;
			}
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 41176
#include <iostream>

using namespace std;

typedef long long ll;

ll a, b, c, l, m, n;

/*
ll move(ll x, ll y, ll z) {
	ll nx = a * x % l;
	ll ny = b * y % m;
	ll nz = c * z % n;

	if (nx == 1 && ny == 1 && nz == 1) return 1;
	else return move(nx, ny, nz) + 1;
}
*/

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

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	while (cin >> a >> l >> b >> m >> c >> n, a || b || c || l || m || n) {
		ll times = 0, x, y, z, tx, ty, tz;

		x = y = z = 1;
		tx = ty = tz = 1;

		while ((x = a * x % l) != 1) ++tx;
		while ((y = b * y % m) != 1) ++ty;
		while ((z = c * z % n) != 1) ++tz;

		cout << lcm( lcm(tx, ty), tz) << endl;
	}
}

Measured memory_bytes: 1156
#include <iostream>
using namespace std;
int main(){
  int N,A[3][3];
  bool used[3][3]={
    {false,false,false},
    {false,false,false},
    {false,false,false}
  };
  for(int i=0;i<9;i++)cin >> A[i/3][i%3];
  cin >> N;
  for(int i=0,b;i<N;i++){
    cin >> b;
    for(int i=0;i<9;i++){
      if(!used[i/3][i%3] && A[i/3][i%3]==b)
        used[i/3][i%3]=true;
    }
  }
  bool flag=false;
  for(int i=0;i<3;i++){
    if(used[i][0] && used[i][1] && used[i][2])flag=true;
    if(used[0][i] && used[1][i] && used[2][i])flag=true;
  }
  if(used[0][0] && used[1][1] && used[2][2])flag=true;
  if(used[0][2] && used[1][1] && used[2][0])flag=true;  
  
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a * b / 2 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3660
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(input())

answers = [0] * (N + 1)
n = N
for x in range(1, n+1):
    x2 = x ** 2
    for y in range(1, n-x2+1):
        y2 = y ** 2
        xy = x * y
        # z = (n - ((x + y) ** 2 - x * y)) / 
        # for z in range(1, n-x2-y2-xy+1):
        for z in range(1, n-x2-y2-xy+1):
            v = x2 + y2 + z ** 2 \
                    + xy + y*z + z*x
            if v > n:
                break
            answers[v] += 1
            
for ans in answers[1:]:
    print(ans)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, t = 0, w = 0, z = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    t += vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    w += vec.at(i);
    if (t <= 2 * w) {
      break;
    }
  }
  for (int i = N - 1; i >= 0; i--) {
    z += vec.at(i);
    if (t <= 2 * z) {
      break;
    }
  }
  if (z < w) {
    cout << 2 * z - t << endl;
  }
  else {
    cout << 2 * w - t << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int H,W,N;
    int count,big,change;
    scanf("%d",&H);
    scanf("%d",&W);
    scanf("%d",&N);
    
    count = 0;
    change = 0;
    
    if(W>=H){
        big = W;
    }else{
        big = H;
    }
    
    while(change < N){
        count++;
        change = count * big;
    }
    
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let i, j, X, Y, xlen, ylen, maxlen;
  let c = Array.from(Array(1000 + 1), () => []);
  while ((X = lines.shift()) && (Y = lines.shift())) {
    xlen = X.length;
    ylen = Y.length;
    for (i = 0; i <= xlen; i++) c[i][0] = 0;
    for (j = 0; j <= ylen; j++) c[0][j] = 0;

    for (i = 1; i <= xlen; i++) {
      for (j = 1; j <= ylen; j++) {
        if (X[i-1] === Y[j-1]) c[i][j] = c[i - 1][j - 1] + 1;
        else c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
      }
    }
    console.log(c[xlen][ylen]);
  }
})();



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

int main(void){
	int h,n;
	cin>>h>>n;
	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		int temp;
		cin>>temp;
		sum+=temp;
	}

	if(sum>=h) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}	

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

bool ba1[201][201];
bool ba2[201][201];

int main() {
  const int dx1[] = {0,-1,-1,0,1,1};
  const int dy1[] = {-1,-1,0,1,1,0};
  const int dx2[] = {1,0,-1,-1,0,1};
  const int dy2[] = {-1,-1,0,1,1,0};
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    string a, b;
    getline(cin, a);
    getline(cin, b);
    string gomi;
    getline(cin, gomi);
    if (a.size() != b.size()) {
      cout << "false" << endl;
      continue;
    }
    if (a == "") {
      cout << "true" << endl;
      continue;
    }
    memset(ba1,0,sizeof(ba1));
    memset(ba2,0,sizeof(ba2));
    int x1,y1,x2,y2;
    x1=y1=x2=y2=100;

    bool dame1 = 0, dame2 = 0;
    ba1[100][100] = ba2[100][100] = 1;
    typedef pair<int,int> pii;
    set<pii> se1;
    set<pii> se2;
    se1.insert(pii(100,100));
    se2.insert(pii(100,100));
    REP(i,a.size()) {
      x1 += dx1[a[i]-'a'];
      y1 += dy1[a[i]-'a'];
      x2 += dx2[a[i]-'a'];
      y2 += dy2[a[i]-'a'];
      se1.insert(pii(x1,y1));
      se2.insert(pii(x2,y2));
      if (ba1[x1][y1]) dame1 = 1;
      ba1[x1][y1] = 1;
      if (ba2[x2][y2]) dame2 = 1;
      ba2[x2][y2] = 1;
//      cout << x2 << " " << y2 << endl;
    }
//    cout<<endl;
    bool yes = 0;
    REP(i,6) {
      FOR(it, se1) {
        x1 = it->first;
        y1 = it->second;
        yes = 1;
        set<pair<int,int> > se;
        REP(j, b.size()) {
          int d = (b[j]-'a'+i)%6;
          x1 += dx1[d];
          y1 += dy1[d];
          se.insert(make_pair(x1,y1));
          if (!ba1[x1][y1]) {
            yes = 0;
            break;
          }
        
        }
        if (yes && !dame1 && se.size() == b.size()) {
          break;
        }
      }
      if (yes) break;
      FOR(it, se2) {
        x2 = it->first;
        y2 = it->second;
        yes = 1;
        set<pair<int,int> > se;
        REP(j, b.size()) {
          int d = (b[j]-'a'+i)%6;
          x2 += dx2[d];
          y2 += dy2[d];
          se.insert(make_pair(x2,y2));
//        cout << x2 << " " << y2 << endl;
          if (!ba2[x2][y2]) {
            yes = 0;
            //        cout << endl;
            break;
          }
        }
        if (yes && !dame2 && se.size() == b.size()) break;
      }
      if (yes) break;
    }
    if (yes)
      cout << "true" << endl;
    else
      cout << "false" << endl;
    
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <utility>
#include <string>
using namespace std;
 
int main() {
 
	//数字
	int N;
  string S,T;
  string O;
  cin >> N;
  cin >> S >> T;
  O="";
  for(int i=0;i<N;i++){
    O+=S[i];
    O+=T[i]; 
  }
  cout << O << endl;
}

Measured memory_bytes: 256
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a3 = a1 * t1 + a2 * t2
b3 = b1 * t1 + b2 * t2
if a3 == b3:
    print("infinity")
else:
    if a3 < b3:
        a1, a2, a3, b1, b2, b3 = b1, b2, b3, a1, a2, a3
    diff = a3 - b3
    width = (b1 - a1) * t1
    if width < 0:
        print(0)
    else:
        ans = 1
        ans += (width // diff) * 2
        if not width % diff:
            ans -= 1
        print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main () {
    string s;
    cin >> s;
    string res = "abc";
    if((int)s.size() == 2){
      cout << s << endl;
    }else{
      res[0] = s[2];
      res[1] = s[1];
      res[2] = s[0];
      cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int five_cnt = 2;
  int seven_cnt = 1;
  if(a== 5) five_cnt--;
  if(a== 7) seven_cnt--;
  if(b== 5) five_cnt--;
  if(b== 7) seven_cnt--;
  if(c== 5) five_cnt--;
  if(c== 7) seven_cnt--;
  if(five_cnt == 0 && seven_cnt == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

typedef pair<pair<int,int>,ll> P;

bool negative_cycle(int N,int M,vector<ll> &d,vector<P> &G){
    REP(i,N)d[i]=0;
  int tmp1,tmp2;
    REP(i,2*N){
      REP(j,M){
        P e=G[j];
        int from=e.first.first;
        int to =e.first.second;
        ll cost =e.second;
        if(d[to]>d[from]+cost){
            d[to]=d[from]+cost;
        }
        if(i==N-1)tmp1=d[N-1];
      }
    }
  tmp2=d[N-1];
    return !(tmp1==tmp2);
}

void Bellman_Ford(int s,int N,int M,vector<ll> &d,vector<P> &G){
    REP(i,N)d[i]=INF;
    d[s]=0;
    REP(l,N){
        bool update=false;
        REP(i,M){
            P e=G[i];
            int from=e.first.first;
            int to  =e.first.second;
            ll cost =e.second;
            if(d[from]!=INF && d[to]>d[from]+cost){
                d[to]=d[from]+cost;
                update=true;
            }
        }
        if(!update) break;
    }
}

int main(){
    int N,M;cin>>N>>M;
    vector<P> G;
    int a,b; ll c;
    REP(i,M){
        cin>>a>>b>>c;a--;b--;
        G.push_back(make_pair(make_pair(a,b),-c));
    }
    vector<ll> d(N);
    bool f=negative_cycle(N,M,d,G);
    if(f)cout<<"inf"<<endl;
    else{
        Bellman_Ford(0,N,M,d,G);
        cout<<-d[N-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
s = input()
n = len(s)
l = 0
r = n - 1
ng = 0
ans = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == "x":
        l += 1
        ans += 1
    elif s[r] == "x":
        r -= 1
        ans += 1
    else:
        ng = 1
        break
if ng:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,l;cin>>n>>l;
  if(l*(n+l-1)<=0){
    cout<<(n+2*l-1)*n/2<<endl;
  }
  else if((n+l-1)<=0){
    cout<<(n+2*l-1)*n/2-(n+l-1)<<endl;
  }
  else {
    cout<<(n+2*l-1)*n/2-l<<endl;
  }

  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void){

char s[51];
int k=0;
int i;
int n=0;
  
scanf("%d",&n);
scanf("%d",&k);
scanf("%s",s);

s[k-1]=tolower(s[k-1]);
  
for(i=0;i<n;i++){
printf("%c",s[i]);
}
return 0;
}

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

int main(){
  string s;
  cin>>s;
  bool bad=false;
  rep(i,3)if(s[i]==s[i+1])bad=true;
  if(bad)cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
  return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
def two_pointers(ary, l, r, split, ary_func, comb_func, comp_func):
    left = ary_func(ary, l, split)
    right = ary_func(ary, split, r)
    val = comb_func(left, right)

    for i in range(split + 1, r):
        tmp_left = ary_func(ary, l, i)
        tmp_right = ary_func(ary, i, r)
        tmp_val = comb_func(tmp_left, tmp_right)

        if comp_func(val, tmp_val):
            return i - 1, val, left, right
        else:
            left = tmp_left
            right = tmp_right
            val = tmp_val

    else:
        return r - 1, val, left, right


if __name__ == '__main__':
    # At-Coder ABC 102 - D
    from operator import add, lt
    from itertools import accumulate

    n = int(input())
    a = [int(_) for _ in input().split()]
    cul_ary = [0] + list(accumulate(a, add))

    ary_func = lambda ary, l, r: ary[r] - ary[l]
    comb_func = lambda left, right: abs(left - right)
    comp_func = lt
    l_split = 1
    r_split = 3
    griefs = []
    for i in range(2, n - 1):
        # left
        l_split, l_diff, p, q = two_pointers(cul_ary, 0, i, l_split, ary_func,
                                             comb_func, comp_func)
        # right
        r_split, r_diff, r, s = two_pointers(cul_ary, i, n, r_split, ary_func,
                                             comb_func, comp_func)

        griefs.append(max(p, q, r, s) - min(p, q, r, s))

    print(min(griefs))


Measured memory_bytes: 28984
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)



vector<int> read_array()
{
    int n;
    scanf("%d", &n);

    vector<int> v(n);
    REP(i, n) {
        scanf("%d", &v[i]);
    }

    return v;
}

int selection(vector<int>& v)
{
    int n_swap = 0;

    REP(i, v.size()) {
        int argmin = i;
        FOR(j, i+1, v.size()) {
            if(v[j] < v[argmin])
                argmin = j;
        }
        if(argmin != i) {
            swap(v[argmin], v[i]);
            ++n_swap;
        }
    }

    return n_swap;
}

int main()
{
    vector<int> v = read_array();

    int n_swap = selection(v);

    REP(i, v.size()) {
        printf("%d%c", v[i], i == v.size()-1 ? '\n' : ' ');
    }
    printf("%d\n", n_swap);

    return 0;

    return 0;
}

Measured memory_bytes: 2736
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

int main() {
	string s;
	cin >> s;
	int n = s.length();
	ll sum = 0;
	for (int b = 0; b < (1 << n-1); b++) {
		ll num = (s[0]-'0');

		for (int i = 1; i < n; i++) {
			if (((b >> (i-1)) & 1) == 0) {
				num = num * 10 + (s[i] - '0');
			}
			else {
				sum += num;
				
				num = (s[i] - '0');

			}
		}

		sum += num;
		
	}

	cout << sum << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	sort.Ints(A)
	mx := A[N-1]
	key := mx / 2
	diff := INF
	var r int
	for i := 0; i < N-1; i++ {
		d := abs(key - A[i])
		if d <= diff {
			diff = d
			r = A[i]
		}
	}

	fmt.Fprintln(wtr, mx, r)
}


Measured memory_bytes: 3072