akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, m; cin >> n >> m;
    int l, r; cin >> l >> r;
    rep(i, m - 1) {
        int a, b; cin >> a >> b;
        chmax(l, a);
        chmin(r, b);
    }
    cout << max(r - l + 1, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
/// 12:09 am 02/08/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)

#include<bits/stdc++.h>

using namespace std;
#define endl '\n'
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll x;
    cin >> x;
    if (x < 600) {
        cout << 8 << endl;
    } else if (x < 800) {
        cout << 7 << endl;
    } else if (x < 1000) {
        cout << 6 << endl;
    } else if (x < 1200) {
        cout << 5 << endl;
    } else if (x < 1400) {
        cout << 4 << endl;
    } else if (x < 1600) {
        cout << 3 << endl;
    } else if (x < 1800) {
        cout << 2 << endl;
    } else if (x < 2000) {
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
N=int(input())
ans=0
i=1
while i**2<N:
    if N%i==0:
        if i>1 and N//(i-1)==N%(i-1):
            ans+=i-1
        j=N//i
        if j!=i and N//(j-1)==N%(j-1):
            ans+=j-1
    i+=1
print(ans)

Measured memory_bytes: 40300
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
for i, a in enumerate(A[::-1]):
    if N - i > N // 2:
        B[-(i+1)] = 1 if a == 1 else 0
    else:
        x = N-i
        n = 2
        c = 0
        while N >= x*n:
            if B[x*n-1] == 1:
                c += 1
            n += 1
        if c % 2 == 1:
            B[-(i + 1)] = 0 if a == 1 else 1
        else:
            B[-(i + 1)] = 1 if a == 1 else 0

M = B.count(1)
if M:
    ans = []
    print(M)
    for i, v in enumerate(B):
        if v == 1:
            ans.append(i+1)
    print(*ans)
else:
    print(0)


Measured memory_bytes: 14132
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let vec: Vec<i64> = (0..n).map(|_| read()).collect();

    let mut a: [i64; 100010] = [<i64>::max_value(); 100010];
    a[0] = 0;

    for i in 0..n-1 {
        for j in 1..k+1{
            if i+j < n {
                a[i+j] = cmp::min(a[i+j], a[i] + (vec[i+j] - vec[i]).abs());
            }
        }
    }

    println!("{}", a[n-1]);
}

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 gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 5116
"""
1 2 3 4 5
1 1 1 1 9   4 4 4 4 36=53 | 1 1 1 1 49
"""
import math
n = int(input())
a = list(map(int, input().split()))

ave1 = math.ceil(sum(a)/n)
ave2 = math.floor(sum(a)/n)
ans1 = 0
ans2 = 0

for _a in a:
    ans1 += (_a - ave1)**2

for _a in a:
    ans2 += (_a - ave2)**2

print(min(ans1, ans2))

Measured memory_bytes: 3064
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader;

public class Main {
    static class IO {
        BufferedReader br;
        StringTokenizer st;

        public IO() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readarray(int sz) {
            int[] ret = new int[sz];
            for (int i = 0; i < sz; i++)
                ret[i] = nextInt();
            return ret;
        }
    }

    public static void main(String[] args) {
        IO fs = new IO();
        String s = fs.nextLine();
        Stack<Integer> st = new Stack<Integer>();
        int n = s.length();
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0' || s.charAt(i) == '1') {
                st.push(s.charAt(i) - '0');
            } else {
                if (st.isEmpty())
                    continue;
                else
                    st.pop();
            }
        }
        ArrayList<Integer> ans = new ArrayList<Integer>();
        while(!st.empty()){
            ans.add(st.pop());
        }
        for(int i = ans.size()-1; i>=0; i--){
            System.out.print(ans.get(i));
        }
        System.out.println();
    }
}


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

