akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

struct UnionFind{
    vector<ll> par;

    UnionFind(ll N) : par(N){
        rep(i,N){
            par[i]=i;
        }
    }

    ll root(ll x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};


int main() {
    ll V,E;
    cin >> V>>E;
    vector<tuple<ll,ll,ll>> S(E);

    rep(i,E){
        ll s,t,w;
        cin >>s>>t>>w;
        S[i] = make_tuple(w,s,t);
    }

    sort(all(S));
    UnionFind tree(V);
    ll ans = 0;
    rep(i,E){
        ll x = get<1>(S[i]);
        ll y = get<2>(S[i]);
        if(!tree.same(x,y)){
            tree.unite(x,y);
            ans += get<0>(S[i]);
        }
        
    }


    



    cout << ans <<endl;
    
    return 0;
    

}



Measured memory_bytes: 5260
#include<iostream>
using namespace std;
int main(){
  int n,count=0,couunt=0;
  cin>>n;
  char c[n];
  for(int i=0;i<n;i++){
    cin >> c[i];
    if(c[i]=='R') count++;
  }
  for(int i=0;i<count; i++){
    if(c[i]=='W')couunt++;
  }
  cout << couunt << endl;
}


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

int main() {
  int N;
  cin >> N;
  string s = to_string(N);
  for(int i=0;i<3;i++){
    if(s.at(i) == '7'){
      cout << "Yes" << endl;
      return(0);
    }
  }
  
  cout << "No" << endl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<vi> gr(n);
	rep(_,1,n){
		int x,y;
		cin >> x >> y;
		--x,--y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}

	function<int(int,int)> nim = [&](int v, int par){
		int val = 0;
		trav(u, gr[v]) if(par != u) val ^= nim(u, v);
		return val+1;
	};
	int val = 0;
	trav(u, gr[0]) val ^= nim(u, 0);
	cout << (val==0 ? "Bob" : "Alice") << endl;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define ll long long
#define elif else if
#define endl "\n"
#define _  <<" "<<
#define eb(x) emplace_back(x)
#define maxelem(v) *max_element(v.begin(),v.end())
#define minelem(v) *min_element(v.begin(),v.end())
#define FOR(a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

const int mod = 1e9+7;

void izlaz(string br)
{
  if(!br.size())
    exit(EXIT_SUCCESS);
  cout<<br;
  exit(EXIT_SUCCESS);

}

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

  ll n,i,ans=0;
  cin>>n;
  vector<ll> a(n);
  for(i=0;i<n;i++)
    cin>>a[i];

  for(i=1;i<n;i++)
  {
      if(a[i]<a[i-1])
      {
        ans+=a[i-1]-a[i];
        a[i]=a[i-1];

      }

  }
  cout<<ans;
 return 0;
}


Measured memory_bytes: 4776
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 200005
  #define INF 1000000000000
  #define eps 1e-6

  vector<int> v;
  int k;
  int dp[1000][1000][2];
 int call(int pos,int cnt,int f)
 {
  if(pos == v.size())
  {
    if(cnt == k) return 1;
    return 0;
  }

  if(dp[pos][cnt][f] != -1)return dp[pos][cnt][f];

  int res = 0;

  int limit;
  if(f == 1)
  {
    limit = 9;
  }
  else
  {
    limit = v[pos];
  }

  int ans = 0;

  for(int i = 0 ; i <= limit; i++)
  {
    int ncnt = cnt;
    if(i != 0)ncnt++;
    int nf = f;
    if(i < v[pos])nf = 1;
    ans += call(pos+1,ncnt,nf);
  }
  return dp[pos][cnt][f] = ans;
 }
 int solve(string s)
 {
  v.clear();

  for(int i = 0; i< s.length(); i++)
  {
    v.PB(s[i] - '0');
  }
 

  memset(dp,-1,sizeof(dp));
  int res = call(0,0,0);
  return res;
 }


int32_t main()
{


    string s;
    cin >> s >> k;

    cout << solve(s) << endl; 


    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for (int i = s.size() - 2; i > 0; --i)
    {
        if (i % 2)
        {
            bool good = true;
            for (int j = 0; j <= i / 2; ++j)
                if (s[j] != s[i / 2 + j + 1])
                    good = false;
            
            if (good)
            {
                cout << i + 1;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int mod=10e8+7;

int getmax(int n,int ar[])
{

    vector<int>dp(n,INT_MAX);
  
    int i,j,res,ans1,ans2,ans3;
      dp[0]=0;
      dp[1]=abs(ar[1]-ar[0]);
   
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<=i+2;j++)
        if(j<n)
        dp[j]=min(dp[j],dp[i]+abs(ar[j]-ar[i]));
    }
  
    return dp[n-1];

    

}
int main()
{
    int T,n,sum;
    
    
   
        cin>>n;
        int ar[n];
        for(int i=0;i<n;i++)
        cin>>ar[i];
        cout<<getmax(n,ar)<<"\n";
    
}

Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

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

	vector<int> L(N);
	REP(i, N) cin >> L[i];
	sort(L.begin(), L.end());

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < i; ++j) {
			for (int k = 0; k < j; ++k) {
				if (L[i] == L[j] | L[j] == L[k] | L[k] == L[i]) continue;
				if (L[j] + L[k] > L[i]) ++ans;
			}
		}
	}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int H,W,D;
  cin>>H>>W>>D;

