akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[N + 100];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		while (a[i] % 2 == 0){
          	a[i]=a[i]/2;
			sum++;
        }
	}
	cout << sum << endl;
}


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

using namespace std;

vector< pair< int, int>> vp;

int check(int p, int q) {
	vector< bool> seen(vp.size(), false);

	int res = 0;
	for (int i = 0; i < (int) vp.size(); i ++) {
		if (seen[i]) continue;
		int last = i;
		res ++;
		for (int j = i + 1; j < (int) vp.size(); j ++) {
			if (vp[j].first == vp[last].first + p and vp[j].second == vp[last].second + q) {
				seen[j] = true;
				last = j;
			}
		}
	}
	return res;
}

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		int a, b;
		scanf("%d %d", &a, &b);
		vp.push_back({a, b});
	}
	if (n <= 2) return !printf("1\n");

	sort(begin(vp), end(vp));

	vector< pair< int, int>> diffs;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			diffs.emplace_back(vp[j].first - vp[i].first, vp[j].second - vp[i].second);
		}
	}

	int res = n;
	for (auto p : diffs) {
		res = min(res, check(p.first, p.second));
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, x, t;
    cin >> n >> x >> t;
    
    int res = 0;
    if (n % x == 0) {
        res = t*n/x;
    } else {
        res = t*(n/x + 1);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define x first 
#define y second
const int maxx = 2000006;
const int mod2 = 987654319;
const int maxlog = 20;
const ll mod = 1000000007;

int main() {
    IOS
    ll N, K;
    cin >> N >> K;
    ll arr[N], brr[N];
    for (int i = 0; i < N; i++) cin >> arr[i];
    for (int i = 0; i < N; i++) cin >> brr[i];
    sort(arr, arr + N);
    sort(brr, brr + N);
    ll l = 0, r = INF, ans = INF;
    while (l <= r) {
        ll mi = (l + r) / 2;
        ll sum = 0;
        for (int i = 0; i < N; i++) {
            if (arr[i] * brr[N - 1 - i] > mi) {
                sum += arr[i] - mi / brr[N - i - 1];
            }
        }
        if (sum <= K) ans = min(mi, ans), r = mi - 1;
        else l = mi + 1;
    }
    cout << ans;
}


Measured memory_bytes: 3328
N=int(input())
points=[]
ds=[]
for i in range(N):
  x,y,d=input().split()
  x,y=map(int,(x,y))
  if d=='L':d=(-1,0)
  if d=='R':d=(1,0)
  if d=='U':d=(0,1)
  if d=='D':d=(0,-1)
  points.append((x,y))
  ds.append(d)

if N==1:
  print(0)
  exit()

x,y=list(zip(*points))
xmax,xmin,ymax,ymin=max(x),min(x),max(y),min(y)

def region(p):
  x,y=list(zip(*p))
  return (max(x)-min(x))*(max(y)-min(y))

def process(p,d,second=1):
  return [(p[i][0]+second*d[i][0],p[i][1]+second*d[i][1]) for i in range(N)]

def func(x):
  return region(process(points,ds,x))

def ternary_search(f, x_min, x_max, epsilon=1e-15):
    while True:
        x1,x2 = 1/3*(x_max-x_min)+x_min,2/3*(x_max-x_min)+x_min
        gap = f(x1)-f(x2)
        if gap < 0: x_max=x2
        else: x_min=x1
        if abs(gap) <= epsilon:break
    return (x_max+x_min)/2
  
t_max=4*(max(xmax-xmin,ymax-ymin))
t_min=0

x_opt = ternary_search(func, t_min, t_max, epsilon=1e-15)

print(func(x_opt))

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void solve()
{
    int N, X[100];
    cin >> N;
    rep(i, N)
    {
        cin >> X[i];
    }

    int hpmin = 100000000;
    rep1(P, 100)
    {
        int hpsum = 0;
        rep(i, N)
        {
            hpsum += (X[i] - P) * (X[i] - P);
        }
        hpmin = min(hpmin, hpsum);
    }

    cout << hpmin << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 256
get = lambda:map(int, raw_input().split())
while 1:
    n,m = get()
    if n==m==0: break
    t = [0]
    if n!=0: t += get()
    if m!=0: t += get()
    t.sort()
    print max(t[i+1]-t[i] for i in xrange(n+m)) if n+m>1 else t[1]

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c ;
	if (a>b) {
		d=a; a=b; b=d;
	}
	if (b<c) {
		cout << a << ' ' << b << ' ' << c << endl;
	}else if (a<c){
		cout << a << ' ' << c << ' ' << b << endl;
	}else {
		cout << c << ' ' << a << ' ' << b << endl;
	}

    return 0;
}

Measured memory_bytes: 1160
N,M = map(int,input().split())
X = sorted(map(int,input().split()))
x = []
for i in range(M-1):
	x.append(abs(X[i]-X[i+1]))
x.sort(reverse=1)
if N >= M:
	print(0)
else:
	print(sum(x[N-1:]))

Measured memory_bytes: 13968
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    x = LI()
    ans = inf
    for i in range(max(x) + 1):
        tmp = 0
        for xi in x:
            tmp += (xi - i) ** 2
        ans = min(tmp, ans)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39536
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AWhiteCells solver = new AWhiteCells();
        solver.solve(1, in, out);
        out.close();
    }

    static class AWhiteCells {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int H = in.nextInt(), W = in.nextInt();
            int h = in.nextInt(), w = in.nextInt();

            out.println((H - h) * (W - w));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
import fractions

T = int(input())

def solve(A, B, C, D):
    left = A
    if A < B:
        print('No')
        return
    if D < B:
        print('No')
        return
    if C >= B:
        print('Yes')
        return
    g = fractions.gcd(B, D)
    max_mod_b = B - g + (A % g)
    if max_mod_b > C:
        print('No')
    else:
        print('Yes')

for _ in range(T):
    A, B, C, D = map(int, input().split())
    solve(A, B, C, D)


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n, 0);
    rep(i, n) cin >> a[i];
    ll cnt_all = 0;
    rep(i, n) cnt_all += a[i];
    ll cnt_s = 0;
    ll cnt_dif = INF;
    rep(i, n - 1)
    {
        cnt_s += a[i];
        if (cnt_dif > abs(2 * cnt_s - cnt_all))
        {
            cnt_dif = abs(2 * cnt_s - cnt_all);
        }
    }
    cout << cnt_dif << endl;
    return 0;
}

