akhauriyash/Code-Regression huggingface dataset:
from math import ceil
N,D,A = list(map(int, input().split()))
P = []
for _ in range(N):
  P.append(list(map(int, input().split())))
  # X,H

P.sort()

#for p in P:
#  print(p)
  
# Attack[i] : i番目（Xi）を左端に爆弾を投げたとき、巻き込める最大の番号Xj
Attack = [-1 for _ in range(N)]
leftx, leftj = 0,0
for i in range(N):
  now = P[i][0]
  leftx = now + 2*D
  while leftj < N:
    if P[leftj][0] <= leftx:
      leftj += 1
    else:
      break
  Attack[i] = leftj - 1
  
#print(Attack)
# damage管理
# 範囲攻撃はimosっぽくやる。届いた左端に+Dして、届いた右端の右隣に-Dする
# 今までのダメージ総和をworkとして持ちつつ、imosで回復すればよい
wk_dam = 0
imos = [0] * (N+1)
ans = 0
for i in range(N):
  wk_dam += imos[i]
  #print(i,wk_dam,P[i][1],ans)
  if P[i][1] <= wk_dam:
    # すでに累積ダメージで死んでる
    continue
  cnt = (P[i][1] - wk_dam + A-1) // A # ceil(zanHP / A)
  wk_dam += cnt * A
  imos[i] += cnt * A
  imos[Attack[i]+1] -= cnt * A
  ans += cnt
  
print(ans)
#print(imos)

Measured memory_bytes: 122832
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for (int i = (a); i < (b); i++)
#define MOD 1000000007LL
#define N 2002
typedef long long ll;

int n, k;
ll dp[N][N], fct[N*N], inv[N*N], ifct[N*N];
int main() {
	scanf("%d %d", &n, &k);
	if (k==1) puts("1"), exit(0);
	fct[0] = 1;
	fo(i,1,N*N) fct[i] = (i * fct[i-1])%MOD;
	inv[1] = 1;
	fo(i,2,N*N) inv[i] = (-(MOD/i) * inv[MOD % i]) % MOD + MOD;
	ifct[0] = 1;
	fo(i,1,N*N) ifct[i] = (inv[i] * ifct[i-1])%MOD;
	dp[0][0] = 1;
	fo(i,0,n+1) fo(j,0,i+1) {
		dp[i+1][j] = (dp[i+1][j] + dp[i][j])%MOD;
		if (j < i) {
			int lft = n-i + (k-1)*(n - j - 1);
			dp[i][j+1] = (dp[i][j+1] + fct[lft + k-2] * (ifct[lft] * (ifct[k-2] * dp[i][j] % MOD)%MOD))%MOD;
		}
	}
	ll ans = (dp[n][n] * fct[n])%MOD;
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 116864
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  // dp[l][r] := m枚についてmax[l:r]の和
  // 値の更新は高々mn回
  ll n, m;std::cin >> n >> m;
  vll a(n, 0);
  for(int i=1;i<n;i++){
    ll tmp;scanf("%lld", &tmp);
    a[i] = a[i-1] + tmp;
  }
  vvl d = VV(m, n, 0, ll);
  //どこまで影響するか
  vvl e = VV(m, n, 0, ll);
  vvl pre = VV(m, n, -1, ll);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++) {
      scanf("%lld", &d[j][i]);
    }
  }
  vvl num = VV(n, n, 0, ll);
  ll ans = 0;
  vll event(n, 0);

  for(int l=n-1;l>=0;l--){
    //新しく入ってきた200要素がどこまで影響するか
    for(int i=0;i<m;i++){
      if(l==n-1) {
        e[i][l] = n - 1;
        event[l] += d[i][l];
      }else{
        ll t = l;
        while(t<n-1){
          if(d[i][t+1]<=d[i][l]) {
            event[t+1] -= (d[i][t+1] - (pre[i][t+1]==-1?0:d[i][pre[i][t+1]]));
            t = e[i][t+1];
          }else break;
        }
        event[l] += d[i][l];
        if(t!=n-1&&t==l) event[t+1] -= d[i][l];
        if(t!=n-1&&t!=l) event[t+1] -= (d[i][l] - d[i][pre[i][t+1]]);
        if(t!=n-1) pre[i][t+1] = l;
        e[i][l] = t;
      }
    }
    ll h = 0, cost = 0;
    for(int r=l;r<n;r++){
      if(l!=r) cost += a[r] - a[r-1];
      h += event[r];
      ans = max(ans, h - cost);
      /*
      if(ans < h - cost){
        std::cout << h << " " << cost << " " << l << " " << r << '\n';
      }
      */
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 219264
import std.stdio;
import std.array;
import std.conv;
import std.math;
import std.algorithm;
void main()
{
  string[] input = split(readln());
  int w = to!int(input[0]), h = to!int(input[1]), n = to!int(input[2]), ans = 0;
  
  input = split(readln());
  int x = to!int(input[0]), y = to!int(input[1]);
  for(auto i = 0; i < n - 1; i++)
  {
    input = split(readln());
    int tx = to!int(input[0]), ty = to!int(input[1]);
    if(tx - x < 0 && ty - y < 0 || tx - x > 0 && ty - y > 0)
      ans += max(abs(tx - x), abs(ty - y));
    else
      ans += abs(tx - x) + abs(ty - y);
    x = tx;
    y = ty;
  }
  writeln(ans);
}

Measured memory_bytes: 1048
N, K = map(int, input().split())
A = [0 for _ in range(10 ** 5)]
for i in range(N):
    a, b = map(int, input().split())
    A[a - 1] += b
for i in range(10 ** 5):
    if K - A[i] > 0:
        K = K - A[i]
    else:
        print(i + 1)
        break

Measured memory_bytes: 45168
n = int(input())
list_s = []
for i in range(n):
    list_s.append(int(input()))
sum = 0
list_s.sort()
for i in range(n):
    sum += list_s[i]
if sum%10 != 0:
    print(sum)
else:
    for i in range(n):
        if list_s[i]%10 != 0:
            print(sum - list_s[i])
            break
    else:
        print(0)        


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
	int n;
  	cin>>n;
 	int sum=0;	
  	int a[n+1];
  for(int i=0; i<n;i++){
	cin>>a[i];
    sum+=a[i];
  }
  cout<<sum-n<<endl;
}

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

const int INF = 1 << 30;
#define SQR(x) ((x)*(x))
int main(){
  int N, W, bm[12], bw[12];
  int *m, *w;

  while(cin >> N >> W, N){
    for(int i = 0; i < N; i++){
      cin >> bm[i];
    }
    for(int i = 0; i < W; i++){
      cin >> bw[i];
    }

    if(N < W){
      swap( N, W);
      m = bw, w = bm;
    } else {
      m = bm, w = bw;
    }

    vector< int > dp( 1 << W, -1);
    dp[0] = 0;
    for(int i = 0; i < N; i++){
      for(int j = (1 << W) - 1; j >= 0; j--){
        if(dp[j] == -1) continue;
        for(int k = 0; k < W; k++){
          if((j >> k) & 1) continue;
          dp[j|(1 << k)] = max( dp[j|(1 << k)], dp[j] + abs(m[i] - w[k]) * SQR(abs(m[i] - w[k]) - 30));
        }
      }
    }
    cout << *max_element( dp.begin(), dp.end()) << endl;
  }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(3)==s.at(2)){
     cout << "Bad" << endl;}
   else cout << "Good" << endl;
   return 0;
 }
     

