akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    int m,n;
    m=a*100/8;
    if(m*8/100!=a) m++;
    n=b*10;
    //cout << m << " " << n << endl;
    if(m>n){
        if(m/10==b){
            cout << m << endl;
            return 0;
        }
    }else{
        if(n*8/100==a){
            cout << n << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

class union_find {
public:
	union_find(const int N) :v(N), size(N) {
		tree_num = N;
		rep(i, N)v[i] = i;
		rep(i, N)size[i] = 1;
	}

	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b)return;

		if (size[a] < size[b])swap(a, b);
		v[b] = a;
		size[a] += size[b];
		tree_num--;
	}

	bool same(int a, int b) { return find(a) == find(b); }

	int get_size(int a) {
		return size[find(a)];
	}
	int get_tree_num() { return tree_num; }

	vector<int> v;
	vector<int> size;
	int tree_num;

	int find(int a) {
		if (v[a] == a)return a;
		return v[a] = find(v[a]);
	}
};


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int N, K, L;
	cin >> N >> K >> L;
	union_find road(N);
	rep(i, K) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		road.unite(p, q);
	}
	union_find rail(N);
	rep(i, L) {
		int r, s;
		cin >> r >> s;
		r--; s--;
		rail.unite(r, s);
	}
	rep(i, N)road.find(i);
	rep(i, N)rail.find(i);
	vector<array<int, 2>>vec(N);
	rep(i, N)vec[i] = { road.v[i] + (rail.v[i] * 300000), i};
	sort(ALL(vec));


	union_find roadrail(N);
	REP(i, 1, N)if (vec[i - 1][0] == vec[i][0])roadrail.unite(vec[i - 1][1], vec[i][1]);

	rep(i, N) {
		cout << roadrail.get_size(i) << endl;
	}


	return 0;
}


Measured memory_bytes: 13056
import sys
n,c,k,*t = map(int, sys.stdin.read().split())
t.sort()

i=0
cnt=0
while i<n:
  departure=t[i]+k
  p=0
  for j in range(i,n):
    if t[j] > departure or p==c:
      break
    p+=1
  i+=p
  cnt+=1
print(cnt)



Measured memory_bytes: 19908
//#include "bits\stdc++.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long LL;

int main()
{
    size_t n;
    string str;

    cin >> str;

    n = str.size();

    cout << str[0] << n - 2 << str[n - 1] << endl;

    return 0;
}

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(){
    int N;
    cin >> N;
    string name;

    map<string,int> pp;
    int mx = -1;
    rep(i,N){
        cin >> name;
        if(pp.count(name)) pp.at(name)++;
        else pp[name] = 1;
        mx = max(mx,pp.at(name));
    }

    for(auto p: pp){
        if(p.second == mx) cout << p.first << endl;
    }
}   

Measured memory_bytes: 25216
n = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
flag = True
for i in reversed(range(len(A))):
  if flag is False:
    flag = True
    continue
  if i - 1 < 0:
    continue
  ans += A[i - 1]
  flag = False
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 100000
 
typedef struct{
  int p;
  int l;
  int r;
}id;
   
id A[MAX];
int n,B[MAX];
 
   
int rec(int x,int y){
  B[x] = y;
  if(A[x].r != -1) rec(A[x].r,y);
  if(A[x].l != -1) rec(A[x].l,y + 1);
}


int main(){
  int i,j,d,v,c,l,r,n,op;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = A[i].l = A[i].r = -1;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) A[v].l=c;
      else A[l].r = c;
      l=c;
      A[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == -1) r=i;
  }
 
  rec(r,0);
 
  for(i=0;i<n;i++){
    
    printf("node %d: parent = %d, depth = %d,",i,A[i].p,B[i]);
    if(A[i].p == -1) printf(" root,");
    else if(A[i].l == -1 ) printf(" leaf,");
    else printf(" internal node,");
    printf(" [");
    op=A[i].l;
    for(j=0;op!=-1;j++){
      if(j != 0) printf(", ");
      printf("%d",op);
      op = A[op].r;
    }
    printf("]\n");  
  }
 
  return 0;
}

