akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    set<vector<int>> s;
    rep(_,n)
    {
        vector<int> v(3);
        rep(i,3) cin >>v[i];
        sort(all(v));
        s.insert(v);
    }

    cout << n - s.size() << endl;
    return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int s,w;
    cin >> s >> w;
    if(s>w){
        cout << "safe" << endl;
    }
    else{
        cout << "unsafe" << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  bool ok = true;
  rep(i,n) {
    if (a[i]%2 == 1) continue;
    if (a[i]%3 != 0 && a[i]%5 != 0) ok = false;
  }
  if (ok) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main()
{
    Hello
    int a, b, k, temp = 0;
    cin >> k >> a >> b;
    while(true){
        if(temp >= a && temp <= b)
            return cout << "OK", 0;
        else if(temp > 10000)
            break;
        temp += k;
    }
    cout << "NG";
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

int main() {
	while( true ) {
		int m,f,r;
		cin >> m >> f >> r;
		if( m == -1 && f == -1 && r == -1 ) { break; }
		if( m == -1 || f == -1 ) { cout << 'F' << endl; }
		else if( m+f >= 80 ) {
			cout << 'A' << endl;
		} else if( m+f >= 65 ) {
			cout << 'B' << endl;
		} else if( m+f >= 50 || r >= 50 ) {
			cout << 'C' << endl;
		} else if( m+f >= 30 ) {
			cout << 'D' << endl;
		} else {
			cout << 'F' << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3124
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}

int main(void){
    int i,j,n,m,k,a,b,c,w,r=0,l,t;
    double d;
    char s[262144];
    scanf("%d%d%d",&a,&b,&c);
    //l=strlen(s);
    //for(i=0;i<n;i++){scanf("%d",&a[i]);}
    //qsort(a,n,sizeof(int),sortfncsj);
    if(a+b>=c){printf("Yes\n");}else{printf("No\n");}
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var a = ReadLine()[0];
            WriteLine(char.IsLower(a)?"a":"A");
        }
    }
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int n, t;
VI A;
LL solve()
{
	LL sum = t;
	for(int i = 0; i + 1 < n; ++i){
		if(A[i + 1] - A[i] < t)
			sum += (A[i + 1] - A[i]);
		else
			sum += t;
	}
	return sum;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> t;

	A.assign(n, 0);
	REP(i, 0, n) cin >> A[i];

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        //Console.WriteLine("{0}: {1}", n, string.Join(" ", PrimeFactors(n)));
		Console.WriteLine("{0}: {1}", n, string.Join(" ", PrimeFactors(n).Select (x => x.ToString()).ToArray())); //AOJ??¨
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i * i <= n)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else{
                i++;
            }
        }
		if(tmp != 1) yield return tmp;
    }
}

Measured memory_bytes: 5968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            int n = Integer.parseInt(in.readLine());
            System.out.println(interest(100000, 5, n));
        } finally {
            if(in != null) in.close();
            in = null;
        }
    }
 
    public static int interest(int debit, int rate, int n) {
        int ret = debit;
         
    
        for(int i = 0; i < n; i++) {

            ret += ret * rate / 100;

            ret = cutOut(ret, 3);
        }
        return ret;
    }
 
    public static int cutOut(int num, int n) {
        int ret = num;
         String kiri = "1";
        for(int i = 0; i < n; i++) {
            kiri = kiri + "0";
        }
         
         String str = String.valueOf(ret);
        str = str.substring(str.length()-n, str.length());
        if(Integer.parseInt(str) > 0) {
            ret  = ret - Integer.parseInt(str) + Integer.parseInt(kiri);
        }
           return ret;
    }
}

Measured memory_bytes: 24072
N,M = list(map(int,input().split()))
H =list(map(int,input().split()))
a =[0]*M
b =[0]*M
key = [-1]*N
count =0
for i in range(M):
	a[i],b[i]= list(map(int,input().split()))
path=[0][0]*(N)
for i in range(M):

	if H[a[i]-1]>=H[b[i]-1]:
		key[b[i]-1] = 1
	if H[b[i]-1]>=H[a[i]-1]:
		key[a[i]-1] =1