  vector<tuple<int, int, int>> tp;//num x y

  int A[H][W];
  rep(i,H){
    rep(j,W){
      cin>>A[i][j];
      --A[i][j];
      tp.emplace_back(A[i][j],i,j);
    }
  }

  SORT(tp);

  ll rwa[H*W];

  rep(i,H*W){
    if(i<D){
      rwa[i]=0;
    }
    else{
      rwa[i]=rwa[i-D]+abs(get<1>(tp[i])-get<1>(tp[i-D]))+abs(get<2>(tp[i])-get<2>(tp[i-D]));
    }
  }

  int Q;
  cin>>Q;

  rep(i,Q){
    int l,r; cin>>l>>r;
    --l; --r;
    cout<< rwa[r]-rwa[l]<<"\n";
  }

}

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


Measured memory_bytes: 3316
def solve(a):
	if type(a[0]) is int:
		a = [a[i]/2+1 for i in range(len(a))]
		return sum(sorted(a)[:len(a)/2+1])
	else:
		return sum(sorted(solve(a[i]) for i in range(len(a)))[:len(a)/2+1])
for i in range(input()):
	A = eval(raw_input().replace("][","],["))
	print solve(A)
	

Measured memory_bytes: 9424
// C - Sugar Water

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

const int MAX = 4000;
bool dp[MAX][MAX]; // dp[a][b]: 水i(g), 砂糖j(g)の組み合わせがあれば1

int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	dp[0][0] = 1;

	for (int a=0; a<=F; a++) {
		for (int b=0; b<=F; b++) {
			if (dp[a][b] == 0) continue;

			if (a + 100*A + b <= F) {
				dp[a + 100*A][b] = 1;
			}

			if (a + 100*B + b <= F) {
				dp[a + 100*B][b] = 1;
			}

			if ((b + C) * (100 + E) <= E * (a + (b + C)) && a + (b + C) <= F) {
				dp[a][b+C] = 1;
			}

			if ((b + D) * (100 + E) <= E * (a + (b + D)) && a + (b + D) <= F) {
				dp[a][b+D] = 1;
			}
		}
	}

	int w = 100*A, s = 0;
	for (int a=0; a<=F; a++) {
		for (int b=0; b<=F; b++) {
			if (dp[a][b] == 0) continue;

			if (b * (w + s) > s * (a + b)) {
				w = a;
				s = b;
			}
		}
	}

	cout << w + s << " " << s << endl;

	return 0;
}

