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


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	
 	int a, b, h;
 	cin >> a >> b >> h;
 	cout << h * ((a+b) / (double) 2) << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 2001000
int n,m,a[N],i;
typedef pair<int,int> pa;
pa s[N];
void insert(pa &x,int y)
{
	if (y==x.fi||y==x.se) return ;
	if (a[y]>a[x.fi]) x.se=x.fi,x.fi=y;
	else if (a[y]>a[x.se]) x.se=y;
}
int main()
{
	scanf("%d",&n);
	m=(1<<n);
	for (i=0;i<m;i++) scanf("%d",&a[i]);
	for (i=0;i<m;i++)
	{
		s[i]=mp(i,m);
		for (int j=0;j<n;j++) if (i&(1<<j)) 
		{
			int t=i^(1<<j);
			insert(s[i],s[t].fi);
			insert(s[i],s[t].se);
		}
	}
	int maxx=0;
	for (i=1;i<m;i++)
	{
		maxx=max(maxx,a[s[i].fi]+a[s[i].se]);
		printf("%d\n",maxx);
	}
}

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

using namespace std;

int main() {
    // 考え方メモ
    // 具体例
    // N=11の場合、1~9->9
    // N=136の場合、9 + 100~136 -> 145
    // N=100000の場合、9 + 900 + 90000 -> 90909
    // 抽象化
    // 先頭が偶数桁の場合、一つ下の奇数桁のパターンは、90..0
    // 先頭が奇数桁の場合、その桁の数の最小値~Nまで、10..0 ~ N

    int N;
    cin >> N;

    int tmpNum = N;  // 桁数を求めるために使う
    int NSize = 0;   // 桁数
    while (tmpNum > 0) {
        tmpNum /= 10;
        NSize++;
    }

    int count = 0;
    if (NSize % 2) {                             // 奇数の場合
        int minInTopDigit = pow(10, NSize - 1);  // 先頭の桁数の最小値
        count = N - minInTopDigit + 1;           // 先頭の桁数の数字の数
        for (int i = 1; i < NSize - 1; i++) {
            if ((i % 2)) count += 9 * pow(10, i - 1);
        }
    } else {  // 偶数の場合
        for (int i = 1; i <= NSize - 1; i++) {
            if ((i % 2)) count += 9 * pow(10, i - 1);
        }
    }

    cout << count << endl;

    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    string card1, card2;
    int score1 = 0;
    int score2 = 0;
    for (int i = 0; i < n; i++) {
        cin >> card1 >> card2;
        if (card1 > card2)
            score1 += 3;
        else if (card1 < card2)
            score2 += 3;
        else {
            score1++;
            score2++;
        }
    }

    cout << score1 << " " << score2 << endl;
    return 0;
}



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

#define ll long long
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define vii vector<int,int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define umii unordered_map<int,int>
#define mii map<int,int>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a ; i<b ; i++)

const long long MOD = 1e9+7;

void solve() {
	int n;
	cin >> n;
	vll l(n);
	for(int i=0; i<n; i++)
		cin >> l[i];
	sort(l.begin(), l.end());
	int ans=0;
	for(int i=0; i<n; i++) {
		for(int j=i+1; j<n; j++) {
			for(int k=j+1; k<n; k++) {
				if(l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i] && (l[i]+l[j]>l[k]))
					ans++;
			}
		}
	}
	cout << ans << endl;
}

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

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

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int &e: a) {
    cin >> e;
  }
  sort(a.begin(), a.end());
  
  int r = 0;
  int sub = 1;
  for (int e: a) {
    if (x >= e) {
      x -= e;
      ++r;
    } else {
      sub = 0;
    }
  }
  if (x == 0)
    sub = 0;
  r -= sub;
  cout << max(0, r) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define sec second
#define pii pair<int, int>
int n, m, k, x, y, a, b, sum, ans;
char s[1005];
int main () {
	scanf("%s", s);
	n=strlen(s);
	for (int i=0;i<n; i++) {
		if (s[i]=='S') {
			x++;
		} else if (s[i]=='N') {
			 y++;
		} else if (s[i]=='E') {
			a++;
		} else {
			b++;
		}
	}
	if (((x&&y)||(x==0&&y==0))&&((a&&b)||(a==0&&b==0))) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int i, j, k;
	int x, y, z;//10000, 5000, 1000
	int N, Y;
	int possibility;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	Y = atoi(ch);

	possibility = 0;
	for(x = 0; x <= N; x += 1) {
		for(y = 0; y <= N - x; y += 1) {
			z = N - x - y;
			if(z < 0) {
				break;
			}
			if(10000 * x + 5000 * y + 1000 * z == Y) {
				possibility = 1;
				break;
			}
		}
		if(possibility == 1) {
			break;
		}
	}

	if(possibility == 1) {
		printf("%d %d %d\n", x, y, z);
	} else {
		printf("-1 -1 -1\n");
	}

	return 0;
}