Measured memory_bytes: 5296
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val K = ni()
    val S = ns()
    if (S.length <= K) out.println(S)
    else {
      out.println("${S.take(K)}...")
    }
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


Measured memory_bytes: 36076
#include <iostream>
using namespace std;
 
int main () {
  int N, sum = 0;
  int A[20], C[20];
  cin >> N;
  for (int i=0; i<N; i++)
    cin >> A[i];
  for (int i=0 ; i<N; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
  }
  for (int i=0; i<N-1; i++)
    cin >> C[i];
  
  for (int i=0; i<N-1; i++)
    if ((A[i+1]-A[i]) == 1)
      sum += C[A[i]-1];
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx;
	int dy = ty - sy;
	string s;
	rep(i, dx) s += 'R';
	rep(i, dy) s += 'U';
	rep(i, dx) s += 'L';
	rep(i, dy) s += 'D';
	s += 'D';
	rep(i, dx + 1) s += 'R';
	rep(i, dy + 1) s += 'U';
	s += 'L';
	s += 'U';
	rep(i, dx + 1) s += 'L';
	rep(i, dy + 1) s += 'D';
	s += 'R';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3656
A = int(input())
B = int(input())
C = int(input())
X = int(input())

a = [i for i in range(0,A*500+1,500)]
b = [i for i in range(0,B*100+1,100)]
c = [i for i in range(0,C*50+1,50)]
sum=0

for i in range(len(a)):
    for j in range(len(b)):
        for l in range(len(c)):
            if X == a[i] + b[j] + c[l]:
                sum = sum + 1
print(sum)


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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

LL a,b;

LL x;

int main(){

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

    cin >> a >> b;

    REP(i, b - a ){
        x += i;
        //dump(x);
    }
    cout << x  - a<< endl;


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(s: str):
    if s[2] == s[3] and s[4] == s[5]:
        print(YES)
    else:
        print(NO)
    return


def main():
    s = sys.stdin.readline().strip()  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    Int a, b, c;
    cin >> a >> b >> c;

    if (a + b + 2 * sqrtl(a * b) < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll A, B, C;
string s, t;

int main(){
	cin >> A >> B;
	p(6 - A - B);

	return 0;
}

Measured memory_bytes: 256
n = int(input())

li = [int(x) for x in input().split()]

count = 0
counter = 0

while True:
  for i in range(0,n):
    if li[i] % 2 == 0:
      count+=1
  if count == n:
    counter+=1
    li = [int(li[i]/2) for i in range(0,n)]
    count = 0
  else:
    break
    
print(counter)

Measured memory_bytes: 3060
import numpy as np
import sys

n = int(input())

a = list(map(int, input().split()))

a_sum = sum(a)
# x[i]はi番目のダムに溜まった水の半分
x = []

x_0 = int(a_sum/2)

for i in range(int((n-1)/2)):
    x_0 -= a[2*i+1]

x.append(x_0)
x_tmp = x_0

for i in range(n-1):
    x_tmp = a[i] - x_tmp
    x.append(x_tmp)

for wa in x:
    print(wa*2, end=' ')


Measured memory_bytes: 23064
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL x;cin >> x;
    if(x < 11){
        LL ans = 0;
        if(ans + 6 >= x)cout << 1 << endl;
        else cout << 2 << endl;
    }
    else{
    LL q = x/11;
    LL ans = 0;
    if(q*11>=x)ans = q*2;
    else if(q*11+6 >= x)ans =q*2+1;
    else ans = q*2 +2;
    cout << ans << endl;  
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct mod_fac{
    private:
        vector<ll> f,i_f;
        int n;ll MOD;
    public:
        void init(int n,ll m){
            MOD=m;
            f.resize(n+1,0);
            i_f.resize(n+1,0);
            f[0]=1;
            rep(i,n){
                f[i+1]=f[i]*(i+1)%MOD;
            }
            i_f[n]=power(f[n],MOD-2);
            per(i,n){
                i_f[i]=(i_f[i+1]*(i+1))%MOD;
            }
        }
        ll power(ll a ,ll x){
            if (x==0) return 1;
            if (x==1) return a%MOD;
            if (x==2) return (a*a)%MOD;
            if (x%2==1) return (a*power(power(a,(x-1)/2),2))%MOD;
            return (power(power(a,x/2),2))%MOD;
        }
        ll fac(int x){
            return f[x];
        }
        ll invfac(int x){
            return i_f[x];
        }
        ll comb(int m,int k){
            if (m<0 or k<0) return 0;
            if (m<k) return 0;
            return (((f[m]*i_f[k])%MOD)*i_f[m-k])%MOD;
        }
};

ll n,a,b,c,ans=0;

void solve(){
    cin >> n >> a >> b >> c;
    mod_fac mo;mo.init(2*n+1,mod);
    ll A=a*mo.power(a+b,mod-2)%mod;
    ll B=b*mo.power(a+b,mod-2)%mod;
    ll C=100ll*mo.power(100ll-c,mod-2)%mod;
    //cout << A << " " << B << " " << C << endl;
    rep(i,n){
        //cout << mo.comb(n-1+i,i) << endl;
        ll a_=n+i;a_*=mo.comb(n-1+i,i);a_%=mod;a_*=mo.power(A,n);a_%=mod;a_*=mo.power(B,i);a_%=mod;
        ll b_=n+i;b_*=mo.comb(n-1+i,i);b_%=mod;b_*=mo.power(B,n);b_%=mod;b_*=mo.power(A,i);b_%=mod;
        //cout << a_ << " " << b_ << endl;
        ans+=a_+b_;
        ans%=mod;
        //scout << ans << endl;
    }
    cout << ans*C%mod<< endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int l, r, d;
    cin >> l >> r >> d;
    while(l % d) l++;
    while(r % d) r--;
    int ans = l > r ? 0 : (r - l) / d + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  long long s,ans,root;
  long long  x1,x2,x3,y1,y2,y3;
  long long lim=1000000000;
  cin>>s;
  long long rest,buf;
  root=sqrt(s);
  ans=s/lim+1;
  rest=lim-s%lim;
  x1=0;
  y1=0;
  x2=lim;
  y2=1;
  x3=rest;
  y3=ans;
  if(s%lim==0){
    y3=s/lim;
    x3=0;
  }
  printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
  //  cout<<x1<<y1<<x2<<y2<<x3<<y3<<endl;
  return 0;
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
a = inp
eda = 1
sum = a.sum()
ans = 0
a.size.times do |i|
  ans += eda
  eda -= a[i]
  sum -= a[i]
  if(eda < 0)
    p -1
    exit
  end
  eda *= 2
  if(eda > sum)
    eda = sum
  end
end
p ans

Measured memory_bytes: 22052
import sys, itertools, collections
sys.setrecursionlimit(10000)

read_ints = lambda: list(map(int, input().split()))
read_int  = lambda: int(input())

SQS = {i * i for i in range(127)}

n, d = read_ints()
p = [read_ints() for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist_sq = sum(
            (p[i][k] - p[j][k]) * (p[i][k] - p[j][k])
            for k in range(d)
        )
        if dist_sq in SQS:
            ans += 1

print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

std::map<long long, long long> mp;
long long A, B, C, D, N;

long long solve(long long n){
  if (mp[n]!=0) return mp[n];
  if (n==0){
    return mp[0];
  } else if (n==1){
    mp[1]=D;
    return mp[1];
  } else if (n==2){
    mp[2]=std::min(2*D, D+A);
    return mp[2];
  } else {
    long long ret=1e18;
    if (1e18/D>=n) ret=n*D;
    ret = std::min(ret, A+D*(n-2*(n/2))+solve(n/2) );
    ret = std::min(ret, A+D*(2*(1+n/2)-n)+solve(n/2+1) );
    ret = std::min(ret, B+D*(n-3*(n/3))+solve(n/3) );
    ret = std::min(ret, B+D*(3*(1+n/3)-n)+solve(n/3+1) );
    ret = std::min(ret, C+D*(n-5*(n/5))+solve(n/5) );
    ret = std::min(ret, C+D*(5*(1+n/5)-n)+solve(n/5+1) );
    mp[n] = ret;
    return mp[n];
  }
}

int main(){
  int T;
  scanf("%d", &T);
  std::vector<long long > out;
  for (int i=0; i<T; i++){
    mp.clear();
    scanf("%lld", &N);
    scanf("%lld", &A);
    scanf("%lld", &B);
    scanf("%lld", &C);
    scanf("%lld", &D);
    long long ans = solve(N);
    out.push_back(ans);
  }
  for (int i=0; i<T; i++){
    std::cout << out[i] << std::endl;
  }
  return 0;
}
 

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

int main() {
    int A, B, ans = 0;
    char op;
    
    cin >> A;
    cin >> op;
    cin >> B;
    
    if (op == '+') ans = A + B;
    if (op == '-') ans = A - B;
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    long long n;int ans=0;
    scanf("%lld",&n);
    for(int i=2;i<=sqrt(n);i++)
    {
    	if(n%i!=0)continue;
    	long long ul=n;
    	while(ul%i==0)ul/=i;
    	if(ul%i==1)ans++;
    }n--;
	for(int i=1;i<=sqrt(n);i++)
    {
    	if(n%i==0)ans+=2;
    	if(1LL*i*i==n)ans--;
    	if(i==1)ans--;
    }pr2(ans+1);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch WalkOnMultiplicationTable | diff WalkOnMultiplicationTable.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address WalkOnMultiplicationTable.cpp && ./a.out

/*
 
 10/27/2019
 
 5:04-
 
 */

LL N;

void solve() {
  LL res=N-1;
  for(LL a=1; a*a<=N; ++a) if(N%a==0) {
    LL b=N/a;
    SMIN(res,b+a-2);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int N;
    int i;
    scanf("%d", &N);
    if(N%10 == 7){
        printf("Yes\n");
        return 0;
    }
    if((N%100)/10 == 7){
        printf("Yes\n");
        return 0;
    }
    if(N/100 == 7){
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n; cin >> n;
	int m=360%n;
	int h=360/n;
	int k=(360/h)-n;
	if(m==0) {
		cout << h << endl;
		return 0;
	}
	cout << 360/k << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int n,k; cin >> n >> k;
  vi a(n); int s = 0;
  rep(i,n) {
    cin >> a[i];
    s += a[i];
  }

  vi divisor;
  for(ll i = 1; i*i <= s; i++) {
    if(s%i == 0){
      divisor.pb(i);
      divisor.pb(s/i);
    }
  }

  int ans = 0;
  for(auto v : divisor) {
    vi b(n); int B = 0;
    rep(i,n) {
      b[i] = a[i]%v;
      B += b[i];
    }

    sort(all(b), greater<int>());

    int cnt = 0;
    int sum = 0;
    for(int i = 0; i < n && sum < B; i++) {
      cnt += v - b[i];
      sum += v;
    } 
    if(cnt <= k) chmax(ans, v);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N, M;
int A[100000];
vector<int> E[100000];
bool visit[100000];

int dfs(int n) {
	visit[n] = true;
	int ret = n;
	for (int i = 0; i < (int)E[n].size(); i++) {
		int v = E[n][i];
		if (visit[v]) continue;
		int r = dfs(v);
		if (A[ret] > A[r]) ret = r;
	}
	return ret;
}

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < M; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		E[x].push_back(y);
		E[y].push_back(x);
	}
	if (N == M + 1) {
		printf("0\n");
		return 0;
	}
	else if (N < 2 * (N - M - 1)) {
		printf("Impossible\n");
		return 0;
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		if (visit[i]) continue;
		int r = dfs(i);
		ans += A[r];
		A[r] = imax;
	}
	sort(A, A + N);
	for (int i = 0; i < 2 * (N - M - 1) - (N - M); i++) {
		ans += A[i];
	}
	printf("%lld\n", ans);

	return 0;
}


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

int main(){
  int N; cin >> N;
  int a[100000];
  for(int i=0; i<N; i++) cin >> a[i];
  sort(a,a+N);
  
  if(N%3==0){
    int x=a[0],y=a[N/3],z=a[2*N/3];
    if(a[N/3-1]==x&&a[2*N/3-1]==y&&a[N-1]==z
       &&(x^y)==z&&(y^z)==x&&(z^x)==y){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(a[N-1]==0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 640
n=int(input())
h=list(map(int,input().split()))
x=[]

def mizu(h):
  if h==[]:
    return 0
  else:
    t=min(h)
    f=[]
    for i in range(len(h)):
      f.append(h[i]-t)
    u=f.index(0)
    return mizu(f[:u])+mizu(f[u+1:])+t


print(mizu(h))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

bool present(ll x,ll p[],ll n)
{
    ll count=0;
    for(ll i=0;i<n;i++)
    {
        if(p[i]==x)
        count=1;
        
    }
    if(count==1)
    return true;
    else
    return false;
    
}
int main()
{
  ll x,n;
  cin >> x >> n;
  ll p[n];ll ans=0;ll diff[n+1];
  if(n==0)
  {
      ans=x;
  }
  else
  {
      ll flag=0;
      for(ll i=0;i<n;i++)
      {
          cin >> p[i];
          
      }
      sort(p,p+n);ll index=0;
      for(ll i=0;i<n;i++)
      {
          if(p[i]==x)
          {
            flag=1;
            index =i;
          }

      }
      if(flag==0)
      {
          ans=x;
      }
      else
      {
          sort(p,p+n);ll count=0;ll hak=0;ll diff[100001];ll call[100001];map<ll,ll> mp;
          for(ll i=0;i<=p[n-1]+1;i++)
          {
            if(!present(i,p,n))
            {
                if(x>=i)
                diff[hak]=(x-i);
                else
                diff[hak]=i-x;
                mp.insert({i,diff[hak]});
                call[hak]=diff[hak];
                count=1;
                hak++;
            }
            
          }
          sort(call,call+hak);
         for(auto x:mp)
         {
             if(call[0]==x.second)
             {
                 ans=x.first;
                 break;
             }
         }
          
      }
      
    
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 123456789

vector<int> vec[100000];
int memo[100000]; //自分以下の子の個数

bool suc = false;

int dfs1(int d, int from){
  memo[d]=1;
  for(auto to : vec[d]) if(to!=from){
    memo[d] += dfs1(to, d);
  }
  return memo[d];
}

void dfs2(int d, int from, int par=0){
  int cnt = 0;
  if(par%2==1) cnt++;
  for(auto to : vec[d]) if(to!=from) if(memo[to]%2==1) cnt++;
  if(cnt>=2){ suc=true; return;}
//dbg(mp(d,cnt));
  for(auto to : vec[d]) if(to!=from) par += memo[to];
  for(auto to : vec[d]) if(to!=from){
    dfs2(to, d, par - memo[to]+1);
  }
}

bool solve(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    vec[a].pb(b);
    vec[b].pb(a);
  }

  dfs1(0,-1);
  dfs2(0,-1);

  if(suc) return true;
  else return false;
}

int main(){
  if(solve()) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define MOD 1000000000+7
#define INF (1LL<<30)
#define LINF (1LL<<55)
long long x[1000000];
int main()
{
    int n,k;
    cin>>n>>k;
    long long ret=1e18;
    for (int i=1;i<=n;i++)
        cin>>x[i];
    for (int i=1;i+k-1<=n;i++)
    {
        long long l=x[i],r=x[i+k-1];
        ret=min(ret,min(abs(r)+r-l,abs(l)+r-l));
    }
    cout<<ret<<endl;
}


Measured memory_bytes: 1024
k,n = map(int,input().split())
l = list(map(int,input().split()))

ll = l[:]

ll.append(k)
ll.pop(0)
s = []
x = (l[0] + k) - l[-1]


for i,j in zip(l,ll):
    s.append(j - i)

print(k - max(s+[x]))

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

int main() {
  double N, M, l=0, k=0;
  cin >> N >> M;
  vector<int> item(N);
  for(int i=0; i < N; i++){
    cin >> item.at(i);
    k += item.at(i);
  }
  for(int j=0; j < N;j++){
    if(item.at(j) >= k/(4*M)){
      l += 1;
    }
  }
  if(l >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 800;
int main() {
	int n;
	long long num, ans = 0;
	cin >> n;
	for(int i= 0; i < n; ++i){
		cin >> num;
		ans+= (num - 1);
	}
	cout << ans;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

int main() {
    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void) {

    string s;
    cin >> s;

    int apos, zpos;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'A') {
            apos = i; break;
        }
    }

    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            zpos = i; break;
        }
    }

    cout << zpos - apos + 1 << endl;

    return 0;
}

Measured memory_bytes: 768
let inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split("\n");

let i = 0;
while (true) {
    l = inputs[i].split(" ");
    x = ~~l[0];
    y = ~~l[1];
    if (x===0 && y===0) {
        break;
    };
    i++;
    if (x>y) {
        z = y;
        y = x;
        x = z;
    };
    console.log(`${x} ${y}`);
}





Measured memory_bytes: 18852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    ll n,k;cin>>n>>k;
    VI a(n),m(n+1);
    rep(i,n){
        cin>>a[i];
        m[i+1]=a[i];
    }
    m[0]=0;
    rep(i,n)m[i+1]=max(m[i+1],m[i]);
    ll ans=INFTY;
    rep(bit,(1LL<<n)){
        VI list;
        rep(i,n)if(bit&(1LL<<i))list.push_back(i);
        if((ll)list.size()!=k)continue;
        ll maxH=0,res=0;
        rep(i,k){
            chmax(maxH,m[list[i]]);
            if(a[list[i]]<=maxH){
                maxH++;
                res+=maxH-a[list[i]];
            }
            else maxH=a[list[i]];
        }
        chmin(ans,res);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3540
#include <iostream>

using namespace std;

int main(void) {
    int R;
    cin >> R;
    if(R < 1200) {
        cout << "ABC" << endl;
    } else if(R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
#define mod 1000000007

int main () {
  ll m, n;
  cin >> m >> n;
  ll x[m], y[n];
  ll X[m - 1], Y[n - 1]; // X[i] = x[i] - x[i - 1]，Y[i] = y[i] - y[i - 1];
  ll xnum[m - 1], ynum[n - 1]; // xnum[i] = iの地点から見たときの両端にどのくらい広げることができるか
  for (ll i = 0; i < m; i++) {
    x[i] = 0;
    if (i != m - 1) {
      X[i] = 0;  
      xnum[i] = 0;  
    }
  }
  for (ll i = 0; i < n; i++) {
    y[i] = 0;
    if (i != n - 1) {
      Y[i] = 0;
      ynum[i] = 0;  
    }  
  }
  for (ll i = 0; i < m; i++) {
    cin >> x[i];  
    if (i != 0) {
      X[i - 1] = x[i] - x[i - 1];
      xnum[i - 1] = (m - i) * i;  
    }
  }  
  for (ll i = 0; i < n; i++) {
    cin >> y[i];  
    if (i != 0) {
      Y[i - 1] = y[i] - y[i - 1];
      ynum[i - 1] = (n - i) * i;  
    }
  }
  ll sub = 0;
  for (ll i = 0; i < n - 1; i++) {
    sub += ((Y[i] % mod) * (ynum[i] % mod)) % mod;  
  }
  ll ans = 0;
  for (ll i = 0; i < m - 1; i++) {
    ll subsub = ((X[i] % mod) * (xnum[i] % mod)) % mod;
    ans = (ans % mod) + ((sub % mod) * (subsub % mod)) % mod;    
  }
  cout << ans % mod << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  double maxv[40001] = {};
  int t[100] = {};
  // 何秒から始まるか(長さはt[i]を見るとわかる)
  pair<int, double> v[100] = {};
  int n;
  int T = 0;
  cin >> n;
  REP(i, n)
  {
    cin >> t[i];
  }
  REP(i, n)
  {
    double vi;
    cin >> vi;
    v[i] = make_pair(T, vi);
    T += t[i];
  }

  REP(i, 2 * T + 1)
  {
    maxv[i] = 50000;
  }

  // maxv[i]を決める
  // t = i/2
  REP(i, 2 * T + 1)
  {
    maxv[i] = min(maxv[i], (double)i / 2);
    maxv[i] = min(maxv[i], (double)T - (double)i / 2);
    REP(j, n)
    {
      if ((double)i / 2 < v[j].first)
      {
        maxv[i] = min(maxv[i], v[j].second + ((double)(2 * v[j].first - i) / 2));
      }
      else if ((double)i / 2 > v[j].first + t[j])
      {
        maxv[i] = min(maxv[i], v[j].second + ((double)(i - 2 * (v[j].first + t[j])) / 2));
      }
      else
      {
        maxv[i] = min(maxv[i], v[j].second);
      }
    }
  }

  double ans = 0;
  FOR(i, 1, 2 * T + 1)
  {
    ans += 0.25 * (maxv[i - 1] + maxv[i]);
  }

  cout << fixed << setprecision(6) << ans << endl;
}


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

int main()
{
    string S, T, U;
    int countS, countT;
    cin >> S >> T;
    cin >> countS >> countT;
    cin >> U;

    if (U == S)
        countS--;
    else if (U == T)
        countT--;

    cout << countS << " " << countT << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int n,a,b,x=0;
 cin>>n>>a>>b;
 for(int i=1;i<=n;i++)
 {
  int m=i;
  int s=0;
  while(m!=0)
  {
  s+=m%10;
  m=m/10;
  }
  if(s>=a&&s<=b)
  x+=i;
 }
 cout<<x;
 return 0;
}

Measured memory_bytes: 256
N,x=map(int, input().split())
a=list(map(int, input().split()))
ans = 0
for i in range(N-1):
 if a[i]+a[i+1]>x:
  ans+=a[i]+a[i+1]-x
  if a[i] > x:
   a[i+1] = 0
  else:
   a[i+1] -= a[i] + a[i+1] - x

print(ans)

Measured memory_bytes: 14132
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  VI cnt(N, 0);
  REP(i,0,M) {
    int a, b;
    cin >> a >> b;
    cnt[a-1]++;
    cnt[b-1]++;
  }
  FOR(x, cnt) {
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int

using namespace std;

int main(){
  int p,q,r; cin>>p>>q>>r;
  cout<<min(p+q,min(q+r,r+p))<<endl;

  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
    int r,g,b;

    cin >> r >> g >> b;

    if((r*100 + g*10 + b) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

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

d = [-1] * N

for i in range(N):
    if i == 0:
        d[i] = 0
    elif i == 1:
        d[i] = abs(h[i] - h[i-1])
    else:
        ele1 = d[i-1] + abs(h[i] - h[i-1])
        ele2 = d[i-2] + abs(h[i] - h[i-2])
        if ele1 < ele2:
            d[i] = ele1
        else:
            d[i] = ele2
print(d[-1])


Measured memory_bytes: 13928
N, K = map(int, input().split())
ro = list(map(int, input().split()))

min = 10e8

for i in range(N-K+1):
  if ro[i] * ro[i+K-1] < 0:
    if abs(ro[i]) < abs(ro[i+K-1]):
      hoho = abs(ro[i])
    else:
      hoho = abs(ro[i+K-1])
    ans = abs(ro[i]) + ro[i+K-1] + hoho
  else:
    ans = max(abs(ro[i]), abs(ro[i+K-1]))
    
  if ans < min:
    min = ans
    
print(min)
  
  

Measured memory_bytes: 14844
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

long long gcd(long long a, long long b){

    if(a < b){
        long long temp = a;
        a = b;
        b = temp;
    }

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


int main(){
    int n;
    cin >> n;
    long long ans;
    long long val;
    cin >> val;
    ans = val;
    for(int i = 1; i < n; i++){
        //cout << "ans:" << ans << endl;
        cin >> val;
        ans = ans * (val / gcd(ans, val));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int N){
        par.assign(N,0);
        rank.assign(N,0);
        REP(i,N) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) swap(x,y);

        //x becomes root
        par[y]=x;
        if(rank[x]==rank[y]) rank[x]++;
    }
};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    UnionFind uf(N+M);
    REP(i,N){
        int k; cin >> k;
        REP(j,k){
            int l; cin >> l;
            l--;
            uf.unite(l,i+M);
        }
    }
    int par = uf.find(M);
    bool ok = 1;
    FOR(i,1,N){
        int tmp = uf.find(M+i);
        if(par != tmp)  ok = 0;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int x, y, f = 0;

    scanf("%d %d",&x, &y);

    if(y % x == 0){
        f = x + y;
        printf("%d\n",f);
    }else{
        f = y - x;
        printf("%d\n",f);
    }


    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		sc.close();
		int x3=x2-(y2-y1);
		int y3=y2+(x2-x1);
		int x4=x3-(y3-y2);
		int y4=y3+(x3-x2);
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
	}

}

Measured memory_bytes: 39680
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <iomanip>
#include <cassert>
using namespace std;

struct wrect{
    int h;
    int w;
    int diag;
    wrect(){}
    ~wrect(){}
    wrect(int a, int b): h(a), w(b), diag(h * h + w * w){}
    bool operator < (const wrect& r) const {
        return diag == r.diag ? h < r.h : diag < r.diag;
    }
};

int main(){
    vector<wrect> rv;
    for(int w = 1; w <= 150; w++){
        for(int h = 1; h < w; h++){
            rv.push_back(wrect(h, w));
        }
    }
    sort(rv.begin(), rv.end());
    while(true){
        int h, w;
        scanf("%d%d", &h, &w);
        if(h == 0 && w == 0) break;
        vector<wrect>::iterator it = lower_bound(rv.begin(), rv.end(), wrect(h, w));
        ++it;
        printf("%d %d\n", it->h, it->w);
    }
    return 0;
}

Measured memory_bytes: 1320
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(int N, std::vector<int> P, std::vector<int> Q) {
  vector<int> v(N);
  rep(i, N) { v.at(i) = i + 1; }
  int a, b;

  int i = 1;
  do {
    if (v == P) {
      a = i;
    }
    if (v == Q) {
      b = i;
    }
    i++;
  } while (next_permutation(all(v)));

  cout << abs(a - b) << endl;
}

int main() {
  int N;
  scanf("%d", &N);
  std::vector<int> P(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &P[i]);
  }
  std::vector<int> Q(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &Q[i]);
  }
  solve(N, std::move(P), std::move(Q));
  return 0;
}


Measured memory_bytes: 256