akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        m: usize,
        target: [(Usize1, Usize1); m]
    }
    let mut bh = vec![];
    let mut bw = vec![];
    for i in 0..h {
        bh.push((0usize, i));
    }
    for i in 0..w {
        bw.push((0usize, i));
    }
    let mut set = BTreeSet::<_>::new();
    for &(h, w) in target.iter() {
        set.insert((h, w));
        bh[h].0 += 1;
        bw[w].0 += 1;
    }
    bh.sort_by(|a, b| b.cmp(a));
    bw.sort_by(|a, b| b.cmp(a));
    let mh = bh[0].0;
    let mw = bw[0].0;

    let mut kh = vec![];
    let mut kw = vec![];
    for i in 0..h {
        if bh[i].0 != mh {
            break;
        }
        kh.push(bh[i].1);
    }
    for i in 0..w {
        if bw[i].0 != mw {
            break;
        }
        kw.push(bw[i].1);
    }
    for &i in kh.iter() {
        for &j in kw.iter() {
            if !set.contains(&(i, j)) {
                println!("{}", mh + mw);
                return;
            }
        }
    }
    println!("{}", mh + mw - 1);
}


Measured memory_bytes: 35460
/*
ID: skipian1
PROB: 
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second

int main() {
  int n;
  cin >> n;
  int arr[n];
  int dp[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    dp[i] =  1e9;
  }
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = i-2; j < i; j++) {
      if (j < 0) continue;
      dp[i] = min(dp[i], abs(arr[i]-arr[j])+dp[j]);
    }
  }
  cout << dp[n-1] << "\n";
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    vector<int> v(N);

    rep(i, N) cin >> v[i];

    int ans = 0;
    rep(l, K + 1) {
        rep(r, K - l + 1) {
            if (l + r > N) continue;
            int d = K - l - r;
            int sum = 0;
            vector<int> s;
            rep(i, l) {
                sum += v[i];
                s.push_back(v[i]);
            }
            rep(i, r) {
                sum += v[N - i - 1];
                s.push_back(v[N - i - 1]);
            }
            sort(s.begin(), s.end());
            rep(i, d) {
                if (i >= s.size()) break;
                if (s[i] >= 0) break;
                sum -= s[i];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


N = int(input())

edge = {}
for _ in range(N):
    tmp = inpl()
    u, k = tmp[:2]
    edge[u] = tmp[2:]

d = {i: -1 for i in range(1, N + 1)}
d[1] = 0
Q = deque()
Q.append(1)
while Q:
    v = Q.popleft()
    for nv in edge[v]:
        if d[nv] != -1:
            continue
        d[nv] = d[v] + 1
        Q.append(nv)

for i in range(1, N + 1):
    print(i, d[i])



Measured memory_bytes: 6032
sub i{$t=<STDIN>;$t=~s/[¥r¥n]+//;return split/ /,$t;}@c=i;for($j=0;$j<$c[2];$j++){@d=i;if($d[1]<=$d[0]){${$s[$d[1]]}[@{$s[$d[1]]}]=$d[0];}}$e=$c[0]+1;$f=1;for($j=1;$j<=$c[1];$j++){foreach $g(sort{$a<=>$b}@{$s[$j]}){if($f==$g){$f++;}if($f<$g&&$e>$g){$e=$g;}}$f++;}$e--;print"$e";

Measured memory_bytes: 28352
# 反復深化

# 距離
distance = (
    (),
    (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6),
    (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5),
    (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4),
    (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3),
    (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5),
    (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4),
    (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3),
    (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2),
    (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4),
    (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3),
    (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2),
    (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1),
    (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3),
    (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2),
    (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1)
)

# 距離を求める
def get_distance(board):
    sd = 0
    for i in range(16):
        p = board[i]
        if p == 0:
            continue
        sd += distance[p][i]
    return sd

adjacent = (
    (1, 4),         # 0
    (0, 2, 5),      # 1
    (1, 3, 6),      # 2
    (2, 7),         # 3
    (0, 5, 8),      # 4
    (1, 4, 6, 9),   # 5
    (2, 5, 7, 10),  # 6
    (3, 6, 11),     # 7
    (4, 9, 12),     # 8
    (5, 8, 10, 13), # 9
    (6, 9, 11, 14), # 10
    (7, 10, 15),    # 11
    (8, 13),        # 12
    (9, 12, 14),    # 13
    (10, 13, 15),   # 14
    (11, 14)        # 15
)

GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]

# 下限値枝刈り法
def df_lower_search(limit, move, space, lower, pre_p):
    if move == limit:
        if board == GOAL:
            return True
    else:
        for i in adjacent[space]:
            p = board[i]
            if p == pre_p:
                continue
            board[space] = p
            board[i] = 0
            new_lower = lower - distance[p][i] + distance[p][space]
            if new_lower + move <= limit:
                if df_lower_search(limit, move + 1, i, new_lower, p):
                    return True
            board[space] = 0
            board[i] = p

import sys

board = list(map(int, sys.stdin.read().split()))

s = board.index(0)
e_o = (0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0)

n = get_distance(board)

if e_o[s] != n % 2:
    n += 1

for l in range(n, 46, 2):
    if df_lower_search(l, 0, s, n, None):
        print(l)
        break
        




Measured memory_bytes: 5772
n = int(input())
s = input()
l = 0
r = n - 1

ans = 0
while True:
    while l < n and s[l] == 'R':
        l += 1
    while r >= 0 and s[r] == 'W':
        r -= 1
    if l > r:
        break
    ans += 1
    l += 1
    r -= 1

print(ans)

Measured memory_bytes: 9480
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;

typedef long long ll;

ll cnt_m;
ll cnt_b;

//分割統治で考える。Aはもともとswapされる配列なので、mergeSortで分割した後、R[]の項が選ばれれば
//swap回数が減る。

ll merge(int A[],int left,int mid,int right)
{
  ll res = 0;
  
  int n1 = mid - left;
  int n2 = right - mid;

  int L[n1+1],R[n2+1];
  for(int i=0;i < n1;i++){
    L[i] = A[left+i];
  }
  for(int i=0;i < n2;i++){
    R[i] = A[mid+i];
  }
  
  L[n1]=R[n2]=INF;
  
  int i=0,j=0;
  for(int k=left;k < right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
      res += n1-i;
      //R[]の項が選ばれたとき、swapの回数が減る。(iが増える)
    }
  }
  return res;
}

ll mergeSort(int A[],int left,int right)
{
  ll cnt1,cnt2,cnt3;
  
  if(left+1 < right){
    int mid = (left + right)/2;
    cnt1 = mergeSort(A,left,mid);
    cnt2 = mergeSort(A,mid,right);
    cnt3 = merge(A,left,mid,right);
    return cnt1+cnt2+cnt3;
  }
  else return 0;
}

int bubbleSort(int A[],int n)
{
  int i,j;
  int temp;
  
  for(i = 0; i < n ;i++){
    for(j = n-1; j > i ;j--){
      
      if( A[j-1] > A[j] ){
	swap(A[j-1],A[j]);
	cnt_b++;
      }
    }
  }
}

int main()
{
  int i;
  int n;
  int A[200001];
  int B[200001];
  
  scanf("%d",&n);

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

  cnt_m = mergeSort(A,0,n);

  //bubbleSort(B,n);

  //for(int i=0;i < n;i++) cout << A[i];
  //cout << endl;

  //cout << cnt_m << endl << "cnt_b = " << cnt_b << endl;
  cout << cnt_m << endl;
  return 0;
}



Measured memory_bytes: 4808
x,y,deg = 0,0,90
while line = gets do
	l,d = line.split(",").map(&:to_i)
	x += l*Math.cos(deg/180.0*Math::PI)
	y += l*Math.sin(deg/180.0*Math::PI)
	deg -= d
end
puts "#{x.to_i}\n#{y.to_i}"

Measured memory_bytes: 8768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename F>
class SegmentTree{
private:
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<=n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

template<class T>
struct Compress{
    map<T,int> idx;
    map<int,T> value;
    vector<T> cmp;
    int N;
    Compress(vector<T> v){
        for(auto& x:v) cmp.push_back(x);
        sort(cmp.begin(),cmp.end());
        cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
        N = cmp.size();
        for(int i=0;i<N;i++) idx[cmp[i]] = i;
    }
    int id(ll val){return idx[val];}
    T val(int id){return cmp[id];}
};

long double eps = 1e-16;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> v;
    vec<int> T(N),A(N);
    for(int i=0;i<N;i++){
        cin >> T[i] >> A[i];
        v.push_back(T[i]);
    }
    int Q;
    cin >> Q;
    vec<int> L(Q),R(Q);
    for(int i=0;i<Q;i++){
        cin >> L[i] >> R[i];
        v.push_back(L[i]);
        v.push_back(R[i]);
    }
    Compress<int> cmp(v);
    int n = cmp.N;
    auto op = [](long double a,long double b){
        return a*b;        
    };
    SegmentTree<long double,decltype(op)> seg(n,op,1);
    for(int i=0;i<N;i++){
        int id = cmp.id(T[i]);
        seg.set(id,1-0.1*A[i]);
    }
    seg.build();
    long double inf = 1e9;
    for(int i=0;i<Q;i++){
        long double p = seg.query(cmp.id(L[i]),cmp.id(R[i])+1);
        cout << fixed << setprecision(10) << inf*p << endl;
    }
}


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

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

const int INF = 1e9;

using namespace std;

stack<tuple<int, int, int> > area;
stack<int> res;
stack<int> downs;

int integrate(int i, int j){
    int value = j-i;
    while(!area.empty() && get<1>(area.top()) >= i && get<2>(area.top()) <= j){
        value += get<0>(area.top());
        area.pop();
    }
    return value;
}

int main() {
    int n, q;
    cin >> n;
    int a[n];
    REP(i, n) cin >> a[i];
    cin >> q;
    int b[q];
    int count = 0;
    REP(i, q) cin >> b[i];

    REP(j, q) REP(i, n){
        if(a[i] == b[j]){
            count++;
            break;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1240
<?php

while ($stdin = fgets(STDIN)) {
    $line[] = trim($stdin);
}
foreach ($line as $key => $value) {
    $data[] = explode(' ', $value);
}

//foreach ($data as &$line) {
//    $line = array_map(function($val) { return (int)$val; }, $line);
//}


$s = $data[0][0];
$length = strlen($s);

$unbalance = false;
$unbalancePoint = null;
for ($i = 0; $i < $length - 1; $i++) {
    if (substr($s, $i, 1) === substr($s, $i+1, 1)) {
        $unbalance = true;
        $unbalancePoint = [$i+1, $i+2];
    }
}

if (!$unbalance) {
    for ($i = 0; $i < $length - 2; $i++) {
        $threestr = substr($s, $i, 3);
        $one = substr($threestr, 0, 1);
        $two = substr($threestr, 1, 1);
        $three = substr($threestr, 2, 1);
        if ($one === $two || $one === $three || $two === $three) {
            $unbalance = true;
            $unbalancePoint = [$i+1, $i+3];
        }
    }
}

$ans = $unbalance ? $unbalancePoint[0] . ' ' . $unbalancePoint[1] : '-1 -1';

printf('%s', $ans);


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

ll GetMinValue(ll x, ll k, ll d)
{
	x = abs(x);
	ll n = x / d;
	if (k < n) return x - k * d;
	else {
		if (n % 2 == k % 2) return x - n * d;
		else return min(x - (n - 1) * d, abs(x - (n + 1) * d));
	}
}

int main()
{
	ll x, k, d;
	cin >> x >> k >> d;
	cout << GetMinValue(x, k, d) << endl;
}


Measured memory_bytes: 3632
#include <iostream>
 
using namespace std;
 
int main() {
  int N, M;
  cin >> N >>M;
 
  int a[M],b[M];
  for(int i=0;i<M;++i){
    cin >> a[i] >> b[i];
  }
  
  bool from_one[N],to_n[N];
  for (int i=0;i<N;++i){
    from_one[i] = false;
    to_n[i] = false;
  }
  for (int i=0;i<M;i++){
    if(a[i] == 1){from_one[b[i]-1] = true;}
    if(b[i] == N){to_n[a[i]-1] = true;}
  }
  
  string ans="IMPOSSIBLE";
  for(int i=0;i<N;++i){
    if(from_one[i] && to_n[i]){
      ans = "POSSIBLE";
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2176
N,M = map(int, input().split(" "))
masks = []
for _ in range(M):
    mask = 0
    for s in list(map(int, input().split(" ")))[1:]:
        mask += 1 << (s-1)
    masks.append(mask)
p = list(map(int, input().split(" ")))

ans = 0
for d in range(1 << N):
    flg = True
    for i in range(M):
        if bin(d & masks[i]).count("1") % 2 != p[i]:
            flg = False
            break
    if flg: ans += 1
print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0065
"""
import sys
from collections import Counter


def analyze_data(this_month, last_month):
    result = []
    tm = Counter(this_month)
    lm = Counter(last_month)

    for ele in lm:
        if ele in tm:
            c = lm[ele] + tm[ele]
            result.append([ele, c])
    result.sort()
    return result



def main(args):
    this_month = []
    last_month = []
    month = this_month
    for line in sys.stdin:
        if len(line) == 1:      #  ??\??????????????????
            month = last_month
        else:
            id, date = line.strip().split(',')
            month.append(int(id))
    # this_month = [1, 123, 56, 34, 23, 1, 23]
    # last_month = [123, 56, 123, 123, 1, 777, 777, 777]
    result = analyze_data(this_month, last_month)

    for d in result:
        print('{} {}'.format(d[0], d[1]))


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

Measured memory_bytes: 7896
import sys
from collections import deque

n = int(sys.stdin.readline())
G = [[] for _ in range(n+1)]
G_order = []
for i in range(n-1):
    a,b = map(lambda x:int(x)-1, sys.stdin.readline().split())
    G[a].append(b)
    G_order.append(b)

que = deque([0])
C = [0]*(n+1)
while que:
    nw = que.popleft()
    c = 1
    for nx in G[nw]:
        if c==C[nw]:
            c+=1
        C[nx] = c
        c += 1
        que.append(nx)

print(max(C))
for i in G_order:
    print(C[i])

Measured memory_bytes: 23336
#coding:utf-8
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

for i,p in enumerate(permutations(range(1,N+1))):
    if p==P:
        a = i
    if p==Q:
        b = i

print (abs(a-b))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  vi dp(n,INF);
  deque<P> q;
  q.eb(1,1);
  while (sz(q)) {
    int x = q[0].fi, d = q[0].se; q.pop_front();
    if (dp[x] != INF) continue;
    dp[x] = d;
    q.emplace_front((x*10)%n, d); 
    q.eb((x+1)%n, d+1); 
  }
  cout<<dp[0]<<endl;
  return 0;
}






















Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
#define PI 3.141592653589793
#define p ps[pi]


struct P{
public:
	int m;
	float g;	// =m/M
	float ath,ax,ay;
	float bth,bx,by;
	float oldarea,newarea;
	float re;
};


int main(){
	int R,X,Y,pl;
	cin>>R>>X>>Y>>pl;
	P ps[pl];
	int M=0;
	REP(pi,pl){
		cin>>p.m;
		M+=p.m;
	}
	
	float th=0;
	REP(pi,pl){
		p.ath=th;
		p.g=float(p.m)/M;
		th+=p.g*2*PI;
		p.bth=th;

		p.ax=R*sin(p.ath);
		p.ay=R*cos(p.ath);
		p.bx=R*sin(p.bth);
		p.by=R*cos(p.bth);

		p.oldarea=(p.bth-p.ath)*R*R/2;
		p.newarea = p.oldarea + (p.ax*Y-p.ay*X)/2 + (X*p.by-Y*p.bx)/2;

		p.re = p.newarea/p.oldarea;
		cout<<INT(p.re*100);
		if(pl-pi-1) cout << " "; else cout<<endl;
	}

}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll 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; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

#define INF 1LL<<60



  int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    ll sum = 0;
    REP(i, n){
       cin >> a.at(i);
       sum += a.at(i);
    }
    ll now = 0, now2 = sum;
    ll ans = INF;
    REP(i, n){
      now += a.at(i);
      now2 -= a.at(i);
      if(i < n - 1)ans = min(ans, abs(now - now2));
    }
    print(ans);
  }


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    ll n, x, m;
    cin >> n >> x >> m;

    vll a(m);
    ll y = x;
    ll st = -1, ed = -1, ly = -1;
    ll ans = 0;
    for (ll i = 0; i < n; ++i)
    {
        ans += y;

        y = (y * y) % m;
        if ((i < n - 1) && a[y])
        {
            st = a[y];
            ed = i + 1;
            ly = y;
            break;
        }
        a[y] = i + 1;
    }
    if (ly == -1)
    {
        cout << ans << endl;
        return 0;
    }

    y = x;
    ans = 0;
    rep(i, st)
    {
        ans += y;
        y = (y * y) % m;
    }

    ll k = ed - st;
    n -= st;
    ll lop = 0;
    rep(i, k)
    {
        lop += y;
        y = (y * y) % m;
    }
    ans += (n / k) * lop;
    n = n % k;
    rep(i, n)
    {
        ans += y;
        y = (y * y) % m;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);cout<<"\n";};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...);}
//FUNCTION

//BELOW
void solve(void)
{ 
  int N;
  cin>>N;
  vector<int> C(N),S(N),F(N);
  for (int i = 0; i < N-1; i++)
  {
    cin>>C[i]>>S[i]>>F[i];
  }
  vector<int> ANS(N,0);
  for (int i = 0; i < N-1; i++)
  {
    int pos = i;
    int TIME = 0;
    for (int p = i; p < N-1; p++)
    {
      if(TIME <S[p]) TIME = S[p];
      if(TIME % F[p] != 0) TIME += F[p] - TIME%F[p];
      TIME += C[p];
    }
    ANS[i] = TIME;

    

  }
  for (int i = 0; i < N; i++)
  {
    cout<<ANS[i]<<endl;
  }
  
  
  return;
}
  
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int main() {
	lli a;
  cin >> a;
  string s;
  lli k[4]={0};
  for(lli i=0; i<a; i++)
  {
    cin >> s;
    if(s=="AC") k[0]++;
    else if(s=="WA") k[1]++;
    else if(s=="TLE") k[2]++;
    else if(s=="RE") k[3]++;
  }
  cout << "AC x " << k[0] << endl;
  cout << "WA x " << k[1] << endl;
  cout << "TLE x " << k[2] << endl;
  cout << "RE x " << k[3] << endl;
	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	queue<ll> q;
	
	for (int i = 1; i < 10; ++i)
		q.push(i);
	
	long k; std::cin >> k;
	ll x;
	while (k-- != 1) {
		x = q.front();
		q.pop();
		if (x % 10 != 0)
			q.emplace(10 * x + x % 10 - 1);
		
		q.emplace(10 * x + x % 10);
		
		if (x % 10 != 9)
			q.emplace(10 * x + x % 10 + 1);
	}
	
	std::cout << q.front();
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a - 1]++;
    m[a]++;
    m[a + 1]++;
  }

  int mx = -1;
  for (auto mm : m) {
    int sec = mm.second;
    if (mx < sec) {
      mx = sec;
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){
  int a[10];
  rep(i,5){
    cin >> a[i];
    if(a[i] == 0){
      cout << i+1 << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
long double calc(ll x) {
    long double prob = 1./x;
    return ((x-1)/2+1)*prob;
}
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n, -1); }

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

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

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    SS(ll,N,K,L)
    UnionFind uf(N);
    UnionFind uf2(N);
    rep(i,K){
        SS(ll,p,q);
        p--;q--;
        uf.unite(p,q);
    }
    rep(i,L){
        SS(ll,r,s);
        r--;s--;
        uf2.unite(r,s);
    }
    map<pair<int,int>,int>ma;
    rep(i,N)ma[{uf.root(i),uf2.root(i)}]++;
    //同じ根のペアの数を列挙
    rep(i,N)cout<<ma[{uf.root(i),uf2.root(i)}]<<" ";

}

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

int main() {
  vector<int> digit;
  int a,b;
  cin >> a;
  cout<<" ";
  cin >> b;
  while(a>=b){
    digit.push_back(a%b);
    a=a/b;
  }
  cout<< digit.size()+1 <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int main(void){
  double l;
  scanf("%lf",&l);
  PRF(l*l*l/27);
  return 0;
}

Measured memory_bytes: 1752
N = int(input())
x = [0] * N
u = [0] * N
for i in range(N):
    x[i],u[i] = map(str, input().split())
    x[i] = float(x[i])

sum = 0

for i in range(N):
    if (u[i] == 'JPY'):
        sum += x[i]
    elif (u[i] == 'BTC'):
        sum += x[i] * 380000
    else:
        break
print(sum)

Measured memory_bytes: 3064
#include <cstdio>

const int N = 200100;
const int MOD = 1000000007;

int a[N], b[N];
int dp[4010][4010];
int val[4010][4010];
int val2[4010][4010];
long long fat[8010], inv[8010];


long long fpow(long long a, long long b){
	long long c = 1;
	for(;b;b>>=1, a=(a*a)%MOD)if(b&1)c=(c*1ll*a)%MOD;
	return c;
}

void calcfat(int qtd){
	fat[0]=1;
	for(int i = 1; i <= qtd; i++){
		fat[i]=(fat[i-1]*1ll*i)%MOD;
	}
}

void calcinv(int qtd){
	inv[0]=1;
	for(int i = 1; i <= qtd; i++){
		inv[i]=fpow(fat[i],MOD-2);
	}
}
long long comb(int a, int b){
	return (((fat[2*a+2*b]*inv[2*a])%MOD)*inv[2*b])%MOD;
}

int main(){
	int n;
	scanf("%d", &n);
	calcfat(8001);
	calcinv(8001);
	long long ans = 0;
	for(int i = 0; i <= 8001; i++){
		//printf("%lld ",fat[i]);
	}
	//puts("");
	for(int i = 0; i < n; i++){
		int a, b;
		scanf("%d %d",&a,&b);
		ans = (ans - comb(a,b) + MOD) % MOD;
		//printf("%lld\n",ans);
		val2[2001+a][2001+b]++;
		val[2001-a][2001-b]++;
	}
	//printf("%lld\n",ans);
	for(int i = 1; i <= 4001; i++){
		for(int j = 1; j <= 4001; j++){
			dp[i][j]=((dp[i-1][j]+dp[i][j-1]) % MOD + val[i][j])%MOD;
			if(i>2001 && j>2001 && val2[i][j]>0){
				ans+=(val2[i][j]*1ll*dp[i][j])%MOD;
				ans%=MOD;
			}

			dp[i][j]%=MOD;
		}
	}
	ans = (ans *1ll* fpow(2,MOD-2))%MOD;
	printf("%lld\n",ans);

}

Measured memory_bytes: 126848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = a; i < b; i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

int main() {
	fast_io;
	int n,m; cin>>n>>m;
	int sum=0;
	lp(i,0,m){
		int t; cin>>t;
		sum+=t;
	}
	if(sum<=n) cout<<n-sum;else cout<<"-1";
}

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

const int AMAX = 100010;
ll bk[AMAX];

int main(void) {
    int n;
    ll k;
    cin >> n >> k;

    rep(i, 0, n) {
        ll a, b;
        cin >> a >> b;
        bk[a] += b;
    }

    ll cur = 0;
    rep(i, 0, AMAX) {
        cur += bk[i];
        if (cur >= k) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10;
int n, a[N], b[N], c[N], d[N][4];
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    d[1][1] = a[1];
    d[1][2] = b[1];
    d[1][3] = c[1];
    for(int i = 2; i <= n; i++)
    {
        d[i][1] = max(d[i - 1][2], d[i - 1][3]) + a[i];
        d[i][2] = max(d[i - 1][1], d[i - 1][3]) + b[i];
        d[i][3] = max(d[i - 1][1], d[i - 1][2]) + c[i];
    }
    cout << max(d[n][1], max(d[n][2], d[n][3]));
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

#include "atcoder/dsu"
using namespace atcoder;

signed main(){
	int N, Q;
	cin >> N >> Q;
	dsu d(N);
	while(Q--) {
		int t, u, v;
		cin >> t >> u >> v;
		if(t == 0) d.merge(u, v);
		else {
			if(d.same(u, v)) {
				out(1);
			} else {
				out(0);
			}
		}
	}
}

Measured memory_bytes: 4856
defmodule Main do
  def main do
    [a,b]=IO.gets("") |> String.trim |> String.split(" ")
    x=String.to_integer(a)
    y=String.replace(b,".","")
    |>String.to_integer
    x*y
    |> Integer.to_string
    |> String.slice(0..-3)
    |> (fn x->if x=="" do
    IO.puts("0")
    else
    IO.puts(x)
    end
    end).()
  end
end


Measured memory_bytes: 31364
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	if (x > y) {
		if (a > c * 2)cout << x * c * 2 << endl;
		else if (a + b > c * 2)cout << c * 2 * y + a * (x-y) << endl;
		else cout << a * x + b * y << endl;
	}
	else {
		if (b > c * 2)cout << y * c * 2 << endl;
		else if (a + b > c * 2)cout << c * 2 * x + b * (y-x) << endl;
		else cout << a * x + b * y << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

bool rev(ll a, ll b) {
	return a > b;
}

ll calc_r(vector<ll> &arr, ll x) {
	int pos = upper_bound(arr.begin(),arr.end(),x)-arr.begin();
	if(pos>=arr.size()) return 1LL<<50LL;
	return arr[pos]-x;
}

ll calc_l(vector<ll> &arr, ll x) {
	int pos = upper_bound(arr.begin(),arr.end(),x,rev)-arr.begin();
	if(pos>=arr.size()) return 1LL<<50LL;
	return x-arr[pos];
}

int main() {
	ll a,b,q;
	cin >> a >> b >> q;
	vector<ll> s(a),t(b);
	for(int i = 0; i < a; i++) {
		cin >> s[i];
	}
	for(int i = 0; i < b; i++) {
		cin >> t[i];
	}
	vector<ll> s_rev(s), t_rev(t);
	reverse(s_rev.begin(),s_rev.end());
	reverse(t_rev.begin(),t_rev.end());
	for(int query = 0; query < q; query++) {
		ll x;
		cin >> x;
		ll s_r = calc_r(s,x);
		ll t_r = calc_r(t,x);
		ll s_l = calc_l(s_rev,x);
		ll t_l = calc_l(t_rev,x);
		ll ans = 1LL<<50LL;
		ans = min(ans,max(s_r,t_r));
		ans = min(ans,max(s_l,t_l));
		ans = min(ans,min(s_r*2+t_l,s_r+t_l*2));
		ans = min(ans,min(t_r*2+s_l,t_r+s_l*2));
		//cout << s_r << "," << s_l << "," << t_r << "," << t_l << endl;
		//cout << min(min(max(s_r,t_r),max(s_l,t_l)),min(s_r,s_l)+min(t_r,t_l)) << endl;
		cout << ans << endl;
	}
}


Measured memory_bytes: 4480
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 505;
int f[maxn], g[maxn];
int a[maxn][maxn];

void get(int l, int r) {
    /* debug("get %d %d\n", l, r); */
    int n = r - l + 1;
    if(n <= 2) {
        a[l][r] = f[n];
        return;
    }
    int mid = l + g[n] - 1;
    get(l, mid);
    get(mid + 1, r);
    for(int i = l; i <= mid; i ++)
        for(int j = mid + 1; j <= r; j ++)
            a[i][j] = f[n];
}