for i in range(N):
	if key[i]==-1:
		count +=1
print(count)

Measured memory_bytes: 21852
def func(args):
    s,a,b,c = args
    return s,int(a)*3+int(c)

n = input()
while True:
    a = map(func,[raw_input().split() for _ in xrange(n)])
    a.sort(key=lambda x:-x[1])#stable
    print "\n".join(map(lambda (s,p):"{},{}".format(s,p),a))
    n = input()
    if n == 0:
        break
    print

Measured memory_bytes: 4224
#include <stdio.h>
void flip(unsigned char Go[],int n);

int main(){
	unsigned char Go[100000];
	int i,j;
	int n;
	int sum;
	
	while(1){
		scanf("%d\n",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d\n",&Go[i]);
			if(i%2){
				if(Go[i]+Go[i-1]==1){
					flip(Go,i);
				}
			}
		}
		sum=0;
		for(i=0;i<n;i++)sum+=Go[i];
		printf("%d\n",n-sum);
	}
	return 0;
}


void flip(unsigned char Go[],int i){
	int k;

	for(k=i-1;k>=0;k--){
		if(Go[k]==Go[i])break;
		Go[k]=Go[i];
	}

	return;
}

Measured memory_bytes: 700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> V(N);
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
    for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }
  int i = 0; // カウンタ変数
int S=0;
  while (i < N) {
  if(V[i] - C[i] >0){
  S += V[i] - C[i];
   
}
    i++;
}
  cout << S << endl;
}

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