Measured memory_bytes: 256
#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;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

ld dp[3001][3001];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	ld p[n + 1];
	for(int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	dp[0][0] = 1.0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= i; j++) {
			if(j >= 1) {
				dp[i][j] += dp[i - 1][j - 1] * p[i];
			}
			dp[i][j] += dp[i - 1][j] * (1 - p[i]);
		}
	}
	ld ans = 0;
	for(int i = 0; i <= n; i++) {
		if(i > n - i) {
			ans += dp[n][i];
		}
	}
	cout << fixed << setprecision(12) << ans;

	return 0;
}

Measured memory_bytes: 85672
using System;
class Program{
	static long m=14510;
	static double[] da=new double[m];
	static void Main(){
		long s=long.Parse(Console.ReadLine());
		long[][] arr=new long[m][];
		long i=0,n=1,t=1;

		while(i<m){
			if(n/t==999){t*=10;}

			string st=n.ToString();
			int a=0;
			for(var j=0;j<st.Length;j=(j+1)|0){a+=int.Parse(st[j].ToString());}

			arr[i]=new long[2];
			arr[i][0]=i;arr[i][1]=n;
			da[i]=1.0*n/a;
			
			i++;
			n+=t;
		}
		
		Array.Sort(arr,ca1);
		
		long b=0,k=0;
		for (int j=0;k<s;j++){
			if(b<arr[j][1]){
				Console.WriteLine("{0}",arr[j][1]);
				b=arr[j][1];
				k++;
			}
		}
	}
	static int ca1(long[] a,long[] b){
		if(da[a[0]]>da[b[0]]){return 1;}
		else if(da[a[0]]<da[b[0]]){return -1;}
		else{
			if(a[0]>b[0]){return 1;}
			else if(a[0]<b[0]){return -1;}
			else{return 0;}
		}
	}
}