Measured memory_bytes: 4796
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let x: i32 = read();
    let y: i32 = read();

    let cmds: Vec<char> = s.chars().collect();
    let mut horizon_moves: Vec<i32> = Vec::new();
    let mut vertical_moves: Vec<i32> = Vec::new();
    let mut is_horizon: bool = true;
    let mut cnt: i32 = 0;
    let mut is_first: bool = true;
    let mut first_x: i32 = 0;
    for cmd in cmds {
        if cmd == 'F' {
            cnt += 1;
        } else {
            if is_first {
                first_x = cnt;
                is_first = false;
            } else if cnt == 0 {  
            } else if is_horizon {
                horizon_moves.push(cnt);
            } else {
                vertical_moves.push(cnt);
            }
            is_horizon = !is_horizon;
            cnt = 0;
        }
    }
    if cnt != 0 {
        if is_first { 
            first_x = cnt;
        } else if is_horizon {
            horizon_moves.push(cnt);
        } else {
            vertical_moves.push(cnt);
        }
    }
    // println!("{:?}", horizon_moves);
    // println!("{:?}", vertical_moves);

    let mut ans = "Yes";
    loop {
        let mut set: HashSet<i32> = HashSet::new();
        set.insert(first_x);
        for h_move in horizon_moves {
            let mut new_set: HashSet<i32> = HashSet::new();
            for h_pos in set {
                new_set.insert(h_pos + h_move);
                new_set.insert(h_pos - h_move);
            }
            set = new_set;
        }
        // println!("{:?}", set);
        if !set.contains(&x) {
            ans = "No";
            break;
        }

        let mut set: HashSet<i32> = HashSet::new();
        set.insert(0);
        for v_move in vertical_moves {
            let mut new_set: HashSet<i32> = HashSet::new();
            for h_pos in set {
                new_set.insert(h_pos + v_move);
                new_set.insert(h_pos - v_move);
            }
            set = new_set;
        }
        // println!("{:?}", set);
        if !set.contains(&y) {
            ans = "No";
            break;
        }

        break;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4476
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
// 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int area =a*b;
        int length =2*a + 2*b;
        System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 26356
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
typedef long long LL;
const int N=100005;
int n,tot,h[N],ne[N<<1],to[N<<1],du[N];
LL a[N],f[N];
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void dfs(int x,int las) {
	if(du[x]==1) {f[x]=a[x];return;}
	LL orzabs=0,p,mx=0;
	for(RI i=h[x];i;i=ne[i]) {
		if(to[i]==las) continue;
		dfs(to[i],x),f[x]+=f[to[i]],mx=max(mx,f[to[i]]);
	}
	if(mx>f[x]-mx) p=f[x]-mx;
	else p=f[x]/2;
	if(f[x]<a[x]) {puts("NO");exit(0);}
	if(f[x]-a[x]>p) {puts("NO");exit(0);}
	f[x]-=(f[x]-a[x])*2LL;
}
int main()
{
	int x,y;
	n=read();
	for(RI i=1;i<=n;++i) a[i]=read();
	if(n==2) {
		if(a[1]==a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	for(RI i=1;i<n;++i)
		x=read(),y=read(),add(x,y),add(y,x),++du[x],++du[y];
	for(RI i=1;i<=n;++i) if(du[i]>1) {
		dfs(i,0);
		if(f[i]) puts("NO");
		else puts("YES");
		return 0;
	}
	return 0;
}

Measured memory_bytes: 8192
A=[]
for i in range(3):
  B=list(map(int,input().split()))
  A.append(B)
N=int(input())
b=[0]*N
for i in range(N):
  b[i]=int(input())
lis=[]
bingo=[[(0,0),(0,1),(0,2)],[(1,0),(1,1),(1,2)],[(2,0),(2,1),(2,2)],[(0,0),(1,0),(2,0)],[(0,1),(1,1),(2,1)],[(0,2),(1,2),(2,2)],[(0,0),(1,1),(2,2)],[(0,2),(1,1),(2,0)]]
for i in range(3):
  for j in range(3):
    if A[i][j] in b:
      lis.append((i,j))
ans=0
for i in range(8):
  count=0
  for j in range(3):
    if bingo[i][j] in lis:
      count+=1
  if count==3:
    ans+=1
    print('Yes')
    break
if ans==0:
  print('No')

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

int main(void){
    int X, Y;
    cin >> X >> Y;
    if((X*2<=Y)&&(X*4>=Y)&&(Y%2==0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define all(X) X.begin(),X.end()
#define pb push_back

using namespace std;

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

const int maxn = 1e5 +5;
const int lg = 20;
const int mod = 1e9 + 7;

template<class T>
void smin(T &_x, const T &_y){
	_x = min(_x, _y);
}
template<class T>
void smax(T &_x, const T &_y){
	_x = max(_x, _y);
}

vector<int> edge[maxn];
int a[maxn];
int h[maxn];

int cnt = 0;
int k;


int dfs(int v){
	int max = 0;
	for(int u : edge[v]) smax(max, dfs(u));
	if(max == k - 1 && v != 0){
		if(a[v] != 0) {
			cnt++;
//`			cout<<v<<endl;
		}
		return 0;
	} 
	return max + 1;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie();
	int n;
	cin>>n>>k;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		a[i]--;
		if(i != 0) edge[a[i]].pb(i);
	}
	if(a[0] != 0) cnt++;
	a[n] = a[0];
	dfs(0);
	cout<<cnt<<endl;
}

Measured memory_bytes: 10880
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        s:Chars,
        w:usize,
    }
    for i in 0..s.len() {
        if i % w == 0 {
            print!("{}", s[i]);
        }
    }
    println!("");
}


Measured memory_bytes: 2132
def func(even_a, odd_a)
  e0 = even_a[0][1]
  e1 = (1 < even_a.length) ? even_a[1][1]: 0

  d0 = even_a[0][1]
  d1 = (1 < odd_a.length) ? odd_a[1][1]: 0

  r = [e0 + d1, e1 + d0].max
  return r
end

n = gets.chomp.to_i
t = gets.chomp.split(' ').map {|i| i.to_i}
even = {}
odd = {}
t.length.times do |i|
  k = t[i]
  if (i + 1) % 2 == 0
    # even
    if even[k]
      even[k] += 1
    else
      even[k] = 1
    end
  else
    # odd
    if odd[k]
      odd[k] += 1
    else
      odd[k] = 1
    end
  end
end

even_a = even.to_a
odd_a = odd.to_a
even_a.sort! {|a, b| (-1) * (a[1] <=> b[1])}
odd_a.sort! {|a, b| (-1) * (a[1] <=> b[1])}

m = 0
if even_a[0][0] != odd_a[0][0]
  m = even_a[0][1] + odd_a[0][1]
else
  m = func(even_a, odd_a)
  if m == 0
    m = t.length / 2
  end
end

r = t.length - m
puts r



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

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char* s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
constexpr ll MOD = 1e9 + 7;

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

ll mul(ll a, ll b) { return a * b; }

ll add(ll a, ll b) { return a + b; }

ll sub(ll a, ll b) { return a - b; }

template <typename ValueType, ValueType defaultVal,
          void (*chadd)(ValueType&, ValueType)>
class BIT {
 private:
  vector<ValueType> a;
  int n;
  inline int lowbit(int x) { return x & -x; }

 public:
  BIT(int n_) : n(n_) { a = vector<ValueType>(n + 1, defaultVal); }

  ValueType sum(int k) {
    ValueType s = defaultVal;
    while (k >= 1) {
      chadd(s, a[k]);
      k -= lowbit(k);
    }
    return s;
  }

  void add(int k, ValueType x) {
    while (k <= n) {
      chadd(a[k], x);
      k += lowbit(k);
    }
  }
};

void chmin(int& a, int b) { a = min(a, b); }
void chmax(int& a, int b) { a = max(a, b); }

int N;
vector<int> a;

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

  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  vector<int> maxIdxLess(N), minIdxLess(N);
  BIT<int, INT_MIN, chmax> left(N);
  for (int i = 0; i < N; i++) {
    maxIdxLess[i] = left.sum(a[i]);
    if (maxIdxLess[i] == INT_MIN) {
      maxIdxLess[i] = -1;
    }
    left.add(a[i], i);
  }
  BIT<int, INT_MAX, chmin> right(N);
  for (int i = N - 1; i >= 0; i--) {
    minIdxLess[i] = right.sum(a[i]);
    if (minIdxLess[i] == INT_MAX) {
      minIdxLess[i] = N;
    }
    right.add(a[i], i);
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans = add(ans, mul(a[i], mul(i - minIdxLess[i], maxIdxLess[i] - i)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int ans=t.size();
  for(int i=0;i<=s.size()-t.size();i++)
  {
    int diff=0;
    for(int j=0;j<t.size();j++)
    {
      if(t[j]!=s[i+j])
      	diff++;
    }
    ans=min(ans,diff);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
def main():
    n = int(input())
    max_score = 0
    max_index = 0
    min_score = float("inf")
    min_index = 0
    for _ in range(n):
        a, b = map(int, input().split())
        if max_index > a:
            max_index = a
            max_score = b
        if min_index < a:
            min_index = a
            min_score = b
    print(min_index + min_score)


if __name__ == '__main__':
    main()



Measured memory_bytes: 43480
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define ll long long
#define ii pair<string,int>ii;

string IntToStr(int tmp){
    ostringstream out;
    out << tmp;
    return out.str();
}

int main()
{
    int n;
    cin>>n;
    if(n>=2&&n<=3)cout<<2<<endl;
    else if(n>=4&&n<=7)cout<<4<<endl;
    else if(n>=8&&n<=15)cout<<8<<endl;
    else if(n>=16&&n<=31)cout<<16<<endl;
    else if(n>=32&&n<=63)cout<<32<<endl;
    else if(n>=64) cout<<64<<endl;
    else cout<<1<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;

int s[100];

int main(){
	int n,m;
	cin >> n >> m;
	memset(s,0,sizeof(s));
	for(int i = 1;i <= m;i++){
		int x,y;
		cin >> x >> y;
		s[x]++;
		s[y]++;
	}
	for(int i = 1;i <= n;i++){
		cout << s[i] <<endl;
	}
}

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

upp = x // 100
rem = x % 100

n5  = rem // 5
rem = rem % 5

n4  = rem // 4
rem = rem % 4

n3  = rem // 3
rem = rem % 3

n2  = rem // 2
rem = rem % 2

n1  = rem

sumn = n1 + n2 + n3 + n4 + n5

if upp >= sumn:
  print('1')
else:
  print('0')

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

int main() {
	int n;cin>>n;
	long long a,b;cin>>a>>b;
	vector<long long> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	sort(h.begin(),h.end(),greater<long long>());
	long long c=a-b;
	long long right=1;
	for(int i=0;i<9;i++){
		right*=10;
	}
	long long left=0;
	while(right-left>1){
		long long center=(right+left)/2;
		int flag=1;
		long long count=0;
		for(int i=0;i<n;i++){
			long long hp=h[i];
			hp-=b*center;
			if(hp>0){
				count+=(hp-1)/c+1;
			}
		}
		if(count>center)flag=0;

		if(flag){
			right=center;
		}else{
			left=center;
		}
	}
	cout<<right<<endl;

	return 0;
}


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

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (abs(a - c) <= d || (abs(a - b) <= d && abs(c - b) <= d) ? "Yes" : "No") << endl;
}


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

// n個の重複しない整数(min ~ max)の和としてsを表す組み合わせの数
int ci(int n, int s, int min, int max) {
  // 特殊なパターンを処理
  if (s < min || n < 1) return 0;
  if (n == 1) return (s > max)? 0: 1;
  
  // 最も小さい数で場合分けし再帰処理
  int r = 0;
  for (int i=min; i<s && i<=max; i++) r += ci(n - 1, s - i, i + 1, max);
  return r;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!n && !s) break;
    cout << ci(n, s, 0, 9) << endl;
  }
  return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;
import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while (true){
			int n = sc.nextInt();
			int sum = 0;
			
			//終了条件の判定
			if (n == 0){
				break;
			}
			
			int[] data = new int[n];
			
			//データの入力
			for (int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			
			//データのソート
			Arrays.sort(data);
			
			for (int i = 1; i < n - 1; i++){
				sum += data[i];
			}
			
			System.out.println(sum / (n - 2));
		}
				
	}
}


Measured memory_bytes: 28980
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    int k=max(max(a,b),c);
    k=3*k-a-b-c;
    if(k&1) k+=3;
    printf("%d\n",k/2);
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 998244353
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define set0(x) memset(x, 0, sizeof(x))
ll fastPowMod(ll a, ll p,ll mod){ if(p==0) return 1; ll z = fastPowMod(a,p/2,mod); z = (z*z)%mod; if(p%2) z = (z*a)%mod; return z; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}



void solve()
{
    string s,t;
    cin>>s;
    cin>>t;
    int sLen = s.length();
    int tLen = t.length();
    int dp[sLen+1][tLen+1];

    set0(dp);
    srep(i,1,sLen)
    {
        srep(j,1,tLen)
        {
            if(s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    int lenResult = dp[sLen][tLen];
    
    string res(lenResult,'a');

    int i = sLen, j = tLen, idx = lenResult-1;

    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            res[idx] = s[i-1];
            i--;j--;idx--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;

    }

    cout<<res;

}

int main()
{
    fastio;
    
    solve();
    cout<<"\n";
    
    return 0;
}

Measured memory_bytes: 38760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();

        long Bcnt = 0;
        long cnt = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'W')
                cnt += Bcnt;
            if (s[i] == 'B')
                Bcnt++;
        }

        System.out.println(cnt);
    }
}


Measured memory_bytes: 25996
#!/usr/bin/env python3

import math

def main():
    [K, N] = list(map(int, input().split()))

    r = []
    if K == 1:
        r = [1] * ((N + 1) // 2)
    elif K % 2 == 0:
        r = [K // 2]
        r += [K] * (N - 1)
    else:
        t = N // 2
        x = int(math.log(N * (K - 1) + 1, K) - 1)
        while t < ((K ** (x + 1) - 1) / (K - 1) + x) // 2:
            x -= 1
        x += 1
        r = [(K + 1) // 2] * (N - x)
        r += [0] * x
        t = ((K ** (x + 1) - 1) / (K - 1) + x) // 2 - t
        for i in range(x, 0, -1):
            r[N - i] = 1
            t -= 1
            for j in range(K - 1):
                if t == 0:
                    break
                if K ** i - 1 <= t * (K - 1):
                    r[N - i] += 1
                    t -= (K ** i - 1) // (K - 1)
            if t == 0:
                break

        for i in range(len(r) - 1, -1, -1):
            if r[i] == 0:
                r.pop()
            else:
                break


    print(' '.join(list(map(str, r))))


if __name__ == '__main__':
    main()



Measured memory_bytes: 26532
#!python3

import sys

iim = lambda: map(int, input().rstrip().split())

def popcnt2(n):
    a = (
        0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
    )
    ans = 0
    while n:
        ans += a[n&0xff]
        n >>= 8
    return ans

def resolve():
    N = int(input())
    S = list(input())
    Q = int(input())

    c0 = ord('a')
    smap = [1<<(i-c0) for i in range(c0, ord('z')+1)]

    T = [0]*N + [smap[ord(S[i])-c0] for i in range(N)]

    for i in range(N-1, 0, -1):
        i2 = i << 1
        T[i] = T[i2] | T[i2|1]

    ans = []
    #print(T)
    for cmd, i, j in (line.split() for line in sys.stdin):
        i = int(i) - 1
        if cmd == "1":
            if S[i] == j:
                continue

            S[i] = j
            i0 = N + i
            T[i0] = smap[ord(j)-c0]
            while i0 > 1:
                i0 = i0 >> 1
                T[i0] = T[i0+i0] | T[i0-~i0]
        elif cmd == "2":
            i += N
            j = int(j) + N

            d1 = 0
            while i < j:
                if i & 1:
                    d1 |= T[i]
                    i += 1
                if j & 1:
                    j -= 1
                    d1 |= T[j]

                i >>= 1; j >>=1

            ans.append(popcnt2(d1))

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 31676
n,k,q = (int(x) for x in input().split())
p = [k-q]*n
for x in range(q):
  s = int(input())
  p[s-1] += 1
for z in range(len(p)):
  if p[z] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 6596
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  string K;
  int D;
  cin >> K;
  cin >> D;
  int L = K.size();
  ll MOD = 1000000007;

  ll dpA[L + 1][D];
  ll dpB[L + 1][D];
  memset(dpA, 0, sizeof(dpA));
  memset(dpB, 0, sizeof(dpB));

  dpA[0][0] = 1;

  for (int i = 0; i < L; ++i) {
    ll n = K[i] - '0';

    for (int j = 0; j < D; ++j) {
      if (dpA[i][j] > 0) {
        dpA[i + 1][(j + n) % D] = dpA[i][j];

        if (i > 0) {
          for (int k = 0; k < n; ++k) {
            dpB[i + 1][(j + k) % D] += 1;
          }
        }
      }

      if (dpB[i][j] > 0) {
        for (int k = 0; k <= 9; ++k) {
          dpB[i + 1][(j + k) % D] += dpB[i][j];
          dpB[i + 1][(j + k) % D] %= MOD;
        }
      }
    }

    for (int k = 1; k <= 9; ++k) {
      if (i == 0 && k >= n) continue;
      dpB[i + 1][k % D] += 1;
    }
  }

  cout << (dpA[L][0] + dpB[L][0]) % MOD << endl;

  return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		String[] getStr = sc.next().split("");
		
		int j = 0;

		for (int i = 0; i < 3; i++) {
			
			if (getStr[i].equals(getStr[i+1])) {

				System.out.println("Bad");
				break;			

			} else {			
				
				j++;	
				
				if (j == 3) {

					System.out.println("Good");		

				}

			}

		}
	}
}

Measured memory_bytes: 23892
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N ,K =map(int,input().split())
    A=list(map(int,input().split()))

    for j in range(N-K):
        if A[j+K] - A[j] >0:
            print("Yes")
        else:
            print("No")







if __name__ == "__main__":
    main()


Measured memory_bytes: 104588
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
vi eulerSieve(int n)    // 查找记录2-n的素数
{
    vi p;
    vector<bool> vst(n+1, false);
    for (int i = 2; i <= n; i++)
    {
        if (vst[i] == false)  // 如果未被筛过，则为素数
            p.push_back(i);
        for (int j = 0; j < p.size(); j++)
        {
            if (i * p[j] > n)      // 当要标记的合数超出范围时跳出
                break;
            vst[i * p[j]] = true;     // 将已经记录的素数的倍数进行标记
            if (i % p[j] == 0)      //关键步骤
                break;
        }
    }
    return p;
}

vi primesUntil(int n){
    vi p;
    p.push_back(2);
    for (int i =3; i<=n; ++i){
        for (int j=0; j<p.size(); ++j){
            if (i%p[j] == 0) break;
            if (p[j]* p[j]> i)
            {
                p.push_back(i);
                break;
            }
        }
    }
    return p;
}

vector<pll> defactor(lint v, const vi& p){// prime,   power
    vector<pll> ans;
    int pid = 0;
    while(v>1){
        int cnt = 0;
        while(v%p[pid] == 0) {
            cnt++;
            v= v/p[pid];
        }
        if (cnt) ans.push_back({p[pid], cnt});
        pid++;
        if (v > 1 && (pid >= p.size() || lint(p[pid])*p[pid]>v)){
            ans.push_back({v, 1});
            break;
        }
    }
    return ans;
}


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

    lint a; cin>>a;

    vi p = eulerSieve(1e6 + 5);

    vector<pll> d = defactor(a, p);

    int op = 0;
    for (pll f : d){
        int cur =1;
        while(f.second >= cur){
            op ++;
            f.second -= cur;
            cur++;
        }
    }
    cout<<op;


}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 1 ; i < n ; i++ )
 
int main(){
  int A , B , ans = 0,  count = 0 ;
  cin >> A >> B ;
  rep(i,B){
    ans = A*i - i + 1 ;
    if ( i == 1 ) ans = A ;
    count = i ;
    if (ans >= B ) break ;
    
}
  cout << count << endl;
}

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

if abs(N - M) > 1:
    print(0)
    exit()

import math

mod = 10**9 + 7

if N == M:
    ans = ((math.factorial(N) * math.factorial(M)) * 2) % mod
else:
    ans = (math.factorial(N) * math.factorial(M)) % mod

print(ans)

Measured memory_bytes: 5184
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
# define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  ll a,b;
  cin >> a >> b;
  ld t = b;
  if((b==2)&&(a==1)){
    cout << "Yes";
    return 0;
  }
  if(b%2==0){
    if((a<=b/2)&&(a>=ceil(t/4))){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
  }
  else{
    cout << "No";
  }
}


Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> v;
	for(int i =0;i<n;i++){
		int x;
		cin>>x;
		v.push_back(x);
	}
	int result = 9999999;
	int cost_p = 0;
	int cost_pp = abs(v[1]-v[0]);
	result = cost_pp;
	for(int i = 2;i<n;i++){
		result = min(cost_p + abs(v[i]-v[i-2]) , cost_pp + abs(v[i]-v[i-1]));
		cost_p = cost_pp;
		cost_pp = result;
	}
	cout<<result;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A,B;
vector<int> E[101010];
int D[101010][2];

void dfs(int cur,int pre,int d,int id) {
	D[cur][id]=d;
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur,d+1,id);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B;
	A--,B--;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(A,A,0,0);
	dfs(B,B,0,1);
	
	int ma=0;
	if(D[B][0]%2==0) {
		FOR(i,N) if(D[i][0]<D[i][1]) ma=max(ma,D[i][1]-1);
	}
	else {
		FOR(i,N) if(D[i][0]<D[i][1]) ma=max(ma,D[i][1]-1);
	}
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 11648
#include<bits/stdc++.h>
int X,k,q;
struct ev{
	int x,y,id;
	bool operator<(const ev&e)const{return x<e.x;}
}e[500007];
int ep=0,as[500007];
int main(){
	scanf("%d%d",&X,&k);
	for(int i=0,a;i<k;++i){
		scanf("%d",&a);
		e[ep++]=(ev){a,0,0};
	}
	scanf("%d",&q);
	for(int i=1,a,b;i<=q;++i){
		scanf("%d%d",&a,&b);
		e[ep++]=(ev){a,b,i};
	}
	std::sort(e,e+ep);
	long long mn=0,mx=X,a=0;
	for(int i=0,sgn=-1,t0=0;i<ep;++i){
		long long v0=(e[i].x-t0)*sgn;
		if(e[i].id){
			long long v=e[i].y+a;
			if(v<mn)v=mn;
			if(v>mx)v=mx;
			v+=v0;
			if(v<0)v=0;
			if(v>X)v=X;
			as[e[i].id]=v;
		}else{
			mn+=v0,mx+=v0,a+=v0;
			if(mn<0) mn=0;
			if(mx<0) mx=0;
			if(mx>X) mx=X;
			if(mn>X) mn=X; 
			t0=e[i].x;
			sgn*=-1;
		}
	}
	for(int i=1;i<=q;++i)printf("%d\n",as[i]);
	return 0;
} 

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};
int R, C, M;
string s[50];
int p[50][50];
int q[50][50];
int r[50][50];
int yy[1010], xx[1010];
vector<int> t[50][50];
pii pre[50][50];

bool contain(int y, int x) {
  return y >= 0 && y < R && x >= 0 && x < C;
}

vector<pii> getPath(int idx) {
  int sy = yy[idx], sx = xx[idx];
  int gy = yy[idx+1], gx = xx[idx+1];
  fill_n((pii*)pre, 50*50, pii(-1, -1));
  pre[sy][sx] = pii(sy, sx);
  queue<pii> que;
  que.emplace(sy, sx);
  while (!que.empty()) {
    int y, x;
    tie(y, x) = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (contain(ny, nx) && s[ny][nx] == '.' && pre[ny][nx].first < 0) {
        pre[ny][nx] = pii(y, x);
        que.emplace(ny, nx);
      }
    }
  }
  int y = gy, x = gx;
  vector<pii> res;
  while (!(y == sy && x == sx)) {
    res.emplace_back(y, x);
    tie(y, x) = pre[y][x];
  }
  reverse(res.begin(), res.end());
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> R >> C >> M;
  for (int i = 0; i < R; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      cin >> p[i][j];
    }
  }
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      cin >> q[i][j];
    }
  }
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      cin >> r[i][j];
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> yy[i] >> xx[i];
  }

  int tm = 0, y = yy[0], x = xx[0];
  t[y][x].emplace_back(tm++);
  for (int i = 0; i < M-1; i++) {
    vector<pii> path = getPath(i);
    for (int j = 0; j < path.size(); j++) {
      tie(y, x) = path[j];
      t[y][x].emplace_back(tm++);
    }
  }
  int ans = 0;
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      if (s[i][j] != '.') continue;
      if (t[i][j].size() == 0) continue;
      ans += q[i][j] + r[i][j];
      for (int k = 0; k+1 < t[i][j].size(); k++) {
        ans += min((t[i][j][k+1] - t[i][j][k]) * p[i][j], q[i][j] + r[i][j]);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8404
N = int(input())

ans1 = N / 1.08
N2 = int(ans1) * 1.08
ans2 = int(ans1) + 1
N3 = int(ans2) * 1.08

if int(N2) == N:
    print(int(ans1))
elif int(N3) == N:
    print(int(ans2))
else:
    print(":(")
    




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

int main() {
  char c;
  cin >> c;
  if(c == 'a'||c == 'i'||c == 'u'||c == 'e'||c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<ll> dist1(N);
    vector<ll> dist2(N);
    for (int i = 0; i < N; ++i) {
        ll x, y;
        cin >> x >> y;
        dist1[i] = x + y;
        dist2[i] = 1000000000 - x + y;
    }
    sort(all(dist1));
    sort(all(dist2));
    ll ans = 0;
    chmax(ans, dist1[N - 1] - dist1[0]);
    chmax(ans, dist2[N - 1] - dist2[0]);
    cout << ans << endl;
}

Measured memory_bytes: 6376
// include headers{{{
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*}}}*/
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    long long r, d, x_2000; cin >> r >> d >> x_2000;
    rep (i, 10) {
        cout << r*x_2000 - d << endl;
        x_2000 = r*x_2000 - d;
    }
    return 0;
}



