akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int n, m;
	cin >> n >> m;

	int A[n][m];
	REP(i, n){
		REP(j, m){
			cin >> A[i][j];
		}
	}
	int B[m];
	REP(i, m){
		cin >> B[i];
	}

	int C[n];

	REP(i, n){
		int tmp = 0;
		REP(j, m){
			tmp += A[i][j] * B[j];
		}
		C[i] = tmp;

	}

	for (auto x : C){
		cout << x << endl;
	}
}



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

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

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

    int q;
    cin>>q;
    map<string, int> mp;
    rep(i, q) {
        int c;
        string k;
        cin>>c>>k;
        if (c == 0) {
            int x;
            cin>>x;
            mp[k] = x;
        }
        else if (c == 1) {
            cout<<mp[k]<<endl;
        }
        else {
            mp.erase(k);
        }
    }
}


Measured memory_bytes: 25972
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        sc.close();

        boolean flg = false;
        String ans = "None";

        for (char c = 'a'; c <= 'z'; c++) {
            if (x.indexOf(c) != -1) {
                continue;
            } else {
                flg = true;
                ans = String.valueOf(c);
                break;
            }
        }

        if (flg) {
            System.out.println(ans);
        } else {
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 25044
#include"bits/stdc++.h"
using namespace std;
bool f[26];
int main(){
	string str;
	cin>>str;
	for(int i=0;i<str.length();i++){
		if(f[str[i]-'a']){
			cout<<"no"<<endl;
			return 0;
		}
		f[str[i]-'a']=true;
	}
	cout<<"yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define float long double 

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

  while(n>0)
  {
    n-=1000;
  }

  cout<<abs(n)<<endl;

  return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif

const long mod = 998244353;

long long bpow(long long a, long long b, const long long mod) {
    return (b ? bpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) : 1) % mod;
}

long long inv(long long a, const long long mod) {
    return bpow(a, mod - 2, mod);
}

template<int N, long long mod>
struct nCr {
    vector<long long> f, finv;

    long long ncr(long long n, long long r) {
        if (r > n || r < 0) return 0;
        assert(n <= N);
        return f[n] * finv[r] % mod * finv[n - r] % mod;
    }

    nCr() {
        f.resize(N + 1);
        finv.resize(N + 1);
        f[0] = 1;
        for (int i = 1; i <= N; i++) f[i] = i * f[i - 1] % mod;
        finv[N] = inv(f[N], mod);
        for (int i = N - 1; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1) % mod;
    }
};


void solve(ll N, ll A, ll B, ll K) {
    nCr<400010, 998244353> ncr;
    ll ans = 0;
    for (int r = 0; r <= N; r++) {
        long long b = (K - r * A);
        if (b % B) continue;
        b /= B;
        if (b > N) continue;
        ans += ncr.ncr(N, r) * ncr.ncr(N, b) % 998244353;
        ans %= 998244353;
    }
    cout << ans << endl;
}


void main_(istream &cin) {
    ll N;
    ll B;
    ll K;
    ll A;
    cin >> N;
    cin >> A;
    cin >> B;
    cin >> K;
    solve(N, A, B, K);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 6528
#include <stdio.h>
#define MAX 201
#define INF 1000000
#define NIL -1
#define WHITE 0
#define BLACK 1

int prim(int, int[MAX][MAX], int);

int main(){
    int G[MAX][MAX];
    int n;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            scanf("%d", &G[i][j]);
            if(G[i][j] == NIL)G[i][j] = INF;
        }
    }

    printf("%d\n", prim(n, G, 1));

    return 0;
}

int prim(int n, int w[MAX][MAX], int r){
    int d[MAX], pi[MAX], color[MAX];
    int mincost;
    int u, v, i;
    int span = 0;

    //d[]は長さ保持
    //pi[]は何してんやろな？？？？
    //color[]は通ったかどうかの判定
    for(u = 0; u < n; u++){
        d[u] = INF;
        pi[u] = NIL;
        color[u] = WHITE;
    }
    d[r] = 0;

    while(1){
        mincost = INF;
        //最小の経路とその番号を探す
        for(i = 0; i < n; i++){
            if(color[i] != BLACK && d[i] < mincost){
                mincost = d[i];
                u = i;
            }
        }
        //隣接しない時
        if(mincost == INF)break;
        //黒色の番号はすでに通ったので通れなくする
        color[u] = BLACK;

        for(v = 0; v < n; v++){
            if(color[v] != BLACK && w[u][v] < d[v]){
                pi[v] = u;
                d[v] = w[u][v];
            }
        }
    }

    for(int k = 0; k < n; k++){
        span += d[k];
    }

    return span;
}






