akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
P p[500];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N){
        int x;
        cin>>x;
        p[i]=P(x,i+1);
    }
    sort(p,p+N);
    ll pos=0;
    rep(i,0,N){
        pos+=p[i].sc;
        if(p[i].fr<pos){
            cout <<"No"<<"\n";
            return 0;
        }
    }
    pos=0;
    rer(i,N,0){
        pos+=N+1-p[i].sc;
        if(N*N-p[i].fr+1<pos){
            cout <<"No"<<"\n";
            return 0;
        }
    }
    cout <<"Yes"<<"\n";
    vector<int> ans(N*N,0);
    rep(i,0,N){
        ans[p[i].fr-1]=p[i].sc;
    }
    pos=0;
    rep(i,0,N){
        int j=p[i].sc-1;
        while(j){
            if(ans[pos]!=0){
                pos++;
                continue;
            }
            ans[pos]=p[i].sc;
            pos++;
            j--;
        }
    }
    pos=N*N-1;
    rer(i,N,0){
        int j=N-p[i].sc;
        while(j){
            if(ans[pos]!=0){
                pos--;
                continue;
            }
            ans[pos]=p[i].sc;
            pos--;
            j--;
        }
    }
    rep(i,0,N*N){
        if(i==N*N-1) cout<<ans[i]<<"\n";
        else cout<<ans[i]<<" ";
    }
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int r,g,b;
    cin >> r >> g >> b;
    if ((g*10 + b) % 4 == 0) { 
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

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

    int n = sc.nextInt();
    String[] s = new String[n+1];

    Map<String, Integer> list = new HashMap<>();
    
    for (int i = 0; i < n; i++) {
      char[] t = sc.next().toCharArray();
      Arrays.sort(t);
      s[i] = "";
      for (int j = 0; j < 10; j++) {
        s[i] += String.valueOf(t[j]);
      }
      list.put(s[i], (list.get(s[i]) == null ? 0 : list.get(s[i])+1));
    }

    long ans = 0;
    for (Map.Entry<String, Integer> entry: list.entrySet()) {
      int cnt = entry.getValue();
      for (int i = 0; i <= cnt; i++) {
        ans += i;
      }
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 98596
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed;
// cout << setprecision(10) << val;

int n, q;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> q;
  vv<tuple<int, bool, int>> tp;
  vii d(q);
  set<int> S;
  rep(i, 0, n) {
    int s, t, x;
    cin >> s >> t >> x;
    tp.pb(make_tuple(s - x, true, x));
    tp.pb(make_tuple(t - x, false, x));
  }
  cin >> d;
  sort(ALL(tp));
  int pos = 0;
  for (auto beg : d) {
    erep(i, pos, tp.size()) {
      if (i == tp.size()) {
        cout << -1 << endl;
        pos = i;
        break;
      }
      auto t = tp[i];
      if (get<0>(t) <= beg) {
        if (get<1>(t)) {
          S.insert(get<2>(t));
        } else {
          S.erase(get<2>(t));
        }
      } else {
        if (S.empty()) cout << -1 << endl;
        else cout << *S.begin() << endl;
        pos = i; 
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 21736
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
      	int d = sc.nextInt();
      	int ans = 0;
       for(int i=L;i<=R;i++){
         if(i % d == 0){
           ans += 1;
         }
       }
         System.out.println(ans);
    }
}

Measured memory_bytes: 35676
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define de(x) cout<<#x<<"="<<x<<endl
const int N=55;
vector<int> q[N];int l[1255],r[1255];
bool in[N];
int n,m,a,b;
bool bfs(int a,int b){
	memset(in,0,sizeof(in));
	queue<int>que;
	que.push(1);
	int u=1,v;in[1]=1;
	while(!que.empty()){
		u=que.front();que.pop();
		for(int i=0;i<q[u].size();i++){
			v=q[u][i];
			if(in[v]||(u==a&&v==b)||(u==b&&v==a))continue;
			else in[v]=1;
			que.push(v);
		}
	}
	for(int i=1;i<=n;i++){
		if(!in[i])return true;
	}
	return false;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		q[a].pb(b);q[b].pb(a);
		l[i]=a;r[i]=b;
	}
	int ans=0;
	for(int i=0;i<m;i++){
		if(bfs(l[i],r[i])){
			ans++;
		}
	}
	printf("%d",ans);
}


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

def main():
# 整数の入力

    line1 = input().split(' ')
    n = int(line1[0])
    m = int(line1[1])
    a = [int(x) for x in input().split(' ')]
    s = sum(a)
    rest = n - s
    if rest >= 0:
        print(rest)
    else:
        print(-1)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 10048
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	ll n,m;
	cin >> n >> m;
	if(abs(n-m)<=1){
		cout << "Brown" << endl;
	}else{
		cout << "Alice" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    unsigned long long ans,res;

    unsigned long long n;

    double k;


    cin >> n >> k;

    // cout << k <<endl;

    // auto num = atoi(k.c_str());

    k=k*100;
    
    string kk = to_string(k);

    int num = stod(kk);

    // num = num*100;

    // cout << k << endl;
    ans = num*n;
    res = ans/100;

    // k1 = k*100;
    // ans=n*k1;
    // ans = ans/100;

    // ans = k * n;
    cout << res;

    return 0;
}

Measured memory_bytes: 3860
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;


int main()
{
    // 整数の入力
    ll N,sum;
    vector<ll> waters;
    cin >> N;
    for(int i = 1;i<=N;i++){
        ll a;
        cin >> a;
        if (i % 2 == 1){
            sum+=a;
        }else{
            sum-=a;
        }
        waters.push_back(a);
    }

    for (int i = 0;i<N;i++){
        if ( i  == 0){
            cout << sum;
        }else{
            sum = - sum + 2 * waters[i-1];
            cout << " " << sum;
        }
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
const constexpr int MAX = 1e5;
vi G[MAX], prenum(MAX, 0), parent(MAX, 0), lowest(MAX, 0);
int n, timer{0};
vb visited(MAX, false);
inline void dfs(int current, int prev) {
	prenum[current] = lowest[current] = ++timer;
	visited[current] = true;
	int next;
	rep(i, 0, len(G[current])) {
		next = G[current][i];
		if(!visited[next]) {
			parent[next] = current;
			dfs(next, current);
			lowest[current] = min(lowest[current], lowest[next]);
		} else if(next != prev) {
			lowest[current] = min(lowest[current], prenum[next]);
		}
	}
}
inline void art_points() {
	dfs(0, -1);
	set<int> ap;
	int np = 0, p;
	rep(i, 1, n) {
		p = parent[i];
		if(p == 0) ++np;
		else if(prenum[p] <= lowest[i]) ap.emplace(p);
	}
	if(np > 1) P(0);
	for(auto it : ap) P(it);
}
int main() {
	int m; cin >> n >> m;
	int s, t;
	rep(i, 0, m) {
		cin >> s >> t;
		G[s].eb(t);
		G[t].eb(s);
	}
	art_points();
	return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define GOOGLE 0
#define MULTIPLE_TC 0

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

const int N = 2e5 + 10;
int a[N];

void solve(){
  long long n, k;
  int i, j;
  cin >> n >> k;
  for(i = 1; i <= n; i++){
    cin >> a[i];
  }
  int u = 1, step = 1, sub = 0, p = 0, cyc = 0;
  map<int, int> m, par;
  par[u] = p;
  vector<int> res;
  while(1){
    if(m.find(u) != m.end()){
      while(p != u){
        res.push_back(p);
        p = par[p];
      }
      res.push_back(u);
      sub = m[u] - 1;
      break;
    }
    m[u] = step;
    par[u] = p;
    p = u;
    u = a[u];
    step += 1;
  }
  reverse(all(res));
  cyc = res.size();
  if(k > sub){
    k -= sub;
    k %= cyc;
    cout << res[k] << '\n';
  }else{
    int u = 1;
    for(i = 1; i <= k; i++){
      u = a[u];
    }
    cout << u << '\n';
  }
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL); 

  pre();

  int t = 1, T;

  if(MULTIPLE_TC)
    cin >> t;

  for(T = 1; T <= t; T++){
    if(GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}


Measured memory_bytes: 23092
# -*- coding: utf-8 -*-
from sys import stdin

d_in = lambda: int(stdin.readline())  # N = d_in()


UPPER_LIMIT = 55555
N = d_in()


ans = [2, 7]
primes = [2, 3, 5, 7]
for i in range(11, UPPER_LIMIT, 2):
    flag = True
    for p in primes:
        if i % p == 0:
            flag = False
    if flag:
        primes.append(i)
    if flag and (i % 5 == 2):
        ans.append(i)
    if len(ans) == N:
        break

print(*ans)


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll K, N;
  scanf("%lld %lld", &K, &N);

  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    A[i] = v;
  }

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

  ll max_dist = 0;
  for (ll i = 0; i < N; i++) {
    if (i == 0) {
      continue;
    }

    ll s = (A[i] - A[i - 1]);
    max_dist = max(s, max_dist);
  }

  ll last = K + A[0];
  ll last_s = last - A[N - 1];
  max_dist = max(last_s, max_dist);

  ll ans = K - max_dist;

  cout << ans << endl;
}


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

int main(){
  int a,b;
  cin >>a>>b;
  int c,d,e;
  c = a+b;
  d = a-b;
  e = a*b;
  if(c>d){
    cout <<max(c,e)<<endl;
  }else{
    cout <<max(d,e)<<endl;
  }
}

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

int main()
{
    ll x, k, d;
    cin>>x>>k>>d;
    if(x<0)x=-x;
    ll kp = (x/d);
    ll ans;
    if(kp>=k)ans=x-(d*k);
    else{
        ll p1=x-(d*kp);
        ll p2=d-p1;
        k = k-kp;
        if(k%2==0)ans=p1;
        else ans=p2;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3628
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
int main(){
  int n;
  cin>>n;
  int cmin=0,x=0;
  int c[10]={};
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a<400){
      c[0]++;
    }else if(a>=400&&a<800){
      c[1]++;
    }else if(a>=800&&a<1200){
      c[2]++;
    }else if(a>=1200&&a<1600){
      c[3]++;
    }else if(a>=1600&&a<2000){
      c[4]++;
    }else if(a>=2000&&a<2400){
      c[5]++;
    }else if(a>=2400&&a<2800){
      c[6]++;
    }else if(a>=2800&&a<3200){
      c[7]++;
    }else if (a>=3200){
      x++;
    }
  }
  for(int i=0;i<8;i++){
    if(c[i]>0){
      cmin++;
    }
  }
  if(cmin==0){
    if(x>=8){
      cout<<1<<" "<<8<<endl;
    }else{
      cout<<1<<" "<<x<<endl;
    }
  }else{
    cout<<cmin<<" "<<cmin+x<<endl;
  }
  return 0;
}
     


Measured memory_bytes: 256
root=(1..gets.to_i).map{
  r,k,*t=gets.split.map(&:to_i)
  [r,t]
}.to_h

gets.to_i.times{
  s,d,v=gets.split.map(&:to_i)
  q=[[s,1]]
  visited={s=>true}
  ret = while q[0]
    id,num=q.shift
    next if num>v
    break num if id==d
    root[id].each{|i|
      unless visited[i]
        visited[i]=true
        q.push([i,num+1])
      end
    }
  end
  puts (ret||"NA")
}

Measured memory_bytes: 9656
main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  putStrLn $ solve a b

solve :: Int -> Int -> String
solve a b
  | a < 0 && b < 0
    = if (-1) ^ (b - a + 1) > 0 then "Positive" else "Negative"
  | a > 0 && b > 0
    = "Positive"
  | otherwise
    = "Zero"


Measured memory_bytes: 508
# D - Chat in a Circle

N = int(input())
A = list(int(a) for a in input().split())

A.sort(reverse=True)

n = N-1
ans = A[0]
n -= 1
i = 1
while n > 0:
    if n == 1:
        ans += A[i]
        n -= 1
    else:
        ans += A[i] * 2
        n -= 2
    i += 1
print(ans)

Measured memory_bytes: 31612
// Aizu Vol-5 0540: Amidakuji
// 2017.9.1 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { int a, h; } T;

int p[1003]; int n;
T tbl[100003]; int m;
T q[1003];
int id[1003];
unsigned char rel[1003][1003];

int cmp(T *a, T *b) { if (b->h - a->h) return b->h - a->h; return a->a - b->a; }

int main()
{
	int h, k, i, j, t, s, ans, max;
	unsigned char cno = 1;

	while (scanf("%d%d%d%d", &n, &m, &h, &k) && n) {
		for (i = 0; i < n; i++) scanf("%d", p+i);
		for (i = 0; i < m; i++) scanf("%d%d", &tbl[i].a, &tbl[i].h);
		qsort(tbl, m, sizeof(T), cmp);
		for (i = 0; i < n; i++) id[i] = i;
		for (i = 0; i < m; i++) {
			j = tbl[i].a, t = id[j], s = id[j-1];
			id[j-1] = t, id[j] = s; rel[t][s] = rel[s][t] = cno;
		}
		for (max = -1, ans = 0, i = 0; i < n; i++) {
			t = p[id[i]], q[i].a = t, q[i].h = id[i]; if (i < k) ans += t;
		}
		if (k < n) {
			for (i = 0; i < k; i++) for (j = k; j < n; j++) {
				t = q[i].a - q[j].a;
				if (rel[q[i].h][q[j].h] == cno && t > 0) {
					if (max < 0 || t > max) max = t;
				}
			}
		}
		if (max	> 0) ans -= max;
		printf("%d\n", ans);
		cno++;
	}
	return 0;
}

Measured memory_bytes: 3800
#include <stdio.h>

int main(){
	int x, a, b;
	scanf("%d %d %d", &x, &a, &b);
	int A = x - a;
	int	B = x - b;
	if (A < 0) A *= -1;
	if (B < 0) B *= -1;
	if (A < B){
		printf("A");
	}
	else {
		printf("B");
	}
	return 0;	
}

Measured memory_bytes: 1660
#include<iostream>
using namespace std;
constexpr auto mod=1000000000+7;
long long quick_pow(long long radix,long long ex){
    long long res=1;
    while(ex>0){
        if(ex & 1)
            res=res*radix%mod;
        radix=radix*radix%mod;
        ex>>=1;
    }
    return res;
}
int main(){
    long long n;
    cin>>n;
    cout<<((quick_pow(10,n)-quick_pow(9,n)+mod)-quick_pow(9,n)+mod+quick_pow(8,n))%mod;
    //getchar();
    //getchar();
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //ll num=1e9;
    ll n,l;
    cin>>n>>l;
    ll r=l+n-1;
    if(r>=0){
        if(l>=0){
            cout << (r+l+1)*(n-1)/2 <<endl;
        }
        else{
            cout << n*(r+l)/2 <<endl;
        }
    }
    else{
        cout <<(n-1)*(r-1+l)/2 <<endl;
    }
    return 0;
}


Measured memory_bytes: 384
def count(l):
    res = {0:0, 1:0}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res
from operator import mul
from functools import reduce

def cmb(n,r):
    if n < r: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n, p = map(int, input().split())
data = list(map(int, input().split()))
data = [i%2 for i in data]
oz = count(data)

ans = 0
m = 2**oz[0]
if p == 0:
    choice = 2
    ans += m
elif p == 1:
    choice = 1
ones = oz[1]
while choice <= ones:
    ans += m*cmb(ones, choice)
    choice += 2
print(ans)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll DP[10][10];

int Solve(int num){
  int j = num % 10;
  while (num >= 10) num /= 10;
  DP[num][j]++;
  return 0;
}

int main(){
  cin >> N;
  for (int i = 1; i <= N; i++) Solve(i);

  ll ans = 0;
  for (int i = 1; i <= 9; i++){
    for (int j = 1; j <= 9; j++){
      ans += DP[i][j] * DP[j][i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for(int i = x; i < y; i++)
typedef long long ll;
using namespace std;

char grid[1001][1001];
int dp[1001][1001];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w;
    cin >> h >> w;
    FOR(i, 1, h + 1) {
        FOR(j, 1, w + 1) {
            cin >> grid[i][j];
        }
    }
    dp[1][1] = 1;
    FOR(i, 1, h + 1) {
        FOR(j, 1, w + 1) {
            if (grid[i][j] == '.' && !(i == 1 && j == 1)) {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
            }
        }
    }
    cout << dp[h][w] << '\n';
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<ll> > vvll;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
int main() {
	ll n;
	cin>>n;
	cout<<(ceil(((double)n/1000))*1000)-n;
	return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n;
vpll a;
vl s;
vvl g;

ll dfs(ll v,ll p,ll d){
	ll res=d;
	for(auto u:g[v]) if(u!=p) res+=dfs(u,v,d+1);
	return res;
}

int main(){
	cin>>n;
	a=vpll(n);
	s=vl(n,1);
	g=vvl(n);
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a[i]={x,i};
	}
	sort(a.begin(),a.end());
	for(int i=n-1;i>0;i--){
		ll d=a[i].first,t=d+2*s[i]-n;
		ll id=lower_bound(a.begin(),a.end(),pll(t,0))-a.begin();
		if(id>=i||a[id].first!=t){
			cout<<-1<<endl;
			return 0;
		}
		ll u=a[i].second,v=a[id].second;
		s[id]+=s[i];
		g[u].push_back(v);
		g[v].push_back(u);
	}
	if(dfs(a[0].second,-1,0)==a[0].first){
		for(int u=0;u<n;u++) for(auto v:g[u]) if(u<v) cout<<u+1<<' '<<v+1<<endl;
	}
	else cout<<-1<<endl;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x;cin >> n >> x;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	int sum=0,ans=0;
	rep(i,n){
		if(sum<=x) ans++;
		sum+=a.at(i);
	}
	if(sum<=x) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;

int main()
{
    ll a,b,c;
    while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)
    {
        if(a==1)
        {
            printf("YES\n");
            continue;
        }
        ll flag=0;
        for(ll i=2;i<2000000;i++)
        {
            if((b*i+c)%a==0)
            {
                flag=1;
                break;
            }
        }
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N,M;cin>>N>>M;
    int X[N];REP(i,N)cin>>X[i];
    sort(X,X+N);

    int cnt[M];
    fill_n(cnt,M,0);
    int pr[M];
    fill_n(pr,M,0);

    REP(i,N)cnt[X[i]%M]++;
    REP(i,N)if(X[i]==X[i+1])pr[X[i++]%M]++;

    int ans=cnt[0]/2;
    for (int i=1;i<M;i++){
        int num = min(cnt[i],cnt[M-i]);
        if(i==M-i)num/=2;
        ans +=num;
        cnt[i]-=num;
        cnt[M-i]-=num;
    }
    for(int i=1;i<M;i++)ans += min(pr[i],cnt[i]/2);
    cout<<ans<<endl;


    return 0;
}

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

#define ll long long
#define vl vector<ll>
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    bool ok = false;
    int K, A, B;
    cin >> K >> A >> B;

    for(int i=A; i<=B; i++){
        if(i%K == 0){
            ok = true;
            break;
        } 
    }

    if(ok) cout << "OK"  << endl;
    else cout << "NG" << endl;
       
}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

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

const int NM = 1000;
int c[NM], s[NM], f[NM];
int ans[NM]; // [n] 駅を出発した列車

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    for(int i=1; i<=n-1; i++){
        cin>>c[i]>>s[i]>>f[i];
    }

    for(int station=1; station<=n; station++){
        for(int j=1; j<station; j++){ // すでに出発していた奴
            int dep = 0;
            if(ans[j] <= s[station-1]) dep = s[station-1]-ans[j];
            else dep = ((ans[j] - s[station-1] + (f[station-1]-1)) / f[station-1]) * f[station-1] + s[station-1] - ans[j];
            ans[j] = ans[j] + dep + c[station-1]; // 前の駅に到着した時間＋出発迄にかかる時間＋駅間
        }
        ans[station] = s[station]; // station 発射はs[station]時刻から。
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<endl;
    }

}
// abc084_c.exe

Measured memory_bytes: 256
N = gets.to_i
stations = (N - 1).times.map { gets.split.map(&:to_i) }

N.times do |i|
  ans = 0

  if i < N - 1
    s = stations[i]
    ans = s[0] + s[1]

    stations[(i + 1)..N].each do |c, s, f|
      if ans <= s
        ans = s
      else
        if ans % f != 0
          ans += f - (ans % f)
        end
      end

      ans += c
    end
  end

  puts ans
end


Measured memory_bytes: 1788
N,C = map(int,input().split())

pre_mx = [(0,0)]
suf_mx = [(0,0)]
run_psum = 0
run_ssum = 0
data = []
for i in range(N):
    x,v = map(int,input().split())
    if run_psum + v - x > pre_mx[i][1]:
        pre_mx.append((x,run_psum + v - x))
    else:
        pre_mx.append((pre_mx[i][0],pre_mx[i][1]))
    run_psum += v
    data.append((x,v))

for i in range(N-1,-1,-1):
    if run_ssum + data[i][1] - C + data[i][0] > suf_mx[N-1-i][1]:
        suf_mx.append((C - data[i][0],run_ssum + data[i][1] - C + data[i][0]))
    else:
        suf_mx.append((suf_mx[N-1-i][0],suf_mx[N-1-i][1]))
    run_ssum += data[i][1]

ansp = anss = 0
for i in range(N+1):
    if ansp < pre_mx[i][1] + suf_mx[-i-1][1] - pre_mx[i][0]:
        ansp = pre_mx[i][1] + suf_mx[-i-1][1]
        if suf_mx[-i-1][0] != 0:
            ansp -= pre_mx[i][0]
            
    if anss < suf_mx[i][1] + pre_mx[-i-1][1] - suf_mx[i][0]:
        anss = suf_mx[i][1] + pre_mx[-i-1][1]
        if pre_mx[-i-1][0] != 0:
            anss -= suf_mx[i][0]

print(max(ansp,anss))


Measured memory_bytes: 40348
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:
ll n,a[410];
ll dp[410][410];
const ll inf = 1LL << 50;

ll rec(int l,int r){
	if(r - l == 1) return 0LL;
	ll &ret = dp[l][r];
	if(ret >= 0) return ret;

	ret = inf;
	ll cost = 0LL;
	rep(i,l,r) cost += a[i];
	
	for(int m = l + 1; m < r; ++m){
		chmin(ret, cost + rec(l, m) + rec(m, r));
	}
	return ret;
}


int main(void){
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n+1)rep(j,n+1) dp[i][j] = -1LL;
	cout << rec(0,n) << endl;
	return 0;	
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;


using namespace std;
bool priN[1000000]={};
bool pri[1000000]={};

bool isPrime(int n){
	if(priN[n]==true)return pri[n];
	for(int i=3;i<=sqrt((double)n);i++){
		if(n%i==0){
			priN[n]=true;
			pri[n]=false;
			return false;
		}
	}
	priN[n]=true;
	pri[n]=true;
	return true;
}

int main(){
	while(1){
		int n;
		if( !(cin>>n) )break;
		ll sum=1;
		if (n<2) sum--;
		for(int i=3;i<=n;i+=2){
			if(isPrime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3108
s = str(input())
q = int(input())
order = [[x for x in input().split()] for _ in range(q)]

for cmd, left, right, *etc in order:
    left=int(left)
    right=int(right) + 1
    if cmd=='replace':
        s = s[:left] + etc[0] + s[right:]
    elif cmd=='reverse':
        s = s[:left] + s[left:right][::-1] + s[right:]
    else:
        print(s[left:right])


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);

  int a, b;
  for(int i = 0; i < M; i++){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist(N);
  for(int i = 0; i < N; i++){
    dist[i] = -1;
  }
  dist[0] = 0;
  queue<int> q;
  q.push(0);

  while(!q.empty()){
    int v = q.front();
    q.pop();

    for(auto nv : G[v]){
      if(dist[nv] >= 0) continue;

      dist[nv] = dist[v] + 1;
      q.push(nv);
    }
  }

  if(dist[N-1] == 2){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 13168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, k, s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n){
    int a;
    cin >> a;
    s += min(a, abs(k-a));
  }
  cout << s*2 << endl;
}

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

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

	vector<int> H(N);
	rep(i, N)
	{
		cin >> H[i];
	}

	int cnt = 0;
	int ans = 0;
	rep(i, N - 1)
	{
		if (H[i] >= H[i + 1])
		{
			cnt++;
		}
		else
		{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);

	cout << ans << endl;

	return 0;
}

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

def inp():
    return(int(input()))
    
def inlt():
    return(list(map(int,input().split())))
    
n = inp()
f = inlt()
f = list(reversed(sorted(f)))
if n%2:
    print(2*sum(f[0:(n+1)//2])-f[0]-f[(n+1)//2-1])
else:
    print(2*sum(f[0:n//2])-f[0])
    

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

int main() {
  int N=0,K=0;
  int D_num[10]={0};
  char D[10]={'\0'};
  char N_str[8]={'\0'};
  int flag=0;

  scanf("%d %d\n",&N,&K);
  for(int i=0;i<K;i++) scanf("%d",&D_num[i]);
  for(int i=0;i<K;i++) sprintf(&D[i],"%c",('0'+D_num[i]));
  for(int i=N;i<100001;i++){
    sprintf(N_str,"%d",i);
    flag=0;
    for(int j=0;N_str[j]!='\0';j++){
      for(int k=0;k<K;k++){
        if(N_str[j]==D[k]){
          flag=1;
          break;
        }
      }
      if(flag==1) break;
    }
    if(flag==0) break;
  }
  printf("%s\n",N_str);

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

bool sosuu(int x){
    int i=x-1;
    while(i>1){
        if(x%i==0) x/=i;
        i--;
    }
    if(x==1) return true;
    return false;
}

int main(){
    int x;
    
    scanf("%d",&x);
    
    while(1){
        if(!sosuu(x)){
            break;
        }
        x++;
    }
    
    printf("%d\n",x);
    
    return 0;
    
}

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

int main() {
	int n;
	cin >> n;
	double dp[3001][3001];
	vector<double> prob;
	for (int i = 0; i < n; i++) {
		double temp;
		cin >> temp;
		prob.push_back(temp);
	}
	for (int i = 0; i < n + 1; i++) {
		for (int j = 0; j < n + 1; j++) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0) {
				dp[i][j] = dp[i - 1][j] * (1 - prob[i - 1]);
			}
			else {
				dp[i][j] =  dp[i - 1][j] * (1 - prob[i - 1]) + dp[i - 1][j - 1] * prob[i - 1];
			}
		}
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += dp[n][i];
	}
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 70656
#include<stdio.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define INF 10000000

int m[10][10];

int main(void)
{
	int n,N,a,b,time,min,index;
	int i,j,k;

	while (1) {
		N = 0;
		scanf("%d", &n);
		if (n == 0)break;
		int sum[15] = { 0 };
	
		for (i = 0; i < 10; i++) {
			for (j = 0; j < 10; j++)
				if (i == j)m[i][j] = 0;
				else
				m[i][j] = INF;
		}

		for (i = 0; i < n; i++) {
			scanf("%d %d %d", &a, &b, &time);
			m[a][b] = time;
			m[b][a] = time;
			if (N < a)N = a;
			if (N < b) N = b;
		}

		
		for (i = 0; i <= N; i++) {
			for (j = 0; j <= N; j++) 
				for (k = 0; k <= N; k++) 
					m[j][k] = MIN(m[j][k], m[j][i] + m[i][k]);
		}
		for (i = 0; i <= N; i++) {
			for (j = 0; j <= N; j++)
				sum[i] += m[i][j];
		}
		index = 0;
		min = sum[0];
		for (i = 1; i <= N; i++) {
			if (min > sum[i]) {
				min = sum[i];
				index = i;
			}
		}
		printf("%d %d\n",index,min);
	}
	return 0;
}

Measured memory_bytes: 600
S = input()

S = list(map(int, S.split()))

N = S[0]
L = S[1]

taste_min = 100000000
taste = 0
for i in range(1, N+1, 1):
    taste = taste + L + i - 1

for i in range(1, N+1, 1):
    taste_temp = 0
    for j in range(1, N + 1, 1):
        if i != j:
            taste_temp = taste_temp + L + j - 1
    if abs(taste_temp-taste) < abs(taste_min-taste):
        taste_min = taste_temp

print(taste_min)


Measured memory_bytes: 3064
/* 
chirag11032000
Chirag Thakur
*/

#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;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int a, b;
	cin >> a >> b;
	cout << max({a + b, a + a - 1, b + b - 1}) << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
    char s[101], s_copy[101], p[101];

    scanf("%s", &s);
    scanf("%s", &p);

    strcpy(s_copy, s);
    strcat(s, s_copy);

    if(strstr(s, p) != 0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	int N=0,W=0,S=0,E=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='N')N=1;
		if(s[i]=='W')W=10;
		if(s[i]=='S')S=-1;
		if(s[i]=='E')E=-10;
	}
	if(N+W+S+E==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int f(int i, int n, int k, vector<int>& h, vector<int>& dp) {
    if (i == n - 1) return 0;
    int& ans = dp[i];
    if (ans != -1) return ans;
//    ans = abs(h[i] - h[i + 1]) + f(i + 1, n, h, dp);
//    if (i + 2 < n) ans = min(ans, abs(h[i] - h[i + 2]) + f(i + 2, n, h, dp));
    ans = INT_MAX;
    for (int j = 1; j <= k; j++) {
        if (i + j < n) ans = min(ans, abs(h[i] - h[i + j]) + f(i + j, n, k, h, dp));
    }
    return ans;
}

void solve(int test) {
    int n, k;
    cin >> n >> k;
    vector<int> h(n), dp(n, -1);
    for (int i = 0; i < n; i++) cin >> h[i];
    cout << f(0, n, k,h, dp) << "\n";
}

int main(){
#ifdef VPAL
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    for (int test = 1; test <= t; test++) {
        solve(test);
    }
    return 0;
}

Measured memory_bytes: 10368
const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function solve()
    a=0
    for i=1:int(input())
        x=split(input())
        a+=floatSub(x[1])*38e4^(x[2]=="BTC")
    end
    return a
end
function main()
    println(solve())
end
main()

Measured memory_bytes: 176212
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
#define maxn 5000010

void read(int &x){
    int f=1;x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    x*=f;
} 
struct node{
    int to;
    int nxt;
}edge[maxn];
int tot,head[maxn],maxx,vis[maxn],ans,cnt;
void add(int x,int y){edge[cnt].to=y;edge[cnt].nxt=head[x];head[x]=cnt++;}
void dfs(int now,int fa,int stp){
    tot++;
    if(stp==0) return ;
    for(int i=head[now];~i;i=edge[i].nxt){
        if(edge[i].to==fa){
            continue;
        }
        dfs(edge[i].to,now,stp-1);
    }
}
int n,k;
int main(){
    read(n),read(k);
    int u,v,del;
    for(int i=0;i<=n;i++) head[i]=-1;
    for(int i=0;i<n-1;i++){
        read(u),read(v);
        add(u,v);add(v,u);
    }
    ans=0;
    if(k%2==0){//k为偶数，枚举点，跑k/2的边 
        for(int i=1;i<=n;i++){
            tot=0;
            dfs(i,0,k/2);
            ans=max(tot,ans);
        }
    }
    else{//k为奇数，枚举边，跑k/2的点 
        for(u=1;u<=n;u++){
            for(int j=head[u];~j;j=edge[j].nxt){
                tot=0;
                int t=edge[j].to;
                dfs(t,u,k/2);
                dfs(u,t,k/2);
                ans=max(tot,ans);
            }
        }
    }
    cout<<n-ans<<endl;
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll MOD=1000000007;
int main(){
	ll n;
	cin>>n;
	int co;
	vvi dp(65,vi(3));
	dp[0][1]=dp[0][0]=1;
	rep(i,63)if(n<pow(2,i)){
		co=i-1;
		break;
	}
	rep(i,co)rep(j,3){
		int t=j*2+(1&(n>>(co-i-1)));
		if(t-2>=0)(dp[i+1][(t-2>=2?2:t-2)]+=dp[i][j])%=MOD;
		if(t-1>=0)(dp[i+1][(t-1>=2?2:t-1)]+=dp[i][j])%=MOD;
		if(t-0>=0)(dp[i+1][(t-0>=2?2:t-0)]+=dp[i][j])%=MOD;
	}
	cout<<(dp[co][0]+dp[co][1]+dp[co][2])%MOD<<endl;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(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 vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

void dfs(const vvint &g, vint &dis, int v, int p = -1) {
    for (int n_v : g[v]) {
        if (n_v == p) continue;
        dis[n_v] = dis[v] + 1;
        dfs(g,dis,n_v,v);
    }
}

int main() {
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    vvint g(n);
    rep(i,n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vint dis_u(n,inf);
    vint dis_v(n,inf);
    dis_u[u] = 0;
    dis_v[v] = 0;
    dfs(g,dis_u,u);
    dfs(g,dis_v,v);
    int ans = 0;
    rep(i,n) {
        if (dis_u[i] < dis_v[i]) {
            ans = max(ans,dis_v[i]-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12928
def resolve():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))

    A=0
    B=0
    mina=min(a)
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(i,len(a)):
            if a[j]<a[i]:
                A+=1
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(len(a)):
            if a[j]<a[i]:
                B+=1
    ans=int(((2*A+(K-1)*B)*K//2)%(10**9+7))
    print('{}'.format(ans))

resolve()

Measured memory_bytes: 3188