akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }
 
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }
 
template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}
 
struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};
 
vector<pair<int,int>> g[100100];
ll d[100100];
 
bool dfs(int v) {
  for (auto e: g[v]) {
    int w, c;
    tie(w, c) = e;
    if (d[w] == ll(1e18)) {
      d[w] = d[v] + c;
      if (!dfs(w)) return false;
    }
    else {
      if (d[w] != d[v] + c) return false;
    }
  }
  return true;
}
 
void solve(ll N, ll M, vector<ll> L, vector<ll> R, vector<ll> D) {
  REP(i,M) {
    int s = L[i] - 1, t = R[i] - 1, d = D[i];
    g[s].emplace_back(t, d);
    g[t].emplace_back(s, -d);
  }
  REP(i,N) d[i] = ll(1e18);
  bool ok = true;
  REP(i,N) {
    if (d[i] != ll(1e18)) continue;
    // cout << i << endl;
    d[i] = 0;
    if (!dfs(i)) ok = false;
  }
  // REP(i,N) cout << d[i] << endl;
  cout << ok << endl;
}
 
int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll M;
	ll N;
	scanf("%lld", &N);
	scanf("%lld", &M);
	vector<ll> L(M-1+1);
	vector<ll> R(M-1+1);
	vector<ll> D(M-1+1);
	for (int i = 0 ; i <= M-1 ; i++) {
	  scanf("%lld", &L[i]);
	  scanf("%lld", &R[i]);
	  scanf("%lld", &D[i]);
	}
	solve(N, M, L, R, D);
	return 0;
}

Measured memory_bytes: 21760
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const hList = input[1].split(' ').map(x => parseInt(x, 10));

    var count = 0;
    var max = 0;
    var current = hList[0];
    var next = NaN;
    for (var i = 1; i < N; i++) {
        next = hList[i];
        if (current >= next) {
            count++;
        } else {
            max = Math.max(count, max);
            count = 0;
        }
        current = next;
    }
  	max = Math.max(count, max);

    console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17784
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy as np
import scipy

from collections import defaultdict
from pprint import pprint

N = int(input())
A = []
B = []
diff = []
points = [] # points[i] = [A,B,diff]
for i in range(N):
    a,b = [int(x) for x in input().split(" ")]
    points.append([a,b,a+b])

sorted_points = sorted(points, key=lambda x: x[2], reverse=True)
point_a, point_b = 0,0

turn_A = True
for p in sorted_points:
    if turn_A:
        point_a += p[0]
        turn_A = False
    else:
        point_b += p[1]
        turn_A = True

print(point_a - point_b)


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s;
    cin >> s;
    s = " " + s;
    if(s[3] == s[4] && s[5] == s[6]) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