Measured memory_bytes: 2124
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

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

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

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


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

printf("%d\n",pop());
return 0;
    
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  if (A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  char s[102];
  int i,j;
  int n;
  int flag = 0;

  scanf("%d %s", &n, s);

  for(i = 0,j = n/2;i < n/2;i++,j++){
    if(s[i] != s[j]) flag = 1;
  }

  if(n % 2 == 1 || n == 1 || flag == 1) printf("No\n");

  else printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void solve()
{   string s;
    cin>>s;
    int n  = s.length();
    if(s[n-1]=='s'){
        cout<<s+"es"<<'\n';
    }
    else
    {
        cout<<s+"s"<<'\n';
    }
    
   
}
int main(){
    IOS;
    int tt;
    tt = 1;
    // cin>>tt;
    int i = 1;
    while(tt--){
        // cout<<"tc "<<i<<" ";
        solve();
        i++;
    }
    return 0;
}


Measured memory_bytes: 3644
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if ((a<9) && (b<9)) printf("Yay!");
	    else printf(":(");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  int N,L;
  scanf("%d%d",&N,&L);
  int S;
  S = (N*(2*L + N-1))/2;
  if (L>=0) {
    S = S-L;
  } else if (L+N-1 < 0) {
    S = S-(L+N-1);
  } else {
    S = S;
  }

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

  return 0;
}


Measured memory_bytes: 128
from bisect import bisect_left, bisect_right, insort_left, insort_right

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(lambda x: int(x)-1, input().split())))


    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_left(C, b))

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24948
#include"bits/stdc++.h"
using namespace std ;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



int n ,a,b;


int main(){

	IOS

	cin >> n >> a >>b;

	string s ;

	cin >> s;

	int  limit= a+b;

	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='a' && (a>0 || b>0) ){

			cout << "Yes" << '\n';
			
			if(a>=0)a--;

            if(a==-1)b--;
            

		}

		else if(s[i] =='b' && b>0){

			cout << "Yes" << '\n';

			if(b>0)b--;

		}

		else{
			cout << "No" << '\n';
		}

	}




	
 
}

Measured memory_bytes: 848
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n]
    }
    let mut pair = vec![0; n];
    a.sort();
    let mut i = n;
    let mut skip = false;
    while i > 1 {
        if skip {
            skip = false;
            i -= 1;
            continue;
        }
        if a[i - 1] == a[i - 2] {
            if pair[0] == 0 {
                pair[0] = a[i - 2];
            } else {
                pair[1] = a[i - 2];
                break;
            }
            skip = true;
        }
        i -= 1;
    }
    println!("{}", pair[0] * pair[1]);
}


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

