akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <complex>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;

struct State{
    int node, prev, v;
    double t;
    State(int node, int prev, int v, double t): node(node), prev(prev), v(v), t(t) {}
    bool operator>(const State& s) const{
        return t > s.t;
    }
};

struct Edge{
    int to;
    double d;
    int c;
    Edge(int to, double d, int c): to(to), d(d), c(c) {}
};

vector<Edge> G[30];

double dist[30][30][30];
priority_queue<State, vector<State>, greater<State> > que;

void dijkstra(int start){
    fill(dist[0][0], dist[29][30], 1e5);
    dist[start][start][0] = 0.0;
    State start_state = State(start, start, 0, 0.0);
    que.push(start_state);
    
    while(!que.empty()){
        State s = que.top(); que.pop();
        if(dist[s.prev][s.node][s.v] < s.t) continue;
        for(Edge e: G[s.node]){
            if(e.to == s.prev) continue;
            for(int dv=-1;dv<=1;dv++){
                if(s.v+dv <= 0 || e.c < s.v+dv) continue;
                if(dist[s.node][e.to][s.v+dv] > dist[s.prev][s.node][s.v] + e.d/(s.v+dv)){
                    dist[s.node][e.to][s.v+dv] = dist[s.prev][s.node][s.v] + e.d/(s.v+dv);
                    que.push(State(e.to, s.node, s.v+dv, dist[s.node][e.to][s.v+dv]));
                }
            }
        }
    }
}

int main(){
    int n, m, s, g, x, y, c;
    double d;
    while(cin >> n >> m && n){
        for(int i=0;i<30;i++){
            G[i].clear();
        }
        
        cin >> s >> g;
        s--; g--;
        
        for(int i=0;i<m;i++){
            cin >> x >> y >> d >> c;
            x--; y--;
            G[x].push_back(Edge(y, d, c));
            G[y].push_back(Edge(x, d, c));
        }
        
        dijkstra(s);
        double ans = dist[0][g][1];
        for(int i=1;i<n;i++){
            ans = min(ans, dist[i][g][1]);
        }
        if(abs(ans - 1e5) < 1){
            printf("unreachable\n");
            continue;
        }
        printf("%.10lf\n", ans);
    }
}


Measured memory_bytes: 3744
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long cnt = 10000000000000000L;

		for(long i = 1; i * i <= N; i++){
			if(N % i == 0){
				long j = N / i;
				cnt = Math.min(cnt, i + j - 2);
			}
		}
		System.out.println(cnt);
		sc.close();
	}
}


Measured memory_bytes: 25044
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
    public static void main(String args[]){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line;
            HashMap<Integer, Integer> hm = new HashMap<Integer,Integer>();
            
            while((line=br.readLine())!=null){
                if(line.equals(""))break;
                String[] splited = line.split(" ");
                int m = Integer.parseInt(splited[0]);
                if(hm.containsKey(m))hm.put(m, hm.get(m)+1);
                else hm.put(m,1);
            }
            ArrayList<Integer> maxes = new ArrayList<Integer>();
            int max=0;
            for(int key:hm.keySet()){
                //System.out.println(max+"al"+Arrays.toString(maxes.toArray()));
                if(hm.get(key)<max)continue;
                if(hm.get(key)>max){max=hm.get(key);maxes.clear();}
                maxes.add(key);                    
                               // System.out.println(max+"al"+Arrays.toString(maxes.toArray()));

            }
            for(int i:maxes)System.out.println(i);
        }catch(Exception e){e.printStackTrace();}
    }
}

Measured memory_bytes: 16972
main = do
  s <- getLine
  let a:b:c:d:[] = s
  putStrLn $
    if (a /= b || a /= c || a /= d) && (
       a == b && c == d ||
       a == c && b == d ||
       a == d && b == c ) then
      "Yes"
    else
      "No"



Measured memory_bytes: 3728
#反転数(sumは1から始めるやつ)

import bisect

n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = sorted(a)

for i in range(n):
    d = bisect.bisect(c,a[i])
    b[i] = d

data = [0] * (n+1)

def init(k,x):
    while k <= n:
        data[k] += x
        k += k & -k
        
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
    
ans = 0
for i in range(n-1,-1,-1):
    init(b[i],1)
    ans += get(b[i]-1)

print(ans)


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

using namespace std;

const int N = 2005;

int cnt[N];
int pref[N];

int sum(int l, int r) {
  l = max(1, l);
  r = min(r, N - 1);
  if (l > r) return 0;
  return pref[r] - (l > 1 ? pref[l - 1] : 0);
}