int main(){
    int n,Min,out,x;
    cin>>n;
    cin>>Min;
    out=1;
    for(int i=0;i<n-1;i++)
    {
        cin>>x;
        if(x<=Min)
        {
            Min=x;
            out++;
        }
    }
    cout<<out<<endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = []
for i in 0...n
    a.push(gets.chomp.to_i)
end
next_botton = 0
ans = 0
while 1
    ans += 1
    next_botton = a[next_botton] - 1
    if next_botton == 1
        break
    end
    if ans > 10**6
        print(-1)
        exit()
    end
end
print(ans)

Measured memory_bytes: 2684
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"

using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int main(){
    bigint p2[100001] = { 0 }, p3[100001] = { 0 } ;
    p2[0] = 1 , p3[0] = 1 ;
    for( int i = 1 ; i < 100001 ; i++ )
        p2[i] = ( p2[i-1] * 2 ) % mod ;
    for( int i = 1 ; i < 100001 ; i++ )
        p3[i] = ( p3[i-1] * 3 ) % mod ;
    string str ; cin >> str ;
    int N = ( int ) str.length() ;
    int cnt = 0 ;
    bigint ans = 0 ;
    for( int i = 0 ; i < N ; i++ ){
        if( str[i] == '1' ){
            (ans += ( p2[cnt] * p3[N-i-1] ) % mod ) %= mod ;
            cnt++ ;
        }
    }
    (ans += p2[cnt]) %= mod ;
    cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 5292
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <cmath>
//#include <iomanip>
//#include <map>
//#include <unordered_map>
//#include <cstring>
#include <queue>

using namespace std;
using ll = long long;
// using pint = pair<int, int>;
// ll INF = 1LL << 60;

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	vector<int> A(N), B(M);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < M; i++) cin >> B[i];
	vector<ll> a(N + 1), b(M + 1);
	a[0] = 0;
	b[0] = 0;
	for (int i = 0; i < N; i++) {
		a[i + 1] = a[i] + A[i];
	}
	for (int i = 0; i < M; i++) {
		b[i + 1] = b[i] + B[i];
	}
	int ans = 0, j = M;
	for (int i = 0; i < N + 1; i++) {
		if (a[i] > K) break;
		while (b[j] > K - a[i]) j--;
		ans = max(ans, i + j);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7920
#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)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n+1),b(n);
  for(ll i=0;i<n+1;i++) {
    cin >> a[i];
  }
  for(ll i=0;i<n;i++) {
    cin >> b[i];
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(a[i]>b[i]) {
      ans+=b[i];
    }
    else {
      ans+=a[i];
      b[i]-=a[i];
      if(a[i+1]>b[i]) {
        ans+=b[i];
        a[i+1]-=b[i];
      }
      else {
        ans+=a[i+1];
        a[i+1]=0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int x;
    cin>>x;
    cout<<(!x);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int dish[6],dishtime[6];
    
    scanf("%d",&dish[1]);
    scanf("%d",&dish[2]);
    scanf("%d",&dish[3]);
    scanf("%d",&dish[4]);
    scanf("%d",&dish[5]);
    int i=0,j=0,k=0;
    int last=10;
    for(i=1;i<6;i++)
    {
        k=dish[i]%10;
        if(k!=0)
        {
            dishtime[i] = dish[i]+(10-k);
        }else
        {
            dishtime[i] = dish[i];
        }
        if(last > k && k%10 != 0)
        {
            last=dish[i]%10;
            j=i;
        }
    }
    int finishtime=0;
    for(i=1;i<6;i++)
    {
        if(j==i && j != 10)
        {
            finishtime = finishtime + dish[i];
        }else if(j != 10)
        {
            finishtime = finishtime + dishtime[i];
        }
    }
    printf("%d",finishtime);
    return 0;
}

Measured memory_bytes: 128
from itertools import combinations

#
N = int(input())
cnt = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(N):
    name = input()
    if name[0] in cnt:
        cnt[name[0]] += 1

#
letters = [_ for _ in 'MARCH' if cnt[_]>0]
if len(letters)<3:
    print(0)
    exit()

#
ans = 0
for combi in combinations(letters, 3):
    tmp = 1
    for i in combi:
        tmp *= cnt[i]
    ans += tmp

#
print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll dp[310][310][310];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll len = S.size();
    ll K;
    cin >> K;
    dp[0][0][0] = 0;
    REP(i, 0, len) {
        REP(k, 0, K + 1) {
            dp[i][i + 1][k] = 1;
        }
    }
    REP(j, 2, len + 1) {
        REP(i, 0, len) {
            if (i + j > len) {
                continue;
            }
            REP(k, 0, K + 1) {
                dp[i][i + j][k] = max(dp[i][i + j - 1][k], dp[i + 1][i + j][k]);
                if (k > 0) {
                    dp[i][i + j][k] = max(dp[i][i + j][k], dp[i + 1][i + j - 1][k - 1] + 2);
                }
                if (S[i] == S[i + j - 1]) {
                    dp[i][i + j][k] = max(dp[i][i + j][k], dp[i + 1][i + j - 1][k] + 2);
                }
            }
        }
    }
    // REP(i, 0, len + 1) {
    //     REP(j, 0, len + 1) {
    //         REP(k, 0, K + 1) {
    //             cout << dp[i][j][k] << " ";
    //         }
    //         cout << "aaa ";
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    REP(i, 0, K + 1) {
        ans = max(ans, dp[0][len][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 225536
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, C;
    cin >> n >> C;
    vector<int> s(n), t(n), c(n);
    vector<vector<pii>> dat(C);
    REP(i, n){
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
        dat[c[i]].push_back(make_pair(s[i], t[i]));
    }


    REP(i, C){
        sort(dat[i].begin(), dat[i].end());
        vector<pii> res;

        REP(j, dat[i].size()){
            int k = j;
            while(k + 1 < dat[i].size() && dat[i][k].second == dat[i][k+1].first)
                k++;
            res.push_back(make_pair(dat[i][j].first, dat[i][k].second));
            j = k;
        }
        dat[i] = res;
    }


    vector<int> accum(100003, 0);
    REP(i, C){
        for(auto t: dat[i]){
            accum[t.first] += 1;
            accum[t.second+1] -= 1;
        }
    }
    int ans = 0;
    IFOR(i, 1, accum.size()-1){
        accum[i] += accum[i-1];
        ans = max(ans, accum[i]);
    }

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

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};


int main(){
  int n,k; cin >> n >> k;
  int A = (n-1)*(n-2)/2;
  int cnt = A - k;
  if(cnt < 0){
    cout << -1 << endl;
    return 0;
  }

  int m = n-1 + cnt;

  vector<pii> ans;
  rep(i,n-1) ans.pb(mp(i+1,n));

  vector<pii> edge;
  rep(i,n-1) rep(j,i) edge.pb(mp(i+1,j+1));
  rep(i,cnt) ans.pb(edge[i]);

  cout << ans.size() << endl;
  rep(i,sz(ans)) printf("%d %d\n", ans[i].first, ans[i].second);

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n=nxtl();
    ll test=0;
    for(ll k=2;k<=sqrt(n);k++)
    {
        ll x=n;
        while(x%k==0)
            x/=k;
        x%=k;
        if(x==1)
            test++;
    }
    //cout<<test<<endl;
    set <ll> s;
    for(ll i=1;i<=sqrt(n-1);i++)
    {
        if((n-1)%i==0)
        {
            s.insert(i);
            s.insert((n-1)/i);
            //cout<<i<<endl;
        }
    }
    for(auto it=s.begin();it!=s.end();it++)
        if(*it>sqrt(n))
            test++;
    test++;
    cout<<test<<endl;
   
    
    return 0;   
}




 
 


Measured memory_bytes: 256
n=int(input())
plis=[]
llis=[]
for i in range(n):
	x,y=map(int,input().split())
	plis.append([x,y])
for i in range(n):
	for j in range(n):
		if i<j:
			a=((plis[i][0]-plis[j][0])**2+(plis[i][1]-plis[j][1])**2)**(1/2)
			llis.append(a)
b=(2*sum(llis))/n
print(b)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int GCD(int a,int b){
	if(a<b) swap(a,b);
	while(b){
		int t = a%b;
		a = b;
		b = t;
	}
	return a;
}
int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	int gcd = arr[0];
	for(int i=1; i<arr.size(); i++) gcd = GCD(gcd,arr[i]);
	cout<<gcd;
}

Measured memory_bytes: 3712
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    vi v(n); rep(i,n)cin>>v[i];
    map<int,int>mp;
    int ans=0;
    rep(i,n){
        if(v[i]-1>=0)mp[v[i]-1]++;
        mp[v[i]]++;
        mp[v[i]+1]++;
    }
    for(auto itr:mp){
        cmax(ans,itr.second);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N,K;
   cin >> N >> K;
   if( K  > (N-1)*(N-2)/2 ){
      cout <<-1 << endl;
      return 0;
   }
   vector<pair<int,int>> v;
   for(int i=2;i<=N;i++){
      v.push_back(make_pair(1, i));
   }
   int cnt = (N-1)*(N-2)/2;
   for(int i=2; cnt >K && i<=N; i++){
      for(int j=i+1; cnt >K && j<=N; j++){
         v.push_back(make_pair(i,j));
         cnt--;
      }
   }
   cout << v.size() << endl;
   for(int i=0;i<(int)v.size(); i++){
      cout << v[i].first <<" " << v[i].second<< endl;
   }

   return 0;
}


Measured memory_bytes: 384
//
//  main.cpp
//  Competitive
//
//  Created by Ashutosh Tiwari on 16/05/20.
//  Copyright © 2020 Ashutosh Tiwari. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <climits>
#include <functional>
#include <unordered_map>
#include <tuple>
#include <iterator>
#include <unordered_set>
#include <chrono>
#include <regex>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
//    freopen("../in.txt", "r", stdin);
    using ll = long long;
    const ll INF = 1e18L + 5;
    int n, W;
    scanf("%d%d", &n, &W);
    vector<int> weight(n), value(n);
    int sum_value = 0;
    for (int i = 0;i < n; i ++) {
        scanf("%d%d", &weight[i], &value[i]);
        sum_value += value[i];
    }
    vector<ll> dp(sum_value + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i ++)
        for (int j = sum_value - value[i]; j >= 0; j --)
            dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]);
    ll ans = 0;

//    for (auto i: dp) cout << i << " ";
//    cout << endl;
    for (int i = 0; i <= sum_value; i ++) //{
        if (dp[i] <= W) //continue;
        ans = max(ans, (ll)i);
//    }
    printf("%lld\n", ans);


    return 0;
}
//
//using ll = long long;
//void min_self(ll& a, ll b) {
//    a = min(a, b);
//}
//
//const ll INF = 1e18L + 5;
//
//int main() {
//
//    ios_base::sync_with_stdio(false);
//    freopen("../in.txt", "r", stdin);
//    int n, W;
//
//    scanf("%d%d", &n, &W);
//    vector<int> weight(n), value(n);
//    for(int i = 0; i < n; ++i) {
//        scanf("%d%d", &weight[i], &value[i]);
//    }
//    int sum_value = 0;
//    for(int x : value) {
//        sum_value += x;
//    }
//    vector<ll> dp(sum_value + 1, INF); // 0 ... W
//    dp[0] = 0;
//    // dp[i] - the minimum total weight of items with total value exactly i
//    for(int item = 0; item < n; ++item) {
//        for(int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
//            //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
//            min_self(dp[value_already+value[item]], dp[value_already] + weight[item]);
//        }
//    }
//    for (auto i: dp) cout << i << " ";
//    cout << endl;
//    ll answer = 0;
//    for(int i = 0; i <= sum_value; ++i) {
//        if(dp[i] <= W) {
//            answer = max(answer, (ll) i);
//        }
//
//    }
//    printf("%lld\n", answer);
//}

Measured memory_bytes: 1024
/*
 　　　　　／＞　 フ
 　　　　　| 　_　 _|
 　 　　　／`ミ _x 彡
 　　 　 /　　　 　 |
 　　　 /　  ヽ　　 ?
 　／￣|　　 |　|　|
 　| (￣ヽ＿_ヽ_)_)
 　＼二つ
  */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 4005;
const int P = 1e9 + 7;
int f[N][N], x[200500], y[200500], lx, ly, n; ll inv[N<<2], fac[N<<2], ans;
inline ll C(int n, int m) { return fac[n] * inv[m] % P * inv[n-m] % P; }
int main() {
    read(n);
    for (int i = 1;i <= n; i++) 
        read(x[i]), read(y[i]), Mx(lx, x[i]), Mx(ly, y[i]);
    lx++, ly++;
    inv[0] = fac[0] = inv[1] = fac[1] = 1;
    for (int i = 2;i <= 8002; i++) inv[i] = (P - P / i) * inv[P % i] % P;
    for (int i = 2;i <= 8002; i++) fac[i] = fac[i-1] * i % P, inv[i] = inv[i-1] * inv[i] % P;
    for (int i = 1;i <= n; i++) f[lx-x[i]][ly-y[i]]++;
    for (int i = 1;i <= n; i++) ans -= C((x[i] + y[i]) * 2, x[i] + x[i]);
    /* write(ans); */
    ans = ans % P + P;
    /* ans = 0; */
    /* write(lx, ' '), write(ly); */
    /* for (int i = 1;i <= n; i++) write(x[i] + lx, ' '), write(y[i] + ly); */
    for (int i = 1;i <= 2 * lx; i++) 
        for (int j = 1;j <= 2 * ly; j++)
            f[i][j] = (f[i][j] + f[i-1][j] + f[i][j-1]) % P;
    for (int i = 1;i <= n; i++) ans = (ans + f[x[i] + lx][y[i] + ly]) % P;
    write(ans * inv[2] % P);
    return 0;
}

/*
5
2000 2000
1563 1535
1 565
23 656
153 32

*/

Measured memory_bytes: 67348
#include <iostream>
#include <string>

using namespace std;

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

    int res = 1;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] != s[i]) {
            res++;
        }
    }

    cout << res << endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> h(n), dp(n,0);
  for(int i=0; i<n; i++)cin>>h[i];

  dp[1]=abs(h[1]-h[0]);
  for(int i=2; i<n; i++)dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));

  cout<<dp[n-1]<<endl;
}

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