Measured memory_bytes: 18256
#include <bits/stdc++.h>
using namespace std;
int main(){
    const char* a[]={"","MON","TUE","WED","THU","FRI","SAT","SUN"};
  	char s[3];
    scanf("%s",s);
    int i=1;
    for(;i<=7;++i)	if(!strcmp(s,a[i]))	break;
    printf("%d\n",7 - i == 0 ? 7 : 7 - i);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <fstream>


class Counter {
	std::vector<int> values, reversed;
public:
	Counter(std::vector<int> _values) :values{ std::move(_values) } {
		std::sort(values.begin(), values.end());
		reversed = values;
		std::reverse(reversed.begin(), reversed.end());
		for (auto& r : reversed) r = -r;
	}
	int count_pair(const long long int target, const long long int current) const {
		if (current == 0) {
			if (target >= 0) return values.size() - 1;
			else return 0;
		}
		else if (current > 0) {
			const auto count = std::distance(values.begin(), std::upper_bound(values.begin(), values.end(), (target < 0 ? (target - current + 1) / current : target / current)));
			if (current * current <= target) return count - 1;
			else return count;
		}
		else {
			const auto count = std::distance(reversed.begin(), std::upper_bound(reversed.begin(), reversed.end(), (target < 0 ? (target + current + 1) / -current : target / -current)));
			if (current * current <= target) return count - 1;
			else return count;

		}
	}
};
int main(){
	int n; long long int k; std::cin >> n >> k;
	std::vector<int> numbers(n); for (auto& a : numbers) std::cin >> a;
	Counter counter(numbers);
	long long int min = LLONG_MIN / 2, max = LLONG_MAX / 2;
	while (min < max) {
		const auto mid = (min + max - ((min + max) >= 0 ? 0 : 1)) / 2;
		long long int count = 0;
		for (const auto a : numbers) {
			count += counter.count_pair(mid, a);
		}
		if (count >= k * 2) {
			max = mid;
		}
		else {
			min = mid + 1;
		}
	}
	std::cout << max << std::endl;
}


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

//constexpr long double PIL = 3.141592653589793238462643383279502884L;
//constexpr double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

int main() {
	int n;
	string s;
	set<string> items;

	for (cin >> n; n > 0; --n) {
		cin >> s;
		items.insert(s);
	}

	cout << items.size() << '\n';
}


Measured memory_bytes: 19096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
// head
const int maxn = 2e5 + 5;
int n, a[maxn], f[maxn][27];
LL ans;

int main() {
	cin>>n;
	rep(i, 1, n) { 
	    cin>>a[i];
	    f[i][0] = a[i];
	}
	rep(k, 1, 25)
	    rep(i, 1, n) 
	    	if(i - (1<<(k - 1)) >= 0) f[i][k] = min(f[i][k - 1], f[i - (1<<(k - 1))][k - 1]);
	    	
	rep(i, 1, n) {
		int l = 1, r = i, x, y;
		while(l < r) {
			int mid = (l + r)>>1;
			int mi = 1e9, now = i;
			per(j, 25, 0) 
				if(1<<j <= now - mid + 1)
					mi = min(mi, f[now][j]), now -= 1<<j;
			if(mi == a[i]) r = mid;
			else l = mid + 1;
		}
		x = i - l + 1;
		l = i, r = n;
		while(l < r) {
			int mid = (l + r + 1)>>1;
			int mi = 1e9, now = mid;
			per(j, 25, 0) 
				if(1<<j <= now - i + 1)
					mi = min(mi, f[now][j]), now -= 1<<j;
			if(mi == a[i]) l = mid;
			else r = mid - 1;
		}
		y = l - i + 1;
		ans += (LL) x*y*a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 25488
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int mi = INT_MAX;
    int aa;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        if(chmin(mi, b)) aa = a;
    }

    cout << mi+aa << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
int main() {
    cin>>n>>m;
	ll haha=max(n,m);
	ll hehe=min(n,m);
	for(int i=m-n+1;i<=m+n-1;i++){
	    cout<<i<<" ";
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_071
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            string s1 = Read();
            string s2 = Read();
            var xys = new List<bool>();
            for(int i = 0; i < n;)
            {
                if (s1[i] == s2[i])
                {
                    xys.Add(true);
                    i++;
                }
                else
                {
                    xys.Add(false);
                    i += 2;
                }
            }
            long mask = 1000000000 + 7;
            long res = xys[0] ? 3 : 6;
            for(int i = 1; i < xys.Count; i++)
            {
                if (xys[i])
                {
                    if (xys[i - 1])
                    {
                        res *= 2;
                        res %= mask;
                    }
                    else
                    {
                        res *= 1;
                        res %= mask;
                    }
                }
                else
                {
                    if (xys[i - 1])
                    {
                        res *= 2;
                        res %= mask;
                    }
                    else
                    {
                        res *= 3;
                        res %= mask;
                    }
                }
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int N, M, fact[3009], inv[3009], factinv[3009], dp[3009][3009], pw[9000009], fermat[3009];
int main() {
	cin >> N >> M;
	fact[0] = 1;
	for (int i = 1; i <= N; i++) fact[i] = 1LL * fact[i - 1] * i % M;
	inv[1] = 1;
	for (int i = 2; i <= N; i++) inv[i] = 1LL * inv[M % i] * (M - M / i) % M;
	factinv[0] = 1;
	for (int i = 1; i <= N; i++) factinv[i] = 1LL * inv[i] * factinv[i - 1] % M;
	pw[0] = 1;
	for (int i = 1; i <= N * N; i++) pw[i] = 2 * pw[i - 1] % M;
	fermat[0] = 2;
	for (int i = 1; i <= N; i++) fermat[i] = 1LL * fermat[i - 1] * fermat[i - 1] % M;
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			dp[i][j] = (dp[i - 1][j - 1] + 1LL * j * dp[i - 1][j]) % M;
		}
	}
	int ret = 0;
	for (int i = 0; i <= N; i++) {
		int val = 1LL * fact[N] * factinv[i] % M * factinv[N - i] % M * fermat[N - i] % M;
		if (i & 1) val = (val == 0 ? 0 : M - val);
		for (int j = 0; j <= i; j++) {
			ret = (ret + 1LL * val % M * dp[i][j] % M * pw[(N - i) * j]) % M;
			ret = (ret + 1LL * (j + 1) * val % M * dp[i][j + 1] % M * pw[(N - i) * j]) % M;
		}
	}
	cout << ret << "\n";
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll n, k, a, b, x, y, ans, M=1e9+7;
int main() {
	int i;
	cin >> n >> k;
	for(a=0; a<k; a++) x += a;
	for(b=n; b>n-k; b--) y += b;
	ans = y-x+1;
	for(i=k; i<=n; i++) {
		x = (x + a) % M;
		++a;
		y = (y + b) % M;
		--b;
		ans = (ans + (y-x+1 + M)) % M;
	}
	cout << ans;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
//const ll INF = 1e18;
//const ld PI = acos(-1L);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int N;
    in(N);
    vector<ll> A(N+1);
    rep(i, N+1) in(A[i]);
    if (N == 0) {
        if (A[0] != 1) {
            out(-1);
        }
        else out(1);
        return 0;
    }
    vector<ll> dp(N+10, 0);
    vector<ll> suffix(N+1, 0);
    suffix[N] = A[N];
    for (int i=N-1; i>=0; i--) suffix[i] = suffix[i+1] + A[i];
    dp[0] = 1;
    rept(i, 1, N+1) {
        //out((dp[i-1] - A[i-1]) * 2);
        //out(suffix[i]);
        dp[i] = min((dp[i-1] - A[i-1]) * 2, suffix[i]);
        if (dp[i] < 0) {
            out(-1);
            return 0;
        }
    }
    if (dp[N] != suffix[N]) {
        out(-1);
        return 0;
    }
    ll ans = 0;
    rep(i, N+1) ans += dp[i];
    out(ans);


    return 0;
}


Measured memory_bytes: 5584
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){

  int n,i,j;
  int a[200007];
  int max = -999999;
  int t;
  int max2 = -999999;

  scanf("%d", &n);

  for(i = 1;i <= n;i++){
    scanf("%d", &a[i]);

    if(max < a[i]){
      max = a[i];
      t = i;
    }
  }

  for(i = 1;i <= n;i++){
    if(i != t) printf("%d\n", max);

    else{
      for(j = 1;j <= n;j++){
        if(j != t && max2 < a[j]) max2 = a[j];
      }

      printf("%d\n", max2);
    }
  }
  return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,x,y;
int a[2005];
int main()
{
    memset(a,0,sizeof(a));
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int d=min(j-i,abs(x-i)+abs(j-y)+1);
            a[d]++;
        }
    }
    for(int i=1;i<=n-1;i++)
        printf("%d\n",a[i]);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

class stack
{
private:
	int rail[10];
	int nowRail;
public:
	stack( void );
	void add( int number );
	int gone( void );
};

stack::stack( void )
{
	nowRail = 0;
}

void stack::add( int number )
{
	rail[nowRail] = number;
	nowRail++;
}

int stack::gone( void )
{
	nowRail--;
	return (rail[nowRail]);
}

int main( void )
{
	int number;
	stack* Stack = new stack();
	
	while( scanf( "%d", &number ) != EOF )
	{
		if( number == 0 )
		{
			printf( "%d\n", Stack->gone() );
		}
		else
		{
			Stack->add( number );
		}
	}
	
	return (0);
}

Measured memory_bytes: 1028
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    
  int n,a[100],c=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n-1;i++){ 
    int mini=i;
    for(int j=i;j<n;j++){
      if(a[j]<a[mini])mini=j;
    }
    int tmp=a[i];
    if(mini!=i)c++,a[i]=a[mini],a[mini]=tmp;
  }
  for(int i=0;i<n-1;i++)cout<<a[i]<<" ";
  cout<<a[n-1]<<endl;
  cout<<c<<endl;
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, t;
  cin >> n >> t;
  int cc = INF;
  bool ok = false;
  rep(i, n) {
    int c, tm;
    cin >> c >> tm;
    if (t >= tm) {
      ok = true;
      cc = min(cc, c);
    }
  }
  if (ok) {
    cout << cc << endl;
  } else {
    cout << "TLE" << endl;
  }
  
  return 0;
}

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

int main() {

    int k, a, b;
    cin >> k >> a >> b;
    
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    
    cout << "NG" << endl;
    


    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int now=0;
	string s;
	cin>>s;

	rep(i,0,s.size()){
		if(now%2==0 && s[i]=='A') now++;
		if(now%2 && s[i]=='Z') now++;
	}
	if(now/2==0){
		o(-1); return 0;
	}
	rep(i,0,now/2){
		cout<<"AZ";
	}
	cout<<endl;
}

Measured memory_bytes: 1180
import math
a, b, c = map(int, input().split())
r = math.radians(c)
S = math.sin(r) * a * b / 2
print(S)
d = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(r))
print(a + b + d)
h = math.sin(r) * b
print(h)