int main() {
  multiset <int> ms;
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int a = arr[i], b = arr[j];
      int l = max(a - b, b - a) + 1;
      int r = a + b - 1;
      ans += sum(l, r);
      //cout << i << " " << j << " " << ans << endl;
    }
    cnt[arr[i]]++;
    pref[1] = cnt[1];
    for (int j = 2; j < N; j++) pref[j] = pref[j - 1] + cnt[j];
  }
  cout << ans << endl;
  return 0;
}


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

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

    N %= 10;

    if (N == 3) {
        cout << "bon" << endl;
    }
    else if (N == 0 || N == 1 || N == 6 || N == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
<?php
fscanf(STDIN, "%d", $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    if ($i === 0) {
        $tallest = $A[$i];
    } else {
        if ($tallest > $A[$i]) {
            $ans += $tallest - $A[$i];
        } else {
            $tallest = $A[$i];
        }
    }
}
printf("%d", $ans);


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

void input(vector<int>& rvnNum)
{
  int nSize;
  cin >> nSize;
  rvnNum.resize(nSize);

  for (int& rnElm : rvnNum)
    cin >> rnElm;
}

llong calcMinOpeTimes(const vector<int>& cnrvnNum)
{ 
  vector<llong> vnOpeTimes(2);

  for (int nEvnOdd = 0; nEvnOdd < vnOpeTimes.size(); nEvnOdd++)
  {
    llong nOpeTimes = 0;
    llong nCumlSum   = 0;
    for (int n = 0; n < cnrvnNum.size(); n++)
    {
      nCumlSum += cnrvnNum[n];
      if ( n % 2 == nEvnOdd )
        if ( nCumlSum > 0 );
        else
        {
          nOpeTimes += 1 - nCumlSum;
          nCumlSum = 1;
        }
      else
        if ( nCumlSum < 0 );
        else
        {
          nOpeTimes += nCumlSum - (-1);
          nCumlSum = -1;
        }
    }
    vnOpeTimes[nEvnOdd] = nOpeTimes;
  }
  auto itElm = min_element(begin(vnOpeTimes), end(vnOpeTimes));
  return *itElm;
}

int main()
{
  vector<int> vnNum;

  input(vnNum);
  cout << calcMinOpeTimes(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int last,x,c[200019];
ll ans;

int main() {
  int n;
  cin >> n;
  ans=1;
  last=-1;
  
  for(int i=0; i<n; i++){
    cin >> x;
    if(x==last){continue;}
    last=x;
    ans = (ans+c[x])%1000000007;
    c[x]=ans;
  }

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

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
ll n, a;
	cin >> n >> a;
	vl v(n);
	REP(i, n)cin >> v[i];
	vector<vvl> dp(n + 1, vvl(n + 1, vl(a*n + 1, 0)));
	REP(i,n+1)dp[i][0][0] = 1;
	REP(i, n) {
		REP(j, n) {
			if (i < j)break;
			REP(k, a*n + 1) {
				if (v[i] > k)dp[i + 1][j + 1][k] = dp[i][j + 1][k];
				else {
					dp[i + 1][j + 1][k] = dp[i][j][k - v[i]] + dp[i][j + 1][k];
				}
			}
		}
	}
	ll ans = 0;
	FOR(i,1, n+1) {
		ans += dp[n][i][a*i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 52224
import sys
 
 
def get_line(line_info):
    for line_pair in line_info:
        line_axis = tuple(map(int, line_pair))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        # print(p0, p1, p2, p3)
        if dot(p1 - p0, p3 - p2) == 0:
            print('1')
        elif cross(p1 - p0, p3 - p2) == 0:
            print('2')
        else:
            print('0')
    return line_info
 
 
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
 
 
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
 
 
if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    lines = map(lambda x: x.split(), _input[1:])
    ans = get_line(lines)

Measured memory_bytes: 8024
use std::io::*;
use std::str::FromStr;
use std::collections::BTreeMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let mut a: BTreeMap<u64, u64> = BTreeMap::new();

    for _ in 0..n {
        let b: u64 = read();
        match a.get_mut(&b) {
            Some(c) => { *c += 1; },
            None => { a.insert(b, 1); },
        }
    }

    let mut sum = (&a).into_iter().fold(0, |b, (c, d)| b + c * d);

    let q: usize = read();
    for _ in 0..q {
        let b: u64 = read();
        let c: u64 = read();
        let val = match a.get(&b) {
            Some(d) => d.clone(),
            None => {
                println!("{}", sum);
                continue;
            }
        };
        sum += c * val;
        sum -= b * val;
        println!("{}", sum);

        match a.get_mut(&c) {
            Some(d) => {
                *d += val;
            },
            None => {
                a.insert(c, val);
            }
        }
        a.remove(&b);
    }
}


Measured memory_bytes: 3936
def push(x):
	global stack

	stack.append(x)

def pop():
	global stack

	ret = stack.pop()
	return ret

ope = {"+": lambda a, b: b + a,
	   "-": lambda a, b: b - a,
	   "*": lambda a, b: b * a}

if __name__ == '__main__':
	stack = []

	for c in input().split():
		if c in ope:
			push(ope[c](pop(), pop()))
		else:
			push(int(c))

	print(" ".join(map(str, stack)))

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

int main()
{
	int N,j;
	vector<int> A;
	
	cin >> N;
	
	for (int i = 0; i < N; ++i) { 
		cin >> j;
		A.push_back(j);
	}
	
	int diff;
	int diff_max = -1;
		
	 for (int i = 0; i < N; ++i){
	 	for (int n = i + 1; n < N; ++n){
	 		if(diff_max < abs(A[n] - A[i]) )
	 		{
	 			diff_max = abs(A[n] - A[i]);
	 		}
	 	}
	 }
	
	 cout << diff_max << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int[]  dice = new int[6];
			dice[0] = 1;
			dice[1] = 6;
			dice[2] = 4;
			dice[3] = 3;
			dice[4] = 2;
			dice[5] = 5;
			int sum = 1;
			String str;
			int t1 = 0;
			int t2 = 0;
			for(int i = 0;i < n;i++){
				str = scan.next();
				if(str.equals("North")){
					t1 = dice[5];
					dice[5] = dice[0];
					t2 = dice[1];
					dice[1] = t1;
					t1 = dice[4];
					dice[4] = t2;
					dice[0] = t1;
				}else if(str.equals("South")){
					t1 = dice[4];
					dice[4] = dice[0];
					t2 = dice[1];
					dice[1] = t1;
					t1 = dice[5];
					dice[5] = t2;
					dice[0] = t1;
				}else if(str.equals("East")){
					t1 = dice[3];
					dice[3] = dice[0];
					t2 = dice[1];
					dice[1] = t1;
					t1 = dice[2];
					dice[2] = t2;
					dice[0] = t1;
				}else if(str.equals("West")){
					t1 = dice[2];
					dice[2] = dice[0];
					t2 = dice[1];
					dice[1] = t1;
					t1 = dice[3];
					dice[3] = t2;
					dice[0] = t1;
				}else if(str.equals("Right")){
					t1 = dice[5];
					dice[5] = dice[2];
					t2 = dice[3];
					dice[3] = t1;
					t1 = dice[4];
					dice[4] = t2;
					dice[2] = t1;
				}else if(str.equals("Left")){
					t1 = dice[4];
					dice[4] = dice[2];
					t2 = dice[3];
					dice[3] = t1;
					t1 = dice[5];
					dice[5] = t2;
					dice[2] = t1;
				}
				sum += dice[0];
			}
			System.out.println(sum);
		}
	}
}

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

int main(){
  int N;
  cin >> N;
  int L[N];
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  sort(L,L+N);
  int ans=0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1; k<N; k++){
        if(L[i]+L[j]>L[k]){
          ans++;
        }else{
          break;
        }
      }
    }
  }
  
  cout << ans;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC74(void);
void ABC75(void);
void ABC76(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC79();
}

void ABC79(){
    int n,i;
    long long int a,b,c;
    cin>>n;
    c=2;
    b=1;
    if(n==1)cout<<1<<endl;
    else{
        for(i=2;i<=n;i++){
            a=b+c;
            c=b;
            b=a;
        }
        cout<<a<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll cnt(ll,ll);
int main(){
    ll n,sum,ans=1e11;
    cin >> n;
    for(ll i=1;i*i<=n;i++){
      if(n%i==0){
         sum=0;
         ans=min(ans,cnt(max(i,(n/i)),0));
      }
    }
    cout <<ans<<endl;
}
ll cnt(ll n,ll sum){
  while(1){
    if(n==0) return sum;
    n/=10;
    sum++;
  }
}


Measured memory_bytes: 256
a = input().split()
n = int(a[0])
k = int(a[1])

b = k // 2
d = 0

for i in range(n):
  c = i + 1
  if c >= k:
    d += 1 / n
    continue
  for j in range(k):
    c *= 2
    if c >= k:
      d += (0.5 ** (j+1)) / n
      break

print(d)

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

int main(){
    int n;
    int a[110000],b[110000];
    cin >> n;
    a[0] = 0;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(int i = 0;i <= n;i++){
        b[i] = 0;
    }
    for(int i = 1;i <= n;i++){
        b[a[i]] += i;
    }
    for(int i = 1;i <= n;i++){
        cout << b[i] << endl;
    }

}

Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cassert>

using namespace std;

const long long MOD = 1000000007;

vector<long long> fact;
vector<long long> factinv;

void initfact(long long n) {
  fact.push_back(1);
  for (long long i = 1; i < n+1; i++) {
    fact.push_back((fact.back()*i)%MOD);
  }
}

long long sqr(long long n) {
  return n*n%MOD;
}

long long bipow(long long c, long long n) {
  if (n == 0) {
    return 1;
  } else if(n == 1) {
    return c;
  } else if(n%2 == 0) {
    return sqr(bipow(c, n/2))%MOD;
  } else {
    return (c*sqr(bipow(c, (n-1)/2)))%MOD;
  }
}

void initfactinv() {
  factinv.push_back(bipow(fact.back(), MOD-2));
  for (long long i = fact.size()-1; i > 0; i--) {
    factinv.push_back((factinv.back()*i)%MOD);
  }
  reverse(factinv.begin(), factinv.end());
}


void solve(long long N, long long K, std::vector<long long> a, std::vector<long long> b){
  vector< vector<long long> > G(N, vector<long long>());
  for (int i = 0; i < N-1; i++) {
    G[a[i]-1].push_back(b[i]-1);
    G[b[i]-1].push_back(a[i]-1);
  }

  initfact(K);
  initfactinv();

  long long ans;
  long long idx;
  long long c, d;
  vector<long long> visited(N, 0);

  ans = K;

  stack<long long> st;
  st.push(0);

  while (!st.empty()) {
    idx = st.top();
    st.pop();
    visited[idx] = 1;
    if (idx == 0) {
      c = K - 1;
      d = static_cast<long long>(G[idx].size());
    } else {
      c = K - 2;
      d = static_cast<long long>(G[idx].size()-1);
    }

    if (c-d < 0) {
      ans = 0;
    } else {
      assert(c <= K);
      assert(c-d <= K);
      ans *= (fact[c] * factinv[c-d]) % MOD;
      ans %= MOD;
    }

    for (int i = 0; i < G[idx].size(); i++) {
      if (visited[G[idx][i]] == 0) {
        st.push(G[idx][i]);
      }
    }
  }

  std::cout << ans % MOD << std::endl;

}

int main() {
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> a(N-1);
  std::vector<long long> b(N-1);
  for(int i = 0 ; i < N-1 ; i++){
      scanf("%lld",&a[i]);
      scanf("%lld",&b[i]);
    }
  solve(N, K, std::move(a), std::move(b));
  return 0;
}



Measured memory_bytes: 11252
N = int(input())
s = [input() for _ in range(N)]
for i in range(N):
  s[i] = "".join(sorted(s[i]))
t = {}
for i in range(N):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k]*(t[k]-1)//2 for k in t))

Measured memory_bytes: 19476
#include <iostream>

using namespace std;

class Dice{
private:
	int faces[1+6] = {};
public:
	void read(){
		for(int i = 1; i <= 6; i++){
			cin >> faces[i];
		}
	}

	void roll(int f){
		roll(f, 1, 7-f, 6);
	}

	void roll(int f1, int f2, int f3, int f4){
		int tmp = faces[f1];
		faces[f1] = faces[f2];
		faces[f2] = faces[f3];
		faces[f3] = faces[f4];
		faces[f4] = tmp;
	}

	int get(int n){
		return faces[n];
	}

	int contains(int n){
		for(int i = 1; i <= 6; i++){
			if(n == faces[i])
				return i;
		}
		return 0;
	}

	bool isEqual(Dice *dice){
		for(int i = 1; i <= 6; i++){
			if(this->faces[i] != dice->faces[i])
				return false;
		}
		return true;
	}
};

int main(){
	Dice input, dice;
	input.read();
	dice.read();

	int top, front, topNum;

	for(int i = 0; i < 1; i++){
		top = dice.contains(input.get(2));
		front = dice.contains(input.get(6));

		if(top && front && top + front != 7){
			topNum = dice.get(top);
			switch(front){
			case 6:
				break;
			case 1:
				dice.roll(top); dice.roll(top);
				break;
			default:
				dice.roll(front);
				break;
			}

			for(int j = 0; j < 4; j++){
				if(dice.get(2) == topNum) break;
				dice.roll(2, 3, 5, 4);
			}

			if(input.isEqual(&dice)){
				cout << "Yes" << endl;
				continue;
			}
		}
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#!/usr/bin/env python3

import sys

input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int,input().split()))

XY = list()
for i in range(N):
    XY.append((A[i], i+1))
XY.sort()

Ans = list()
for x,y in XY:
    Ans.append(y)

print(*Ans)

Measured memory_bytes: 25000
#include <iostream>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (a > 0 && c > 0) {
    c -= b;
    a -= d;
  }
  cout << (c <= 0 ? "Yes" : "No") << endl;
  return 0;
}


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<int> v;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        v.push_back(a);
    }

    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            if(abs(v[i]-v[j])%(n-1) == 0){
                cout << v[i] << " " << v[j] << endl;
                return 0;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 3160
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};
ll pow(ll x, ll ntimes) {
    ll ret = 1;
    while (ntimes > 0) {
        if ((ntimes & 1) == 1) {
            ret = ret * x;
        }
        x = x * x;
        ntimes >>= 1;
        x %= mod;
        ret %= mod;
    }
    return ret;
}
mint computeD(ll x){
    if(x==0){
        return mint(1);
    }else{
        mint ret = mint(pow(2,x));
        mint tmp = mint(pow(2,x-1));
        tmp *= mint(x);
        tmp += mint(pow(2,x));
        ret *= tmp;
        return ret; 
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll c(n);
    REP(i,n){
        cin >> c[i];
    }
    sort(ALL(c));
    mint ans = mint(0);
    REP(i,n){
        ans += mint(c[i]) * computeD(n-1-i) * mint(2) * mint(pow(2,i*2));
        //cout << ans.x << endl;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		Arrays.sort(a);
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}
}


Measured memory_bytes: 26208
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void Exit() {
  cout << -1 << endl;
  exit(0);
}

int main(void) {
  int64_t k;
  cin >> k;
  std::vector<int64_t> a(k);
  for (int i = 0; i < k; i++) {
    cin >> a[i];
  }

  if (a.back() != 2) {
    Exit();
  }

  int64_t min = 2, max = 3;
  for (int i = k - 2; i >= 0; i--) {
    if (max < a[i]) {
      Exit();
    }
    if (min % a[i] == 0) {
      // nothing
    } else {
      min = (min / a[i] + 1) * a[i];
    }
    max = (max / a[i]) * a[i] + a[i] - 1;
    if (min > max) {
      Exit();
    }
    cerr << "\033[93m" << min << " " << max << "\033[m" << endl;
  }
  cout << min << " " << max << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const LL M=1e9+7;
// a>=0, b>=0, x*a+y*b=gcd>=0, a>0,b>0=>abs(y)<=a,abs(x)<=b
LL gcdex(LL a,LL b,LL& x, LL& y){
	LL ax=1,ay=0;
	LL bx=0,by=1;
	while(b){
		LL r=a/b;
		LL t=a-r*b; a=b; b=t;
		LL tx=ax-r*bx; ax=bx; bx=tx;
		LL ty=ay-r*by; ay=by; by=ty;
	}
	x=ax;
	y=ay;
	return a;
}
LL modinv(LL a, LL m){
	LL x,y;
	gcdex(a,m,x,y);
	if(x<0){
		x+=m;
	} else if(x>=m){
		x-=m;
	}
	return x;
}
// powmod p^n%mod
LL powmod(LL p,LL n,LL mod){
	LL q=p%mod;
	LL pow=1;
	while(n){
		if(n&1){
			pow*=q;
			pow%=mod;
		}
		q=q*q;
		q%=mod;
		n/=2;
	}
	return pow;
}
vector<LL> ds;
vector<LL> dp;
int main() {
	LL N,K;
	cin >> N >> K;
	for(LL i=1;i*i<=N;i++){
		if(N%i==0){
			ds.push_back(i);
			if(i*i<N){
				ds.push_back(N/i);
			}
		}
	}

	sort(ds.begin(),ds.end());
	for(int i=0;i<ds.size();i++){
		LL v=powmod(K,(ds[i]+1)/2,M);
		//cerr << v << endl;
		for(int j=0;j<i;j++){
			if(ds[i]%ds[j]==0){
				v+=M-dp[j];
				v%=M;
			}
		}
		dp.push_back(v);
		//cerr << ds[i] << ", " << dp[i] << endl;
	}

	LL ret=0;
	LL r2=modinv(2,M);
	for(int i=0;i<ds.size();i++){
		if(ds[i]%2==0){
			ret+=ds[i]*r2%M*dp[i]%M;
			ret%=M;
		}
		else{
			ret+=ds[i]*dp[i]%M;
			ret%=M;
		}
	}
	cout << ret << endl;

	return 0;
}



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

int main() {
  int n, k;
  string S;
  cin >> n >> k;
  cin >> S;
  k=k-1;
  if (S.at(k)=='A') {
    S.at(k)='a';
  }
  if (S.at(k)=='B') {
    S.at(k)='b';
  }
  if (S.at(k)=='C') {
    S.at(k)='c';
  }
  cout << S <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    cout << a[n - 1] - a[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>

#define PI 3.14159265359

using namespace std;

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double lh_angle = 6 * m;
  double sh_angle = 30 * h + 0.5 * m;
  double theta = abs(lh_angle - sh_angle);
  if (theta > 180) theta = 360 - theta;
  // cout << "theta" << theta << endl;
  double unit = PI / 180.0;
  double deg_r = theta * unit;
  // cout << deg_r << endl;

  double co = cos(deg_r);
  cout << std::setprecision(30)
       << sqrt((long double)(b * b + a * a) - (long double)(2.0 * b * a) * co)
       << endl;
  return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        int count[100011] = {0}, ans = 0;
        rep(i,n){
            int a, b;
            cin >> a >> b;
            a--;
            count[a]++;
            count[b]--;
        }
        int sum = 0;
        rep(i,n + 1){
            sum+=count[i];
            if(sum >= i && ans < i) ans = i;
        }
        cout << ans << endl;
    }
}

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

int main() {
	std::size_t N;
	std::cin >> N;
	std::vector<std::size_t > vc;
	vc.reserve(2 * N);
	for (std::size_t i{ 0 }; i < 2*N; i++) {
		size_t t;
		std::cin >> t;
		vc.emplace_back(t);
	}
	/*
	for (auto &v : vc) {
		std::cout << v << " ";
	}*/
	std::sort(std::begin(vc), std::end(vc));
	size_t res{};
	for(std::size_t i{ 0 }; i < N; i++) {
		res += vc[i*2];
	}
	std::cout << res << "\n";
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    for (ll k = K; k <= N + 1; k++){
        // 連続するn個からk個選んだときに取れる値は k(n-k)+1
        ans += ((k * (N + 1 - k) + 1) % MOD);
    }
    cout << (ans % MOD) << endl;
}

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


Measured memory_bytes: 3652
S = input()

def div_plus(i, s):
    if i == len(S):
        s_list = [int(i) for i in s.split("+")]
        return sum(s_list)
    
    pos = i - len(S)
    # プラスを挿入しない場合
    d1 = div_plus(i+1, s)
    
    # プラスを挿入する場合
    d2 = div_plus(i+1, s[:pos]+"+"+s[pos:])
    return d1 + d2

print(div_plus(1, S))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

namespace ALDS1_14A_1 {
    public class Program {
        public static void Main(string[] args) {
            var str = Console.ReadLine();
            var search = Console.ReadLine();
            var findList = new List<int>();

            int find;
            while((find = str.IndexOf(search, StringComparison.Ordinal)) != -1){
                findList.Add(find + 1);
                str = str.Remove(0, find + 1);
            }

            for(var i = 1; i < findList.Count; i++){
                findList[i] += findList[i - 1];
            }

            foreach(var f in findList){
                Console.WriteLine(f - 1);
            }
        }
    }
}

Measured memory_bytes: 9220
<?php
fscanf(STDIN, "%d%d", $N, $M);
$A = array_map("intval", explode(" ", fgets(STDIN)));
$sum = 0;
$zero = 0;
foreach($A as $i => $a){
  $sum+=$a;
  $sum%=$M;
  $B[] = $sum;
  if($sum == 0){
    $zero++;
  }
  if(!isset($map[$sum])){
    $map[$sum] = 0;
  }
  $map[$sum]++;
}
foreach($map as $k => $c){
  $zero+=($c*($c-1))/2;
}
echo $zero;


Measured memory_bytes: 18932
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        int l = Integer.parseInt(s.substring(0, 2));
        int r = Integer.parseInt(s.substring(2, 4));

        if (!isMonth(l) && !isMonth(r)) {
            System.out.println("NA");
        } else if (isMonth(l) && isMonth(r)) {
            System.out.println("AMBIGUOUS");
        } else if (isMonth(r)) {
            System.out.println("YYMM");
        } else {
            System.out.println("MMYY");
        }
    }
    static boolean isMonth(int num) {
        return num > 0 && num <= 12;
    }
}

