akhauriyash/Code-Regression huggingface dataset:
toInt :: (String -> Int)
toInt x = read x ::Int


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


ten :: Int -> Int
ten x = x * 10


create :: Int -> Int -> Int
create n m =
    let s = take m (iterate ten n)
        r = sum s
    in r


ret :: Int -> Int -> Int
ret n m
    | n < m = create n m
    | m < n = create m n
    | otherwise = create n m


main = do
    x <- getInts
    let n = head x
    let m = last x
    let r = ret n m
    putStrLn $ show r

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int ans[N], col[N];
vector<int> adjlist[N];
vector<int> sets[2];
void dfs(int u, int p){
    sets[col[u]].push_back(u);
    for (auto v : adjlist[u]){
        if (v == p) continue;
        col[v] = 1-col[u];
        dfs(v,u);
    }
}
int main(){
    int n;
    scanf("%d",&n);
    for (int i = 1; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    col[1] = 1;
    dfs(1,-1);
    if (sets[0].size() > sets[1].size()) swap(sets[0],sets[1]);
    int X = n/3;
    int R = sets[0].size(), B = sets[1].size();
    int lim1 = (n+2)/3, lim2 = (n+1)/3;
    if (R <= X){
        for (auto x : sets[0]) ans[x] = 3;
        for (auto x : sets[1]){
            if (lim1) {
                lim1--;
                ans[x] = 1;
            }
            else if (lim2){
                lim2--;
                ans[x] = 2;
            }
            else ans[x] = 3;
        }
    }
    else{
        for (auto x : sets[0]){
            if (lim1) {
                lim1--;
                ans[x] = 1;
            }
            else ans[x] = 3;
        }
        for (auto x : sets[1]){
            if (lim2) {
                lim2--;
                ans[x] = 2;
            }
            else ans[x] = 3;
        }
    }
    int cur[4]; iota(cur,cur+4,0);
    for (int i = 1; i <= n; i++){
        printf("%d ",cur[ans[i]]);
        cur[ans[i]]+=3;
    }
}


Measured memory_bytes: 22516
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
a = []
for i in range(n):
    b = x_list[i+1]-x_list[i]
    a.append(b)
import math
from functools import reduce
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
ans = reduce(gcd, a)
print(int(ans))

Measured memory_bytes: 14228
# https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
ans = 0
if M == 0:
    print(1)
    exit()
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1,B-1)
    ans = max(ans,uf.size(A-1))
print(ans)

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

#define MAX_N (100000)
#define MAX_M (200000)
#define MAX_COR (1000000000)

int K;
int bases[MAX_N], offsets[MAX_N];

void uf_init(int N) {
  K = N;
  for (int i = 0; i < K; i++) {
    bases[i] = i;
    offsets[i] = 0;
  }
}

int uf_find_root_r(int k, int *p_offset) {
  // the root's base is itself
  if (bases[k] == k) {
    *p_offset = 0;
    return k;
  }
  // recursively search for the root (and optimize)
  int ret = uf_find_root_r(bases[k], p_offset);
  *p_offset += offsets[k];
  bases[k] = ret;
  offsets[k] = *p_offset;
  return ret;
}

int uf_find_base(int k) {
  int offset;
  return uf_find_root_r(k, &offset);
}

int uf_add(int l, int r, int d) {
  const int base_l = uf_find_base(l), offset_l = offsets[l];
  const int base_r = uf_find_base(r), offset_r = offsets[r];
  // printf("insert rule: l = %d, r = %d, d = %d\n", l, r, d);
  // printf("before: base_l = %d, offset_l = %d, base_r = %d, offset_r = %d\n",
  //        base_l, offset_l, base_r, offset_r);
  if (base_l == base_r) {  // same root, check for inconsistencies
    return offset_r - offset_l == d;
  } else {  // they are not related yet
    bases[base_r] = base_l;
    offsets[base_r] = d - offset_r + offset_l;
    return 1;
  }
}

int all_offsets_below(int thresh) {
  for (int i = 0; i < K; i++) {
    uf_find_base(i);
    if (offsets[i] > thresh) {
      return 0;
    }
  }
  return 1;
}