def power(x, y, mod):
    """
    https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
    二分累乗法でx ** yを求める
    
    2 ** n = 4 ** (n//2) = 16 ** (n//4)
    みたいなことをする
    """

    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2, mod)**2 % mod
    else            : return power(x, y//2, mod)**2 * x % mod


def mul(a, b, mod):
    """
    https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
    modを加味したかけ算を行う
    """
    return ((a % mod) * (b % mod)) % mod

def div(a, b, mod):
    """
    https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
    modを加味した割り算を行う    
    """
    if a == b:
        return 1
    return mul(a, inv_t[b], mod)


def factorial_part(start, last, mod):
    """
    startからlastまでのかけ算を行う
    
    factorial_part(2, 4, mod) = 2 * 3 * 4 = 24    
    """
    assert(start <= last)
    x = 1
    for k in range(start, last+1):
        x *= k
        x %= mod
    return x

def combination(n, a, mod):
    if a == 0:
        return 1
    nCa = div(factorial_part(n - a + 1, n, mod), factorial_part(1, a, mod), mod)
    return nCa

n, m, k = list(map(int, input().split()))
mod =  998244353

P = mod
N = max([max([n, m]), k]) + 5
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

powers = [0] * n
a = m
for kk in range(n):
    powers[kk] = a
    a = (a * (m - 1)) % mod

c =0
p = 1
comb = 1
kk = 0
a = n - kk
c += powers[a - 1] * comb

for kk in range(1, k + 1):
    a = n - kk
    comb = (div(comb,  kk, mod) * (a))%mod
    c = c + powers[a - 1] * comb
    c = c%mod
print(c)

Measured memory_bytes: 24632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

const int mod=2019;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int f[mod];
    //set<int> s1;
    for(int i=0;i<mod;i++){
        f[(i*10)%mod]=i;
     ///   s1.insert((i*10)%mod);
    }
    string s;
    cin>>s;
    int n=s.size();
    ll ans=0;
    int pre[2019];
    for(int j=0;j<2019;j++){
        if(j==s[0]-'0') pre[j] =1;
        else pre[j]=0;
    }
    int gre[2019];
    ans+=pre[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<2019;j++){
            int y=(j-(s[i]-'0')+mod)%mod;
            int r=f[y];
            gre[j]=pre[r];
            if(j==s[i]-'0'){
                gre[j]++;
            }
        }
        ans+=gre[0];
        for(int j=0;j<mod;j++){
            pre[j]=gre[j];
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 3764
# AGC008A - Simple Calculator
def main():
    x, y = tuple(map(int, input().rstrip().split()))
    cand = [y - x, y + x + 1, -y - x + 1, -y + x + 2]
    print(min(i for i in cand if i >= 0))


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
cnt = 0
max_cnt = -1
for s in S:
    if s == 'R':
        cnt += 1
    else:
        if max_cnt < cnt:
            max_cnt = cnt
        cnt = 0
if max_cnt < cnt:
    max_cnt = cnt
print(max_cnt)


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

char count_bomb(int i,int j,vector<string> str){
  int sum = 0;
  if(str.at(i).at(j)=='#')
    return '#';
  else
  {
    if(str.at(i-1).at(j-1)=='#')
      sum++;
    if(str.at(i-1).at(j)=='#')
      sum++;
    if(str.at(i-1).at(j+1)=='#')
      sum++;
    if(str.at(i).at(j+1)=='#')
      sum++;
    if(str.at(i+1).at(j+1)=='#')
      sum++;
    if(str.at(i+1).at(j)=='#')
      sum++;
    if(str.at(i+1).at(j-1)=='#')
      sum++;
    if(str.at(i).at(j-1)=='#')
      sum++;
    return (char)(sum +'0');
  }
}

int main(){
  int h,w;
  cin>>h>>w;
  
  vector<string> str(h+2);
  for(int i=0;i<w+2;i++){
    str.at(0)="0"+str.at(0);
    str.at(h+1)="0"+str.at(0);
  }
  
  for(int i=1;i<h+1;i++){
    cin>>str.at(i);
    str.at(i)="0"+str.at(i)+"0";
  }
  
  
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cout<<count_bomb(i,j,str);
    }
    cout<<endl;
  }
}

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

int main(){
  long long N, D;
  cin >> N >> D;
  vector<long long> C(N * 2);
  for (long long i = 0; i < N * 2; i++){
    cin >> C[i];
  }
  
  long long count = 0;
  for (long long i = 0; i < N; i++){
    if (pow(pow(C[i * 2], 2) + pow(C[i * 2 + 1], 2), 0.5) <= D){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 6468
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(10);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<string,string>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
////////////////

void solve(){
  ini(N , K , R , S , P);
  ins(C);

  ll ans = 0;
  auto f = [&](int i){
    return C[i] == 'r' ? P : C[i] == 's' ? R : S ;
  };
  vi flg(N + 1);
  rep(i , N){
    if(i < K){
      ans += f(i);
      flg[i] = 1;
    }
    else {
      if(C[i] != C[i-K] || flg[i - K] == 0){
        ans += f(i);
        flg[i] = 1;
      }
    }
  }
  out(ans);
  

   
}

Measured memory_bytes: 848
M = 998244353
a, b, c, d = gets.split.map(&:to_i)

dp = Array.new(c + 1) {Array.new(d + 1, 0)}

dp[a][b] = 1
(b+1).upto(d) {|j| dp[a][j] = dp[a][j-1] * a % M}

(a+1).upto(c) do |i|
    dp[i][b] = dp[i-1][b] * b % M
    (b+1).upto(d) do |j|
        dp[i][j] = (dp[i-1][j] * j + dp[i][j-1] * i - dp[i-1][j-1] * (i-1) * (j-1)) % M
    end
end

p dp[c][d]

Measured memory_bytes: 84656
import math

c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]

d = math.sqrt(pow(c1x-c2x, 2) +  pow(c1y-c2y, 2))

s = c1r + c2r

if d > s:
    print(4)
elif d == s:
    print(3)
else:
    if c1r > c2r:
        if d + c2r > c1r:
            print(2)
        elif d + c2r == c1r:
            print(1)
        else:
            print(0)
    else:
        if d + c1r > c2r:
            print(2)
        elif d + c1r == c2r:
            print(1)
        else:
            print(0)



Measured memory_bytes: 5668
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200005
#define LOG         20
#define mod         1000000007
using namespace std;
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust";
    }
    else{
        cout<<"win";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

long long 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;
    }
}

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<ll> ans_1;
  vector<ll> ans_2;
  ans_1.emplace_back(a[0]);
  ans_2.emplace_back(a[n-1]);
  ll ans = a[n-1] - a[0];
  int left = 1;
  int right = n-2;
  rep(i, n-2) {
    ll p = abs(a[left]-ans_1.back());
    ll q = abs(a[left]-ans_2.back());
    ll r = abs(a[right]-ans_1.back());
    ll s = abs(a[right]-ans_2.back());
    vector<ll> candidate({p, q, r, s});
    ll t = *max_element(candidate.begin(), candidate.end());
    ans += t;
    if(p == t) {
      ans_1.emplace_back(a[left]);
      left++;
    }
    else if(q == t) {
      ans_2.emplace_back(a[left]);
      left++;
    }
    else if(r == t) {
      ans_1.emplace_back(a[right]);
      right--;
    }
    else if(s == t) {
      ans_2.emplace_back(a[right]);
      right--;
    }
  }

  cout << ans << endl;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()