Measured memory_bytes: 7896
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class C{
  public:
    string s;
    int i, a, b, c;
    C(){}
    C(string _s, int _i, int _a, int _b, int _c) { s = _s; i = _i; a = _a; b = _b; c = _c; }
    bool operator < (const C &_) const {
      int x = a * 3 + c, y = _.a * 3 + _.c;
      return (x != y ? x > y : i < _.i);
    }
};

int main() {
  int N;
  bool f = false;
  while(cin >>N && N){
    if(f) cout <<endl;
    f = true;
    vector<C> v(N);
    REP(i, N){
      cin >>v[i].s >>v[i].a >>v[i].b >>v[i].c;
      v[i].i = i;
    }
    SORT(v);
    REP(i, N) cout <<v[i].s <<"," <<v[i].a * 3 + v[i].c <<endl;
  }


  return 0;
}

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

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

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int maxv = 100000;
int dp[maxv + 1];

void solve(int tc) {
    fill(dp + 1, dp + maxv + 1, 1 << 30);

    int N, W;
    cin >> N >> W;
    while (N--) {
        int w, v;
        cin >> w >> v;
        for (int i = maxv; i >= v; i--) {
            dp[i] = min(dp[i], dp[i - v] + w);
        }
    }
    
    for (int i = maxv;; i--)
        if (dp[i] <= W) return void(cout << i);
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) solve(tc);
}


