akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)


int main() {
	int n;
	while(cin >> n, n) {
		vector<vector<int> > ms(n, vector<int>());
		for(int i = 0; i < n; i++) {
			int m;
			cin >> m;
			for(int j = 0; j < m; j++) {
				int mss;
				cin >> mss;
				mss--;
				ms[i].push_back(mss);
			}
		}
		int k;
		cin >> k;
		vector<int> led(n);
		for(int i = 0; i < k; i++) {
			int j;
			cin >> j;
			j--;
			led[j] = 1;
		}
		bool summable = true;
		// fill one
		int kouho = -1;
		for(int i = 0; i < n; i++) {
			int count = 0;
			for(int j = 0; j < ms[i].size(); j++) {
				if(led[ms[i][j]]) count++;
			}
			if (count == k) {
				if (kouho != -1) {
					cout << -1 << endl;
					goto end_loop;
				}
				kouho = i;
			}
		}
		// fill some
		for(int i = 0; i < n; i++) {
			if (i == kouho) continue;
			for(int j = 0; j < ms[i].size(); j++) {
					led[ms[i][j]] = 2;
			}
		}
		
		for(int i = 0; i < n; i++) {
			if (led[i] == 1) {
				summable = false;
				break;
			}
		}
		if (summable || kouho == -1) {
			cout << -1 << endl;
		}
		else {
			cout << kouho+1 << endl;
		}
		
		end_loop: {}
	}
	
	return 0;
}

Measured memory_bytes: 952
#!/usr/bin/env python3
import sys

input = sys.stdin.readline
mod = 1000000007


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


n = I()

ten = 1
nine = 1
eight = 1
for _ in range(n):
    ten *= 10
    ten %= mod
    nine *= 9
    nine %= mod
    eight *= 8
    eight %= mod

ans = ten - 2 * nine + eight
ans %= mod
print(ans)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll Q,H,S,D;
    cin >> Q >> H >> S >> D;
    ll N;
    cin >> N;
    Q *= 4;
    H *= 2;
    ll m = min(Q,min(H,S));
    ll ans = 0;
    if (m*2 <= D) ans = m * N;
    else ans = D * (N / 2) + m * (N%2);

    cout << ans << '\n';

    return 0;
}

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

using namespace std;

