akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <set>
#include <stdio.h>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a;
  std::vector<std::pair<int, int>> pairs;
  for (int i = 0; i < n; i++) {
    int num;
    std::cin >> num;
    a.push_back(num);
    pairs.emplace_back(num, i);
  }

  std::sort(pairs.begin(), pairs.end());
  std::reverse(pairs.begin(), pairs.end());

  std::set<int> setted;
  std::vector<int> fr(n, 0);
  std::vector<int> sr(n, 0);
  for (int i = 0; i < n; i++) {
    int pos = pairs[i].second;
    if (setted.lower_bound(pos) == setted.end()) {
      fr[i] = n;
      sr[i] = n;
    } else {
      fr[i] = *setted.lower_bound(pos);
      if (setted.upper_bound(fr[i]) == setted.end()) {
        sr[i] = n;
      } else {
        sr[i] = *setted.upper_bound(fr[i]);
      }
    }
    setted.insert(pos);
  }

  std::set<int> setted_rev;
  std::vector<int> fl(n, 0);
  std::vector<int> sl(n, 0);
  for (int i = 0; i < n; i++) {
    int pos = n - 1 - pairs[i].second;
    if (setted_rev.lower_bound(pos) == setted_rev.end()) {
      fl[i] = n;
      sl[i] = n;
    } else {
      fl[i] = *setted_rev.lower_bound(pos);
      if (setted_rev.upper_bound(fl[i]) == setted_rev.end()) {
        sl[i] = n;
      } else {
        sl[i] = *setted_rev.upper_bound(fl[i]);
      }
    }
    setted_rev.insert(pos);
  }

  /*
    for (int i = 0; i < n; i++) {
      std::cerr << fr[i] << std::endl;
    }
    for (int i = 0; i < n; i++) {
      std::cerr << sr[i] << std::endl;
    }
    */

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long pos = pairs[i].second;
    long long val = pairs[i].first;
    ans += (sl[i] - fl[i]) * (fr[i] - pos) * val;
    ans += (sr[i] - fr[i]) * (fl[i] - (n - 1 - pos)) * val;
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 12400
#include<bits/stdc++.h>
using namespace std;
int n;
double x,ans;
string s;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>s;
        if(s=="JPY")ans+=x;
        else ans+=x*380000;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void) {
    string s;cin>>s;
    if(s=="Sunny")cout<<"Cloudy"<<endl;
    if(s=="Cloudy")cout<<"Rainy"<<endl;
    if(s=="Rainy")cout<<"Sunny"<<endl;
} 

Measured memory_bytes: 256
N=int(input())
m=45
for a in range(1,N):
    b=a//100000
    c=(a-b*100000)//10000
    d=(a-b*100000-c*10000)//1000
    e=(a-b*100000-c*10000-d*1000)//100
    f=(a-b*100000-c*10000-d*1000-e*100)//10
    g=a-b*100000-c*10000-d*1000-e*100-f*10
    h=(N-a)//100000
    i=(N-a-h*100000)//10000
    j=(N-a-h*100000-i*10000)//1000
    k=(N-a-h*100000-i*10000-j*1000)//100
    l=(N-a-h*100000-i*10000-j*1000-k*100)//10
    n=N-a-h*100000-i*10000-j*1000-k*100-l*10
    m=min(m,b+c+d+e+f+g+h+i+j+k+l+n)
    
print(m)
  

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int c[3][3];
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			cin >> c[i][j];
		}
	}
	if(c[0][0]-c[0][1]==c[1][0]-c[1][1]&&c[1][0]-c[1][1]==c[2][0]-c[2][1]
		&& c[0][2]-c[0][1]==c[1][2]-c[1][1]&&c[1][2]-c[1][1]==c[2][2]-c[2][1]
		&& c[0][0]-c[1][0]==c[0][1]-c[1][1]&&c[0][1]-c[1][1]==c[0][2]-c[1][2]
		&& c[2][0]-c[1][0]==c[2][1]-c[1][1]&&c[2][1]-c[1][1]==c[2][2]-c[1][2])
		cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<double> p(n);
  REP(i,n) cin >> p[i];
  double ans;
  double sum = 0;
  
  REP(i,n) p[i] = p[i]+1;
  
  REP(i,k) sum += p[i];
  ans = sum;
  
  REP(i,n-k){
    sum += p[i+k] - p[i];
    ans = max(ans, sum);
  }
  
  cout << fixed << setprecision(10) << ans/2;
  return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