int main() {
  string a;
  string b;
  int c;
  cin >> a;
  cin >> b;
  c = 0;
  for (int i = 0; i < (int)a.size(); ++i) {
    char ac = a[i];
    char bc = b[i];
    if (ac != bc) {
      c++;
    }
  }
  cout << c << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<ll> a;
ll n,k;
const bool DBG = false;

ll ss(){
  ll x = 0;
  rep(i,n){
    x += a[i];
  }
  return x;
}

ll check(ll t){
  ll x = 0;
  vector<ll> p;
  vector<ll> l, r;
  p.resize(n);
  l.resize(n);
  r.resize(n);
  rep(i,n){
    p[i] = a[i]%t;
  }
  sort(all(p));
  l[0] = p[0];
  for(int i = 1; i < n; ++i){
    l[i] += p[i] + l[i-1];
  }
  r[n-1] = t-p[n-1];
  for(int i = n-2; i >= 0; --i){
    r[i] += t-p[i] + r[i+1];
  }

  if(DBG){
    rep(i,n){
      cout << r[i] << " ";
    }cout << endl;
    rep(i,n){
      cout << l[i] << " ";
    }cout << endl;
  }

  for(int i = 0; i < n-1; ++i){
    if (l[i] == r[i+1] && l[i] <= k){
      return t;
    }
    if( abs(l[i]-r[i+1])%t == 0 && max(l[i], r[i+1]) <= k ){
      return t;
    }
  }

  return -1;
}

int main(void){
  ll ans = 0;
  cin >> n >> k;
  a.resize(n);
  rep(i, n){
    cin >> a[i];
  }

  ll x = ss();

  if(DBG) cout << x << endl;
  for(ll i = 1; i * i <= x; ++i){
    if(x % i == 0){
      if(DBG) cout << "check" << i << endl;
      ll tmp = check(i);
      if (tmp != 0){
        ans = max(ans, tmp);
      }
      if(DBG) cout << "check" << x/i << endl;
      tmp = check(x/i);
      if (tmp != 0){
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


fn gcd(a: i64, b:i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}


fn main() {
    let t:usize = read();
    for i in 0..t {
        let v:Vec<i64> = read_vec();
        let (a, b, c, d) = (v[0], v[1], v[2], v[3]);
        /*
        if a % b + b - 1 < c {
            println!("Yes");
        } else {
            println!("No");
        }
        */
        if b > d {
            println!("No");
        } else if a < b {
            println!("No");
        } else if a % b > c {
            println!("No");
        } else {
            let gcdr = gcd(b, d);
            let mut num2 = a % b + ((b - 1 - (a % b)) / gcdr) * gcdr;
            // println!("\na % b {0}, (b - 1 - (a % b) / gcdr) * gcdr {1}", a % b, ((b - 1 - (a % b)) / gcdr) * gcdr);
            // println!("{0}, {1}, {2}, {3}", gcdr, num2, a, b);
            if num2 > c {
                println!("No");
            } else {
                println!("Yes");
            }
        }
    }
}


Measured memory_bytes: 4352
n, x = map(int, input().split())
a = [int(_) for _ in input().split()]
ans = max(0, a[0]-x)
a[0] -= ans
for i in range(n-1):
    if a[i] + a[i+1] > x:
        val = a[i] + a[i+1] - x
        a[i+1] -= val
        ans += val
print(ans)

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

int main(){

    int n,m,c;
    int ans=0;
    cin>>n>>m>>c;
    vector<int> b(m);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0;i<m;i++) cin>>b[i];
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            sum+=a[i][j]*b[j];
        }
        if(sum>-c) ans++;
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256
R,G,B,N=map(int,input().split())
ans=0
for r in range(N+1):
    if r*R>N:
        break
    else:
        for g in range(N+1):
            if ((r*R)+(g*G))>N:
                break
            else:
                if (N-(r*R)-(g*G))%B==0:
                    ans+=1
print(ans)

Measured memory_bytes: 40688
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
i=n//100
j=n%10
if i == j:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 77212
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

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

class UnionFind:
    def __init__(self, node:int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]
        
    def find(self, x:int) -> int:
        if x == self.par[x]:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x:int, y:int) -> bool:
        if self.isSame(x,y):
            #print("x and y has already united")
            return False
        
        rx = self.find(x)
        ry = self.find(y)
        
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = self.par[ry]
        else:
            self.par[ry] = self.par[rx]
            
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1
                
        return True
                
    def isSame(self, x:int, y:int) -> bool:
        return self.find(x) == self.find(y)
    
from collections import defaultdict
    
n,k,l = li()
pq = []
rs = []

for _ in range(k):
    pq.append(tuple(li_()))
    
for _ in range(l):
    rs.append(tuple(li_()))

road = UnionFind(n)
rail = UnionFind(n)

for p,q in pq:
    road.unite(p,q)
    
for r,s in rs:
    rail.unite(r,s)
    
for i in range(n):
    road.find(i)
    
for i in range(n):
    rail.find(i)
    
road_dic = {i:set() for i in range(n)}
rail_dic = {i:set() for i in range(n)}

for i in range(n):
    road_dic[road.par[i]].add(i)
    rail_dic[rail.par[i]].add(i)
    
ans_dic = defaultdict(int)
for i in range(n):
    if ans_dic[(road.par[i], rail.par[i])] == 0:
        ans_dic[(road.par[i], rail.par[i])] = len(road_dic[road.par[i]] & rail_dic[rail.par[i]])
    
ans = []
for i in range(n):
    ans.append(ans_dic[(road.par[i], rail.par[i])])
    
print(*ans)

Measured memory_bytes: 209616
#define _GLIBCXX_DEBUG
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <random>
#include <utility>
#include <map>
#include <vector>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#define REP(i,x) for(int i=0; i<(x); i++)
#define all(x) (x).begin(),(x).end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;


int main(int argc, const char * argv[]) {
    int h,w;
    cin >> h >> w;
    vvi s(h, vi(w));
    REP(i,h){
        REP(j, w){
            char tmp;
            cin >> tmp;
            if(tmp == '#') s[i][j] = 1;
        }
    }
    vvi count(h, vi(w));
    count[0][0] = s[0][0];
    REP(i,w-1){
        count[0][1+i] = count[0][i] + max(s[0][1+i] - s[0][i], 0);
    }
    REP(i,h-1){
        count[1+i][0] = count[i][0] + max(s[1+i][0] - s[i][0], 0);
    }
    for(int i=1; i<h; i++){
        for(int j=1; j<w;j++){
            count[i][j] = min(count[i][j-1] + max(s[i][j] - s[i][j-1], 0), count[i-1][j] + max(s[i][j] - s[i-1][j], 0));
        }
    }
    cout << count[h-1][w-1] << endl;
    
    return 0;
}


Measured memory_bytes: 384
l = []
s = set()
while True:
	n, a = input()
	if n == a == 0:
		break;
	l.append(a)
	s.add(a)

s = list(s)
s.reverse()
while True:
	try:
	    n = input()
	except:
		break
	print(s.index(l[n-1])+1)

Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
int main(){
    int  a, b ,c;
    char X,Y;
    string S1,S2;
    cin >>a >> b >> c;
    
    if(c-b <= 0) cout << "delicious" <<endl;
    if(a >= c-b && c -b > 0) cout << "safe" << endl;
    if(a < c -b) cout << "dangerous" << endl;
    



}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int n;
  cin>>n;
  int ans=n*n;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_s.to_i
a = gets.to_s.split.map{|t| t.to_i }

a = a.map.with_index{|t,i| [t,i] }.sort.reverse

dp = Array.new(n+1){ [0] * (n+1) }

a.each_with_index do |tmp,i|
  a, k = *tmp
  (i+1).times do |j|
    dp[i+1][j+1] = [ dp[i+1][j+1],  dp[i][j] + (k-j) * a       ].max
    dp[i+1][j]   = [ dp[i+1][j],    dp[i][j] + (n-i+j-1-k) * a ].max
  end
end

puts dp[-1].max

Measured memory_bytes: 45756
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 30003;
const int K = 20;
vector < pair < int, int > > con[N];
set < pair < pair < int, int >, pair < int, int > > > s;
vector < pair < int, int > > g[N], sp[N];
int p[N], sz[N], u[N], w[N], v[N], aw[N], insp[N];
int dfs(int v, int tar, int p = -1, int pw = 1e15){
    if (v == tar) return pw;
    for (auto u: sp[v]){
        if (u.F == p) continue;
        int x = dfs(u.F, tar, v, u.S);
        if (x != 1e15){
            x = max(x, u.S);
            return x;
        }
    }
    return 1e15;
}
int gt(int x){
    if (p[x] == x) return x;
    return p[x] = gt(p[x]);
}
void unite(int x, int y){
    x = gt(x);
    y = gt(y);
    if (sz[x] < sz[y]) swap(x, y);
    p[y] = x;
    sz[x] += sz[y];
}
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1);
    int z = binpow(x, y / 2);
    return z * z % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    int x;
    cin >> x;
    for (int i = 1; i <= m; i++){
        cin >> u[i] >> v[i] >> w[i];
        g[u[i]].pb({v[i], w[i]});
        g[v[i]].pb({u[i], w[i]});
        s.insert({{w[i], i}, {u[i], v[i]}});
    }
    for (int i = 1; i <= n; i++){
        p[i] = i;
        sz[i] = 1;
    }
    int spw = 0;
    while(!s.empty()){
        auto z = *s.begin();
        s.erase(s.begin());
        int u = z.S.F;
        int v = z.S.S;
        if (gt(u) != gt(v)){
            unite(u, v);
            sp[u].pb({v, z.F.F});
            sp[v].pb({u, z.F.F});
            insp[z.F.S] = 1;
            spw += z.F.F;
        }
    }
  //  cout << "spw = " << spw << endl;
    for (int i = 1; i <= m; i++){
        if (insp[i]) continue;
        aw[i] = w[i] - dfs(u[i], v[i]);
      //  cout << i << " " << aw[i] << endl;
    }
    if (x < spw){
        cout << 0;
        return 0;
    }
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    for (int i = 1; i <= m; i++){
        if (aw[i] == 0) cnt1++;
        if (aw[i] == x - spw) cnt2++;
        if (aw[i] > x - spw) cnt3++;
    }
    //cout << "cnt1 = " << cnt1 << endl;
    if (x == spw){
        cout << binpow(2, cnt3) * (binpow(2, cnt1) - 2) % mod;
        return 0;
    }
    cout << binpow(2, cnt3) * (binpow(2, cnt2) - 1) % mod * 2LL % mod;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    map<int,int> mp;
    rep(i,n){
        int p;cin>>p;p--;
        mp[p]=i+1;
    }
    vector<int> a(n,0),b(n,0);
    a[0]=mp[0];
    b[n-1]=mp[n-1];
    rep(i,n-1){
        a[i+1]=a[i]+mp[i+1];
        b[n-i-2]=b[n-1-i]+mp[n-i-2];
    }
    rep(i,n)cout<<a[i]<<" ";
    cout<<endl;
    rep(i,n)cout<<b[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 4680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		char[] s = sc.nextLine().toCharArray();
		char[] a = new char[]{'A', 'B', 'C'};
		long answer = 0;

		for (int i = 0; i < s.length; i++) {
			for (int j = 0; j < 3 && i + j < s.length; j++) {
				if (s[i + j] != a[j]) break;
				if (j == 2) answer++;
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,M;
  cin>>N>>M;
  ll L[M],R[M];
  rep(i,M) cin>>L[i]>>R[i];
  ll mi=1;
  ll ma=N;
  for(int i=0;i<M;i++){
    mi=max(mi,L[i]);
    ma=min(ma,R[i]);
  }
  ll ans=0;
  if(mi<=ma) ans=ma-mi+1;
  cout<<ans<<endl;
}


Measured memory_bytes: 5184
class Stats:
    def __init__(self, is_AC=False, cnt=0):
        self.is_AC = is_AC
        self.cnt = cnt


N, M = map(int, input().split())

S = [Stats() for _ in range(N)]

for _ in range(M):
    p, s = input().split()
    p = int(p)

    if not S[p - 1].is_AC:
        S[p - 1].cnt += 1

    if s == 'AC':
        S[p - 1].is_AC = True

print(
    len(list(filter(lambda s: s.is_AC, S))),
    sum(map(lambda s: s.cnt - 1, (filter(lambda s: s.is_AC, S))))
)


Measured memory_bytes: 21232
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
#define REP(i,n) for (int i = 1; i<= (n); i++)
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
const long double PI = acos(-1);
using ll = long long;
using ld = long double;
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    if (y % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i <= (x); i++){
        if (y == i*2 + (x-i)*4) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    int N; cin >> N;
    int ans=0;
    int cnt[N+1]={};
    for(int i=1;i*i<=N;i++){
        for(int j=1;j*j<=N;j++){
            for(int k=1;k*k<=N;k++){
                int res=i*i+j*j+k*k+i*j+j*k+i*k;
                if(res<=N){
                    cnt[res]++;
                }
            }
        }
    }
    for(int i=1;i<=N;i++){
        cout << cnt[i] << endl;
    }
}

Measured memory_bytes: 3528
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int m[n];
    unsigned int s=0,d=0;
    for(int i=0;i<n;i++) cin >> m[i];
    sort(m,m+n);
    d = m[0];
    for(int i=1;i<n;i++){
      s += d;
      d += m[i];
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var ans = Array(n);
  ans[0] = a[0]+a[n-1];
  for(var i = 1; i < n; i++){
    ans[i] = (a[i-1] - ans[i-1]/2)*2;
  }
  if((ans[0]+ans[n-1])/2 !== a[n-1]){
    ans[0] -= (ans[0]+ans[n-1])/2 - a[n-1]
    for(var i = 1; i < n; i++){
      ans[i] = (a[i-1] - ans[i-1]/2)*2;
    }
  }
  return ans.join(" ");
}

Measured memory_bytes: 38220
n = int(input())
i=1
x=[1]
while(6**i<=n):
    x.append(6**i)
    i+=1
i=1
while(9**i<=n):
    x.append(9**i)
    i+=1

dp=[0]
for i in range(1,n+1):
    k=n
    for j in x:
        if j<=i:
            k=min(dp[i-j]+1, k)
    dp.append(k)
print(dp[-1])

Measured memory_bytes: 3860
{-# LANGUAGE OverloadedStrings #-}
module Main where
 
import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char
import Data.Bits
 
modN = 1000000007
 
 
readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)
 
readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)
 
readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine
 
readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
 
split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las
 
pow :: Int -> Int -> Int -> Int
pow base 1 modNum = base `mod` modNum
pow base time modNum
    | odd time = let 
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a * base `mod` modNum
    | otherwise = let
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a `mod` modNum
 
 
 
main = do
    r <- readInt
    print $ (fromIntegral r) * 2 * 3.1415926
 
 
 

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll n,a,b,ng=0,ok=-1;cin>>n>>a>>b;
  vector<ll> h(n);
  for(int i=0;i < n;i++)
  {
    cin>>h[i];
    ok=max(ok,(h[i]+b-1)/b);
  }
  

  while(abs(ok-ng)>1){
    ll mid=(ng+ok)/2,need=0;

    rep(i,n){
      need+=max((h[i]-b*mid+a-b-1)/(a-b),0ll);//ここ
    }

    if(need<=mid){
      ok=mid;
    }else{
      ng=mid;
    }
  }

  cout<<ok<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    string s;
    cin >> s;
    if(s.substr(0,4) == "YAKI")cout << "Yes\n";
    else cout << "No\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in);) {
			
			int seconds = sc.nextInt();
			
			LocalTime time = LocalTime.ofSecondOfDay(seconds);
			
			DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:m:s");
			
			System.out.println(time.format(formatter));
		}
		
	}

}