int main() {
	
	int n = 0, c = 0, d = 0, ans = -1;
	string a;
	cin >> n >> a;
	for(int i = 0; i < n; i++){
		map<char, int> s;
		d = 0;
		for(int j = 0; j < i; j++){
			if(s[a[j]] == 0){
			//	cout << "fooo" << endl;
 				s[a[j]]++;
			}
			
		}
		for(int j = n; j >= i; j--){
			//cout << j << endl;
			if(s[a[j]] == 1){
				s[a[j]]++;
				//cout << "aooo" << endl;
				d++;
			}
			
		}
		if(max(ans, d) == d){
			ans = d;
		}
	}
	
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(i,s,e) for(int i=s;i<e;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
int main(){
    fast;
    int n;
    double x,japan=0,bitc=0;
    string y;
    cin>>n;
    while(n--){
        cin>>x>>y;
        if(y=="JPY")
            japan+=x;
        else
            bitc+=x;
    }
    cout<<(japan+bitc*380000.00);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long k = sc.nextLong();
		int a[] = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		long ans = 0;
		long cnt1 = 0;
		long cnt2 = 0;
		long mod = 1000000007;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(a[i] > a[j]) {
					cnt1++;
				}
			}
			for(int j = i + 1; j < n; j++) {
				if(a[i] > a[j]) {
					cnt2++;
				}
			}
		}
//			System.out.println(before);
//			System.out.println(after);
		ans = (((cnt1 % mod) * ((k * (k - 1)) / 2 % mod)) % mod) % mod;
		ans = (ans + (cnt2 * k));
		ans = ans % mod;
		System.out.print(ans);
	}
}