Measured memory_bytes: 2112
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    int n,k;string s;
    cin>>n>>k>>s;
    s[k-1]=tolower(s[k-1]);
    cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
//use std::str::FromStr;

struct Patient{
    number: i32,
    day1: i32,
    day2: i32
}
fn main() {
    let cin = stdin();
    let mut n: i32;
    let mut lines = cin.lock().lines();
    loop {
        n = lines.next().unwrap().unwrap().parse().unwrap();
        if n == 0 {break};
        let mut patients: Vec<Patient> = vec![];
        for _ in 0 .. n {
            let arg: Vec<i32> = lines.next().unwrap().unwrap().split_whitespace().map(|s|s.parse().unwrap()).collect();
            patients.push(Patient{number:arg[0], day1:arg[1], day2:arg[2]});
        }
        patients.sort_by_key(|p|p.day1 + p.day2);
        let last = patients.last().unwrap();
        println!("{} {}", last.number, last.day1 + last.day2);
    };
}



Measured memory_bytes: 5056
A,V = list(map(int,input().split()))
B,W = list(map(int,input().split()))
T = int(input())
if V-W == 0 and A==B:
    print('YES')
    exit()
if V-W <= 0:
    print('NO')
    exit()
if (abs(A-B)/(V-W)) <= T:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <map>
#include <cmath>
#include <vector>

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

typedef unsigned long long ull;
typedef long long ll;
using namespace std;

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

    int w[n];
    rep(i, n) {
        cin >> w[i];
    }

    int count = 0;
    int mini = 101;
    rep(i, n) {
        int sum_former = 0;
        int sum_latter = 0;
        rep(j, n) {
            if (j <= i)
            {
                sum_former += w[j];
                // cout << sum_former << " " << sum_latter << endl;
            }
            else
            {
                /* code */
                sum_latter += w[j];
                // cout << sum_former << " " << sum_latter << endl;
            }
        }
        mini = min(mini, abs(sum_former - sum_latter));
        // cout << mini << endl;
    }
    cout << mini << endl;
}

Measured memory_bytes: 384
from sys import stdin


def main() -> None:
    n = int(next_str())
    print("Yes" if n % sum(map(int, str(n))) == 0 else "No")


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
def gcdf(a):
    a.sort()
#    print("a2:",a)
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
#    print("a2:",a)
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

#n=8
#a=[746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#ans=[19]
#n=2
#a=[1000000000, 1000000000]
#n=5
#a=[15, 18, 24, 36, 81]
#n=3
#a=[7, 6, 8]
n=int(input())
a=[]
for i in map(int,input().split()):
    a.append(i)
if n==2:
    print(max(a))
elif n<2**10:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
else:
    m=int(n**(1/2))
    ns=int(n/m)
    rgcd=[]
    for mi in range(m):
        ms=ns*mi
        if mi==m-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
        gcdm=gcdf(am)
        rgcd.append(gcdm)
    gcdv=0

    for mi in range(m):
        rgcd1=list(rgcd)
        del rgcd1[mi]
        gcdrg1=gcdf(rgcd1)
        ms=ns*mi
        if mi==m-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
#        print(mi,gcdf(am),len(am),gcdf(rgcd1))
        for i in range(len(am)):
            acpy=list(am)
#            del acpy[i]
#            acpy.append(gcdrg1)
            acpy[i]=gcdrg1
            gcdx=gcdf(acpy)
            if gcdx>gcdv:
                gcdv=gcdx
    print(gcdv)


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

int main(){
  int n,num;

  for(cin >> n; n != 0;cin >> n){ 
    num = 0;
    for(int i = 5;i <= n;i = i*5){
      num = num + (n / i);
    
    }
    cout << num << endl;
  }
}

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

