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

using namespace std;

const int P = 1000000007;

long long power(long long x, long long t) {
	long long ret = 1;
	for(; t; t >>= 1, x = x * x % P) {
		if(t & 1) {
			ret = ret * x % P;
		}
	}
	return ret;
}

int main() {
	int n, m;
	cin >> n >> m;

	vector<long long> fac(m + 1);
	fac[0] = 1;
	for(int i = 0; i < m; ++i) {
		fac[i + 1] = fac[i] * (i + 1) % P;
	}

	vector<long long> inv(m + 1);
	inv[m] = power(fac[m], P - 2);
	for(int i = m; i >= 1; --i) {
		inv[i - 1] = inv[i] * i % P;
	}

	auto C = [&] (int n, int m) {
		if(n < m) {
			return 0LL;
		}
		return fac[n] * inv[m] % P * inv[n - m] % P;
	};

	long long ans = 0;
	for(int i = 0; i <= n; ++i) {
		long long x = C(n, i) * C(m - i, n - i) % P * fac[n - i] % P;
		if(i % 2 == 0) {
			ans = (ans + x) % P;
		} else {
			ans = (ans - x + P) % P;
		}
	}

	ans = ans * fac[n] % P * C(m, n) % P;

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 11088
import sys
n, m = map(int, input().split())

c_dict = {}
flag = False
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if s in c_dict and c != c_dict[s]:
        flag = True
    elif s not in c_dict:
        c_dict[s] = c
if flag:
    print("-1")
    sys.exit()

if 0 in c_dict and c_dict[0] == 0 and n > 1:
    print("-1")
    sys.exit()
ans = ""
for i in range(n):
    if i in c_dict:
        ans += str(c_dict[i])
    elif i > 0:
        ans += "0"
    elif i == 0 and n > 1:
        ans += "1"
    elif i == 0 and n == 1:
        ans += "0"
print(ans)


Measured memory_bytes: 8892
#!/usr/bin/env python

contents = []

while True:
    text = input()
    if text == '-':
        break
    m = int(input())
    hArray = []
    for i in range(m):
        h = int(input())
        hArray.append(h)
    contents.append([text, hArray])

for x in contents:
    deck = x[0]
    for i in x[1]:
        deck = deck[i:] + deck[:i]
    print(deck)

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

int main()
{
	int sx,sy,tx,ty;
	while(~scanf("%d%d%d%d",&sx,&sy,&tx,&ty))
	{
		for(int i=1;i<=ty-sy;i++)
		printf("U");
		for(int i=1;i<=tx-sx;i++)
		printf("R");
		for(int i=1;i<=ty-sy;i++)
		printf("D");
		for(int i=1;i<=tx-sx;i++)
		printf("L");
		
		printf("L");
		sx--;ty++;
		for(int i=1;i<=ty-sy;i++)
		printf("U");
		for(int i=1;i<=tx-sx;i++)
		printf("R");
		printf("D");
		
		sx++;sy--;ty--;tx++;
		printf("R");
		for(int i=1;i<=ty-sy;i++)
		printf("D");
		for(int i=1;i<=tx-sx;i++)
		printf("L");
		printf("U");

		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
     
    int main(int argc, char**argv){
      int a, b, ret;
      if((scanf("%d %d", &a, &b)) == EOF) return 1;
      ret = a * b % 2;
      if(ret) printf("Odd\n");
      else printf("Even\n");
      return 0;
    }  

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

namespace ConsoleApp11
{
    class Class12
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int abc = 0;
            for(int i = 0; i < N-2; i++)
            {
                if (S[i] == 'A' & S[i + 1] == 'B' & S[i + 2] == 'C')
                {
                    abc += 1;
                    i += 2;
                } 
            }
            Console.WriteLine(abc);
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ff first
#define ss second
#define sf ss.ff
#define tt ss.ss
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);

using namespace std;

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

/*
 *Use abbreviation:
 *dsu ->Disjoint Set Union
 *bit ->Binary Indexed Tree
 *math ->Mathematical Functions(gcd,fact,bigMod,ncr)
 *test ->For test cases
 */

ll n,sm,x,res;

int main()
{
    cin>>n;
    res=sm=0;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x){
            sm+=x;
        }
        else{
            res+=sm/2;
            sm=0;
        }
    }
    cout<<res+sm/2<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main(){
  int a,b;
  cin >> a>>b;
  int ans;
  for(int i=0;i<a+1;i++){
    if(a>=0&&b>=0)if(2*i+(a-i)*4==b){
      cout << "Yes" << endl;
      return 0;
    }
  }
 
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include "stdlib.h"
using namespace std;

int main() {
  int change(int n, int b);
  char operand(int n);
  int N; cin >> N;
  int A = N / 1000;
  int B = (N / 100) % 10;
  int C = (N / 10) % 10;
  int D = N % 10;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        if (A + change(B, i) + change(C, j) + change(D, k) == 7) {
          cout << A << operand(i) << B << operand(j) << C << operand(k) << D <<"=7" << endl;
          return 0;
        }
      }
    }
  }
}