void uf_print() {
  printf("bases:\n");
  for (int i = 0; i < K; i++) {
    printf("%5d ", bases[i]);
  }
  printf("\noffsets:\n");
  for (int i = 0; i < K; i++) {
    printf("%5d ", offsets[i]);
  }
  printf("\n");
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, Ls[MAX_M], Rs[MAX_M], Ds[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", &Ls[i], &Rs[i], &Ds[i]);
    Ls[i]--;  // NOTE : modified input
    Rs[i]--;  // NOTE : modified input
  }

  // initialize the uf tree
  uf_init(N);
  // keep inserting rules
  int possible = 1;
  for (int i = 0; i < M; i++) {
    if (!uf_add(Ls[i], Rs[i], Ds[i])) {
      possible = 0;
      break;
    }
    // uf_print();
  }
  if (possible && all_offsets_below(MAX_COR)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  rep(i,n) p.at(i)++;
  
  int sum = 0;
  int mx = 0;
  queue<int> que;
  rep(i,n) {
	sum += p.at(i);
	que.push(p.at(i));
    if (que.size() > k) {
      sum -= que.front(); que.pop();
    }
    if (que.size() == k) {
	  mx = max(sum, mx);
    }
  }
  
  double ans = mx;
  ans /= 2;
  
  printf("%.10f", ans);
  
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> rui(n); //今までた白の累積和
    rep(i, n)
    {
        if (i == 0)
        {
            if (s[i] == '.')
                rui[i]++;
        }
        else if (s[i] == '.')
        {
            rui[i] = rui[i - 1] + 1;
        }
        else
        {
            rui[i] = rui[i - 1];
        }
    }

    ll w = rui[n - 1];
    ll b = n - w;

    ll ans = min(w, b);
    rep(i, n - 1)
    {
        ll tmp=i+1-rui[i]+w-rui[i];
        ans=min(ans,tmp);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 5220
from itertools import product

A,B,C,D=map(int,input())
O=["+","-"]
X=product(O,repeat=3)

for (p,q,r) in X:
    T="{}{}{}{}{}{}{}".format(A,p,B,q,C,r,D)
    if eval(T)==7:
        print("{}=7".format(T))
        break


Measured memory_bytes: 61972
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    from collections import deque

    # compressed[v]: 縮約後のグラフで縮約前のvが属する頂点
    # num: 縮約後のグラフの頂点数
    def SCC(adj, adj_rev):
        N = len(adj) - 1
        seen = [0] * (N + 1)
        compressed = [0] * (N + 1)
        order = []

        for v0 in range(1, N + 1):
            if seen[v0]:
                continue
            st = deque()
            st.append(v0)
            while st:
                v = st.pop()
                if v < 0:
                    order.append(-v)
                else:
                    if seen[v]:
                        continue
                    seen[v] = 1
                    st.append(-v)
                    for u in adj[v]:
                        st.append(u)

        seen = [0] * (N + 1)
        num = 0
        for v0 in reversed(order):
            if seen[v0]:
                continue
            num += 1
            st = deque()
            st.append(v0)
            seen[v0] = 1
            compressed[v0] = num
            while st:
                v = st.pop()
                for u in adj_rev[v]:
                    if seen[u]:
                        continue
                    seen[u] = 1
                    compressed[u] = num
                    st.append(u)

        return num, compressed

    # 縮約後のグラフを構築
    # 先にSCC()を実行してnum, compressedを作っておく
    def construct(adj, num, compressed):
        N = len(adj) - 1
        adj_compressed = [set() for _ in range(num + 1)]
        for v in range(1, N + 1):
            v_cmp = compressed[v]
            for u in adj[v]:
                u_cmp = compressed[u]
                if v_cmp != u_cmp:
                    adj_compressed[v_cmp].add(u_cmp)
        return adj_compressed

    N, M = map(int, input().split())
    adj = [set() for _ in range(N+1)]
    adj_rev = [set() for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a+1].add(b+1)
        adj_rev[b+1].add(a+1)

    num, compressed = SCC(adj, adj_rev)
    ans = [[] for _ in range(num+1)]
    for v in range(1, N+1):
        ans[compressed[v]].append(v-1)
    print(num)
    for i in range(1, num+1):
        line = [len(ans[i])] + ans[i]
        print(*line)


if __name__ == '__main__':
    main()


Measured memory_bytes: 354524
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#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 FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
template <class T> struct FenwickTree {
   vector<T> node;
   FenwickTree(int n) : node(n,0) {}
   void add(int idx, T val) {
      while (idx < node.size()) {
         node[idx] += val;
         idx += idx & -idx;
      }
   }
   T sum(int idx) {
      T ret = 0;
      while (idx > 0) {
         ret += node[idx];
         idx -= idx & -idx;
      }
      return ret;
   }
};

int N,M;
vector< pair<int,int> > add;
vector<int> l,r;
FenwickTree<int> inst(100010);

int main() {

  cin >> N >> M;
  l.resize(N);
  r.resize(N);

  REP(i,N) {
    int lt,rt; cin >> lt >> rt;
    l[i] = lt;
    r[i] = rt;
    add.push_back(make_pair(rt - lt + 1, i));
  }
  
  sort(add.begin(),add.end());

  int j = 0;
  for(int i=1; i<=M; i++) {
    while(j < add.size()) {
      if(add[j].first >= i) break;
      int idx = add[j].second;
      inst.add(l[idx],1);
      inst.add(r[idx]+1,-1);
      j++;
    }

    int ans = N - j;
    for(int k=i; k<=M; k+=i) ans += inst.sum(k);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 9200
package main

import (
	"bufio"
	"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
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, K := sc.nextInt(), sc.nextInt()
	L := sc.nextIntSlice(N)
	sort.Sort(sort.Reverse(sort.IntSlice(L)))
	ans := 0
	for i := 0; i < K; i++ {
		ans += L[i]
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


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

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

    if (A%2==1) cout << setprecision(6) << (double)(A-(A-1)/2)/A << endl;
    else cout << setprecision(6) << 0.50000000000 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn     cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;

int main()
{
    ll n,q=1;
    cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    if(n%2){rep(i,n)if(a[i]!=(i/2+i%2)*2) cout<<"0\n",exit(0);}
    else rep(i,n)if(a[i]!=i/2*2+1) cout<<"0\n",exit(0);
    rep(i,n/2) q*=2,q%=(INF-2);
    cout<<q<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    if (S == "SAT") {
        cout << 1 << endl;
    } else if (S == "FRI") {
        cout << 2 << endl;
    } else if (S == "THU") {
        cout << 3 << endl;
    } else if (S == "WED") {
        cout << 4 << endl;
    } else if (S == "TUE") {
        cout << 5 << endl;
    } else if (S == "MON") {
        cout << 6 << endl;
    } else {
        cout << 7 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
ans=0
A=[]
for x in range(N):
  X=list(map(int,input().split()))
  for y in range(len(A)):
    s=0
    for z in range(D):
      s+=(A[y][z]-X[z])**2
    if ((s**(1/2))*10)%10==0:
      ans+=1
  A.append(X)
print(ans)

Measured memory_bytes: 9352
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
ll MOD=998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll N;
    cin>>N;
    ll thr = N/3;
    ll fiv = N/5;
    ll fif = N/15;
    ll sum = -(fif+1)*fif/2*15;
    sum += (thr+1)*thr/2*3;
    sum += (fiv+1)*fiv/2*5;
    cout<<(1+N)*N/2-sum<<endl;
}


Measured memory_bytes: 3592
N = int(input())
L = []
for _ in range(N):
    L.append(int(input()))

dp_table = [None for _ in range(10**5+2)]
for i in range(len(L)):
    dp_table[L[i]] = [0 for _ in range(N)]
    dp_table[L[i]][i] +=  1
import copy
for i in range(10**5+2):
    if dp_table[i] != None:
        for j in range(N):
            if dp_table[i][j] == 0:
                tmp = copy.copy(dp_table[i])
                tmp[j] += 1
                dp_table[i+L[j]] = tmp
ans = 0
for i in range(10**5+1):
    if dp_table[i] != None and i % 10 != 0:
        ans = max(ans, i)

print(ans)

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

int main()
{
    // 入力
    ll S;
    cin >> S;

    ll Y = S / 1000000000;
    ll X = S - Y * 1000000000;
    if (X > 0) {
        X = 1000000000 - X;
        Y = Y + 1;
    }

    // 出力
    printf("0 0 1000000000 1 %lld %lld", X, Y);
    return 0;
}


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

int N;

int main()
{
    cin >> N;

    int cnt = 0;

    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (x % 2 == 1)
            cnt++;
    }

    if(cnt%2 == 0){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,m;
bool A[2002+2][2002+2];
int rowmx[2002+2][2002+2],rowmi[2002+2][2002+2],colmx[2002+2][2002+2],colmi[2002+2][2002+2];
int main()
{
	FAST
	cin>>n>>m;
	FOR(i,1,n+1){
		FOR(j,1,m+1){
			char ch;cin>>ch;A[i][j]=(ch=='.');
		}
	}
	FOR(i,0,n+2){
		FOR(j,0,m+2){
			rowmi[i][j]=m+1;
			colmi[j][i]=n+1;
		}
	}
	FOR(i,1,n+1){
		// row i
		FOR(j,1,m+1){
			if(!A[i][j])rowmx[i][j]=j;else rowmx[i][j]=rowmx[i][j-1];
		}
		for(ll j=m;j>=1;--j){
			if(!A[i][j])rowmi[i][j]=j;else rowmi[i][j]=rowmi[i][j+1];
		}
	}
	FOR(j,1,m+1){
		FOR(i,1,n+1){
			if(!A[i][j])colmx[j][i]=i;else colmx[j][i]=colmx[j][i-1];
		}	
		for(ll i=n;i>=1;--i)if(!A[i][j])colmi[j][i]=i;else colmi[j][i]=colmi[j][i+1];
	}
	ll ans=0;
	FOR(i,1,n+1){
		FOR(j,1,m+1)if(A[i][j]){
			ans=max(ans,(j-rowmx[i][j])+(rowmi[i][j]-j)+(colmi[j][i]-i)+(i-colmx[j][i])-3);
		}
	}
	cout<<ans;
}


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

int findSumOfDigits(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N;
    cin >> N;
    int ans = 100000000;
    int A, B;
    for (int i=1; i<N; i++) {
        int A, B;
        int j = i;
        A = j;
        B = N - j;
        int sum = findSumOfDigits(A) + findSumOfDigits(B);
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

def runLength(s):
  if len(s) == 0: return []
  if len(s) == 1: return [(s, 1)]
  res = []
  lc = 1
  for i in range(1, len(s)):
    if s[i-1] == s[i]:
      lc += 1
    else:
      res.append((s[i-1], lc))
      lc = 1
  res.append((s[i], lc))
  return res

S = runLength(input())
accsum = [0] * (1 + (S[0][0] == "0"))
for i in range(len(S)):
  accsum.append(accsum[-1] + S[i][1])
if S[-1][0] == "0":
  accsum.append(accsum[-1])
print(max([accsum[i] - accsum[i-2*K-1] for i in range(2*K+1, len(accsum), 2)]) if len(accsum) > 2*K+2 else N)

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

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}, b;
    cin >> b;
    cout << a[b-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string stones;
	cin >> stones;

	int red = 0, white = 0;
	int valid = true;
	for (int i = 0; i < n; ++i) {
		if (stones[i] == 'R') {
			++red;
		} else {
			++white;
		}

		if (i > 0 && stones[i] == 'R' && stones[i - 1] == 'W') {
			valid = false;
		}
	}

	if (!white || !red || valid) {
		cout << "0\n";
		return 0;
	}

	int red_left = red, white_left = white;
	int ans = min(red, white);
	int i = 0, j = n - 1;
	int swaps = 0;
	while (i < j) {
		if (stones[i] == 'W' && stones[j] == 'R') {
			--red_left;
			--white_left;
			++i;
			while (i < j && stones[i] == 'R') {
				++i;
				--red_left;
			}

			--j;
			while (j > i && stones[j] == 'W') {
				--j;
				--white_left;
			}

			++swaps;
			watch(swaps);
			watch(red_left);
			watch(white_left);
			ans = min(ans, min(swaps + red_left, swaps + white_left));
		} 
		else if (stones[i] == 'R') {
			++i;
			--red_left;
		}
		else {
			--j;
			--white_left;
		}
	}

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 5972
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define ff first
#define ss second
typedef long long ll;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int mod = 1e9 + 7;

ll dp[1010][1010];
char g[1010][1010];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) scanf(" %c", &g[i][j]);
  }  
  dp[1][1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (g[i][j] != '#') {
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + dp[i][j - 1]);
        dp[i][j] %= mod;
      }
    }
  }
  printf("%lld\n", dp[n][m]);
}


Measured memory_bytes: 9088
n,m=map(int,raw_input().split())
stu=[]
point=[]


for i in xrange(n):
    stu.append(map(int,raw_input().split()))
for j in xrange(m):
    point.append(map(int,raw_input().split()))


def dis(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])



for co in stu:
    ctr=1
    l=[]
    for po in point:
        l.append((dis(po,co),ctr))
        ctr+=1
    l.sort()
    print l[0][1]

Measured memory_bytes: 32364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] h2 = Console.ReadLine().Split(' ');
            int N = int.Parse(h2[0]);
            int K = int.Parse(h2[1]);
            string[] Hs = Console.ReadLine().Split(' ');
            int[] H = new int[N];
            int ans = 0;
            for (var i = 0; i < N; i++)
            {
                int h = int.Parse(Hs[i]);
                if (h >= K) ans++;
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main() {
	int a[4][13];
	int r,n;
	char s;
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 13; ++j)
		{
			a[i][j]=0;/* code */
		}
	}
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin >>s>>r;
		if (s=='S') a[0][r-1]=1;
		if (s=='H') a[1][r-1]=1;
		if (s=='C') a[2][r-1]=1;
		if (s=='D') a[3][r-1]=1;/* code */
	}
	for (int s= 0; s < 4; ++s)
	{
		for (int r = 0; r < 13; ++r)
		{
			if (a[s][r]==0)
			{
				if (s==0) cout<<'S'<<" "<<r+1<<endl;
				if (s==1) cout<<'H'<<" "<<r+1<<endl;
				if (s==2) cout<<'C'<<" "<<r+1<<endl;
				if (s==3) cout<<'D'<<" "<<r+1<<endl;
			}
		}
	}


	return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<int> mao(n);
    for(int i=0; i<n; i++) {
        cin>>mao.at(i);
    }

    vector<int> ans(n);
    for(int i=0; i<n; i++) {
        int z = mao.at(i);
        ans.at(z-1) = i+1;
    }

    for(int i=0; i<n-1; i++) cout<<ans.at(i)<<" ";

    cout<<ans.at(n-1)<<endl;
}

Measured memory_bytes: 1536
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val As = List.fill(N)(in.nextLong).sorted.reverse

  println(As.head + {
    val l = As.tail.take((N - 1)  / 2)
    if (N % 2 == 0) l.sum * 2
    else l.sum * 2 - l.last
  })
}

Measured memory_bytes: 79640
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL dp[20001];
LL og[20001];
int main(void){
	int n,m,k;
	int i,j;
	LL MAX;
	LL MIN;
	cin>>n>>m>>k;
	for(i=0;i<n;i++){
		cin>>og[i];
		dp[i+1]=LLONG_MAX;
	}
	dp[0]=0;
	for(i=0;i<n;i++){
		MAX=og[i];
		MIN=og[i];
		for(j=1;j<=m;j++){
			LL ans=k+j*(MAX-MIN);
			dp[i+j]=min(dp[i+j],dp[i]+ans);
			MAX=max(MAX,og[i+j]);
			MIN=min(MIN,og[i+j]);
			if(i+j==n)	break;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}



Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<int>ans;
vector<int>curr,tar;
bool go[55][55];
int main(){
	int n; cin>>n;
	for(int i=0;i<n;i++){
		int a; cin>>a; curr.pb(a);
	}
	for(int i=0;i<n;i++){
		int a; cin>>a; tar.pb(a);
	}
	ll ret = 0;
	int cur = 53;
	while(1){
		for(;cur>=0;cur--){
			//ans & cur,cur-1,...,1
			memset(go,0,sizeof(go));
			for(int i=0;i<55;i++) go[i][i] = true;
			vector<int>can = ans;
			for(int j=cur;j>=1;j--) can.pb(j);
			while(1){
				bool upd = 0;
				for(int i=0;i<can.size();i++){
					for(int j=0;j<55;j++){
						for(int k=0;k<=j;k++){
							if(go[j][k] == false) continue;
							if(go[j][k%can[i]] == false){
								go[j][k%can[i]] = true;
								upd = 1;
							}
						}
					}
				}
				if(!upd) break;
			}
			bool flag = 0;
			for(int i=0;i<n;i++){
				if(!go[curr[i]][tar[i]]){
					flag = 1;
					break;
				}
			}
			if(flag){
				if(cur == 53){
					puts("-1"); return 0;
				}
				ans.pb(cur+1);
				goto nxt;
			}
		}
		for(int i=0;i<ans.size();i++) ret += 1LL<<ans[i];
		cout<<ret<<endl; return 0; nxt:;
	}
}

Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N, L; cin >> N >> L;
	vector<ll> v(N);
	ll val = LLINF;
	rep(i, N){
		v[i] = i + L;
		val = min(val, abs(v[i]));
	}
	ll sum = accumulate(ALL(v), 0LL);
	ll sa = LLINF;
	ll ans = 0;
	rep(i, N){
		ll sum2 = sum - v[i];
		if(sa > abs(sum2 - sum)){
			sa = abs(sum2 - sum);
			ans = sum2;
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3576
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
input()
a = list(map(int, input().split()))
r=0
l=a[0]
for i in range(1,len(a)):
  if l > a[i]:
    r=r+(l-a[i])
  else:
    l=a[i]
print(r)


Measured memory_bytes: 32288
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;

long long pwr(long long a, long long b, long long m = M) {
  long long ret = 1;

  while (b > 0) {
    if (b & 1)  ret = ret * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ret;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  int n;
  cin >> n;
  
  int bo = 0, l = 0, r = 0;
  map<pair<int, int>, int> m;

  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (!a && !b) ++bo;
    else if (!a) ++l;
    else if (!b) ++r;
    else {
      if (a < 0) a *= -1, b *= -1;
      int g = abs(__gcd(a, b));
      m[{a/g, b/g}]++;
    }
  }
  
  int ans = 1;
  ans = ans * (pwr(2, l) + pwr(2, r) + M - 1) % M;

  for (auto s : m) {
    int a = s.first.first, b = s.first.second, na = abs(b), nb = a;
    if (b > 0) nb *= -1;
    if (m.count({na, nb})) {
      if (b > 0) ans = ans * (pwr(2, m[{a,b}]) + pwr(2, m[{na,nb}]) + M - 1) % M;
    } else ans = ans * pwr(2, m[{a, b}]) % M;
  }
  cout << (ans-1+bo+M)%M << '\n';
}


Measured memory_bytes: 16080
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0

for i in range(N):
    ans+=B[A[i]-1]
    if i == 0:
        continue
    if A[i-1]+1  == A[i]:
        ans+=C[A[i-1]-1]

print(ans)


Measured memory_bytes: 3064
n,a,b = map(int,input().split())
if (b-a)%2 == 0:
  print(min((b-a)//2,b-1,n-a))
else:
  print(min(b-1,n-a,a+(b-a-1)//2,n-b+1+(b-a-1)//2))

Measured memory_bytes: 2940
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use num::integer::{gcd, lcm};
#[allow(unused_imports)]
use permutohedron::LexicalPermutation;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(dead_code)]
const MOD: i32 = 1e9 as i32 + 7;

fn main() {
    input!(a:i32, b:i32);
    println!("{}", a*b);
}


Measured memory_bytes: 2136
import itertools
ns=""
def calc(nums,op):
    sum=int(nums[0])
    for i in range(0,3):
        if op[i]=="+":
            sum=sum+int(nums[i+1])
        elif op[i]=="-":
            sum=sum-int(nums[i+1])
    return sum
S=list(input())
l=["+","-"]
p_list=list(itertools.product(l,l,l))
#print(p_list)

for i in range(len(p_list)):
    if calc(S,list(p_list[i]))==7:
        #print(S,list(p_list[i]))
        ans=list(p_list[i])
        ns="".join((ns,S[0]))
        for i in range(3):
            ns="".join((ns,ans[i],S[i+1]))
        ns = "".join((ns,"=7"))
        print(ns)
        break

Measured memory_bytes: 38384
n, k = map(int,input().split())
r, s, p = map(int,input().split())
t = [i for i in input()]
ans = 0
for i in range(n):
    if t[i] == 'r':
        tmp = p
        ans += p
    elif t[i] == 's':
        tmp = r
        ans += r
    elif t[i] == 'p':
        tmp = s
        ans += s
    if k <= i and t[i-k] == t[i]:
        ans -= tmp
        t[i] = 'X'
print(ans)

Measured memory_bytes: 4212
import Control.Applicative ((<$>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (unfoldr)
import Data.Char (isSpace)

main :: IO ()
main = getLine >> solve <$> readil B.readInt <$> B.getLine >>= print

solve :: [Int] -> Int
solve = sum . map (subtract 1)

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where g s = do
          (n, s') <- f s
          return (n, B.dropWhile isSpace s')


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

vector<bool> seen(2*1e5,false);

//頂点vの子全てにxを足しこむ
void dfs(vector<vector<int>> &T, vector<int> &count,int v) {
    seen.at(v) = true;
    for(auto w: T.at(v)) {
        if(seen.at(w)) continue; 
        count.at(w) += count.at(v);
        dfs(T,count,w);
    }
}

int main() {
    int N,Q; cin >> N >> Q;
    vector<vector<int>> T(N,vector<int>());
    vector<int> count(N,0);
    rep(i,N-1) {
        int a,b;
        cin >> a >> b;
        T.at(a-1).push_back(b-1);
        T.at(b-1).push_back(a-1);
    }
    rep(i,Q) {
        int q,x;
        cin >> q >> x;
        count.at(q-1) += x;
    }

    dfs(T,count,0);

    for(auto c:count) cout << c << " ";
    cout << endl;
    
}

Measured memory_bytes: 29824
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll a, b;
	cin >> a >> b;
	if(a >= 13)
		cout << b;
	else if(a <= 5)
		cout << "0";
	else
		cout << b/2;
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
// kuch ni ho rha to kya pta binary search ho
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e18;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  ll ans=0;
  for(ll i=1;i<=n-1;i++)
    ans=ans+(n-1)/i;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3568
import itertools
A, B, C = map(int, input().split())

qs = []
s = 0
for n in itertools.count(1):
    s += A
    q = (s - C) % B
    if q == 0:
        print('YES')
        break
    elif q in qs:
        print('NO')
        break
    else:
        qs.append(q)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  vector<char> s(4);
  string str;
  cin>>str;
  for(int i=0;i<4;i++)
    s[i]=str[i];
  
  
  sort(s.begin(),s.end());
  if((s[0]==s[1])&&(s[1]!=s[2])&&(s[2]==s[3])){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i).sort
c = as[-1]

min_d = 1_000_000_000
min_v = 0
as.each do |a|
  d = (c - a * 2).abs
  if d < min_d
    min_d, min_v = d, a
  end
end

puts "#{c} #{min_v}"

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;
ll N;

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

vector<vector<int>> grid;
vector<ll> H, S;
vector<bool> seen;
vector<ll>sum;
vector<int> pl;

int main(int argc, char **argv){
	ll n,k; cin>>n>>k;
	ll a[n];
	rep(i,0,n){
		cin>>a[i];
	}
	sort(a,a+n);
	if(a[n-1]<k){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}

	ll g=a[0];
	rep(i,0,n-1){
		g=__gcd(g,a[i+1]);
	}

	if(k%g==0){
		cout<<"POSSIBLE"<<endl;
		return 0;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	double a;

	while (scanf("%lf", &a) != EOF){
		int i;
		double array[10] = {a};
		double sum = a;

		for (i = 1; i < 10; i++){
			switch (i % 2){
				case 0:
					array[i] = array[i - 1] / 3;
					break;
				case 1:
					array[i] = array[i - 1] * 2;
					break;
			}
			sum += array[i];
		}
		printf("%f\n", sum);
	}

	return 0;
}

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

#define int long long

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N;
vector<int> tree[1100];
int X[1100];
bool dp[1100][5500];

bool dfs(int n, int& a, int& b) {
    int sum = 0;
    vector<int> child_a, child_b;
    for (int i = 0; i < tree[n].size(); i++) {
        int tmp_a, tmp_b;
        if (!dfs(tree[n][i], tmp_a, tmp_b)) {
            return false;
        }
        sum += tmp_a + tmp_b;
        child_a.push_back(tmp_a), child_b.push_back(tmp_b);
    }
    for (int i = 0; i <= X[n]; i++) {
        dp[0][i] = false;
    }
    dp[0][0] = true;
    for (int i = 0; i < tree[n].size(); i++) {
        for (int j = 0; j <= X[n]; j++) {
            dp[i + 1][j] = false;
            if (j - child_a[i] >= 0) {
                dp[i + 1][j] |= dp[i][j - child_a[i]];
            }
            if (j - child_b[i] >= 0) {
                dp[i + 1][j] |= dp[i][j - child_b[i]];
            }
        }
    }
    for (int i = X[n]; i >= 0; i--) {
        if (dp[tree[n].size()][i]) {
            a = X[n];
            b = sum - i;
            // cout << n << " " << a << " " << b << endl;
            return true;
        }
    }
    return false;
}

signed main() {
    cin >> N;
    for (int i = 1; i < N; i++) {
        int P;
        cin >> P;
        tree[P - 1].push_back(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    int tmp_a, tmp_b;
    if (dfs(0, tmp_a, tmp_b)) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  string s;
  cin >> s;
  int n=s.size();
  ll sum3=0;
  rep(i,n){
    sum3+=s[i]-'0';
  }
  ll sum1=9*(n-1);
  ll sum2=(s[0]-'0'-1)+9*(n-1);
  cout <<max({sum1,sum2,sum3})<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  	string s;	cin >> s;
	for(int i = 0; i < s.size(); i++){
    	cout << "x";
    }
  	cout << endl;
  	
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

//Input Candidates
public class Main{

	Map<String, Integer>[] ref;
	int f;
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			sc.nextLine();
			ref = new Map[26];
			for(int i=0;i<26;i++)ref[i]=new HashMap<String, Integer>();
			while(n--!=0){
				for(String s:sc.nextLine().split(" ")){
					int x = s.charAt(0)-'a';
					if(ref[x].containsKey(s)){
						int z = ref[x].get(s)+1;
						ref[x].put(s, z);
					}
					else ref[x].put(s, 1);
				}
			}
			f = sc.next().charAt(0)-'a';
			PriorityQueue<String> q = new PriorityQueue<String>(5, new Comparator<String>() {
				public int compare(String o1, String o2) {
					return ref[f].get(o1)!=ref[f].get(o2)?ref[f].get(o2)-ref[f].get(o1):o1.compareTo(o2);
				}
			});
			for(String s:ref[f].keySet())q.add(s);
			if(q.isEmpty())System.out.println("NA");
			else {
				int t = Math.min(5, q.size());
				for(int i=0;i<t;i++)System.out.print(q.poll()+(i==t-1?"\n":" "));
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define REP(i,n) for((int)(i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for((int)(i)=0;(i)<(int)(n);(i)++)
#define forn(i,n,m) for((int)(i)=(n);i<=(int)(m);(i)++)
#define push_back pb
#define make_pair mp
using namespace std;
typedef long long ll;
int A,B,C; 
typedef long double ld;
int main(){
	cin>>A>>B>>C;
	if(C-(A-B)>=0)cout<<C-(A-B);
	else cout<<"0";
	return 0;
}

Measured memory_bytes: 256
N,M,X=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(N)]
ans=float("inf")
for i in range(2**N):
  price=0
  abil=[0]*M
  for j in range(N):
    if (i>>j)&1==1:
      #その本を購入する場合
      price+=li[j][0]
      #購入代金がpriceに加算される
      for k in range(1,M+1):
        abil[k-1]+=li[j][k]
        #購入したらその分の能力が各能力に加算される
  if min(abil)>=X:
    ans=min(ans,price)
if ans==float("inf"):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9112