int main() {
  int n,k,x;
  cin >> n >> k;
  int i;
  int p=0;
  for(i=0;i<n;i++){
    cin >> x;
    if(x*2>k){
      p+=(k-x)*2;
    }else{
      p+=x*2;
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<memory.h>
#include<cstdio>
#include<utility>
#include<algorithm>
#define mp make_pear
#define pd push_bake
#include<bitset>
#include<cassert>
#include<climits>
#include<complex>
#include<stack>
#include<numeric>
#include<memory>
#include<functional>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<stack>
using namespace std;
int a,b,c,d,a1,b1,c1,d1; 
string s;
int main(){
	cin>>s;
    a1=a=s[0]-'0';
    b1=b=s[1]-'0';
    c1=c=s[2]-'0';
    d1=d=s[3]-'0';
    for(int i=0;i<=1;i++){
    	b=-b;
    	for(int j=0;j<=1;j++){
    		c=-c;
    		for(int f=0;f<=1;f++){
    			d=-d;
    	        if(a+b+c+d==7){
    	        	cout<<a;
    	        	if(i)cout<<"+"<<b1;
    	        	else cout<<"-"<<b1;
    	        	if(j)cout<<"+"<<c1;
    	        	else cout<<"-"<<c1;
    	        	if(f)cout<<"+"<<d1<<"=7\n";
    	        	else cout<<"-"<<d1<<"=7\n";
    	        //	cout<<s;
    	        	return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(int argc, char const *argv[])
{
	string str;
	cin>>str;
	if (str.find("A")!=string::npos)
	{
		if (str.find("B")==string::npos)
		{
			cout<<"No";
		}
		else cout<<"Yes";
	}
	else if (str.find("B")!=string::npos)
	{
		if (str.find("A")==string::npos)
		{
			cout<<"No";
		}
		else cout<<"Yes";
	}
	cout<<endl;
	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector< vector<int> > V(N, vector<int>());
    vector< pair<int, int> > edge;

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        V[a].emplace_back(b);
        V[b].emplace_back(a);
        edge.emplace_back(make_pair(a, b));
    }

    int K = 0;            /* 塗り分ける色の数 */
    map< pair<int, int>, int > I; /* どの辺が何色になったか */

    queue<int> q;         /* 幅優先探索 */
    vector<int> cs(N, 0);
    vector<int> used(N, 0);  /* 一度でも通ったことがあるか */

    used[0] = 1;
    q.emplace(0);
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        if (K < (int)V[v].size())
            K = V[v].size();
        int cur = 1;
        for (int u: V[v]) {
            if (used[u])   /* 一度でも通った頂点はもう計算しない */
                continue;
            if (cur == cs[v])
                cur++;
            cs[u] = I[make_pair(u, v)] =
                    I[make_pair(v, u)] = cur++;
            used[u] = 1;
            q.emplace(u);
        }
    }

cout << K << endl;
for (auto p: edge) {
    cout << I[p] << endl;
}
return 0;
}

Measured memory_bytes: 20084
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
	Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		double ans=0;
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
			ans+=b[i];
		}
		ans/=a;
		double min=1145141919;
		int minn=0;
		for(int i=0;i<a;i++) {
			if(Math.abs(b[i]-ans)<min) {
				min=Math.abs(b[i]-ans);
				minn=i;
			}
		}
		System.out.println(minn);
	}
}

Measured memory_bytes: 23380
#include <algorithm>
#include <bits/stdc++.h>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/cumsum.hpp
#ifndef CUMSUM_HPP
#define CUMSUM_HPP


/*
usage:

std::vector<std::vector<std::int_fast64_t>> a;
const std::vector<std::vector<std::int_fast64_t>> cumsum = tools::cumsum(a);
*/

namespace tools {
  template <typename T>
  std::vector<T> cumsum(const std::vector<T>& source) {
    std::vector<T> result({0});
    result.reserve(source.size() + 1);
    for (const T& x : source) {
      result.push_back(result.back() + x);
    }
    return result;
  }

  template <typename T>
  std::vector<std::vector<T>> cumsum(const std::vector<std::vector<T>>& source) {
    if (source.empty()) return std::vector<std::vector<T>>({std::vector<T>({0})});
    const std::size_t n1 = source.size();
    const std::size_t n2 = source.front().size();
    std::vector<std::vector<T>> result(n1 + 1, std::vector<T>(n2 + 1, 0));
    for (std::size_t i = 0; i < n1; ++i) {
      for (std::size_t j = 0; j < n2; ++j) {
        result[i + 1][j + 1] = result[i + 1][j] + source[i][j];
      }
    }
    for (std::size_t j = 0; j < n2; ++j) {
      for (std::size_t i = 0; i < n1; ++i) {
        result[i + 1][j + 1] += result[i][j + 1];
      }
    }
    return result;
  }
}

#endif

// main.cpp

int main() {
  i64 N, M, Q;
  std::cin >> N >> M >> Q;

  std::vector<std::vector<i64>> points(N, std::vector<i64>(N, 0));
  for (i64 i = 0; i < M; ++i) {
    i64 L_i, R_i;
    std::cin >> L_i >> R_i;
    --L_i;
    --R_i;
    ++points[L_i][R_i];
  }

  const std::vector<std::vector<i64>> cumsum = tools::cumsum(points);

  for (i64 i = 0; i < Q; ++i) {
    i64 p_i, q_i;
    std::cin >> p_i >> q_i;
    --p_i;
    --q_i;
    std::cout << cumsum[q_i + 1][q_i + 1] - cumsum[p_i][q_i + 1] - cumsum[q_i + 1][p_i] + cumsum[p_i][p_i] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

const int MAX_N = 3003;
double probability_heads[MAX_N][MAX_N], probability[MAX_N];

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

    for(int i = 1; i <= no_of_coins; i++)
        cin >> probability[i];

    memset(probability_heads, 0, sizeof(probability_heads));
    probability_heads[0][0] = 1;

    for(int i = 1; i <= no_of_coins; i++)
    {
        double head_event = probability[i], tail_event = 1 - probability[i];

        probability_heads[0][i] = tail_event*probability_heads[0][i - 1];

        for(int heads = 1; heads <= i; heads++)
        {
            probability_heads[heads][i] = head_event*probability_heads[heads - 1][i - 1] + tail_event*probability_heads[heads][i - 1];
        }
    }

    double answer = 0;
    for(int i = no_of_coins/2 + 1; i <= no_of_coins; i++)
        answer += probability_heads[i][no_of_coins];

    cout << setprecision(9) << answer;
    return 0;
}


Measured memory_bytes: 70784
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int inputSecond = scanner.nextInt();

        int hour   =  inputSecond / 3600;
        int minute =  inputSecond / 60 - hour*60;
        int second =  inputSecond % 60;

        System.out.println(hour+":"+minute+":"+second);

    }
}



Measured memory_bytes: 26200
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

vector <int> g[maxn];
bool vis[maxn], ans;
int mxDeg, num;
int n, m;

void dfs (int v, int start, int parent = -1) {
	vis[v] = true;
	for (auto u : g[v]) {
		if (u == parent)
			continue;
		if (u == start)
			ans = true;
		if (!vis[u] && sz(g[u]) != 4)
			dfs(u, start, v);
	}
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		--v; --u;
		g[v].PB( u );
		g[u].PB( v );
	}
	for (int i = 0; i < n; i++) {
		if (sz(g[i]) % 2)
			return cout << "No\n", 0;
		mxDeg = max(mxDeg, sz(g[i]));
		if (sz(g[i]) == 4)
			num++;
	}
	if (mxDeg > 4 || num > 2)
		return cout << "Yes\n", 0;
	if (num <= 1)
		return cout << "No\n", 0;
	for (int i = 0; i < n; i++)
		if (sz(g[i]) == 4) {
			dfs(i, i);
			break;
		}
	cout << ((ans) ? "Yes" : "No") << "\n";
}





Measured memory_bytes: 7040
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
//インクルード(アルファベット順)
#include<bits/stdc++.h>
using namespace std;
typedef int ll;

#define REP(i,n) for(ll i=0;i<n;i++)
//xにはvectorなどのコンテナ
#define SIZE(x) ll(x.size())
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n-1));
    REP(i,n){
        REP(j,n-1){
            ll c;cin>>c;
            if(c-1<i)a[i][j]=c-1+n*i;
            else a[i][j]=i+n*(c-1);
        }
    }
    map<ll,ll> d;
    REP(i,n)d[a[i][0]]++;
    vector<ll> b(n,0);
    ll ans=0;
    deque<ll> nextd;
    deque<ll> cleard;
    while(!d.empty()){
        ans++;
        bool g=true;
        for(const auto& i : d){
            if(i.S==2){
                g=false;
                ll e=(i.F)/n;ll f=(i.F)%n;
                cleard.insert(cleard.begin(),i.F);
                b[e]++;b[f]++;
                if(b[e]<n-1)nextd.insert(nextd.begin(),a[e][b[e]]);
                if(b[f]<n-1)nextd.insert(nextd.begin(),a[f][b[f]]);
            }
        }
        if(g){
            cout<<-1<<endl;
            return 0;
        }
        ll ln,lc;ln=SIZE(nextd);lc=SIZE(cleard);
        REP(i,ln){
            d[*--nextd.end()]++;
            nextd.pop_back();
        }
        REP(i,lc){
            d.erase(*--cleard.end());
            cleard.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7664
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut c: [usize; n],
    }

    c.sort();

    let mut ans = 0;
    for i in 1..n {
        ans += c[n - 1 - i / 2]
    }

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


Measured memory_bytes: 6308
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main() {
	int n,ans=0;
	int i=0;
	int L[200];
	
	cin>>n;
	
	while(cin>>L[i]){
		i+=1;
	}
	
	sort(L,L+i);
	
	for(int j=0;j<n;j++){
		ans+=L[2*j];
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

#define f(i,a) for(int i=0;i<a;i++)
#define absc(x) abs(ir[i]-row[x])<2&&abs(ic[i]-col[x])<2

char str[17][17];
int dx[]={-1,-1,-1,0,0,0,1,1,1},dy[]={-1,0,1,-1,0,1,-1,0,1};
int u[17][17],v[17][17],ir[17],ic[17];
int row[300],col[300];
int id,sz,a,b;
long long pow10[17];

struct st{
    long long v;
    int i;
    st(){i=0,v=0;}
};
bool operator<(const st& a,const st& b){
    return a.v!=b.v?a.v<b.v:a.i<b.i;
}
map<st,int>dp;
int abs(int a){return max(a,-a);}
int solve(int a,st b){
    if(dp.count(b))return dp[b];
    f(i,id){
        int cnt=0;
        for(int j=a;j<sz;j++)
            if(absc(j))cnt++;
        if(cnt<b.v%pow10[i+1]/pow10[i])
            return dp[b]=1e9;
    }
    if(a==sz)return dp[b]=0;
    int ret=1e9;
    b.i++;
    bool ne=true;
    f(i,id)if(absc(a)&&b.v%pow10[i+1]/pow10[i]==0)ne=false;
    if(ne){
        f(i,id)if(absc(a))b.v-=pow10[i];
        ret=min(ret,solve(a+1,b)+1);
        f(i,id)if(absc(a))b.v+=pow10[i];
    }
    ret=min(ret,solve(a+1,b));
    b.i--;
    return dp[b]=ret;
}
int main(){
    pow10[0]=1;
    for(int i=1;i<17;i++)pow10[i]=pow10[i-1]*10;
    while(cin>>a>>b,a){
        id=sz=0;
        dp.clear();
        st w;
        f(i,a)
            cin>>str[i];
        f(i,a)f(j,b)
            v[i][j]=u[i][j]=0;
        f(i,a)f(j,b)
            if('0'<=str[i][j]&&str[i][j]<='9'){
                ir[id]=i;
                ic[id]=j;
                w.v+=pow10[id++]*(str[i][j]-'0');
                v[i][j]=str[i][j]-'0';
                f(k,9)
                    if(0<=i+dx[k]&&i+dx[k]<a&&0<=j+dy[k]&&j+dy[k]<b&&str[i+dx[k]][j+dy[k]]!='.')
                        u[i+dx[k]][j+dy[k]]++;
            }
        f(i,a)f(j,b)if(u[i][j])
            row[sz]=i,col[sz++]=j;
        cout<<solve(0,w)<<endl;
    }
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long

typedef pair<int, int> ii;

const int mod = 1e9 + 7;

const int N = 1e5 + 5;

const int inf = 1e15;

int n, dp[N][2];

vector<int> graph[N];

void dfs(int u, int p) {
    for(int i = 0; i < graph[u].size(); i++) {
        int v = graph[u][i];
        if(v == p) continue;
        dfs(v, u);
    }
    int sum0 = 1, sum1 = 1;
    for(int i = 0; i < graph[u].size(); i++) {
        int v = graph[u][i];
        if(v == p) continue;
        sum0 = (sum0 * dp[v][0]) % mod;
        sum1 = (sum1 * (dp[v][0] + dp[v][1])) % mod;
    }
    dp[u][1] = sum0; dp[u][0] = sum1;
    //cout << dp[u][1] << " " << dp[u][0] << " " << u << "\n";
    if(graph[u].size() == 1 && u != 1) {
        dp[u][0] = 1;
        dp[u][1] = 1;
    }
}

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(1, 1);
    cout << (dp[1][0] + dp[1][1]) % mod;
}


Measured memory_bytes: 12800
#include <stdio.h>
#include <math.h>

int main(void) {
  int i, n;
  float debt = 100000, interest = 0.05;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    debt += debt * interest;
    debt /= 1000;
    debt = ceil(debt) * 1000;
  }

  printf("%d\n", (int)debt);

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n, a[maxn + 10], b[maxn + 10];
int bela[maxn + 10], belb[maxn + 10];
int ans;

namespace flow {
	struct edge {
		int to, cp, fl, rev;
	};
	vector<edge> g[maxn + 10];
	int n, s, t, cur[maxn + 10], d[maxn + 10];
	queue<int> q;

	void addeg(int l, int r, int w) {
		g[l].push_back((edge){r, w, 0, (int)g[r].size()});
		g[r].push_back((edge){l, 0, 0, (int)g[l].size() - 1});
	}

	bool bfs() {
		for (int i = 1; i <= n; ++i) d[i] = i == s ? 0 : -1;
		q.push(s);
		while (!q.empty()) {
			int p = q.front(); q.pop();
			for (int i = 0; i < (int)g[p].size(); ++i) {
				edge e = g[p][i];
				if (e.cp > e.fl && d[e.to] == -1) {
					d[e.to] = d[p] + 1; q.push(e.to);
				}
			}
		}
		return d[t] != -1;
	}

	int dfs(int p, int a) {
		if (p == t) return a;
		int ans = 0;
		for (int &i = cur[p]; i < (int)g[p].size(); ++i) {
			edge &e = g[p][i];
			if (e.cp > e.fl && d[p] + 1 == d[e.to]) {
				int now = dfs(e.to, min(e.cp - e.fl, a));
				e.fl += now; g[e.to][e.rev].fl -= now;
				ans += now; a -= now;
				if (!a) break;
			}
		}
		return ans;
	}

	int solve() {
		int ans = 0;
		while (bfs()) {
			for (int i = 1; i <= n; ++i) cur[i] = 0;
			ans += dfs(s, 1e9);
		}
		return ans;
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), ++a[i];
	for (int i = 1; i <= n; ++i) scanf("%d", &b[i]), ++b[i];
	flow::s = 1; flow::t = 2; flow::n = 2;
	for (int i = 1; i <= n; ++i)
		if (!bela[i]) {
			++flow::n;
			for (int j = i; !bela[j]; j = a[j])
				bela[j] = flow::n;
		}
	for (int i = 1; i <= n; ++i)
		if (!belb[i]) {
			++flow::n;
			for (int j = i; !belb[j]; j = b[j])
				belb[j] = flow::n;
		}
	ans = n;
	for (int i = 1; i <= n; ++i)
		if (a[i] == b[i] && a[i] == i) --ans;
		else if (a[i] == i && b[i] != i)
			flow::addeg(1, belb[i], 1);
		else if (a[i] != i && b[i] == i)
			flow::addeg(bela[i], 2, 1);
		else if (a[i] == b[i] && a[i] != i) {
			flow::addeg(bela[i], belb[i], 1);
			flow::addeg(belb[i], bela[i], 1);
		} else flow::addeg(bela[i], belb[i], 1);
	printf("%d", ans - flow::solve());
}


Measured memory_bytes: 49280
def main():
    n = int(input())
    a = tuple(int(x) for x in input().split())

    memo = [0] * n ** 2
    for i, aa in enumerate(a):
        memo[i * (n + 1)] = aa

    for l in range(n - 2, -1, -1):
        for r in range(l + 1, n):
            memo[l * n + r] = max(a[l] - memo[(l + 1) * n + r], a[r] - memo[l * n + r - 1])

    print(memo[n - 1])


if __name__ == '__main__':
    main()

# 連投の結果分かったこと
#
# [1]
# memoの初期化
# None => 530 ms
# 0 => 290 ms
# メモ化する配列の初期値が違うだけで、速度に大差
# Noneで初期化すると、代入時にint型に直すような処理が入るのか？
#
# [2]
# if __name__ == '__main__':
# なくすと遅くなった
# 530 ms -> 615 ms
#
# [3]
# map(int, input().split())
# int(x) for x in input().split()
# 数 msの違い？
#
# [4]
# メモ化配列の一次元化
# 287 ms よりこのコードが速ければ、一次元化した方がよい

# [l,r]を
# l:=配列aの右端から左にシフト
# r:=lと一致する位置からn-1まで右にシフト
# と考えると、l==rは既にメモ化済みなので、l=n-2以前、r=l+1以降を調べればよい
# 漸化式で使う値は、
# lがより右にいるときの計算結果（前のループで計算済み）と
# rがより左にいるときの計算結果（一番左でもl==rなので計算済み）
# なので、参照する値がNoneになることはなく、Noneのチェックは不要になる


Measured memory_bytes: 110704
#include <iostream>
using namespace std;
int main(void) {
  int k;
  cin >> k;
  int n = k % 2;
  int m = k / 2;
  if(n == 0) {
    cout << m * m << endl;
  }
  else {
    cout << m * (m + 1) << endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;
 
int main(){
    string S;
    cin >> S;
    if(S[0] == 'A'){
        cout << 'T' << endl;
    }else if(S[0] == 'T'){
        cout << 'A' << endl;
    }else if(S[0] == 'C'){
        cout << 'G' << endl;
    }else{
        cout << 'C' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder_Beginner_Contest_13
{
    class Program
    {
        //配列にする
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        //Listにする
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
        }
        static void Solve()
        {
            var ABC = Sarray();
            WriteLine(Math.Max(0, ABC[2] - (ABC[0] - ABC[1])));
        }
    }
}

Measured memory_bytes: 13396
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = map(int, input().split())
    uf = UnionFind(n+1)
    for _ in range(m):
        a, b = map(int, input().split())
        uf.union(a, b)
    ans = -min(uf.parents)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14928
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], x = tmp[1];
	int[] m = new int[n];
	int s = 0;
	for (int i = 0; i < n; i++)
	{
	    m[i] = int.Parse(ReadLine());
	    s += m[i];
	}

	x -= s;
	Array.Sort(m);
	int ans = n + x/m[0];
	WriteLine(ans);
    }
}


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

int main() {
	long long int n,b,r;
	cin >> n >> b >> r;
	long long int all = b + r;
	long long int bai = n / all + 1;
	long long int bnum = b * bai;
	long long int noneed;
	noneed = all * bai - n;
	if(noneed <= r){
		cout << bnum << '\n';
	}else{
		cout << bnum - (noneed - r) << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int n=sc.nextInt();
        HashMap<Integer,Integer> pf=new HashMap<>();
        for (int i = 1; i <= n; i++) {
            int s=(int)sqrt(n)+1;
            int t=i;
            for (int j = 2; j <= s; j++) {
                while (t%j==0){
                    pf.put(j,pf.getOrDefault(j,0)+1);
                    t/=j;
                }
            }
            if(t!=1)pf.put(t,pf.getOrDefault(t,0)+1);
        }
        int[] p=new int[25];
        int c=0;
        for (Integer key:pf.keySet())p[c++]=pf.get(key);
        int ans=0;
        for (int i = 0; i < 25; i++) {
            if(p[i]+1>=75)ans++;
        }
        for (int i = 0; i < 25; i++) {
            for (int j = 0; j < 25; j++) {
                if(i==j)continue;
                if(p[i]+1>=3&&p[j]+1>=25)ans++;
                if(p[i]+1>=5&&p[j]+1>=15)ans++;
            }
        }
        for (int i = 0; i < 25; i++) {
            for (int j = 0; j < 25; j++) {
                for (int k = 0; k < 25; k++) {
                    if(i==j||j==k||k==i)continue;
                    if(p[i]+1>=3&&p[j]+1>=5&&p[k]+1>=5&&j>k)ans++;
                }
            }
        }
        out.println(ans);
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX_W 50
#define MAX_H 50
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int H, W;
char S[MAX_H][MAX_W];
char ans[MAX_H][MAX_W];

char bombSearch(int h, int w)
{
  int res = 0;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      int nh = h + i, nw = w + j;
      if (nh < 0 || nh >= H) continue;
      if (nw < 0 || nw >= W) continue;
      if (S[nh][nw] == '#') res++;
    }
  }
  return res + '0';
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> S[i][j];

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        ans[i][j] = bombSearch(i, j);
      }
      else {
        ans[i][j] = '#';
      }
    }
  }

  REP(i, H)
  {
    REP(j, W) { cout << ans[i][j]; }
    cout << endl;
  }

  return 0;
}


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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

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

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans += (i < K ? X : Y);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int n, m;