int main(){
    int n;
    int mode;
    int a;
    vector<int> vec;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> mode;
        switch(mode){
            case 0:
                cin >> a;
                vec.push_back(a);
                break;
            case 1:
                cin >> a;
                cout << vec[a] << endl;
                break;
            case 2:
                vec.pop_back();
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n,p;
  cin >> n >> p;
  
  vector<int>bis(n,0);
  for(int i=0;i<n;i++){
    cin >> bis[i];
  }
  
  for(int i=0;i<n;i++){
    bis[i] %= 2;
  }
  
  int odd = 0;
  int even = 0;
  for(int i=0;i<n;i++){
    if(bis[i] == 0) even++;
    else odd++;
  }
  long long ans = 1;
  for(int i=0;i<n;i++){
    ans *= 2;
  }
  
  
  if(odd == 0){
    if(p == 0){
      cout << ans << endl;
    }
    else
      cout << 0 << endl;
  }
  else{
    cout << ans / 2 << endl;
  }
  
  return 0;
}

      

Measured memory_bytes: 256
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

/*lld fac[100001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=100000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}*/


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

lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;



void solve()
{
    cin>>n;
    if(n%2==1)
    {
        cout<<0;
        return;
    }
    m=n;
    ans=n/10;
    
   // cout<<ans<<"\n";
    x=10;
    

    while(x<=m)
    {
        x*=5;
        y = m/x;
        //cout<<y<<" " <<(y/2+(y%2))<< " "<<x<<"\n";
        ans+=(y);
       
    }

    cout<<ans;
    
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
   //  getfac(p2);
    //check the value by which modulo is to be taken
    lld ans=0;
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
                  solve();
        cout<<"\n";
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> hvec;
    for (int i = 0; i < N; ++i) {
        int h;
        cin >> h;
        hvec.push_back(h);
    }
    if (N == 1) {
        cout << "Yes\n";
        return 0;
    }
    int pre_h = hvec[0];
    for (int i = 0; i < N - 1; ++i) {
        int h = hvec[i];
        int next_h = hvec[i+1];
        if (next_h == h - 1) {
            hvec[i+1]++;
        } else if (next_h <= h - 2) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class C
{
	public static void Main()	
	{
		double X = GetDouble();
		Console.WriteLine(Math.Ceiling((-1.0 + Math.Sqrt(8.0 * X + 1.0))/2.0));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,T; cin>>N>>T;
  vector<int> times(N);
  for(auto& t: times) {
    cin>>t;
  }

  ll sum = 0;
  for(int i=1; i<N; i++) {
    int pre_time = times[i-1];
    int now_time = times[i];
    int diff = now_time - pre_time;
    if(diff < T) {
      sum += diff;
    } else {
      sum += T;
    }
  }

  sum += T;
  cout << sum << endl;
}


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

using ll = long long;
using ull = unsigned long long;
constexpr ll mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
using namespace std;

vector<int> E[200050];
int n;
ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
 
ll modpow(ll a, ll n=mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
    vector<int> c(200050);
    vector<ll> dp(200050);
void dfs(int u,int pre){
        dp[u] = 1;
        for(auto v : E[u])if(v != pre){
            
            dfs(v,u);
            (dp[u] *= dp[v])%=mo;
            (dp[u] *= comb(c[v]+c[u],c[v]))%=mo;
            c[u] += c[v];
        }
        c[u]++;
}
auto dfs2(int u,ll pre,ll pv)->void{
        (dp[u] *= pv)%=mo;
        (dp[u] *= comb(n-1,n-c[u]))%=mo;
        for(auto v : E[u])if(pre != v){
            pv = dp[u]*modpow(dp[v]*comb(n-1,c[v])%mo)%mo;
            dfs2(v,u,pv);
        }
}
int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    cin>>n;
    for(int i=0;i<n-1;++i){
        int a,b;
        cin>>a>>b;
        a--;b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    dfs(0,-1);
    dfs2(0,0,1);
    for(int i=0;i<n;++i)cout << dp[i] << endl;
    return 0;
}

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

int main() {
  
  string s, t; cin >> s >> t;
  
  sort(s.begin(), s.end());
  
  sort(t.begin(), t.end());
  
  reverse(t.begin(), t.end());
  
  if (s < t) cout << "Yes" << endl;
  
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
N,K=map(int,input().split())
A = [int(i) for i in input().split()]
mod = 10**9 + 7
st = 1
st_list = [0] * N
st_rev = [0] * N
for i in range(N-1):
    st *= (i+1)
    st %= mod
    st_list[i] = st
    st_rev[i] = pow(st,mod-2,mod)
list.sort(A,reverse = True)
ans = 0
for i in range(N+1-K):
    ans += (A[i] * st_list[N-1-i-1] * st_rev[K-2] *st_rev[max(N-K-i-1,0)])%mod
    ans %= mod
list.sort(A)
for i in range(N+1-K):
    ans -= (A[i] * st_list[N-1-i-1] * st_rev[K-2] *st_rev[max(N-K-i-1,0)])%mod
    ans %= mod
print(ans)

Measured memory_bytes: 90604
import java.io.PrintWriter;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int sum = n*l +  n*(1+n)/2 - n;
		// 全て正の場合
		if(l>0) sum -= l;
		// 全て負の場合
		else if(l + n - 1<0) sum -= l+n-1;
		out.println(sum);

		out.flush();
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	char b;
    cin >> b;
    if(b=='A')b='T';
    else if(b=='C')b='G';
    else if(b=='G')b='C';
    else if(b=='T')b='A';
    cout << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
class UnionFind {
  public:
    vector<int> parent;
    UnionFind(int n) {
        parent = vector<int>(n, -1);
    }
    int root(int a) {
        if (parent[a] < 0) return a;
        return parent[a] = root(parent[a]);
    }
    int size(int a) {
        return -parent[root(a)];
    }
    bool is_connected(int a, int b) {
        return root(a) == root(b);
    }
    bool connect(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;
    }
};
int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (auto & a : A) cin >> a;
    for (auto & b : B) cin >> b;
    vector<int> AS = A, BS = B;
    sort(AS.begin(), AS.end());
    sort(BS.begin(), BS.end());
    map<int, int> AB, BI;
    UnionFind UF(N);
    for (int i = 0; i < N; ++i) {
        if (BS[i] < AS[i]) {
            puts("No");
            return 0;
        }
        AB[AS[i]] = BS[i];
        BI[B[i]] = i;
    }
    for (int i = 0; i < N; ++i) {
        UF.connect(i, BI[AB[A[i]]]);
    }
    for (int i = 1; i < N; ++i) {
        if (BS[i-1] >= AS[i]) {
            puts("Yes");
            return 0;
        }
        if (UF.root(i) != UF.root(i-1)) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 13568
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

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

  vector<int> cntACs;
  int cnt = 0;
  cntACs.push_back(cnt);
  for(int i = 1; i < n; i++) {
    if(s[i - 1] == 'A' && s[i] == 'C') cnt++;
    cntACs.push_back(cnt);
  }
  vector<P> ivl(q);
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    ivl[i] = make_pair(l, r);
  }

  rep(i, q) {
    int ans = cntACs[ivl[i].second] - cntACs[ivl[i].first];
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
int N, M;
int main() {
    cin >> N >> M;
    vector<long long> a(N, 0);
    vector<long long> b(N, 0);
    vector<long long> c(M, 0);
    vector<long long> d(M, 0);

    for(int i = 0; i < N; ++i) {
        cin >> a.at(i) >> b.at(i);
    }
    for(int j = 0; j < M; ++j) {
        cin >> c.at(j) >> d.at(j);
    }

    for(int i = 0; i < N; ++i) {
        long long min = 1e+9;
        int check = 0;
        for(int j = 0; j < M; ++j) {
            long long len = abs(a.at(i)-c.at(j)) + abs(b.at(i)-d.at(j));
            if(min > len) {
                min = len;
                check = j+1;
            }
        }
        cout << check << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	int *A = new int[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", A + i);
	}
	int *B = new int[N];
	int c = 0;
	for (int i = N; i >= 1; i--) {
		int cnt = 0;
		for (int j = 2; j <= N / i; j++) {
			cnt += B[j*i - 1];
		}
		if (cnt % 2 == A[i - 1]) {
			B[i - 1] = 0;
		}
		else {
			B[i - 1] = 1;
			c++;
		}
	}
	printf("%d\n", c);
	for (int i = 0; i < N; i++) {
		if (B[i]) {
			printf("%d ", i + 1);
		}
	}
	return 0;
}

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

const int N = 1e5 + 10;
set<pair<int,int> > st;
int n, x[N], mx;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x[i];
		mx = max(mx, x[i]);
	}
	for (int i = 0; i < n; i++)
		if(x[i] != mx)
			st.insert({abs(mx / 2 - x[i]), i});
		
	cout << mx << ' ' << x[(*st.begin()).second];
}



Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    char c;cin>>c;
    cout<<char(c+1)<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
// Problem: 
// 			B - Distance 
// 			Editorial
// 		
// Contest: AtCoder - AtCoder Beginner Contest 174
// URL: https://atcoder.jp/contests/abc174/tasks/abc174_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 *   ﷽
 * In the name of Allah, the Most Gracious, the Most Merciful
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <climits>
#include <cmath>

using namespace std;

int main()
{
	unsigned long long n,d;
	cin>>n>>d;
	int ans = 0;
	while(n--)
	{
		unsigned long long a,b;
		cin>>a>>b;
		if((a*a + b*b) <= d*d) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3192
"use strict";
    
const main = arg => {
  // とりあえず切り分け
  let NumAmount = arg.split("\n")[0];
  let Nums = arg.split("\n").slice(1, NumAmount+1).map(n=>Number(n));  
  // counterをセット
  let count = 0;
  // 配列の初期値（今回はnow）をセット
  let now = 1;
  // nowが2になるまでループしてね
  while(now !== 2){
    // 次のnowはNumsからnow-1です
    now = Nums[now-1];
    // countもプラスしていって
    count++;
    // 数列よりも多くなったら明らかに間違えなのでその時点で-1を吐き出して終了
    if(count > NumAmount){
      console.log("-1");
      return;
    }
  }
  console.log(count);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 28772
#include<stdio.h>
int main()
{
  int i,n,m[100],sum=0,sum1=0,sum2=0;
  scanf("%d", &n);
  for (i=0; i<n; i++) 
    {
      scanf("%d", &m[i]);
      sum += m[i]; 
    }
  i=0;
  while (sum1<=sum/2)
    {
      sum1 += m[i];
      if (sum%2==0 && sum1 == sum/2) 
        {
          printf("0");    
          return 0;
        }
      i++;
    }
  sum2 = sum - 2*(sum1-m[i-1]);
  sum1 = 2*sum1-sum;
  if (sum1<sum2) printf("%d", sum1);
   else printf("%d", sum2);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  srep(i,1,N) {
    cin >> A[i];
    A[i]--;
  }
  vi B(N);
  srep(i,1,N) {
    B[A[i]]++;
  }
  rep(i,N) {
    cout << B[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 4840
#include <stdio.h>
    #include <string.h>
     
    int main(void){
       char num[5];
       scanf("%s", num);
       int first = 0;
       for(int i = 0;i<4;i++){
          if(num[i] == '+'){
             first++;
          }else{
             first--;
          }
       }
       
      printf("%d\n",first);
      return 0;
    }

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
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(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,j,h,w;
	cin>>h>>w;
	string g[h];
	for(i=0;i<h;i++)cin>>g[i];
	for(i=0;i<h;i++){
		cout<<g[i]<<endl<<g[i]<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
cnt = 0

arr = 1.upto(n).to_a

t =  (arr.count{ |v| v <= 9} + arr.count{ |v| (v >= 100) && (v <= 999) })
t += arr.count{|v| v >= 10000  && v < 100000}

p t


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

typedef long long int lli;
#define rep(i, a, b) for(lli i  = (lli)(a); i < (lli)(b);i++)
#define rip(i, a ,b) for(lli i  = (lli)(a); i >= (lli)(b);i--)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define trace(x) cerr << #x << ": " << x << endl;

typedef pair<lli, lli> ii;
typedef pair<ii, lli> iii;
typedef vector<lli> vi;
typedef vector<ii> vii;

int main(){
	vi v;
	lli n,k; cin>>n>>k;
	rep(i,0,n){
		lli num; cin>>num;
		v.pb(num);
	}

	sort(all(v));
	lli adel=k-1;
	lli mini=1000000009;
	rep(i,0,sz(v)-k+1){
		mini=min(mini,v[i+adel]-v[i]);
	}
	cout<<mini<<endl;


	return 0;
}

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

int main() {
  vector<int> x(3);
  cin >> x[0] >> x[1] >> x[2];
  sort(x.begin(), x.end(), greater<int>());

  int cnt = 0;
  while (true) {
    if (x[0] == x[1] && x[1] == x[2]) break;
    if (x[0] == x[1]) {
      int tmp = x[0] - x[2];
      if (tmp == 1) {
        x[2] += 2;
      } else {
        x[2] += (2 * (tmp / 2));
        cnt += (tmp / 2) - 1;
      }
    } else if (x[1] == x[2]) {
      if (x[0] - x[1] == 1) {
        x[1]++;
        x[2]++;
      } else {
        int tmp = x[0] - x[1];
        x[1] += tmp;
        x[2] += tmp;
        cnt += tmp - 1;
      }
    } else if (x[0] - x[1] >= 2) {
      int tmp = x[0] - x[1];
      x[1] += (2 * (tmp / 2));
      cnt += (tmp / 2) - 1;
    } else if (x[0] - x[1] == 1) {
      x[1]++;
      x[2]++;
    } else if (x[0] - x[2] >= 2) {
      int tmp = x[0] - x[2];
      x[2] += (2 * (tmp / 2));
      cnt += (tmp / 2) - 1;
    } else if (x[0] - x[2] == 1) {
      x[2]++;
    }
    cnt++;
    sort(x.begin(), x.end(), greater<int>());
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
def test(total):
  if total == 14:
    print('1')
  elif total == 13:
    print('2')
  elif total == 12:
    print('3')
  elif total == 11:
    print('4')
  else:
    print('5')

x1, x2, x3, x4, x5 = input().split()
test(int(x1) + int(x2) + int(x3) + int(x4) + int(x5)) 

Measured memory_bytes: 61684
#include <iostream>

using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;
  if (A <= 5)
    cout << 0 << endl;
  else if (A >= 13)
    cout << B << endl;
  else
    cout << B/2 << endl;
  
  return 0;
}

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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll pwr(ll a, ll b){
    if(b==0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b==0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
/*
void Dfs(int u, int p){
    visited[u] = 1;
    if(a[u]) con[u] = con[p] + 1;
    else con[u] = 0;
    if(con[u] > mx[p]) mx[u] = con[u];
    else mx[u] = mx[p];

    for(int i : adj[u]){
        if(i != p){
            Dfs(i, u);
        }
    }
}
*/
int dsum(int x){
    if(x == 0) return 0;
    return ( (x%10) + dsum(x/10));
}
int main(){
// #ifndef ONLINE_JUDGE
// freopen("input", "r", stdin);
// freopen("output", "w", stdout);
// #else
// // online submission
// #endif
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
    int r;
    cin >> r;
    int ans = 3 * r * r;
    cout << ans;
}



Measured memory_bytes: 256
N,M,X = map(int,input().split())
A = [[0 for j in range(M+1)]for i in range(N)]
for i in range(N):
    A[i] = list(map(int,input().split()))

S = 10**10

for i in range(2**N):
    B = [0 for m in range(M+1)]
    SS = 0
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(1,M+1):
                B[k] += A[j][k]
            SS += A[j][0]
    flag = True
    for k in range(1,M+1):
        if B[k] < X:
            flag = False
    if flag and SS < S:
        S = SS

if S == 10**10:
    print('-1')
else:
    print(str(S))
    

Measured memory_bytes: 9244
import math

n, m = map(int, input().split())
MOD = 10**9+7

if abs(n-m) >= 2:
    print(0)
    exit()

n_cnt = 1
m_cnt = 1
if abs(n-m) == 1:
    for i in range(1, n+1):
        n_cnt *= i
        n_cnt %= MOD
    for i in range(1, m+1):
        m_cnt *= i
        m_cnt %= MOD
    print(n_cnt*m_cnt%MOD)
    exit()

n_cnt = 1
m_cnt = 1
if n == m:
    for i in range(1, n+1):
        n_cnt *= i
        n_cnt %= MOD
    for i in range(1, m+1):
        m_cnt *= i
        m_cnt %= MOD
    print(2*n_cnt*m_cnt%MOD)

Measured memory_bytes: 39408
//第 4 問: ABC 087 B - Coinsi (200 点)

import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		scan.nextLine();

		int arr[] = new int[N];
		int flag = 1;
		int count = 0;

		for(int i=0; i<N; i++) {
			arr[i] = scan.nextInt();
		}

		while(flag==1) {

			for(int i=0; i<N; i++) {

				if(count==0 && arr[i]%2 == 1) {
					flag = 0;
					count= -1;
					break;
				}

				arr[i] = arr[i]/2;

				if(arr[i]%2 == 1) {
					flag = 0;
				}

			}

			++count;

		}

		System.out.println(count);

	}
}



Measured memory_bytes: 23760
import java.util.Scanner;
public class Main
{
   public static void main(String[] args)
   {
      Scanner scanner = new Scanner(System.in);

      int X = scanner.nextInt();
      int N = scanner.nextInt();
      
      int[] array = new int[N];
      
      for (int i = 0; i < N; i++)
      {
         array[i] = scanner.nextInt();
      }
      
      boolean checkBelow = true;
      
      for (int i = 0; i <= N ; i++)
      {
         if (!search(X - i, array))
         {
            System.out.println(X - i);
            return;
         } 
            
         if (!search(X + i, array))
         {
            System.out.println(X + i);
            return;
         }
               
      }
      
   }
   
   public static boolean search(int num, int[] array)
   {
      for (int i = 0; i < array.length; i++)
      {
         if (array[i] == num)
         {
            return true;
         }
      }
      
      return false;
   }
}
      
      
            
      
      
         

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

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

int main()
{
    int K;
    cin >> K;
    string S;
    cin >> S;
    if(S.length() <= K){
        cout << S << endl;
    }else{
        for (int i = 0; i < K;i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }
}



Measured memory_bytes: 3624
def main():
    n, adj = getInputs()
    sequence = getTopologicalSort(n, adj)

    distance = [-1] * n
    longest = -1

    for v in sequence:
        if len(adj[v]) == 0:
            distance[v] = 0
        else:
            for dest in adj[v]:
                distance[v] = max(distance[v], 1 + distance[dest])
                longest = max(longest, distance[v])

    print(longest)

def getTopologicalSort(n, adj):
    state = [0] * n
    toVisit = list(range(n))

    topologicalSort = []
    order = []

    while len(toVisit) > 0:
        curr = toVisit.pop()

        if state[curr] == 0:
            order.append(curr)
            state[curr] = 1

            foundNewDest = False
            for dest in adj[curr]:
                if state[dest] == 0:
                    toVisit.append(dest)
                    foundNewDest = True

            if not foundNewDest:
                while True:
                    v = order[-1]

                    allProcessed = True
                    for dest in adj[v]:
                        if state[dest] == 0:
                            allProcessed = False
                            break

                    if allProcessed:
                        state[v] = 2
                        topologicalSort.append(order.pop())

                    if len(order) == 0 or not allProcessed:
                        break

    return topologicalSort

def getInputs():
    n, m = map(lambda x: int(x), input().split())

    adj = []
    for i in range(n):
        adj.append([])

    for i in range(m):
        a, b = map(lambda x: int(x), input().split())
        adj[a - 1].append(b - 1)

    return n, adj

main()


Measured memory_bytes: 97648
#include <stdio.h>
#include <stdlib.h>
int main()
{
 long long int n;
scanf("%lld",&n);
long long int h[n] , x;
int i , s=0   ;
int arr[n];
for(i=0;i<n;i++)
    scanf("%lld" , &h[i]);
for(i=0;i<n;i++)
{
    if(h[i] >= h[i+1])
        {s++;}
    else if(h[i] < h[i+1])
        {s=0;}
        arr[i] = s;

}
x=arr[0];
for(i=0 ; i<n ; i++)
{
    if (x < arr[i])
        {x = arr[i] ; }
}
printf("%lld",x);
}


Measured memory_bytes: 1280
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    println(-(intLine()...)+1)
end
main()

Measured memory_bytes: 114696
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int siz[6], damy;
	char mozi[2];
	for (int abc = 0; abc < 6; abc++) {
		cin >> siz[abc];
	}
	fgets(mozi,2,stdin);
	while(true){
		fgets(mozi,2,stdin);
		if (mozi[0] == '\n') {
			cout << siz[0] << endl;
			break;
		}
		switch (mozi[0]) {
		case 'S':
			damy = siz[0];
			siz[0] = siz[4];
			siz[4] = siz[5];
			siz[5] = siz[1];
			siz[1] = damy;
			break;
		case 'E':
			damy = siz[0];
			siz[0] = siz[3];
			siz[3] = siz[5];
			siz[5] = siz[2];
			siz[2] = damy;
			break;
		case 'N':
			damy = siz[0];
			siz[0] = siz[1];
			siz[1] = siz[5];
			siz[5] = siz[4];
			siz[4] = damy;
			break;
		case 'W':
			damy = siz[0];
			siz[0] = siz[2];
			siz[2] = siz[5];
			siz[5] = siz[3];
			siz[3] = damy;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
from math import gcd

n = int(input())
a = list(map(int, input().split()))

d = a[0]
m = a[0]

g = True

for i in range(1, n):
    d = gcd(d, a[i])

if d != 1:
    print("not coprime")
else:
    while len(a) > 1:
        b = []
        for i in range(0, len(a), 2):
            #print(i, a)
            if i == len(a)-1:
                b.append(a[i])
            else:
                e = gcd(a[i], a[i+1])
                if e != 1:
                    g = False
                    break
                else:
                    b.append(a[i] * a[i+1])
        a = b.copy()
        #print(a)


    if not g:
        print("setwise coprime")
    else:
        print("pairwise coprime")

Measured memory_bytes: 134476
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)

Measured memory_bytes: 76376
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long int
#define N 200005
 
main(){
    // ios_base::sync_with_stdio(false); 
    // cin.tie(NULL);
    int n;
	cin>>n;
	int a[n+5],b[n+5],c[n+5];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n-1;i++)cin>>c[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=b[a[i]];
	}
	for(int i=2;i<=n;i++){
		if((a[i-1]+1)==a[i]){
			ans+=c[a[i-1]];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
    int n;
    const int principal = 10000;
 
    while (cin >> n, n) {
        int y, b, r, t, p, maxp, bid;
        cin >> y;
        maxp = 0;
        while (n--) {
            cin >> b >> r >> t;
            if (t == 1) {
                p = principal * (100 + y * r) / 100;
            }
            else {
                p = principal * pow(1 + (double)r / 100, y);
            }
            if (maxp < p) {
                maxp = p;
                bid = b;
            }
        }
        cout << bid << endl;
    }
    return 0;
}

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

int main(){

  int ch[3],cm[3],cs[3];
  int lh[3],lm[3],ls[3];
  int t[3];
  int rh[3],rm[3],rs[3];

  for(int i=0; i<3; ++i){
    cin>>ch[i]>>cm[i]>>cs[i];
    cin>>lh[i]>>lm[i]>>ls[i];
  }

  for(int i=0; i<3; ++i){
    t[i] = (lh[i] - ch[i])*3600 + lm[i]*60 - cm[i]*60 + ls[i] - cs[i];
    rh[i] = t[i]/3600;
    rm[i] = t[i]%3600/60;
    rs[i] = (t[i]%3600)%60;
    cout << rh[i] << " " << rm[i]<< " " << rs[i] << endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 3100
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		n = readln().strip().to!int;
	}
}

auto main2(Input* input)
{
	with (input)
	{
		return (n + 1) / 2;
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`5`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 3);
	}

	unittest // example2
	{
		string example =
`2`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 1);
	}

	unittest // example3
	{
		string example =
`100`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 50);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b;
  cin >> a >> b;
  cout << a*a-b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int dp[N][2][3];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(dp, -63, sizeof(dp));
	dp[0][0][1] = 0;
	for(int i = 1; i <= n; i++) {
		if(i & 1) {
			for(int j = 1; j < 3; j++) {
				dp[i][1][j] = max(dp[i][1][j], dp[i - 1][0][j - 1] + a[i]);
			}
			for(int j = 0; j < 2; j++) {
				dp[i][0][j] = max({dp[i][0][j], dp[i - 1][0][j], dp[i - 1][1][j]});
			}
		}
		else {
			for(int j = 0; j < 2; j++) {
				dp[i][1][j] = max(dp[i][1][j], dp[i - 1][0][j] + a[i]);
			}
			for(int j = 0; j < 2; j++) {
				dp[i][0][j] = max({dp[i][0][j], dp[i - 1][0][j + 1], dp[i - 1][1][j + 1]});
			}
		}
	}
	cout << max(dp[n][0][1], dp[n][1][1]);

	return 0;
}

Measured memory_bytes: 14508
import java.util.*;

public class Main {
    public static int Max_cnt = 1;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] S = new String[N];

        for (int i = 0; i < N; i++) {
            S[i] = sc.next();
        }

        Arrays.sort(S);
        //System.out.println(Arrays.toString(S));

        ArrayList<String> Ans = new ArrayList<>();
        String tmp;
        int count = 1;

        for (int i = 0; i < N-1; i++) {
            tmp = S[i];
            if(tmp.equals(S[i+1])){
                count++;
            }else{
                count = 1;
            }

            if(count == Max_cnt){
                Ans.add(tmp);
            }else if(count > Max_cnt){
                Ans.clear();
                Ans.add(tmp);
                Max_cnt = count;
            }
        }

        if(Max_cnt == 1){
            Ans.add(S[N-1]);
        }

        for (int i = 0; i < Ans.size(); i++) {
            System.out.println(Ans.get(i));
        }
    }
}


Measured memory_bytes: 79592
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int a,b,c,k;
    cin >> a >> b >> c >> k;

    int d = max({a,b,c});
    cout << d * (pow(2, k) -1) + (a+b+c) << endl;

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var quotientIntValue = input[0] / input[1];
            var remainder = input[0] % input[1];
            var quotientFloatValue = (double)input[0] / input[1];
            Console.WriteLine($"{quotientIntValue} {remainder} {quotientFloatValue.ToString("F9")}");
        }
    }
}



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

int main(){
  int a,b;
  unsigned long long int c=1,d,e=1;
  cin>>a>>b;
  for(unsigned long long int i=1;i<=a;i++){
    c*=i;
    c=c%1000000007;
  }
  for(unsigned long long int i=1;i<=b;i++){
    e*=i;
    e=e%1000000007;
  }
  if(abs(a-b)>1)
    cout<<0<<endl;
  else if(a==b){
    d=2*c*e%1000000007;
    cout<<d<<endl;
  }
  else{
    d=c*e%1000000007;
    cout<<d<<endl;
  }
}


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

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

  return 0;
}

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

#pragma region
typedef long long ll;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define rep(i, begin, end)                              \
    for (__typeof(end) i = (begin) - ((begin) > (end)); \
         i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, j) rep(i, 0, j)
#define testcase \
    int _;       \
    cin >> _;    \
    while (_--)
#define io                            \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    if (fopen("./input.txt", "r")) freopen("./input.txt", "r", stdin);
#define en '\n'
#pragma endregion

int main() {
    io;
    int n;
    cin >> n;
    int arr[n];
    REP(i, n) cin >> arr[i];
    sort(arr, arr + n);
    ll ans = arr[n - 1];
    ll i = n - 2, j = n - 3;
    while (j >= 0) {
        if (j - 1 >= 0) {
            ans += arr[i] + arr[i];
        } else {
            ans += arr[i];
        }
        j -= 2;
        i--;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4444
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(auto &a)
{
    for (auto s: a) cout<<s<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a%p * b%p) % p;
}

int add(int a, int b) {
    ll s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

vector<int> Z(string s)
{
int n = s.length();
vector<int> z(n);
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
  if (i > R) {
    L = R = i;
    while (R < n && s[R-L] == s[R]) R++;
    z[i] = R-L; R--;
  } else {
    int k = i-L;
    if (z[k] < R-i+1) z[i] = z[k];
    else {
      L = i;
      while (R < n && s[R-L] == s[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
return z;
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<int> a(n);
    get(a);
    vector<int> dp(90010);
    dp[0] = 1;
    
    int ans = po(3, n);
    int total = 0;
    for (int i = 0; i<n; i++) total+=a[i];
    
    //cout<<total<<endl;
    //print(a);
    
    //cout<<ans<<endl;
    
    for (int i = 0; i<n; i++)
    for (int j = 90009; j>=0; j--)
    if (j>=a[i]) dp[j] = add(mul(2, dp[j]), dp[j-a[i]]);
    else dp[j] = mul(2, dp[j]);
    //print(dp);
    
    
    vector<int> dp1(90010);
    dp1[0] = 1;
    for (int i = 0; i<n; i++)
    for (int j = 90009; j>=a[i]; j--)
    dp1[j] = add(dp1[j], dp1[j-a[i]]);

    //cout<<dp1[8]<<endl;

    for (int i = total; 2*i>=total; i--)
    {
        ans = add(ans, -mul(3, dp[i]));
    }
    //cout<<ans<<endl;
    //cout<<dp[8]<<endl;
    if (total%2==0) ans = add(ans, mul(dp1[total/2], 3));
    cout<<ans;
    

    
}

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

#define MAX_N 55
ll C[MAX_N][MAX_N];
void make() {
  rep(i, MAX_N) {
    C[i][1] = i;
    C[i][i] = 1;
    C[0][i] = 1;
    C[i][0] = 1;
  }
  REP(i, 1, MAX_N) rep(j, i) {
    if(i-1 < 0 || j-1 < 0) continue;
    C[i][j] = C[i-1][j] + C[i-1][j-1];
  }
}
ll comb(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return C[n][r];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  make();
  int n, p; cin >> n >> p;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  int nOdd=0, nEven=0;
  rep(i, n) (A[i]%2==0 ? nEven : nOdd)++;
  if(nOdd == 0) {
    if(p == 1) cout << 0 << "\n";
    else cout << (1LL<<n) << "\n";
  } else if(nEven == 0) {
    if(p == 1) {
      ll ans = 0;
      rep(i, n+1) if(i%2==1) ans += comb(n, i);
      cout << ans << "\n";
    } else {
      ll ans = 0;
      rep(i, n+1) if(i%2==0) ans += comb(n, i);
      cout << ans << "\n";
    }
  } else {
    if(p == 1) {
      ll ans = 0;
      rep(i, nOdd+1) if(i%2==1) ans += comb(nOdd, i);
      ans *= (1<<nEven);
      cout << ans << "\n";
    } else {
      ll ans = 0;
      rep(i, nOdd+1) if(i%2==0) ans += comb(nOdd, i);
      ans *= (1<<nEven);
      cout << ans << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 3652
import sys


# 区間更新一点取得
class RangeUpdateQuery:
    def __init__(self, n, initial=2 ** 31 - 1):
        self.n = 1 << (n - 1).bit_length()
        self.INT = (-1, initial)
        # 更新時刻, 値
        self.segtree = [self.INT] * (2 * self.n)

    # 区間[l, r)をv(時刻, 値)で更新
    def update(self, l, r, v):
        L, R = l + self.n, r + self.n
        while L < R:
            if L & 1:
                self.segtree[L] = v
                L += 1

            if R & 1:
                self.segtree[R - 1] = v
                R -= 1

            L >>= 1
            R >>= 1

    # i番目の値を取得
    def query(self, i):
        i += self.n
        s = self.INT
        while i > 0:
            s = max(s, self.segtree[i])
            i = i // 2
        return s[1]


N, Q = map(int, input().split())
RUQ = RangeUpdateQuery(N)
for q in range(Q):
    query = list(map(int, sys.stdin.readline().split()))
    if query[0] == 0:
        s, t, x = query[1:]
        RUQ.update(s, t + 1, (q, x))

    if query[0] == 1:
        i = query[1]
        print(RUQ.query(i))



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

namespace Atcoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static void Yes() { print("YES"); }
        private static void No() { print("NO"); }
        private static void print(object obj) { Console.WriteLine(obj); }

        static void Main(string[] args)
        {
            var a = Read();
            int max = 0;
            for (int i = 0;i<a.Length;i++)
            {
                if(a[i] =='A' || a[i] == 'C' ||a[i] == 'G'|| a[i] == 'T')
                {
                    var m = 0;
                    for (int j = i; j < a.Length; j++)
                    {
                        if (a[j] == 'A' || a[j] == 'C' || a[j] == 'G' || a[j] == 'T')
                        {
                            m++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    max = Math.Max(max, m);
                }
            }

            print(max);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;


int main(){
   
	int n, m;
	cin >> n >> m;
	long long sum = 0;
	
	while (m--) {
		int x; cin >> x;
		sum += x;
	}
	if (sum <= n) {
		cout << n - sum;
	}
	else cout << -1;

}


Measured memory_bytes: 3640