using namespace std;
int main(){  
	string a[1];
	string b[1];
	int n=1;
	int H,D;

    
	for(int i=0;i<n;i++){

		cin>>a[i]>>b[i];
		
	}
		
    for(int i=0;i<n;i++){
    	
		if(a[i]=="H"){
			
			if(b[i]=="H"){
				cout<<"H";}
			if(b[i]=="D"){
				cout<<"D";}
		}
		if(a[i]=="D"){
			
			if(b[i]=="H"){
				cout<<"D";}
			if(b[i]=="D"){
				cout<<"H";}
		}
	}
		

}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<int,int>> k;
	for(int i = 0;i < N ;i++){
		int a,b;
		cin >> a >> b;
		k.emplace_back(b, a);
	}
	int flag; 
	sort(k.begin(),k.end());

	int f=0;
	long long t=0;
	for(int i = 0;i<N;i++){
		t += k[i].second;
		if(t > k[i].first){
			f=1;
			break;
		}
	}
	if(f==1)cout<<"No";
	else cout<<"Yes";
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int X;
    cin >> X;
    int gohyaku = X / 500;
    int go = (X - gohyaku * 500) / 5;
    cout << gohyaku * 1000 + go * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    vector<ll> s(n),t(n);
    rep(i,n){
        ll a,b;cin>>a>>b;
        s[i]=a-b;
        t[i]=a+b;
    }
    pair<ll,ll> itv[n];
    rep(i,n){
        itv[i].first=t[i];
        itv[i].second=s[i];
    }
    sort(itv,itv+n);
    ll res=0,tt=-1e+9;
    rep(i,n){
        //cout<<itv[i].first<<" "<<itv[i].second<<endl;
        //cout<<tt<<endl;
        if(tt<=itv[i].second){
            res++;
            tt=itv[i].first;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
map<pair<ll, ll>, P> mp;
const ll mod = 1000000007;

struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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

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

int main()
{
    int N;
    cin >> N;
    ll zero = 0;
    for (int i = 0; i < N; i++)
    {
        ll x, y;
        cin >> x >> y;

        if (x == 0 && y == 0)
        {
            zero++;
            continue;
        }
        // (1) 単位ベクトルに回転
        ll g = gcd(x, y);
        x /= g;
        y /= g;

        // (3) y < 0の時、180度回転
        if (y < 0)
        {
            x = -x;
            y = -y;
        }

        // (2) x = 0 or y = 0なら同様に正規化
        if (y == 0 && x < 0)
        {
            x = -x;
            y = -y;
        }

        // (4) x <= 0のとき、90度回転
        bool rot90 = false;
        if (x <= 0)
        {
            rot90 = true;
            ll tmp = y;
            y = -x;
            x = tmp;
        }

        // 同じグループに格納
        if (rot90)
        {
            mp[{x, y}].first++;
        }
        else
        {
            mp[{x, y}].second++;
        }
    }

    mint ans = 1;
    for (auto p : mp)
    {
        int s = p.second.first;
        int t = p.second.second;

        ll now = 1;

        now = now + modpow(2, s, mod) - 1;
        now = now + modpow(2, t, mod) - 1;

        ans = ans * now;
    }

    ans -= 1;    // 何も選ばない
    ans += zero; // x =0, y=0を選ぶ

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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_N = 1000000;
int n;
int dp[MAX_N+1];

int solve(int n)
{
  if(dp[n] >= 0) return dp[n];
  if(n & 1) return dp[n] = solve(3 * n + 1) + 1;
  else return dp[n] = solve(n / 2) + 1;
}

int main()
{
  erep(i, 0, MAX_N) dp[i] = -1;
  dp[1] = 0;
  while(~scanf(" %d", &n) && n) printf("%d\n", solve(n));

  return 0;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
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;}

int main(){
	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int cnt = 0;
	REP(i,s.size()){
		if(s[i] != t[i]) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define int long long
using namespace std;
signed main() {
  int N,A;
  cin>>N>>A;
  
  if(N%500<=A){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;}
  
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(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; }


int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m), c(m), q(2);
    map<ll,ll> num;
    rep1(i, n){
        cin >> a[i];
        if (num.count(a[i])) num[a[i]] += 1;
        else num[a[i]] = 1;
    }
    priority_queue<vector<ll>> pq;
    rep1(i, n){
        if (num.count(a[i])){
            q[0] = a[i];
            q[1] = num[a[i]];
            num.erase(a[i]);
            pq.push(q);
        }
    }
    rep1(i, m){
        cin >> b[i] >> c[i];
        q[0] = c[i];
        q[1] = b[i];
        pq.push(q);
    }
    ll ans=0, res=n, cnt;
    while (res > 0){
        q = pq.top(); pq.pop();
        ans += q[0] * min(q[1], res);
        res -= q[1];
    }
    cout << ans << endl;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    String[] inputRowAndCol = (input.readLine()).split("\\s");
    int x = Integer.parseInt(inputRowAndCol[0]);
    int y = Integer.parseInt(inputRowAndCol[1]);

 
    int[][] a = new int[x][y];
    String[] b = null; 
    
    for (int i = 0; i < x; i++) {
     
      b = (input.readLine()).split("\\s");
     
      for (int j = 0; j < y; j++) {
        
       a[i][j] = Integer.parseInt(b[j]);
      }
    }
   
    int[] vectorB = new int[y];
    for (int k = 0; k < y; k++) {
      vectorB[k] = Integer.parseInt(input.readLine());
    }

    for (int l = 0; l < x; l++) {
      int result = 0; 
    
      for (int m = 0; m < y; m++) {
       
        result += (a[l][m] * vectorB[m]);
      }
      
      System.out.println(result);
    }
  }
}


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

typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++) // no semicoron
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>0;i--)
#define FORD(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく

using namespace std;

int main(){
    ll N, X, Y;
    cin >> N >> X >> Y;

    //最短距離を求める

    ll count = 1;

    vector<int> ans (N);
    FOR(i, 0, N) ans[i] = 0;

    FOR(i, 1, N){
        FOR(j, i+1, N+1){

            if(j <= X || Y <= i){
                //cout << j-i << endl;
                ans[j - i]++;
            }
            else{
                ll mindis = min(abs(j - i), (abs(X - i) + 1 + abs(j - Y))); 
                //cout << mindis << endl;
                ans[mindis]++;              
            }

        }
    }

    FOR(i, 1, N) cout << ans[i] << endl;

    //count = 0;

    /*FOR(i, 1, N+1){
        FOR(j, i+1, N+1){
            ll mindis = min(abs(j - i), (abs(X - i) + 1 + abs(j - Y)));
            if(mindis == k) count++;
        }
    }*/

    


    //cout << count << endl;
    
        //FOR(k, k, N) cout << '0' << endl;


    

}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ll aaa = 1000000000000000;
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
struct edge { int to;ll cost; };
int V;
vector<edge> G1[100000];
ll d1[100000];
void dijkstra1(int s) {
	priority_queue<LP, vector<LP>, greater<LP>>que;
	fill(d1, d1 + V, INF);
	d1[s] = 0;
	que.push(LP(0, s));
	while (!que.empty()) {
		LP p = que.top(); que.pop();
		int v = p.second;
		if (d1[v] < p.first)continue;
		for (int i = 0; i < (int)G1[v].size(); i++) {
			edge e = G1[v][i];
			if (d1[e.to] > d1[v] + e.cost) {
				d1[e.to] = d1[v] + e.cost;
				que.push(LP(d1[e.to], e.to));
			}
		}
	}
}
ll d2[100000];
vector<edge> G2[100000];
void dijkstra2(int s) {
	priority_queue<LP, vector<LP>, greater<LP>>que;
	fill(d2, d2 + V, INF);
	d2[s] = 0;
	que.push(LP(0, s));
	while (!que.empty()) {
		LP p = que.top(); que.pop();
		int v = p.second;
		if (d2[v] < p.first)continue;
		for (int i = 0; i < (int)G2[v].size(); i++) {
			edge e = G2[v][i];
			if (d2[e.to] > d2[v] + e.cost) {
				d2[e.to] = d2[v] + e.cost;
				que.push(LP(d2[e.to], e.to));
			}
		}
	}
}
int main(){
	int n, m, s, t;
	cin >> n >> m >> s >> t; s--; t--;
	V = n;
	rep(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b; u--; v--;
		G1[u].push_back({ v,a });
		G1[v].push_back({ u,a });
		G2[u].push_back({ v,b });
		G2[v].push_back({ u,b });
	}
	dijkstra1(s); dijkstra2(t);
	ll out[100000];
	rep(i, n) {
		out[i] = d1[i] + d2[i];
	}
	for (int i = n - 2; i >= 0; i--) {
		out[i] = min(out[i], out[i + 1]);
	}
	rep(i, n) {
		cout << aaa - out[i] << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> a(3 * n);
    rep(i, 3 * n) cin >> a[i];

    sort(all(a));
    reverse(all(a));

    ll ans = 0;
    for (int i = 1; i < 2 * n; i += 2)
    {
        ans += a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

class Combination {
   public:
    Combination(int n) {
        fac = new ll[n];
        inv = new ll[n];
        finv = new ll[n];
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        REP(i, 2, n) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    ll cnr(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

   private:
    ll *fac, *inv, *finv;
};

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];
    sort(ALL(A));

    Combination comb(N + 1);
    
    ll minX = 0, maxX = 0;
    REP(i, 0, N) {
        minX += A[i] * comb.cnr(N - 1 - i, K - 1) % MOD;
        maxX += A[N - 1 - i] * comb.cnr(N - 1 - i, K - 1) % MOD;
    }

    cout << (maxX - minX) % MOD << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//

int main() {
  use_cio();
  int n;
  cin >> n;
  vector<int> va(n + 1), vb(n + 1, 0);
  rep(i, n) cin >> va[i + 1];
  int cnt = 0;

  for (int i = n; i > 0; i--) {
    for (int j = 2 * i; j <= n; j += i) va[i] ^= vb[j];
    vb[i] = va[i];
    cnt += vb[i];
  }
  cout << cnt << endl;
  rep(i, n + 1) if (vb[i]) cout << i << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
int main(){
  string A,B,C;
  cin >> A >> B >> C;
  if(A[A.length()-1] == B[0] && B[B.length()-1] == C[0]){
    cout << "YES" << endl;

  }else{
    cout << "NO" << endl;
  }
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  int a1 = h1*60 + m1;
  int a2 = h2*60 + m2;
  
  cout << a2 - a1 - k << endl;
  
  
}

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

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int V, E, x, y; cin >> V >> E;
    vector<vector<int> > G(V);
    vector<int> deg(V);
    for(int i=0;i < E; ++i) {
        cin >> x >> y;
        G[x].push_back(y);
        ++deg[y];
    }

    queue<int> que;
    for(int i=0; i < V; ++i) if(deg[i]==0) que.push(i);

    // topological sort
    while(!que.empty()) {
        int v = que.front(); que.pop();
        cout << v << '\n';
        for(int nv : G[v]) {
            --deg[nv];
            if(deg[nv] == 0) que.push(nv);
        }
    }
    return 0;
}


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int n;
	string s,j="",k="";
	cin>>s;
	n=s.size();
	n--;
	for(int i =0;i<n/2;i++){
		j+=s[i];
	}
	n+=2;
	for(int i =n/2;i<n-1;i++){
		k+=s[i];
	}
	if(k==j)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int e;
		while (true) {
			e = sc.nextInt();
			if (e == 0) break;
			int min = 10000000;
			for (int z = 0; z*z*z <= e; z++) {
				for (int y = 0; y*y <= e-z*z*z; y++) {
					min = Math.min(min, e-z*z*z-y*y+y+z);
				}
			}
			out.println(min);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 26728
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		Arrays.fill(d, -1);
		Map<Integer, Map<Integer, Integer>> l = new HashMap<>();
		Map<Integer, List<Integer>> m = new HashMap<>();
		for(int i = 0; i < N; i++) {
			m.put(i, new ArrayList<>());
			l.put(i, new HashMap<Integer, Integer>());
		}
		for(int i = 0; i < N-1; i++) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			int w = sc.nextInt() % 2;
			m.get(u).add(v);
			m.get(v).add(u);
			l.get(u).put(v, w);
			l.get(v).put(u, w);
		}
		d[0] = 0;
		Deque<Integer> q = new ArrayDeque<>();
		q.add(0);
		while(q.size() > 0) {
			int r = q.pollFirst();
			for(int p : m.get(r)) {
				if(d[p] != -1)
					continue;
				d[p] = d[r] + l.get(r).get(p);
				q.offerFirst(p);
			}
		}
		for(int i = 0; i < N; i++) {
			if(d[i] % 2 == 0)
				System.out.println(0);
			else
				System.out.println(1);
		}
	}

}

Measured memory_bytes: 150796
import sys
Row = input()
List = [int(j) for j in input().split()]
for i in range(len(List)):
    ans = List[i] % 2
    if ans == 1:
        print(0)
        sys.exit()

count = 0
flg = 0
while flg == 0:
    count = count + 1
    for j in range(len(List)):
        List[j] = List[j] / 2
        if List[j]%2:
            flg = 1
            break
print(count)


Measured memory_bytes: 3064
n,m = input().split()
n = int(n)
m = int(m)

a_list = []
b_list = []

for i in range(n):
    a,b = input().split()
    a_list.append(int(a))
    b_list.append(int(b))


price_order = sorted(range(len(a_list)), key=lambda k: a_list[k])

m_carrent = m
sum_price = 0
for p in price_order:
    if m_carrent - b_list[p] >=0:
        sum_price += b_list[p] * a_list[p]
    else:
        sum_price += m_carrent * a_list[p]
        break

    m_carrent -= b_list[p]

print(sum_price)


Measured memory_bytes: 16520
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const int MAX_X=4;
const int MAX_Y=50;

struct Event{
    int evt;
    int val;
};

int main(){
    int x,y,z,dy,dx;
    int n,e,a,bc;
    double sum;
    double dp[MAX_Y+1][MAX_Y*100+1][2];
    Event ev[MAX_Y+1];
    vector<int> v;

    while(cin>>x>>y>>z,x|y|z){

        v.clear();
        for(int i=0;i<x;i++){
            int t;
            cin>>t;
            v.push_back(t);
        }

        for(int i=0;i<=MAX_Y;i++){
            ev[i].evt=ev[i].val=0;
        }

        bc=0;
        for(int i=0;i<z;i++){
            cin>>n>>e>>a;
            ev[n].evt=e;
            ev[n].val=(e==3 ? -a : a);
            if(e==2) bc+=ev[n].val;
        }

        for(int i=0;i<=MAX_Y;i++){
            for(int j=0;j<=MAX_Y*100;j++){
                dp[i][j][0]=dp[i][j][1]=0.0;
            }
        }

        dp[0][0][0]=1.0;

        for(int i=0;i<y;i++){
            for(int j=0;j<=bc;j++){
               if(ev[i].evt==1){
                    dy=(i+ev[i].val<=y ? i+ev[i].val : y);
                    dp[dy][j][1] += dp[i][j][0];
                }
                for(auto vi:v){
                    dy=(i+vi<=y ? i+vi : y);
                    if(ev[dy].evt>=2 && j+ev[dy].val<=bc){
                        dx=(j+ev[dy].val>=0 ? j+ev[dy].val : 0);
                        dp[dy][dx][0] += (ev[i].evt==1 ? (dp[i][j][1]) : (dp[i][j][0]+dp[i][j][1]))/x;
                    }else if(ev[dy].evt<2){
                        dp[dy][j][0] += (ev[i].evt==1 ? (dp[i][j][1]) : (dp[i][j][0]+dp[i][j][1]))/x;
                    }
                }
            }
        }

        sum=0.0;

        for(int i=0;i<=bc;i++){
            sum += (dp[y][i][0]+dp[y][i][1])*i;
        }

        cout<<floor(sum)<<endl;
    }

    return 0;
}

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

const int IMAX = pow(2.0,31.0)-1;

#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b

void strInit(char str[]);//str[]を0で初期化
void extIntStr(char str[],int data[]);//str[]から数値(int)を抽出しdata[]に順次格納
void incsort(int data[],int len);//data[]を昇順ソート
void decsort(int data[],int len);//data[]を降順ソート
void printIntArray(int data[],int len);//data[]をprint
int* inputArray(int n);//文字列を受け取り数値を抽出、n個の数値(int)を格納した配列のポインタをreturn
int* cpyArray(int data[],int len);//配列(int)を複製した配列のポインタをreturn

//don't forget free(data);

int main(){
    int n,k;
    scanf("%d %d ",&n,&k);
    int *data = inputArray(n);
    int dp[100010];
    int h[100010];
    for(int i=0;i<100010;i++){
        dp[i]=IMAX;
    }
    for(int i=0;i<n;i++)h[i]=data[i];
    dp[0]=0;
    for(int i=0;i<100010;i++){
        for(int j = 1;j<=k;j++){
            if(i+j>100010)break;
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    printf("%d",dp[n-1]);
    free(data);
    return 0;
}

//temp##############################################

void strInit(char str[]){
    int len=strlen(str);
    for(int i=0;i<len;i++){
        str[i]=0;
    }
}

void extIntStr(char str[],int data[]){
    int length=strlen(str);
    str[length-1]=' ';
    char buff[12];
    int j,index;
    index=j=0;
    for(int i=0;i<length;i++){
        if(str[i]!=' '){
            buff[j++]=str[i];
        }else{
            data[index++]=atoi(buff);
            strInit(buff);
            j=0;
        }
    }
}

void incsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]>data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void decsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]<data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void printIntArray(int data[],int len){
    for(int i=0;i<len;i++){
        printf("%d\n",data[i]);
    }
}

int* inputArray(int n){
    int *data;
    data=(int*)malloc(sizeof(int)*n);
    char *get;
    get=(char*)malloc(sizeof(char)*11*n+1);
    fgets(get,11*n+1,stdin);
    extIntStr(get,data);
    free(get);
    return data;
}

int* cpyArray(int data[],int len){
    int *cp;
    cp=(int*)malloc(sizeof(int)*len);
    for(int i=0;i<len;i++){
        cp[i]=data[i];
    }
    return cp;
}

//temp##############################################


Measured memory_bytes: 1340
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const int nmax = 1e5;

int main(){
    int n;
    cin >> n;
    vector<lli> a(nmax+1, 0);
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }

    int ans = 0;
    for(int i=1; i<=nmax && n>=3; i++){
        while(a[i]>=3){
            a[i]-=2;
        }
        if(a[i] > 1){
            bool del = false;
            a[i]--;
            for(int j=i+1; j<=nmax; j++){
                if(a[j]>1){
                    a[j]--;
                    del = true;
                    break;
                }
            }
            if(!del){
                ans = -1;
                break;
            }
        }
    }

    for(int i=1; i<=nmax; i++){
        if(a[i]==1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())

A= list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

ans=sum(B)

for i in range(n-1):
	if A[i]+1==A[i+1]:
		ans+=C[A[i]-1]

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

const int N = 15;
int main()
{
	int n, s[N] = {0}, h[N] = {0}, c[N] = {0}, d[N] = {0};
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		char k;
		int p;
		scanf(" %c %d", &k, &p);
		if(k == 'S')
		{
			s[p]++;
		}
		else if(k == 'H')
		{
			h[p]++;
		}
		else if(k == 'C')
		{
			c[p]++;
		}
		else
		{
			d[p]++;
		}

	}
		for(int i = 1; i<= 13; i++)
	{
		if(s[i] == 0)
		{
			printf("S %d\n", i);
		}
	}
	for(int i = 1; i<= 13; i++)
	{
		if(h[i] == 0)
		{
			printf("H %d\n", i);
		}
	}
	for(int i = 1; i<= 13; i++)
	{
		if(c[i] == 0)
		{
		printf("C %d\n", i);
		}
	}
	for(int i = 1; i<= 13; i++)
	{
		if(d[i] == 0)
		{
			printf("D %d\n", i);
		}
	}
}


Measured memory_bytes: 2684
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    string S, X, Y;
    cin >> N >> S;
    int m = S.size();
    int c1[26], c2[26];
    memset(c1, 0, sizeof(c1));
    memset(c2, 0, sizeof(c2));
    REP(i, m) {
        c2[S[i] - 'a']++;
    }
    int res = 0;
    FOR(i, 0, m - 1, 1) {
        c2[S[i] - 'a']--;
        c1[S[i] - 'a']++;
        int cnt = 0;
        REP(j, 26) {
            if (c1[j] > 0 && c2[j] > 0) {
                cnt++;
            }
        }
        amax(res, cnt);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String c = sc.next();
    int answer = 0;
    int[] sumR = new int[n];
    sumR[0] = (c.charAt(0) == 'R') ? 1 : 0;
    for(int i = 1; i < n; i++){
      sumR[i] = sumR[i - 1];
      if(c.charAt(i) == 'R') sumR[i]++;
    }
    int cntR = sumR[n -1];
    int cntW = n - cntR;
    answer = Math.min(cntR, cntW);
    if(answer == 0){
      System.out.println(0);
      return;
    }
    System.out.println(Math.min(cntR - sumR[cntR - 1], answer));
  }
}


Measured memory_bytes: 41148
n,m=map(int,input().split())
arr1=[[i for i in input()] for _ in range(n)]
arr2=[[i for i in input()] for _ in range(m)]
count=0
for i in range(n-m+1):
  for j in range(n-m+1):
    flag=True
    for k in range(m):
      for l in range(m):
        if arr1[i+k][j+l]!=arr2[k][l]:
          flag=False
    if flag:
      count+=1
if count>=1:
  print('Yes')
else:
  print('No')

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

int main(){

string S;
  cin >> S;

int ans = 0;
  
  for(int i = 0;i < 4;i++){
  if(S.at(i) == '+') ans++;
    else ans--;
  }

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  uint64_t n;
  cin >> n;
  if (n == 1) {
    std::cout << 0 << std::endl;
  } else if (n == 2) {
    std::cout << 1 << std::endl;
  } else {
    cout << ((((n + 1) * n) >> 1) - n) << endl;
  }
}

Measured memory_bytes: 888
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A[] = new long[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();
    }
    int answer = 100;
    int tmp =0;
    for(int i=0;i<N;i++){
      tmp=divcnt(A[i]);
      if(tmp<answer){
        answer=tmp;
      }
    }
    System.out.println(answer);
  }
  
  public static int divcnt(long n){
    int res =0;
    while(n%2==0){
      n=n/2;
      res++;
    }
    return res;
  

  }
}