int main() {
    int n = input();
    f[1] = f[2] = 1;
    for(int i = 3; i <= n; i ++) {
        f[i] = 1000000000;
        for(int j = 1; j < i; j ++) {
            int v = std::max(f[j], f[i - j]) + 1;
            if(v < f[i]) {
                f[i] = v;
                g[i] = j;
            }
        }
    }

    /* for(int i = 1; i <= n; i ++) */
    /*  debug("%d %d\n", f[i], g[i]); */

    get(1, n);
    for(int i = 1; i < n; i ++) {
        for(int j = i + 1; j <= n; j ++)
            printf("%d ", a[i][j]);
        puts("");
    }
}


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

int main() {
  int H, W;

  while (1) {
    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int dp[maxn][4];
int main()
{
    int n;
    cin>>n;
    int ans =0;
    for(int i=1;i<=n;i++)
    {
        cin>>dp[i][1]>>dp[i][2]>>dp[i][3];
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2]);
        ans = max(dp[i][1],max(dp[i][2],dp[i][3]));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string s, t;
	cin >> s >> t;

	// 文字を数で表現
	vector<int> start(26, -1);
	vector<int> end(26, -1);
	
	REP(i, s.size()){
		int a = s[i] - 'a';
		int b = t[i] - 'a';
		if(start[a] != -1 or end[b] != -1){
			if(a != end[b] or b != start[a]){
				cout << "No" << endl;
				rtn 0;
			}
		}
		else{
			start[a] = b;
			end[b] = a;
		}
	}
	cout << "Yes" << endl;
	rtn 0;
}

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

long long n;
int cnt = 0;

int main(){
	cin >> n;
	if (n == 2){
		cout << 0 << endl;
		return 0;
	}
	if (n == 1){
		cout << 0 << endl;
		return 0;
	}
	long long ans = 0;
	for (long long i = 1; i * i <= n; i++){
		if (n % i) continue;
		if (n / (n / i - 1) == n % (n / i - 1)) ans += n / i - 1;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
	int N;
	cin >> N;
	map < string, int >result =
	    { {"AC", 0}, {"WA", 0}, {"TLE", 0}, {"RE", 0} };

	vector < string > S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	for (int i = 0; i < N; i++) {
		result[S[i]]++;
	}

	cout << "AC x " << result["AC"] << endl;
	cout << "WA x " << result["WA"] << endl;
	cout << "TLE x " << result["TLE"] << endl;
	cout << "RE x " << result["RE"] << endl;

	return 0;
}


Measured memory_bytes: 6372
targets = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]
n = int(input())
for i in range(n):
	b, f, r, v = map(int, input().split())
	targets[b - 1][f - 1][r - 1] += v
s = '#' * 20
index = 0
for target in targets:
	for t in target:
		print(' ' + ' '.join(list(map(str, t))))
	if index < 3: 
		print(s)
	index += 1


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX=1e6;
int a[MAX],f[MAX];

signed main()
{
	int n,d;
	int x,y;
	int dem=0;
	cin >> n >> d;
	for (int i=1;i<=n;i++)
	{
		cin >> x  >> y;
		if (x*x+y*y<=d*d) dem++;
	}
	cout << dem;
}

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

typedef long long ll;

const int N = 4000;

int a[2*N + 5], n, x;

int le[2*N + 5], ri[N + 5];

ll s[2*N + 5];

int main() {
	scanf("%d%d", &n, &x);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]), a[n + i] = a[i];
	a[0] = a[2*n + 1] = 0;
	for(int i=1;i<=2*n;i++) {
		le[i] = i - 1;
		while( a[le[i]] >= a[i] ) le[i] = le[le[i]];
	}
	for(int i=2*n;i>=1;i--) {
		ri[i] = i + 1;
		while( a[ri[i]] > a[i] ) ri[i] = ri[ri[i]];
	}
	for(int i=1;i<=n;i++) {
		int p = (n + i) - le[n + i], q = ri[i] - i;
		s[0] += a[i], s[min(p, q)] -= a[i];
		s[max(p, q)] -= a[i], s[min(p, q) + max(p, q)] += a[i];
		
	}
	
	for(int i=1;i<=n;i++) s[i] += s[i - 1];
	for(int i=1;i<=n;i++) s[i] += s[i - 1];
	
	ll ans = (1ll << 60);
	for(int i=0;i<=n;i++) ans = min(ans, s[i] + 1ll*i*x);
	printf("%lld\n", ans);
}


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