V g[10];

bool used[10];

int dfs(int i)
{
    int res = 0;

    used[i] = true;

    bool ok = true;
    REP(j, n)
    if (!used[j + 1])
        ok = false;

    if (ok)
    {
        used[i] = false;
        return 1;
    }

    for (int j : g[i])
    {
        if (!used[j])
            res += dfs(j);
    }

    used[i] = false;

    return res;
}

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

    cin >> n >> m;

    REP(i, m)
    {
        int a, b;
        cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    fill(used, used + n + 1, false);

    cout << dfs(1) << endl;

    return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ii solve(int a,int b,int c,int d,int e,int f) {
    // 1<=a<b<=30
    // 1<=c<d<=30
    // 1<=e<=100
    // 100a <= f <= 3000
    double best = -1;
    ii best_at(-1, -1);

    vi dp_w(6001, 0), dp_s(3031, 0);
    vi ws, ss;

    dp_w[0] = dp_s[0] = 1;
    for (int i=0; i<=3000; ++i) {
        if (dp_w[i]) {
            ws.pb(i);
            dp_w[i+100*a] = dp_w[i+100*b] = 1;
        }
        if (dp_s[i]) {
            ss.pb(i);
            dp_s[i+c] = dp_s[i+d] = 1;
        }
    }
    // cerr << ws << endl;
    // cerr << ss << endl;

    for (int w:ws) {
        int solvable = w * e / 100; // わりきれる
        for (int s:ss) {
            if (s > solvable || w+s > f) break;

            double r = 100.0 * s / (w + s);
            if (r > best){
                best = r;
                best_at = ii(w+s, s);
            }
        }
    }

    return best_at;
}

int main() {
    int A,B,C,D,E,F; cin>>A>>B>>C>>D>>E>>F;
    ii ans = solve(A,B,C,D,E,F);
    cout << ans.first << " " << ans.second << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	q, _ := strconv.Atoi(stringLineScan())
	a := make([]int, 100001)
	x := 0
	for i := 1; i < 100001; i++ {
		p1 := PrimeFactors(i)
		p2 := PrimeFactors((i + 1) / 2)
		if len(p1) == 1 && len(p2) == 1 {
			x += 1
		}
		a[i] = x
	}
	for i := 0; i < q; i++ {
		l, _ := strconv.Atoi(stringLineScan())
		r, _ := strconv.Atoi(stringLineScan())
		fmt.Println(a[r] - a[l-1])
	}

}
func PrimeFactors(n int) (pfs []int) {
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}
	if n > 2 {
		pfs = append(pfs, n)
	}
	return
}


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