int main(){
  ll H,W;
  cin >> H >> W;
  if((H==1) || (W==1)) cout << 1 << endl;
  else cout << ll((H+1)/2)*ll((W+1)/2)+ll(H/2)*ll(W/2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int INF = 1e9;

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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> a(H);
	vector<vector<int>> d(H, vector<int>(W, INF));
	deque<pii> dq;
	for (int i = 0; i < H; i++) {
		cin >> a[i];
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '.') {
				a[i][j] = '0';
				dq.emplace_front(i * W + j, 0);
			}
		}
	}
	while (!dq.empty()) {
		auto p = dq.front(); dq.pop_front();
		int x = p.first / W, y = p.first % W;
		if (d[x][y] != INF) continue;
		int cnt = 0;
		for (int i = 0; i < 8; i++) {
			int tx = x + dx[i], ty = y + dy[i];
			cnt += (0 <= tx && tx < H && 0 <= ty && ty < W && d[tx][ty] < p.second);
		}
		if (cnt < a[x][y] - '0') continue;
		d[x][y] = p.second;
		for (int i = 0; i < 8; i++) {
			int tx = x + dx[i], ty = y + dy[i];
			if (tx < 0 || H <= tx || ty < 0 || W <= ty || d[tx][ty] != INF) continue;
			int cnt = 0;
			for (int j = 0; j < 8; j++) {
				int ttx = tx + dx[j], tty = ty + dy[j];
				cnt += (0 <= ttx && ttx < H && 0 <= tty && tty < W && d[ttx][tty] < d[x][y]);
			}
			if (cnt >= a[tx][ty] - '0') {
				dq.emplace_front(tx * W + ty, d[x][y]);
			}
			else {
				dq.emplace_back(tx * W + ty, d[x][y] + 1);
			}
		}
	}
	int res = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (d[i][j] != INF) {
				res = max(res, d[i][j]);
			}
		}
	}
	cout << res << endl;
	return 0;
}



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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, W;
    cin>>n>>W;
    vector<int> w(n+1), v(n+1);
    vector<vector<long long int>> dp(n+1, vector<long long int> (W+1, 0));
    for(int i = 1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=W;j++)
        {
            if(j - w[i] >= 0)
            {
                dp[i][j] = max(dp[i-1][j - w[i]] + v[i], dp[i-1][j]);
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][W]<<"\n";
    return 0;
}

Measured memory_bytes: 83064
N = int(input())
xyh = [list(map(int,input().split())) for _ in range(N)]
xyh = sorted(xyh, key = lambda x: -x[2])
xt, yt, ht = xyh[0]
for Cx in range(101):
  for Cy in range(101):
    H = ht + abs(xt - Cx) + abs(yt - Cy)
    if(all(h == max(H - abs(x - Cx) - abs(y - Cy), 0) for x,y,h in xyh)):
      print(Cx, Cy, H)
      exit()

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        int ans = 0;

        for (int i = 0; i<s.length();i++){
            ans += Character.getNumericValue(s.charAt(i));
        }

        if (ans % 9 == 0)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}


Measured memory_bytes: 40488
a, b, c = map(int, input().split())
if a <= b <= c:
    print(a, b, c)
    
elif a <= c <= b :
    print(a, c, b)
    
elif b <= a <= c :
    print(b, a, c)
    
elif b <= c <= a:
    print(b, c, a)
    
elif c <= a <= b:
    print(c, a, b)
    
elif c <= b <= a:
    print(c, b, a)


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