int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> V(N);
	REP(i, N)
		cin >> V[i];

	sort(ALL(V));
	if (V[0] == 0)
	{
		std::cout << 0 << std::endl;
		return 0;
	}

	ll res{1};
	ll tmp{1000000000000000000ll};
	REP(i, N)
	{
		if (V[i] > tmp)
		{
			std::cout << -1 << std::endl;
			return 0;
		}
		res *= V[i];
		tmp /= V[i];
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 4000
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;


int main() {
	ll N;
	int digcnt = 0, topdig;
	int a=0, b;

	cin >> N;
	while (N != 0) {
		if (N < 10) topdig = N;
		a += N % 10;
		N /= 10;
		digcnt++;
	}
	b = (topdig - 1) + 9 * (digcnt - 1);

	cout << max(a,b) << endl;

	return 0;
}

Measured memory_bytes: 256
/*
    A - Frog 1
    
    30/11/2019
    
    https://atcoder.jp/contests/dp/tasks/dp_a
    
    @Ritik Gajjar
    
    Topic : DP
*/

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

typedef long long int ll;

ll minCost(int height[] , int n , int k)
{
    ll dp[n];
    dp[0] = 0;
    
    for(int i=1 ; i<n ; i++)
    {
        int j=i-1;
        dp[i] = LLONG_MAX;
        while(j >= 0 && j >= i-k)
        {
            dp[i] = min(dp[i] , dp[j] + abs(height[i]-height[j]));
            j--;
        }
    }

    return dp[n-1];
}

int main() 
{
    int n,k;
    cin >> n >> k;
    int height[n];

    for(int i=0 ; i<n ; i++)
        cin >> height[i];

    cout << minCost(height , n , k);

    return 0;
}


Measured memory_bytes: 1408
/*
 * b.cc: B: ABC Edition
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_L = 100;

/* typedef */

/* global variables */

string ss[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, l;
  cin >> n >> l;
  for (int i = 0; i < n; i++) cin >> ss[i];
  sort(ss, ss + n);

  for (int i = 0; i < n; i++) cout << ss[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  template<class Int> ModInt(Int x) : v(x >= 0 ? x % P : -x % P ? P - -x % P : 0) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M rhs) const { return M(*this) *= rhs; }
  M operator/(M rhs) const { return M(*this) /= rhs; }
  M operator+(M rhs) const { return M(*this) += rhs; }
  M operator-(M rhs) const { return M(*this) -= rhs; }
  bool operator==(M rhs) const { return v == rhs.v; }
  bool operator!=(M rhs) const { return !(*this == rhs); }
  M& operator*=(M rhs) { v = (unsigned long long) v * rhs.v % P; return *this; }
  M& operator/=(M rhs) { return *this *= rhs.inv(); }
  M& operator+=(M rhs) { v = rhs.v < P - v ? v + rhs.v : v - (P - rhs.v); return *this; }
  M& operator-=(M rhs) { v = rhs.v <= v ? v - rhs.v : v + (P - rhs.v); return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Int> M pow(Int n) const {
    n = n >= 0 ? n % (P - 1) : P - 1 - -n % (P - 1);
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  template<class Int> friend M operator*(Int lhs, M rhs) { return M(lhs) *= rhs; }
  template<class Int> friend M operator/(Int lhs, M rhs) { return M(lhs) /= rhs; }
  template<class Int> friend M operator+(Int lhs, M rhs) { return M(lhs) += rhs; }
  template<class Int> friend M operator-(Int lhs, M rhs) { return M(lhs) -= rhs; }
  friend ostream& operator<<(ostream& os, M rhs) { return os << rhs.v; }
  friend istream& operator>>(istream& is, M& rhs) { lint x; is >> x; rhs = x; return is; }
  template<class Int> friend bool operator==(Int lhs, M rhs) { return M(lhs) == rhs; }
  template<class Int> friend bool operator!=(Int lhs, M rhs) { return !(lhs == rhs); }
};
using Mint = ModInt<(unsigned) 1e9 + 7>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V< array<Mint, 2> > dp(n + 1);
  for (int x = 0; x <= n; ++x) {
    dp[x][x == 0] = 1;
  }
  for (int i = 0; i < m; ++i) {
    V< array<Mint, 2> > ndp(n + 1);
    for (int x = 0; x <= n; ++x) for (int f = 0; f < 2; ++f) {
      if (x > 0) {
        ndp[x - 1][f or x - 1 == 0] += dp[x][f];
        ndp[x][f or x == 1] += dp[x][f];
      }
      if (x < n) {
        ndp[x + 1][f] += dp[x][f];
        ndp[x][f] += dp[x][f];
      }
    }
    swap(dp, ndp);
  }
  Mint res = 0;
  for (int x = 0; x <= n; ++x) {
    res += dp[x][1];
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,s1,s2,s3;
  s1="Sunny";
  s2="Cloudy";
  s3="Rainy";
  cin>>s;
  if(s==s1)cout<<s2<<endl;
  else if(s==s2)cout<<s3<<endl;
  else cout<<s1<<endl;
  return 0;

}



Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

int
gcd(int a, int b)
{
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

int
main(int argc, char** argv)
{
	int a, b;

	scanf("%d %d", &a, &b);
	printf("%d\n", gcd(a, b));
	return 0;
}

Measured memory_bytes: 592
#include<iostream>

using namespace std;

int main(){
	int t;	cin>>t;
	while(t--){
		int x,y,w,h,n,cnt=0;	cin>>x>>y>>w>>h>>n;
		while(n--){
			int xx,yy;	cin>>xx>>yy;
			if(x<=xx && xx<=x+w && y<=yy && yy<=y+h)	cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    const int n = 3;
    vector<vector<int>> c(n, vector<int> (n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> c.at(i).at(j);
        }
    }
    for(int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            if (c.at(i + 1).at(j) - c.at(i).at(j) != c.at(i + 1).at(j + 1) - c.at(i).at(j + 1)) {
                goto next;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
    next:
    cout << "No" << endl;
}


Measured memory_bytes: 256
A=list(map(int, input().split()))
for i in range(3):
	for j in range(2):
		if A[j]<A[j+1]:
			temp_A=A[j]
			A[j]=A[j+1]
			A[j+1]=temp_A
print(A[0]*10+A[1]+A[2])



Measured memory_bytes: 2940
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
/* Returns the value of maximum profit */
ll knapSackRec(ll W, ll wt[], ll val[], ll i, ll** dp) 
{ 
    // base condition 
    if (i < 0) 
        return 0; 
    if (dp[i][W] != -1) 
        return dp[i][W]; 
  
    if (wt[i] > W) { 
  
        // store the value of function call stack in  
        // table before return 
        dp[i][W] = knapSackRec(W, wt, val, i - 1, dp); 
        return dp[i][W]; 
    } 
    else { 
  
        // store value in a table before return 
        dp[i][W] = max(val[i] + knapSackRec(W - wt[i], wt, val, i - 1, dp), 
                       knapSackRec(W, wt, val, i - 1, dp)); 
  
        // return value of table after storing 
        return dp[i][W]; 
    } 
} 
  
ll knapSack(ll W, ll wt[], ll val[], ll n) 
{ 
    ll** dp; // double poller to declare the table dynamically 
    dp = new ll*[n]; 
  
    // loop to create the table dynamically 
    for (ll i = 0; i < n; i++)  
        dp[i] = new ll[W + 1];     
  
    // loop to initially filled the table with -1 
    for (ll i = 0; i < n; i++)  
        for (ll j = 0; j < W + 1; j++)  
            dp[i][j] = -1; 
    return knapSackRec(W, wt, val, n-1, dp); 
} 
  
int main() 
{ 
    ll n,w,i;
  cin>>n>>w;
  ll a[n],b[n];
  for(i=0;i<n;i++)
    cin>>a[i]>>b[i];
    cout << knapSack(w,a,b, n); 
    return 0; 
} 

Measured memory_bytes: 79488
#include <iostream>
#include <cmath>

using namespace std;

int a[10];

int main()
{
	int n;
	cin>>n;
	
	for (int i=1;i<=n;++i){
		string s;
		cin>>s;
		
		if (s[0]=='A')
			a[1]++;
		if (s[0]=='W')
			a[2]++;
		if (s[0]=='T')
			a[3]++;
		if (s[0]=='R')
			a[4]++;
	}
	
	cout<<"AC "<<"x "<<a[1]<<endl;
	cout<<"WA "<<"x "<<a[2]<<endl;
	cout<<"TLE "<<"x "<<a[3]<<endl;
	cout<<"RE "<<"x "<<a[4]<<endl;
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
    return (a.second > b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
     fast;
     //int t;
     //cin>>t;
     //while(t--)
     {
      ll i,j,c=0,d=0,sum=0,e=0,f=0,g=0,h=0,n,maxi=0;
       cin>>n;
       for(i=1;i<=n;i++)
       {
        if((i%3!=0)&&(i%5!=0))
        {
            sum+=i;
        }
       }
       cout<<sum;
     }

}



Measured memory_bytes: 3648
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	int k;
	string s;
	cin >> k >> s;

	int n = s.size();

	if (n <= k) cout << s << endl;
	else {
		rep(i, 0, k) cout << s[i];
		cout << "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3628
#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
A = [LI() for _ in range(N)]


def main():
    ans = 0
    for i in range(N):
        for j in range(N):
            flag = True
            for k in range(N):
                if i == k or j == k:
                    continue
                d = A[i][k] + A[k][j]
                if A[i][j] > d:
                    print(-1)
                    return
                if A[i][j] == d:
                    flag = False
            if flag:
                ans += A[i][j]
    ans //= 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42332
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 1e5 + 5;

int A[N];

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));
	
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	sort(A, A + n), reverse(A, A + n);
	int p = 0;
	while (p < n && A[p] > p) p++;
	p--;
	int x = A[p] - p, y = 0;
	while (p + y < n && A[p + y] > p) y++;
	if (x % 2 == 1 && y % 2 == 1) cout << "Second" << endl;
	else cout << "First" << endl;

	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabr(i, a, b) for(int i = int(b)-1; i >= int(a); i--)
#define all(X) X.begin(), X.end()

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		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;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////



int main() {
	ll N;
	cin >> N;
	vll A(N + 1);
	repn(i, N)cin >> A[i];

	mint s = 0;
	repn(i, N)s += A[i];

	mint ans = s * s;
	repn(i, N)ans -= A[i] * A[i];
	ans /= 2;
	cout << ans << endl;
}


Measured memory_bytes: 4776
#include <stdio.h>
int main(void){
  int i, j, cnt = 0, flag, k;
  int numbers[100];
 
  scanf("%d", &k);
   
  for(i = 0;i < k;i++){
    scanf("%d", &numbers[i]);
  }
 
  flag = 1;
  while(flag){
    flag = 0;
      for(j=k-1;j>=1;j--){
        if(numbers[j] < numbers[j-1]){
          i = numbers[j-1];
          numbers[j-1] = numbers[j];
          numbers[j] = i;
          flag = 1;
          cnt++;
        }
      }
 
  }
  for(i = 0;i < k-1;i++){
    printf("%d ", numbers[i]);
  }
  printf("%d\n", numbers[i]);
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
 
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
 
  int c = 1;
  int n = 0;
  while(true) {
    if(c >= b) {
      cout << n << endl;
      return 0;
    }
 
    c += a-1;
    n++;
  }
 
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int N;
  string s;

  cin >> N >> s;

  if (N % 2 == 1) {
    goto NO;
  } else {
    for (int i = 0; i < s.size() / 2; ++i) {
      if (s[i] != s[s.size() / 2 + i])
        goto NO;
    }
    goto YES;
  }
YES:
  cout << "Yes" << endl;
  return 0;
NO:
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define d 1000000007
int mp(long long m,int n){return n?(mp((m*m)%d,n/2)*((n%2)?m:1)%d):1;}
int main(){
    int m,n;
    scanf("%d%d",&m,&n);
    printf("%d\n",mp((long long)m,n));
    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   double a,b,old=0.08,now=0.1;
   cin>>a>>b;

   rep(i,int(b)*10,int(b)*10+9){
      if(int(i * old) == int(a)){
         cout<<i<<'\n';
         return 0;
      }
   }

   cout<<-1<<'\n';
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '



signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N, D;
    scanf("%d%d",&N,&D);
    vector<int> d(N);
    times(N, i) scanf("%d",&d[i]);

    vector<long> z(N+1);
    times(N, i) z[i+1] = z[i] + d[i] > D ? max(z[i], 2 * D - (z[i] + d[i])) : z[i] + d[i];

    vector<bool> p(N);
    long s = 0;
    rtimes(N, i) {
        p[i] = D - s > z[i];
        //cout << D-s sp << z[i] ln;
        if(d[i] / 2 <= s) s += d[i];
    }

    int Q;
    scanf("%d",&Q);

    times(Q, j) {
        int q;
        scanf("%d",&q);
        printf(p[q-1] ? "YES\n" : "NO\n");
    }

    return 0;
}


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

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

int main() {
  int n;
  cin >> n;
  vector<i64> a(n);
  int n2 = log(1e13) / log(2) + 2;
  int n5 = log(1e13) / log(5) + 2;
  vector<i64> cnt(n2 * n5, 0);
  for (i64& x : a) {
    long double f;
    cin >> f;
    x = f * 1e9 + 0.5;
    int c2 = 0, c5 = 0;
    while (x % 2 == 0) {
      c2++;
      x /= 2;
    }
    while (x % 5 == 0) {
      c5++;
      x /= 5;
    }
    cnt[c2 * n5 + c5]++;
  }
  i64 ans = 0;
  rep(i, n2 * n5) {
    for (int j = i; j < n2 * n5; j++) {
      int i2 = i / n5, i5 = i % n5;
      int j2 = j / n5, j5 = j % n5;
      if (i2 + j2 < 18 || i5 + j5 < 18) continue;
      if (i == j) {
        ans += cnt[i] * (cnt[i] - 1) / 2;
      } else {
        ans += cnt[i] * cnt[j];
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 4764
import static java.util.Arrays.*;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int[] count = new int[100];
		for (;;) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			if (a == -1 && b == -1) break;
			++count[a];
			++count[b];
		}
		++count[0];
		++count[1];
		boolean ok = true;
		for (int i = 0; i < 100; i++) if (count[i] % 2 == 1) ok = false;
		out.println(ok ? "OK":"NG");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	Scanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

}

Measured memory_bytes: 24168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>

using namespace std;

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

const int N=(int)1e5+7;
const long long inf = (long long)1e16 + 7;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a*100+b*10+c)%4==0) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll mod_pow(ll x, ll n, ll mod = MOD) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

int main() {
	int N;
	cin >> N;
	
	vector<ll> C(N);
	REP(i, N) cin >> C[i];
	
	sort(ALL(C));
	
	if (N == 1) {
		cout << C[0] * 2 % MOD << endl;
		return 0;
	}
	
	ll p21 = mod_pow(2, N - 2);
	p21 = p21 * p21 % MOD; // 2^(N-2) ^2
	
	ll ans = 0;
	REP(i, N) {
		ans = (ans + C[i] * p21 % MOD * 4 % MOD * (N - i - 1)) % MOD;
	}
	
	ll p22 = mod_pow(2, N - 1);
	p22 = p22 * p22 % MOD;
	REP(i, N) ans = (ans + C[i] * p22 % MOD * 2 % MOD) % MOD;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()




int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    double M = 0;
    int ans_w = 100 * a;
    int ans_s = 0;
    vector<int> water_sizes(31, 0);
    rep (i, 31) {
        rep (j, 31) {
            int water_size = i * a + j * b;
            if (water_size >= 31) continue;
            water_sizes[water_size] = 1;
        }
    }
    rep (water_size, 1, water_sizes.size()) {
        if(water_sizes[water_size] == 0) {
            continue;
        }
        int sugar_capacity = e * water_size;
        rep (sugar_size, sugar_capacity+1) {
            if (water_size * 100 + sugar_size > f) {
                break;
            }
            bool sugar_configurable = false;
            for (int c_i = 0; c_i * c <= sugar_size; ++c_i) {
                if ((sugar_size - c_i * c) % d == 0) {
                    sugar_configurable = true;
                    break;
                }
            }
            if (sugar_configurable) {
                if (chmax(M, 1.0 * sugar_size / (water_size * 100 + sugar_size))) {
                    ans_w = water_size * 100;
                    ans_s = sugar_size;
                }
            }
        }
    }
    cout << ans_w + ans_s << " " << ans_s << endl;
}



Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    CIN(N);
    V v;
    REP(a,N){
        CIN(b);v.pb(b);
    }
    sort(ALL(v));
    COUT(v.back()-v.front());
    return 0;
}


Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
# mod = 998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 1<<32-1
# INF = 10**18

#UnionFindのクラス,0-indexed
class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents = [-1,0,-4,1,1,1]のように、親の添字かマイナス要素数を表す
        self.parents = [-1] * n

    def find(self, x): # find: xの親がすべてrootになる。これにより計算量削減(O(N) for all (not each))
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n = int(ipt())
    xs = []
    ys = []
    for i in range(n):
        x,y = map(int,ipt().split())
        xs.append(x*n+i)
        ys.append(y*n+i)
    xs.sort()
    ys.sort()
    ways = []
    x0 = xs[0]//n
    xi = xs[0]%n
    y0 = ys[0]//n
    yi = ys[0]%n
    for i in xs[1::]:
        x = i//n
        j = i%n
        ways.append((x-x0)*(n**2)+xi*n+j)
        x0 = x
        xi = j
    for i in ys[1::]:
        y = i//n
        j = i%n
        ways.append((y-y0)*(n**2)+yi*n+j)
        y0 = y
        yi = j

    ways.sort()
    ans = 0
    uf = UnionFind(n)
    for i in ways:
        d = i//(n**2)
        i1 = (i//n)%n
        i2 = i%n
        # print(i,d,i1,i2)
        if not uf.same(i1,i2):
            uf.union(i1,i2)
            ans += d

    print(ans)

    return None

if __name__ == '__main__':
    main()


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

using namespace std;

#define ll long long

const int N = (int)1e5 + 7;
const int mod = (int)1e9 + 7;

int a[N], b[N];
int dp[N];
ll ans = 1;

main() {
    int n; scanf ("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", a + i);
    }
    for (int i = 1; i <= n; i++) {
        scanf ("%d", b + i);
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);

    for (int i = 1; i <= n; i++) {
        int l = i, r = n;
        int q = i;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (a[mid] <= b[i]) {
                l = mid;
                q = mid;
            } else {
                r = mid;
            }
        }
        if (a[r] <= b[i]) q = r;
        l = i, r = n;
        int p = i;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (b[mid] <= a[i]) {
                l = mid;
                p = mid;
            } else {
                r = mid;
            }
        }
        if (b[r] <= a[i]) p = r;
        ans *= (max(p, q) - i + 1);
        ans %= mod;
    }
    printf ("%lld", ans);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
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;}
using Ps=pair<int,string>;

int main(){
    int n;
    cin>>n;
    map<string,int>mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    printf("AC x %d\n",mp["AC"]);
    printf("WA x %d\n",mp["WA"]);
    printf("TLE x %d\n",mp["TLE"]);
    printf("RE x %d\n",mp["RE"]);
    return 0;
}

Measured memory_bytes: 3724
solve :: String -> Int
solve [] = 0
solve ss@(_:xs)
    | odd l = solve xs
    | otherwise = let (a, b) = splitAt (l `div` 2) ss
                  in if a == b then l else solve xs
    where
        l = length ss

main :: IO ()
main = do
    s <- getLine
    print $ solve (reverse $ init s)


Measured memory_bytes: 892