akhauriyash/Code-Regression huggingface dataset:
//#include <ext/pb_ds/assoc_container.hpp> 
    // #include <ext/pb_ds/tree_policy.hpp> 
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <cstring>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <set>
    #include <map>
    #include <valarray>
    #include <iterator>
    #include <functional>
    #include <limits>
    #include <algorithm>
    #include <numeric>
    #include <cmath>
    #include <cassert>
    #include <unordered_map>
    #include <unordered_set>
    #include <stack>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define trace(x) cerr << #x << ": " << x << " " << endl;
     
    typedef int64_t ll;
     
    #define endl '\n'
    #define int ll
    ll mod=1e17;
    ll mod1=1e9+5;
     
    ll power(ll a,ll b)
    {
        if(b==0) return 1;
        else if(b%2==0)
            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
    }
     
    // using namespace __gnu_pbds;
    // #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
    //find_by_order(k)  returns iterator to kth element starting from 0;
    //order_of_key(k) returns count of elements strictly smaller than k;
    //erase,insert same as normal set
     int h,n;
       pair<int,int> p[1000+1];
       int dp[20001][1001];
        vector<pair<double,int>> v;
    int solve(int sum,int i)
    {
        if(sum>=h)
            return 0;
        if(i==n+1)
        {
            return 1e15;
        }
        int &res=dp[sum][i];
        if(res!=-1)
            return res;
        res=1e15;
        
        int ind=v[i-1].second;
        int init=(h-sum)/(p[ind].first);
        for(int j=max(init-10,(ll)0);j<=(h-sum)/(p[ind].first)+10;++j)
        {
            res=min(res,(p[ind].second)*j+solve((p[ind].first)*j+sum,i+1));
        }
        return res;
    }
    int32_t main()
    {
        IOS
 
        
      
       cin>>h>>n;
     
       for(int i=1;i<=n;++i)
        cin>>p[i].first>>p[i].second;
   
    for(int i=1;i<=n;++i)
    {
        double x=(double)p[i].first/(double)p[i].second;
        v.push_back({x,i});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    memset(dp,-1,sizeof(dp));
    cout<<solve(0,1);



    }       

Measured memory_bytes: 156800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9 + 10)
#define PI (acos(-1))
#define MOD (1000000007)
#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 debug(x) cout<<#x<<": "<<x<<endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    int a[N], b[N];
    REP(i, N) {
        cin >> a[i];
    }
    REP(i, N) {
        cin >> b[i];
    }

    ll ans = 0;
    REP(i, N) {
        ans ^= a[i];
        ans ^= b[i];
    }
    ll temp = 0;
    REP(i, N) {
        temp ^= ans;
    }
    ans = temp;
    int am[N];
    int bm[N];
    REP(d, 29) {
        ll mod = pow(2, d);
        int c = 0;
        REP(i, N) {
            am[i] = a[i] % mod;
            bm[i] = b[i] % mod;
        }
        sort(bm,bm+N);
        REP(i, N) {
            ll key = mod - am[i];
            c ^= (bm+N - lower_bound(bm, bm+N, key))%2;//end - lowerboundで以上の数。
        }
        ans ^= (c << d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n; 
  vi p(n); rep(i,n) cin >> p[i];
  int ans = 0;
  auto comp = [](int a, int b, int c) {
    return (a < b && b < c) || (a > b && b > c);
  };
  for (int i=1; i<n-1; i++) {
    if (comp(p[i-1], p[i], p[i+1])) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let mut A = read![[usize]];
    A.sort();
    let mut d = 0;
    for i in 1..A.len() {
        d += A[i] - A[i - 1];
    }
    println!("{}", d);
    return;
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 

const int N = 1e6 + 2;

int spf[N];

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<N; i++) 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<N; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<N; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<N; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 


vector<bool> vis(N, 0);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    // #endif
    sieve();
    // int T;cin>>T;while(T--) 
    {
        ll n;
        cin>>n;
        vector<ll> a(n);
        ll g=0;
        for(auto &it: a)
            cin>>it, g = gcd(it, g);
        if(g>1) {
            cout<<"not coprime"<<endl;
            return 0;
        }
        for(auto x: a) {
            set<int> s;
            while (x != 1) 
            { 
                s.insert(spf[x]);
                x = x / spf[x]; 
            }
            for(auto it: s) {
                if(vis[it]) {
                    cout<<"setwise coprime"<<endl;
                    return 0;
                }
                vis[it] = 1;
            }
        }
        cout<<"pairwise coprime"<<endl;
    }
    return 0;
}

Measured memory_bytes: 14988
N=int(input())
S=input()
a=0
b=0
for i in S:
    if i=="(":
        if b>0:
            a+=b
            b=0
        b-=1
    if i==")":
        b+=1
a+=max(b,0)
S="("*a+S
a=0
b=0
for i in S[::-1]:
    if i==")":
        if b>0:
            a+=b
            b=0
        b-=1
    if i=="(":
        b+=1
a+=max(b,0)
S+=")"*a
print(S)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int MOD=MOD2;

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
         int a,b;
         cin>>a>>b;
         cout<<a*b<<endl;
      } 
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        ostringstream oss;
        oss << setw(3) << setfill('0') << i;
        string t = oss.str();

        int p = 0;
        for (char c : s) {
            if (t[p] == c) p++;
            if (p == 3) break;
        }
        if (p == 3) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    int N,K;
    cin >> N >> K;
    ll  ans = 0;
    rep(i,0,N){
        int tmp;
        cin >> tmp;
        ans += 2LL * min(abs(tmp),abs(K-tmp));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int INFTY=(1<<20);
int n;
vector<pair<int,int> >adj[10000];
void di()
{
    priority_queue<pair<int,int> >PQ;
    int c[10000],d[10000];
    for(int i=0;i<n;i++)
        d[i]=INFTY;
    d[0]=0;
    PQ.push(make_pair(0,0));
    while(!PQ.empty())
    {
        pair<int,int>f=PQ.top();PQ.pop();
        int u=f.second;
        c[u]=BLACK;
        if(d[u]<f.first*(-1))continue;
        for(int j=0;j<adj[u].size();j++)
        {
            int v=adj[u][j].first;
            if(c[v]==BLACK)continue;
            if(d[v]>d[u]+adj[u][j].second)
            {
                d[v]=d[u]+adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                c[v]=GRAY;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
    }
}
int main()
{
    scanf("%d",&n);
    int a,b,c,d;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        for(int j=0;j<b;j++)
        {
            scanf("%d %d",&c,&d);
            adj[a].push_back(make_pair(c,d));
        }
    }
    di();
    return 0;
}

Measured memory_bytes: 8000
# coding: utf-8
# Your code here!

N = int(input())

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


A = sorted(A)
ans = A[-1] - A[0]
A_nashi = A[1:-1]

plus = len(A_nashi)
for i in range(len(A_nashi)):
    if A_nashi[i] >= 0:
        plus = i
        break

ans += sum(A_nashi[plus:]) - sum(A_nashi[:plus])

print(ans)

res = A[0]
for i in range(len(A_nashi) - plus):
    print(res,A_nashi[-i-1])
    res -= A_nashi[-i-1]
    
print(A[-1], res)
res = A[-1] - res

for i in range(plus):
    print(res,A_nashi[i])
    res -= A_nashi[i]
    

Measured memory_bytes: 14016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
/*  i <= j;
  j - i = A_i + A_j;
  j-A_j=x;
  i+A_i=x;
  */
int main()
{
  int n;
  cin >> n;
  map<ll, ll> L, R;
  ll ans = 0;
  rep(i, n)
  {
    ll A;
    cin >> A;
    ans += L[i - A];
    ans += R[i + A];
    L[i + A]++;
    R[i - A]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 48876
#include<iostream>
#include <string>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define mp make_pair
#define sz(v) (int)(v.size())
#define len(s) (int)(s.length())
#define M 1000000007
#define all(v) v.begin(),v.end()
#define fr(a,b,c) for(ll i=a;i<=b;i+=c)
#define inarr(arr,n); for(ll i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(ll i=0;i<n;i++) cout<<arr[i]<<" ";
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf = 9e18;
const ld pi = 2*acos(0.0); 
using namespace std;
ll power(ll a,ll n) 
{
    if(n==0){
        return 1;
    }
    ll p=power(a,n/2) % M;
    p = (p * p) % M;
    if (n%2==1)
    {
        p=(p*a)%M;
    }
    return p;
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
const int N=1e6+5;
vector <ll> sieve(N,0); 
void si() 
{
    sieve[1]=1;
    for(int i=2;i<N;i++){
        if(sieve[i]==0){
            for(int j=i;j<N;j+=i){
                sieve[j]=i;
            }
        }
    }
}
void dfs(vector <ll> a[],vector <ll> &visited,ll pos,ll val){
    visited[pos]=val;
    for(int i=0;i<sz(a[pos]);i++){
        if(visited[a[pos][i]]==0){
            dfs(a,visited,a[pos][i],val);
        }
    }
    return ;
}
int main(){
    ios;
    int n,m;
    cin>>n>>m;
    vector <ll> a[n+1];
    for(int i=0;i<m;i++){
        ll u,v;
        cin>>u>>v;
        a[u].pb(v);
        a[v].pb(u);
    }
    vector <ll> visited(n+1,0);
    for(int i=1;i<=n;i++){
        if(visited[i]==0){
            dfs(a,visited,i,i);
        }
    }
    map <ll,ll> mm;
    for(int i=1;i<=n;i++){
        mm[visited[i]]+=1;
    }
    ll ans=0;
    for(auto itr:mm){
        ll val=itr.second;
        ans=max(ans,val);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	int n,x,y;
	cin >> n;
	vector<int> h(n+4,0);
	for(int i = 1;i<=n;i++) cin >> h[i];
	h[0] = h[1];
	vector<int> dp(n+4,0);
	for(int i = 2;i<=n;i++){
		x = abs(h[i]-h[i-1]) + dp[i-1];
		y = abs(h[i]-h[i-2]) + dp[i-2];
		dp[i] += min(x,y);
	}
	printf("%d\n",dp[n]);
	return 0;
}
	


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    string S,T;
    cin >> S >> T;

    // resolve
    int ans=0;
    for (int i=0; i<S.size(); i++) {
        if (S[i] != T[i])ans++;
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
long long n,i,j,c,x,a,b;
bool res=true;
int main(){
  cin>>n>>a>>b;
  if(a&1&&b&1||!(a&1)&&!(b&1))cout<<b-(a+b)/2;
  else cout<<min(n-b,a-1)+(b-a-1)/2+1;
}

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

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

    ll S,W;
    cin>>S>>W;

    string ans;
    if(W>=S){
        ans = "unsafe";
    }else{
        ans = "safe";
    }
	
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3652
iN = int(input())
iLim = int(iN**0.5) + 1

iMinMax = len(str(iN))
for i in range(iLim+1,0,-1):
    if iN % i == 0:
        iMax = max(i,iN//i)
        iMinMax = min(len(str(iMax)),iMinMax)
print(iMinMax)


Measured memory_bytes: 2940
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }

    input! {
        s: String,
        t: String
    }

    let mut maps = BTreeMap::<char, usize>::new();
    let mut mapt = BTreeMap::<char, usize>::new();

    for c in s.chars() {
        *maps.entry(c).or_insert(0) += 1;
    }
    for c in t.chars() {
        *mapt.entry(c).or_insert(0) += 1;
    }

    let mut sv = vec![];
    let mut tv = vec![];
    for (_, n) in maps {
        sv.push(n);
    }
    for (_, n) in mapt {
        tv.push(n);
    }
    sv.sort();
    tv.sort();

    println!("{}", if sv == tv { "Yes" } else { "No" });
}
fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
from functools import reduce
from fractions import gcd

MOD = 10**9+7

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def main():
    N = int(input())
    a = [int(i) for i in input().split()]

    lcm = reduce(lcm_base, a, 1)
    
    ans = 0
    for i in a:
        ans += lcm // i

    print(ans % MOD)


if __name__ == "__main__":
    main()


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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

int main()
{
    long double circum;
    ll r;

    cin>>r;

    circum = (long double)(2*22*r)/(long double)7;

    cout<<setprecision(10)<<circum<<endl;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
	int n;
	cin>>n;
	int ans=0,sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<=a[i-1])sum++;
		else {
			ans=max(ans,sum);
			sum=0;
		}
	}
	ans=max(ans,sum);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
	int n,l,min=10000,sum=0;
	scanf("%d%d",&n,&l);
	int apple[n];
	for(int i=0;i<n;i++){
		apple[i]=l+i;
		if(apple[i]==0)min=0;
	}

	for(int i=0;i<n;i++){
		sum+=apple[i];
	}
	for(int i=0;i<n;i++){
		if(min==0)break;
		if(min>sum-abs(sum-apple[i]))min=sum-(sum-apple[i]);
	}
	printf("%d\n",sum-min);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

vector <int> edges[100000];

bool used[100000];
vector <int> path[2];

void dfs(int v, int path_ind){
    used[v] = true;
    path[path_ind].push_back(v);
    for(int i = 0; i < edges[v].size(); i++){
        if(!used[edges[v][i]]){
            dfs(edges[v][i], path_ind);
            break;
        }
    }
}

int main(){
    int N;
    int M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int A;
        int B;
        cin >> A >> B;
        edges[A-1].push_back(B - 1);
        edges[B-1].push_back(A - 1);
    }

    if(edges[0].size() < 2){
        dfs(0, 0);
    } else {
        dfs(0, 0);
        for(int i = 0; i < edges[0].size(); i++){
            if(!used[edges[0][i]]){
                dfs(edges[0][i], 1);
                break;
            }
        }
    }
    
    vector <int> ans = path[0];
    reverse(ans.begin(), ans.end());
    ans.insert(ans.end(), path[1].begin(), path[1].end());

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        if(i != ans.size() - 1){
            cout << ans[i] + 1 << " ";
        } else {
            cout << ans[i] + 1<< endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using V = vector<int>;
using VV = vector<vector<int>>;
int Inf = (1<<30);
ll inf = (1LL<<60);
int main() {
	int k;
	cin >> k;
	int s;
	cin >> s;
	int x, y;
	int ans = 0;
	for (x = 0; x <= k; x++) {
		for (y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z && z <= k) ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import copy
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x,k,d=INTM()
    if abs(x)-k*d>0:
        flg=1
        ans=abs(x)-k*d
    else:
        flg=2
        a=x%d
        b=a-d
        #c,d=max(a,abs(b)),min(a,abs(b))
        if (k-((x-a)//d))%2==0:
            flg=3
            ans=abs(a)
        else:
            flg=4
            ans=abs(b)
            
    print(ans)
    #print(a,b,flg)
    #print(((x-a)//d))
    
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 9344
/**
 *    Author  : Ador
 *    Created : 24.07.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
        //freopen("input.txt", "r", stdin) ;
        //freopen("output.txt", "w", stdout) ;
    int t ; cin >> t ;
    int i , x , cnt = 0 ;
    for(i = 1 ; i <= t ; ++i)
    {
        cin >> x ;
        if(i % 2 and x % 2) ++cnt ;
    }
    cout << cnt << "\n" ;
    return 0 ;
}


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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	int n; cin >> n;
	bool flag = true;
	int T = 0, X = 0, Y = 0;
	Rep(i, n){
		int t, x, y; cin >> t >> x >> y;
		int d = abs(T-t) - (abs(X-x) + abs(Y-y));
		if(d < 0 || d % 2 != 0){
			flag = false;
		}
		T = t; X = x; Y = y;
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	_, M := sc.i(), sc.i()
	n := 2*M + 1
	if M%2 == 1 {
		for i := 0; i < M/2; i++ {
			fmt.Printf("%d %d\n", i+1, M-i)
		}
		for i := 0; i < M/2+1; i++ {
			fmt.Printf("%d %d\n", M+1+i, n-i)
		}
	} else {
		for i := 0; i < M/2; i++ {
			fmt.Printf("%d %d\n", i+1, M+1-i)
		}
		for i := 0; i < M/2; i++ {
			fmt.Printf("%d %d\n", M+2+i, n-i)
		}
	}
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}


Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    int a,b,c;
    while(~scanf("%d%d%d", &a, &b, &c))
    {
        int flag=1;
        for(int i=1;i<=20000;++i)
        {
            if((a*i%b)==c)
            {
                cout<<"YES"<<endl;
                flag=0;
                break;
            }
        }
        if(flag) cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L, R, i;
  cin >> N;
  int S = 0;
  for(i = 0;i < N;i++){
    cin >> L >> R;
   S = S + R - L + 1;
  }
  cout << S << endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static int GCD(int a, int b) {
        if (b == 0)
            return a;
        else
            return GCD(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int ans = GCD(x, y);
        System.out.println(ans);
        sc.close();
    }
}


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

N, M = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

s = sum(L)
d = set()
for i in range(1, int(s ** 0.5) + 1):
    if s % i == 0:
        d.add(i)
        d.add(s // i)
        
d = list(d)
d.sort(reverse = True)

ans = 1
for n in d:
    p = [v % n for v in L]
    p.sort()
    pc = n * N - sum(p)
    mc = 0
    for v in p:
        pc -= (n - v)
        mc += v
        
        if pc == mc:
            break
                
    if pc <= M:
        ans = max(ans, n)

print(ans)

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


struct Node {
    int num;
    int parent;
    int pl;
    vector<int> children;
    Node(int n) {
        num = n;
        parent = -1;
        pl = -1;
    }
};


int N, M;
vector<int> A, B, L, R, visit, ans;
vector<pair<int, int>> AB;
vector<vector<pair<int, int>>> link;
vector<Node> nl;


void input() {
    cin >> N >> M;  
    A = B = vector<int>(N);
    L = R = vector<int>(M);
    rep(i, N) cin >> A[i] >> B[i];
    rep(i, M) cin >> L[i] >> R[i];
}


void make_tree(int v) {
    visit[v] = 1;
    for (auto p : link[v]) {
        if (visit[p.first]) continue;
        nl[v].children.push_back(p.first);
        nl[p.first].parent = v;
        nl[p.first].pl = p.second;
        make_tree(p.first);
    }
}


void solve(int v) {
    for (int child : nl[v].children) solve(child);
    if (nl[v].parent == -1) return;
    if (nl[v].num == 1) {
        ans.push_back(nl[v].pl + 1);
        nl[nl[v].parent].num ^= 1;
    }
}


int main() {
    input();
    AB = vector<pair<int, int>>(N);
    rep(i, N) AB[i] = make_pair(A[i], B[i]);
    sort(AB.begin(), AB.end());
    nl.push_back(Node(AB[0].second));
    rep(i, N-1) nl.push_back(Node(AB[i].second ^ AB[i+1].second));
    nl.push_back(Node(AB.back().second));
    link = vector<vector<pair<int, int>>>(N+1);
    sort(A.begin(), A.end());
    rep(i, M) {
        auto x = lower_bound(A.begin(), A.end(), L[i]);
        int l = distance(A.begin(), x);
        auto y = upper_bound(A.begin(), A.end(), R[i]);
        int r = distance(A.begin(), y);
        if (l == r) continue;
        link[l].push_back(make_pair(r, i));
        link[r].push_back(make_pair(l, i));
    }
    visit = vector<int>(N+1, 0);
    rep(i, N+1) {
        if (visit[i]) continue;
        make_tree(i);
        solve(i);
        if (nl[i].num == 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size();
    if (ans.size()) cout << endl;
    for (int x : ans) cout << x << " ";
    cout << endl;
}


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

using namespace std;

int main()
{ ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0) ;
   bool x[4] ;
   memset(x,false,sizeof(x)) ;
  long long a, b ;
  cin >>a>>b;
  x[a] = true;
  x[b] = true;
  for (int i = 1 ; i<=3; i++)
  if ( x[i] == false) { cout<<i; return 0;}


    return 0;
}


Measured memory_bytes: 384
import 'dart:io';

main(List<String> args) {
  var K = int.parse(stdin.readLineSync());
  List<int> AB =
      stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  if (AB[0] ~/ K < AB[1] ~/ K || AB[0] % K == 0) {
    print("OK");
  } else {
    print("NG");
  }
}


Measured memory_bytes: 13132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k, sum, a[505], b[505];
int comp(ll a, ll b){
	return a>b;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		scanf("%lld", &a[i]);
		sum+=a[i];
	}
	for(int i=1;i*i<=sum;i++){
		if(sum%i==0){
			ll p=sum/i, now=0, ret=0, r=i;
			for(int j=1;j<=n;j++) b[j]=a[j]%p, r-=a[j]/p;
			sort(b+1, b+n+1, comp);
			for(int j=1;j<=r;j++) {
				ret+=p-b[j];
				if(ret>k) break;
			}
			if(ret<=k) {
				cout<<p;
				return 0;
			}
		}
	}
	for(int i=sqrt(sum+0.5);i>=1;i--){
		if(sum%i==0){
			ll p=i, now=0, ret=0, r=sum/i;
			for(int j=1;j<=n;j++) b[j]=a[j]%p, r-=a[j]/p;
			sort(b+1, b+n+1, comp);
			for(int j=1;j<=r;j++) {
				ret+=p-b[j];
				if(ret>k) break;
			}
			if(ret<=k) {
				cout<<p;
				return 0;
			}
		}
	}
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	vector<int> v(n + 2);
	rep(i, 1, n + 1) cin >> v[i];
	v[0] = 0, v[n + 1] = 0;
	
	ll sum = 0;
	rep(i, 1, n + 2) sum += abs(v[i] - v[i - 1]);

	rep(i, 1, n + 1) {
		cout << (sum - abs(v[i] - v[i - 1]) - abs(v[i + 1] - v[i]) + abs(v[i + 1] - v[i - 1])) << endl;
	}
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i >=stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

//累乗 a**n%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;
}

ll L;
ll b;

int check(ll n){
    FOR(i,0,21){
        if(modpow(2,i,MOD)-1<=n && n<modpow(2,i+1,MOD)-1){
            b=n-modpow(2,i,MOD)+1;
            return i+1;
        }
    }

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>L;
    L--;
    b=0;
    int a=check(L);
    cout<<a<<' '<<(a-1)*2 + __builtin_popcount(L+1) - 1<<endl; //?

    FOR(i,0,a-1){
        cout<<i+1<<' '<<i+2<<' '<<0<<endl;
        cout<<i+1<<' '<<i+2<<' '<<modpow(2,i,MOD)<<endl;
    }
    
    ll c=L-(modpow(2,a-1,MOD)-1);
    //cout<<c<<endl;
    FORR(i,a-1,0){
        if(c>=modpow(2,i,MOD)){
            //cout<<c<<modpow(2,i,MOD)<<endl;
            cout<<i+1<<' '<<a<<' '<<L-c+1<<endl;
            c-=modpow(2,i,MOD);
        }
    }
    //cout<<c<<endl;
    
}
//100

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	long long s=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		if(i<=k) continue;
		s+=(i-k)*(n/i);
		s+=max(n%i-k+1,0);
	}
	if(k==0) s-=n;
	cout<<s;
}

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

int N, A, B, C, X;
int Y[210];

int solve() {
  int cur = 0;
  for (int i = 0; i <= 10000; ++i) {
    if (Y[cur] == X) ++cur;
    if (cur == N) return i;
    X = (X * A + B) % C;
  }
  return -1;
}

int main() {
  while (cin >> N >> A >> B >> C >> X) {
    if (N == 0) break;
    for (int i = 0; i < N; ++i) cin >> Y[i];
    cout << solve() << endl;
  }
}


Measured memory_bytes: 1160
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();

		int[] index = new int[3];
		int current = 'a';
		while (true) {
			if (current == 'a') {
				if (index[0] == a.length) {
					System.out.println('A');
					return;
				}
				current = a[index[0]++];
			} else if (current == 'b') {
				if (index[1] == b.length) {
					System.out.println('B');
					return;
				}
				current = b[index[1]++];
			} else if (current == 'c') {
				if (index[2] == c.length) {
					System.out.println("C");
					return;
				}
				current = c[index[2]++];
			} else {
				throw new RuntimeException("FAILED");
			}
			System.err.println((char) current);
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 8332
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
ans=0

for x in range(0,n+1):
  a1sum=sum(a1[0:x+1])
  a2sum=sum(a2[x:n+1])
  ans=max(ans,a1sum+a2sum)
  
print(ans)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,p,k,j,q;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
    {
       cin>>a[i];
    }k=0;m=0;
    sort(a,a+n);
    for(i=0; i<n; i++)
    {
        k+=a[i];
        //k%=1000000007;
    }
    //k=(k*k)%10000000007;
    for(i=0; i<n; i++)
    {
        k-=a[i];
        m+=((k%1000000007)*a[i])%1000000007;
        m%=1000000007;
    }
    cout<<m;
}



Measured memory_bytes: 4400
def examA():
    K, X = LI()
    if K*500>=X:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    N = I()
    S = SI()
    ans = 0
    for i in range(N-2):
        if S[i:i+3]=="ABC":
            ans +=1
    print(ans)
    return

def examC():
    N = I()
    P = LI()
    Q = LI()
    Cp = [i for i in itertools.permutations(P,N)]; Cp.sort()
    Cq = [i for i in itertools.permutations(Q, N)]; Cq.sort()
#    print(Cp)
#    print(Cq)
    for k,i in enumerate(Cp):
        flag = True
        for j in range(N):
            if P[j]!=i[j]:
                flag = False
                break
        if flag:
            a = k
            break
    for k,i in enumerate(Cq):
        flag = True
        for j in range(N):
            if Q[j]!=i[j]:
                flag = False
                break
        if flag:
            b = k
            break
    ans = abs(a-b)
    print(ans)
    return

def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x
def lcm(x, y):
    return x * y // gcd(x, y)
def examD():
    N, M = LI()
    A = LI()
    flag = 0
    for i in range(1,32):
        if A[0]%(2**i)==0:
            flag +=1
        else:
            break
#    print(flag)
    for a in A:
        cur = 0
        for i in range(1, 32):
            if a % (2 ** i) == 0:
                cur += 1
            else:
                break
        if cur!=flag:
            print(0)
            return
    cur = A[0]
    for i in range(1,N):
        cur = lcm(cur,A[i])
        if cur>2*M:
            print(0)
            return
    ans = 1 + (M-cur//2)//cur
    print(ans)
    return

def examE():
    N = I()
    C = LI(); C.sort(reverse = True)
    sumC = sum(C)
    sumC %=mod
    Cp = pow(2,N*2-2,mod)
    cur = (sumC*Cp*2) %mod
#    print(cur)
    for i in range(1,N):
        now = (Cp*C[i]*(i)) %mod
        cur +=now
        cur %=mod
    ans = cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()


Measured memory_bytes: 81520
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

bool isvowel(char c) {
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') return true;
	return false;
}

string tocode(string s) {
	const int N = s.size();
	string res;
	res += s[0];
	for (int i = 0; i < N; ++i)
		if (i < N - 1 && isvowel(s[i])) res += s[i + 1];
	return res;
}

int match(string s1, string s2) {
	const int N = min(s1.size(), s2.size());
	int res = 0;
	for (int i = 0; i < N; ++i) {
		if (s1[i] == s2[i]) res++;
		else break;
	}
	return res;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<string> s(n);
		for (int i = 0; i < n; ++i) {
			cin >> s[i];
			s[i] = tocode(s[i]);
		}
		sort(s.begin(), s.end());
		int ans = 0;
		for (int i = 1; i < n; ++i) {
			if (s[i - 1] == s[i]) {
				ans = -1;
				break;
			}
			ans = max(ans, match(s[i - 1], s[i]) + 1);
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3136