int main(){
  int N;
  cin >> N;
  int ans=0;
  while(N>=500){
    N -= 500;
    ans += 1000;
  }
  while(N>=5){
    N -= 5;
    ans+=5;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <math.h>
#include <stack>
#include <cctype>
using namespace std;
#define int long long
#define pi 2*acos(0.0)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

signed main()
{

	int n, k, x, y;
	cin >> n >> k >> x >> y;
if(n<k) k=n;
	cout << x*k + y*(n - k) << endl;
}

Measured memory_bytes: 256
#104b
S = str(input())

#Sが次の条件すべてを満たすか判定してください。
#・Sの先頭の文字は大文字の A である。
#・Sの先頭から 3 文字目と末尾から 2 文字目の間（両端含む）に大文字の C がちょうど 1個含まれる。
#・以上の A, C を除く Sのすべての文字は小文字である。

#Sが問題文中の条件すべてを満たすなら AC、そうでなければ WA と出力せよ。

#0A1t2C3o4d5e6r7

C_check = 0

if S[0]=="A":
    for i in range(1,len(S)):
        if S[i].isupper() == True:
            if i>=2 and i<=len(S)-2 and C_check==0 and S[i]=="C":
                C_check=1
            else:
                print("WA")
                break
    else:
        if C_check == 1:
            print("AC")
        else:
            print("WA")
else:
    print("WA")

Measured memory_bytes: 3064
N = gets.split.map(&:to_i)
A_ARRAY = gets.split.map(&:to_i)
B_ARRAY = gets.split.map(&:to_i)

result = 0
gap = 0
yobis = []
A_ARRAY.zip(B_ARRAY).each do |ary|
  a = ary[0]
  b = ary[1]

  if b > a
    result += 1
    gap += b - a
  else
    yobis << a - b
  end
end

if result.zero?
	puts 0
	exit
end

yobis.sort!.reverse_each do |i|
  result += 1
  gap -= i

  if gap <= 0
    puts result
    exit
  end
end

puts -1


Measured memory_bytes: 20932
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define NINTH_POWER_OF_TEN 1000000000
#define LL_INF (numeric_limits<long long>::max()/2)
#define int long long

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

void P2(int a, int b) {
  cout << a << " " << b << endl;
  return;
}

const int kMaxN = 200000;

int n;
int v[kMaxN];
int ans = 0;

signed main() {
  cin >> n;
  REP(i, n) { cin >> v[i]; }

  unordered_map<int, int> h1, h2;
  REP(i, n/2) {
    h1[v[2*i]]++; h2[v[2*i+1]]++;
  }
  int maxn1[2], maxn2[2];
  int maxc1[2] = {0, 0}, maxc2[2] = {0, 0};
  for (auto it = h1.begin(); it != h1.end(); ++it) {
    if (it->second > maxc1[0]) {
      maxn1[1] = maxn1[0]; maxc1[1] = maxc1[0];
      maxn1[0] = it->first; maxc1[0] = it->second;
    } else if (it->second > maxc1[1]) {
      maxn1[1] = it->first; maxc1[1] = it->second;
    }
  }
  for (auto it = h2.begin(); it != h2.end(); ++it) {
    if (it->second > maxc2[0]) {
      maxn2[1] = maxn2[0]; maxc2[1] = maxc2[0];
      maxn2[0] = it->first; maxc2[0] = it->second;
    } else if (it->second > maxc2[1]) {
      maxn2[1] = it->first; maxc2[1] = it->second;
    }
  }
  // P2(maxn1[0], maxc1[0]);
  // P2(maxn1[1], maxc1[1]);

  if (maxn1[0] != maxn2[0]) {
    ans = n/2 - maxc1[0] + n/2 - maxc2[0];
  } else {
    ans = MIN(n/2 - maxc1[1] + n/2 - maxc2[0], n/2 - maxc1[0] + n/2 - maxc2[1]);
  }

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


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int h, w, c[26] = {};
    char f[100][100], visit[100][100] = {};
    vector<int> v;

    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> f[i][j];
            c[f[i][j] - 'a']++;
            if (visit[i][j])
                continue;

            int cnt = 1;
            if (h - i - 1 != i)
                cnt++;
            if (w - j - 1 != j)
                cnt++;
            if (cnt == 3)
                cnt++;
            
            visit[i][j] = 1;
            visit[h - i - 1][j] = 1;
            visit[i][w - j - 1] = 1;
            visit[h - i - 1][w - j - 1] = 1;
            
            v.push_back(cnt);
        }
    }
    sort(c, c + 26);
    sort(v.begin(), v.end(), greater<int>());

    for (int i = 0; i < v.size(); ++i) {
        int s = lower_bound(c, c + 26, v[i]) - c;
        if (s == 26) {
            cout << "No" << endl;
            return 0;
        }
        c[s] -= v[i];
        sort(c, c + 26);
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

color = [0]*8
cnt = 0
free = 0

for x in a:
    tmp = x // 400
    if tmp >= 8:
        free += 1
        continue
    if color[tmp] == 0:
        color[tmp] = 1
        cnt += 1

print(max(cnt, 1), cnt + free)


Measured memory_bytes: 9176
n,h,*ab = map(int,open(0).read().split())
a_max = max(ab[::2])
b_sort = sorted(ab[1::2],reverse = True)

ans = 0
i = 0
while h>0:
    if i<n and b_sort[i] > a_max:
        h -= b_sort[i]
        i += 1
        ans += 1
    else:
        ans += -(-h//a_max)
        h = 0
print(ans)
    

Measured memory_bytes: 25124
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
    int x,y;
    int a,b,c;
    cin>>x>>y;
    if((y%1000)!=0){
        cout<<"-1 -1 -1";
        return 0;
    }
    y/=1000;
    if(y<x){
        cout<<"-1 -1 -1";
    }
    else if(y==x){
        cout<<"0 0 "<<y;
    }
    else{
        for(int i=0;i<=2000;i++){
            for(int j=0;j<=2000;j++){
                if(i+j*5>y){
                    break;
                }
                if((i+j*5+(x-i-j)*10)==y){
                    cout<<(x-i-j)<<" "<<j<<" "<<i;
                    return 0;
                }
            }
        }
        cout<<"-1 -1 -1";
    }
}


Measured memory_bytes: 256
num_list = []
while True:
    values = [int(x) for x in input().split()]
    if 0 == values[0] and 0 == values[1]:
        break
    num_list.append(values)

for n, t in num_list:
    ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1) if t == x + y + z)
    print(ret.count(str(t)))

