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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    i64 x = 4 * a * b;
    i64 d = c - a - b;
    i64 y = d * d;
    if (d > 0 && x < y) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

n,m = map(int, stdin.readline().split())
an = [i*(-1) for i in map(int, stdin.readline().split())]
#print(an)
#print(sum(an))

import heapq
heapq.heapify(an)

for _ in range(m):
    b = heapq.heappop(an)
    heapq.heappush(an, (-1)*((-1)*b//2))

#print(an)
ans = (-1)*sum(an)
print(ans)

Measured memory_bytes: 20256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n, max = -INT_MAX, min = INT_MAX, in;
  long long sum = 0;
 
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> in;
    max = std::max(max, in);
    min = std::min(min, in);
    sum += in;
  }
  cout << min << " " << max << " " << sum << endl;
 
  return 0;
}

Measured memory_bytes: 3100
N = int(input())
array1 = []
array2 = []
for i in range(N):
    s = input()
    x1 = 0
    x2 = 0
    x3 = 0
    flag = True
    for j in range(len(s)):
        if s[j] == "(":
            if flag:
                x3 = 1
            else:
                x3 += 1
            flag = False
            x1 += 1
        elif s[j] == ")":
            x1 -= 1
            if flag:
                x2 += 1
            else:
                x3 -= 1
    if x3 < 0:
        x2 = x2 - x3
    if x1 >= 0:
        array1.append((-x2,x1))
    else:
        array2.append((x2+x1,-x2,x1))
array1.sort(reverse = True)
array2.sort(reverse = True)
sum = 0
ans = True
for i in range(len(array1)):
    if sum + array1[i][0] >= 0:
        sum += array1[i][1]
    else:
        ans = False
        break
for i in range(len(array2)):
    if sum + array2[i][1] >= 0:
        sum += array2[i][2]
    else:
        ans = False
        break
if sum != 0:
    ans = False
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 212240
function main(data){
    input = data.split(" ");
    x = parseInt(input[0],10);
    a = parseInt(input[1],10);
    b = parseInt(input[2],10);
    if(b - a <= 0){
        console.log("delicious");
    }else if(b - a > 0 && b - a <= x){
        console.log("safe");
    }else{
        console.log("dangerous");
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
fun lcm(n1: Long, n2: Long): Long {
    var temp: Long
    var m = n1
    var n = n2
    while (m % n != 0L) {
        temp = n
        n = m % n
        m = temp
    }
    return n1 / n * n2
}
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var a = readLine()!!.toLong()
    (2..N).map{
        var b = readLine()!!.toLong()
        a = lcm(a,b)
    }
    println(a)
}


Measured memory_bytes: 33684
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define t1 first
#define t2 second
#define ll long long
using namespace std;
int main()
{
	int a,b,x;
	cin>>a>>b>>x;
	if(x>a+b||x<a)
	cout<<"NO";
	else
	cout<<"YES"; 
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())

    def trial_division(n):
        """
        nの約数のリストをO(sqrt(n))で求める
        """
        divs = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.append(i)
                if i != n//i:
                    divs.append(n//i)
        return divs
    divs = trial_division(N)
    ans = 10**14
    for d in divs:
        i = N//d
        ans = min(ans, d - 1 + i - 1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39024
n, p = map(int, input().split())
s = input()

ans = 0
if p == 2:
    for i, char in enumerate(s):
        if int(char) % 2 == 0:
            ans += i + 1
    print(ans)

elif p == 5:
    for i, char in enumerate(s):
        if int(char) % 5 == 0:
            ans += i + 1
    print(ans)

else:
    a = [0] * (n + 1)
    for i in range(n):
        a[i + 1] = a[i] + int(s[n - i - 1]) * pow(10, i, p)
        a[i + 1] %= p
    memo = {}
    for i in range(n + 1):
        if a[i] not in memo:
            memo[a[i]] = 1
        else:
            memo[a[i]] += 1
    for i in memo:
        ans += memo[i]* (memo[i] - 1) // 2
    print(ans)

Measured memory_bytes: 43980
import java.util.Scanner;

public class Main {

  private static final long MOD = 998244353;
  private static long FACT[];
  private static long IFACT[];

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A = sc.nextInt();
    long B = sc.nextInt();
    long K = sc.nextLong();
    solve(N, A, B, K);
  }

  private static void solve(int N, long A, long B, long K) {
    FACT = new long[N+1];
    IFACT = new long[N+1];
    FACT[0] = 1;
    IFACT[0] = 1;
    for (int i=1; i<=N; i++) {
      FACT[i] = FACT[i-1] * i % MOD;
      IFACT[i] = inv(FACT[i]);
    }

    long ans = 0;
    /*
    for (int numA=0; numA<=N; numA++) {
      long rem = K - A*numA;
      if (rem < 0) {
        break;
      }
      int numB = (int)(rem/B);
      if ((long)A*numA+(long)B*numB == K && numB <= N) {
        ans = (ans + comb(N, numA) * comb(N, numB))%MOD;
      }
    }
    */
    long max = Math.min((long)N,K/A);
    for(int as=0;as<=max;++as){
      long bs = (K-A*as)/B;
      if(bs<=N && (A*(long)as + B*bs)==K){
        ans += comb(N,as) * comb(N,(int)bs);
        ans %= MOD;
      }
    }
    System.out.println(ans);
  }

  private static long comb(int n, int r) {
    if (n < 0 || r < 0 || n < r) {
      return 0;
    }
    if (r > n/2) {
      r = n - r;
    }
    return FACT[n]*IFACT[n-r]%MOD*IFACT[r]%MOD;
  }

  private static long inv(long a) {
    long b = MOD;
    long p = 1, q = 0;
    while (b > 0) {
      long c = a / b;
      long d;
      d = a;
      a = b;
      b = d % b;
      d = p;
      p = q;
      q = d - c * q;
    }
    return p < 0 ? p + MOD : p;
  }
}


Measured memory_bytes: 25812
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);

  const T: number[] = [];

  for (let i = 2; i < D + 2; i++) {
    const S = input[i].map(Number);

    const max = Math.max(...S);

    T.push(S.indexOf(max) + 1);
  }

  return T.join("\n");
};