Measured memory_bytes: 21844
#include <iostream>
#define N_MAX 200000
using namespace std;

int main() {
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	int L[N_MAX] = {0}, R[N_MAX] = {0};
	for (int i = 0, x = 1; x <= k; i++) {
		if (s[i] == 'x') continue;
		L[i] = x;
		x++;
		i += c;
	}
	for (int i = n-1, x = k; x >= 1; i--) {
		if (s[i] == 'x') continue;
		R[i] = x;
		x--;
		i -= c;
	}
	for (int i = 0; i < n; i++) {
		if (L[i] != 0 && L[i] == R[i]) cout << i+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}


int main()
{
    int a,b;
    cin >> a >> b;
    if (1 <= a && a <= 9 && 1 <= b && b <= 9){
        cout << a * b << endl;
    }else{
        cout << -1 << endl;
    }
}

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

int main() {
  int N, A;
  cin >> N;
  A = N % 1111;

  if (A < 10) {
    cout << "Yes" << endl;
  }
  else if (A % 1000 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let n = read_one::<String>().chars().collect::<Vec<char>>();
    if n[0] == '9' || n[1] == '9' { println!("Yes"); }
    else { println!("No"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
S = list(input())
if S == ['>'] or S == ['<']:
    print(1)
    exit()
l = []
if S[0] == '>':
    l.append(0)
    p = '>'
else:
    p = '<'
c = 1
for i in range(1, len(S)):
    if S[i] == p:
        c += 1
    else:
        l.append(c)
        c = 1
        p = S[i]
if c != 0:
    l.append(c)
if S[-1] == '<':
    l.append(0)
ans = 0


def calc(x):
    return (1 + x) * x // 2


for i in range(0, len(l), 2):
    ans += calc(l[i]) + calc(l[i + 1]) - min(l[i], l[i + 1])
print(ans)


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

int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	cout << (e-a<=k ? "Yay!" : ":(") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0)
const double Pi=3.14159265;
const int N=1e4+5;
const ull base=163;
const int INF=0x3f3f3f3f;
using namespace std;
int path[600][600];
int ans[600][600];
bool vis[600][600];
int n,m,q;
int dfs(int l,int r){

    if(l>r)return 0;
    if(vis[l][r])return ans[l][r];
    vis[l][r]=1;
    return ans[l][r]+=dfs(l+1,r)+dfs(l,r-1)-dfs(l+1,r-1);
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1,u,v;i<=m;++i){
        scanf("%d%d",&u,&v);
        ans[u][v]++;
    }
    dfs(1,n);
    for(int i=1,u,v;i<=q;++i){
        scanf("%d%d",&u,&v);
        printf("%d\n",ans[u][v]);
    }
    return 0;
}

Measured memory_bytes: 2432
using System;
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            n = int.Parse(Console.ReadLine());
            double a = n / 2 + 1;
            double b = n + 0;
            double c = n / 2;
            
            if (n % 2 == 1)
                Console.WriteLine(a / b);
            else
                Console.WriteLine(c / b);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
n,x =map(int, input().split())

m_list = []
for i in range(n):
  m_list.append(int(input()))
m_list = sorted(m_list)
remain_x = x - sum(m_list)

cnt_list = []
for i in m_list:
  if remain_x >= i:
    cnt = remain_x // i
    cnt_list.append(cnt)
    remain_x = remain_x % (i *cnt)
  else:
    break

print(n + sum(cnt_list))

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<double> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i + 1][j] += dp[i][j] * (1 - P[i]);
      dp[i + 1][j + 1] += dp[i][j] * P[i];
    }
  }
  double res = 0;
  for (int i = N / 2 + 1; i < N + 1; i++) {
    res += dp[N][i];
  }
  cout << fixed << setprecision(10) << res << '\n';
  return 0;
}