Measured memory_bytes: 23252
from fractions import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

sub = []

for i in range(N):
    sub.append(abs(X-x[i]))

max = sub[0]

for i in range(1,N):
    max = gcd(max, sub[i])

print(max)

Measured memory_bytes: 16280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string kekka = "";
            string[] input1 = Console.ReadLine().Split();
            int hp = int.Parse(input1[0]);
            string[] input2 = Console.ReadLine().Split();
            int[] round = new int[input2.Length];
            for(int i = 0; i < input2.Length; i++)
            {
                round[i] = int.Parse(input2[i]);
                hp = hp - round[i];
            }
            if(hp <= 0)
            {
                kekka = "Yes";
            }
            else
            {
                kekka = "No";
            }
            Console.WriteLine(kekka);
            Console.Read();
        }
    }
}


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

(n, m) = map(int, raw_input().split())
while n!=0 or m!=0:
    T = [int(raw_input()) for i in range(n)]
    H = [int(raw_input()) for i in range(m)]
    min = [1000, 1000]
    for i in range(n):
        for j in range(m):
            if(sum(T)-T[i]+H[j] == sum(H)+T[i]-H[j] and sum(min) > H[j] + T[i]):
                min = [T[i], H[j]];
    if min == [1000, 1000]:
        print -1
    else:
        print min[0], min[1]
    
    (n, m) = map(int, raw_input().split())

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

    int a,b;
    cin>>a>>b;
    char ans[100][100];
    int n = 100;
    for(int i=0;i<100;i++) {
        for(int j=0;j<100;j++) {
            ans[i][j] = ((i<50)?'#':'.');
        }
    }

    int rema = a-1;
    int remb = b-1;

    int ax=0, ay=0, bx=99, by=0;

    for(int i=0;i<rema;i++) {
        if(ay>=100) {
            ay = 0;
            ax+=2;
        }
        ans[ax][ay]='.';
        ay+=2;
    }

    for(int i=0;i<remb;i++) {
        if(by>=100) {
            by = 0;
            bx-=2;
        }
        ans[bx][by]='#';
        by+=2;
    }

    cout<<"100 100\n";

    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            cout<<ans[i][j];
        }
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>
int main(void){
    long long n,i,j,a,m,M,c;
    c=0;
    scanf("%lld",&n);
    long long v[n];
    for (j=1;j<=n;j++) {
        scanf("%lld",&a);
        v[j]=a;
    }
    for (i=1;i<=n;i++) {
        if (i==1){
            m=v[i];
            M=v[i];
        }
        m=(m<v[i])?m:v[i];
        M=(M>v[i])?M:v[i];
    }
    
    for (i=1;i<=n;i++) c+=v[i];
    
    printf("%lld %lld %lld\n",m,M,c);
}


Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)

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

  vint p, m;

  rep(i, N) {
    int x;
    std::cin >> x;
    if (x >= 0)
      p.push_back(x);
    else
      m.push_back(-1*x);
  }
  reverse(ALL(m));

  int ans = INT_MAX;
  if (K <= p.size()) ans = min(ans, p[K - 1]);
  if (K <= m.size()) ans = min(ans, m[K - 1]);

  REP(i, 1, K) {
    if (i - 1 >= p.size() || K - i - 1 >= m.size()) continue;
    int tmp = p[i - 1] + m[K - i - 1];
    tmp += min(p[i - 1], m[K - i - 1]);
    ans = min(ans, tmp);
  }

  MSG(ans);

  return 0;
}