long long A, B, C;
int solve() {
    for (int i = 0; i < 1000; ++i) {
        if (A & 1) return i;
        if (B & 1) return i;
        if (C & 1) return i;
        long long tA = (B + C) / 2;
        long long tB = (C + A) / 2;
        long long tC = (A + B) / 2;
        A = tA, B = tB, C = tC;
    }
    return -1;
}


int main() {
    cin >> A >> B >> C;
    cout << solve() << endl;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, mod = 1e9 + 7;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	vector<long long> b(n);
	b[n - 1] = a[n - 1];
	for (int j = n - 2; j >= 0; j--) b[j] = (b[j + 1] + a[j])%mod;
	long long ans{};
	for (int i = 0; i < n - 1; i++) ans = (ans + a[i]*b[i + 1])%mod;
	cout << ans;
}


Measured memory_bytes: 6360
import  java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		// 標準入力からデータを読み込む準備 
		Scanner sc = new Scanner(System.in); // 最初の文字の固まりを整数値と想定して読み込む 
		int x = sc.nextInt();
		int answer = x*x*x; 
		System.out.println(answer);   
		sc.close();

	}

}


Measured memory_bytes: 26168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		
		double dist = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
		System.out.println(dist);
	}
}



Measured memory_bytes: 28036
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<iostream>
#include<algorithm>//next_permutation
#include <cmath>

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int sort(const void *a, const void *b){
  int A = *(int *)a, B = *(int *)b;
  if(A > B) return  1;
  if(A < B) return -1;
  return 0;
}