Measured memory_bytes: 25972
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(20);

    int n;
    cin >> n;
    double ans = 0;
    while(n--)
    {
        static double x;
        cin >> x;
        ans += 1.0 / x;
    }
    ans = 1.0 / ans;
    cout << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;
LL n , m;
int main()
{
	scanf("%lld%lld" , &n , &m);
	if(n * 2 <= m) printf("%lld\n" , n + (m - 2 * n) / 4);
	else printf("%lld\n" , m / 2);
}

Measured memory_bytes: 128
#include <string>
#include <vector>
#include <iostream>
#define int long long
using namespace std;

const int N = 17, P = 1 << N;

bool b[P];
int n, a[N][N], maxi[P], p[N], c[P];

int group(int i) {
  if(c[i] == 1)
    return 0;
  if(b[i])
    return maxi[i];
  b[i] = true;
  vector<int> l;
  for(int j = i, k = 0; k < n; j /= 2, k++)
    if(j % 2 == 1)
      l.push_back(k);
  for(int j = 0; j < c[i]; j++)
    for(int k = j+1; k < c[i]; k++)
      maxi[i] += a[l[j]][l[k]];
  for(int val = 0; val < p[c[i]-1]; val++) {
    int sum = p[l[c[i]-1]];
    for(int j = 0, k = val; j < c[i]-1; j++, k /= 2)
      if(k % 2 == 1)
        sum += p[l[j]];
    if(sum != i && sum != 0) {
      maxi[i] = max(maxi[i], group(sum) + group(i - sum));
    }
  }
  return maxi[i];
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  for(int i = 0; i < N; i++)
    p[i] = 1 << i;
  for(int i = 0; i < P; i++) {
    int j = i;
    while(j != 0) {
      c[i] += j % 2;
      j /= 2;
    }
  }
  
  cin >> n;
  
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      cin >> a[i][j];
  
  cout << group((1 << n) - 1);
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { 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(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi c(n);
    rep(i, n) cin >> c[i];
    sort(c.rbegin(), c.rend());
    mint ans = 0;
    rep(i, n) {
        ans += mint(c[i]) * mint(i+2);
    }
    ans *= mint(4).pow(n-1);
    cout << ans << endl;
}

Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    int n = cast(int)a.length;
    auto indices = new int[n];
    for (int i = 0; i < n; i++) {
        indices[a[i]-1] = i;
    }

    int ans = 0;
    int end = 0;
    int len = 0;
    for (int beg = 0; beg < n; beg++) {
        while (end < n && (beg == end || indices[end-1] < indices[end])) {
            len++;
            end++;
        }

        ans = max(ans, len);

        if (beg == end) end++;
        else len--;
    }
    return n - ans;
}

void main() {
    int n = readint;
    int[] a;
    foreach (_; 0..n) a ~= readint;

    writeln(calc(a));
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
//const int INF=1e+11;
const int NMAX=8;
const int MOD=10000;
const int dbase=80*160;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
ll n,m;
cin>>n>>m;
vector<ll> a(n,0);
ll ans1=0;
ll ans2=0;

rep(i,m){
	ll p1;string s1;
	cin>>p1>>s1;
	p1--;
	if (s1=="AC"){
		if (a[p1]==-1)continue;

		ans1++;
		ans2+=a[p1];
		a[p1]=-1;
	}
	if (s1=="WA"){
		if (a[p1]==-1)continue;
		a[p1]++;
	}

}
cout<<ans1<<' '<<ans2;



}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;
const int maxn=1e7+5;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    s[3]='8';
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
map<string, int> f;
 
main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, mf = 0;
	string s;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s;
		f[s]++;
		mf = max(mf, f[s]);
	}
	for (auto i : f)
		if (i.second == mf) cout << i.first << '\n';
}