Measured memory_bytes: 1020
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 2019;

ll L, R;

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

  ll ans = LL_INF;
  for (ll k = L; k <= min(R, L + 2019); k++) {
    for (ll l = k + 1; l <= min(R, L + 2019); l++) {
      ll sum = k * l % MOD;
      if (sum == 0) {
        cout << 0 << endl;
        return 0;
      }

      if (sum < ans) {
        ans = sum;
      }
    }
  }

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

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int c[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      scanf("%d",&c[i][j]);
    }
  }
  if((c[0][0]-c[1][0]!=c[0][1]-c[1][1])||(c[0][0]-c[1][0]!=c[0][2]-c[1][2])||(c[0][0]-c[2][0]!=c[0][1]-c[2][1])||(c[0][0]-c[2][0]!=c[0][2]-c[2][2])){
    printf("No");
  }
  else{
    printf("Yes");
  }
  return 0;
}


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

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

int main(void){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);

    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int>());


    int maxlen = 0;
    for(int i = 0;i < n-1;i++){
        maxlen = max(a[i]-a[i+1],maxlen);
    }
    maxlen = max((a.back()+k-a[0]),maxlen);

    cout << k - maxlen << endl;
}

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

int main() {
    string S; cin >> S;

    map<string, int> table {
        {"SUN", 0},
        {"MON", 1},
        {"TUE", 2},
        {"WED", 3},
        {"THU", 4},
        {"FRI", 5},
        {"SAT", 6}
    };

    cout << 7 - table[S] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}