int dsort(const void *a, const void *b){
  int A = *(int *)a, B = *(int *)b;
  if(A < B) return  1;
  if(A > B) return -1;
  return 0;
}

int
main(int argc, char *argv[])
{
  int n, a[500]; int sum = 0;
  int k;
  scanf("%d %d", &n, &k);
  rep(i, n){
    scanf("%d", &a[i]);
    sum += a[i];
  }

  int y[100000]; int l = 0;
  int x = (int)sqrt((float)sum); 
  for(int i = 1; i <= x; i++){
    if(sum % i == 0 && sum / i != i){
      y[2 * l] = i;
      y[2 * l + 1] = sum / i;
      l++;
    }
    else if(sum % i == 0 && sum / i == i){
      y[2 * l] = i;
      y[2 * l + 1] = 1000000000;
      l++;
    }
  }

  l = 2 * l;
  qsort(y, l, sizeof(int), sort);
  if(sum == x * x) l--;


  int cnt = 0; int f; int flag;
  for(int i = l - 1; i >= 0; i--){
    int c[500]; int s = 0;
    for(int j = 0; j < n; j++){
      c[j] = a[j] % y[i];
      s += c[j];
    }
    cnt = s / y[i];
    
    qsort(c, n, sizeof(int), dsort);

    f = 0;
    for(int j = 0; j < cnt; j++){
      f += y[i] - c[j];
    }

    if(f <= k){
      printf("%d\n", y[i]);
      break;
    }
  }

  return 0;
}

  
    


Measured memory_bytes: 256