Measured memory_bytes: 3960
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(i, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int main() { 
    int A = In<int>();
    int B = In<int>();
    cout << (B-1 + A-1  -1) / (A-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
LL ans[101010];

struct Mt{
    int c; // 石の個数.
    int i; // 山の番号.
    bool operator < (const Mt &rhs) const {
        return (c < rhs.c) || ((c == rhs.c) && (i > rhs.i));
    }
};

int main(){
    
    // 1. 入力情報.
    int N, a;
    scanf("%d", &N);
    priority_queue<Mt> pq;
    Mt mt;
    map<LL, LL> m;
    rep(i, N){
        scanf("%d", &a);
        mt.c = a;
        mt.i = i + 1;
        pq.push(mt); // {石の個数, 山の番号}
        m[mt.c]++;
    }
    
    // 2. 番兵.
    mt.c = 0;
    mt.i = 0;
    pq.push(mt);
    m[0] = 0;
    
    // 3. 累積和.
    LL t = 0;
    map<LL, LL> sCum;
    map<LL, LL>::reverse_iterator it;
    for(it=m.rbegin(); it!=m.rend(); ++it){
        t += it->b;      // 山の個数.
        sCum[it->a] = t; // 累積和を保存.
    }
    sCum[0] = 0; // 番兵分は, 除外.
    // for(auto &p : sCum) printf("key=%lld val=%lld\n", p.a, p.b);
    
    // 4. 集計.
    // 石の個数が変化したら, 山の番号を確認し, 減少していたら更新.
    LL cur = 0, bef = 0, idx = 101010;
    while(!pq.empty()){
        // 4-1. 要素を一つ取得.
        Mt m = pq.top();
        pq.pop();
        
        // 4-2. 現在の石の個数を取得.
        cur = (LL)m.c;
        
        // 4-3. 初回設定.
        if(idx == 101010) idx = m.i;
        
        // 4-4. 前回と変わっていたら, 更新.
        if(cur != bef){
            // 石の個数をカウント.
            ans[idx] += (bef - cur) * sCum[bef];
            
            // 山の番号を更新.
            if(idx > m.i) idx = m.i;
        }
        
        // 4-5. 前回分更新.
        bef = cur;
        // printf("c=%d i=%d\n", m.c, m.i);
    }
    
    // 5. 出力.
    repx(i, 1, N + 1) printf("%lld\n", ans[i]);
    return 0;
    
}

Measured memory_bytes: 17244
#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,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
  int n, m, sum=0;
  cin >> n;
  m = n;
  string s = to_string(m);
  rep(i, 0, s.size()){
    sum += s[i]-'0';
  }
  n%sum==0 ?cout<<"Yes":cout<< "No";
  cout << endl;
  //if(n%sum==0)cout<<"Yes" << endl;
  //else cout<<"No" << endl;
}

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

typedef long long ll;
const int inf = 1e9 + 7;
const int N = 5e3 + 1;

int n, x[N], y[N];
vector <int> g[N];

void dfs(int v){
      vector <int> dp(N, 1e9);
      dp[0] = 0;
      for(int to : g[v]){
            dfs(to);
            vector <int> old(N, 1e9);
            for(int i = 0; i <= 5000; i ++){
                  if(i + x[to] <= 5000) old[i + x[to]] = min(old[i + x[to]], dp[i] + y[to]);
                  if(i + y[to] <= 5000) old[i + y[to]] = min(old[i + y[to]], dp[i] + x[to]);
            }
            dp = old;
      }
      for(int i = 0; i <= x[v]; i ++)
            y[v] = min(y[v], dp[i]);
      if(y[v] == 1e9){
            puts("IMPOSSIBLE");
            exit(0);
      }
}

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

      for(int i = 2; i <= n; i ++){
            int p;
            scanf("%d", &p);
            g[p].pb(i);
      }

      for(int i = 1; i <= n; i ++){
            scanf("%d", &x[i]);
            y[i] = 1e9;
      }

      dfs(1);

      puts("POSSIBLE");
}


Measured memory_bytes: 9708
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

#define MAX_V 100005

struct edge { int to, cost; };
typedef pair<Int, Int> P;

vector<edge> G[MAX_V];
vector<Int> d(MAX_V);

void dijkstra(Int s) {
    priority_queue<P, vector<P>, greater<P>> q;
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    q.push({0, s});
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        Int v = p.second;
        if (d[v] < p.first) continue;
        for (Int i = 0; i < (Int)G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push({d[e.to], e.to});
            }
        }
    }
}

