akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int main(){
  int64_t n,k,a=0;
  cin>>n>>k;
  for(int i=k;i<n+2;i++)a=(a+i*(n-i+1)+1)%MOD;
  return cout<<a<<endl,0;
}


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

using namespace std;
typedef long long ll;

vector<ll> a;
ll x[10];
ll y[10];

double dist(ll a,ll b,ll c,ll d){
    ll t = (a-c) * (a-c) + (b-d) * (b-d);
    return sqrt(t);
}

int main(){
    int N;
    cin >> N;
    double sum = 0;
    ll p = 0;
    for(int i=0;i<N;i++) cin >> x[i] >> y[i];
    for(int i=0;i<N;i++) a.push_back(i);
    do{
        p++;
        for(int i=1;i<N;i++){
            sum += dist(x[a[i]],y[a[i]],x[a[i-1]],y[a[i-1]]);
        }
    }while(next_permutation(a.begin(), a.end()));
    cout << fixed << setprecision(15) << sum / p << endl;
    return 0;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    string s = in<string>();

    int cnt = 0;
    rep(i, s.size() - 1) {
        cnt += s[i] != s[i + 1];
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 640
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())  
    print((a-1)*(b-1))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	long long l, r;
	cin >> l >> r;
	long long ans = LONG_INF;
	for (long long geko = l; geko <= min(l + 2020, r); ++geko) {
		for (long long tea = geko + 1; tea <= min(geko + 2020, r); ++tea) {
			ans = min(ans, (geko % 2019 * tea % 2019) % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter
 
 
stdin = open(0)
 
N = int(stdin.readline())
S = stdin.read().split()
 
counter = Counter(S)
max_cnt = max(counter.values())
names = [name for name, cnt in counter.items() if cnt == max_cnt]
names.sort()
 
print(*names, sep='\n')

Measured memory_bytes: 38476
fn main() {
    let v = read_vec::<usize>();
    let n = v[0];
    let k = v[1];
    let ps = read_vec::<u32>();
    let exps = ps
        .iter()
        .map(|&p| (p + 1) as f64 / 2.0)
        .collect::<Vec<f64>>();
    let mut s = vec![0.0; n + 1];
    for i in 0..n {
        s[i + 1] = s[i] + exps[i];
    }
    //println!("{:?}", s);

    let mut ans = 0.0;
    for i in 0..n - k + 1 {
        let c = s[i + k] - s[i];
        //println!("{} {}", i, c);
        ans = f64::max(ans, c);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 11512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a=1,b,p,i;
      cin>>n;
     if(n%2==0||n%5==0)
     {
         cout<<-1<<endl;
     }
     else
     {
         a=7%n;
         p=1;
         while(a!=0)
         {
             a=a*10+7;
             a=a%n;
             p++;
         }
         cout<<p<<endl;
     }


}


Measured memory_bytes: 3636
import math
N=int(input())
def f(N):
  minn=10000000000000
  k=int(math.sqrt(N)+1)
  for i in range(1,k):
    j=N//i
    if i*j==N :
      minn=min(minn,i-1+j-1)
  return(minn)
print(f(N))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,a,b;

ll comb(int a,int b){
    if(a<b)return 0;
    if(b>a-b) return comb(a,a-b);
    ll rtn=1;
    REP(i,b){
        rtn *= (a-i);
        rtn /= (i+1);
    }
    return rtn;
}

int main() {
    cin >> n >> a >> b;
    vector<ll> v(n);
    REP(i,n){
        cin >> v[i];
    }
    sort(all(v),greater<ll>());
    ll cs = 0;
    REP(i,a){
        cs += v[i];
    }
    double ave = (double)cs/a;
    printf("%0.6lf\n",ave);
    ll res;
    if(v[0]!=v[a-1]){
        int cnt1 = 0;
        int cnt2 = 0;
        REP(i,n){
            if(v[a-1]==v[i]){
                cnt1++;
                if(i<a){
                    cnt2++;
                }
            }
        }
        res = comb(cnt1,cnt2);
    }else{
        int cnt1= 0;
        REP(i,n){
            if(v[0]==v[i]){
                cnt1++;
            }
        }
        res = 0;
        FOR(i,a,b+1){
            res += comb(cnt1,i);
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
if not h % 3 or not w % 3:
    print(0)
    exit()
    
ans = min(h, w)
for i in range(1, h):
    a = i * w
    b = (h - i) * (w // 2)
    c = h * w - (a + b)
    ans = min(ans, abs(max(a, b, c) - min(a, b, c)))

for i in range(1, w):
    a = i * h
    b = (w - i) * (h // 2)
    c = h * w - (a + b)
    ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
    
print(ans)


Measured memory_bytes: 3064
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    if N == 1:
        return 1
    else:
        lucas = []
        lucas.append(2)
        lucas.append(1)
        for i in range(1, N):
            lucas.append(lucas[-1]+lucas[-2])
        return lucas[-1]

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ls = new List<int>();
            ls.AddRange(s);
            string ans = "Yes";
            for (int i = n - 1; i >= 1; i--)
            {
                if (ls[i] - ls[i-1] == -1)
                {
                    ls[i - 1]--;
                }
                else if (ls[i] - ls[i - 1] < -1)
                {
                    ans = "No";
                }
            }
            WriteLine(ans);
        }
    }

    
}


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

int main() {
  long long N, x; cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    long long red = max(a.at(i-1)+a.at(i)-x, 0LL);
    long long tmp = min(red, a.at(i));
    a.at(i) -= tmp;
    a.at(i-1) -= red - tmp;
    ans += red;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
 
int main() {

    int n;
    string s;

    cin>>n>>s;

    int ans=n;
    for(int i=1;i<n;i++) {
        if(s[i]==s[i-1])    ans--;
    }
    
    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Fraction {
    long num;
    long denom;

    Fraction(int num, int denom) {
        this.num = num;
        this.denom = denom;

        reduction();
    }

    void reduction() {
        long gcdA = gcd(num, denom);
        num /= gcdA;
        denom /= gcdA;
    }

    long gcd(long x, long y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

    void add(Fraction fraction) {
        num = fraction.denom * num + fraction.num * denom;
        denom *= fraction.denom;

        reduction();
    }

    void mul(Fraction fraction) {
        num *= fraction.num;
        denom *= fraction.denom;

        reduction();
    }

    double value() {
        return (double) num / denom;
    }

}

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");

        int x = Integer.parseInt(line[0]);
        int y = Integer.parseInt(line[1]);

        Fraction posX = new Fraction(0, 1);
        Fraction posY = new Fraction(0, 1);

        Fraction diffX = new Fraction(1, y);
        Fraction diffY = new Fraction(1, 2 * x);

        int result = 0;

        while (posX.value() <= 2 * x) {
            if (posX.denom == 1 && (posX.num % 2 == 0)) {
                // System.out.println("posX : " + posX.num + " / " + posX.denom + "\t posY : " + posY.num + " / " + posY.denom);
                result++;
            } else if (posY.denom == 1){
                // System.out.println("posX : " + posX.num + " / " + posX.denom + "\t posY : " + posY.num + " / " + posY.denom);
                result++;
            }

            posX.add(diffX);
            posY.add(diffY);
        }

        // wrong.
        // int result = x + 1 + y + 1 - gcd(2 * x, y) - 1;

        System.out.println(result);
    }
}


Measured memory_bytes: 25140
# -*- coding: utf-8 -*-
"""
C - When I hit my pocket...
https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_c

"""
import sys


def solve(K, A, B):
    ans = 1
    if B-A <= 2 or (A-1) > K:
        return ans + K
    K -= (A-1)
    ans = A
    if K % 2:
        ans += 1
    rep = K // 2
    ans += (B - A) * rep
    return ans


def main(args):
    K, A, B = map(int, input().split())
    ans = solve(K, A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main() {
    int n;
    cin >> n;
    int a[200];
    rep(i, n) cin >> a[i];
    bool f = true;
    int ans = 0;
    
    while(true) {
        rep(i, n) {
            if ((a[i] % 2) != 0) {
                f = false;
                break;
            }
            
            a[i] /= 2;
        }
        
        if (!f) {
            break;
        }
        
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}

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

#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) (v.begin(),v.end())
#define ll long long

const int N=105;
const int inf=2e9;


int main(){
    ios::sync_with_stdio(0);
    //freopen("in.txt","r",stdin);
    int n,a,b,tmin=inf;
    ll sum=0;
    cin>>n;
    rep(i,0,n){
        cin>>a>>b;
        if(a>b) tmin=min(tmin,b);
        sum+=a;
    }
    if(tmin!=inf) sum-=tmin;
    else sum=0;
    cout<<sum;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def conbination(n, r):
    return f[n] // (f[r] * f[n-r])

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

f = [1]
for i in range(1, N+1):
    f.append(int(f[i-1]*i))

for i in range(1, K+1):
    if i > N-K+1:
        print(0)
        continue
    c_blue = conbination(K-1, i-1)
    c_red = conbination(N-K+1, i)
    print((c_blue * c_red) % (10**9 + 7))


Measured memory_bytes: 5748
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut a: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut ans = 0;
    for i in 1..n {
        if a[i - 1] > a[i] {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 5824
/*input

*/
/*
Contest: 
Problem: 
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define F first
#define S second
#define mp make_pair
#define append push_back
#define vi vector<ll>
#define pii pair<ll,ll>
#define qi queue<ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define print(a) cout<<a<<endl
#define sorted(a) sort(arr.begin(), arr.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define read(a) scanf("%d", &a)
#define int long long int
 
const int MAXN = 2019;

int n, k;
vector<int> graph[MAXN];
vector<int> depth(MAXN);
vector<pair<int, int> > edges;

void dfs(int node, int par){
	for(auto u : graph[node]){
		if(par == u)
			continue;
		depth[u] = depth[node] + 1;
		dfs(u, node);
	}
}

signed main(){
    
    cin>> n >> k;

    for(int i = 0; i < n - 1; i++){
    	int u, v;
    	cin>> u >> v;
    	graph[u].append(v);
    	graph[v].append(u);
    	edges.append(mp(u, v));
    }
    int ans = n;
    if(k&1){
    	for(int i = 0; i < n-1; i++){
    		int u, v, res = 0;
    		u = edges[i].F;
    		v = edges[i].S;
    		depth[u] = depth[v] = 0;
    		dfs(u, v);
    		dfs(v, u);
    		for(int j = 1; j <= n; j++)
    			if(depth[j] > k/2)
    				res++;
    		ans = min(ans, res);
    	}
    }
    else{
    	for(int i = 1; i <= n; i++){
    		depth[i] = 0;
    		dfs(i, 0);
    		int res = 0;
    		for(int j = 1; j <= n; j++){
    			if(depth[j] > k/2)
    				res++;
    		}
    		ans = min(ans, res);
    	}
    }
    print(ans);

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	int n;
	int k;
	cin >>n>>k;
	int arr[k];
	for(int i=0;i<k;i++)
		cin >> arr[i];
	while(1)
	{
		int temp=n;
		int flag=0;
		while(temp>0)
		{
			if(*lower_bound(arr,arr+k,temp%10)==temp%10)
			{
				flag=1;
			}
			if(flag)
				break;
			temp/=10;
		}
		if(flag)
		{
			// cout << n;
			n++;
		}
		else
		{
			cout << n;
			break;
		}
	}
}

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

int A[110000];

int pertition(int A[],int p,int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int z = pertition(A, 0, N - 1);
	for (int i = 0; i < N; i++) {
		if (i)cout << " ";
		if (i == z)cout << "[" << A[i] << "]";
		else cout << A[i];
	}
	cout << endl;
}


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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define TYPEMAX(type)   numeric_limits<type>::max()
#define TYPEMIN(type)   numeric_limits<type>::min()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MD=998244353;
class Segment_Tree{
private:
    vector<int> seg;
    int n;
public:
    Segment_Tree(int n){
        this->n=n;
        seg.resize(4*n,0);
    }
    void update(int idx, int l, int r, int f, int g){
        if(l>f || r<f) return;
        seg[idx]=max(seg[idx],g);
        if(l==r) return;
        int m=(l+r)/2;
        update(2*idx,l,m,f,g);
        update(2*idx+1,m+1,r,f,g);
    }
    int find(int idx, int l, int r, int fl, int fr){
        if(fr<l || r<fl) return 0;
        if(fl<=l && r<=fr) return seg[idx];
        int m=(l+r)/2;
        return max(find(2*idx,l,m,fl,fr),find(2*idx+1,m+1,r,fl,fr));
    }
};
ll mypow(ll x, int y){
    ll res=1;
    while(y){
        if(y%2) res=(res*x)%MD;
        x=(x*x)%MD;
        y/=2;
    }
    return res;
}
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    vector<pll> arr(n);
    vector<ll> ord(n);
    for(int i=0;i<n;i++){
        ll x,d; cin>>x>>d;
        arr[i]={x,d};
        ord[i]=x;
    }
    sort(arr.begin(),arr.end());
    sort(ord.begin(),ord.end());
    ll ans=mypow(2,n);
    vector<int> rr(n+5,0);
    vector<int> memo(n+5,0);
    for(int i=0;i<n;i++){
        auto low=lower_bound(ord.begin()+i+1,ord.end(),arr[i].first+arr[i].second);
        rr[i]=low-1-ord.begin();
        //if(i && ord[i]==ord[i-1]) debug(i,rr[i]);
    }
    Segment_Tree seg=Segment_Tree(n);
    for(int i=n-1;i>=0;i--){
        //seg.update(1,0,n-1,i,rr[i]);
        memo[i]=seg.find(1,0,n-1,i+1,rr[i]);
        memo[i]=max(memo[i],rr[i]);
        seg.update(1,0,n-1,i,memo[i]);
        //debug(i,memo[i]);
    }
    vector<int> dp(n+5,0);
    dp[n]=1;
    for(int i=n-1;i>=0;i--){
        dp[i]=(dp[i+1]+dp[memo[i]+1])%MD;
    }
    cout<<dp[0];
    return 0;
}

Measured memory_bytes: 10496
// from : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1811250#1
 
#include<iostream>
#include<vector>
#include<queue>
  
using namespace std;
 
#define DEBUG(x) cout<<(#x)<<": "<<(x)<<endl
  
int nowS = 0;
int x, y, n;
int mp[1000][1000] = {};
int k[4] = {1, -1, 0, 0};
int h[4] = {0, 0, 1, -1};
int cx[9] = {};
int cy[9] = {};
queue<int> bufX, bufY, bufD;
  
bool search(int xx, int yy, int dd) {
    bufX.pop();
    bufY.pop();
    bufD.pop();
  
    for (int i = 0; i < 4; i++) {
        int nx = xx+k[i];
        int ny = yy+h[i];
        if (nx < 0 || nx >= x || ny < 0 || ny >= y)//?????????
            continue;
        if (mp[ny][nx] == -1) {//?????
            continue;
        }
        if (cx[nowS] == nx && cy[nowS] == ny) {//??????
            nowS++;
            while (!bufX.empty()) {
                bufX.pop();
                bufY.pop();
                bufD.pop();
            }
            if (nowS == n) {//?????????????????????
                cout << dd + 1 << endl;
                return true;
            }
            else {//
                bufX.push(nx);
                bufY.push(ny);
                bufD.push(dd + 1);
                mp[ny][nx] = nowS + 1;
            }
            return false;
        }
        if(mp[ny][nx] >= 0 && mp[ny][nx] < nowS + 1){
            bufX.push(nx);
            bufY.push(ny);
            bufD.push(dd + 1);
            mp[ny][nx] = nowS + 1;
        }
    }
    return false;
}
  
int main() {
    int ch = 0;
    cin >> y >> x >> n;
    for (int i = 0; i < y; i++) {//??\???
        char c[1001];
        cin >> c;
        for (int j = 0; j < x; j++) {
            if(c[j] == 'X')
                mp[i][j] = -1;
            else if(c[j] == 'S'){
                bufX.push(j);
                bufY.push(i);
                bufD.push(0);
                mp[i][j] = 1;
            }   
            else {
                mp[i][j] = 0;
            }
            if (c[j] >= 48 && c[j] <= 57) {
                int m;
                m = c[j] - 49;
                cx[m] = j;
                cy[m] = i;      
                ch++;
            }
        }
    }
      
  
    while(!search(bufX.front(), bufY.front(), bufD.front())){}//????????????????§?????????
  
    return 0;
}

Measured memory_bytes: 5124
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

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

  int ans = 0, x;
  rep(i, 0, N) {
    cin >> x;
    ans += min(x, K - x) * 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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


int32_t  main()
{ 
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
  #ifndef ONLINE_JUDGE
  freopen("input.txt","rt",stdin);
  freopen("output.txt","wt",stdout);
  #endif

  int n,d;
  cin>>n>>d;
  int cnt=0;
  for(int i=0;i<n;i++)
  {
    int x,y; cin>>x>>y;
    if(x*x+y*y<=d*d)cnt++;
  }
  cout<<cnt<<"\n";

}

Measured memory_bytes: 3656
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;

	if (m1 == 2 && d1 == 28 || d1 == 31 || d1 == 30 && d2 == 1)
		cout << "1";
	else cout << "0";
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
const int maxn=1e5+10;
using namespace std;
int tot=0,head[maxn],n,x,y,siz[maxn],f[maxn];
struct line{int to,next;}e[maxn*2];
void pushline(int x,int y)
{
	e[++tot].to=y;e[tot].next=head[x],head[x]=tot;
}
bool dfs(int x,int fa)
{
	siz[x]=1;
	int cnt=0;
	for(int i=head[x];int v=e[i].to;i=e[i].next)
	{
		if(v==fa)continue;
		if(dfs(v,x))return 1;
		if(siz[v])
		{
			cnt++,siz[x]=0;
			if(cnt==2)return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		pushline(x,y);pushline(y,x);
	}
	printf(dfs(1,0)||siz[1]?"First":"Second");
}
/*
先手如果摁了叶子的爸爸，那么后手必定跟着染叶子，这样非常赚。然后这两个点就可以滚了，因为爸爸已经被叶子标记掉了。
不断这样处理即可。
*/

Measured memory_bytes: 6180
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	n := readInt64() // S
	m := readInt64() // c

	if m <= 2*n {
		println(m / 2)
		return
	}
	ans := n
	l := m - 2*n
	ans += l / 4
	println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string d;
string c[]={"SSS","RRR","RRS","SRR"};
int main()
{
	cin>>d;
	if(d==c[0]) cout<<0;
	else if(d==c[1]) cout<<3;
	else if(d==c[2]||d==c[3]) cout<<2;
	else cout<<1;
	return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rep1(i,N) for(int i=1;i<=(int)N;++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define SZ(x) (int)x.size()
#define e_b emplace_back
using ll = long long;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct LazySegmentTree{
	int n;
	vector<ll> node,lazy;
	
	LazySegmentTree(int sz){
		n=1;
		while(sz>n) n<<=1;
		node.assign(2*n,0);
		lazy.assign(2*n,0);
	}
	
	void eval(int k,int l,int r){
		if(lazy[k]){
			node[k]+=lazy[k];
			if(r-l>1){
				lazy[2*k]+=lazy[k]/2;
				lazy[2*k+1]+=lazy[k]/2;
			}
			lazy[k]=0;
		}
	}
	
	void add(int a,int b,ll x,int k=1,int l=0,int r=-1){
		if(r<0) r=n;
		eval(k,l,r);
		if(r<=a||b<=l) return;
		if(a<=l&&r<=b){
			lazy[k]+=(r-l)*x;
			eval(k,l,r);
		}
		else{
			add(a,b,x,2*k,l,(l+r)/2);
			add(a,b,x,2*k+1,(l+r)/2,r);
			node[k]=node[2*k]+node[2*k+1];
		}
	}
	
	ll getSum(int a,int b,int k=1,int l=0,int r=-1){
		if(r<0) r=n;
		eval(k,l,r);
		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return node[k];
		ll vl=getSum(a,b,2*k,l,(l+r)/2);
		ll vr=getSum(a,b,2*k+1,(l+r)/2,r);
		return vl+vr;
	}
};

int main(){
	int n,q; cin>>n>>q;
	LazySegmentTree tree(n);
	rep(i,q){
		int m,s,t,x;
		cin>>m;
		if(m==0){
			cin>>s>>t>>x;
			s--,t--;
			tree.add(s,t+1,x);
		}else{
			cin>>s>>t;
			s--,t--;
			cout<<tree.getSum(s,t+1)<<endl;
		}
	}
}

	



Measured memory_bytes: 7036
using System;

public class Program{
  public static void Main(string[] args){
    var input = Console.ReadLine();
    var output = "Sunny";
    if(input == "Sunny")
    {
      output = "Cloudy";
    }
    else if(input == "Cloudy")
    {
      output = "Rainy";
    }
    Console.WriteLine(output);
  }
}

Measured memory_bytes: 11092
import java.util.Scanner;

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

    	int[] b = new int[n-1];
    	for(int i = 0; i < n-1; i++) {
    		b[i] = sc.nextInt();
    	}
    	
    	int[] a = new int[n];
    	for(int i = 0; i < n; i++) {
    		a[i] = 0;
    	}
    	
    	a[0] = b[0];
    	a[1] = b[0];
    	for(int i = 1; i < n-1; i++) {
    		if(a[i] > b[i]) {
    			a[i] = b[i];
    		}
    		a[i+1] = b[i];
    	}
    	
    	int ans = 0;
    	for(int i = 0;i < n; i++) {
    		ans = ans + a[i];
    		//System.out.println(a[i]);
    	}

    	System.out.println(ans);

	}

}


Measured memory_bytes: 22740
def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n, k = map(int, input().split())
mod = 10**9+7
ans = 0
k_ = min(n-1, k)
for i in range(k_+1):
    ans += cmb1(n, i, mod) * cmb1(n-i-1+i, i, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 127752
n, _ = map(int, input().split())

ans = []

for _ in range(n):
    s = input()
    inserted = False
    for i, s2 in enumerate(ans):
        if s < s2:
            ans.insert(i, s)
            inserted = True
            break
    if not inserted:
        ans.append(s)

print(''.join(ans))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    var s = sc.next();
    var answer = 0;
    for (String w : s.split("S")) {
      answer = Math.max(answer, w.length());
    }
    System.out.println(answer);
  }
}


Measured memory_bytes: 35548
check = [0, 0, 0, 0]
for i in range(3):
    a, b = map(int, input().split())
    check[a-1] += 1
    check[b-1] += 1

check.sort()

if check[0] == 1 == check[1] and check[2] == 2  == check[3]:
    print('YES')
else:
    print('NO')
    
    

Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long int ll;

int main()
{
	int H,W;
	scanf("%d %d",&H,&W);
	ll ret=(ll) H*(ll) W;
	for(int i=1;i<H;i++)
	{
		int a=W/2,b=W-a;
		vector <ll> st;
		st.push_back((ll) a*(ll) (H-i));
		st.push_back((ll) b*(ll) (H-i));
		st.push_back((ll) i*(ll) W);
		sort(st.begin(),st.end());
		ret=min(ret,st[2]-st[0]);
		if(H-i>=2)
		{
			a=(H-i)/2,b=H-i-a;
			st.clear();
			st.push_back((ll) a*(ll) W);
			st.push_back((ll) b*(ll) W);
			st.push_back((ll) i*(ll) W);
			sort(st.begin(),st.end());
			ret=min(ret,st[2]-st[0]);
		}
	}
	swap(H,W);
	for(int i=1;i<H;i++)
	{
		int a=W/2,b=W-a;
		vector <ll> st;
		st.push_back((ll) a*(ll) (H-i));
		st.push_back((ll) b*(ll) (H-i));
		st.push_back((ll) i*(ll) W);
		sort(st.begin(),st.end());
		ret=min(ret,st[2]-st[0]);
		if(H-i>=2)
		{
			a=(H-i)/2,b=H-i-a;
			st.clear();
			st.push_back((ll) a*(ll) W);
			st.push_back((ll) b*(ll) W);
			st.push_back((ll) i*(ll) W);
			sort(st.begin(),st.end());
			ret=min(ret,st[2]-st[0]);
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
D = [0]*N
for i in range(1,N):
    if (A[i-1] + D[i-1]) > (A[i] + D[i]): #自分の方が低い場合
        D[i] = abs((A[i-1] + D[i-1]) - (A[i] + D[i]))
    else: #自分の方が高ければOK
        continue
ans = sum(D)
print(ans)

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

int main(){
	ll n,h;
	cin >> n >> h;
	vector<ll> a(n);
	vector<ll> b(n);
	rep(i,n) cin >> a[i] >> b[i];
	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	ll count = 0;
	rep(i,n){
		if(h <= 0) break;
		if(a[0] <= b[i]){
			h -= b[i];
			count++;
		}
	}
	if(h > 0){
		count += (h + a[0] - 1) / a[0];
	}
	cout << count << endl;
    return 0;
}



Measured memory_bytes: 4812
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  int a[n];
  REP(i, n) cin>>a[i];
  int ans = 0;
  REP(i, n){
    if(i % 2 == 1) continue;
    if(a[i] % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int n;
int a[200010];
set<int> s;
long long ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i){
		int t;
		cin >> t;
		a[t] = i+1;
	}
//	for(int i=1; i<=n; ++i)
//		cout << a[i] << "\n";
	s.insert(0);
	s.insert(n+1);
	for(int i=1; i<=n; ++i){
		auto ite = s.lower_bound(a[i]);
		ans += (long long)i * (*ite - a[i]) * (a[i] - *prev(ite));
		s.insert(a[i]);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 10368
def main():
    N, H = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    maximum = max(A)
    throw = list(filter(lambda x: x > maximum, B))
    if sum(throw) > H:
        throw.sort(reverse=True)
        for i in range(len(throw)):
            H -= throw[i]
            if H <= 0:
                print(i+1)
                return
    else:
        H -= sum(throw)
        print(-((-H)//maximum) + len(throw))


if __name__ == "__main__":
    main()


Measured memory_bytes: 50904
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main() {
	/*
	int a = 0;//整数変数aを作る
	int b = 0;//整数変数bを作る

	cin >> a >> b;//2つの数字を受け取り、a,bに代入

	cout << a * b << endl;//a*bを出力
	*/
	/*
	string S;
	cin >> S;
	if (S[0]=='7'||S[1]=='7'||S[2]=='7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	int a = 0;
	int b = 0;
	int ans = 0;

	cin >> a >> b;

	int apb = a + b;
	int akb = a * b;
	int amb = a - b;
	ans = apb;
	if (ans < a - b) {
		ans = a - b;
	}


	if (ans < a * b) {
		ans = a * b;
	}
	cout << ans << endl;

	int N = 0;
	int R = 0;
	int Ans = 0;
	cin >> N >> R;
	if (N >=10) {
		Ans = R;
	}
	else
	{
		Ans = R + (100 * (10 - N));
	}

	cout << Ans << endl;
	
	int A = 0;
	cin >> A;
	cout << A + (A * A) + (A * A * A) << endl;

    ==は右と左が同じかの判定をする
	＝は代入する
	*/

	int a, b, x;

	cin >> a >> b ;

	x = (a + b) / 2;

	if ((a + b) % 2 == 1) {
		cout << x + 1 << endl;
	}
	else {
		cout << x << endl;
	}
	 
	




	return 0;
}








Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define for0(i, n) for (int i = 0; i < n; i++)
#define tc(t) int t; cin >> t; while (t--)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ps(x,y)         fixed<<setprecision(y)<<x
using namespace std;
ll n;
vector<double> a(3000);
double dp[3000][3000];
void solve(){
    ll head=(n+1)/2;
    for(ll x=1;x<=head;x++)
        dp[0][x]=0;
    for(ll i=0;i<=n;i++)
        dp[i][0]=1;
    for(ll i=1;i<=n;i++){
        for(ll x=1;x<=head;x++){
            dp[i][x]=a[i]*dp[i-1][x-1]+(1-a[i])*dp[i-1][x];
        }
    }
   cout<<fixed<<setprecision(10)<<dp[n][head]<<endl;
}
int main(){
    cin>>n;
    a[0]=0;
    for(ll i=1;i<n+1;i++){
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    solve();
    return 0;}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, x, y;
    cin>>n>>m;
    vector<int> compo(n+1, -1);
    vector<vector<int>> road(n+1);

    for(int i=0; i<m; i++){
        cin>>x>>y;
        road[x].push_back(y);
        road[y].push_back(x);
    }
    int currComp = 0;
    for(int i=1; i<=n; i++){
        if(compo[i]==-1){
            //Start bfs
            compo[i]=currComp;
            currComp++;
            queue<int> q;
            q.push(i);
            while(!q.empty()){
                int elem = q.front();
                q.pop();
                for(auto node: road[elem]){
                    if(compo[node]==-1){
                        compo[node]=compo[i];
                        q.push(node);
                    }
                }
            }
        }
    }
    cout<<currComp-1;
}


Measured memory_bytes: 8804
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 3010 
using namespace std;
double dp[N][N], p[N];
int n;
double fun(int a, int b){
	if(a == n){
		//cerr << a << " " << b << '\n';
		if(b > n / 2)
			return 1;
		return 0;
	}
	if(dp[a][b] > -1e5)
		return dp[a][b];
	return dp[a][b] = (p[a] * fun(a + 1, b + 1) + (1 - p[a]) * fun(a + 1, b));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++)cin >> p[i];
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= n; j++)
			dp[i][j] = -1e9;
	printf("%.17lf", fun(0, 0));

}

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

using namespace std;
using ll = long long;
#define N (ll)(1e9+7)
ll mypower(ll a, ll b, ll mod = N)
{
    ll ans = 1;
    while(b)
    {
        if(b%2)
            ans = (ans*a)%mod;
        b=b/2;
        a=(a*a)%mod;
    }
    return ans;
}
bool comp(pair<ll,ll> a, pair<ll,ll> b)
{
    return a.first > b.first;
}
int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll p[a+1], q[b+1], r[c+1];
    ll pa[a+1] = {0};
    ll qb[b+1] = {0};
    int i;
    vector<pair<ll,ll>> comb(a+b+1);
    for(i=1;i<=a;i++)
    {
        cin >> p[i];
        comb[i].first = p[i];
        comb[i].second = 1;
    }
    
    sort(p+1, p+a+1, greater<ll>());
    for(i=1;i<=a;i++)
        pa[i] = pa[i-1] + p[i];
        
    for(i=1;i<=b;i++)
    {
        cin >> q[i];
        comb[a+i].first = q[i];
        comb[a+i].second = 2;
    }
    sort(q+1, q+b+1, greater<ll>());
    for(i=1;i<=b;i++)
        qb[i] = qb[i-1] + q[i];
        
    sort(comb.begin() + 1, comb.end(), comp);
    //cout << comb[1].first << endl;
    for(i=1;i<=c;i++)
        cin >> r[i];
    sort(r+1, r+c+1,greater<ll>());
    ll cpref[c+1];
    cpref[0] = 0;
    for(i=1;i<=c;i++)
        cpref[i] = cpref[i-1] + r[i];
    
    ll pref[a+b+1] = {0};
    for(i=1;i<=a+b;i++)
        pref[i] = pref[i-1] + comb[i].first;
        
    vector<ll> cnt(a+b+1);
    for(i=1;i<=a+b;i++)
        cnt[i] = cnt[i-1] + (comb[i].second == 1);
    ll maxa = 0;
    for(i=max(x+y-c, (ll)0);i<=(x+y);i++)
    {
        if(cnt[i] <= x && (i-cnt[i]) <= y)
            maxa = max(maxa, cpref[x+y-i] + pref[i]);
        else
        {
            if(cnt[i] > x)
            {
                maxa = max(maxa, cpref[x+y-i] + pa[x] + qb[i-x]);
            }
            else
            {
                maxa = max(maxa, cpref[x+y-i] + pa[i-y] + qb[y]);
            }
        }
    }
    cout << maxa << '\n';
}

Measured memory_bytes: 11136
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;

main(){
    int n=in(),k=in();
    if(k==1)cout<<0;
    else cout<<n-k;
}



Measured memory_bytes: 256
from fractions import gcd
a, b, c, d = map(int, input().split())
e = b//c - (a-1)//c
f = b//d - (a-1)//d
def lcm(x, y):
	return (x * y) // gcd(x, y)
g = lcm(c, d)
h = b//g - (a-1)//g

print (b-a+1 -(e+f-h))

Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
map<int,bool>ex;
const int N = 1e6+10;
int arr[N];
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	int g = -1;
	int pc = 1;
	for (int i = 1; i <= n; i++){
		int num = arr[i];
		if (g == -1)
			g = num;
		else
			g = gcd(g,num);
		for (long long j = 2; j*j <= num && pc; j++) {
			if (num % j == 0){
				if (ex.count(j)){
					pc = 0;
					break;
				}
				else {
					ex[j] = true;
					while (num && num %j == 0){
						num /= j;
					}
				}
			}
		}
		if (num > 2){
			if (ex.count(num))
				pc = 0;
			else
				ex[num] = true;
		}
	}
	if (pc == 1)
		cout << "pairwise coprime";
	else if (g == 1)
		cout << "setwise coprime";
	else
		cout << "not coprime";
	return 0;
}


Measured memory_bytes: 54172
#include<stdio.h>

 int main(void){

int a,b,c,d;

   scanf("%d %d %d",&a,&b,&c);


 if(a>c){

  d=a;

  a=c;

  c=d;

 }

 if(a>b){

  d=a;

  a=b;

  b=d;

 }

 if(b>c){

  d=b;

  b=c;

  c=d;

 }

 printf("%d %d %d\n",a,b,c);

 return 0;

}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if((s[i]+n)>'Z')
		{
			s[i]=s[i]-26+n; 
		}
		else
		s[i]=s[i]+n;
	}
	cout<<s;
	return 0;
}

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

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

    int a[110000];
    for(int i = 0; i < N; i++) cin >> a[i];

    bool reachable = true;
    int count = 1;
    int cur_pos = 1;

    while(1){
        if(a[cur_pos - 1] == 2) {
            //到達できた場合
            break;
        }

        if(count > N) {
            reachable = false;
            break;
        }
        cur_pos = a[cur_pos - 1];
        count++;
    }    
    if(!reachable) {
        cout << "-1" << endl; 
    } else {
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import sys
N, M = map(int, input().split())
mod = 7 + 10 ** 9

fact = [1] * (N + 1)
for i in range(1, N + 1): fact[i] = (fact[i-1] * i) % mod
revfact = [1] * (N + 1)
revfact[N] = pow(fact[N], mod - 2, mod)
for i in reversed(range(1, N)): revfact[i] = ((i+1) * revfact[i+1]) % mod

def comb(n, k): return (fact[n] * revfact[n-k] * revfact[k]) % mod

def solve():
      Perm = [1] * (N + 1) #M-iPN-i
      P = 1
      for i in reversed(range(N)): 
            Perm[i] = ((M - i) * Perm[i + 1]) % mod

      Ans = pow(Perm[i], 2, mod)

      for i in range(1, N + 1):
            P *= (M - i + 1)
            P %= mod
            Ans += pow(-1, i % 2) * (comb(N, i) * P * pow(Perm[i], 2, mod)) % mod
            Ans %= mod

      print(Ans)
      #print(Perm)
      return 0

if __name__ == "__main__":
      solve()

Measured memory_bytes: 87056
//SkGeN
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
const int N = 2 * 1e5 + 10;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve() {
    ll a , b;
    cin>>a>>b;
    cout<<a*b<<"\n";
}
int main()
{
    DANGER;
    ll t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
return 0;
}
//---->O ,,

Measured memory_bytes: 3652