Measured memory_bytes: 10496
#include<stdio.h>
int main(void)
{
    int n,i,k,p,s;
	scanf("%d",&n);
	for (i=0;i<n;i++){
	    scanf("%d %d",&k,&p);
		s=k%p;
		if (s==0){
		    printf("%d\n",p);
		}
		
		else if (p>=k){
		    printf("%d\n",k);
		}
		else if (k>=p){
		    printf("%d\n",s);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define vl vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：割り当て
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_4_D
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----
const ll N_MAX = 100000 + 10;

// グローバル変数（入力）
ll n, k, w[N_MAX];

bool ok(ll P) {
  // 最大積載量Pのトラックに順に積み込んだ時必要台数がk以内でおさまるか
  vl truck(k, 0);
  ll CT = 0; // CurrentTruck
  rep(i, n) {
    if (w[i] > P) { return false; }
    if (truck[CT] + w[i] > P) { CT++; }
    if (CT >= k) { return false; }
    truck[CT] += w[i];
  }
  return true;
}

void solve() {
  ll l = 0, h = LONG_LONG_MAX;
  while (l + 1 < h) {
    // ループ不変条件：lでは積めない，hで積める
    ll m = (l + h) / 2;
    if (ok(m)) {
      h = m;
    } else {
      l = m;
    }
  }
  cout << h << endl;
}

int main() {
  cin >> n >> k;
  rep(i, n) { cin >> w[i]; }
  solve();
  return 0;
}



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

void show(int **L,int N,int *ln){
	for(int i=0;i<N;i++){
		for(int j=0;j<ln[i];j++){
			printf("%d ",L[i][j]);
		}printf("\n");
	}printf("\n");
}

void calc(int N,int M,int *lane,int *number){
	int **list;
	int *lane_number;
	int min;

	list=(int**)malloc(N*sizeof(int*));
	lane_number=(int*)malloc(N*sizeof(int));
	for(int i=0;i<N;i++){
		lane_number[i]=0;
		list[i]=(int*)malloc(M*sizeof(int));
		for(int j=0;j<M;j++){
			list[i][j]=-1;
		}
	}

	for(int i=0;i<M;i++){
		switch(lane[i]){
		case 0:
			printf("%d\n",list[number[i]-1][0]);
			for(int j=0;j<lane_number[number[i]-1];j++){
				list[number[i]-1][j]=list[number[i]-1][j+1];
			}
			lane_number[number[i]-1]--;
			break;
		case 1:
			min=0;
			for(int j=1;j<N;j++){
				if(lane_number[min] > lane_number[j]){
					min=j;
				}
			}
			list[min][lane_number[min]]=number[i];
			lane_number[min]++;
			break;
		}
	}
}

int main(void){
	int N,M;
	int *lane,*number;

	scanf("%d %d",&N,&M);
	lane=(int*)malloc(M*sizeof(int));
	number=(int*)malloc(M*sizeof(int));
	for(int i=0;i<M;i++){
		scanf("%d %d",&lane[i],&number[i]);
	}

	calc(N,M,lane,number);

    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {

	int a, b;
	cin >> a >> b;

	cout << (a + b) % 24 << endl;

	return 0;
}


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

int main() {
    vector<int> vec(3);
    rep(i, 3) cin >> vec[i];
    sort(vec.begin(), vec.end());
    if (vec[0] == 5 && vec[1] == 5 & vec[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import collections

n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
q=collections.deque()
q.append(1)
check=[0]*(n+1)
check[1]=1
ans=[0]*(n+1)
while len(q)!=0:
  v=q.popleft()
  for u in g[v]:
    if check[u]==0:
      check[u]=1
      ans[u]=v
      q.append(u)
print('Yes')
for i in range(2,n+1):
  print(ans[i])

Measured memory_bytes: 34756
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (a, b) = i.read2::<usize, usize>();
    let r = if a <= 8 && b <= 8 { "Yay!" } else { ":(" };

    writeln!(o, "{}", r).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        {$f:ident($($v:ident: $t:ident),*)} => {
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                $(
                    let $v = i.next().unwrap().parse().ok().unwrap();
                )*
                ($($v),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(v1: T1, v2: T2) }
    }
}


Measured memory_bytes: 4352
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	x = readline() |> parseInt
	y = x%100
	f = 0
	for b in 0:50
		for c in 0:33
			for d in 0:25
				for e in 0:20
					if (2*b+3*c+4*d+5*e)%100<=y
						v = 102*b+103*c+104*d+105*e+(y-((2*b+3*c+4*d+5*e)%100))*101
						if v<=x&&(x-v)%100==0
							f = 1
							break
						end
					end
				end
			end
		end
	end
	println(f)
end

main()

Measured memory_bytes: 128508
a=int(input())
b=input()
sum=0
for i in range(a-2):
	if b[i:i+1] == "A":
		if b[i+1:i+2] == "B":
			if b[i+2:i+3] == "C":
				sum+=1
			pass
		pass
	pass
print(sum)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;
int bubbleSort(int a[], int n){
    int s = 0;
    int j = 0;
    for (int i = 0; i < n; i++){
        for (int j = n-1; j > 0; j--){
            if (a[j] < a[j-1]){
                swap(a[j], a[j-1]);
                s++;
            }
        }
    }
    for (int i = 0; i < n; i++){
        if (i != n-1)
            cout << a[i] << " ";
        else
            cout << a[i] << endl;
    }
    cout << s << endl;
}
int main()
{
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    bubbleSort(a,n);
    return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
using namespace std;

int h, w;
int c[50][50];

int stuck()
{
    int x = 0, y = 0;
    int len = 1;
    queue<int> qx, qy, q;
    qx.push(x);
    qy.push(y);
    q.push(len);
    int canVisit[50][50];
    for (int i = 0; i < h; i++) {
        for (int k = 0; k < w; k++) {
            canVisit[i][k] = c[i][k];
        }
    }
    while (!qx.empty()) {
        x = qx.front();
        y = qy.front();
        len = q.front();
        qx.pop();
        qy.pop();
        q.pop();
        if (x == h - 1 && y == w - 1)
            return len;

        len++;
        if (x < h - 1 && canVisit[x + 1][y]) {
            qx.push(x + 1);
            qy.push(y);
            q.push(len);
            canVisit[x + 1][y] = 0;
        }
        if (y < w - 1 && canVisit[x][y + 1]) {
            qx.push(x);
            qy.push(y + 1);
            q.push(len);
            canVisit[x][y + 1] = 0;
        }
        if (x > 0 && canVisit[x - 1][y]) {
            qx.push(x - 1);
            qy.push(y);
            q.push(len);
            canVisit[x - 1][y] = 0;
        }
        if (y > 0 && canVisit[x][y - 1]) {
            qx.push(x);
            qy.push(y - 1);
            q.push(len);
            canVisit[x][y - 1] = 0;
        }
    }
    return -1;
}

int main()
{
    int cnt = 0;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int k = 0; k < w; k++) {
            char sign;
            cin >> sign;
            if (sign == '.') {
                c[i][k] = 1;
            } else {
                c[i][k] = 0;
                cnt++;
            }
        }
    }
    int len = stuck();
    if (len < 0) {
        cout << -1 << endl;
    } else {
        cout << h * w - len - cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws java.lang.Exception
    {		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n =Integer.parseInt(br.readLine()),a[]=new int[n];
		StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0; i<n; i++) a[i]=Integer.parseInt(st.nextToken());
		long sum=0;
		for(int i=1; i<n; i++) {
			if(a[i]<a[i-1]) {
				sum+=(a[i-1]-a[i]);
				a[i]=a[i-1];
			}
		}
		System.out.println(sum);
	}

}


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

int main(){
  int N, L;
  cin >> N >> L;
  int eatApple = N + abs(L);
  int sum = 0;
  for(int i = 1; i < N + 1; i++){
    sum += L + i - 1;
//    cout << "sum = " << sum << endl;
    if(abs(eatApple) > abs(L + i - 1)) eatApple = L  + i - 1;
//    cout << "eatApple = " << eatApple << endl;
  }
  cout << sum - eatApple << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<double> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v[i];
    }
    for (int i = N - 1; i >= 1; i--)
    {
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        v[i-1] = (double)(v[i]+v[i-1])/2.0;
        v.pop_back();
    }
    cout << fixed << setprecision(6);
    cout << v[0] << endl;
}

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

int main() {
    string s;
    cin>>s;
    int a=stoi(s.substr(0,2));
    int b=stoi(s.substr(2));
    int yymm=1;
    int mmyy=1;
    if (a==0||a>12)
        mmyy=0;
    if (b==0||b>12)
        yymm=0;
    if (yymm&&mmyy)
        puts("AMBIGUOUS");
    else if (yymm)
        puts("YYMM");
    else if (mmyy)
        puts("MMYY");
    else
        puts("NA");
    return 0;
}

Measured memory_bytes: 256
n = input()
i = int(n)
cnt = 0
ans = 0
while i >= 1:
  i = int(i) / 10
  cnt = int(cnt) + 1
if int(cnt) % 2 == 0:
  i = cnt / 2
  if i == 3:
      ans = 90000 + 900 + 9
  elif i == 2:
      ans = 900 + 9
  else :
      ans = 9
else :
  i = (int(cnt) / 2) + 1
  if i >= 3:
    ans = 9 + 900 + (int(n) - 10000) + 1
  elif i >= 2:
    ans = 9 + (int(n) - 100) + 1
  else :
    ans = int(n)
print(ans)

Measured memory_bytes: 3064
// A - Weather Prediction

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

		String S = sc.next();


		String[] ch = S.split("");
		for(int i=0;i < ch.length;i++){
			boolean isEven = i%2 == 0;
			String s = ch[i];
			if(isEven && (s.equals("R") || s.equals("U") || s.equals("D"))){
				
			}else if(!isEven && (s.equals("L") || s.equals("U") || s.equals("D"))){
				
			}else{
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
		
	}
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long 
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int a[114514];
signed main() {
	int n, k, cnt, inf = 1e9;
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	for (int i = 0; i <= n - k; i++) {
		if (a[i] <= 0 && a[i + k - 1] >= 0)cnt = abs(a[i]) + a[i + k - 1]+min(abs(a[i]),a[i+k-1]);
		else if(a[i]<=0&&a[i+k-1]<=0)cnt = abs(a[i]);
		else cnt = a[i + k - 1];
		if (cnt < inf)inf = cnt;
	}
	cout << inf << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
if(n%2 != 0):
  print("No")
else:
  flag = 0
  for i in range(n//2):
    if(s[i]!=s[i+n//2]):
      flag = 1
      break
  if(flag):
    print("No")
  else:
    print("Yes")

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

#define int long long
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define printarr(arr, n) for(int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl;
#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define debug(x) cout << "#debug " << x << endl;
#define print2D(arr, n) cout << "\n_____________________\n";  for(int i = 1; i  <= n; i++){	for(int j = 1; j <= n; j++){cout << arr[i][j] << " ";}cout << endl;}cout << "\n_____________________\n";
#define mii map<int,int>
#define printmap(mm) for(map<int,int>::iterator itr = mm.begin(); itr!=mm.end(); itr++) cout << itr->first << "->" << itr->second << " "; cout << endl;
#define iterm(mm) for(map<int,int>::iterator itr = mm.begin(); itr!=mm.end(); itr++)
#define NO cout << "NO"; return 0;
#define MO 1000000007
#define N 100100
#define MX 2000000000

void preprocess(){
	
}

signed main(){
	FAST_IO;
	#ifndef ONLINE_JUDGE
	//freopen("/home/divakar/programs/input.txt","r",stdin);
	//freopen("/home/divakar/programs/output.txt","w",stdout);
	#endif
	clock_t clk = clock();

	preprocess();
	int t=1;
	//cout << " dsf ";
	//cin >> t; 
	while(t--){

		int n, k;
		cin >> n >> k;
		int w[n], v[n];
		for (int i = 0; i < n; ++i)
		{
			cin >> w[i] >> v[i];
		}

		int dp[N];
		memset(dp, INT_MAX, sizeof(dp));

		for (int i = 0; i < N; ++i)
		{
			dp[i] = INT_MAX;
		}
		dp[0] = 0;
		//printarr(dp, N);

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

			for (int j = N-1; j >= v[i]; --j)
			{
				dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
			}


		}

		for (int i = N-1; i >= 0; --i)
		{
			if(dp[i]<=k){
				cout << i << endl;
				break;
			}
		}


        
		//cout << "ENDOFTEST "<< t << "\n";
	}









	#ifndef ONLINE_JUDGE
	clk = clock() - clk;
	//cout << "Time Elapsed: " << fixed << setprecision(10) << ((long double)clk)/CLOCKS_PER_SEC << "\n";
	#endif
	return 0;
}






















Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <queue>
#include <climits>
using namespace std;
typedef long long int ll;

int main()
{
    int arr[5];
    int a=-1;
    for(int i=0;i<5;i++)
    {
        cin>>arr[i];
        if(arr[i]==0)
        a=i+1;
    }
    cout<<a;
}

Measured memory_bytes: 3632
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
char a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b;
    int c=a-'0';
    int d=b-'0';
    string s1="";
    string s2="";
    for(int i=0;i<c;i++){
        s1+=b;
    }
    for(int i=0;i<d;i++){
        s2+=a;
    }
    vector<string> s;
    s.push_back(s1);
    s.push_back(s2);
    sort(ALL(s));
    cout<<s[0]<<"\n";
}



Measured memory_bytes: 256
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        t = []
        for row in s:
            t.append(row[:])
        for p in range(h):
            if (i >> p) & 1:
                for a in range(w):
                    t[p][a] = '.'
        for p in range(w):
            if (j >> p) & 1:
                for a in range(h):
                    t[a][p] = '.'
        res = 0
        for row in t:
            res += row.count('#')
        if res == k:
            ans += 1
print(ans)


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
int n,m,x,t;
int *k;
int *p;
bool checkForDigit(int n,int i){
	return (n & 1 << i);
}

int main(){
	startTime=clock();
	cin >> n >> m ;
	int b[m][n];

	FOR(i,n) FOR(j,m) b[j][i]=0;
	FOR(i,m){
		cin >> x;
		FOR(j,x){
			cin >> t;
			b[i][t-1]++;
		}
	}
	bool flag;
	p=new int [m];
	int ans=0;
	FOR(i,m) cin >> p[i];
	for(int i=0; i < (1<< n) ; i++){
		flag=true;
		FOR(j,m){
			t=0;
			FOR(k,n){
				if(b[j][k] & checkForDigit(i,k)) t++;
			}
			if((t-p[j])%2==0) ;
			else {flag=false; break;}
		}
		if(flag==true) ans++;
		
	}
	cout << ans;
	

	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll n; cin >> n;

    ll kurai1 = (n % 10);

    if (kurai1 == 2 || kurai1 == 4 || kurai1 == 5 || kurai1 == 7 || kurai1 == 9) {
        cout << "hon" << newl;
    } else if (kurai1 == 0 || kurai1 == 1 || kurai1 == 6 || kurai1 == 8) {
        cout << "pon" << newl;
    } else {
        cout << "bon" << newl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

class Use_Item{
	public:
		
		void Set_Item(string s, int num){		//zñÌY¦Æ¶ñðnµÄ °Ä­¾³¢
			Item_List[num] = s;
		}
		int cont;
		string Item_List[100];
};

int n,m,t;

//i¨Xg
vector<pair<string,int> > item;

//ÅIIÉìéACe
string make_item;

//ÀÛÌVs
Use_Item ui[100];

//VsÉ éACeXg
string list[100];

int saiki(string make_item)
{
	int total = 0;
	int kane = 0;
	bool find = false;
	
	//ACeðT·
	for(int i = 0; i < n; i++){
		if(item[i].first == make_item){
			kane = item[i].second;
		}
	}
	//VsðTµÄìéACeª é©Ç¤©ðõ
	for(int i = 0; i < m; i++){
		if(list[i] == make_item){
			find = true;
			//©Â©Á½çAVs©çACeXgÌACeðnµÄÄA
			for(int j = 0; j < m; j++){
				total += saiki(ui[i].Item_List[j]);
			}
			return min(kane, total);
		}
	}
	
	if(find == false){
		return kane;
	}
}

int main()
{
	for(;;){
		string temp, temp2;
		fill_n(list, 100, "");
		item.clear();
		
		//ACeÌÍn
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> temp;
			cin >> t;
			item.push_back(make_pair(temp,t));
		}
		
		//VsÌÍm
		cin >> m;
		
		for(int i = 0; i < m; i++){
			cin >> temp;
			cin >> t;
			
			list[i] = temp;
			ui[i].cont = t;
			for(int j = 0; j < t; j++){
				cin >> temp2;
				ui[i].Set_Item(temp2,j);
			}
		}
		cin >> make_item;
		
		
		//±±ÜÅCvbg
		
		cout << saiki(make_item) << endl;
	}
}

Measured memory_bytes: 0
card = [0] * 3
for i in range(3):
    card[i] = [int(_) for _ in input().split()] 

n = int(input())
ls = [int(input()) for _ in range(n)]

for p in range(3):
    for q in range(3):
        if card[p][q] in ls:
            card[p][q] = -1
        else:
            continue

flag = [0, 0, 0]

for j in range(3):
    if card[j] == [-1, -1, -1]:
        flag[0] = 1

for k in range(3):
    if card[0][k] == card[1][k] == card[2][k] == -1:
        flag[1] = 1

if card[0][0] == card[1][1] == card[2][2] == -1:
    flag[2] = 1

if card[0][2] == card[1][1] == card[2][0] == -1:
    flag[2] = 1

if sum(flag) == 0:
    print("No")
elif sum(flag) > 0:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d, n;
  cin >> d >> n;
  int ans;
  if(n == 100)n++;
  if(d == 0){
    ans = n;
  }else if(d == 1){
    ans = n * 100;
  }else{
    ans = n * 10000;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 998244353;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e6 + 1;
	
	
	void doIt() {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int m1, m2, len1 = M, len2 = 2 * M + 1;
		if(M % 2 == 0)len1++;
		len2 -= len1;
		m1 = len1 / 2 + 1;
		m2 = len2 / 2 + len1;
		//System.out.println(len1 + " " + len2);
		//System.out.println(m1 + " "  + m2);
		for(int i = 1; i <= len1 / 2; i++) {
			System.out.println((m1 - i) + " " + (m1 + i));
		}
		for(int i = 1; i <= len2 / 2; i++) {
			System.out.println((m2 - i + 1) + " " + (m2 + i));
		}
	}
	
	
	public static void main(String[] args) {
		new Main().doIt();
	}

}


Measured memory_bytes: 55152
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
#define ll long long
using namespace std;




int main(){
    
    string S;
    ll K;
    ll gsncho = 5 * pow(10,15);
    cin >> S >> K;
    
    /*
    ll position=1;
    for(int i=0;i<S.length();i++){
        position += pow(S[i]-'0', gsncho);
        cout << position << endl;
        if(position >= K) {
            cout << S[i] << endl;
            return 0;
        }
    }
    */
    
    for(int i=0;i<min(K,(ll)S.length());i++){
        if(S[i]!='1'){
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N,Y;
  int x = -1;
  int y = -1;
  int z = -1;
  cin >> N >> Y;
  for(int a = 0; a <= N; a++){
    for(int b = 0; b <= N; b++){
      int c = N - a - b;
      if(c >= 0){
          if(a*10000 + b*5000 + c*1000 == Y){
            x = a;
            y = b;
            z = c;
            cout << x << " " << y << " " << z << endl;
            return 0;
          }
        }
      }
    }
  cout << x << " " << y << " " << z << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 1050
typedef long long ll;
int ir,ic,grid[N][N];
ll memo[N][N];
const ll m = (ll)1e9 + 7;

bool inside(int r , int c) {
    return r >= 1 && r <= ir && c >= 1 && c <= ic;
}

ll add(ll a , ll b) {
    return ((a % m) + (b % m)) % m;
}

ll dp(int r , int c) {
    if (r == ir && c == ic) return 1;
    if (grid[r][c] == -1) return 0;
    if (!inside(r , c)) return 0;
    ll &sol = memo[r][c];
    if (sol != -1) return sol;
    return sol = add(dp(r + 1 , c) , dp(r , c + 1));
}

int main() {
    scanf("%d%d" , &ir , &ic);
    for (int r = 1 ; r <= ir ; r++) {
        char inp[N]; scanf("%s" , inp);
        for (int c = 0 ; c < strlen(inp) ; c++) {
            int keep = 0;
            if (inp[c] == '#') keep = -1;
            grid[r][c + 1] = keep;
        }
    }
    memset (memo , -1 , sizeof memo);
    printf("%lld\n" , dp(1 , 1));
}


Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int n;
int h[100000+10];
int dp[10000+10];
int cha(int x,int y)
{
    if(x>=y)    return x-y;
    else    return y-x;
    return  y-x;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)    cin>>h[i];
    dp[0]=0;
    dp[1]=cha(h[1],h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+cha(h[i],h[i-1]),dp[i-2]+cha(h[i],h[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AL {
public:
	void solve(istream& in, ostream& out) {
        int a, b, c;
        in >> a >> b >> c;
        if(a - b == b - c) out << "YES" << endl;
        else out << "NO" << endl;
	}
};

int main() {
	AL solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

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

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

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint pow(i64 r) const noexcept {
    modint ans(1);
    modint aa = *this;
    while(r) {
      if(r & 1) {
        ans *= aa;
      }
      aa *= aa;
      r >>= 1;
    }
    return ans;
  }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

template<const i64 M>
std::ostream& operator<<(std::ostream& os, const modint<M>& m) {
  os << m.value();
  return os;
}

const i64 MOD = 1e9 + 7;
using fp = modint<MOD>;

int main() {
  i64 N;
  cin >> N;
  vector<i64> C(N);
  rep(i,0,N) {
    cin >> C[i];
  }
  vector<fp> bin(N + 1);
  bin[0] = 1;
  rep(i,1,N + 1) {
    bin[i] = bin[i - 1] * fp(2);
  }
  sort(all(C));
  fp ans = 0;
  rep(i,0,N) {
    i64 n = N - i - 1;
    if(n == 0) {
      ans += fp(C[i]) * bin[N] * bin[i];
    }
    else {
      ans += fp(C[i]) * bin[N] * bin[i] * (bin[n - 1] * fp(n) + bin[n]);
    }
  }
  cout << ans.value() << endl;
}


Measured memory_bytes: 3328
a=[[int(i) for i in input().split()] for _ in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
                a[j][k]=1000
ans=False
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]==1000:
        ans=True
    elif a[0][i]==a[1][i]==a[2][i]==1000:
        ans=True
if a[0][0]==a[1][1]==a[2][2]==1000:
    ans=True
elif a[0][2]==a[1][1]==a[2][0]==1000:
    ans=True
print("Yes" if ans else "No")

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
sums = 0
count = 0
for i in range(n):
    sums = sums + a[i]
    if i % 2 ==0 :
        if sums > 0:
            None
        else:
            count = count + 1 -sums
            sums = 1
    else:
        if sums < 0:
            None
        else:
            count = count + 1 + sums
            sums = -1
            
count2 = 0
sums2 = 0
for i in range(n):
    sums2 = sums2 + a[i]
    if i % 2 ==1 :
        if sums2 > 0:
            None
        else:
            count2 = count2 + 1 -sums2
            sums2 = 1
    else:
        if sums2 < 0:
            None
        else:
            count2 = count2 + 1 + sums2
            sums2 = -1
            
print(min(count,count2))

Measured memory_bytes: 14468
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
switch =1
s = 0
ans = [0]*n
for v in a:
    s+= 2*v*switch
    switch*=-1
x=s//2
ans[-1]=x//2
for i in range(n-1,0,-1):
    need = (a[i]-ans[i])*2
    ans[i]=need
    ans[i-1]=need//2
ans[0]= x
print(*ans)

Measured memory_bytes: 14124
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 20:55:32 2020

@author: Kanaru Sato
"""

n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
hdic={}
for i in range(n):
    hdic[i] = h[i]

pl = []
for i in range(n):
    pl.append([-1])

for i in range(m):
    pair = list(map(int,input().split()))
    pl[pair[0]-1].append(pair[1])
    pl[pair[1]-1].append(pair[0])

count = 0
for i in range(n):
    Isgood = 1
    for connected in pl[i][1:]:
        if hdic[connected-1] >= hdic[i]:
            Isgood = 0
    if Isgood == 1:
        count += 1

print(count)

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

int main() {
  constexpr int kMax = 101;
  int X, N;
  std::cin >> X >> N;
  std::vector<bool> prohibited(kMax + 1);
  for (int i = 0; i < N; ++i) {
    int p;
    std::cin >> p;
    prohibited[p] = true;
  }
  int result = kMax;
  for (int i = 0; i <= kMax; ++i) {
    if (prohibited[i]) continue;
    const int current_diff = std::abs(result - X);
    const int diff = std::abs(i - X);
    if (diff < current_diff || (diff == current_diff && i < result)) {
      result = i;
    }
  }
  std::cout << result << std::endl;
  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,a[20010],b[20010],m,s=0,i,max,p[20010];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&m);
    p[m-1]=i+1;
  }
  //for(i=0;i<n;i++)printf("%d ",p[i]);printf("\n");
  for(i=0;i<n;i++){
    b[i]=s+i;
    max=MAX(max,b[i]);
    s+=p[i];
    a[i]=s+i;
  }
  for(i=0;i<n-1;i++)printf("%d ",a[i]);
  printf("%d\n%d",a[i],max+1);
  for(i=1;i<n;i++)printf(" %d",max-b[i]+1);
  printf("\n");
  return 0;
}


Measured memory_bytes: 768
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    x, y = gets.chomp.split.map(&:to_i)

    ans = 0
    ans += if x == 1
             300000
           elsif x == 2
             200000
           elsif x == 3
             100000
           else
             0
           end

    ans += if y == 1
             300000
           elsif y == 2
             200000
           elsif y == 3
             100000
           else
             0
           end

    if x == 1 && y == 1
      ans += 400000
    end

    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF=1e18;
#define PI 3.14159265358979323846
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


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

    int X;
    cin >> X;
    int ichi = X % 10;
    string result = "hon";
    if (ichi == 3) {
        result = "bon";
    } else {
        if (ichi == 0 || ichi == 1 || ichi == 6 || ichi == 8) {
            result = "pon";
        }
    }

    cout << result << '\n';

    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    double r, S, L;
    cin >> r;
    S = r*r*M_PI;
    L = 2*r*M_PI;
    
    cout <<fixed<< S << " " <<fixed<< L <<endl;
    return 0;
}


Measured memory_bytes: 3276
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_i32_vec() -> Vec<i32> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: i32 = input();
    let w_vec = input_i32_vec();
    let mut a = 0;
    let mut b = 0;
    for w in &w_vec {
        b += *w;
    }
    let mut min = b;
    for w in &w_vec {
        a += *w;
        b -= *w;
        if (a - b).abs() < min {
            min = (a - b).abs();
        }
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int x,y,a,b,c,d,ryo;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&ryo);
	x=a*ryo;
	if(c<ryo){
		y=b+(ryo-c)*d;
	}
	else{
		y=b;
	}
	if(x<y){
		printf("%d\n",x);
	}
	else{
		printf("%d\n",y);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <array>

using namespace std;

int const dir[][2] = {{1,0},{-1,0},{0,1},{0,-1}};
void clear( array<array<bool, 12>, 12>& f, int const i, int const j )
{
    if ( !f[i][j] )
        return;

    if ( i < 0 || j < 0 || i >= 12 || j >= 12 )
        return;

    f[i][j] = false;

    for( int ii=0; ii<4; ++ii ) {
        clear( f, i + dir[ii][0], j + dir[ii][1] );
    }
}

int main()
{
    for(;;) {
        array<array<bool, 12>, 12> f;
        string s;
        for( int iii=0; iii<12; ++iii ) {
            if ( !( cin >> s ) )
                return 0;

            for( int ii=0; ii<12; ++ii )
                f[iii][ii] = s[ii] == '1';
        }

        size_t sum = 0;
        for( int i=0; i<12; ++i ) {
            for( int j=0; j<12; ++j ) {
                if ( f[i][j] ) {
                    clear( f, i, j );
                    ++sum;
                }
            }
        }
        cout << sum << endl;
    }
}

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

using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll w,h; cin>>w>>h;
    if(w==1||h==1) cout<<1;
    else if(w%2==0) cout<<w*h/2;
    else if(h%2==0) cout<<w*(h/2);
    else cout<<w*(h/2)+w/2+1;
    return 0;
}

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

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

const int max_n = 101010;
int n, m;

vector<int> g[max_n];
vector<int> par;

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

	cin >> n >> m;

	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	par.resize(n, -1);
	queue<int> q;
	q.push(0);

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

		for(int x : g[p]){
			if(par[x] == -1){
				par[x] = p;
				q.push(x);
			}
		}
	}

	vector<int> ans;
	rep(i, n - 1){
		if(par[i+1] == -1){
			cout << "No" << endl;
			return 0;
		}
		ans.push_back(par[i+1] + 1);
	}

	cout << "Yes" << "\n";
	rep(i, n - 1){
		cout << ans[i] << "\n";
	}

}


Measured memory_bytes: 10944