int main() {
    Int V, E, r;
    cin >> V >> E >> r;
    for (Int i = 0; i < E; i++) {
        Int a;
        edge b;
        cin >> a >> b.to >> b.cost;
        G[a].emplace_back(b);
    }
    dijkstra(r);
    for (Int i = 0; i < V; i++) {
        if (d[i] != INF) {
            dump(d[i]);
        }
        else {
            dump("INF");
        }
    }
    return 0;
}


Measured memory_bytes: 14400
def dot(x,y):
    cnt = 0
    for i in range(M):
        cnt += x[i]*y[i]
    return cnt
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
cor = 0
for _ in range(N):
    A = list(map(int,input().split()))
    if dot(A,B)+C>0:
        cor += 1
print(cor)  

Measured memory_bytes: 3060
import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
A = np.array(input().split(), np.int)
#print(A)

cnt = 0
for i in range(61):
    B = (A>>i)&1
    z = np.count_nonzero(B)
    cnt += z*(N-z)*(2**(i))
    cnt %= MOD

print(cnt)



Measured memory_bytes: 62808
#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;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
 
void solve(){
    char c;
    cin >> c;
    if(c > 'Z') {
        cout << 'a';
    }else {
        cout << 'A';
    }
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int n, m;
  cin >> n >> m;
  int count = 0;
  if (n != 0 && n != 1)
  {
    count += n * (n - 1) / 2;
  }
  if (m != 0 && m != 1)
  {
    count += m * (m - 1) / 2;
  }
  cout << count << endl;
}


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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) break;
		int p1=0,p2=0;
		for(int i=0;i<n;i++){
			int t1,t2;
			cin>>t1>>t2;
			if(t1==t2){
				p1+=t1;
				p2+=t2;
			}
			else if(t1>t2)
				p1+=t1+t2;
			else p2+=t1+t2;
		}
		cout<<p1<<" "<<p2<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  long long H, W, i, a, b, c, max, min, re;
  int h1, h2, h3, w1, w2, w3; 
  scanf("%lld %lld", &H, &W);
  re = H * W;

  if(H%3 == 0 || W%3 == 0){
    printf("0\n");
    return 0;
  }

  h1 = H/3; h3 = h1+1;
  min = (long long)h1*W;
  max = (long long)h3*W;
  if(re > (max-min)) re = max-min;

  w1 = W/3; w3 = w1+1;
  min = (long long)w1*H;
  max = (long long)w3*H;
  if(re > (max-min)) re = max-min;

  for(i = 1; i < H; i++){
    int w = W/2;
    a = W * i;
    b = (H-i) * w;
    c = (H-i) * (W-w);
    max = a;
    if(max < b) max = b;
    if(max < c) max = c;
    min = a;
    if(min > b) min = b; 
    if(min > c) min = c;

    if(re > max-min) re = max-min;
  }

for(i = 1; i < W; i++){
  int h = H/2;
    a = H * i;
    b = (W-i) * h;
    c = (W-i) * (H-h);
     max = a;
    if(max < b) max = b;
    if(max < c) max = c;
    min = a;
    if(min > b) min = b; 
    if(min > c) min = c;

    if(re > max-min) re = max-min;
 }

 printf("%lld\n", re);
 return 0;
}


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