console.log(main(read()));


Measured memory_bytes: 30560
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;
  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
}

const o = new AtCoder()
let s=o.s()
o.o('x'.repeat(s.length))

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

int main(){
    int N, M;
    cin >> N >> M;

    long long hairetu[3000];
    int a, b;

    for(int i=1; i<=M; i++){
        cin >> a >> b;
        ++hairetu[a];
        ++hairetu[b];
    }

    for(int i=1; i<=N; i++){
        cout << hairetu[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;

    if (n % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int a = scanner.nextInt();
		final int b = scanner.nextInt();
		final int c = scanner.nextInt();
		System.out.println(Math.min(b / a, c));
		scanner.close();
	}

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int f[10001][101][2];
char a[10001];
int main()
{
	int i,D,j,k,n;
	scanf("%s",a);
	scanf("%d",&D);
	f[0][0][1]=1;
	n=strlen(a);
	for(i=0;i<n;i++)
	{
		for(j=0;j<D;j++)
		{
			for(k=0;k<=9;k++)
			{
				f[i+1][(j+k)%D][0]=(f[i+1][(j+k)%D][0]+f[i][j][0])%1000000007;
			}
			for(k=0;k<=a[i]-'0';k++)
			{
				if(k==a[i]-'0')
					f[i+1][(j+k)%D][1]=(f[i+1][(j+k)%D][1]+f[i][j][1])%1000000007;
				else
					f[i+1][(j+k)%D][0]=(f[i+1][(j+k)%D][0]+f[i][j][1])%1000000007;
			}
		}
	}
	printf("%d",((f[n][0][0]+f[n][0][1]-1)%1000000007+1000000007)%1000000007);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T> class ReRooting {
  vector<T> res;
public:
  ReRooting(int n, vector<vector<int>> &_to, T identity, function<T(T, int)> trans, function<T(T, T)> merge) {
    res.resize(n);
    if (n == 1) {
      res[0] = identity;
      return;
    }
    vector<vector<int>> to(n), idx(n);
    for (int x = 0; x < n; x++) {
      for (int i = 0; i < _to[x].size(); i++) {
        int y = _to[x][i];
        if (x >= y)
          continue;
        idx[x].push_back(to[y].size());
        idx[y].push_back(to[x].size());
        to[x].push_back(y);
        to[y].push_back(x);
      }
    }
    vector<vector<T>> dp(n);
    for (int i = 0; i < n; i++)
      dp[i].resize(to[i].size());
    vector<int> ord = {0}, par(n);
    par[0] = -1;
    stack<int> st;
    st.push(0);
    while (!st.empty()) {
      int cur = st.top();
      st.pop();
      for (auto next : to[cur]) {
        if (next == par[cur])
          continue;
        par[next] = cur;
        ord.push_back(next);
        st.push(next);
      }
    }
    for (int i = n - 1; i > 0; i--) {
      int cur = ord[i], par_idx;
      T accum = identity;
      for (int j = 0; j < to[cur].size(); j++) {
        if (to[cur][j] == par[cur])
          par_idx = j;
        else
          accum = merge(accum, dp[cur][j]);
      }
      dp[par[cur]][idx[cur][par_idx]] = trans(accum, cur);
    }
    for (int i = 0; i < n; i++) {
      int cur = ord[i];
      vector<T> r_accum(to[cur].size());
      r_accum.back() = identity;
      for (int j = (int)r_accum.size() - 1; j > 0; j--)
        r_accum[j-1] = merge(r_accum[j], dp[cur][j]);
      T l_accum = identity;
      for (int j = 0; j < r_accum.size(); j++) {
        T accum = merge(l_accum, r_accum[j]);
        dp[to[cur][j]][idx[cur][j]] = trans(accum, cur);
        l_accum = merge(l_accum, dp[cur][j]);
      }
      res[cur] = l_accum;
    }
  }
  T query(int root) {
    return res[root];
  }
};

struct Data {
  ll num;
  int mod;
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ReRooting<Data> dp(n, to, Data({1, m}), [](auto x, auto y) {
    x.num++;
    return x;
  }, [](auto x, auto y) {
    ll a = x.num, b = y.num;
    int mod = x.mod;
    return Data({a*b%mod, mod});
  });
  rep(i, n)
    cout << dp.query(i).num << '\n';
  return 0;
}

Measured memory_bytes: 29304
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<double> P(N);
  rep(i,0,N) cin >> P[i];
  double now = 0;
  rep(i,0,K - 1) {
    now += (P[i] + 1) / 2;
  }
  double ans = now;
  rep(i,K - 1, N){
    now += (P[i] + 1) / 2;
    ans = std::max(ans, now);
    now -= (P[i - K + 1] + 1) / 2;
  }
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
ll a[n],b[n];
ll bunshi = 1;
REP(i,n) {
  cin >> a[i];
  bunshi += a[i];
  bunshi *= a[i];
}
ll bunbo = 0;
REP(i,n) {
  b[i] = bunshi/a[i];
  bunbo += b[i];
}
double ans = (double)bunshi/bunbo;
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0ll, A + B - N) << endl;
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define MAX 999999999

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

typedef long long ll;

int func(int n){
    if(n % 2 == 0) return n / 2;
    else return 3 * n + 1;
}

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

    ll s;
    cin >> s;

    vector<int> nums;
    ll before = s;
    nums.push_back(before);
    ll cnt = 0;
    while(true){
        before = func(before);
        nums.push_back(before);
        cnt++;

        if(count(all(nums), before) > 1){
            cout << cnt + 1 << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <numeric>
#include <cmath>
#include <limits>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int su[n];
	int ans =0;
	for(int i = 0; i < n; i++){
		cin >> su[i];
		ans += su[i];
	}
	cout << ans -n <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ll N,K;
    cin >> N >> K;
    ll a = N/K;
    
    cout << min({abs(N-K*a),abs(N-(a+1)*K)})  << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <utility>
#include <queue>
#include <map>
using namespace std;

#define TEST 0
#if TEST
FILE *in = freopen("./q.txt", "r", stdin);
FILE *out = freopen("./a.txt", "w", stdout);
#endif

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

inline void pusuQueue(queue<int>& q, int x, int y, int t){
	q.push(x), q.push(y), q.push(t);
}
inline void popQueue(queue<int>& q, int& x, int& y, int& t){
	x = q.front(); q.pop();
	y = q.front(); q.pop();
	t = q.front(); q.pop();
}

int main(){
	while (1){
		int t, n; cin >> t >> n;
		if (!t && !n) break;

		map<pair<int, int>, bool> isBar;

		for (int i = 0; i < n; i++){
			int x, y; cin >> x >> y;
			isBar[make_pair(x, y)] = true;
		}
		
		int sx, sy; cin >> sx >> sy;
		isBar[make_pair(sx, sy)] = true;

		int cnt = 0;
		queue<int> q;
		pusuQueue(q, sx, sy, 0);
		while (!q.empty()){
			int x, y, turn; popQueue(q, x, y, turn);
			cnt++;

			for (int i = 0; i < 6; i++){
				int nx = x + dx[i], ny = y + dy[i];
				if (turn < t && !isBar[make_pair(nx, ny)]){
					pusuQueue(q, nx, ny, turn+1);
					isBar[make_pair(nx, ny)] = true;
				}
			}
		}
		cout << cnt << endl;

	}

#if TEST
	fclose(in);
	fclose(out);
#endif
}

Measured memory_bytes: 1412
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    //rep(i,n)cout << " " << a[i];cout << endl;
    int ans = 0;
    rep(i,n)rep(j,i){//j,i,k
        //cout << i << " "<< j  << endl;
        int l,r;
        l = abs(a[i]-a[j]);
        r = a[i] + a[j];
        if(a[i] > r)continue;
        if(l < a[i])l = a[i];
        if(l > r)continue;
        int li = lower_bound(all(a), l)-a.begin();
        li = max(li, i+1);
        int ri = lower_bound(all(a), r)-a.begin();
        if(li > ri)continue;
        //cout << l << " " << r << " " << li << " " << ri << endl;
        ans += ri-li;
        if(li <= i && i <= ri)ans--;
        if(li <= j && j <= ri)ans--;
    }
    cout << ans << endl;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }
    sort(a.begin(), a.end());
    vector<ll> sum(n);
    sum[0] = a[0];
    repd(i, 1, n) { sum[i] = sum[i - 1] + a[i]; }
    ll sum_all = sum[n - 1];

    auto num = [&](ll x) -> ll {
        ll ans = 0;
        rep(i, n) {
            ans += a.end() - lower_bound(a.begin(), a.end(), x - a[i]);
        }
        return ans;
    };

    ll l = 0, r = sum_all + 1;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (num(mid) >= m) {
            l = mid;
        } else {
            r = mid;
        }
    }

    ll base = l;
    ll num_diff = num(base) - m;
    ll result = 0;
    rep(i, n) {
        ll count = lower_bound(a.begin(), a.end(), base - a[i]) - a.begin();
        ll total;
        if (count == 0) {
            total = sum_all + a[i] * n;
        } else {
            total = sum_all - sum[count - 1] + a[i] * (n - count);
        }
        result += total;
    }

    result -= num_diff * base;
    cout << result << endl;

    return 0;
}



Measured memory_bytes: 4764
n = int(input())
s = list(input())

result = s[1:].count("E")
temp = result
for i in range(n-1):
    if s[i] == "W":
        temp += 1
    if s[i+1] == "E":
        temp -= 1
    if temp < result:
        result = temp

print(result)

Measured memory_bytes: 8012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i, n)cin >> x[i];
    rep(i, n)x[i] -= a;
    vector<vector<ll>> dp(n+1, vector<ll>(5001, 0));
    dp[0][2500] = 1;
    rep(i, n){
        rep(j, 5001){
            dp[i+1][j] = dp[i][j] + dp[i][j - x[i]];
        }
    }
    cout << dp[n][2500] - 1 << endl;
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

 
 
int main(){
	int n;
	cin >> n;
	if(n==1)cout << "Hello World" << endl;

	else{
		int a,b;
		cin >> a >> b;
		cout  << a+b << endl;
	}

    return 0;
}


Measured memory_bytes: 256
import Data.List

main = do
  li <- getLine
  let [n,m] = map read $ words li
  li <- getLine
  let as = map read $ words li
  let ans = compute n m as
  print ans

{-
aは偶数なので2で割ってそれらのlcmを求めて、
その定数倍であって、全てのaiに対して kl/ai が奇数であるようなものを数えたい

もしl/aiが偶数だったら、kをいくつにしてもkl/aiは偶数
そんなときの答えは0個、そうでないときはつまり奇数なので、
m/lまでのkで奇数の個数だから、m/l+1/2 かな？

-}
compute :: Int -> Int -> [Int] -> Int
compute n m as
  | any (even . div l) bs = 0
  | True = (m `div` l + 1) `div` 2
  where
    bs = map (flip div 2) as
    l = foldl' lcm 1 bs


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

int main() {
  int N;
  cin >> N;
  vector<int> a_vec(N);
  vector<int> alice;
  vector<int> bob;
  for(int i=0; i<N; i++){
    cin >> a_vec.at(i);
  }
  sort(a_vec.begin(),a_vec.end());
  reverse(a_vec.begin(),a_vec.end());
  for (int i=0; i<N; i++){
    if(i%2==0){
      alice.push_back(a_vec.at(i));
    }
    else{
      bob.push_back(a_vec.at(i));
    }
  }
  int ans = accumulate(alice.begin(),alice.end(),0) - accumulate(bob.begin(),bob.end(),0);
  cout << ans << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  unordered_map<int,int> m;
  for (int i = 0; i < n; i++ ){
    int a;
    cin >> a;
    if (m.find(a) != m.end()) {
      m[a] += 1;
    } else {
      m[a] = 1;
    }
  }
  vector<pair<int,int>> v(m.begin(), m.end());
  sort(v.begin(), v.end(), [](auto a, auto b){ return a.second < b.second; });
  int c = 0;
  int d = v.size() - k;
  if (d > 0) {
    for (int i = 0; i < d; i++) {
      c += v[i].second;
    }
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 9724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  rep(snip_i, h) cin >> a.at(snip_i);
  rep(j, w+2) cout << '#';
  cout << endl;
  rep(i, h) cout << '#' << a.at(i) << '#' << endl;
  rep(j, w+2) cout << '#';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f for(int i=0;i<n;i++)
int main()
{
    int n;
    cin>>n;
    vector<int>v;
    f
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    int count=0;
      for(int i=1;i<n-1;i++)
      {
          if(v[i-1]<v[i]&&v[i]<v[i+1])
         count++;
         if(v[i-1]>v[i]&&v[i]>v[i+1])
         count++;
      }
cout<<count<<endl;


    return 0;
}



Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))

cnt2 = 0
cnt4 = 0
for i in range(n):
  if li[i]%4 == 0:
    cnt4 += 1
  elif li[i]%2 == 0:
    cnt2 += 1
if cnt2 == 0:
  if n//2 <= cnt4:
    print("Yes")
  else:
    print("No")
else:
  if 2*cnt4 + cnt2 >= n:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 15020
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
ll n,c,g,a,we,ac,L[7],p[7],m,k,dp[500][500];
int main(){
cin>>n>>c,c*=n,m=n-1,k=1<<m;
forn(i,n)cin>>L[i],L[i]*=n;
sort(L,L+n);
iota(p,p+m,0);
do{
    memset(dp,0,sizeof(dp)),dp[L[m]][0]=1;
    forn(i,c)if(i%n){
        we = p[i%n-1];
        forn(mask,k)if(!((1<<we)&mask))
            for(ac=i;ac<=c;ac++)dp[max(ac,min(c,L[we]+i))][mask+(1<<we)]+=dp[ac][mask];
    }g+=dp[c][k-1],a++;
}while(next_permutation(p,p+m));
printf("%.15f",g/pow(c/n,m)/a);
}


Measured memory_bytes: 2176
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <iostream>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	
	int  k =0;
	ll s= 0;
	int i = 1;
	while(k < n)
	{
		if(i % 3 != 0 && i % 5 != 0)
			s+=i;
		i++;
		k++;
	}
	cout << s;


    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define coutline cout<<"------------ ("<<__LINE__<<")"<<endl;

typedef long long ll;

int main(void)
{
    int N;
    cin >> N;

    vector<pair<string,vector<pair<int,int>>>> list;

    rep(i,N){
        string s;
        int p;
        cin >> s >> p;
        
        bool flg = false;
        for (int j = 0; j < list.size(); j++) {
            if (list.at(j).first == s) {
                list.at(j).second.push_back(make_pair(p,i+1));
                flg = true;
            }
        }
        if(!flg) {
            vector<pair<int,int>> v;
            v.push_back(make_pair(p,i+1));
            list.push_back(make_pair(s,v));
        }
    }

    sort(list.begin(), list.end());
    


    rep(i,list.size()){
        //cout << list.at(i).first << endl;
        sort(list.at(i).second.begin(), list.at(i).second.end(), std::greater<pair<int,int>>());

        for (int j = 0; j < list.at(i).second.size(); j++) {
            cout << list.at(i).second.at(j).second << endl;
        }

    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)

int main() {
    // your code goes here
    ll n,r=0,g=0,b=0,k,an=0;
    char s[4005];
    cin >> n >> s;
    rep(i,0,n-1){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            k=2*j-i;
            if(k>=n) break;
            bool mm=true;
            if(s[i]==s[j]) mm=false;
            if(s[j]==s[k]) mm=false;
            if(s[k]==s[i]) mm=false;
            if(mm) an++;
        }
    }
    cout << r*g*b-an << endl;
    return 0;
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

// dp[i][j] := i行j列目に到達するときの経路の総数 % mod
lli dp[1002][1002];
lli mod = 1e9+7;


inline lli add(lli x, lli y) {
    return (x + y) % mod;
}

int main() {
    lli h,w;
    cin2(h,w);
    char a[h+2][w+2];
    REPE(i,1,h) {
        REPE(j,1,w) {
            cin >> a[i][j];
        }
    }
    dp[h+1][w] = 1;
    a[h+1][w] = '.';
    a[h][w+1] = '#';
    REPE_R(i,h,1) {
        REPE_R(j,w,1) {
            if (a[i][j] != '.')
                continue;
            if (a[i+1][j] == '.')
                dp[i][j] = add(dp[i][j], dp[i+1][j]);
            if (a[i][j+1] == '.')
                dp[i][j] = add(dp[i][j], dp[i][j+1]);
        }
    }
    //REPE(i,1,h) {
    //    REPE(j,1,w) {
    //        cout << dp[i][j];
    //    }
    //    cout << endl;
    //}
    cout << dp[1][1]<<endl;
}


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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int cnt[MAX];
char _s[MAX];
int s[MAX];
ll sol;
int n;

void solve(int poc){
	REP(i,300) cnt[i]=0;
	FOR(i,poc+1,n) cnt[s[i]]++;
	FOR(nx,poc+1,n){
		cnt[s[nx]]--;
		if (s[nx]==s[poc]) continue;
		sol+=cnt['R']+cnt['G']+cnt['B'];
		sol-=cnt[s[poc]];
		sol-=cnt[s[nx]];
		int d=nx + (nx-poc);
		if (d>=n) continue;
		if (s[d]!=s[poc] && s[d]!=s[nx]) sol--;
	}
}

int main(){
	scanf ("%*d");
	scanf ("%s",_s);
	n=strlen(_s);
	REP(i,n) s[i]=(int)_s[i];
	REP(i,n) solve(i);
	
	printf ("%lld\n",sol);
	return 0;
}


Measured memory_bytes: 3856
while True:
    m,ni,na = map(int,input().split())
    if m+na+ni == 0:
        break
    P = [int(input()) for _ in range(m)]
    P.sort(reverse=True)
    m = 0
    ans = 0
    for i in range(ni-1, na):
        if m <= abs(P[i]-P[i+1]):
            m = abs(P[i]-P[i+1])
            ans = i+1
    print(ans)


Measured memory_bytes: 5620
#include <stdio.h>

int aStr, aHp, bStr, bHp;

int main() {

    scanf("%d %d %d %d", &aHp, &aStr, &bHp, &bStr);

    while (1) {
        bHp -= aStr;
        if (bHp <= 0) {
            printf("Yes\n");
            break;
        }

        aHp -= bStr;
        if (aHp <= 0) {
            printf("No\n");
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;

    int A[N];
    priority_queue<int> q;
    REP(i, N){
        cin >> A[i];
        q.push(A[i]);
    }

    REP(i, M){
        int a = q.top(); q.pop();
        q.push(a/2);
    }

    ll ans = 0;
    REP(i, N){
        int a = q.top(); q.pop();
        ans += a;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4228
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int a[2010];bool used[2010];int ans=1e9;
priority_queue<int,vector<int>,greater<int> > pq,pq2;
int main()
{
	int n,k,q;scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		memset(used,0,sizeof(used));
		while(!pq2.empty())pq2.pop();
		for(int j=1;j<=n;j++)if(a[j]<a[i])used[j]=1;
		int st=0;used[n+1]=1;
		for(int j=1;j<=n+1;j++)
		{
			if(used[j]==1)
			{
				for(int l=st+1;l<j;l++)
				{
					pq.push(a[l]);
				}
				for(int l=1;l<=j-st-k;l++)pq2.push(pq.top()),pq.pop();
				st=j;
			}
			while(!pq.empty())pq.pop();
		}
		int now=0;
		while(!pq2.empty())
		{
			if(now==q-1)break;pq2.pop();now++;
		}
		if(pq2.empty())continue;
		ans=min(ans,pq2.top()-a[i]); 
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#pragma region Macros
#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_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#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") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  string s;
  cin >> s;
  int i = 0;
  bool can = true;
  int n = s.length();
  while (i < s.length())
  {
    if (s[i] == 'e')
    {
      if (i + 6 <= n && s.substr(i, 6) == "eraser")
      {
        i += 6;
      }
      else if (i + 5 <= n && s.substr(i, 5) == "erase")
      {
        i += 5;
      }
      else
      {
        can = false;
        break;
      }
    }
    else if (s[i] == 'd')
    {
      if (i + 7 <= n && s.substr(i, 7) == "dreamer" && (i + 7 >= n || s[i + 7] != 'a'))
      {
        i += 7;
      }
      else if (i + 5 <= n && s.substr(i, 5) == "dream")
      {
        i += 5;
      }
      else
      {
        can = false;
        break;
      }
    }
    else
    {
      can = false;
      break;
    }
  }
  YES(can);
  return 0;
}


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

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

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

int cmp(const void* p, const void* q) {
	return *(int*)p - *(int*)q;
}

int main(void) {
	char s[30];
	int flag[30] = { 0 };
	int len;
	int temp;
	char min;
	int key = 1;

	scanf("%s", s);
	len = strlen(s);
	for (int i = 0; i < len; i++) flag[s[i] - 97] = 1;
	if (len != 26) {
		printf("%s", s);
		for (int i = 0; i < 26; i++) {
			if (flag[i] == 0) {
				printf("%c", i + 97);
				break;
			}
		}
	}
	else {
		temp = 25;
		for (int i = 25; i >= 1; i--) {
			if (s[i - 1] < s[i]) {
				temp = i;
				break;
			}
			if (i == 1) {
				printf("-1");
				key = 0;
			}
		}
		if (key) {
			min = CHAR_MAX;
			for (int j = temp; j < 26; j++) {
				if (s[temp - 1] < s[j] && min >= s[j]) min = s[j];
			}
			for (int k = 0; k < temp - 1; k++) {
				printf("%c", s[k]);
			}
			printf("%c\n", min);
		}
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[in.nextInt() - 1] = i + 1;
		}

		System.out.print(arr[0]);
		for(int i = 1; i < n; i++)
			System.out.print(" " + arr[i]);
	}
}

Measured memory_bytes: 61300
import java.util.Scanner;

public class Main {

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

        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        double ave = (double) (a + b) / 2 + 0.5;
        System.out.println((int) ave);
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,M,a=0,ans=0;
  cin>>N>>M;
  vector<pair<ll,ll>> p(N);
  map<ll,ll> m;
  for(ll i=0;i<N;i++){
    cin>>p[i].first>>p[i].second;
    m[p[i].first]++;
  }
  sort(p.begin(),p.end());
  priority_queue<ll> pq;
  for(ll i=1;i<=M;i++){
    for(ll j=0;j<m[i];j++,a++){
      pq.push(p[a].second);
    }
    if(pq.empty()) continue;
    ans+=pq.top();
    pq.pop();
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9212
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- fmap (map read . words) getLine :: IO [Int]
  print $ solve as

solve as = traceShow (ls, rs) $ maximum $ zipWith gcd ls rs
  where
    ls = init $ scanl' gcd 0 as
    rs = tail $ scanr gcd 0 as


Measured memory_bytes: 114044
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string S;
  cin >> S;

  if (len(S) % 2) {
    cout << "No\n";
    return 0;
  }

  bool ok = true;
  rep(i, len(S)) {
    if (S[i] != (i % 2 ? 'i' : 'h'))
      ok = false;
  }

  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";
}

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

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

using namespace std;

int n;
string s;
int c[26][100001];
bool p[100001];

bool srch(int k){
	rep(i, 26){
		rep(j, n - k + 1){
			if(c[i][j + k] - c[i][j] > k / 2){
				cout << j + 1 << ' ' << j + k << endl;
				return true;
			}
		}
	}
	return false;
}

int main() {
	cin >> s;
	n = s.size();

	rep(i, n){
		rep(j, 26){
			c[j][i + 1] = c[j][i];
		}
		++c[s[i] - 'a'][i + 1];
	}

	if(!srch(2) && !srch(3)){
		cout << "-1 -1" << endl;
	}
	return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
LL n,a,b;
int main(){
	cin>>n;a=1;b=1;
	F(i,1,n){
		LL x,y;cin>>x>>y;
		LL k1=(a-1)/x+1,k2=(b-1)/y+1;
		a=max(k1,k2)*x;
		b=max(k1,k2)*y;
	}
	cout<<a+b<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> x(n), l(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> l[i];
  }
  vector<P> vec(n);
  for (int i = 0; i < n; ++i) {
    vec[i].second = x[i] - l[i];
    vec[i].first = x[i] + l[i];
  }
  sort(vec.begin(), vec.end());
  ll ans = 0;
  ll before = -1e18;
  for (int i = 0; i < n; ++i) {
    if (before <= vec[i].second) {
      ans++;
      before = vec[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	string S;
	cin >> S;
	string ans;
	for (int i = 0; i < n; i++) {
		if (k - 1 != i) {
			ans += S[i];
		}
		else {
			ans += char(S[i] + 'a' - 'A');
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication76
{
    class Program
    {
        static void Main(string[] args)
        {
			string a= Console.ReadLine();
			if(a.Length<4)
			Console.WriteLine("No");
			else if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')
			Console.WriteLine("Yes");
			else Console.WriteLine("No");
			}
			}
			}



Measured memory_bytes: 11092
n = int(input())
b = list(map(int, input().split()))
a = [0 for i in range(n)]
s = 0

for i in range(n):
    if i == 0:
        a[0] = b[0]
    elif i == n-1:
        a[i] = b[i-1]
    else:
        a[i] = min(b[i-1], b[i])
s = sum(a)
print(s)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
	int k,n;
	int a[100000];
	while (cin>>n>>k,n!=0&&k!=0) {
		long long sum=0,max;
		for (int i=0; i<n; i++) cin>>a[i];
		for (int i=0; i<k; i++) sum+=a[i];
		max=sum;
		for (int i=k; i<n; i++) {
			sum=sum+a[i]-a[i-k];
			if (sum>max) max=sum;
		}
		cout<<max<<endl;
	}
}

Measured memory_bytes: 1544