using namespace std;

int dp[100005][3];
int n;
int happy[100005][3];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>happy[i][0]>>happy[i][1]>>happy[i][2];
    }
    dp[0][0] = happy[0][0]; dp[0][1] = happy[0][1]; dp[0][2] = happy[0][2];
    int ans = -1;
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int max_val = -1;
            for(int q=0;q<3;q++){
                if(j==q) continue;
                max_val = max(max_val, dp[i-1][q]);
            }
            dp[i][j] = max_val + happy[i][j];
        }
    }
    for(int i=0;i<3;i++){
        ans = max(ans, dp[n-1][i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
S = input()

while len(S) >= 5:
    if S[-5:] == 'dream':
        S = S[:-5]
    elif S[-7:] == 'dreamer':
        S = S[:-7]
    elif S[-5:] == 'erase':
        S = S[:-5]
    elif S[-6:] == 'eraser':
        S = S[:-6]
    else:
        break
print('YES' if S == '' else 'NO')


Measured memory_bytes: 3188
# Problem C - Skill Up

# input
N, M, X = map(int, input().split())
book_list = []
for i in range(N):
    book = list(map(int, input().split()))
    book_list.append(book)

# initialization
min_cost = float("INF")
is_ok = False
pattern = []
for i in range(2**N):
    p = [0]*N
    for j in range(N):
        if (i>>j)&1==1:
            p[j] = 1
    pattern.append(p)

# check
for p in pattern:
    tmp_cost = 0
    tmp_list = [0] * M
    tmp_ok = True
    for i in range(N):
        if p[i]==0:
            continue

        tmp_cost += book_list[i][0]
        for j in range(1, M+1):
            tmp_list[j-1] += book_list[i][j]
    for t in tmp_list:
        if t<X:
            tmp_ok = False
            break
    if tmp_ok:
        is_ok = True
        min_cost = min(min_cost, tmp_cost)

# output
if is_ok:
    print(min_cost)
else:
    print(-1)


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

int main(){
  int N;
  cin>>N;
  for (int i=0;i<26;i++){
    for (int j=0;j<16;j++){
      if(4*i+7*j==N){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout <<"No"<<endl;
  return 0;
}

  
      
          

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dp[(1LL<<13)];

int main(){
    // cout << fixed << setprecision(5);

    lli n,m;
    cin>>n>>m;

    REP(i,0,(1LL<<13))dp[i]=INF;
    dp[0]=0;

    REP(i,0,m){
        lli a,b;
        cin>>a>>b;
        lli bit=0;
        REP(j,0,b){
            lli c;
            cin>>c;
            c--;
            bit|=(1LL<<c);
        }
        REP(j,0,(1LL<<n)){
            dp[j|bit] = min(dp[j]+a,dp[j|bit]);
        }
    }
    if(dp[(1LL<<n)-1]==INF)cout<<-1<<endl;
    else cout<<dp[(1LL<<n)-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[105], d = 1;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort (a, a+n);
    for (int i = 0; i < n - 1; i++){
        if (a[i] != a[i+1]) d++;
    }
    cout << d;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    vector<ll> b(N);
    rep(i,N){
        cin >> b[i];
    }
    ll out[N];
    rep(i,N){
        bool isExist = false;
        rep(j,N-i){
            if(b[N-i-1-j]==N-i-j){
                isExist = true;
                out[N-1-i] = N-i-j;
                if(b.size()>1) b.erase(b.begin()+N-i-1-j);
                break;
            }
        }
        if(!isExist){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,N){
        cout << out[i] << endl;
    }
    return 0;
}


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


int solve(vector<int>& v, int pos, vector<int>& memo){

    if(pos==v.size()-1)return 0;
    if(memo[pos]!=-1)return memo[pos];



    if(pos==v.size()-2){
       return memo[pos]= abs(v[pos]-v[pos+1])+solve(v,pos+1,memo);
    }else{

           return  memo[pos]= min(
                    abs(v[pos]-v[pos+1])+solve(v,pos+1,memo),
                    abs(v[pos]-v[pos+2])+solve(v,pos+2,memo)
                    );
    }


}

int main(){

   int n;
   cin>>n;

   vector<int> v;
   for(int i=0;i<n;i++){
       int temp;
       cin>>temp;

   v.push_back(temp);
   }


   vector<int> memo;

   for(int i=0;i<100001;i++){
   memo.push_back(-1);
   }

   int pos=0;
   int sum=0;

   cout<< solve(v,pos,memo) <<endl;
//    cout<<memo[0]<<endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;
const ll INF = (ll) (1e18) + 5;
int main(){
  FASTER;
  int n, k;
  cin >> n >> k;
  vector<int>ar(n);
  for (int i = 0; i < n; i++){
    cin >> ar[i];
  }
  vector<ll> dp(n, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++){
    for (int j = i + 1; j <= i + k; j++){
      if (j < n){
        dp[j] = min(dp[j], dp[i] + abs(ar[i] - ar[j]));
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <cstdio>

constexpr unsigned int m = 1000000007;
int main()
{
  char st[100001];
  scanf("%s", st);
  unsigned int s[4] = {1, 0, 0, 0};
  for (char *p = st; *p; ++p)
  {
    switch (*p)
    {
      case 'A':
        s[1] = (s[1] + s[0]) % m;
        break;
      case 'B':
        s[2] = (s[2] + s[1]) % m;
        break;
      case 'C':
        s[3] = (s[3] + s[2]) % m;
        break;
      default:
        s[3] = (3 * s[3] + s[2]) % m;
        s[2] = (3 * s[2] + s[1]) % m;
        s[1] = (3 * s[1] + s[0]) % m;
        s[0] = 3 * s[0] % m;
        break;
    }
  }
  printf("%u\n", s[3]);
  return 0;
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(a*b,c*d) << endl;
	return 0;
	
}


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

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	int sum;
	sum = 100 * r + 10 * g + b;
	if (sum % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256