int main() {
  int H, M, I, N, K;
  cin >> H >> M >> I >> N >> K;
  int a, b, c;
  a = 60 * H + M;
  b = 60 * I + N;
  c = b - a - K;
  
  cout <<  c << endl;
}

Measured memory_bytes: 3632
a, b, c, k = map(int, input().strip().split())


def solve():
    global k

    total = 0
    num_a = min(k, a)

    total += num_a

    k -= num_a

    if k <= 0:
        return total

    num_b = min(k, b)

    if k <= 0:
        return total

    k -= num_b

    num_c = k
    total -= num_c

    return total

print(solve())


Measured memory_bytes: 9180
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n, k, ans = 0, l;
    set<int> typ;
    vector<int> a(200000, 0);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        scanf("%d", &l);
        a[l] += 1;
        typ.insert(l);
    }
    sort(a.begin(), a.end());
    auto itr = lower_bound(a.begin(), a.end(), 1);
    for(int i = 0; i < int(typ.size()) - k; i++){
        ans += *itr;
        itr++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int W = s.nextInt();
		int H = s.nextInt();
		int C = s.nextInt();
		
		int a = 0;
		int b = 0;
		int c = 0;
		int x = 0;
		
		if(W>H){
			a = W;
			b = H;
		}else{
			a = H;
			b = W;
		}                   
		
		
		while(C>0){
			if(a%b != 0){
				c = a;
				a = b;
				b = c%b;
				
			}else{
				x = b;
				break;
			}
		}
		
		System.out.println(W/x * H/x * C);         
	}
}

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

using pint = pair<int,int>;

int main(){
    int n;
    cin >> n;
    int deadline;
    priority_queue<pint> q;
    rep(i,n){
        int a, b;
        cin >> a >> b;
        q.push(make_pair(b, a));
    }
    deadline = q.top().first;

    string ans = "Yes";
    while(!q.empty()){
        pint e = q.top(); q.pop();
        if(deadline > e.first) deadline = e.first;
        deadline -= e.second;
        if(deadline < 0){
            ans = "No";
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2420
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;
int main()
{
    double ans=0;

    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        double x;
        string s;

        cin >> x >> s;

        if (s == "JPY") {
            ans += x;
        }
        else {
            ans += 380000 * x;
        }
    }
    printf("%.5f", ans);
    return 0;
}



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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> time(5);
  rep(i,5){
    int T;
    cin >> T;
    time[i] = T;
  }
  int ANS = 999;
  sort(time.begin(),time.end());
  int ans=0;
  do{
    rep(i,4){
      ans += (time[i] + 9)/10 * 10;
    }
    ans += time[4];
    ANS = min(ans,ANS);
    ans = 0;
  }while(next_permutation(time.begin(),time.end()));
  
  cout << ANS << endl;
}

Measured memory_bytes: 256
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

void solve()
{
	string s;
	cin >> s;
	int ans1 = 0, ans2 = 0;
	char c = s[0];
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i] != s[i+1])
		{
			ans1++;
		}
	}
	reverse(all(s));
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i] != s[i+1]) ans2++;
	}
	cout << min(ans1,ans2);
}

int32_t main()
{
	FastIO;
	Fast_D;
	solve();
	return 0;
}


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

int main() {
	// your code goes here
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]){
	    cout << "Yes" << endl;
	}
	else
	    cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import sys, os
def ac_input(*args):
    return map(int, input().split())


def main():
    num = input()
    sseq = input().split()
    seq = map(int, sseq)
    prev = 0
    ans = int(sseq[0]) + int(sseq[-1])
    
    for i, s in enumerate(seq):
        ans = ans + min(s,prev)
        prev = s
        #print(ans)
    print(ans)    