Measured memory_bytes: 70784
N,A,B = map(int,input().split())
S = str(input())

Ap = 0
Bp = 0
n = 0

while True:
    if S[n]=='a':
        if (Ap+Bp) < (A+B):
            print('Yes')
            Ap = Ap + 1
        else:
            print('No')
    if S[n]=='b':
        if ((Ap+Bp) < (A+B)) and Bp < B:
            print('Yes')
            Bp = Bp + 1
        else:
            print('No')
    if S[n]=='c':
        print ('No')
    n = n + 1
    
    if n == N:
        break

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

int main(){
  long long int H,ans;
  cin>>H;
  ans = 0;
  long long int limit = 0;
  if(pow(2,log2(H))==H){limit = log2(H);}
  else{limit = log2(H);}
  for(long long int i=0;i<=limit;i++){
    ans+=pow(2,i);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 12+5;
const int M = 1e3+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, m;
int a[M], b[M], c[M][N];
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> m;
	for(int i=1; i<=m; i++){
		cin >> a[i] >> b[i];
		for(int j=1; j<=b[i]; j++) {
			cin >> c[i][j];
		}
	}
	vector<int> dp(5000, INF);
	dp[0] = 0;
	for(int i=1; i<=m; i++){
		int now = 0;
		for(int j=1; j<=b[i]; j++){
			now |= 1 << (c[i][j]-1);
		}
		for(int bits=0; bits<(1<<n); bits++){
			dp[bits|now] = min(dp[bits|now], dp[bits] + a[i]);
		}
	}
	int ans = dp[(1<<n)-1];
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
k=0
a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0]
while k<14 :
    a[k],a[k+1]=input().split()
    k=k+2

i=0
while i<14 : 
    w=int(a[i])-int(a[i+1])
    print(w)
    i=i+2


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3556
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;

int main(){
    int N,M,ans=0;
    cin >> N >> M;
    ans=1900*M+(100*(N-M));
    ans=ans*pow(2,M);
    cout << ans << endl;
	}

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

class Program {
    static void Main(string[] args) {
        int n = Cin.Ni();
        int maxNum = 1;
        while (maxNum * 2 <= n) {
            maxNum *= 2;
        }
        Console.WriteLine(maxNum);
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


Measured memory_bytes: 11092
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int h, w;
	int i, j;
	char a[101][101] = {0};
	int rm_w[101] = {0};

	fgets(str, 100, stdin);
	sscanf(str, "%d %d\n", &h, &w);

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			scanf("%c ", &a[i][j]);
		}
	}

	for (j = 0; j < w; j++) {
		for (i = 0; i < h; i++) {
			if (a[i][j] == '#') {
				break;
			}
		}

		if (i == h) {
			rm_w[j] = 1;
		}
	}

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				break;
			}
		}

		if (j == w) {
			continue;
		}

		for (j = 0; j < w; j++) {
			if (rm_w[j] == 0) {
				printf("%c", a[i][j]);
			}
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,m,a,b,dp[3001][3001],ans,L,rans;
vector<P> v;
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        v.push_back({a,b});
        sort(v.begin(),v.end());
    }
    rans=v[0].second;
    for(int i=0;i<n-1;i++){
        a=v[i].first;
        b=v[i].second;
        ans=0;
        for(int j=0;j<=m-1;j++){
            if(j-a>=0)dp[i+1][j]=max(dp[i][j],dp[i][j-a]+b);
            else dp[i+1][j]=dp[i][j];
            ans=max(ans,dp[i+1][j]);
        }
        rans=max(rans,ans+v[i+1].second);
    }
    cout<<rans<<endl;
}


Measured memory_bytes: 70656