Measured memory_bytes: 32756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

// dijkstra
template<class T>
struct dijkstra {
    struct edge{int to, cost;};
    vector<T> d;
    vector<vector<edge>> G;

    dijkstra(int n) {init(n);} 

    void init(int n) {
        G.resize(n);
        d.resize(n);
        rep(i,n) d[i] = inf;
    }

    void add_edge(int s, int t, int cost) {
        edge e;
        e.to = t; e.cost = cost;
        G[s].push_back(e);
    }

    void run(int s) {
        priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
        d[s] = 0;
        q.push(pair<T,int>(0,s));
        while (!q.empty()) {
            pair<T,int> e = q.top(); q.pop();
            int v = e.second;
            if (d[v] < e.first) continue;
            for (auto e: G[v]) {
                if (chmin(d[e.to],d[v]+e.cost)) {
                    q.push(pair<T,int>(d[e.to],e.to));
                }
            }
        }
    }
};

int main() {
    int H, W; cin >> H >> W;
    int c_h ,c_w; cin >> c_h >> c_w;
    c_h--; c_w--;
    int d_h, d_w; cin >> d_h >> d_w;
    d_h--; d_w--;
    vector<string> field(H);
    rep(i,H) cin >> field[i];
    dijkstra<int> dj(H*W);
    rep(i,H)rep(j,W) {
        for (int h = -2; h <= 2; h++) {
            for (int w = -2; w <= 2; w++) {
                if (h == 0 && w == 0) continue;
                int n_i = i + h;
                int n_j = j + w;
                if (n_i >= 0 && n_i < H && n_j >= 0 && n_j < W) {
                    if (field[n_i][n_j] == '#') continue;
                    if (abs(h) + abs(w) == 1) {
                        dj.add_edge(W*i+j,W*n_i+n_j,0);
                    } else {
                        dj.add_edge(W*i+j,W*n_i+n_j,1);
                    }
                }
            }
        }
    }
    dj.run(W*c_h+c_w);
    int ans = dj.d[W*d_h+d_w];
    if (ans != inf) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 172252
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
const int maxn = 4000+500;
long long save[maxn];
map<long long, bool> mp;
map<long long, long long> which;
void init(){
    mp.clear();
    which.clear();
    for(long long i=0; i<=4000; i++){
        save[i] = i*i*i*i*i;
        mp[save[i]] = true;
        which[save[i]] = i;
    }
}
int main(){
    init();
    long long x;
    cin>>x;
    for(int i=0; i<=4000; i++){
        if(mp[x-save[i]]){
                cout<<which[x-save[i]]<<" "<<-which[save[i]]<<endl;
                break;
        }else if(mp[ x+save[i] ]){
                cout<<which[x+save[i]]<<" "<<which[save[i]]<<endl;
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 4136
#include <bits/stdc++.h>
#define yes { cout << "YES" << endl; exit(0); }
#define no { cout << "NO" << endl; exit(0); }
#define impossible { cout << "Impossible" << endl; exit(0); }

using namespace std;

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

string a;
int N, K;
vector<int> v;

void return_ans(vector<int> v)
{
    int ans = 0;
    for(auto it : v) ans += it/2;

    bool ok = 0;

    int i;
    int cnt1 = 0, cnt2 = 0;

    for(i=0; a[i] == a[0]; ++i) ++cnt1;
    for(i=N-1; a[i] == a[0]; --i) ++cnt2;

    ok = (K > 1 && cnt1 % 2 == 1 && cnt2 % 2 == 1);
    cout <<  (ll) K * ans - (ok ? 1 : 0) << '\n';
    exit(0);
}

int main()
{
  //  freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> a >> K;
    N = a.size();

    int i, nr = 0, cnt = 1;

    for(i=1; i<N; ++i)
        if(a[i] != a[i-1])
        {
            if(nr > 0 || K == 1 || a[0] != a[N-1]) v.push_back(cnt);
            cnt = 1;
            ++nr;
        }
        else ++cnt;

    if(nr == 0)
    {
        cout << (ll) N * K / 2 << '\n';
        return 0;
    }

    if(K > 1 && a[0] == a[N-1])
    {
        for(i=0; a[i] == a[N-1]; ++i)
            ++cnt;
        v.push_back(cnt);
    }
    else v.push_back(cnt);

    return_ans(v);

    return 0;
}


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

int main(){
    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, 0, H) cin >> a[i];

    ll h = 0, w = 0;
    ll d1[2] = {1,0}, d2[2] = {0,1};
    ll th, tw;
    vector<vector<bool>> s(H, vector<bool>(W, false));
    s[0][0] = true;
    while(true){
        ll c = 0;
        rep(i, 0, 2){
            ll nh = h+d1[i];
            ll nw = w+d2[i];
            if(nh < H && nw < W && a[nh][nw] == '#'){
            s[nh][nw] = true;
                c++;
                th = nh; tw = nw;
            }
        }
        if(c != 1){
            cout << "Impossible" << endl;
            return 0;
        }
        if(th == H-1 && tw == W-1) break;
        h = th; w = tw;
    }

    rep(i, 0, H){
        rep(j, 0, W){
            if(!s[i][j] && a[i][j] == '#'){
            cout << "Impossible" << endl;
            return 0;

            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
S = [[-float("inf")] for k in range(N)]
for k in range(N):
    t, d = map(int,input().split())
    S[t-1].append(d)

top = []
hoka = []
for k in range(N):
    S[k].sort()
    top.append(S[k].pop())
    hoka += S[k]

top.sort(reverse=True)
hoka.sort(reverse=True)

T = [0 for k in range(N+1)]
H = [0 for k in range(N+1)]
T[1], H[1] = top[0], hoka[0]
for k in range(2,N):
    T[k] = T[k-1] + top[k-1]
    H[k] = H[k-1] + hoka[k-1]

ans = 0
for k in range(1,K+1):
    ans = max(ans,T[k]+H[K-k]+k**2)
print(ans)

Measured memory_bytes: 77904
h, w = map(int, input().split())

s = ["." * (w + 2)]
for i in range(h):
    s.append("." + input() + ".")
s.append("." * (w + 2))

ans = "Yes"
for h_i in range(1, h + 1):
    for w_i in range(1, w + 1):
        if s[h_i][w_i] == "#":
            if s[h_i-1][w_i] == "." and s[h_i+1][w_i] == "." and s[h_i][w_i-1] == "." and s[h_i][w_i+1] == ".":
                ans = "No"

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#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 INF 1145141919810893//810114514
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define rollcall cout<<"I'm Sucu."<<endl
#define int long long 


signed main(){
    int N;
    cin >> N;
    cout << ((N>999)?"ABD":"ABC") << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> d(n);
   rep(i, n) { cin >> d[i]; }
   sort(d.begin(), d.end());
   int ans = d[n / 2] - d[n / 2 - 1];
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 640
from collections import deque

def bfs():
    q = deque()
    color1 = [-1] * (n + 1)
    color2 = [-1] * (n + 1)
    for i in range(1, n + 1):
        if color1[i] == -1:
            color1[i] = i
            q.append(i)
            while q:
                p = q.popleft()
                for j in G[p]:
                    if color1[j] == -1:
                        color1[j] = color1[p]
                        q.append(j)
        if color2[i] == -1:
            color2[i] = i
            q.append(i)
            while q:
                p = q.popleft()
                for j in H[p]:
                    if color2[j] == -1:
                        color2[j] = color2[p]
                        q.append(j)
    group = [color1[i] + 200000 * color2[i] for i in range(n + 1)]
    return group

n, k, l = map(int, input().split())
G = [[] for _ in range(n + 1)]
H = [[] for _ in range(n + 1)]
for _ in range(k):
    p, q = map(int, input().split())
    G[p].append(q)
    G[q].append(p)
for _ in range(l):
    r, s = map(int, input().split())
    H[r].append(s)
    H[s].append(r)
group = bfs()
d = {}
for i in range(1, n + 1):
    if group[i] in d:
        d[group[i]] += 1
    else:
        d[group[i]] = 1
ans = [0] * n
for i in range(1, n + 1):
    ans[i - 1] = d[group[i]]
print(" ".join(map(str, ans)))

Measured memory_bytes: 80400
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};


llint n, m;
UnionFind uf(100005);
set<llint> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	llint a, b;
	for(int i = 1; i <= m; i++){
		cin >> a >> b;
		uf.unite(a, b);
	}
	
	for(int i = 1; i <= n; i++) S.insert(uf.root(i));
	
	cout << (int)S.size() - 1 << endl;
	
	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

VI toBin(LL a)
{
	VI res;
	FOR (i, 0, 61)
	{
		res.PB(a & 1);
		a /= 2;
	}
	reverse(ALL(res));
	return res;
}

LL toInt(VI a, int start)
{
	LL res = 0;
	FOR (i, start, SZ(a))
	{
		res *= 2;
		res += a[i];
	}
	return res;
}

ostream& operator <<(ostream& os, VI a)
{
	FOR (i, 0, SZ(a))
	{
		os<<a[i]<<' ';
	}
	return os;
}

int getLen(LL a)
{
	int res = 0;
	while(a)
	{
		a /= 2;
		res++;
	}
	return res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	LL a, b;
	cin>>a>>b;

	VI A = toBin(a);
	VI B = toBin(b);

	int ind = -1;

	FOR (i, 0, SZ(A))
	{
		if (A[i] == B[i]) continue;

		ind = i;
		break;
	}

	if (ind == -1)
	{
		cout<<1<<endl;
		return 0;
	}

	if (ind == SZ(A) - 1)
	{
		cout<<2<<endl;
		return 0;
	}

//	cout<<A<<endl<<B<<endl;

	LL res = 0;

	LL val = toInt(A, ind + 1);

	LL all = 1ll << (SZ(A) - ind - 1);

	val = all - val;

	res += val;

	LL v1 = toInt(A, ind + 1);
	LL t2 = toInt(B, ind + 1);
	int len = getLen(t2);
	LL v2 = 1ll << len;

	if (v1 <= v2) res += all;
	else
	{
		res += v2;
		res += val;
	}

	cout<<res<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    ll X, Y;
    cin >> X >> Y;
    ll ans = INF<ll>;
    for (int c = 0; c <= max(X, Y) * 2; c++) {
        ans = min(ans, A * max(0LL, X - c / 2) + B * max(0LL, Y - c / 2) + C * c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
S=str(input())
s=len(S)
Sk=[]
Sg=[]
for i in range(0,s,2):
    Sk.append(S[i])
for i in range(1,s,2):
    Sg.append(S[i])
Sk0=Sk.count('0')
Sk1=Sk.count('1')
Sg0=Sg.count('0')
Sg1=Sg.count('1')
Stotal=[Sk0,Sk1,Sg0,Sg1]
if Sk0+Sg1<Sk1+Sg0:
    print(Sk0+Sg1)
else:
    print(Sk1+Sg0)

Measured memory_bytes: 3956
#include <stdio.h>

int main()
{
    int n = 0 ,m = 0, tmp = 0;
    scanf("%d %d", &n, &m);
    int sum = 0;
    for (int i = 0; i < m; ++i)
    {
        scanf("%d", &tmp);
        sum += tmp;
    }
    int result = (n >= sum) ? n - sum : -1;
    printf("%d\n", result);
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const string YES = "Yes";

int main(){
    int n, m;
    cin >> n >> m;
    vector<vi> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].pb(b);
        g[b].pb(a);
    }
    queue<int> q;
    vi dir(n, INF);
    q.push(0);
    dir[0] = -1;
    while (!q.empty()) {
        int p = q.front(); q.pop();
        for (int i : g[p]) {
            if (dir[i]!=INF) continue;
            q.push(i);
            dir[i] = p;
        }
    }
    bool ans = true;
    rep(i, n) {
        if (dir[i]==INF) ans = false;
    }
    if (!ans) puts("No");
    else {
        puts("Yes");
        rep1(i, n-1) cout << dir[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<ll> divisor;
void find_divisor(ll N) {
  for(int i=1; i<=sqrt(N); i++) {
    if(N % i == 0)
      divisor.push_back(i);
  }
  int n = divisor.size();
  for(int i=n-1; i>=0; i--) {
    if(N != (ll)pow(divisor[i], 2))
      divisor.push_back(N / divisor[i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n; cin >> n;
  find_divisor(n);
  ll ans = 0;
  for(ll d: divisor) {
    if(d > 1 && n/d < d-1) ans += d-1;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#define N_MAX 9
#define S_MAX 1000
#define V_MAX 100

int main(void)
{
    int n, s, v, v_max;

    static long int dp[N_MAX + 1][S_MAX + 1][V_MAX + 1];

    /* n = 1 */
    for(v_max = 0; v_max <= V_MAX; v_max++)
        for(s = 0; s <= v_max; s++)
            dp[1][s][v_max] = s <= v_max;

    /* n >= 2 */
    for(n = 2; n <= N_MAX; n++)
        for(s = 0; s <= S_MAX; s++)
            for(v_max = 0; v_max <= V_MAX; v_max++)
            {
                long int sum = 0;
                for(v = 1; v <= s && v <= v_max; v++)
                    sum += dp[n - 1][s - v][v - 1];
                dp[n][s][v_max] = sum;
            }

    while(scanf("%d %d", &n, &s), n + s)
        printf("%ld\n", dp[n][s][V_MAX]);

    return 0;
}

Measured memory_bytes: 7004
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var a = lines[0].split(' ');
 var b = a.map(function(str) { return Number(str)});
 var c = [];
 for(i=0; i<3; i++){
   var min = Math.min(...b);
   c.push(min);
   
   var index = b.indexOf(min);
   
   b.splice(index,1);

 }
   //console.log(index);

   //console.log(b);
   
 
 console.log(c.join(' '));
});


Measured memory_bytes: 16268
(N,M),*ab = [tuple(map(int, s.split())) for s in open(0)]

ab.sort()

max_a = 0
min_b = float('inf')

ans = 1
for i, (a, b) in enumerate(ab):
    if min_b <= a:
        ans += 1
        max_a, min_b = a, b
    else:
        max_a = max(max_a, a)
        min_b = min(min_b, b)

print(ans)

Measured memory_bytes: 87184
#include <iostream>
#include <stdint.h>
using namespace std;

int main() {
	int64_t all;
	int64_t b, r;
	int64_t div = 0;
	int64_t left = 0;

	cin >> all >> b >> r;

	if (b == 0) {
		printf("0");
		return 0;
	}
	else {
		div = all / (b + r);
		left = all % (b + r);
		if (left >= b) {
			printf("%ld\n", b*(div + 1));
		}
		else {
			printf("%ld\n", div*b + left);
		}
	}

	return 0;
}

Measured memory_bytes: 256