if __name__ == "__main__" :
    main()



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long 
vector<int> s[1010];
signed main(void){
    // Your code here!
    int N;
    cin>>N;
    int sum = 0;
    int i;
    for (i = 0; i < 1010; i++) {
        sum += i;
        if(sum ==N)break;
        if(sum >N){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    int max = i;
    int now = 1;
    for (i = 0;; i++) {
        for (int j = i+1; j < max+1; j++) {
            s[i].push_back(now);
            s[j].push_back(now++);
            if(now == N+1) goto LOOP;
        }
    }
    LOOP:
    std::cout << "Yes" << std::endl;
    std::cout << 2*N/max << std::endl;
    for ( i = 0; i < 2*N/max; i++) {
        std::cout << max<<" ";
      for (int j = 0; j < max; j++) {
            /* code */
            std::cout <<s[i][j]<<" ";
        }
       std::cout << "" << std::endl;
    }
    return 0;    
}


Measured memory_bytes: 3200
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, D, X; cin >> N >> D >> X;
    vi A(N); REP(i, N) cin >> A[i];

    int sum = 0;
    REP(i,N) sum += (D - 1) / A[i] + 1;
    
    int ans = sum + X;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int k;
    cin >> k;

    int res = 0;

    for (int i = 1; i <= k; i++) {
        for (int j = i+1; j <= k; j++) {
            if ((i & 1) ^ (j & 1)) res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
A,B,C,D = map(int,input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
E = lcm(C,D)
print( (B-A+1)-((B//C-A//C + (A%C==0)) + (B//D-A//D+ (A%D==0)) - (B//E-A//E+ (A%E==0))))

Measured memory_bytes: 3064
from collections import defaultdict as dd
from collections import deque as dq
N, Q = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  
res = [0] * (N + 1)
for _ in range(Q):
  p, x = map(int, input().split())
  res[p] += x
visited = [0] * (N + 1)
Q = dq([])
Q.append(1)
visited[1] = 1
while len(Q) != 0:
  n = Q.pop()
  visited[n] = 1
  for o in e[n]:
    if visited[o] == 0:
      res[o] += res[n]
      Q.append(o)
#def dfs(n):
#  global visited
#  global res
#  visited[n] = 1
#  for o in e[n]:
#    if visited[o] == 0:
#      res[o] += res[n]
#      dfs(o)
#dfs(1)
sen = ""
for i in range(1, N + 1):
  sen += str(res[i])
  if i != N:
    sen += " "
print(sen)



Measured memory_bytes: 67872
class Stack:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._top = 0

    def push(self, x):
        if self.isFull():
            raise IndexError("stack is full")
        else:
            self._top += 1
            self._l[self._top] = x

    def pop(self):
        if self.isEmpty():
            raise IndexError("pop from empty stack")
        else:
            e = self._l[self._top]
            self._l[self._top] = None
            self._top -= 1
            return e

    def isEmpty(self):
        return self._top == 0

    def isFull(self):
        return self._top == self.n

def poland_calculator(s):
    n = len(s)
    stack = Stack(n)
    i = 0
    while i < n:
        if s[i] == ' ':
            i += 1
            continue
        elif s[i].isdigit():
            sn = ''
            while s[i].isdigit():
                sn += s[i]
                i += 1
            stack.push(int(sn))
        else:
            b = stack.pop()
            a = stack.pop()
            if s[i] == '+':
                e = a + b
            elif s[i] == '-':
                e = a - b
            else:
                e = a * b
            stack.push(e)
            i +=1

    return stack.pop()


if __name__ == '__main__':
    s = input()
    res = poland_calculator(s)
    print(res)



Measured memory_bytes: 5612
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	long long n, x;
	cin >> n >> x;
	long long ans = n;
	n -= x;
	bool flag = true;
	while (flag){
		long long temp = 2 * (n / x);			
		long long res = n % x;
		if (res == 0){
			temp -= 1;
			flag = false;
		}
		temp *= x;
		ans += temp;
		swap(n, x);
		x = res;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
const int INF=1000000000;

long long n,a,b,ng=0,ok=INF;

bool chk(int x,vector<long long> hp)
{
    long long tm=0;
    for(int i=0;i<n;i++){
        hp.at(i)-=b*x;
        hp.at(i)=max(0LL,hp.at(i));
        tm+=hp.at(i)/(a-b);
        if(hp.at(i)%(a-b)!=0)tm++;
    }
    return tm<=x;
}

int main()
{
    cin >> n >> a >> b;
    vector<long long > h(n);
    for(int i=0;i<n;i++)cin >> h.at(i);
    while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(chk(mid,h)){
            ok=mid;
        }else{
            ng=mid;
        }
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
public class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
     String str=sc.nextLine();
     String s1=str.substring(0);
      char c1=str.charAt(0);
      char c2=str.charAt(1);
      char c3= str.charAt(2);
     
      if(c1==c2 && c2==c3)
      System.out.println("No");
      else
      System.out.println("Yes");
      }
    
}

Measured memory_bytes: 35744
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

// nCr mod p(n<p)をキビキビ計算する
// 構築:O(n), クエリ:O(1)
struct combination_mod {
    using lint = long long int;
    int sz;
    lint mod;
    vector<lint> fac;
    vector<lint> finv;
    combination_mod(int _sz, int _mod) : sz(_sz), mod(_mod) {
        fac.assign(sz + 1, 1);
        finv.assign(sz + 1, 1);
        vector<lint> inv(sz + 1, 1);
        for (int i = 2; i <= sz; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    lint query(int n, int r) {
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
};
int main() {
    lint mod = 998244353;
    lint n, a, b, k;
    cin >> n >> a >> b >> k;
    combination_mod cm(n, mod);
    lint ans = 0;
    // Aでi箇所塗る
    for (int i = 0; i <= n; i++) {
        // m:Bの数
        lint rem = k - a * i;
        lint m = rem / b;
        if (rem < 0 || rem % b != 0 || m > n) continue;
        lint temp = cm.query(n, i) * cm.query(n, m);
        temp %= mod;
        ans += temp;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7424