int main() {
    IN(ll , a);
    COUT(a+pow(a, 2)+pow(a, 3));
}



Measured memory_bytes: 4148
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a,x,b) (a<=x && x<=b)
#define WS std::cout<<" ";
#define NL std::cout<<"\n"
#define OUT(dist) std::cout<<(dist);
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;

int N;
V<int> v;

int main(){
    INIT;
    cin >> N;
    v.resize(N);
    REP(i,N) cin >> v[i];
    LL sum = 0, sum2 = 0;
    REP(i,N) sum += v[i]; sum /= 2;
    for(int i = 0; i < N; i+=2) sum2 += v[i];
    V<LL> od; od.push_back(sum2 - sum);
    REP(i,N-1) od.push_back(v[i]-od.back());
    for(auto& x : od) { x *= 2; cout << x << " "; }
}

Measured memory_bytes: 2676
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long N,cnt=0,keep;
    cin >> N;
    vector<long>A(N+1),B(N);
    for(int i=0;i<N+1;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    for(int i=0;i<N;i++){
        if(B[i]>=A[i]){
            cnt += A[i];
            if(B[i]>A[i]){
                keep=B[i]-A[i];
                if(keep>=A[i+1]){
                    cnt +=A[i+1];
                    A[i+1]=0;
                }else{
                    cnt += keep;
                    A[i+1] -= keep;
                }
            }
        }else{
            cnt += B[i];
        }
    }
    cout << cnt;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;

int main() {
   int n;
   cin>>n;
   vector<int>a(n);
   for(int i=0;i<n;i++){
     cin>>a[i];}
   int64_t sum1=0;int64_t count1=0;
   int64_t sum2=0;int64_t count2=0;

    //a[0]が正から始まると決めれば操作回数は自動的に決まる。
    //正からと負から始まるもの両方を調べて少ないほうを出力する。
    //累積を常に持って置き、正負に合わなければ累積分＋１の操作回数で正負を逆にできる
   for(int i=0;i<n;i++){//a[0]が正の場合の操作回数を計算
    sum1+=a[i];
    if(i%2==0){if(sum1<=0){count1+=abs(sum1)+1;sum1=1;}}
    else{if(sum1>=0){count1+=abs(sum1)+1;sum1=-1;}}
   }
   for(int i=0;i<n;i++){//a[0]が負の場合の操作回数を計算
    sum2+=a[i];
    if(i%2==0){if(sum2>=0){count2+=abs(sum2)+1;sum2=-1;}}
    else{if(sum2<=0){count2+=abs(sum2)+1;sum2=1;}}
   }
   cout<<min(count1,count2)<<endl;
return 0;}

Measured memory_bytes: 640
N = int(input())
# スペース区切りの整数をリストに入力

sdic = {}

nMax = 1

for i in range(N):
    s = str(input())
    if s in sdic:
        sdic[s] += 1
        nMax = max(nMax,sdic[s])
    else:
        sdic[s] = 1

slist = []
for k in sdic:
    if sdic[k] == nMax:
        slist.append(k)

for s in sorted(slist):
    print(s)


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

int main(){
  string N;
  cin >> N;
  bool judge = false;
  for(int i = 0; i < N.size(); i++){
    if(N.at(i) == '7') judge = true;
  }
  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 3624
<?php
$n = trim(fgets(STDIN));
$a = explode(" ",trim(fgets(STDIN)));
$i = 0;
$o = 0;
$ee = 0;
while($i < $n){
if($a[$i] % 2 == 1){
++$o;
}elseif($a[$i] % 4 == 0){
++$ee;
}
++$i;
}
 
if($o <= $ee){
echo "Yes";
}elseif($o == $ee + 1){
if($o + $ee == $n){
echo "Yes";
}else{
echo "No";
}
}else{
echo "No";
}

Measured memory_bytes: 21928
#include "bits/stdc++.h"
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1150&lang=jp
using namespace std;
typedef long long ll;
typedef pair<pair<int, int>, pair<int, int>> foot;
#define INF 1<<30

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

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int w, h;
	while (cin >> w >> h, w | h) {
		vector<vector<int>> masu(h, vector<int>(w, INF));
		vector<vector<vector<int>>> dist(h, vector<vector<int>>(w, vector<int>(2,INF)));
		queue<pair<foot, bool>> q; // foot: foot location , bool : next foot(left:bool,right:true)
		/* input */
		for (int y = 0; y < h;y++) {
			for (int x = 0; x < w;x++) {
				char c; cin >> c;
				if (c == 'X') continue;
				if (c == 'S' || c == 'T') masu[y][x] = 0;
				else masu[y][x] = c - '0';
			}
		}

		/* initialize */
		for (int x = 0; x < w;x++) {
			if (masu[h - 1][x] == 0) {
				// dist initialize
				dist[h - 1][x][0] = dist[h-1][x][1] = 0;
				// q initialize
				q.push({ {{h - 1,x},{-1,-1}},true });
				q.push({ {{-1,-1},{h - 1,x}},false });
			}
		}

		while (!q.empty()) {
			auto v = q.front(); q.pop();
			pair<int, int> l_foot = { v.first.first.first,v.first.first.second };
			pair<int, int> r_foot = { v.first.second.first,v.first.second.second };
			bool foot_flag = v.second;

			if (foot_flag) {
				for (int i = 0; i < 9;i++) {
					int next_r_foot_y = l_foot.first + dy[i];
					int next_r_foot_x = l_foot.second + dx[i];

					if (next_r_foot_y < 0 || next_r_foot_y >= h) continue;
					if (next_r_foot_x < 0 || next_r_foot_x >= w) continue;

					if (dist[next_r_foot_y][next_r_foot_x][foot_flag] >
						dist[l_foot.first][l_foot.second][!foot_flag] + masu[next_r_foot_y][next_r_foot_x]) {
						dist[next_r_foot_y][next_r_foot_x][foot_flag] =
							dist[l_foot.first][l_foot.second][!foot_flag] + masu[next_r_foot_y][next_r_foot_x];
						q.push({ {{l_foot.first,l_foot.second},{next_r_foot_y,next_r_foot_x}},!foot_flag });
					}
				}
			}
			else {
				for (int i = 0; i < 9;i++) {
					int next_l_foot_y = r_foot.first + dy[i];
					int next_l_foot_x = r_foot.second - dx[i];

					if (next_l_foot_y < 0 || next_l_foot_y >= h) continue;
					if (next_l_foot_x < 0 || next_l_foot_x >= w) continue;

					if (dist[next_l_foot_y][next_l_foot_x][foot_flag] >
						dist[r_foot.first][r_foot.second][!foot_flag] + masu[next_l_foot_y][next_l_foot_x]) {
						dist[next_l_foot_y][next_l_foot_x][foot_flag] =
							dist[r_foot.first][r_foot.second][!foot_flag] + masu[next_l_foot_y][next_l_foot_x];
						q.push({ {{next_l_foot_y,next_l_foot_x},{r_foot.first,r_foot.second} }, !foot_flag });
					}
				}
			}
		}

		int ans = INF;
		for (int i = 0; i < w;i++) {
			if (masu[0][i] != 0) continue;
			ans = min(ans, min(dist[0][i][0],dist[0][i][1]));
		}
		if (ans == INF) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 3360
#include <stdio.h>
#define MAX 100000
int A[MAX];
int partition(int p,int r){
  int x = A[r];
  int i = p-1,j;
  int y;
  for (j = p;j < r;j++){
    if (A[j] <= x){
      i = i+1;
      y=A[j];
      A[j]=A[i];
      A[i]=y;
    }
  }
  A[r]=A[i+1];
  A[i+1]=x;
  return i+1;
}

int main(){
  int i,n,q;
  scanf("%d",&n);
  for(i=0;i < n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);

  for(i=0;i < n-1;i++){
    if(i == q)printf("[%d] ",A[q]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);

  return 0;
}



Measured memory_bytes: 2112
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N,M,C = (int(i) for i in input().split())
B = list(map(int, input().split()))
B =np.array(B,dtype=int)
A =np.zeros((N,M),dtype=int)
for i in range(N):
    A[i] = list(map(int, input().split()))
    
#
count =0
for i in range(N):
    if np.sum(A[i] *B) +C >0:
        count +=1
print(count) 

Measured memory_bytes: 27124
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  long long N,K;
  long long ans = 0;
  cin >> N >> K;
  if(K == 0){
    cout << N*N << endl;
    return 0;
  }
  FOR(b,1,N+1){
    if(b <= K) continue;
    else{
      int x = b - K;
      ans += (N / b) * x;
      if(N % b >= K) ans += (N % b) - K + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

s = n**0.5 + 20
s = int(s)

while True:
    if n%s == 0:
        a = list(str(s))
        b = list(str(n//s))
        ans = max(len(a), len(b))
        print(ans)
        exit()
    else:
        s -= 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int geta=100;

signed main(){
	vector<int> num(1000000+geta);
	int N; cin>>N;
	for(int i=0;i<N;i++){
		int a; cin>>a;
		num[a+geta]++;
		num[a-1+geta]++;
		num[a+1+geta]++;
	}
	int ans=0,sum=0;
	for(int i=0;i<1000000;i++){
		if(num[i+geta]>sum){
			sum=num[i+geta];
			ans=i;
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stdlib.h>

int main(){
   int n,x,y,d,i,j,k,t;

   scanf("%d %d",&n,&x);
   for (d=i=0;i<n;i++) {
      scanf("%d",&y);
      if (d==0) d=abs(x-y);
      else {
         j=d;
         k=abs(x-y);
         if (k>j) {
            t=j;j=k;k=t;
         }
         while (k>0) {
            t=j%k;j=k;k=t;
         }
         d=j;
         x=y;
      }
   }
   printf("%d\n",d);
   return 0;
}


Measured memory_bytes: 128