Measured memory_bytes: 7768
l = [[0,0],[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]
n,m = map(int,input().split())
a = list(map(int,input().split()))
l0 = []
for i in range(m):
    l0.append(l[a[i]])
l0.sort(key=lambda x:x[0],reverse=True)
l0.sort(key=lambda x:x[1])
p,q = l0[0]
count = n - (n//q)*q
c = 1
ans = 0
for i in range(n//q):
    ans += p*c
    c *= 10
c = c//10
l0.sort(key=lambda x:x[0],reverse=True)
i = 0
while count > 0 and i < m:
    p1,q1 = l0[i]
    if q1 > q:
        q1 -= q
    #print(count)
    if p1 > p:
        while count >= q1:
            ans -= p*c
            ans += p1*c
            count -= q1
            c = c//10
        i += 1
    else:
        i += 1
i = 0
c = 1
l0.sort(key=lambda x:x[1],reverse=True)
while count > 0 and i < m:
    p1,q1 = l0[i]
    if q1 > q:
        q1 -= q
    if p1 < p:
        while count >= q1:
            ans -= p*c
            ans += p1*c
            count -= q1
            c *= 10
        i += 1
    else:
        i += 1
if count == 0:
    print(ans)
else:
    x = n//q - 1
    for i in range(n//q-1):
        count = n - (x)*q
        c = 1
        ans = 0
        for i in range(x):
            ans += p*c
            c *= 10
        c = c//10
        l0.sort(key=lambda x:x[0],reverse=True)
        i = 0
        while count > 0 and i < m:
            p1,q1 = l0[i]
            if q1 > q:
                q1 -= q
            #print(count)
            if p1 > p:
                while count >= q1:
                    ans -= p*c
                    ans += p1*c
                    count -= q1
                    c = c//10
                i += 1
            else:
                i += 1
        i = 0
        c = 1
        l0.sort(key=lambda x:x[1],reverse=True)
        while count > 0 and i < m:
            p1,q1 = l0[i]
            if q1 > q:
                q1 -= q
            if p1 < p:
                while count >= q1:
                    ans -= p*c
                    ans += p1*c
                    count -= q1
                    c *= 10
                i += 1
            else:
                i += 1
        if count == 0:
            print(ans)
            break
        else:
            x += 1

Measured memory_bytes: 3192
n, a = map(int, input().split())
x = list(map(int, input().split()))
sum_x = sum(x)
sum_x = max(sum_x, n*a)

dp = [[[0]*(sum_x+1) for _ in range(n+1)] for _ in range(n+1)]
#dp[i][j][k]はi番目までのカードの中からj枚選んで、合計がkになるときの選び方の総数
dp[0][0][0] = 1

for i in range(n):
    for j in range(n):
        for k in range(sum_x+1):
            if k-x[i] >= 0:
                dp[i+1][j+1][k] += dp[i][j][k-x[i]]
            dp[i+1][j][k] += dp[i][j][k]

ans = 0
for i in range(1, n+1):
    ans += dp[n][i][i*a]
    #print(dp[n][i][i*a])
print(ans)



Measured memory_bytes: 118500
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
  int n;
  string s,t,ans;
  cin >> n;
  cin >> s >> t;
  rep(i,n){
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const int inf=1e9+7;
const int mod=1e9+7;

//const int maxn=

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    ll int n;
    
    cin>>n;
    
    if(n&1)
    	return cout<<0<<endl,0;
    
    ll int ans=0;
    
    for(ll int i=1;(ll int)pow(5,i)<=n;i++)
    {
    	ll int now=2LL*(ll int)pow(5,i);
    	ans+=n/now;
	}
	
	cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,k,s=1,n;
    cin>>n>>k;
    s=k;
    for(int i=2;i<=n;i++)
    {
    	s*=k-1;
	}
	cout<<s;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

//-----------------------------------------
const int hash_size = 1046527;
string H[hash_size];
ll getkey(string key){
  ll sum = 0, p = 1;
  for(ll i=0;i<key.size();i++){
    sum += p * (key[i] - 'A' + 1);
    p *= 27;
  }
  return sum;
}
ll h1(ll key){
  return key % hash_size;
}
ll h2(ll key){
  return 1 + (key % (hash_size - 1)); 
}
bool find(string str){
  ll key, i, h;
  key = getkey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % hash_size;
    if(H[h] == str) return true;
    else if(H[h] == "") return false;
  }
  return false;
}
void insert(string str){
  ll key, i, h;
  key = getkey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % hash_size;
    if(H[h] == str) return;
    else if(H[h] == ""){
      H[h] = str;
      return;
    }
  }
  return;
}
//-----------------------------------------
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string s, t;
    cin >> s >> t;
    if(s=="insert"){
      insert(t);
    }
    else{
      if(find(t)) yes();
      else no();
    }
  }
    
  return 0;
}




Measured memory_bytes: 24256
n, q = gets.chomp.split.map(&:to_i)
queue = Array.new

n.times do |i|

   input = gets.chomp.split
   name = input[0]
   time = input[1].to_i
   queue.push [name, time]

end

flag = true
time = 0
while flag

   diff = queue[0][1] - q
   name = queue[0][0]

   if diff > 0

      queue.shift
      queue.push [name, diff]
      time += q

   else

      time += queue[0][1]
      puts "#{name} #{time}"
      queue.shift

   end

   flag = false if queue[0].nil?
   break if flag == false

end

Measured memory_bytes: 19924
#include<bits/stdc++.h>
const int inf=1e9+7;
const int N=100010;
using namespace std;
int val[N],lx[N],rx[N],pos[N],vis[N],isodd[N];
int tot,n,k,head[N];
struct Edge{int u,v,next;}G[N<<1];
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
inline void addedge(int u,int v){
	G[++tot].u=u;G[tot].v=v;G[tot].next=head[u];head[u]=tot;
	G[++tot].u=v;G[tot].v=u;G[tot].next=head[v];head[v]=tot;
}
inline void dfs1(int u,int f){
	vis[u]=1;
	if(~val[u]&&isodd[u]!=(val[u]&1)){puts("No");exit(0);}
	for(int i=head[u];i;i=G[i].next){
		int v=G[i].v;if(vis[v])continue;
		isodd[v]=isodd[u]^1;
		dfs1(v,u);
		lx[u]=max(lx[u],lx[v]-1);rx[u]=min(rx[u],rx[v]+1);
	}
	if(lx[u]>rx[u]){puts("No");exit(0);}
}
inline void dfs2(int u,int f){
	vis[u]=1;
	for(int i=head[u];i;i=G[i].next){
		int v=G[i].v;if(vis[v])continue;
		if(lx[v]<=val[u]-1&&val[u]-1<=rx[v])val[v]=val[u]-1;
		else val[v]=val[u]+1;
		dfs2(v,u);
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){lx[i]=-inf;rx[i]=inf;val[i]=-1;}
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		addedge(u,v);
	}
	k=read();int rt=0;
	for(int i=1;i<=k;i++){
		int x=read(),v=read();
		val[x]=v;lx[x]=v;rx[x]=v;
		rt=x;
	}
	isodd[rt]=val[rt]&1;
	dfs1(rt,0);
	memset(vis,0,sizeof(vis));
	dfs2(rt,0);
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d\n",val[i]);
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	string s;
	cin >> s;
	const int n = s.size();

	ll ans = 0LL;

	int white = 0;
	rrep(i,n){
		if(s[i] == 'W')
			white++;
		else 
			ans += white;
	}

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

Measured memory_bytes: 640
import sys
(h, w) = list(map(int, input().split()))

ah = round(h / 3)
aw = w // 2
bh = h // 2
bw = round(w / 3)

ans1_area_1 = ah * w
ans1_area_2 = (h - ah) // 2 * w
ans1_area_3 = (h - (h - ah) // 2 - ah) * w
ans1 = max(ans1_area_1, ans1_area_2, ans1_area_3) - min(ans1_area_1, ans1_area_2, ans1_area_3)


ans2_area_1 = ah * w
ans2_area_2 = (h - ah) * aw
ans2_area_3 = (h - ah) * (w - aw)
ans2 = max(ans2_area_1, ans2_area_2, ans2_area_3) - min(ans2_area_1, ans2_area_2, ans2_area_3)

ans3_area_1 = bw * h
ans3_area_2 = (w - bw) // 2 * h
ans3_area_3 = (w - (w - bw) // 2 - bw) * h
ans3 = max(ans3_area_1, ans3_area_2, ans3_area_3) - min(ans3_area_1, ans3_area_2, ans3_area_3)

ans4_area_1 = bw * h
ans4_area_2 = (w - bw) * bh
ans4_area_3 = (w - bw) * (h - bh)
ans4 = max(ans4_area_1, ans4_area_2, ans4_area_3) - min(ans4_area_1, ans4_area_2, ans4_area_3)

print(min(ans1, ans2, ans3, ans4))

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

int main(){
	int N,C,S,M;
	bool flag=true;
	C = 0;
	M = -1;
	cin >> N;
	
	for(int i=N;i>0;){
		S = i%10;

		if(S==M){
			C++;
		}
		else{
			C=1;
			M=S;
		}
		i=i/10;
		
		if(C>2){
			break;
		}
	}

	if(C>2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

ll a,b,c,k;

int main() {
    ios::sync_with_stdio(false);
    cin>>a>>b>>c>>k;
    ll cnt1=min(a,k);
    ll cnt2=0;
    if(k-a-b>0) cnt2=min(c,k-a-b);
    printf("%lld\n",cnt1-cnt2);

    return 0;
}

Measured memory_bytes: 3628
let n = Scanf.scanf " %d" (+) 0
let vs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let css = Array.init 2 @@ fun _ -> Array.init 100001 @@ fun i -> 0, i
let (e0, em), e1, (o0, om), o1 = Array.iteri (fun i v -> css.(i mod 2).(v) <- let c, i = css.(i mod 2).(v) in c + 1, i) vs;
  List.iter (fun i -> Array.sort (fun x y -> compare y x) css.(i)) [0; 1];
  css.(0).(0), fst css.(0).(1), css.(1).(0), fst css.(1).(1)
let _ = Printf.printf "%d\n" @@ if em = om then n - max (e0 + o1) (e1 + o0) else n - e0 - o0

Measured memory_bytes: 13184
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)
#define ll long long


int main(){
  int n,m,ans=0;
  cin>>n>>m;
  vector<int> x(m),y(m-1),z(m-1),t(m-1);
  if(n<m){
  r(i,m){
    cin>>x.at(i);
  }

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

  r(i,m-1){
    y.at(i)=abs(x.at(i+1)-x.at(i));
  }

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

  r(i,m-1-(n-1)){
    ans+=y.at(i);
  }


}else{

}

  cout<<ans<<endl;

  return 0;

}


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

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

typedef long long int ll;

int read_int()
{
    int a;
    scanf("%d", &a);
    return a;
}

int read_lint()
{
    ll a;
    scanf("%lld", &a);
    return a;
}

int read_float()
{
    float a;
    scanf("%f", &a);
    return a;
}

char read_char()
{
    char c;
    scanf("%c", &c);
    return c;
}

int read_double()
{
    double a;
    scanf("%lf", &a);
    return a;
}

void read_string(char *s)
{
    scanf("%s", s);
}

#define N 6

char c[N][N + 1];
char t[N][N + 1];

int main()
{
    ll h = read_lint();
    ll w = read_lint();
    ll k = read_lint();
    for (int i = 0; i < h; i++)
    {
        read_string(c[i]);
    }

    ll ans = 0;
    ll paternh = (int)pow(2.0, (double)h);
    ll paternw = (int)pow(2.0, (double)w);
    for (int i = 0; i < paternh; i++)
    {
        for (int j = 0; j < paternw; j++)
        {
            for (int l = 0; l < h; l++)
            {
                strcpy(t[l], c[l]);
            }

            int mask = 1;
            for (int l = 0; l < h; l++)
            {
                if (i & mask)
                {
                    for (int m = 0; m < w; m++)
                    {
                        t[l][m] = '.';
                    }
                }
                mask <<= 1;
            }

            mask = 1;
            for (int l = 0; l < w; l++)
            {
                if (j & mask)
                {
                    for (int m = 0; m < h; m++)
                    {
                        t[m][l] = '.';
                    }
                }
                mask <<= 1;
            }

            ll black = 0;
            for (int l = 0; l < h; l++)
            {
                for (int m = 0; m < w; m++)
                {
                    if (t[l][m] == '#')
                    {
                        black++;
                    }
                }
            }

            // printf("%lld\n", black);
            if (black == k)
            {
                ans++;
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 2500
/*
                        Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}      
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi
    int k;
    cin>>k;
    int sum=0;
    for(int i=1;i<=k;i++)
    {   for(int j=1;j<=k;j++)
        {   for(int l=1;l<=k;l++)
            {   int y=gcd(i,j);
                y=gcd(y,l);
                sum+=y;
            }
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3652
/** 
 * THIS IS MOOONI'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << max(0, n * (n - 1) / 2) + max(0, m * (m - 1) / 2) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

int c[1001];
int t[1001];
int main() {
	int N, T;
	cin >> N >> T;
	int ans = 10000;
	REP(i, N) {
		cin >> c[i] >> t[i];
	}
	REP(i, N) {
		if (t[i] <= T) {
			ans = min(ans, c[i]);
		}
	}
	if (ans == 10000) {
		cout << "TLE" << endl;
		return 0;
	}
	cout << ans << endl;
}


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

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> x(h,vector<char>(w));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin>>x[i][j];
    }
  }
  //白だけの行Hと列Wをカウント
  vector<int> couh,couw;
  for(int i=0; i<h; i++){
    int a=0;
    for(int j=0; j<w; j++){
      if(x[i][j]=='.'){
        a++;
      }
    }
    if(a==w){
      couh.push_back(i);
    }
  }

  for(int i=0; i<w; i++){
    int a=0;
    for(int j=0; j<h; j++){
      if(x[j][i]=='.'){
        a++;
      }
    }
    if(a==h){
      couw.push_back(i);
    }
  }
    //cout<<couw[0]<<endl<<endl;
    //出力
  bool okh=true,okw=true;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      okh=true;okw=true;
      for(int k=0; k<couh.size(); k++){
        if(couh[k]==i){
            okh=false;
        }
      }
      for(int k=0; k<couw.size(); k++){
        if(couw[k]==j){
            okw=false;
        }
      }
      if(okh&&okw){
          cout<<x[i][j];
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3608
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/
const ll MOD=1000000007;

ll min(ll a, ll b){
	if(a>=b){
		return b;
	}
	else{
		return a;
	}
}

void solve(){

	ll ans=0;
	ll n;
	cin>>n;
	vector<ll> a (n,0);
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}

	sort(a.begin(),a.end());
	ans+=a[n-1];
	if(n%2==0){
		for(ll i=2;i<=n/2;i++){
			ans+=2*a[n-i];
		}
	}
	else{
		for(ll i=2;i<=(n-1)/2;i++){
			ans+=2*a[n-i];
		}
		ans+=a[(n-1)/2];
	}

	cout<<ans<<endl;		
}


int main(){
	
	solve();
	
    return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<long long> input(N);
  //vector<long long> output(N);
  for(int i= 0; i < N; ++i){
    cin >> input.at(i);
  }
  long long S = 0;
  for (int i = 0; i < N; ++i){
    S = S^input.at(i);
  }
  for (int i = 0; i < N; ++i){
    long temp = S^input.at(i);
    cout << temp;
    cout << " ";
  }
}


Measured memory_bytes: 4748
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std;

int main() {

    int n;
    cin >> n;

    vector<int> a(n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] % 2 != 0) {
            cnt ++;
        }
    }

    if (cnt % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;

}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>
#include <fstream>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int a[2000];
int b[2000];
int c[2000];
vector<int> ab;
vector<int> abc;

signed main(){
  int x,y,z,k;
  //ifstream in("./in22.txt");
  //cin.rdbuf(in.rdbuf());
  cin >> x >> y >> z >> k;
  REP(i,x) cin >> a[i];
  REP(i,y) cin >> b[i];
  REP(i,z) cin >> c[i];
  sort(a,a+x);
  sort(b,b+y);
  sort(c,c+z);
  reverse(a,a+x);
  reverse(b,b+y);
  reverse(c,c+z);
  REP(i,x){
    REP(j,y){
      ab.pb(a[i]+b[j]);
    }
  }
  sort(ab.begin(),ab.end());
  reverse(ab.begin(),ab.end());
  REP(i,min(k,x*y)){
    REP(j,z){
      abc.pb(ab[i]+c[j]);
    }
  }
  sort(abc.begin(),abc.end());
  reverse(abc.begin(),abc.end());
  REP(i,k){
    cout << abc[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 43364
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = []
for i, v in cnt.items():
    if 2 <= v < 4:
        ans.append(i)
    elif 4 <= v:
        ans.append(i)
        ans.append(i)

if not ans:
    print(0)
else:
    ans.sort()
    x = ans.pop()
    y = ans.pop()
    print(x * y)

Measured memory_bytes: 18600
N, M = map(int, input().split())
A = list(map(int, input().split()))
total = sum(A)
least = total * (1 / (4 * M))

count = 0
for a in A:
    if a >= least:
        count += 1

if count >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
N,H = map(int,input().split())
A = [];B = []
for _ in range(N):
  a,b = map(int,input().split())
  A.append(a);B.append(b)
B.sort(reverse = True)
ma = max(A)
counter = 0
for b in B:
  if b > ma:
    counter += 1
    H -= b
    if H <= 0:
      print(counter)
      exit()
  else:
    break
counter += (H -1)//ma + 1
print(counter)

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int i,j,c=0,c1=0,ans,a,b;
    string st;
    vector<int>v;
    cin >> a >> b >> c;
    ans=(abs(a-b)+abs(b-c));
    ans=min(ans,abs(a-c)+abs(c-b));
    ans=min(ans,abs(b-c)+abs(c-a));
    ans=min(ans,abs(c-a)+abs(a-b));
    ans=min(ans,abs(c-b)+abs(b-a));
    cout << ans << "\n";



    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
sum1 = 0
ans = 0
for i in range(1,n+1):
  sum1 =0
  for j in range(len(str(i))):
    sum1 +=int(str(i)[j])
  if a<= sum1 <=b:
    ans += i
print(ans)

Measured memory_bytes: 3060
/*
    AUTHOR : TANMAY SINHA
    INORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(i,L,R) for(i=L;i<R;i++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5+10,MAX = 500500;
#define sq(X) ((X)*(X))

int main()
{
    ll h,a;
    cin>>h>>a;
    if(h%a==0)
    cout<<h/a<<"\n";
    else
    {
        cout<<h/a+1<<"\n";
    }
    
}

Measured memory_bytes: 256