Measured memory_bytes: 23936
#include<stdio.h>
#include<queue>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c;
    d=max(a,b);
    e=max(b,c);
    f=max(d,e);
    cout<<(a+b+c-f);
}


Measured memory_bytes: 256
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sin
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
count=0
point=[]
for i in range(n-1):
    if count%2==0 and lis[i+1]-lis[i]>0:
        point.append(lis[i])
        count+=1
    if count%2==1 and lis[i+1]-lis[i]<0:
        point.append(lis[i])
        count+=1
'''if count%2==1 and lis[n-1]-lis[n-2]>=0:
    point.append(lis[n-1])
elif count%2==0 and lis[n-1]-lis[n-2]<=0:
    point.append(lis[n-1])'''
point.append(lis[-1])   
#print(point)
#print(lis[-1])
money=1000
for i in range(len(point)//2):
    x=money//point[2*i]
    y=money%point[2*i]
    money=y+x*point[2*i+1]
print(money)
    
    
        
        
        



        
    
    


    


    


Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define dprint(v) cout << #v"=" << v << endl //;)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define INF (ll)1e16
#define endl '\n'
#define isin(x,y) ((y).find(x)!=(y).end())
#define forr(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef pair<int,int> ii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
        cin>>n;
        vector<pll> v(n);
        forn(i,n){
            cin>>v[i].ff;
            v[i].ss=i;
        }
        sort(rall(v));
        forn(i,n){
            cout<<(i==v[0].ss?v[1].ff:v[0].ff)<<endl;
        }
	return 0;
}


Measured memory_bytes: 4736
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let n: usize = iterator.next().unwrap().parse().unwrap();

    let a = max(h, w);

    if n % a == 0 {
        format!("{}", n / a)
    } else {
        format!("{}", n / a + 1)
    }
}


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

int main (){

    int a, b;
    cin >> a >> b;
    int x = a + b;
    int k = x%2;
  
  int y = x/2;




    if(k ==0){

    }
    else{
      y++;

    }

    cout << y <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    int N;
    cin >> N;
    int i=0;
    while (1)
    {
        if(i*1000 >= N){
            break;
        }
        i++;
    }
    cout << 1000*i - N;
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  map<string, int> week = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}
  };
  string S;
  cin >> S;
  cout << week[S] << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
const int INF = 2e9;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll k; cin >> k;
  if(k==1 || k==7){
    cout << 1 << endl;
    return 0;
  }
  if(k%2==0 || k%5==0){
    cout << -1 << endl;
    return 0;
  }
  ll a = 7%k;
  set<int> st;
  st.insert(a);
  REP(i,k+1){
    a = (a*10+7) % k;
    if(st.count(a)){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3608