Measured memory_bytes: 888
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int n;
    cin >> n;
    cout << (n / 3) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<sstream>
#include<algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

bool s(int n) {
  stringstream ss;
  ss << n;
  string str1, str2;
  ss >> str1;
  str2 = str1;
  reverse(str2.begin(), str2.end());
  return str1 == str2;
}

int main() {
  int n, res = 0;
  cin >> n;
  rep (i, 10000) if (abs(n - res) > abs(n - i) && s(i)) res = i;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int>a(N);
  vector<int>b(N);
  vector<int>c(M);
  vector<int>d(M);
  vector<int>ch(M);
  
  for(int i=0;i<N;i++){
    cin>>a.at(i)>>b.at(i);
    
  }
  
  for(int i=0;i<M;i++){
    cin>>c.at(i)>>d.at(i);
  }
  
  
  for(int i=0;i<N;i++){
    long long min=400000000;
    int sum=0;
    int ans;
    for(int j=0;j<M;j++){
      int X=abs(a.at(i)-c.at(j));
      int Y=abs(b.at(i)-d.at(j));
      
      sum=X+Y;
      if(sum<min){
        min=sum;
        ans=j+1;
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int r, d, x;
	long long now;

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

	now = x;

	for (int i = 0; i < 10; i++)
	{
		now = r * now - d;
		printf("%lld\n", now);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 3e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, Q, T;
int A[MAXN];

int main() {
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
	}
	int sum = 0;
	for (i = 1; i <= N; ++i) {
		for (j = i + 1; j <= N; ++j) {
			sum += A[i] * A[j];
		}
	}
	printf("%d", sum);
	return 0;
}


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

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define piii    pair<int, pair<int, int>>

vector<int> a;
vector<vector<int>> g;
vector<bool> win;
vector<bool> used;

bool dfs(int v) {
        used[v] = true;
        if (g[v].size() == 0) return win[v] = false;
        bool lose = true;
        for (int u : g[v]) {
                lose &= dfs(u);
        }
        return win[v] = !lose;
}

int main() {
        int n;
        cin >> n;
        a.resize(n);
        g.resize(n);
        win.resize(n);
        used.resize(n, false);
        for (int i = 0; i < n; i ++) {
                cin >> a[i];
        }
        for (int i = 0; i < n - 1; i ++) {
                int u, v;
                cin >> u >> v;
                u --, v --;
                if (a[u] == a[v]) continue;
                if (a[u] > a[v]) {
                        g[u].push_back(v);
                } else {
                        g[v].push_back(u);
                }
        }
        for (int i = 0; i < n; i ++) {
                if (!used[i]) dfs(i);
        }
        for (int i = 0; i < n; i ++) {
                if (win[i]) cout << i + 1 << ' ';
        }
        return 0;
}



Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};

int main () {
    int h, w; cin >> h >> w;
    vector<string> maze(h);
    rep(i, h) cin >> maze[i];
    vector<vector<int>> d(h, vector<int> (w, -1));
    int black = 0;
    rep(i, h) rep(j, w) {
        if (maze[i][j] == '#') black++;
    }
    d[0][0] = 1;
    queue<P> q;
    q.push({0, 0});
    while (!q.empty()) {
        auto v = q.front(); q.pop();
        int y = v.first, x = v.second;
        rep(i, 4) {
            int ny = y+dy[i], nx = x+dx[i];
            if (ny<0 || ny>=h || nx<0 || nx>=w || d[ny][nx]!=-1 || maze[ny][nx]=='#') continue;
            d[ny][nx] = d[y][x] + 1;
            q.push({ny, nx});
        }
    }
    if (d[h-1][w-1] == -1) {
        cout << -1 << endl;
        return 0;
    }
    cout << h*w - black - d[h-1][w-1] << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
As =   list(map(int,input().split(" ")))
Bs =   list(map(int,input().split(" ")))
ans = 0
for i in range(N):
    ans += min(As[i],Bs[i]) #i町での討伐数
    Bs[i] = max(Bs[i] - As[i] , 0 ) #勇者iの余力
    ans +=min(As[i + 1],Bs[i]) #i + 1町での討伐数
    As[i + 1] = max(As[i + 1] - Bs[i], 0)
    # if As[i] <= Bs[i]: #全員倒せた
    #     ans += As[i]
    #     Bs[i] -= As[i]
    #     if As[i + 1] <= Bs[i]:
    #         ans += Bs[i]
    #
    #
    #     As[i + 1] = max ( As[i + 1] - Bs[i] ,0)
    #
    # else: #全員は倒せなかった
    #     ans += Bs[i]

print(ans)

Measured memory_bytes: 19116
N=int(input())
A=[]
B=[]
if N%2==0:
  for i in range(1,N):
    for j in range(i+1,N+1):
      A.append((i,j))
  for i in range(N//2):
    B.append((i+1,N-i))
  D=set(A)-set(B)
  print(len(D))
  for a,b in D:
    print(a,b)
else:
  for i in range(1,N):
    for j in range(i+1,N+1):
      A.append((i,j))
  for i in range(N//2):
    B.append((i+1,N-i-1))
  D=set(A)-set(B)
  print(len(D))
  for a,b in D:
    print(a,b)

Measured memory_bytes: 4208