akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int N, K;
int ans;
vector<vector<int>> rev;

int dfs(int v, int prev){
    int depth = 0;
    for(int to : rev[v]){
        if(to == prev) continue;
        depth = max(depth, dfs(to, v));
    }
    if(depth == K-1){
        if(prev != 0) ans++;
        return 0;
    }
    return depth + 1;
}

// int dfs(int pos, int pre) {
// 	int e = 0;
// 	for (int i : rev[pos]) {
// 		if (i == pre) continue;
// 		e = max(e, dfs(i, pos));
// 	}
// 	if (e == K - 1) {
// 		if(pre != 0) ans++;
// 		return 0;
// 	}
// 	return e + 1;
// }

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

    ans = 0;
    rev.assign(N, {});
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(i == 0){
            ans += a != 1 ? 1 : 0;
        }else{
            rev[a-1].push_back(i);
        }
    }

    for (int i : rev[0]) dfs(i, 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10368
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


from queue import PriorityQueue


def main():
    n = gete(int)
    que = PriorityQueue()

    for _ in range(n):
        x, l = geta(int)
        que.put((x + l, x - l))

    ans = 0
    max_r = -10**9

    while not que.empty():
        r, l = que.get()

        if max_r <= l:
            max_r = r
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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

long long gcd(long long a, long long b) {
  if(a < b) return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

long long lcm(long long a, long long b){
 return (a*b)/gcd(a,b);
}

int main(){
  long long N, M; cin >> N >> M;
  string S, T; cin >> S >> T;
  long long K=gcd(N, M);
  long long k=lcm(N, M);
  for(int i=0;i<K;i++){
    if(S[i*(k/M)]!=T[i*(k/N)]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << k << endl;
}
  
  

Measured memory_bytes: 512
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<vector<int>> g(n);
    rep(i, n - 1)
    {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);

    vector<int> ans(n, 0);
    struct Data
    {
        int index;
        int distance;
    };
    queue<Data> q;
    rep(i, n - 1)
    {
        vector<bool> visit(n, false);
        q.push({i, 0});
        while(!q.empty())
        {
            auto t = q.front();
            q.pop();

            if(visit[t.index])
            {
                continue;
            }
            visit[t.index] = true;
            if(i < t.index)
            {
                ans[t.distance]++;
            }
            for(auto next : g[t.index])
            {
                if(visit[next])
                {
                    continue;
                }
                q.push({next, t.distance + 1});
            }
        }
    }

    rep(i, n - 1)
    {
        cout << ans[i + 1] << endl;
    }

    return 0;
}


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

int v;
int op(int a, int b){
  return max(a,b);
}
int e(){
  return -1;
}
bool f(int x){
  if(x<v) return true;
  else return false;
}

int main(){
  int N,Q;
  cin >> N >> Q;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  segtree<int,op,e> S(A);
  
  for(int i=0;i<Q;i++){
    int t,x,y;
    cin >> t >> x >> y;
    
    if(t==1){
      S.set(x-1,y);
    }
    if(t==2){
      cout << S.prod(x-1,y) << endl;
    }
    if(t==3){
      v = y;
      cout << S.max_right<f>(x-1) + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 6144
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string n;

int main() {
	cin >> n;
	rep(i, sz(n)) {
		if (n[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
local mod = 998244353
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local n, a, b, k = io.read("*n", "*n", "*n", "*n")
local combs = {1}
for i = 1, n do
  local v = combs[i]
  v = bmul(v, n + 1 - i)
  v = bmul(v, modinv(i))
  combs[i + 1] = v
end

local ret = 0
for ib = 0, n do
  local rem = k - ib * b
  if rem < 0 then break end
  if rem % a == 0 then
    local ia = mfl(rem / a)
    if ia <= n then
      ret = badd(ret, bmul(combs[ib + 1], combs[ia + 1]))
    end
  end
end
print(ret)


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D)
    cout<<"Left"<<endl;
  else if(A+B<C+D)
    cout<<"Right"<<endl;
  else
    cout<<"Balanced"<<endl;
}

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

using namespace std;
const int  N = 1e6+100;
int a[N];
int pre[N];
int last[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0;
	pre[1]=a[1];
	for(int i=2;i<=n;i++){
		pre[i]=__gcd(pre[i-1],a[i]);
	}
	last[n]=a[n];
	for(int i=n-1;i>=1;i--){
		last[i]=__gcd(last[i+1],a[i]);
	}
	ans=last[2];
	ans=max(ans,pre[n-1]);
	for(int i=2;i<=n-1;i++){
		ans=max(ans,__gcd(pre[i-1],last[i+1]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8832
#include <stdio.h>

int main(void) {
	int i;
	char s[21];
	int len, cnt, turn;

	scanf("%s%n", s, &len);

	i = cnt = turn = 0;
	while (i < len) {
		if (!turn)
			while (i < len && s[i] != 'A')
				i++;
		else {
			while (i < len && s[i] != 'Z')
				i++;
			cnt += i < len;
		}

		turn ^= 1;
	}

	if (cnt == 0)
		puts("-1");
	else {
		for (i = 0; i < cnt; i++)
			printf("AZ");
		putchar('\n');
	}

	return 0;
}

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

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> y(q);
	rep(i, q) cin >> y.at(i);
	vector<int> x(n, k - q);
	rep(i, q) x.at(y.at(i) - 1)++;
	for (int i : x) { if (0 < i) cout << "Yes" << endl; else cout << "No" << endl; }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{
  ll f = 0, n, m = 1000, x, y, i, j, st = 0;
  cin >> n;
  int a[n + 23];
  for (i = 1; i <= n; i++)
  {
    cin >> a[i];
  }
  for (i = 2; i <= n; i++)
  {
    if (a[i] > a[i - 1])
    {
      if (f == 0)
      {
        st = m / a[i - 1];
        m = m % a[i - 1];
      }
      f = 1;
    } else if (a[i] < a[i - 1])
    {
      if (f == 1)
      {
        m += st * a[i-1];
        st = 0;
      }
      f = 0;
    }
    if (i == n)
    {
      m += st * a[i];
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 3620
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        while(true) {
            string inpt = Reader.ReadLine();
            if(inpt == null) {
                break;
            }
            int num = int.Parse(inpt);
            ans.AppendLine(GetAns(0, num).ToString());
        }
        Console.Write(ans.ToString());
    
    }

    private long GetAns(int idx, int remain) {
        if(idx >= 4) {
            if(remain == 0) {
                return 1;
            } else {
                return 0;
            }
        }

        long ans = 0;
        for (int i = 0; i <= Math.Min(remain, 9); i++) {
            ans += GetAns(idx + 1, remain - i);
        }
        return ans;
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



35
1


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 9036
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    public static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());

        int[][] a_b_c = new int[N][];

        int[][] dp = new int[N][];

        for (var i = 0; i < N; i++)
        {
            a_b_c[i] = new int[3];
            dp[i] = new int[] { 0, 0, 0 };
        }

        for (var i = 0; i < N; i++)
        {
            var tempInput = Console.ReadLine().Split(' ');

            for ( var j = 0; j < 3; j++)
            {
                a_b_c[i][j] = int.Parse(tempInput[j]);
            }
        }

        // N - 1日目が終わるまでに溜まった幸福度を計算する
        for (int i = 0; i < N - 1; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    if (j == k) continue;

                    dp[i + 1][k] = chmax(dp[i + 1][k], dp[i][j] + a_b_c[i][k]);
                }
            }
        }

        // N日目が終わるまでに溜まった幸福度
        var ans = new int[] { 0, 0, 0 };

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i == j) continue;

                ans[j] = chmax(ans[j], dp[N - 1][i] + a_b_c[N - 1][j]);
            }
        } 

        Console.WriteLine(ans.Max());
    }

    public static T chmin<T>(T a, T b) where T : IComparable
    {
        if (a.CompareTo(b) > 0)
        {
            a = b;
            return a;
        }
        return a;
    }

    public static T chmax<T>(T a, T b) where T : IComparable
    {
        if (a.CompareTo(b) < 0)
        {
            a = b;
            return a;
        }
        return a;
    }
}

Measured memory_bytes: 30248
#include<cstdio>

const int MAX_N = 2e5, MOD = 998244353;
int n, m, k;
int fac[MAX_N + 1], inv[MAX_N + 1];

int po(int x, int y) {
    int ans = 1;
    while (y > 0) {
        if (y & 1) ans = static_cast<long>(ans) * x % MOD;
        x = static_cast<long>(x) * x % MOD;
        y >>= 1;
    }
    return ans;
}

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

    fac[0] = 1;
    for (int i = 1; i <= n; i++) {
        fac[i] = static_cast<long>(fac[i - 1]) * i % MOD;
    }
    inv[n] = po(fac[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--) {
        inv[i] = static_cast<long>(inv[i + 1]) * (i + 1) % MOD;
    }

    int ans = 0;
    for (int i = 0; i <= k; i++)  {
        ans = (ans + static_cast<long>(fac[n - 1]) * inv[i] % MOD * inv[n - 1 - i] % MOD * po(m - 1, n - i - 1) % MOD) % MOD;
    }
    ans = static_cast<long>(ans) * m % MOD;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> mul(vector<int> x, vector<int> y){
    vector<int> z(x.size());
    for (int i = 0; i < x.size(); ++i) {
        z[i] = x[y[i]];
    }
    return z;
}


vector<int> pow_(vector<int> x, int n){
    vector<int> ans(x.size()), xx = x;
    iota(ans.begin(),ans.end(), 0);
    while(n > 0){
        if(n & 1) ans = mul(ans, xx);
        xx = mul(xx, xx);
        n >>= 1;
    }
    return ans;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n), A(n), B(n);
    for (auto &&i : a) scanf("%d", &i), i--;
    for (auto &&i : b) scanf("%d", &i), i--;
    if(k == 1){
        for (int i = 0; i < n; ++i) {
            if(i) printf(" ");
            printf("%d", a[i]+1);
        }
        puts("");
        return 0;
    }
    vector<string> v{"b", "bA", "bAB", "bABaB", "bABaaB", "bABabaB"};
    for (int i = 0; i < n; ++i) {
        A[a[i]] = i;
        B[b[i]] = i;
    }
    auto f = [&](string s){
        vector<int> ans(n);
        iota(ans.begin(),ans.end(),0);
        for (char i : s) {
            if(i == 'a') ans = mul(ans, a);
            else if(i == 'b') ans = mul(ans, b);
            else if(i == 'A') ans = mul(ans, A);
            else if(i == 'B') ans = mul(ans, B);
        }
        return ans;
    };
    vector<int> X = f("bABa"), Y = f("AbaB");
    auto ans = mul(mul(pow_(X, (k-2)/6), f(v[(k-2)%6])), pow_(Y, (k-2)/6));
    for (int i = 0; i < n; ++i) {
        if(i) printf(" ");
        printf("%d", ans[i]+1);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 6196
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = 1000000007;
const long long MINF = LLONG_MIN;

// -------------------------------------------------------
const int MAX_V = 330;
int V;

long long dist[MAX_V][MAX_V];

void init_dist() {
  for (int i = 0; i < MAX_V; ++i) {
    for (int j = 0; j < MAX_V; ++j) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = INF;
      }
    }
  }
}

void warshall_floyd() {
  // 1-indexed
  for (int k = 1; k <= V; ++k) {
    for (int i = 1; i <= V; ++i) {
      for (int j = 1; j <= V; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

ll N, M;
struct edge {
  ll from, to, cost;
};
edge es[2000];

int main() {
  cin >> N >> M;
  V = N;
  init_dist();
  rep(i, 0, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    dist[a][b] = c;
    dist[b][a] = c;
    es[i] = edge{a, b, c};
  }

  warshall_floyd();

  ll ans = 0;
  rep(i, 0, M) {
    auto ce = es[i];
    bool used = false;
    repe(j, 1, N) {
      repe(k, 1, N) {
        /*
        cout << dist[j][ce.from] << " " << ce.cost << " " << dist[ce.to][k]
             << " " << dist[j][k] << endl;
             */
        if (dist[j][ce.from] + ce.cost + dist[ce.to][k] == dist[j][k]) {
          used = true;
          /*
          cout << ce.from << " " << ce.to << " " << ce.cost << " "
               << dist[j][ce.from] << " " << ce.cost << " " << dist[ce.to][k]
               << " " << dist[j][k] << endl;
               */
          break;
        } else {
        }
      }
    }
    if (!used) {
      ++ans;
    }
  }
  cout << ans;
}


Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
const int N=2e5+3;
ll M=1e9+7;
ll BM(ll a,ll b)
{
    ll k=1;
    a%=M;
    while(b!=0)
    {
        if(b%2==1)
        {
            k=(k*a)%M;
        }
        a=(a*a)%M;
        b/=2;
    }
    return k;
}
ll MI(ll x)
{
    return BM(x,M-2);
}
ll ncr(ll n,ll r)
{
    ll m=max(n-r,r);
    ll s=1,p=1;
    for(ll i=m+1;i<=n;i++)
    {
        s=(s*i)%M;
    }
    m=min(n-r,r);
    for(ll i=1;i<=m;i++)
    {
        p*=MI(i);
        p%=M;
    }
    return (s*p);
}
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n>>m>>l;
    r=BM(2ll,n)-1;
    m=ncr(n,m);
    l=ncr(n,l);
    ll ans=((r+M)%M - (m+M)%M - (l+M)%M + 9*M)%M;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
int INF=1e9;
int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
double EPS = 1e-10;
const int mod=1e9+7;
int dp[4000][4000];
int main(){
  string s,t;
  while(cin>>s>>t){
    int ans=0;
    memset(dp,0,sizeof(dp));
    REP(i,s.size()){
      REP(j,t.size()){
        if(s[i]==t[j]){
          if(i==0||j==0)dp[i][j]=1;
          else dp[i][j]=dp[i-1][j-1]+1;
        }
        ans=max(ans,dp[i][j]);
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 63716
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//#define int long long
 
const int N = 1e5 + 1, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;

double dp[3003][3003], a[3003], ans;

signed main() { __
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    // fill dp with 1 ???
    dp[1][0] = 1.0 - a[1];
    dp[1][1] = a[1];
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (i - 1 >= j) {
                dp[i][j] += dp[i - 1][j] * (1.0 - a[i]);
            }
            dp[i][j] += dp[i - 1][j - 1] * a[i];
//            dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i][j - 1] * a[i];
        }
    }
    for (int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }
    cout << setprecision(10) << ans << '\n';
    return 0;
}


Measured memory_bytes: 68992
#include <stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char s[200001];
int main() {
	int t = 0, i = 0;
	cin >> s;
	while (s[i]!='\0') {
		t += s[i] - '0';
		i++;
	}
	if (t % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

int main(){
  int n,m,ans=0;cin>>n>>m;
  vector<int> k(m,0),p(m,0);
  vector<vector<int>> s(m,vector<int>(n,0));
  REP(i,m){
    cin>>k.at(i);
    for(int j=0;j<k.at(i);j++){
      cin>>s.at(i).at(j);
    }
  }
  REP(i,m) cin>>p.at(i);
  
  for(int i=0;i<pow(2,n);i++){
    bool flag=1;
    for(int j=0;j<m;j++){
      int num_of_on=0;
      for(int l=0;l<k.at(j);l++){
        if(i&(1<<(s.at(j).at(l)-1))) num_of_on++;
      }
      if(num_of_on%2!=p.at(j)) flag=0;
    }
    if(flag) ans++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <array>
#include <numeric>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;



int main()
{
    ll n;
    cin >> n;
    ll cnt = 0;
    vector<ll> v(n);
    rep(i, n) { 
        cin >> v[i];
    }
    
    for(ll i = 1; i < n-1; i++) {
        if ((v[i] < v[i-1] && v[i] > v[i+1]) || (v[i] > v[i-1] && v[i] < v[i+1])) {
            cnt++;
        }
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    ans = 0
    prev_a = -1
    for i, a in enumerate(A):
        if (a > i) or (a > prev_a + 1):
            ans = -1
            break

        if a > 0:
            ans += 1
            if prev_a + 1 != a:
                ans += (a - 1)

        prev_a = a

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  set<string> bad; bad.insert(s);
  for(int i = 1; i < n; i++){
    string now; cin >> now;
    if(now[0] != s.back()){
      cout << "No" << endl;
      return 0;
    }
    if(bad.count(now)){
      cout << "No" << endl;
      return 0;
    }
    bad.insert(now);
    s = now;
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    long long res =0;
    vector<int> a(n+1),b(n+1),c(n+1);
    int maxi = -1;
    for(int i =1; i<=n; ++i)
    {
        cin >> a[i];
    }
    for(int i = 1; i<=n; ++i)
    {
        cin >> b[i];
    }
    for(int i = 1; i< n; ++i)
    {
        cin >> c[i];
    }
    for(int i = 1; i<=n ;++i)
    {
        res += b[a[i]];
        maxi = b[a[i]];
        if(i!= 1 && a[i]-a[i-1] == 1)
            res+=c[a[i-1]];
    }
    cout << res;
    return 0;


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

int a[100005];
int d[100005];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        d[a[i]]++;
    }
    int ans=0;
    int dd=0;
    rep(i,100005){
        if(d[i]>=2){
            dd+=d[i]-1;
            ans+=1;
        }else{
            ans+=d[i];
        }
    }
    if(dd%2==1){
        ans-=1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,a[maxn];

int main()
{
	n=read(); rep(i,1,n) a[i]=read();
	ll nw=0,ans=0;
	rep(i,1,n)
	{
		if(a[i]==0) nw=0;
		else
		{
			if(nw) a[i]++,ans+=(a[i]/2),nw=a[i]%2;
			else ans+=(a[i]/2),nw=a[i]%2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const float eps=1e-6;
const ll mod=1e8;
int main()
{
    ll n,i;
    cin>>n;
    ll a[n+1]={0},dp[n+1];
    for(i=1;i<=n;i++) cin>>a[i];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(i=3;i<=n;i++)
    {
        //cout<<abs(a[i-1]-a[i])+dp[i-1]<<" "<<abs(a[i-2]-a[i])+dp[i-2]<<endl;
        if(abs(a[i-1]-a[i])+dp[i-1]>abs(a[i-2]-a[i])+dp[i-2])
            dp[i]=abs(a[i-2]-a[i])+dp[i-2];
        else dp[i]=abs(a[i-1]-a[i])+dp[i-1];
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll ma(ll x, ll y){
    if(x>y)return x;
    return y;
}
vector <int> g[200001];
ll dp[200001];
int main(void){
    int n; cin >> n; fill(dp, dp+n+1, 0); dp[0] = 1; int pr = 0;
    for(int i = 1;i <= n;i++){
        int c; cin >> c;
        if(pr == c){dp[i] = dp[i-1]; continue;}
        pr = c; g[c].push_back(i);
        if(g[c].size() == 1)dp[i] = dp[i-1];
        else dp[i] = (dp[i-1] + dp[g[c][g[c].size()-2]])%mod;
    }
    cout << dp[n] << endl;
	return 0;
}


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

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) の絶対値

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//配列の受け取り

main(){
  string n;
  int ans=0;
  cin >> n;
  for (int i=0;i<4;i++){
    if (n[i]=='2') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

bool flag;
string s;
vector <int> vec;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> s; n = (int)s.size();
	flag = (s[0] == '1' && s[n - 1] == '0');
	for (int i = 0; i < n - 1; i++){
		flag &= (s[i] == s[n - 2 - i]);
		if (s[i] == '1') vec.push_back(i);
	}
	if (!flag) return cout << -1 << endl, 0;
	int len = (int)vec.size() + 2;
	for (int i = 0; i < vec.size(); i++){
		cout << i + 1 << " " << i + 2 << "\n";
	}
	for (int i = 1; i < vec.size(); i++){
		for (int j = 0; j < vec[i] - vec[i - 1] - 1; j++){
			cout << i + 1 << " " << len + j << "\n";
		}
		len += vec[i] - vec[i - 1] - 1;
	}
	return 0;
}
 



Measured memory_bytes: 1992
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    vec<string> week{"SUN", "MON", "TUE", "WED","THU","FRI","SAT"};
    string S;
    cin >> S;
    REP(i, week.size()){
        if(S == week[i]){
            cout << 7-i << el;return;
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  int cur=0;
  rep(i,0,n){
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
      cur++;
    }
    else{
      ans=max(ans,cur);
      cur=0;
    }
  }
  ans=max(ans,cur);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// 解答不能.
// CharlotteL氏.
// https://atcoder.jp/contests/abc145/submissions/8490302
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repx(i, a, b) for(int i = a; i <= b; i++)

int main(){
    LL inf = 1e18;
    int n;
    LL k;
    scanf("%d %lld", &n, &k);
    vector<LL> h(n + 2);
    repx(i, 1, n) scanf("%lld", &h[i]);
    vector<vector<LL>> dp(n + 2, vector<LL>(k + 1, inf));
    dp[0][0] = 0;
    repx(i, 1, n + 1){
        rep(j, i){
            int c = i - j - 1;
            LL d = max(h[i] - h[j], 0LL);
            rep(l, k - c + 1) dp[i][l + c] = min(dp[i][l + c], dp[j][l] + d);
        }
    }
    printf("%lld\n", *min_element(dp.back().begin(), dp.back().end()));
    return 0;
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
    ll n;
    cin >> n;
    ll x = (ll) sqrt(n);
    while(x*x<n) x++;
    ll y = x*x-n;
    if(y > 1000000000){
        ll z = 0;
        while(y > 1000000000){
            z++;
            y-=x;
        }
        cout << "0 0 " << x << " " << y << " 1 " << x-z << endl;
    }
    else cout << "0 0 " << x << " " << y << " 1 " << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep(i, n){
    int h;
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3600
a, b, k = map(int, input().split())
l = []
for i in range(k):
    if a + i <= b:
        l.append(a + i)
    if b - i >= a:
        l.append(b - i)
l = sorted(set(l), key=l.index)
l.sort()
print(*l, sep="\n")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
int n;
double pw;
double vw[MAX],pf[MAX],vf[MAX],th[MAX];
double eps=(1e-10);

double calc(double W){
  double res=pw*W,x;
  for(int i=0;i<n;i++){
    x=vw[i]*W;
    if(x>=th[i])continue;
    res+=(th[i]-x)*pf[i]/vf[i];
  }
  return res;
}

double solve(){
  double l=0,r=1000;
  for(int i=0;i<100;i++){
    double d=(r-l)/3.0;
    if(calc(l+d)<calc(r-d)){
      r=r-d;
    }else{
      l=l+d;
    }
  }
  return calc(l);
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>pw;
    for(int i=0;i<n;i++)
      cin>>vw[i]>>pf[i]>>vf[i]>>th[i];
    printf("%.8f\n",solve());
  }
  return 0;
}

Measured memory_bytes: 4372
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	string s;
  	cin >> s;
  	sort(all(s));
  	if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3]) puts("Yes");
	else puts("No");
    return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int main(){

  int x,y,x1,y1;
  int cnt=0;

  while(1)
    {
      cnt=0;
      cin >> x >> y;

      if(x==0 && y==0)
	{
	  break;
	}

      if(x < y)swap(x,y);

      while(1)
	{
	  x = x%y;
	  swap(x,y);
	  
	  cnt++;
	  if(y == 0)break;
	}
	
      cout << x << " " << cnt << endl;
    }
}
  


Measured memory_bytes: 2980
a=int(input())
b=int(input())
if a == 1 and b ==2:
  print(3)
if a == 2 and b ==1:
  print(3)
if a == 1 and b ==3:
  print(2)
if a == 3 and b ==1:
  print(2)
if a == 2 and b ==3:
  print(1)
if a == 3 and b ==2:
  print(1)


Measured memory_bytes: 3060
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n,int k) {
	//nのk桁目
	rep(i, k-1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N;
	cin >> N;
	if ( N%DIGITSUM(N)  == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int K,N;
    cin>>K>>N;
    vector<int> A(N);
    rep(n,0,N) cin>>A.at(n);

    int maxD=0;
    rep(n,0,N){
        if(n==0) maxD=max(maxD,A.at(0)+K-A.at(N-1));
        else maxD=max(maxD,A.at(n)-A.at(n-1));
    }

    cout<<K-maxD<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000007
#define pb push_back
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
  vector<ll>A;
  ll k;
  ll x;
  cin>>x>>k;
  ll sum = (((((k+1))*k))/2);
  ll dum = (((((k))*((k-1))))/2);
  for (ll i = 0; i < x; ++i)
  {
    ll hi;cin>>hi;A.pb(hi);
  }
  ll di=0;
  for (ll i = 0; i < x; ++i)
  {
    for (ll j = i+1; j < x; ++j)
    {
      if(A[i]>A[j])di=(sum+di)%INF;
      else if(A[i]<A[j])di=(dum+di)%INF;
    }
  }
  cout<<di%INF;
  return 0;
}
//code the AC sol !
// BS/queue/map

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

using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);

    for (int i = 0; i < m; i++) {
        cin >> l.at(i);
        cin >> r.at(i);
    }

    int L = *max_element(l.begin(), l.end());
    int R = *min_element(r.begin(), r.end());

    if (L <= R) cout << R - L + 1 << endl;
    else cout << 0;

    return 0;
}



Measured memory_bytes: 1024
import itertools

N=input()
OP=['+','-']
for op in itertools.product(OP, repeat=3):
  str=N[0]+op[0]+N[1]+op[1]+N[2]+op[2]+N[3]
  ans = eval(str)
  if ans==7:
    print(str + "=7")
    break

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
#define mp make_pair

const ll INF = (ll)1e18;

const int N = 300300;
int n;
ll a[N];
ll b[N];
ll c[N];
set<pli> setik;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    for (int i = 0; i < 3 * n; i++)
        scanf("%lld", &a[i]);

    setik.clear();
    ll sum = 0;
    for (int i = 0; i < 3 * n; i++)
    {
        if ((int)setik.size() < n)
        {
            setik.insert(mp(a[i], i));
            sum += a[i];
        }
        else
        {
            ll sm = setik.begin()->first;
            if (sm < a[i])
            {
                sum += a[i] - sm;
                setik.erase(setik.begin());
                setik.insert(mp(a[i], i));
            }
        }
        if ((int)setik.size() == n)
            b[i + 1] = sum;
    }

    setik.clear();
    sum = 0;
    for (int i = 3 * n - 1; i >= 0; i--)
    {
        if ((int)setik.size() < n)
        {
            setik.insert(mp(-a[i], i));
            sum += a[i];
        }
        else
        {
            ll sm = setik.begin()->first;
            if (sm < -a[i])
            {
                sum += a[i] + sm;
                setik.erase(setik.begin());
                setik.insert(mp(-a[i], i));
            }
        }
        if ((int)setik.size() == n)
            c[i] = sum;
    }
    
    ll ans = -INF;

    for (int i = n; i <= 2 * n; i++)
        ans = max(ans, b[i] - c[i]);

    printf("%lld\n", ans);


    return 0;
}

Measured memory_bytes: 13056
import java.util.*;
import java.math.*;
 
public class Main {
  static int mod = (int) 1e9 + 7;
    static int n;
    static long k;
    static long a[];
  public static void main(String[] args) {
    	Scanner fs = new Scanner(System.in);
    	n = fs.nextInt();
        k = fs.nextLong();
    	a = new long[n];
        for(int i = 0; i < n; ++i) {
          a[i] = fs.nextLong();
        }
        Arrays.sort(a);
        long INF = (long)(1e18)+1;
        long l = -INF;
        long r = INF;
        while(l < INF && l <= r) {
            long c = (l+r)/2;
            if(check(c))l = c + 1;
            else r = c - 1;
        }
        System.out.println(Math.max(-INF, l - 1));
    }

    static boolean check(long x) {
        long tot = 0;
        for(int i=0;i<n;i++) {
            long now = a[i];
            int l = 0, r = n;
            if(now >= 0) {
                --r;
                while(l < n && l <= r) {
                    int c = (l+r)/2;
                    if(now * a[c] < x) l = c + 1;
                    else r = c - 1;
                }
                tot += l;
            }
            else {
                while(l < n && l <= r) {
                    int c = (l+r)/2;
                    if(now * a[c] >= x) l = c+1;
                    else r = c - 1;
                }
                tot += (n - l);
            }
            if((long)a[i] * a[i]<x)tot--;
        }
        if(tot/2 < k) return true;
        else return false;
    }
}

Measured memory_bytes: 88676
"use strict"
function main(arg) {
    var b =  arg.trim().split(' ')[0];
    var c = arg.trim().split(' ')[1];



     console.log(combination(b,2) + combination(c,2)) 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function permutation(n, r) {
for(var i = 0, res = 1; i < r; i++) {
res *= n - i;
}


return res;
}

function combination(n, r) {

    
return permutation(n, r) / permutation(r, r);
}

Measured memory_bytes: 7372
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;

int main()
{
	/*int n,k;
	cin >> n;
	vector<char>s(n);
	for (int j = 0; j < n; j++)  cin >> s[j];
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		if (s[i] != s[k-1]) {
			s[i] = '*';
		}
	}

	for (int l = 0; l < n; l++)
	{
		cout << s[l] ;
	}*/

	int n;
	cin >> n;
	vector<int>b(n-1);
	vector<int>a(n);
	for (int i = 0; i < n-1; i++) cin >> b[i];

	a[0] = b[0];

	for (int i = 1; i < n-1; i++) {

		if (b[i-1] >= b[i]) {
			a[i]=b[i];
		}

		if (b[i-1] < b[i]) {
			a[i]= b[i-1];
		}
	}

		a[n-1] = b[n -2];
	

	int sum = 0;

	for (int i = 0; i < n; i++)sum = sum + a[i];

	cout <<sum  << endl;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n,m,k;
string s,t;

int main() {
  cin >> k >> s;
  cout << (s.size()<=k ? s : s.substr(0,k)+"...") << endl;
}

Measured memory_bytes: 3624
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	yaki := "YAKI"
	if len(s) < len(yaki) {
		fmt.Fprintln(writer, "No")
		return
	}
	for i := 0; i < len(yaki); i++ {
		if s[i] != yaki[i] {
			fmt.Fprintln(writer, "No")
			return
		}
	}
	fmt.Fprintln(writer, "Yes")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
	int n;
	cin>>n;
	vector<int> p(n),q(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
		q[p[i]]=i;
	}
	
	int temp=1;
	int l=1;
	rep(i,n-1){
		if(q[i]<q[i+1]){
			temp++;
			l=max(l,temp);
		}
		else temp=1;
	}
	cout<<n-l<<endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll MAX = 2e5;
ll siz[MAX], cnt[MAX], ans[MAX], color[MAX];
vector<ll> g[MAX];
void dfs1(ll from, ll at){
    siz[at]++;
    for(ll i : g[at]) if(i != from){
        dfs1(at, i);
        siz[at] += siz[i];
    }
}
void dfs2(ll from, ll at){
    const ll c = color[at];
    ll tmp = cnt[c];
    for(ll i : g[at]) if(i != from){
        cnt[c] = siz[i];
        dfs2(at, i);
        ans[c] -= cnt[c] * (cnt[c] + 1) / 2;
    }
    cnt[c] = tmp - siz[at];
}
int main(){
    ll n;
    cin >> n;
    for(ll i = 0; i < n; i++){
        ll c;
        cin >> c;
        c--;
        color[i] = c;
        cnt[c] = n;
        ans[c] = n * (n + 1) / 2;
    }
    for(ll i = 1; i < n; i++){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(-1, 0);
    dfs2(-1, 0);
    for(ll i = 0; i < n; i++) ans[i] -= cnt[i] * (cnt[i] + 1) / 2;
    for(ll i = 0; i < n; i++) cout << ans[i] << ' ';
}

Measured memory_bytes: 36388
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int K = x[0], X = x[1];
		if (500 * K >= X) { Console.WriteLine("Yes"); }
		else { Console.WriteLine("No"); }
	}
}

Measured memory_bytes: 28100