akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 1e+5 + 10;
const ll INF = 1LL << 50;

ll A[MAX_N], X[MAX_N];
ll sum[MAX_N], even_sum[MAX_N];

int main() {
    int N, Q;
    cin >> N >> Q;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        sum[i] = A[i] + sum[i - 1];
        even_sum[i] = even_sum[i - 1];
        if (i % 2 == 0) even_sum[i] += A[i];
    }
    A[N + 1] = INF;
    for (int i = 0; i < Q; i++) cin >> X[i];
    for (int i = 0; i < Q; i++) {
        int left = 0, right = N;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            // mid番目が境界となるか調べる
            // mid番目を高橋くんが最後にとるところとする
            int takahashi = N - mid + 1;
            int sub = abs(X[i] - A[mid]);
            int low = lower_bound(A + 1, A + N + 2, X[i] - sub) - A;
            int high = upper_bound(A + 1, A + N + 2, X[i] + sub) - A;
            int aoki = high - low;
            if (low == mid) aoki--;
            if (takahashi <= aoki) right = mid;
            else left = mid;
        }
        int cnt = N - right + 1;
        int idx = right - cnt;
        ll ans = sum[N] - sum[right - 1];
        if ((idx - 1) % 2 == 0) ans += even_sum[idx - 1];
        else ans += sum[idx - 1] - even_sum[idx - 1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
static const int MAX=100000;

int main(){
    string s;
    cin>>s;
    int cunt =0;
    for(int i=0;i<3;i++){
        if(s[i]=='o')
            cunt++;
    }

    cout<<700+100*cunt<<"\n";
    return 0;
}



Measured memory_bytes: 256
_n = gets.to_i
prices = readlines.map(&:to_i)
current_min = prices[0]
prices.shift
max_profit = prices[0] - current_min
prices.each do |price|
  max_profit = [max_profit, price - current_min].max
  current_min = [current_min, price].min
end
puts max_profit



Measured memory_bytes: 19612
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = scan!(i64, i64);
    let vs = scan!(i64,i64;n);
    let ws = scan!(i64,i64;m);

    for &(a, b) in vs.iter() {
        let mut min_val = 1 << 60;
        let mut min = 0;
        for (i, &(c, d)) in ws.iter().enumerate() {
            let d = (a - c).abs() + (b - d).abs();
            if d < min_val {
                min_val = d;
                min = i as i64 + 1;
            }
        }
        println!("{}", min)
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll> v;
int main()
{
	ll n;cin>>n;
	for (int i = 1; i <= 9; i++)
	{
		v.push_back(i);
	}
	ll t=9;
	ll first=0;
	while(1)
	{
		if(t>100001) break;
		ll top=v[first];
		if(top%10==0)
		{
			v.push_back(top*10);
			v.push_back(top*10+1);
			t+=2;
		}
		else if(top%10==9)
		{
			v.push_back(top*10+8);
			v.push_back(top*10+9);
			t+=2;
		}
		else
		{
			ll tt=top%10;
			v.push_back(top*10+tt-1);
			v.push_back(top*10+tt);
			v.push_back(top*10+tt+1);
			t+=3;
		}
		first++;
	}
	cout<<v[n-1]<<endl;

	
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec h(N);
    rep(i, N) cin >> h[i];
    ll res = 0;
    while(1){
        bool flg=true;
        bool p = false;
        rep(i, N){
            if(h[i] > 0){
                flg = false;
                h[i]--;
                if(!p){
                    res++;
                    p = true;
                }
            }else{
                p = false;
            }
        }
        if(flg) break;
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

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

	string s;
	cin >> s;

	if (s[0] == 'A')cout << 'T';
	if (s[0] == 'T')cout << 'A';
	if (s[0] == 'C')cout << 'G';
	if (s[0] == 'G')cout << 'C';

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef long long ll;

ll dp[101][21];
int a[101],n;

ll func(int i, int res){

  if(res<0 || 20<res)return 0;
  if(dp[i][res]>0)return dp[i][res];
  if(i>n-2 && res==a[n-1])return 1;
  else if(i>n-2 && res!=a[n-1])return 0;

  ll ans=0;
  ans+=func(i+1,res+a[i]);
  if(i)ans+=func(i+1,res-a[i]);
  
  return dp[i][res]=ans;
}


int main(void){

  while(cin >> n){
    for(int i=0;i<n;i++)
      cin >> a[i];

    for(int i=0;i<=n;i++)
      for(int j=0;j<21;j++)
	dp[i][j]=0;
    
    cout << func(0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1176
def z a,b,c,d
a*d-b*c>0
end
def x a,b,c,d,e,f,s,t
z(a-c,b-d,a-s,b-t)==(k=z c-e,d-f,c-s,d-t)&&k==z(e-a,f-b,e-s,f-t)
end
gets.to_i.times{*a,g,h,i,j=gets.split.map &:to_i
puts x(*a,g,h)^x(*a,i,j)?:OK:"NG"}

Measured memory_bytes: 6172
def get_exp_mod(base, exp, mod):
    exp_bin = str(format(exp, 'b'))  # ２進表現
    res = 1
    for i in range(len(exp_bin)):
        if exp_bin[-i - 1] == '1':
            res = res * base % mod
        base = base * base % mod  # base^2^nをmodで割ったあまり

    return res


def comb(n, r, mod):
    X = 1
    Y = 1
    for i in range(r):
        X = X * (n - i) % mod
        Y = Y * (i + 1) % mod
    return X * get_exp_mod(Y, mod - 2, mod) % mod


mod = 10 ** 9 + 7
n, a, b = map(int, input().split())


# 2^n -1のmodを求める
all_case = (get_exp_mod(2, n, mod) - 1) % mod

# nCa modを引く
print((all_case - comb(n, a, mod) - comb(n, b, mod)) % mod)


Measured memory_bytes: 3064
import java.io.PrintWriter
import java.util.ArrayDeque

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

/** edge info */
data class Edge<T>(val to: Int, var cost: T)

fun solve(out: PrintWriter) {
    val n = readInteger()
    val incidenceList = Array(n) { mutableListOf<Edge<Long>>() }
    repeat(n - 1) {
        val (a, b, c) = readLongList()
        incidenceList[a.toInt() - 1].add(Edge(b.toInt() - 1, c))
        incidenceList[b.toInt() - 1].add(Edge(a.toInt() - 1, c))
    }

    val (q, k) = readIntegerList()
    val kList = LongArray(n) { -1 }
    val queue = ArrayDeque<Int>()
    queue.addLast(k - 1)
    kList[k - 1] = 0
    while (queue.isNotEmpty()) {
        val p = queue.removeFirst()
        for (e in incidenceList[p]) {
            if (kList[e.to] == -1L) {
                kList[e.to] = kList[p] + e.cost
                queue.addLast(e.to)
            }
        }
    }

    repeat(q) {
        val (x, y) = readIntegerList()
        out.println(kList[x - 1] + kList[y - 1])
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 109404
s1 = list(str(input()))
s2 = list(str(input()))
s3 = list(str(input()))
import sys
for i in range(300):
    if i == 0:
        x = s1[0]
        s1.pop(0)
    else:
        if x == 'a':
            if len(s1) == 0:
                print('A')
                sys.exit()            
            x = s1[0]
            s1.pop(0)
        if x == 'b':
            if len(s2) == 0:
                print('B')
                sys.exit()            
            x = s2[0]
            s2.pop(0)     
        if x == 'c':
            if len(s3) == 0:
                print('C')
                sys.exit()            
            x = s3[0]
            s3.pop(0)

Measured memory_bytes: 38256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
std::vector<bool> IsPrime;

int main() {
	long long  counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	ll n, m;
	ll prob[100002], probac[100002];
	string ac[100000];
	cin >> n >> m;
	ll a;
	string in;
	rep(i, n + 1) {
		prob[i] = 0;
		probac[i] = 0;
	}
	rep(i, m) {
		cin >> a >> in;
		if (in == "WA" && probac[a] != 1) {
			prob[a]++;
		}
		if (in == "AC" && probac[a] ==0) {
			probac[a]++;
		}
	}
	ll ans = 0, ans2 = 0;
	rep(i, n + 1) {
		if (probac[i] > 0) {
			ans += prob[i];
		}
		ans2 += probac[i];
	}
	cout << ans2 << " " << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#define re register
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
namespace io
{
	template<typename T>void read(T &x)
	{
		x=0;char str=getchar();int ng=1;
		while(!isdigit(str)){if (str=='-')ng=-1;str=getchar();}
		while(isdigit(str)){x=(x<<3)+(x<<1);x+=str-48;str=getchar();}
		x*=ng;
	}
	int buf[100],top;
	template<typename T>void print(T x)
	{
		if (!x)putchar('0');
		if (x<0)putchar('-'),x=-x;
		while(x)buf[++top]=x%10,x/=10;
		while(top)putchar(buf[top--]+48);
	}
}
using io::read;
using io::print;
int n,k,s,tc;
int main()
{
	read(n);read(k);read(s);
	for (re int i=1;i<=k;++i)print(s),putchar(' ');
	if (n-k<s)tc=1;
	else tc=s+1;
	for (re int i=1;i<=n-k;++i)print(tc),putchar(' ');
	puts("");
	return 0;
}

Measured memory_bytes: 1280
def warshall_floyd(dist)
  # dist: 隣接行列
  #   dist[u][v]はe=(u, v)のコスト(dist[i][i] = 0, 存在しない場合はINF)
  res = dist.dup
  vertex_num = res.size
  vertex_num.times do |k|
    vertex_num.times do |i|
      vertex_num.times do |j|
        res[i][j] = [res[i][j], res[i][k] + res[k][j]].min
      end
    end
  end
  res
end



v, e = gets.split.map(&:to_i)
d = Array.new(v) { Array.new(v, Float::INFINITY) }
v.times { |i| d[i][i] = 0 }
edges = []
e.times do
  s, t, c = gets.split.map(&:to_i)
  d[s][t] = c
  edges << [s, t, c]
  # d[t][s] = c
end
res = warshall_floyd(d)
v.times do |i|
  edges.each do |edge|
    if res[i][edge[0]] + edge[2] < res[i][edge[1]]
      puts "NEGATIVE CYCLE"
      exit
    end
  end
end
res.each do |row|
  puts row.map{|x| x == Float::INFINITY ? "INF" : x} * " "
end


Measured memory_bytes: 7756
import sys
input = sys.stdin.readline

K = int(input())

def dfs(le, L, ret):
    if len(L) == le:
        ret.append(L)
        return ret
    l = L[-1]
    for num in range(max(0, l-1), min(l+1, 9)+1):
        ret = dfs(le, L+[num], ret)
    return ret

le = 0
ans = []
while True:
    le += 1
    for n in range(1, 10):
        ret = dfs(le, [n], [])
        if len(ret) < K:
            K -= len(ret)
        else:
            ans = ret[K-1]
            break
    if ans: break

print("".join([str(a) for a in ans]))

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

using namespace std;
long M = 1e9 + 7, n, k, ans = 1, l, r, sign = 1, a[1 << 18], x, y, i;

main() {
    cin >> n >> k;
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    r = n - 1;

    if (k % 2 == 1) {
        ans = a[r], r--, k--;
        sign = (ans < 0 ? -1 : 1);
    }

    while (k) {
        x = a[l] * a[l + 1], y = a[r] * a[r - 1];
        if (x * sign > y * sign) ans *= x % M, ans %= M, l += 2;
        else ans *= y % M, ans %= M, r -= 2;
        k -= 2;
    }
    

    cout << (ans + M) % M << endl;
}

Measured memory_bytes: 5116
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


M = 10**9+7 # 出力の制限
N = 10**4 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

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

N = 50
f = [None]*N
v = 1
for i in range(N):
    f[i] = v
    v *= (i+1)
def cmb(n, r, M=None):
    return (f[n] // f[r] // f[n-r])

n0 = sum(num%2==0 for num in a)
n1 = sum(num%2==1 for num in a)
ans = 0
if p==1:
    for i1 in range(1, n1+1, 2):
        ans += cmb(n1, i1)
else:
    for i1 in range(0, n1+1, 2):
        ans += cmb(n1, i1)
ans *= pow(2, n0)
print(ans)

Measured memory_bytes: 65560
N=int(input())
if 1<=N<=10**6:
    a=N*(N+1)/2
    b=N//15
    c_3=3*5*b*(5*b+1)/2
    c_5=5*3*b*(3*b+1)/2
    c_15=15*b*(b+1)/2
    a=a-c_3-c_5+c_15
    i=15*b+1
    if N%15==0:
        a=int(a)
        print(a)
    else:
        for i in range(15*b+1,N+1):
            if (i%5==0)or(i%3==0):
                a=a-i
                i+=1
        a=int(a)
        print(a)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (A >= K) {
        cout << K << endl;
    } else if (A + B >= K) {
        cout << A << endl;
    } else {
        cout << A - (K - A - B) << endl;
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    ll Q, H, S, D;
    ll N;
    cin >> Q >> H >> S >> D;
    cin >> N;
    ll ans = 0;
    ans = (N / 2) * min({D, 2 * S, 4 * H, 8 * Q}, [](const ll o1, const ll o2){return o1 < o2;})
            + (N % 2) * min({S, 2 * H, 4 * Q}, [](const ll o1, const ll o2){return o1 < o2;});
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline

k, a, b = map(int, input().split())
if b > a and k + 1 > a:
    ans = max(k + 1, (b - a) * math.floor((k + 1 - a) / 2) + (k + 1 - a) % 2 + a)
else:
    ans = k + 1
print(ans)


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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (u == s) cout << a - 1 << " " << b;
  if (u == t) cout << a << " " << b - 1;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, b int
	fmt.Scan(&n, &b)
	wtched := 0
	man := 1
	for {
		if n-wtched <= 2*b+1 {
			fmt.Println(man)
			return
		}
		wtched += 2*b+1
		man++
	}
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 24;

int main(void){
    vi a(5);
    for(; cin >> a[0];){
        range(i, 1, 5) cin >> a[i];

        int sum = 0;
        rep(i, 5){
            sum += max(40, a[i]);
        }

        cout << sum / 5 << endl;
    }

	return 0;
}

Measured memory_bytes: 1192
S = list(input())
N = len(S)
Ans = [0 for _ in range(N)]

left = 0
right = 0
mid = 0
for i in range(N-1):
    if S[i] == "R" and S[i+1] == "L":
        mid = i
    if S[i] == "L" and S[i+1] == "R":
        right = i
        if (mid - left) % 2 == 1:
            Ans[mid] += int((mid - left) / 2)
            Ans[mid+1] += int((mid - left) / 2) + 1
        else:
            Ans[mid] += (mid - left) / 2
            Ans[mid+1] += (mid - left) / 2
        if (right - (mid + 1)) % 2 == 1:
            Ans[mid] += int((right - (mid + 1)) / 2) + 1
            Ans[mid+1] += int((right - (mid + 1)) / 2)
        else:
            Ans[mid] += (right - (mid + 1)) / 2
            Ans[mid+1] += (right - (mid + 1)) / 2
        Ans[mid] += 1
        Ans[mid+1] += 1
        
        left = right + 1
    if i == N - 2:
        right = i+1
        if (mid - left) % 2 == 1:
            Ans[mid] += int((mid - left) / 2)
            Ans[mid+1] += int((mid - left) / 2) + 1
        else:
            Ans[mid] += (mid - left) / 2
            Ans[mid+1] += (mid - left) / 2
        if (right - (mid + 1)) % 2 == 1:
            Ans[mid] += int((right - (mid + 1)) / 2) + 1
            Ans[mid+1] += int((right - (mid + 1)) / 2)
        else:
            Ans[mid] += (right - (mid + 1)) / 2
            Ans[mid+1] += (right - (mid + 1)) / 2
        Ans[mid] += 1
        Ans[mid+1] += 1
        
        left = right + 1

print(*map(int, Ans))

Measured memory_bytes: 61448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

ll power(ll a,ll b,ll mod){
	ll ret=1;
	if(b>0){
		ret = power(a,b/2,mod);
		if(b%2==0)ret = (ret*ret)%mod;
		else ret = (((ret*ret)%mod)*a)%mod;
	}
	return ret;
}

int main(){
	int n,m;
	cin>>m>>n;
	cout<<power(m,n,1e9+7)<<endl;
}

Measured memory_bytes: 3100
N,M,X,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
if (X < Y)&(max(x) < min(y))&(max(x) < Y)&(X < min(y)):
    print("No War")
else:
    print("War")


Measured memory_bytes: 9176
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
 
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
 
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
 
def SMI(): return input().split()
def SLI(): return list(input())
 
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
 
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
 
def solve():
    S = SLI()
    l = len(S)
    MOD = 1000000007
    dp = [[0]*13 for _ in range(l+1)]
    dp[0][0] = 1
    mul = 1
    S = S[::-1]
    for i in range(l):
        if S[i] == '?':
            for q in range(10):
                for j in range(13):
                    dp[i+1][(q*mul + j)%13] += dp[i][j]
                    dp[i+1][(q*mul + j)%13] %= MOD
        else:
            for j in range(13):
                k = int(S[i])
                dp[i+1][(k*mul + j)%13] += dp[i][j]
                dp[i+1][(k*mul + j)%13] %= MOD
 
        mul = mul * 10 % 13
    # print(dp[-1])
    print(dp[-1][5] % MOD)
 
if __name__ == '__main__':
    solve()

Measured memory_bytes: 66040
fun main(args: Array<String>) {
    val (N,M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toLong() }.sorted().toLongArray()
    val BC = Array(M){ readLine()!!.split(" ").map { it->it.toLong() }}.sortedBy { -it[1] }

    var cursor=0
    var sum = 0.toLong()
    BC.forEach {
        if(cursor<N){
            for (i in 0 until it[0].toInt()){
                if(cursor+i>=N)break
                sum+=Math.max(A[cursor+i],it[1])
            }
            cursor+=it[0].toInt()
        }
    }
    for (i in cursor until N){
        sum+=A[i]
    }
    println(sum)
}

Measured memory_bytes: 95120
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll num[9];

string out(ll n){
  string res,o="0123456789abcdef";
  if(n>=16) return out(n/16)+o[n%16];;
  return res+o[n%16];
}

ll s2i(string s){
  ll res=0;
  for(int i=0;i<s.size();i++)
    if('0'<=s[i]&&s[i]<='9') res=res*16+s[i]-'0';
    else res=res*16+(10+s[i]-'a');
  return res;
}

ll ans;
bool saiki(ll a,ll b,int kai){
  if(kai==33)return true;
  ll sum0=0,sum1=0,c;
  for(int i=0;i<8;i++) {
    c=(num[i]>>kai)%2;
    sum0+=(c^0);
    sum1+=(c^1);
  }
  
  c=(num[8]>>kai)%2;
  
  ll na=a+(sum0<<kai);
  ll nb=b+((c^0)<<kai);
  if(na%(1LL<<kai)==nb%(1LL<<kai)&&saiki(na,nb,kai+1))return true;
  
  na=a+(sum1<<kai);
  nb=b+((c^1)<<kai);
  if(na%(1LL<<kai)==nb%(1LL<<kai) && saiki(na,nb,kai+1)) {
    ans|=(1LL<<kai);
    return true;
  }

  return false;
}

int main(){
  int q;
  cin >>q;
  while(q--){
    string str;
    for(int i=0;i<9;i++)cin>>str,num[i]=s2i(str);
    ans=0;
    saiki(0,0,0);
    cout<<out(ans)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N,ans;
    bool ok = true;
    ans = 0;
    cin >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++){
        cin >> data[i];
    }
      sort(data.begin(), data.end());

      for (int i = 0; i + 1 < N; ++i) {
        if (data[i] == data[i+1]) ok = false;
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
using namespace std;
vector<pair<long long,long long> > i;
long long u[11111110];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0;
  string s;
  cin >>s;
  if(s[0]==s[1]) cout <<1<<' '<<2<<'\n';
  else{
    for(int n=2;n<s.size();n++){
      if(s[n]==s[n-1]){
	cout <<n<<' '<<n+1<<'\n';
	return 0;
      }
      if(s[n]==s[n-2]){
	cout <<n-1<<' '<<n+1<<'\n';
	return 0;
      }
    }
    cout <<"-1 -1\n";
  }
  return (0);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
struct keitai{
    int key=0,val=0;
    vs d={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    void in(int k){
        if(key==k)val++;
        else{
            if(key) cout<<d[key][val%d[key].size()];
            key=k,val=0;
        }
    }
};
int main(void){
    int n;
    cin>>n;
    rep(i,n){
        keitai k;
        string s;
        cin>>s;
        for(auto c:s){
            k.in(c-'0');
        }
        cout<<endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX= 3005;

string s,t;
int dp[MAX][MAX];
char parent[MAX][MAX];


int lcs(int i , int j) {
    if( i < 0 || j < 0) {
        return 0;
    }
    if( dp[i][j] != -1) {
        return dp[i][j];
    }
    if( s[i] == t[j]) {
        parent[i][j] = 'D';
        return dp[i][j]=lcs(i-1,j-1) + 1;
    } else if(lcs(i-1,j) > lcs(i,j-1)){
        parent[i][j] = 'U';
        return dp[i][j] = lcs(i-1,j);
    } else {
        parent[i][j] = 'L';
        return dp[i][j] = lcs(i,j-1);
    }
}



int main() {
    ios_base::sync_with_stdio(false);
    for(int i = 0; i < MAX; i++) {
        for(int j = 0; j < MAX; j++) {
            dp[i][j] = -1;
        }
    }

    cin >> s >> t;
    lcs(s.size()-1,t.size()-1) ;

    int cx = s.size()-1;
    int cy = t.size()-1;
    string res="";
    while( cx >= 0 && cy >= 0 ) {
        if ( parent[cx][cy] == 'D') {
            res += s[cx];
            cx--;
            cy--;
        } else if ( parent[cx][cy] == 'U') {
            cx--;
        } else {
            cy--;
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<"\n"; 
    return 0;
}



Measured memory_bytes: 44800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {
    string N;
    cin >> N;
    ll leng = N.size();
    ll cnt = 0;
    rep(i,leng){
        char n = N.at(i);
        int a = ctoi(n);
        cnt += a;
    }
    if(cnt % 9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3692
# %%
class Queue:
    def __init__(self, size=100005):
        self.size = size
        self.q = [None] * self.size
        self.head = 1
        self.tail = 1

    def is_empty(self):
        return self.head == self.tail

    def enqueue(self, obj):
        self.q[self.tail] = obj
        if self.tail == self.size - 1:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.head == self.size - 1:
            self.head = 0
            return self.q[self.size - 1]
        else:
            self.head += 1
            return self.q[self.head - 1]


qu = Queue()

li = list(map(int, input().split()))
n = li[0]
q = li[1]

for i in range(n):
    li = list(map(str, input().split()))
    li[1] = int(li[1])
    qu.enqueue(li)

# q = 100
# qu.enqueue(['p1', 150])
# qu.enqueue(['p2', 80])
# qu.enqueue(['p3', 200])
# qu.enqueue(['p4', 350])
# qu.enqueue(['p5', 20])

time = 0
while True:
    temp_list = qu.dequeue()
    temp_name = temp_list[0]
    temp_num = temp_list[1]
    if temp_num <= q:
        time += temp_num
        print(temp_name + ' {}'.format(time))
        if qu.is_empty():
            break
    else:
        li = [temp_name, temp_num - q]
        qu.enqueue(li)
        time += q



Measured memory_bytes: 20088
#include<bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int n;
string sam[10005];
const ll MX=1e9;
ll tonum(string s)
{
  return (int)atoi(s.c_str());
}
string solve()
{
  ll upper,lower;
  string prev;
  upper=MX*2;lower=-MX*2;
  prev=to_string(upper);
  for(int i=0;i<n;i++)
    {
      if(sam[i]=="x")
	{
	  if(prev=="x") return "none";
	  if((i+1)%2==1)
	    {
	      upper=min(upper,tonum(prev));
	      if(i<n-1)upper=min(upper,tonum(sam[i+1]));
	    }
	  else
	    {
	      lower=max(lower,tonum(prev));
	      if(i<n-1) lower=max(lower,tonum(sam[i+1]));
	    }
	}
      else
	{
	  if((i+1)%2==1 && prev!="x")
	    {
	      if((tonum(prev))<=tonum(sam[i])) return "none";
	    }
	  else if(prev!="x")
	    {
	      if((tonum(prev)) >=tonum(sam[i])) return "none";
	    }
	}
      prev=sam[i];
      if(upper-lower<2) return "none";
    }
  if(upper-lower>2) return "ambiguous";
  return to_string((upper+lower)/2);
}
	  

int main(int argc,char const* argv[])
{
  while(1)
    {
      cin >> n;
      if(!n) break;
      for(int i=0;i<n;i++)
	{
	  cin >> sam[i];
	}
      cout << solve()<<endl;
    }
  return 0;
}
			       
	



Measured memory_bytes: 3396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
const int _=1e5+5;
#define ll long long
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int n,m;
char A[_],B[_];
map<ll,char>s;
map<ll,bool>vis;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",A);scanf("%s",B);
	int c=gcd(n,m);
	ll d=1ll*n*m/c;
	ll tmp=d/n;
	for(ll i=0;i<n;++i)
		s[i*tmp+1]=A[i],vis[i*tmp+1]=1;
	tmp=d/m;bool f=0;
	for(ll i=0;i<m;++i)
		if(vis[i*tmp+1]&&B[i]!=s[i*tmp+1]){f=1;break;}
	f?puts("-1"):printf("%lld\n",d);
	return 0;
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	string S;;
	cin>>S;
	int N = S.size();
	ll ans = 0;
	// 全探索 --- bit は {0, 1, ..., n-1} の 2^n 通りの部分集合全体を動きます。
	for (int bit = 0; bit < (1<<N-1); ++bit){
		/* bit で表される集合の処理を書く */
		ll res = S[0] - '0';
		for (int i = 0; i < N-1; ++i){
			if(bit & (1<<i)){
				ans += res;
				res = S[i+1] - '0';
			}
			else{
				res = res * 10 + (S[i+1] - '0');
			}
		}
		cerr<<res<<endl;
		ans += res;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,m;
    int i=0,j=0;
    int a[100][100],b[100],c[100]={0};
    
    scanf("%d %d",&n,&m);
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&b[j]);
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
        printf("%d\n",c[i]);
    }
    return 0;
}



Measured memory_bytes: 2084
n=int(input())
s=[list(input()) for i in range(n)]
ans=0
for i in range(n):
  ct=0
  for j in range(n):
    for k in range(n):
      if s[(j+i)%n][k]!=s[(k+i)%n][j]:
        ct+=1
  if ct==0:
    ans+=1
print(ans*n)

Measured memory_bytes: 47272
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
//int rnd(int x) { return mrand() % x;}
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int n,p[maxn],vis[maxn];
ll k;

int main()
{
	fastIO;
	cin >> n >> k;
	rep(i,1,n + 1) cin >> p[i];
	int i = 1; 
	vector<int>v;
	while(1) {
		v.pb(i);
		vis[i]++;
		if(vis[p[i]]) break;
		i = p[i];
	}	
	//for(auto it : v) cout << it << endl;
	int ed = v[v.size() - 1] ,st = p[ed] , len = 0;
	rep(i,0,SZ(v)) {
		if(v[i] == st) {
			len = v.size() - i;
			break;
		}
	}
	//cout << len << endl;
	if(k < v.size()) cout << v[k] << endl;
	else {
		k -= v.size();
		int t = k % len;
		int pos = 0;
		rep(i,0,SZ(v)){
			if(v[i] == st) {
				pos = i; break;
			}
		}
		cout << v[pos + t] << endl;
	}
	return 0;
}


Measured memory_bytes: 5820
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main()
{
    IOS;
	  int x;
	  cin>>x;
	  int ans = 2*(x/11);
	  x = x%11;
	  if(x>6) ans++;
	  if(x>0) ans++;
	  cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for (int i = 0;i < M;i++){
        cin >> X[i];
    }
    sort(X.begin(),X.end());
    
    vector<int> Y(M-1);
    for (int i = 0;i < M - 1;i++){
        Y[i] = X[i+1] - X[i];
    }
    sort(Y.begin(),Y.end());
    
    int ans = 0;
    for (int i = 0;i < M - N;i++){
        ans += Y[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
N = gets.to_i
As = gets.split.map(&:to_i)

@a = As.inject([0]){|r, a| r << r.last + a}.drop(1)
@b = As.reverse.inject([0]){|r, a| r << r.last + a}.drop(1)

def cut(a)
  (2 .. N - 3).each_with_object({1 => 0}) do |i, h|
    h[i] = (h[i - 1] ... i).find{|j| (a[i] - 2*a[j]).abs < (a[i] - 2*a[j + 1]).abs}
  end
end

def md(i, j, k)
  [@a[i], @a[j] - @a[i], @a[k] - @a[j], @a.last - @a[k]].minmax.inject(:-).abs
end

l = cut(@a)
r = cut(@b).map{|k, v| [N - 2 - k, N - 2 - v]}.to_h
puts (1 .. N - 3).map{|i| md(l[i], i, r[i])}.min

Measured memory_bytes: 69772
//by shubham_bitsg

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin>>c;
    if(isupper(c)) cout<<"A\n";
    else cout<<"a\n";
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

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

  VAR(int, N, M);

  bool exist[100010];
  vector<int> buff;
  vector<int> vec[100010];
  vector<int> p(M+5), y(M+5);
  rep(i, M) {
    IN(p[i], y[i]);
    vec[p[i]].emplace_back(y[i]);
    if (!exist[p[i]]) buff.emplace_back(p[i]);
    exist[p[i]] = true;
  }

  map<pii, i64> mp;
  rep(i, buff.size()) {
    int P = buff[i];
    sort(all(vec[P]));
    rep(j, vec[P].size()) {
      mp[make_pair(P, vec[P][j])] = j+1;
    }
  }

  rep(i, M) {
    OUTN(setw(6), setfill('0'), p[i]);
    OUTN(setw(6), setfill('0'), mp[make_pair(p[i], y[i])]);
    OUTL("");
  }

  return 0;
}


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

using namespace std;

int main()
{
  long long a,b,v,w,t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  
  if(a <= b)
  {
    if((a + v*t) >= (b + w*t))
    {
      cout << "YES";
    }
    else
    {
      cout << "NO";
    }
  }
  else
  {
    if((a - v*t) <= (b - w*t))
    {
      cout << "YES";
    }
    else
    {
      cout << "NO";
    }
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,ll>;
using Graph= vector<vector<ll>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
  ll a,v,b,w ,t ;cin>>a>>v>>b>>w>>t ;
  if((v-w)*t>=abs(a-b)) cout<<"YES"<<endl ;
  else cout<<"NO"<<endl ;
  return 0;
  }

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint N,P;
    cin >> N >> P;
    string S;
    cin >> S;
    lint ans=0;
    if(P==2){
        rep(i,N) if((S[i]-'0')%2==0) ans+=i+1;
        cout << ans << endl;
        return 0;
    }
    if(P==5){
        rep(i,N) if((S[i]-'0')%5==0) ans+=i+1;
        cout << ans << endl;
        return 0;
    }
    lint dp[N+10][10]={};
    rep(i,10) dp[0][i]=i%P;
    for(int i=1;i<N+5;i++) rep(j,10) dp[i][j]=(dp[i-1][j]*10)%P;
    lint mod[N]={};
    rep(i,N) mod[N-1-i]=dp[N-1-i][(S[i]-'0')];
    lint sum[N+1]={};
    rep(i,N) sum[i+1]=(sum[i]+mod[i])%P;
    sort(sum,sum+N+1);
    lint num=sum[0],count=0;
    rep(i,N+1){
        if(sum[i]==num) count++;
        else ans+=(count*(count-1))/2,count=1,num=sum[i];
    }
    if(count>1) ans+=(count*(count-1))/2;
    cout << ans << endl;
}

Measured memory_bytes: 19348
#include<bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    int a, b;
    cin >> a >> b;
    int sum = 0;
    for (int i = 1; i <= b-a; i++)
    {
        sum += i;
    }
    sum -= b;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string s;

void solve() {
  int cnt = 0;
  int l = 0, r = s.size() - 1;
  while (l < r) {
    if (s[l] == s[r]) {
      l++;
      r--;
    } else if (s[l] == 'x') {
      cnt++;
      l++;
    } else if (s[r] == 'x') {
      cnt++;
      r--;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> s;
  solve();
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

const int N = 2e5 + 5;
int arr[N], sz[N];

int root(int i)
{
  while(arr[i] != i)
  {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}

int Union(int x, int y)
{
  int rootX = root(x);
  int rootY = root(y);
  if(sz[rootX] < sz[rootY])
    swap(rootX, rootY);
  arr[rootY] = arr[rootX];
  if(rootX != rootY)
    sz[rootX] += sz[rootY];
  return max(sz[rootX], sz[rootY]);
}

int32_t main(){
  boost;
  int t = 1; //cin>>t;
  while(t--)
  {
    iota(arr, arr+N, 0);
    for(int i=0; i<N; i++)
      sz[i] = 1;
    int n, m; cin >> n >> m;
    int ans = 1;
    while(m--)
    {
      int a, b; cin >> a >> b;
      int cnt = Union(a, b);
      ans = max(ans, cnt);
    }
    cout << ans <<"\n";
  }
}



Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n;
    cin >> n;
    cout << (double) ((n + 1) / 2) / (double) n << endl;
    return 0;
}


Measured memory_bytes: 256