int change(int n, int b) {
  if (b)
    return n;
  else
    return -n;
}

char operand(int n) {
  if (n == 1)
    return '+';
  else
    return '-';
}


Measured memory_bytes: 256
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
ll i,n,m,a[N],d[N],f[N],x;
int main()
{
	scanf("%lld %lld",&n,a);
	fo(i,1,n)
	{
		scanf("%lld",d+i);
		a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	}
	f[n+1]=1;
	fd(i,n,1)
	{
		f[i]=f[i+1];
		if (d[i]<f[i]*2) f[i]+=d[i];
	}
	scanf("%lld",&m);
	fo(i,1,m)
	{
		scanf("%lld",&x);
		if (a[x-1]>=f[x+1]) printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 18304
#include<cctype>
#include<stdio.h>
int main(){
    char ch;
    while(true){
        scanf("%c",&ch);
        if(islower(ch)){
            printf("%c",toupper(ch));
        }
        else if(isupper(ch)){
            printf("%c",tolower(ch));
        }
        else{
            printf("%c",ch);
        }
        if(ch=='\n') break;
    }
    return 0;
    
}


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

int main(){
	int N,M;
	cin >> N >> M;
	int a[M+M];
	
	for(int h = 0;h < 2*M;h++){
		cin >> a[h];
	}
	for(int x = 0;x < N;x++){
		int ans = 0;
		for(int i =0;i < 2*M;i++){
			if(a[i] == x+1){	ans++;	}
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  REP(i, N) {
    cin >> h[i];
  }
  int ans = 0;
  for(int i = *max_element(h.begin(), h.end()); i > 0; i--) {
    int count = 0;
    REP(j, h.size()) {
      if(h[j] == i) {
        count++;
        h[j]--;
      } else {
        if(count > 0) {
          ans++;
          count = 0;
        }
      }
    }
    if(count > 0) {
      ans++;
      count = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N,X=map(int,input().split())
t=[]
s=0
for i in range(N):
    b,l,u=map(int,input().split())
    t.append(((X-b)*u+l*b,b,l,u))
    s-=b*l
t.sort()
def condition(q):
    check=sum(t[i][0] for i in range(N-q,N))
    return check+s>=0

start=0
end=N
while end-start>1:
    test=(end+start)//2
    if not condition(test):
        start=test
    else:
        end=test

if not condition(end):
    Q=end
else:
    Q=start

check=sum(t[i][0] for i in range(N-Q,N))
check2=check+t[N-Q-1][0]
def condition2(r):
    M=0
    for i in range(N):
        test=0
        if N-Q>i:
            test=check
            val,b,l,u=t[i]
            if b>=r:
                test+=r*l
            else:
                test+=r*u-b*(u-l)
            M=max(M,test)
        else:
            val,b,l,u=t[i]
            test=check2-val
            if b>=r:
                test+=r*l
            else:
                test+=r*u-b*(u-l)
            M=max(M,test)
    return M+s>=0

start=0
end=X-1
while end-start>1:
    mid=(end+start)//2
    if condition2(mid):
        end=mid
    else:
        start=mid

if condition2(start):
    R=start
elif condition2(end):
    R=end
else:
    R=X
print(Q*X+R)

Measured memory_bytes: 68440
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<vector<int>> G(n);
  rep(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> path;
  vector<bool> vis(n);
  ll ans = 0;
  auto dfs = [&](auto dfs, int cur, int par) -> void {
    if((int)path.size() == n-1) {
      ans++;
      return;
    }
    vis[cur] = true;
    path.push_back(cur);
    for(int ne: G[cur]) {
      if(!vis[ne]) dfs(dfs, ne, cur);
    }
    vis[cur] = false;
    path.pop_back();
  };
  dfs(dfs, 0, -1);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#define N 100000
int binary(int );
int A[N+1],n;

int main ()  {
  int q,key,sum = 0,i;

  scanf("%d",&n);
for(i=0;i<n;i++)  scanf("%d", &A[i]);
  scanf("%d", &q);

for(i=0;i<q;i++) {
    scanf("%d", &key);
    if(binary(key)) sum++;
}
  printf("%d\n",sum);

  return 0;
}

int  binary(int key) {
   int left=0,right=n,mid;
   while(left < right) {
     mid = (left + right)/2;
      if(A[mid] == key)
         return 1;
         else if(key < A[mid])
         right = mid;
         else left = mid +1;
   }
   return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, K; cin >> N >> K;
    vector<int> v(N);
    for(int i=0; i<N; i++) cin >> v[i];

    int ans = 0;
    for(int a=0; a<=K; a++){
        for(int b=0; b<=K-a; b++){
            if(a+b > N) continue;
            priority_queue<int> pq;
            int tmp = 0;
            int res = K-a-b;
            for(int i=0; i<a; i++){
                tmp += v[i];
                if(v[i] < 0) pq.push(-v[i]);
            }
            for(int i=0; i<b; i++){
                tmp += v[N-1-i];
                if(v[N-1-i] < 0) pq.push(-v[N-1-i]);
            }

            while(res>0 && !pq.empty()){
                int u = pq.top(); pq.pop();
                tmp += u;
                res--;
            }

            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC_133A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
 
            var word = Console.ReadLine().Split(' ');
 
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
 
            if (a * b > c)
            {
                Console.WriteLine(c);
            }
 
            else 
            {
                Console.WriteLine(a * b);
            }
 
            Console.ReadKey();
 
 
 
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>

int main() {
    char A[20], B[20], C[20];
    A[20] = 'a' - 'z';
    B[20] = 'a' - 'z';
    C[20] = 'a' - 'z';
    scanf ("%s %s %s", &A, &B, &C);
    
    if (A [strlen(A) - 1] == B[0] && B [strlen(B) - 1] == C[0]) {
        printf ("YES");
    }
    else {
        printf ("NO");
    }
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;
  if (s.size() == t.size()) {
	if (s > t) {
	  cout << "GREATER" << endl;
	  return 0;
	}
	if (t > s) {
	  cout << "LESS" << endl;
	  return 0;
	}
	else {
	  cout << "EQUAL" << endl;
	  return 0;
	}
  }
  if (s.size() > t.size()) {
	cout << "GREATER" << endl;
	return 0;
  }
  else {
	cout << "LESS" << endl;
	return 0;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

int N, M;

/*==================================================*/

/*==================================================*/

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

    double ans = 0;
    double count = 1;
    double c = 1;
    REP(i,0,M){
        c *= 2.0;
    }
    int t = (M*1900 + (N-M)*100);

    cout<<t * (1<<M)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
 ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll x=0;
  x=max(a*d,max(a*c,max(b*c,b*d)));
  cout<<x<<endl;
}


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

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

    if(n%2 == 0) cout << n/2 << endl;
    if(n%2 == 1) cout << (n/2)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
N=int(S)
k=len(S)

dp = [[-1] * 2 for _ in range(k+1)]
dp[0][0] = 0
for i in range(k):
    c = int(S[i])
    dp[i+1][0] = dp[i][0] + c
    dp[i+1][1] = dp[i][1]
    if dp[i][1] >= 0:
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] + 9)
    if c >= 1:
        dp[i+1][1] = max(dp[i+1][1], dp[i][0] + c-1)

print(max(dp[k][0], dp[k][1]))


Measured memory_bytes: 38384
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
    int n;
    int max,min;
    long long s;
    s=0;
    max=-1000000;
    min=8901016;
    int a[10000];
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        s+=a[i];
        if(max<=a[i]){
            max=a[i];
        }
        
        if(min>=a[i]){
            min=a[i];
        }
    }
    cout<<min<<" "<<max<<" "<<s<<endl;
    return 0;
}



Measured memory_bytes: 3116
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m, k = map(int, readline().split())

    for row in range(n + 1):
        for col in range(m + 1):
            count = n * m - (row * col) - ((n - row) * (m - col))
            if count == k:
                return print("Yes")

    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 64532
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
int n;

int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	int a,b;
	cin>>a>>b;
	cout<<a*(a-1)/2+b*(b-1)/2<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                Set<String> A = new HashSet<>();
                for (int i = 0; i < N; i++) {
                        String S = sc.next();
                        String str = sc.next();
                        if (S.equals("insert")) {
                                A.add(str);
                        } else {
                                if (A.contains(str)) {
                                        System.out.println("yes");
                                } else {
                                        System.out.println("no");
                                }
                        }
                }
        }
}

Measured memory_bytes: 253620
#include <bits/stdc++.h>
     
    int main() {
     
            int n, sum = 0, max = 0;
     
            std::cin >> n;
     
            for (auto i = 0; i < n; ++i) {
                    int v;
                    std::cin >> v;
                    if (v > max) {
                            max = v;
                    }
                    sum += v;
            }
     
            if ((sum - max) > max) {
                    std::cout << "Yes" << std::endl;
            }
            else {
                    std::cout << "No" << std::endl;
            }
     
            return 0;
    }

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int height = array[0];
			int width = array[1];
			int area = height * width / 2;

			Console.WriteLine($"{area}");

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int N,M,X[100010]={},D[100010]={};
int main(){
  cin >>N>>M;
  if(N>=M){
    cout << "0" << endl;
    return 0;
  }
  for(int i=0;i<M;i++){
    cin >> X[i];
  }
  sort(X,X+M);
  for(int i=0;i<M-1;i++){
    D[i]= X[i+1]-X[i];
  }
  sort(D,D+M-1);
  //reverse(L,L+N);
  int ans=0;
  for(int i=0;i<M-N;i++){
    ans +=D[i];
  }
  //cout << sum << endl;
  cout << ans << endl;
  //else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
static const int Size = 100;


void Print(int A[], int N, int cnt);
int selectionSort(int A[], int N);


int main() {
    int N;
    int A[Size];
    scanf("%d", &N);
    for (int i = 0 ; i < N; i++) {
        scanf("%d", &A[i]);
    }

    int sw;
    sw = selectionSort(A, N);

    Print(A, N, sw);

}


int selectionSort(int A[], int N) {
    int cnt = 0;
    int minj;
    for (int i = 0; i < N; i++) {
        minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(A[i], A[minj]);
            cnt++;
        }
    }

    return cnt;
}

void Print(int A[], int N, int cnt) {
    for (int i = 0; i < N; i++) {
        if (i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", cnt);
}




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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main(){
	int n;
	while(cin >> n){
		int d=0;
		string s;
		cin >> s;
		for(auto i:s){
			if(i=='R')d++;
			else d--;
		}
		if(d>0){
			cout<<"Yes"<<endl;
		}
		else{
			cout <<"No"<<endl;
		}
	}
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a_arr = []
b_arr = []
n.times do
  a,b = gets.chomp.split(" ").map(&:to_i)
  a_arr << a
  b_arr << b
end

count = 0
(n-1).downto(0) do |i|
  a = a_arr[i] + count
  b = b_arr[i]
  r = a % b
  next if r == 0
  count += b - r
end

puts count


Measured memory_bytes: 16256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string x,y; cin >> x >>y;
    if(x>y)cout << '>' << endl;
    else if(x==y)cout << '=' << endl;
    else cout << '<' << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=110,M=10010;
int a[M],w[N][N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') ch=getchar(),o=-1;
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,m,q,x=1,y=1,t=1;
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++) a[i]=gi();
    while(1) {
	if(!a[t]) ++t;
	w[x][y]=t,--a[t];
	if(y<m&&!w[x][y+1]) ++y;
	else if(x<n&&!w[x+1][y]) ++x;
	else if(y>1&&!w[x][y-1]) --y;
	else if(x>1&&!w[x-1][y]) --x;
	else break;
    }
    for(int i=1;i<=n;i++) {
	for(int j=1;j<=m;j++)
	    printf("%d ",w[i][j]);
	puts("");
    }
    return 0;
}

Measured memory_bytes: 384
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");

typedef long long ll;
typedef long double ld;

void solve(){
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    for(int i = k; i <= 3000; i += k){
        if(i <= b && i >= a){
            cout << "OK\n";
            return;
        } 
    }
    cout << "NG\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

typedef struct node {
  char name[11];
  i32 p;
  i32 k;
} node;

int cmp_node (const void *a, const void *b) {
  const node *p = a;
  const node *q = b;
  int c = strcmp (p->name, q->name);
  if (c != 0) return c;
  return p->p > q->p ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  node *t = ALLOC (n, node);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%s%" SCNi32, t[i].name, &t[i].p);
    t[i].k = i + 1;
  }
  SORT (t, n, cmp_node);
  for (i32 i = 0; i < n; ++i) {
    printf ("%" PRIi32 "\n", t[i].k);
  }
}

int main (void) {
  run();
  return 0;
}


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

int solve(int N, int M) {
    vector<int> h(N+1);
    vector<int> w(M+1);
    
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
        h[i] += h[i-1];
    }
    for (int i = 1; i <= M; i++) {
        cin >> w[i];
        w[i] += w[i-1];
    }
    vector<int> seg;
    for (int i = 0; i <= M; i++) {
        for (int j = i+1; j <= M; j++) {
            seg.push_back(w[j] - w[i]);
        }
    }
    sort(seg.begin(), seg.end());
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = i+1; j <= N; j++) {
            int key = h[j] - h[i];
            int l = (int)(lower_bound(seg.begin(), seg.end(), key) - seg.begin());
            int r = (int)(lower_bound(seg.begin(), seg.end(), key+1) - seg.begin());
            ans += r - l;
        }
    }
    return ans;
}

int main(void){
    // Your code here!
    int N, M;
    while (1) {
        cin >> N >> M;
        if (!N && !M) break;
        cout << solve(N, M) << endl;
    }
}



Measured memory_bytes: 15560
/**
 *    Author:  "Robin Singh" !!!
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     // 0 -> n-1 (i,0,n)
#define bk(i, j, k) for(int i = j-1; i >= k; i--)  // n-1 -> 0 (i,n,0)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0
#define rtn return 
#define nl "\n"      // avoid endl
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const ld eps = 1e-9;
const ll INF = (1LL<<61);
const int inf = (1<<30);
//-------------------------------------------------------------------------------------------------------------
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//-------------------------------------------------------------------------------------------------------------

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, i;
    cin >> n >> i;
    cout << n-i+1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    int n ;
    cin >> n ;
    vector<int> x (n) ;
    rep(i, n) cin >> x[i] ;
    ll ans = INF;
    for(int i = 1 ; i <= 100 ; i++){
        ll res = 0 ;
        rep(j, n){
            res += ((x[j] - i) * (x[j] - i)) ;
        }
        if(res < ans){
            ans = res ;
        }
    }
    cout << ans << endl ;
} 

Measured memory_bytes: 3552
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))[::-1]

    snuke = sum(A)
    arai = 0

    res = f_inf
    for i in range(n - 1):
        snuke -= A[i]
        arai += A[i]
        res = min(res, abs(snuke - arai))

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 23800
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000
#define NUM 100000

using namespace std;

int main(){
	int limit;
	int* table = new int[NUM];

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;
	table[1] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int index = 0;
	int* prime_table = new int[10000];

	for(int i = 2; i < NUM; i++){
		if(table[i] == 1){
			prime_table[index++] = i;
		}
	}

	int M,bunshi,bunbo,ans_p,ans_q,maximum,left,right,m;

	while(true){
		scanf("%d %d %d",&M,&bunshi,&bunbo);
		if(M == 0 && bunshi == 0 && bunbo == 0)break;

		maximum = 0;
		ans_p = 0,ans_q = 0;

		for(int p = 0; prime_table[p]*prime_table[p] <= M; p++){
			left = p,right = index-1, m = (left+right)/2;

			while(left <= right){
				if(bunshi*prime_table[m] > bunbo*prime_table[p] || prime_table[p]*prime_table[m] > M){
					right = m-1;
				}else{
					if(maximum < prime_table[p]*prime_table[m]){
						maximum = prime_table[p]*prime_table[m];
						ans_p = prime_table[p];
						ans_q = prime_table[m];
					}else if(maximum == prime_table[p]*prime_table[m]){
						if(prime_table[p] > ans_p && prime_table[m] > ans_q){
							ans_p = prime_table[p];
							ans_q = prime_table[m];
						}
					}
					left = m+1;
				}
				m = (left+right)/2;
			}
		}

		printf("%d %d\n",ans_p,ans_q);
	}

	return 0;
}

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

int main()
{

    int N, K, max, min;
    cin >> N>>K;

    max = N / K + 1;
    min = N / K;

    if(N>=K && N%K==0){
        cout << "0" << endl;
    }
    else{
        cout << max - min << endl;
    }

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int m, f, r;
	char grade;
	
	while (1) {
		scanf("%d %d %d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		
		if (m == -1 || f == -1) {
			grade = 'F';
		} else {
			if (m + f >= 80){
				grade = 'A';
			} else if (m + f >= 65) {
				grade = 'B';
			} else if (m + f >= 50) {
				grade = 'C';
			} else if (m + f >= 30) {
				if (r >= 50) {
					grade = 'C';
				} else {
					grade = 'D';
				}
			} else {
				grade = 'F';
			}
		}
		
		printf("%c\n", grade);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

//セグメント木
// ref:https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Mnd>
struct segment_tree {
    int n;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> op;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int sz, function<Mnd(Mnd, Mnd)> f, Mnd a) {
        e = a;
        op = f;
        n = 1;
        while (n < sz) n *= 2;
        data.assign(n * 2, e);
    }
    // vectorで要素を指定して初期化
    segment_tree(vector<Mnd> v, function<Mnd(Mnd, Mnd)> f, Mnd a) {
        e = a;
        op = f;
        n = 1;
        while (n < (int)v.size()) n *= 2;
        data.assign(n * 2, e);
        for (int i = 0; i < (int)v.size(); i++) {
            set(i, v[i]);
        }
    }
    //値をセットするだけ
    void set(int k, Mnd x) {
        data[n + k] = x;
    }
    //木を構築 O(n)
    void build() {
        for (int i = n - 1; i > 0; i--) {
            data[i] = op(data[2 * i], data[2 * i + 1]);
        }
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        set(k, x);
        k = (k + n) / 2;
        while (k > 0) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for (a += n, b += n; a < b; a /= 2, b /= 2) {
            if (a % 2 == 1) l = op(l, data[a++]);
            if (b % 2 == 1) r = op(r, data[--b]);
        }
        return op(l, r);
    }
    //代入とかcoutもできる
    Mnd& operator[](const int& k) {
        return data[k + n];
    }
};

//最大公倍数の計算(ユークリッドの互除法)
long long int gcd(long long int a, long long int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int n;
    cin >> n;
    segment_tree<int> seg(n, gcd, 0);
    for (int i = 0; i < n; i++) {
        cin >> seg[i];
    }
    seg.build();
    // i:抜くやつ
    int ans = 1;
    for (int i = 0; i < n; i++) {
        int left = seg.query(0, i);
        int right = seg.query(i + 1, n);
        ans = max((lint)ans, gcd(left, right));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
// NOTE: one-indexed
template <typename T> struct bit {
    const int n;
    vector<T> t;
    bit(int n) : n(n), t(n + 1) {}
    void add(int i, T value) {
        for(int j = i; j <= n; j += j & -j) {
            t[j] += value;
        }
    }
    T sum(int i) {
        T res = 0;
        for(int j = i; j > 0; j -= j & -j) {
            res += t[j];
        }
        return res;
    }
    T sum(int L, int R) {
        return sum(R) - sum(L - 1);
    }
};
void solve(long long N, std::vector<char> c, std::vector<long long> a) {
    vector<vector<int>> pos_black_ignore_white_le(N + 1, vector<int>(N + 1));
    vector<vector<int>> pos_white_ignore_black_le(N + 1, vector<int>(N + 1));
    for(int white = 0; white <= N; white++) {
        bit<int> b(N);
        for(int i = 0, whites_seen = 0; i < 2 * N; i++) {
            if(c[i] == 'B') {
                pos_black_ignore_white_le[white][a[i]] = whites_seen + b.sum(a[i] + 1, N);
                b.add(a[i], 1);
            }
            whites_seen += c[i] == 'W' and a[i] > white;
        }
    }
    for(int black = 0; black <= N; black++) {
        bit<int> b(N);
        for(int i = 0, blacks_seen = 0; i < 2 * N; i++) {
            if(c[i] == 'W') {
                pos_white_ignore_black_le[black][a[i]] = blacks_seen + b.sum(a[i] + 1, N);
                b.add(a[i], 1);
            }
            blacks_seen += c[i] == 'B' and a[i] > black;
        }
    }
    vector<vector<int>> opt(N + 1, vector<int>(N + 1));
    for(int black = N; black >= 0; black--) {
        for(int white = N; white >= 0; white--) {
            int& ans = opt[black][white];
            if(black == N and white == N) {
                ans = 0;
            } else if(black == N) {
                ans = pos_white_ignore_black_le[black][white + 1] + opt[black][white + 1];
            } else if(white == N) {
                ans = pos_black_ignore_white_le[white][black + 1] + opt[black + 1][white];
            } else {
                ans = min({
                    pos_white_ignore_black_le[black][white + 1] + opt[black][white + 1],
                    pos_black_ignore_white_le[white][black + 1] + opt[black + 1][white]
                });
            }
        }
    }
    cout << opt[0][0] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld",&N);
    std::vector<char> c(2*N);
    std::vector<long long> a(2*N);
    for(int i = 0 ; i < 2*N ; i++){
        std::cin >> c[i];
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(c), std::move(a));
    return 0;
}


Measured memory_bytes: 47360
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    int N, score;
    string name;
    cin >> N;
    vector<tuple<string, int, int>> rest;

    for (int i = 0; i < N; i++) {
        cin >> name >> score;
        score = -score;
        rest.emplace_back(name, score, i + 1);
    }

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

    for (int i = 0; i < N; i++) {
        cout << get<2>(rest[i]) << endl;
    }


    return 0;
}

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

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        N: usize,
        a: [i64; N],
    }
    let minus = a.iter().filter(|&&i| i < 0).count();
    let mut ans: i64 = a.iter().map(|&i| i.abs()).sum();
    if minus % 2 != 0 {
        let min = a.iter().map(|&i| i.abs()).min().unwrap();
        ans -= min * 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データの読み取りの準備
		Scanner sc = new Scanner(System.in);
		
		while(true){
			//データの読み取り
			String temp = sc.next();
			
			//終了条件の判定
			if(temp.equals("0")){
				break;
			}
			
			int result = 0;
			
			//tempをchar型の配列に変換
			char temp_2[] = temp.toCharArray();
			
			for(char c:temp_2){
				result += Character.getNumericValue(c);
			}
			
			System.out.println(result);
		}
	}
}


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

#define SENTINEL 1000000000

int count=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}


int main(){
  int A[500000];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  multiset<int> ms;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ms.insert(x);
  }
  while (m--) {
    int cur = *ms.rbegin();
    ms.erase(ms.lower_bound(cur));
    cur >>= 1;
    ms.insert(cur);
  }   
  ll res = 0;
  for (auto e : ms) 
    res += e;
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
using namespace std;
 //Compiler version g++ 4.9

 int main()
 {
 	long N, countPair = 0;
 	cin >> N;
 	long rabbits[N];
 	for (long i = 0; i < N; i++) {
 		cin >> rabbits[i];
 		if (rabbits[i]-1 < i) {
 			if (i+1 == rabbits[rabbits[i]-1]) {
 				countPair++;
 			}
 		}
 	}
 	
 	cout << countPair;
 }

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

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solveA() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes";
    else cout << "No";
}

void solveB() {
    int n; cin >> n;
    string s; cin >> s;
    int res = 0;
    for (int i = 0; i + 2 < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') res++;
    }
    cout << res;
}

void solveC() {
    int n; cin >> n;
    int p[n], q[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n;i ++) cin >> q[i];
    int arr[n];
    int lim = 1;
    for (int i = 1; i <= n; i++) lim *= i;
    for (int i = 0; i < n; i++) arr[i] = i + 1;
    int a = 0, b = 0;
    for (int i = 0; i < lim; i++) {
        int isA = 1, isB = 1;
        for (int j = 0; j < n; j++) {
            if (arr[j] != q[j]) isB = 0;
            if (arr[j] != p[j]) isA = 0;
        }
        if (isA) a = i;
        if (isB) b = i;
        next_permutation(arr, arr + n);
    }
    cout << abs(a - b);
}

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

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

int find2(long long x) {
    int res = 0;
    while (x % 2 == 0) {
        res++;
        x /= 2;
    }
    return res;
}

void solveD() {
    long long n, m; cin >> n >> m;
    long long arr[n];
    if (n == 1) {
        int x; cin >> x;
        if (x % 2 == 1) cout << 0;
        else {
            x /= 2;
            int res = m / x - m / (2 * x); //(m + x) / (2 * x);
            cout << ((res < 0) ? 0 : res);
        }
        return;
    }
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        arr[i] /= 2;
    }
    int two = find2(arr[0]);
    for (int i = 1; i < n; i++) {
        if (find2(arr[i]) != two) {
            cout << 0;
            return;
        }
    }
    long long arrLcm = 1LL;
    for (int i = 0; i < n; i++) arrLcm = lcm(arrLcm, arr[i]);
    long long res = m / arrLcm - m / (2 * arrLcm); //(m + arrLcm) / (2 * arrLcm);
    cout << ((res < 0) ? 0 : res);
}

const long long MOD = 1e9 + 7;

long long modPow(long long b, int p = MOD - 2) {
    if (p == 0) return 1LL;
    long long x = modPow(b, p / 2);
    if (p % 2 == 0) return x * x % MOD;
    return (x * x % MOD) * b % MOD;
}

void solveE() {
    int n; cin >> n;
    long long c[n];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(c, c + n);
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += c[i] * (n - i + 1) % MOD;
        res %= MOD;
    }
    res = res * modPow(4LL, n - 1) % MOD;
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
   // rwFile();
    ///solveA();
    ///solveB();
    ///solveC();
    ///solveD();
    solveE();
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define OPED 100
#define OPER 99

void push(int);
int pop();

int top,S[OPER *2];

int main(){
  int a,b;
  int top = 0;
  char s[OPED];

  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    } else if(s[0] == '-'){
      a = pop();
      b = pop();
      push(b-a);
    } else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    } else {
      push(atoi(s));
    }
  }

  printf("%d\n",pop());

  return 0;
}

void push(int a){
  S[top] = a;
  top++;
}

int pop(){
  top--;
  return S[top];
}



Measured memory_bytes: 2052
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
using namespace std;
typedef long long LL;

LL n,ans = 0;
LL a[200005],b[200005];
LL c[200005];

struct node{
    LL id,val;
    // ???????????????
    bool operator < (const node &nd)const{
        return nd.val > val;
    }
}h,t;
priority_queue <node> q;

bool cmp(LL x,LL y){
    return b[x] > b[y];
}

LL getnum(LL x){
    if(x == 0) return n;
    if(x == n + 1) return 1;
    return x;
    // ?????
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for(LL i = 1;i <= n;i ++) cin >> a[i];
    for(LL i = 1;i <= n;i ++) cin >> b[i];
    
    for(LL i = 1;i <= n;i ++){
    	if(a[i] > b[i]){
    		cout << -1 << endl;
    		return 0;
		}
	}
    
    for(LL i = 1;i <= n;i ++){
        if(a[i] < b[i]){
            t.id = i; t.val = b[i];
            q.push(t);
        }
    }

    while(!q.empty()){
        LL del,mns,i = q.top().id; q.pop();
        del = b[i] - a[i];
        mns = b[getnum(i - 1)] + b[getnum(i + 1)];

        if(del / mns == 0 && b[i] != a[i]){ cout << -1 << endl; return 0; }

        ans += del / mns;
        b[i] -= (del / mns) * mns;
        if(b[i] > a[i]){
            t.id = i; t.val = b[i];
            q.push(t);
        }
    }
    cout << ans << endl;
    return 0;
}

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

long long  gcd(long long  a, long long  b) { return b ? gcd(b, a%b) : a; }
long long  lcm(long long  a, long long  b) { return a / gcd(a, b) * b; }

int main() {
	int N; cin >> N;
	cout << lcm(N, 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int A, P;
    cin >> A >> P;

    cout << (3 * A + P) / 2 << endl;

    return 0;
}

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

using namespace std;

int main() {
	int m, n;
	while (cin >> m >> n) {
		if (m == 0 && n == 0) {
			break;
		}
		vector<int> d(n);
		for (int i = 0; i < n; i++) {
			cin >> d[i];
		}
		int lb = 0;
		int rb = 1500000;
		while (rb-lb > 1) {
			int mid = (lb+rb)/2;
			int mm = 1;
			int c = 0;
			bool h = true;
			for (int i = 0; i < n; i++) {
				if (d[i] > mid) {
					h = false;
					break;
				}
				c += d[i];
				if(c > mid) {
					mm++;
					c = 0;
					i--;
				}
			}
			if (mm > m) {
				h = false;
			}
			if (h) {
				rb = mid;
			} else {
				lb = mid;
			}
		}
		cout << rb << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    if N == 1:
        print(sum(A[0]))
        return

    before_t = A[0][0]
    before_a = A[0][1]
    for t, a in A[1:]:
        n1 = -(-before_t // t)
        n2 = -(-before_a // a)
        n = max(n1, n2)
        taka, aoki = t * n, a * n
        before_t, before_a = taka, aoki

    print(taka + aoki)

main()


Measured memory_bytes: 3064