akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
ll ans = 0;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> color(2e5, 0);

void dfs(const vector<vector<int>> &G, set<pair<int, int>> &s, int u, ll &x, ll &y, bool root = true) {
  color[u] = 1; // GRAY
  if (u < 1e5) x++;
  else y++;
  for (int i = 0; i < G[u].size(); i++) {
    s.insert(make_pair(min(u, G[u][i]), max(u, G[u][i])));
    if (color[G[u][i]] == 0) dfs(G, s, G[u][i], x, y, false);
  }
  color[u] = 2; // BLACK
  if (root) {
    if (x >= 2 && y >= 2) ans += x * y - s.size();
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<vector<int>> G(2e5); // 隣接リスト
  
  for (int i = 0; i < n; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    v += 1e5;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  for (int i = 0; i < 1e5; i++) {
    if (color[i] == 0) {
      set<pair<int, int>> s;
      ll x = 0, y = 0;
      dfs(G, s, i, x, y);
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 22400
#include<bits/stdc++.h>
using namespace std;
#define int long long 
 
main(){
	int n,x,m; cin>>n>>x>>m;
	
	vector<int> v;
	vector<int> rep;
	vector<bool> visit(m + 1);
	int cnt=1, curr=x, ans=0;
	
	while(cnt <= n){
		if(!visit[curr]){
			visit[curr] = 1;
			ans += curr;
			v.push_back(curr);
			curr = (curr * curr) % m;
		}
		else{
			while(v.back()!=curr){
	            rep.push_back(v.back());
                v.pop_back();				
			}
			rep.push_back(v.back());
			break;
		}
		cnt++;
	}
	cnt--;
 	reverse(rep.begin(), rep.end());
	
	int rem_n = n-cnt;
	if(rem_n > 0){
		int cyclen = rep.size();
	    int times = rem_n / cyclen;
	    int rem = rem_n % cyclen;
	
	    for(int i=0; i<cyclen; i++){
		    ans += rep[i] * times;
		    if(i < rem) ans += rep[i];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 4232
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
using namespace std;
char c;
int main()
{
	cin>>c;
    if(c=='a'||c=='e'||c=='o'||c=='i'||c=='u') cout<<"vowel";
    else cout<<"consonant";
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
c = Counter(S)
# print(f'{c=}')

print(f'AC x {c.get("AC", 0)}')
print(f'WA x {c.get("WA", 0)}')
print(f'TLE x {c.get("TLE", 0)}')
print(f'RE x {c.get("RE", 0)}')


Measured memory_bytes: 16616
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,l,s=0,minn=INT_MAX,pos;
	scanf("%d%d",&n,&l);
	for(i=1;i<=n;i++)
	{
		s+=l+i-1;
		if(abs(l+i-1)<minn)
		{
			minn=abs(l+i-1);
			pos=i;
		}
	}
	printf("%d",s-l-pos+1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	std::string s;

	std::cin >> s;

	std::string ans[] = { "AKIHABARA", "AKIHABAR", "AKIHABRA", "AKIHABR", "AKIHBARA", "AKIHBAR", "AKIHBRA", "AKIHBR", "KIHABARA", "KIHABAR", "KIHABRA", "KIHABR", "KIHBARA", "KIHBAR", "KIHBRA", "KIHBR" };

	int pos = 0, pos2 = 0;

	for (auto& a : ans) {
		if (a == s) {
			std::cout << "YES" << std::endl;
			return 0;
		}
	}

	std::cout << "NO" << std::endl;

	return 0;
}


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

using namespace std;

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

    int64_t best = 0;
    vector<int64_t> x(5);
    int i = 0;
    for (auto &xi: x) {
        cin >> xi;
        xi = ceil(1.0*N/xi);
        best = max(xi, best);
        ++i;
    }

    cout << (best + 4);
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define endl "\n"
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef long long ll;
#define MOD 1000000007;

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

    int n; cin >> n;
    int k; cin >> k;
    ll a[n];
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    for(int i = 0; i < n - k; i++){
      if(a[i] < a[i+k]){
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }


    
    
    return 0;
}

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

using namespace std;


int main()
{
	int n;
	cin>>n;
	vector<long long> a(n);

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

	int dp[n];
	fill(dp,dp+n,0);
	dp[0] = 0;
	for(int i=1;i<n;i++)
	{
		if(i-2>=0)
			dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]),dp[i-2]+ abs(a[i] - a[i-2]));
		else
			dp[i] = dp[i-1]+ abs(a[i]-a[i-1]);
	}
	cout<<dp[n-1];
}

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

int main() {
  
  long int n;
  cin >> n;
  
  long int num = 1;
  
  long int k = n-1;
  
  if(k==1){
    cout << "1" << endl;
    return 0;
  }
  
  for(long int i=2; i*i<=k; i++){
    
    if(k%i==0){
      int a = 0;
      while(k%i==0){
        k /= i;
        a++;
      }
      
      num *= a+1;
    }
  }
  
  if(k!=1)
    num *=2;
  
  for(long int i=2; i*i<=n; i++){
    
    k=n;
    
    if(k%i==0){
      while(k%i==0){
        k /=i;
      }
      
      if(k%i==1)
        num++;
      
    }
  }
  
  cout << num << endl;
  
  return 0;
}

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

int main()
{
	float a, b;
	cin >> a >> b;
	float x = (a + b) / 2;
	if (((int)(10 * x)) % 10 == 5)
	{
		x += 0.5;

	}
	else
	{
		x = x;
	}
	cout << x << endl;

}

Measured memory_bytes: 384
s=input()
for _ in range(int(input())):
 a=input().split()
 if a[0][0]=='p':print(s[int(a[1]):int(a[2])+1])
 else:
  t=a[3]if'p'==a[0][2]else s[int(a[1]):int(a[2])+1][::-1]
  s=s[0:int(a[1])]+t+s[int(a[2])+1:]

Measured memory_bytes: 5620
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int []a = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		Arrays.sort(a);
		
		long ans = a[n-1];
		int id = n-2;
		int cnt = n-2;
		
		while(cnt > 0) {
			if(cnt >= 2) {
				ans += (long)(a[id]*2);
				cnt-=2;
			}
			else {
				ans += (long)a[id];
				cnt--;
			}
			id--;
		}
		
		System.out.println(ans);
		
		
		
	}
}


Measured memory_bytes: 60584
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
for i in range(n-1):
  if kabu==0:
    if a[i]<=a[i+1]:
      kabu += money//a[i]
      money %= a[i]
  else:
    if a[i]>a[i+1]:
      money += kabu*a[i]
      kabu = 0
print(money+kabu*a[-1])

Measured memory_bytes: 9196
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let n: u64 = read_as_vec()[0];

    let mut anses: Vec<u64> = vec![0; n as usize];

    for a in 1..n {
        for b in 1..n {
            if a * b >= n {
                break;
            }
            anses[(a * b) as usize] += 1;
        }
    }

    let mut ans = 0;
    for i in 1..anses.len() {
        ans += anses[i];
    }

    println!("{}", ans);
}


Measured memory_bytes: 9592
a=int(input())

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

li.reverse()

mins = 100000000000

isyes = True
for i in li:
    if i < mins:
        mins = i
    
    if i - mins > 1:
        isyes=False

if(isyes):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
def next_pos(x, y, W):
    if x % 2 == 0 and y == W - 1:
        return (x + 1, y)
    elif x % 2 == 0:
        return (x, y + 1)
    elif y == 0:
        return (x + 1, y)
    else:
        return (x, y - 1)


def solve(a, H, W):
    x, y = 0, 0
    c = [[""] * W for _ in range(H)]
    for i, v in enumerate(a):
        for _ in range(v):
            c[x][y] = str(i + 1)
            x, y = next_pos(x, y, W)
    return c


H, W = map(int, input().split())
N = int(input())
a = map(int, input().split())

for row in solve(a, H, W):
    print(" ".join(row))


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

const int maxh = 10004, maxn = 1005;
int H, N, a[maxn], b[maxn];

int dp[maxh];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> H >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= H; i++) {
        dp[i] = 2e9+9;
        for (int j = 0; j < N; j++) {
            dp[i] = min(dp[i],dp[max(0,i-a[j])]+b[j]);
        }
    }
    cout << dp[H] << endl;
}



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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h.at(i);
  }
  int ans = 0;
  for(int i=0; i<N; i++){
    if(h.at(i)>=K){
      ans++;
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
const ll mod = 998244353;

#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define FOr(i, s, e) for (ll i = s; i >= e; i--)

#define PI acos(-1)
#define sz 100005

void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


void solve()
{
	ll n; cin >> n;
	string st;

	while (n)
	{
		ll a = n % 26;
		//cout << a << endl;
		if (a == 0)
			a += 26, --n;
		st += a + 'a' - 1;

		n /= 26;
		// cout << n << endl;
	}
	reverse(st.begin(), st.end());
	cout << st << endl;
}

int main()
{
	fastio();

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

	return 0;
}


Measured memory_bytes: 3652
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    G = [[0] * n for _ in range(n)]
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in range(k):
            G[u-1][v[j]-1] = 1

    for i in range(n):
        print(*G[i])


if __name__ == '__main__':
    main()



Measured memory_bytes: 6388
N,C = map(int, input().split())

channels =[[]for i in range(C)]

for i in range(N):
    s,t,c = map(int,input().split())
    channels[c-1].append([s,t])

merged_channels = [[]for i in range(C)]
for i in range(len(channels)):
    channels[i].sort()
    if len(channels[i])>0:
        merged_channels[i].append(channels[i][0])
        for j in range(1,len(channels[i])):
            if merged_channels[i][-1][1]==channels[i][j][0]:
                merged_channels[i][-1][1] = channels[i][j][1]
            else:
                merged_channels[i].append(channels[i][j])

tv = [0]*(10**5+1)
for i in range(len(merged_channels)):
    for s,t in merged_channels[i]:
        for k in range(s,t+1):
            tv[k]+=1

print(max(tv))





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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int q;
    cin>>q;
    set<int> st;
    rep(i, q) {
        int m, x;
        cin>>m>>x;
        if (m == 0) {
            st.insert(x);
            cout<<st.size()<<endl;
        }
        else {
            if (st.find(x) != st.end()) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
}


Measured memory_bytes: 12524
N, M = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
diff = []
for i in range(len(l)-1):
  diff.append(l[i]-l[i+1])
diff.sort()
s = 0
for i in range(M-N):
  s += diff[i]
print(s)


Measured memory_bytes: 13968
using System;
using System.IO;
using System.Linq;

namespace Contest
{
    class Program
    {
        private Scanner sc;
        public void Solve()
        {
            sc = new Scanner();
            int N = sc.NextInt();
            int[] W = sc.IntArray();
            int sum = W.Sum();
            int ans = sum;
            int s = 0;
            for (int i = 0; i < N; i++)
            {
                s += W[i];
                ans = Math.Min(ans, Math.Abs(sum - s - s));
            }
            Console.WriteLine(ans);
        }


        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private char _separator;
    private StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
long long n,f[5005];
struct eming
{
	long long a,b;
};
eming e[5005];
long long cmp(eming x,eming y)
{
	return (x.a+x.b<y.a+y.b)?1:0;
}
int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		f[i]=99999999999;
		scanf("%lld %lld",&e[i].a,&e[i].b);
	}
	sort(e+1,e+n+1,cmp);
	for(long long i=1;i<=n;i++)
	{
		for(long long j=n;j>=1;j--)
		{
			if(f[j]>f[j-1]+e[i].b&&e[i].a>=f[j-1])
			{
				f[j]=f[j-1]+e[i].b;
			}
		}
	}
	for(long long i=n;i>=0;i--)
	{
		if(f[i]<9999999999)
		{
			printf("%lld\n",i);
			return 0;
		}
	}
	return 0;
}

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

int main () {
	int a1, a2, a3, mx = 0;
	cin >> a1 >> a2 >> a3;

	mx = max(max(abs(a1 - a2), abs(a2 - a3)), abs(a3 - a1));

	cout << abs(a1 - a2) + abs(a2 - a3) + abs(a3 - a1) - mx << endl;

	return 0;
}

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

using namespace std;

struct Query {
    int v;
    int d;
    int c;

    Query(int v, int d, int c) : v(v), d(d), c(c) {}
};

struct Node {
    int from;
    int d;

    Node(int from, int d) : from(from), d(d) {}
};

const int maxN = 1e5 + 100;
bool used[maxN][12];
vector <int> g[maxN];
int colors[maxN];
bool finalized[maxN];

int main() {
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector <Query> Q;
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        Q.push_back(Query(v, d, c));
    }
    for (auto cur = Q.rbegin(); cur != Q.rend(); cur++) {
        int from = cur->v;
        if (!used[from][cur->d]) {
            queue <Node> qu;
            qu.push(Node(from, cur->d));
            used[from][cur->d] = true;
            while (!qu.empty()) {
                auto top = qu.front();
                qu.pop();
                if (!finalized[top.from]) {
                    colors[top.from] = cur->c;
                    finalized[top.from] = true;
                }
                if (top.d == 0) {
                    continue;
                }

                for (int to : g[top.from]) {
                    if (!used[to][top.d - 1]) {
                        qu.push(Node(to, top.d - 1));
                        used[to][top.d - 1] = true;
                    }
                }
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << colors[i] << "\n";
    }
    cout << endl;



    return 0;
}

Measured memory_bytes: 10224
#include<stdio.h>
#include<string.h>
int main(void)
{	
	int n;
	scanf("%d",&n);
	if(n==1){
		printf("1\n");
	}
	else if(2<=n && n<=3){
		printf("2\n");
	}
	else if(4<= n && n <=7){
		printf("4\n");
	}
	else if(8<= n && n <=15){
		printf("8\n");
	}
	else if(16<= n && n <=31){
		printf("16\n");
	}
	else if(32<= n && n <=63) {
		printf("32\n");
	}
	else{
		printf("64\n");
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
https://abc088.contest.atcoder.jp/tasks/abc088_c

"""
import sys
from sys import stdin
input = stdin.readline


def solve(M):
    for a1 in range(100+1):
        b1 = M[0][0] - a1
        a2 = M[1][0] - b1
        a3 = M[2][0] - b1
        b2 = M[0][1] - a1
        b3 = M[0][2] - a1
        if a2+b2 == M[1][1] and a2+b3==M[1][2] and a3+b2==M[2][1] and a3+b3==M[2][2]:
            return 'Yes'
    return 'No'


def main(args):
    M = []
    for _ in range(3):
        M.append([int(x) for x in input().split()])
    ans = solve(M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void){
    int x;
    cin >> x;

    int happy1000 = x / 500;
    int happy5 = (x - happy1000 * 500) / 5;

    cout << happy1000 * 1000 + happy5 * 5 << endl; 
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main{

	public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter wr = new PrintWriter(System.out);
        String str = br.readLine().trim();
        StringTokenizer stk = new StringTokenizer(str);
        int A = Integer.parseInt(stk.nextToken());
        int B = Integer.parseInt(stk.nextToken());
        int C = Integer.parseInt(stk.nextToken());
        int X = Integer.parseInt(stk.nextToken());
        int Y = Integer.parseInt(stk.nextToken());
        long first=0l,second=0l,third = 0l;
        first = (long)A*X+B*Y;
        //System.out.println(Math.min(A, B)+Math.min(C,D));
        if(X>Y) {
        	int left = X-Y;
        	second = (long)Y*2*C;second+=left*A;
        }
        else {
        	int left = Y-X;
        	second = (long)X*2*C;second+=left*B;
        }
        if(X>Y)third = (long)(X+X)*C;
        else third = (long)(Y+Y)*C;
        System.out.println(Math.min(first, Math.min(second, third)));
	}

}


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

namespace ABC153
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }

        public static void c()
        {
            long[] nk = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            long n = nk[0];
            long k = nk[1];
            long[] h = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            Array.Sort(h);
            Array.Reverse(h);
            long ans = 0;
            for(long i = 0; i < n; i++)
            {
                if(i < k)
                { continue; }
                else
                { ans += h[i]; }
            }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

vi adjList[100005];
int par[100005];
bool vis[100005];

int main(){
	int n, m;
	cin >> n >>m;
	for(int i = 0; i < m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		adjList[a].pb(b);
		adjList[b].pb(a);
	}

	queue<int> q;
	q.push(1);
	vis[1] = true;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v : adjList[u]){
			if(!vis[v]){
				vis[v] = true;
				par[v] = u;
				q.push(v);
			}
		}
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for(int i = 2; i <=n; i++){
		printf("%d\n", par[i]);
	}
	return 0;
}



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

int main(){

    long long N;
    long long K;
    cin >> N >> K;

    long long a=0;
    long long b=0;

    long long a_hairetu[1000000];

    long long b_temp=0;
    long long result = 0;
    //int cnt=0;

    for(long long i=0; i<N; i++){
        cin >> a >> b;
        a_hairetu[a-1]+= b;

    }

    for(long long i=0; i<1000000; i++){
        b_temp += a_hairetu[i];
        if(b_temp >= K){
            result = i+1; 
            break;
        }        
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>

int main()
{
    int a, b, c;
    
    // スペース区切りの整数の入力
    scanf("%d %d",&a, &b);
    //printf("a:%d b:%d\n", a, b);
    c = b*2;
    //printf("c %d\n", c);
    //printf("a-c %d\n", (a-c));
    
    if(c >= a){
        printf("0");
    }else{
        printf("%d", (a-c));
    }
    
    return 0;
}


Measured memory_bytes: 128
# coding: utf-8

def f(n, k, h):
    dp = [0]
    for i in range(1, n):
        js = max(i - k, 0)
        dp.append(min(dp[j] + abs(h[i] - h[j]) \
            for j in range(js, i)))
    return(dp[-1])

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

print(f(n, k, h))


Measured memory_bytes: 13980
while True:
    n,r = map(int,input().split())
    if n == r == 0: break
    cards = [n-i for i in range(n)]
    for i in range(r):
        p,c = map(int,input().split())
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
    print(cards[0])

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    int sum = 0;
    for (int& x : v) {
        cin >> x;
        sum += x;
    }

    sort(v.begin(), v.end());
    bool f = false;
    for (int i = 0; i < v.size(); i++) {
        if (sum % 10 != 0) {
            f = true;
            break;
        }
        if (v[i] % 10 != 0) {
            sum -= v[i];
        }
    }

    if (f) {
        cout << sum << endl;
    } else {
        puts("0");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int a, b, gcd;
    std::cin >> a >> b;
	while(1){
		if(b % a == 0){
			gcd = a;
			break;
		}
		int temp = a % b;
		a = b;
		b = temp;
	}
	std::cout << gcd << std::endl;

	return 0;
}

Measured memory_bytes: 1164
import bisect

N = int(input())
LIS = [-1 * int(input())]
for _ in range(N-1):
    A = -1 * int(input())
    if A >= LIS[-1]:
        LIS.append(A)
    else:
        LIS[bisect.bisect_right(LIS, A)] = A

print(len(LIS))

Measured memory_bytes: 50264
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const ll INF = 1LL<<60;

struct edge {
    int to;
    ll cost;
};

int n, t, k;
vector<vector<edge>> tree;
vector<ll> dist;

void dijkstra(int x) {
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(P(0, x));
    dist[x] = 0; 
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < tree[v].size(); ++i) {
            int nv = tree[v][i].to, weight = tree[v][i].cost;
            if (dist[nv] <= dist[v] + weight) continue;
            dist[nv] = dist[v] + weight;
            q.push(P(dist[nv], nv));
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    tree.resize(n);
    rep(i, n-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    cin >> t >> k;
    k--;

    dist.resize(n, INF);
    dijkstra(k);
    
    rep(i, t) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << dist[x] + dist[y] << endl;
    }
}

Measured memory_bytes: 9984
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
  string a;
  cin >> a;
  if(a.length()==2)cout << a << endl;
  else{
    cout << a[2] << a[1]<<a[0] << endl;
  }
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}









Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] ary = br.readLine().split(" ");
        int min = 1000000;
        int max = -1000000;
        long sum = 0;
        for(int i=0;i<N;i++){
            int num = Integer.parseInt(ary[i]);
            if(num<min) min = num;
            if(num>max) max = num;
            sum += num;
        }
        System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 28804
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

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

  string ans = S;
  char c = ans.at(K - 1);
  for (int i = 0; i < 26; i++)
  {
    if (c == ABC.at(i))
    {
      ans.at(K - 1) = abc.at(i);
      break;
    }
  }
  

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    
    vector<bool> s(N, false), f(N, false);
    s[A - 1] = true;
    for (int i = A; i < C; ++i) {
        if (S[i] == '#') continue;
        if (i == 1) s[i] = true;
        else if (s[i - 1] || s[i - 2]) s[i] = true;
    }
    f[B - 1] = true;
    for (int i = B; i < D; ++i) {
        if (S[i] == '#') continue;
        if (i == 1) f[i] = true;
        else if (f[i - 1] || f[i - 2]) f[i] = true;
    }
    
    if (C < D) {
        if (s[C - 1] && f[D - 1]) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        bool judge = false;
        REP(i, N - 1) {
            if (f[i] && s[i - 1] && s[i + 1]) judge = true;
        }
        if (judge) {
            if (s[C - 1] && f[D - 1]) cout << "Yes" << endl;
            else cout << "No" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 644
n,k=map(int,input().split())
cnt=dict()
for _ in range(n):
    a,b=map(int,input().split())
    cnt[a]=cnt.get(a,0)+b
cnt=sorted(cnt.items(),key=lambda x:x[0])

tmp=0
for key,val in cnt:
    tmp+=val
    if tmp >= k:
        print(key)
        exit()

Measured memory_bytes: 15040
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod = 1000000007


def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x, y: x*y % mod, range(n, n - r, -1), 1)
    denom = pow(reduce(lambda x, y: x*y % mod, range(1, r + 1), 1), mod-2, mod)
    return numer * denom % mod


def solve():
    pass


def main():
    n = int(input().strip())
    a = list(map(int, input().strip().split()))
    max_x = a[0]
    ans = 0
    for i in range(1,n):
        ans += max(max_x - a[i], 0)
        max_x = max(max_x, a[i])
        # eprint('minx, a[i], ans ',end=':\n')
        # eprint(minx, a[i], ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103516
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long Comb (long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);cout<<N*N*N;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000
#define NIL -1

void Preorder(int);
void Inorder(int);
void Postorder(int);

typedef struct{
    int p;
    int l;
    int r;
}Node;

Node T[MAX];

void Pre(int);
void In(int);
void Post(int);

int main()
{
    int n, r, node, c;
    int i, j;
    
    scanf("%d", &n);
    
    for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for(i=0; i<n; i++){
        scanf("%d", &node);
        for(j=0; j<2; j++){
            scanf("%d", &c);
            if(c != NIL){
                T[c].p = node;
                if(j==0) T[node].l = c;
                else T[node].r = c;
            }
        }
    }
    
    for(i=0; i<n; i++){
        if(T[i].p == NIL) r = i;
    }
    
    printf("Preorder\n");
    Preorder(r);
    printf("\n");
    printf("Inorder\n");
    Inorder(r);
    printf("\n");
    printf("Postorder\n");
    Postorder(r);
    printf("\n");
    
    return 0;
}

void Preorder(int r)
{
    printf(" %d", r);
    if(T[r].l != NIL) Preorder(T[r].l);
    if(T[r].r != NIL) Preorder(T[r].r);
}

void Inorder(int r)
{
    if(T[r].l != NIL) Inorder(T[r].l);
    printf(" %d", r);
    if(T[r].r != NIL) Inorder(T[r].r);
}

void Postorder(int r)
{
    if(T[r].l != NIL) Postorder(T[r].l);
    if(T[r].r != NIL) Postorder(T[r].r);
    printf(" %d", r);
}

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

int main()
{
 	int N, K;
  cin >> N >> K;
  
  int A[N];
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  
  sort(A,A+N);
  int ans = A[N-1];
  for (int i = 0, j = K-1; j < N; ++i, ++j)
    ans = min(A[j] - A[i], ans);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var b string
	fmt.Scan(&b)

	if b == "A" {
		fmt.Println("T")
	} else if b == "C" {
		fmt.Println("G")
	} else if b == "G" {
		fmt.Println("C")
	} else if b == "T" {
		fmt.Println("A")
	}

}


Measured memory_bytes: 512
import java.util.*;

public class Main
{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
	String[] temp = in.nextLine().split(" ");
	int N = Integer.parseInt(temp[0]);
	int M = Integer.parseInt(temp[1]);
	ArrayList<Integer>[] graph = new ArrayList[N+1];
	for (int i = 0; i <= N; i++) graph[i] = new ArrayList<>();
	for (int i = 0; i < M; i++) {
	    temp = in.nextLine().split(" ");
	    int from = Integer.parseInt(temp[0]);
	    int to = Integer.parseInt(temp[1]);
	    graph[to].add(from);
	}
	in.close();
	int[] mem = new int[N+1];
	Arrays.fill(mem, -1);
	int res = 0;
	for (int i = 1; i <= N; i++) {
	    res = Math.max(res, longest(i, mem, graph));
	}
	System.out.println(res);
	
    }

    public static int longest(int i, int[] mem, ArrayList<Integer>[] graph) {
	if (mem[i] == -1) {
	    int res = 0;
	    for (int j : graph[i]) {
		res = Math.max(res, longest(j, mem, graph)+1);
	    }
	    mem[i] = res;
	}
	return mem[i];
    }
}


Measured memory_bytes: 84532
# N,M = 2, 2
N, M = map(int, input().split())

# kの値は特に必要ないので最初から取得しない
# S = [[1, 2], [2]]
# p = [0, 1]
S = [list(map(int,input().split()))[1:] for i in range(M)]
p = list(map(int, input().split()))

ans = 0

for i in range(1<<N): #スイッチのオンオフ状態(0, 1, 2, 3)
    count_2 = -1
    bit = list(str(bin(i))) # 0b0, 0b1, 0b10...
    fail = 0
    
    # 桁埋め処理
    ketaume = (1<<N) // 2 + 2 - len(bit) 
    if ketaume > 0:
        for i in range(ketaume):
            bit.insert(2, "0")
    # print("search target={}".format(bit))
    for s in S: #[1, 2], [2]の階層
        count_2 += 1 # 何番目のSかを数えたい
        count = 0
        for t in s: # 1, 2の階層
            # print("bit = {}".format(bit[-t]))
            if int(bit[-t]) == 1:
                count += 1 # ついているスイッチの数を数える
                
        # print("{}-> number of switch is {}".format(s, count))
                
        # ついているスイッチが偶数か奇数かを判定
        # print("if mod is {}, OK".format(p[count_2]))
        # print("")
        if not count % 2 == p[count_2]:
            fail = 1 # 望ましくなければ，失敗フラグを立ててブレイク
            break
    if fail == 0:
        # print("ans += 1")
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] abc = new int[] {sc.nextInt(), sc.nextInt(), sc.nextInt()};
        Arrays.sort(abc);
        System.out.println(abc[0] + abc[1]);
    }

}


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

const int mod = 1000000007;
//const int mod = 998244353;

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

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


int main()
{
    string s;
    cin >> s;
    ll cnt = 0;
    ll ans = 0;
    rep(i, 0, s.size()){
        if(s[i] == 'W'){
            cnt++;
            ans += i;
        }
    }
    cout << ans - cnt*(cnt-1)/2 << endl;
    return 0;
}


Measured memory_bytes: 3696
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val C = readLine()!!.split(" ").map{it.toLong()}.sorted()
    val MOD = 1e9.toLong() + 7L

    var res = ModInt(0L, MOD)
    val TWO = ModInt(2L, MOD)

    for (i in C.indices) {
        val m = N - i - 1L
        res += TWO.pow(i.toLong()).pow(2L) * (TWO.pow(m - 1L) * m + TWO.pow(m)) * TWO.pow(m) * C[i] * 2L
    }

    println(res.value)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}

class ModCombination(val n: Long, val mod: Long) {
    private val fact = Array(n.toInt() + 1) { ModInt(1, mod) }
    private val invfact = Array(n.toInt() + 1) { ModInt(1, mod) }

    init {
        for (i in 2..n.toInt()) {
            fact[i] = fact[i - 1] * i.toLong()
            invfact[i] = fact[i].inv()
        }
    }

    operator fun get(n: Long, m: Long): ModInt {
        if (m > n) {
            return ModInt(0, mod)
        }

        return fact[n.toInt()] * invfact[m.toInt()] * invfact[(n - m).toInt()]
    }
}


Measured memory_bytes: 85172
import bisect
N = int(input())
rate = sorted(list(map(int,input().split())))
allcoder = 0
for i in range(N):
    if rate[i] > 3199:
        allcoder += 1
color = 0        
for i in range(8):
    if bisect.bisect_left(rate,i*400 if i>0 else 1) != bisect.bisect_right(rate,i*400+399) :
        color += 1
print(max(color,1),color+allcoder)       

Measured memory_bytes: 3064
n,q = map(int, input().split(" "))
s = input()

cnt = 0
before = [0] * len(s)

for i in range(1, len(s)):
	if s[i-1] == 'A' and s[i] == 'C':
		cnt += 1
	before[i] = cnt

for _ in range(q):
	l,r = map(int, input().split(" "))
	print(before[r-1] - before[l-1])


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

INF = float('inf')


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

    alice = 0
    bob = 0

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(A.index(max(A)))
        if len(A) != 0:
            bob += A.pop(A.index(max(A)))

    print(alice - bob)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      String weather =sc.next();
      String S ="Sunny";
      String C ="Cloudy";
      String R ="Rainy";
      
      if(weather.equals(S)){
      System.out.println(C);
      }
      else if(weather.equals(C)){
      System.out.println(R);
      }
      else{
      System.out.println(S);
      }
    }
}

Measured memory_bytes: 20820
#include<iostream>
#include<algorithm>
using namespace std;
int n,x,a[100010],ans=-1;
int main(void){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>x;
    a[x]++;
  }
  for(int i=1;i<=100000;i++){
    ans=max(a[i-1]+a[i]+a[i+1],ans);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	char c;
	scanf("%c",&c);
	printf("%c",c=='A'?'T':c=='T'?'A':c=='G'?'C':'G');
}

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

int main()
{
    int h,w;
    cin>>h>>w;
    string* arr = new string[h];
    for(int i=0;i<h;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<w+2;i++)
    {
        cout<<"#";
    }
    cout<<endl;
    for(int i=0;i<h;i++)
    {
        cout<<"#";
        cout<<arr[i];
        cout<<"#";
        cout<<endl;
    }
    for(int i=0;i<w+2;i++)
    {
        cout<<"#";
    }
}

Measured memory_bytes: 3620