akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > adj(n+1);
    while (m--) {
        int x, y; cin >> x >> y;
        adj[x].push_back(y); adj[y].push_back(x);
    }
    bool used[n+1];
    fill(used, used+n+1, false);
    vector<int> fwd, bwd;
    fwd.push_back(1);
    int cur = 1;
    used[1] = true;
    while (true) {
        bool ext = false;
        for (int x : adj[cur]) if (!used[x]) { fwd.push_back(x); used[x] = true; ext = true; cur = x; break; }
        if (!ext) break;
    }
    cur = 1;
    while (true) {
        bool ext = false;
        for (int x : adj[cur]) if (!used[x]) { bwd.push_back(x); used[x] = true; ext = true; cur = x; break; }
        if (!ext) break;
    }
    cout << fwd.size() + bwd.size() << endl;
    for (auto it = bwd.rbegin(); it != bwd.rend(); it++) cout << *it << ' ';
    for (auto it = fwd.begin(); it != fwd.end(); it++) cout << *it << ' ';
    cout << endl;
}


Measured memory_bytes: 6904
#include <iostream>
#include <string>
using namespace std;
int main() {
	int A[4] = { 0 };
	int N, ans = 0;
	char s;

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if (s == 'P') {
			A[0] = 1;
		}
		if (s == 'W') {
			A[1] = 1;
		}
		if (s == 'G') {
			A[2] = 1;
		}
		if (s == 'Y') {
			A[3] = 1;
		}
	}

	for (int i = 0; i < 4; i++)
	{
		ans += A[i];
	}

	if (ans == 3) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}

	return 0;
}

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

#define LIM_S 200002
#define LIM_N 200001
#define DIV 998244353

char str[LIM_S];

int A, B, T;

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d %d", &A, &B, &T);
}

void initialize() {

}


int main(void) {
	receive_input();
	initialize();

	printf("%d\n", T / A * B);

	return 0;
}


Measured memory_bytes: 128
from math import gcd

k = int(input())

res = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        g1 = gcd(a, b)
        for c in range(1, k + 1):
            g2 = gcd(g1, c)
            res += g2
print(res)

Measured memory_bytes: 9092
#include <stdio.h>
int main(void){
    int i;
    int a[5];
    int b[5];
    scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4]);
    int t=0;
    for (i=0;i<5;i++){
	if(a[i]%10!=0){
      	    b[i]=a[i]%10;
	    a[i]=(a[i]/10)*10+10;
	    t+=a[i];
	    }
	else {
	    b[i]=10;
	    t+=a[i];
	    }
	}
    int min=10;
    for (i=0;i<5;i++){

	if(min>b[i])min=b[i];
	}
    
    printf("%d\n",t-(10-min));
    return 0;
}




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

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

int main() {
        int N, M;
        while (cin >> N >> M && N) {
                vector<vector<int>> imos(M + 1, vector<int>(1300, 0)) ;
                int r;
                cin >> r;
                rep(i, r) {
                        int t, n, m, s;
                        cin >> t >> n >> m >> s;
                        if (s == 1) {
                                imos[m][t] ++;
                        } else {
                                imos[m][t] --;
                        }
                }
                rep(i, M + 1) {
                        for (int j = 1; j < imos[i].size(); j ++) {
                                imos[i][j] += imos[i][j - 1];
                        }
                }
                //rep(i, M) {
                //        cout << i + 1 << endl;
                //        rep(j, imos[i].size()) {
                //                cout << imos[i][j] << ' ';
                //        }
                //        cout << endl;
                //}
                int q;
                cin >> q;
                rep(i, q) {
                        int ts, te, m;
                        cin >> ts >> te >> m;
                        int ans = 0;
                        for (int t = ts; t < te; t ++) {
                                ans += imos[m][t] > 0;
                        }
                        cout << ans << endl;
                }

        }
        return 0;
}

Measured memory_bytes: 52424
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define plaese return
constexpr auto AC = 0;
using namespace std;
int max(ll a, ll b) {
	if (a < b)return b;
	return a;
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> dp(n, vector<int>(3)), a(n,vector<int>(3));
	rep(i, n)rep(j, 3)cin >> a[i][j];
	rep(i, 3) dp[0][i] = a[0][i];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (k != j)dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
			}
		}
	}
	int ans = 0;
	rep(i, 3)ans = max(ans, dp[n - 1][i]);
	cout << ans << endl;


	plaese AC;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;


int main() {
    int s;
    cin >> s;
    set<int> st;
    st.insert(s);
    rep(i,1e9){
        if(s%2==0){
            s/=2;
        }else{
            s = 3*s +1;
        }
        if(st.count(s)){
            cout << i+2 << endl;
            return 0;
        }
        st.insert(s);
    }
    return 0;
}

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


def solve(N: int, d: "List[int]"):
    d.sort()
    print(d[N//2] - d[N//2-1])

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


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

namespace CompetitiveProgramming
{

  class Solve 
  {
    const int MOD = (int)(1e9) + 7;
    public Solve() 
    {
      ulong[] input = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
      ulong H = input[0];
      ulong W = input[1];
      ulong A = input[2];
      ulong B = input[3];


      ulong[,] t = new ulong[H + W + 1, 2];

      t[0, 0] = 1;
      for (ulong i = 0; i <= H + W; i++)
      {
        ulong f = 1;
        if (i > 0)
        {
          f = (t[i - 1, 0] * i) % MOD;
        }
        ulong g = MyMath.ModExpo(f, MOD - 2, MOD);
        t[i, 0] = f;
        t[i, 1] = g;
      }
      

      ulong ans = 0;
      for (ulong i = B; i < W; i++)
      {
        ulong u, v, w;
      
        u = H - A - 1 + i;
        v = (((t[u, 0] * t[i, 1]) % MOD) * t[u - i, 1]) % MOD;

        u = H - 1 - (H - A) + (W - i - 1);
        w = (((t[u, 0] * t[A - 1, 1]) % MOD) * t[u - (A - 1), 1]) % MOD;

        ans = (ans + v * w) % MOD;
      }

      Console.WriteLine(ans);
    }
  }
  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }
  
  class MyMath
  {
    public static ulong ModExpo(ulong n, ulong r, ulong mod) 
    {
      if (r == 0)
      {
        return 1;
      }
      if (r == 1)
      {
        return n % mod;
      }
      ulong a = ModExpo(n, r / 2, mod);
      if (r % 2 == 0)
      {
        return ((a % mod) * (a % mod)) % mod;
      }
      else 
      {
        return ((((n % mod) * (a % mod)) % mod) * (a % mod)) % mod;
      }
    }

    public static ulong ModFact(ulong n, ulong mod)
    {
      ulong ret = 1;
      for (ulong i = 1; i < n; i++)
      {
        ret = (ret * n) % mod;
      }

      return ret;
    }
  }

}

Measured memory_bytes: 5976
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(){
  int dataset, i, j, k, alen, blen;
  string a, b;
  cin >> dataset;
  for (i = 0; i < dataset; ++i){
    cin >> a >> b;
    alen = a.length();
    blen = b.length();
    int lcs[alen+1][blen+1];
    for (j = 0; j <= alen; ++j){
      for (k = 0; k <= blen; ++k){
        lcs[j][k] = 0;
      }
    }
    for (j = 1; j <= alen; ++j){
      for (k = 1; k <= blen; ++k){
        if(a.at(j-1) == b.at(k-1)){
          lcs[j][k] = lcs[j-1][k-1] + 1;
        }else{
          lcs[j][k] = max(lcs[j-1][k], lcs[j][k-1]);
        }
      }
    }
    cout << lcs[alen][blen] << endl;
  }
}

Measured memory_bytes: 5120
import sys
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]


if __name__ == '__main__':
    h, w = wi()
    s = hs(h)
    flagli = [[0] * w for i in range(h)]
    stack = deque()
    black = 0
    white = 0
    for i in range(h):
        for j in range(w):
            if flagli[i][j] == 0:
                flagli[i][j] = 1
                white = 1 if s[i][j] == "." else 0
                black = 1 if s[i][j] == "#" else 0
                stack.append([i, j])
                while stack != deque():
                    p, q = stack.pop()
                    k = 0 if s[p][q] == "." else 1
                    for dx, dy in dd:
                        nx = q + dx;
                        ny = p + dy
                        if 0 <= nx < w and 0 <= ny < h:
                            if flagli[ny][nx] == 0:
                                if k == 0 and s[ny][nx] == "#":
                                    flagli[ny][nx] = 1
                                    stack.append([ny, nx])
                                    black += 1
                                elif k == 1 and s[ny][nx] == ".":
                                    flagli[ny][nx] = 1
                                    stack.append([ny, nx])
                                    white += 1
                ans += black * white
                black = 0
                white = 0
print(ans)

Measured memory_bytes: 14876
#include<stdio.h>
int main(){
    int N,K,Q;
    int Aq[100010];
    int Ak[100010];
    scanf("%d" "%d" "%d",&N,&K,&Q);
    for(int i = 0; i < N; i++){
        Ak[i] = K;      
    }

    for(int j = 0; j < Q; j++){
        int r;
        scanf("%d", &r);
        Ak[r-1] = Ak[r-1] + 1;
    }

    for(int i = 0; i < N; i++){
        Ak[i] = Ak[i]-Q;
        if(Ak[i]<=0){
            printf("%s\n","No");
        }else{
            printf("%s\n","Yes");
        }
    }

    return 0;
}

Measured memory_bytes: 896
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [-v for v in a]
heapq.heapify(a)

for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (x+1)//2)

print(-sum(a))

Measured memory_bytes: 73068
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b ] <- readInts
	let
		ab = show $ a + b
	putStrLn $ which "error" ab $ 2 <= length ab


Measured memory_bytes: 508
N, K, L = map(int, input().split())

par = [i for i in range(N)]

def find(x, P):
    if P[x] == x:
        return x
    else:
        b = find(P[x], P)
        P[x] = b
        return b

def unite(x, y, P):
    root_x = find(x, P)
    root_y = find(y, P)
    if root_y > root_x:
        P[root_x] = root_y
    else:
        P[root_y] = root_x

par2 = [i for i in range(N)]

for _ in range(K):
    p, q = map(int, input().split())
    unite(p-1, q-1, par)

for _ in range(L):
    p, q = map(int, input().split())
    unite(p-1, q-1, par2)
#print(par2)

r=[]
for i in range(N):
    r.append((find(i,par), find(i, par2)))

import collections
count = collections.Counter(r)
#print(count)

for i in range(N):
  ans = count[r[i]]
  if i == N-1:
    print(ans)
  else:
    print(ans, end=' ')

Measured memory_bytes: 58720
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>

using namespace std;
int n,m;
    int inf = 1<<21;
    const int m_max = 200000;
    vector<int> G[m_max];
    int a,b;
    int d[m_max];
    int dis[m_max];

void wfs(int s){
    queue<int> q;
    dis[s] = 0;
    d[s] = 0;
    q.push(s);
    int u;
    while(!q.empty()){
        u = q.front();
        q.pop();
        for(int v = 0;v<G[u].size();v++){
            if(dis[G[u][v]] != inf) continue;
            dis[G[u][v]] = dis[u] + 1;
            d[G[u][v]] = u;
            q.push(G[u][v]);
        }
    }
}

int main(){
    for(int i=0;i<m_max;i++) {
        d[i] = inf;
        dis[i] = inf;
    }
    cin >> n >> m;
    for (int i=0;i<m;i++){
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    wfs(0);
    cout << "Yes" << endl;
    for(int i=1;i<n;i++){
        cout  << d[i]+1 << endl;
    }
    return 0;


}

Measured memory_bytes: 13476
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, K;
  cin >> N >> K;
  vll A(N);
  rep(i, N) cin >> A[i];
  SORT(A);
  REVERSE(A);

  ll ans = 0;
  rep(i, K) ans += A[i];
  ANS;

  return 0;
}

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

using namespace std;
const int MAXN = 1000000;
int n;
int a[MAXN];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    if (a[n-1] - a[0] > 1) {
        cout << "No\n";
        return 0;
    }
    int p = 0, q = 0;
    int k = a[n-1];
    for (int i = n-1; i >= 0; i--) if (a[i] == k) p++;
    q = n - p;

    if (q == 0) {
        if (k == n-1 || 2*k <= n) cout << "Yes\n";
        else cout << "No\n";
        return 0;
    }

    if (k <= p/2 + q && k > q) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

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

	cout << N * (N - 1) / 2 - N / 2 << endl;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			if (i + j + 1 != (N / 2) * 2) {
				cout << j + 1 << " " << i + 1 << endl;
			}
		}
	}
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a <= c && c <= b){
    puts("Yes");
    return 0;
  }
  puts("No");
  return 0;
}


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

int main(){
 string S,T; cin>>S>>T;
 string ans = "$";

 for(int i=0; i+T.size()<=S.size(); i++){
  bool ok=true;
  rep(t,T.size())
   if(S[i+t]!='?') if(S[i+t]!=T[t]) ok=false;
  if(!ok) continue;

  string tmp=S;
  rep(i,S.size()) if(tmp[i]=='?') tmp[i]='a';
  rep(t,T.size()) tmp[i+t]=T[t];
  ans = min(ans,tmp);
  if(ans=="$") ans=tmp;
 }

 if(ans=="$") cout<<"UNRESTORABLE"<<endl;
 else cout<<ans<<endl;

 return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using P1 = pair<int, P>;
#define FOR(t, a, b) for (int t = (a); t < (b); ++t)
#define REP(t, n) FOR(t, 0, n)

int main()
{
    string s, t;
    cin >> s >> t;
    bool ans = false;
    for (int i = 0; i < s.size(); i++)
    {
        if (s == t)
        {
            ans = true;
            break;
        }
        s = s.back() + s.substr(0, s.size() - 1);
    }
    if (ans)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    int dis_a = max(x - a, a - x);
    int dis_b = max(x - b, b - x);
    if (dis_a < dis_b){
        cout << "A" << endl;
    }
    else{
        cout << "B" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,m,i,s=0,ans,c=0;
	cin>>n>>m;
	long long int a[n];
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		s=s+a[i];
	}
	sort(a+1,a+n+1);
	if(a[n-m+1]<double(s)/(4*m))cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            // 入力（スペース区切り）
            string[] input = Console.ReadLine().Split(' ');

            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            string S = Console.ReadLine();

            if(S.Length != (A + B + 1))
            {
                Console.WriteLine("No");
            }
            else if (S.Length == (A + B + 1))
            {
                if (S[A] == '-')
                {
                    int c = 0;

                    for (int i = 0; i < S.Length; i++)
                    {
                        if (S[i] == '-')
                        {
                            c++;
                        }
                    }
                    if (c > 1)
                    {
                        Console.WriteLine("No");
                    }
                    else
                    {
                        Console.WriteLine("Yes");
                    }
                }
                else
                {
                    // 出力
                    Console.WriteLine("No");
                }
            }
        }
    }
}

Measured memory_bytes: 13140
A, B, C, D = list(map(int, input().split()))


if C%B == 0:
    cntA = C//B
else:
    cntA = C//B + 1

if A%D == 0:
    cntC = A//D
else:
    cntC = A//D + 1

if cntA <= cntC:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;
bool comp(pair <int,bool> &p1,pair <int,bool>&p2){
	return abs(p1.first) > abs(p2.first);
}

void solve(){
	int n,k;
	cin >> n >> k;
	vector <pair <int,bool>> a(n);
	for(int i = 0;i < n;++i){
		int num;
		cin >> num;
		if(num < 0) a[i] = {num,1};
		else a[i] = {num,0};
	}
	sort(a.begin(),a.end(),comp);
	bool par = 0;
	for(int i = 0;i < k;++i) par ^= a[i].second;
	if(!par or k == n){
		lli ans = 1;
		for(int i = 0;i < k;++i) ans = (ans * a[i].first) % mod;
		cout << (ans + mod) % mod << newl;
	}
	else{
		int sn = mod,sp = -mod;
		for(int i = 0;i < k;++i){
			if(a[i].second) sn = i;
		}
		for(int i = 0;i < k;++i){
			if(!a[i].second) sp = i;
		}
		if(sp == -mod){
			//cout << "yes" << newl;
			int sp1 = -mod;
			for(int i = k;i < n;++i){
				if(!a[i].second){
					sp1 = i;
					break;
				}
			}
			if(sp1 == -mod){
				lli ans = 1;
				for(int i = n - 1;i >= n - k;--i) ans = (ans * a[i].first) % mod;
				cout << (ans + mod) % mod << newl;
			}
			else{
				lli ans = 1;
				for(int i = 0;i < k - 1;++i) ans = (ans * a[i].first) % mod;
				ans = (ans * a[sp1].first) % mod;
				cout << (ans + mod) % mod << newl;
			}
		}
		else{
			int sn1 = mod, sp1 = -mod;
			for(int i = k;i < n;++i){
				if(a[i].second){
					sn1 = i;
					break;
				}
			}
			for(int i = k;i < n;++i){
				if(!a[i].second){
					sp1 = i;
					break;
				}
			}
			if(sp1 == -mod){
				lli ans = 1;
				for(int i = 0;i < k;++i) if(i != sp) ans = (ans * a[i].first) % mod;
				ans = (ans * a[k].first) % mod;
				cout << (ans + mod) % mod << newl;
				return;
			}
			if(sn1 == mod){
				lli ans = 1;
				for(int i = 0;i < k;++i) if(i != sn) ans = (ans * a[i].first) % mod;
				ans = (ans * a[k].first) % mod;
				cout << (ans + mod) % mod << newl;
				return;
				
			}
			if((lli)a[sp].first * a[sp1].first > (lli)a[sn1].first * a[sn].first){
				lli ans = 1;
				for(int i = 0;i < k;++i) if(i != sn) ans = (ans * a[i].first) % mod;
				ans = (ans * a[sp1].first) % mod;
				cout << (ans + mod) % mod << newl;
			}
			else{
				lli ans = 1;
				for(int i = 0;i < k;++i) if(i != sp) ans = (ans * a[i].first) % mod;
				ans = (ans * a[sn1].first) % mod;
				cout << (ans + mod) % mod << newl;
			}
		}
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
 
 
int main() {
int N;
cin>>N;
vector<int> a(N*2);
for(int i=0;i<N*2;i++) cin>>a[i];
sort(a.begin(),a.end());
long ans=0;
for(int i=0;i<N;i++){
  ans+= min(a[2*i],a[2*i+1]);
}
cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
  int n=0,i=0,count=0,max=0;
  int h[100]={};
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&h[i]);
  }
  max=h[0];
  count=0;
  for(i=0;i<n;i++){
	  if(max<=h[i]){
      	count++;
        max=h[i];
      }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   while(true){
    int n = sc.nextInt();
    int sum=0;
    double m=0;
    double ans=0;
    double sum1=0;
    if(n==0){
      break;
    }
    int[] s = new int[n];
    for(int i=0;i<n;i++){
     s[i]=sc.nextInt();
     sum += s[i];
    }
    m = (double)sum/n;
    for(int i=0;i<n;i++){
      sum1 += ((double)s[i]-m)*((double)s[i]-m);
    }
    ans = Math.sqrt(sum1/n);
    System.out.println(ans);
   }
  }
}


Measured memory_bytes: 31004
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	k := nextInt64()

	for i := 0; int64(i) < min(k, int64(len(s))); i++ {
		if s[i] != '1' {
			fmt.Println(string(s[i]))
			return
		}
	}
	fmt.Println(1)
	return

}
func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1784
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    if (x/d >= k) {
        cout << x - k*d << endl;
        return 0;
    }

    k -= x / d;
    ll ans;
    if (k%2 == 0) ans = x - x/d * d;
    else ans = d - (x - x/d * d);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cntA=0; int cntB=0; int cntO=0; int cntAB=0;
		while(sc.hasNext()){
			String t = sc.nextLine();
			String[] temp = t.split(",");
			if(temp[1].equals("A")) cntA++;
			if(temp[1].equals("B")) cntB++;
			if(temp[1].equals("O")) cntO++;
			if(temp[1].equals("AB")) cntAB++;
		}
		System.out.printf("%d%n%d%n%d%n%d%n",cntA,cntB,cntAB,cntO);
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  ll n;cin>>n;
  if(n==1){cout<<0;return 0;}
  int t=0;
  
  ll m=ceil(sqrt(n));
  for(ll i=2;i<=m;i++){
    if(n%i==0){
       ll j=i;
      while(n%j==0){
        n/=j;
        t++;
        j*=i;
      }
      while(n%i==0)n/=i;
    }
  }
  if(n!=1)t++;
  cout<<t;
}

Measured memory_bytes: 3744
#include <iostream>  
using namespace std;  
int n,m;  
void f(){  
    for(int i=0;i<=2000;i++){  
        for(int j=0;j+i<=2000&&i+j<=n;j++){  
            if(i*10000+j*5000+(n-i-j)*1000==m)  
            {  
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;  
                return;  
            }  
        }  
    }  
     cout<<-1<<" "<<-1<<" "<<-1<<endl;  
}  
int main() {  
    scanf("%d%d",&n,&m);  
    f();  
    // insert code here...  
    //std::cout << "Hello, World!\n";  
      
    return 0;  
}  

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  set<int> syo;
  int pro = 0;
  for(int i = 0; i < N; i++) {
    if(a[i] >= 3200) {
      pro++;
      continue;
    }
    syo.insert(a[i] / 400);
  }
  int sz = syo.size();
  cout << max(1, sz) << " " << sz + pro << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
V = gets.split.map(&:to_i)

ls = V.partition.with_index {|v,i| i.even? }
a,b = ls.map.with_index {|v,i| v.group_by(&:itself).map {|k,v| [v.size, k] }.sort }

if a[-1][1] != b[-1][1]
  ans = N - a[-1][0] - b[-1][0]
elsif a[-2] == nil && b[-2] == nil
  ans = N - [a[-1][0], b[-1][0]].max
else
  ans = N - [a[-1][0] + (b[-2][0]||0), a[-2][0] + (b[-1][0]||0)].max
end
puts ans


Measured memory_bytes: 25348
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

int main() {
  using namespace std;
  namespace mp = boost::multiprecision;
  using Real = mp::number<mp::cpp_dec_float<1024>>;

  Real a, b, c;
  cin >> a >> b >> c;

  if (mp::sqrt(a) + mp::sqrt(b) < mp::sqrt(c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
 int X,h;
 scanf("%d",&X);
 int x,b,c;
 if(X>=500)
     {
         x=X%500;
         b=X/500;
         c=x/5;
         h=(b*1000)+(c*5);
         printf("%d\n",h);

    }
    else if(X==0)
    {
        printf("%d\n",X);
    }
    else
    {
        x=X/5;
        h=x*5;
        printf("%d\n",h);
    }

 }




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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
//---------------------------------------------------------------
int main(){
  ll N,M,S;
  cin>>N>>M;
  vector<int> A(M);
  ll ans;
  S = 0;
  llrep(i,M){
    cin>>A.at(i);
    S+= A.at(i);
  }

  if(S>N)ans = -1;
  else ans = N-S;
  cout<<ans<<endl;

}


Measured memory_bytes: 3668
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==0 && b==0 && c==0 && d==0) return 0;
    if(b*c<=a){
      cout<<0<<endl;
    }else{
      cout<<(b*c-a+d-1)/d<<endl;
    }
  }
}


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

int main() {
 // An % B = Cになるか
 // n=1 : B-1
  int A,B,C;
  cin >> A >> B >> C;
  bool can = false;
  for (int i=1; i<B; i++){
    if (A*i % B == C){
      can = true;
      break;
    }    
  }
  if (can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

int main(void)
{
	int a, b, sum;
	while(cin >> a >> b){
		int c = 0;
		sum = a + b;
		for (int i = 0; sum / 10 != 0; ++i)
		{
			sum /= 10;
			c++;
		}
		c++;
		cout << c << endl;
	}
}

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

int main() {
  int a,b;
  cin >> a >> b;
  cout << a*b << " " << (a+b)*2 << endl;
  return 0;
}


Measured memory_bytes: 3096
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

/** 約数計算
    12: 1, 2, 3, 4, 6, 12
*/
template<typename T>
std::set<T> divisors(T n)
{
    std::set<T> ret;
    for (T i = 1; i*i <= n; ++i) {
        if (n % i == 0) {
            ret.insert(i);
            if (i != 1 && i * i != n) {
                ret.insert(n/i);
            }
        }
    }
    ret.insert(n);
    return ret;
}

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

    auto mm = divisors(M);

    for (auto m: mm) {
        if (m >= N) {
            std::cout << M / m << std::endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}


int main()
{
	ll ans = 0;
	char S[7] = {0};
	scanf("%s", S);
	if ((S[2] == S[3]) && (S[4] == S[5])) {
		ans = 1;
	} else {
		ans = 0;
	}
	if (ans == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


ll n,k;
const int max_k=4005;
int bb[max_k][max_k];
int ww[max_k][max_k];

int bacc[max_k][max_k];
int wacc[max_k][max_k];
int bsum(int x1, int y1, int x2, int y2){
  return bacc[y2][x2] -bacc[y2][x1] - bacc[y1][x2] + bacc[y1][x1];
}

int wsum(int x1, int y1, int x2, int y2){
  return wacc[y2][x2] -wacc[y2][x1] - wacc[y1][x2] + wacc[y1][x1];
}




int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  cin >> n >> k;
  int k2=k*2;
  rep(i,n){
    int x,y;
    char c;
    cin >> x >> y >> c;
    x%= k2;
    y%= k2;
    if(c=='B'){
      bb[y][x]++;
      bb[y+k2][x]++;
      bb[y][x+k2]++;
      bb[y+k2][x+k2]++;
    }else{
      ww[y][x]++;
      ww[y+k2][x]++;
      ww[y][x+k2]++;
      ww[y+k2][x+k2]++;
    }
  }

  rep(y, k2*2) rep(x,k2*2){
    bacc[y+1][x+1] += bb[y][x] + bacc[y+1][x] + bacc[y][x+1] - bacc[y][x];
    wacc[y+1][x+1] += ww[y][x] + wacc[y+1][x] + wacc[y][x+1] - wacc[y][x];
  }

  int ans=0;
  rep(y1,k2) rep(x1,k2){
    //    cout << bacc[y1][0] << bacc[0][x1] << endl;
    int x2=x1+k, y2=y1+k;
    int sum = bsum(x1,y1,x2,y2) + bsum(x2,y2,x2+k, y2+k);
    sum += wsum(x2,y1,x2+k,y2) + wsum(x1,y2,x2, y2+k);
    //    cout << x2 << " " << y2 << " " <<sum << endl;
    ans = max(ans,sum);
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 250752
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n;
int a[200005];
unordered_map<int,vector<int> > mp;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	read(n);
	for(register int i=1;i<=n;i++)
		read(a[i]);
	for(register int i=1;i<=n;i++)
		mp[i-a[i]].push_back(i);
	long long ans=0;
	for(register int i=1;i<=n;i++)
	{
		vector<int> v=mp[i+a[i]];
		int id=upper_bound(v.begin(),v.end(),i)-v.begin();
		ans+=(long long)(v.size()-id);
	}
	writeln(ans);
	return 0;
}


Measured memory_bytes: 30972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


signed main() {
	ll t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll a[n];
		rep(i,n)
			cin>>a[i];
		sort(a,a+n, greater<ll>());
		if(n==2){
			cout<<a[0];
			continue;
		}
		if(n==3){
			cout<<a[0]+a[1];
			continue;
		}
		ll x = n - 2;
		ll ans = a[0];
		ll p = x/2;
		for(ll i= 1; i <=p; ++i){
			ans += 2*a[i];
		}		
		if(x%2 != 0){
			ans += a[p+1];
		}
		cout<<ans;
		
	}
	
}

Measured memory_bytes: 5168
#include <algorithm>
#include <cstdio>

const int N = 100;

int a[2][N];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < 2; ++ i) {
        for (int j = 0; j < n; ++ j) {
            scanf("%d", a[i] + j);
        }
    }
    int result = 0;
    for (int j = n - 2; j >= 0; -- j) {
        a[1][j] += a[1][j + 1];
    }
    for (int j = 0; j < n; ++ j) {
        if (j) {
            a[0][j] += a[0][j - 1];
        }
        result = std::max(result, a[0][j] + a[1][j]);
    }
    printf("%d\n", result);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

vector<Int> edge[3][110000];
Int grundy[3][110000];
Int grundysum[3][110000];
Int n, m[3], a, b;
bool nums[110000];

Int mod_pow(Int x, Int a, Int m = MOD){
    if(a == 0)return 1;
    Int res = mod_pow(x, a / 2, m);
    res = res * res % m;
    if(a % 2)res *= x;
    return res % m;
}

Int inv(Int x, Int m = MOD){
    return mod_pow(x, m-2, m);
}


void calc(Int x){
    for(Int i = n;i >= 1;i--){
        for(Int neib:edge[x][i]){
            if(neib < i)continue;
            nums[grundy[x][neib]] = true;
        }
        while(nums[grundy[x][i]])grundy[x][i]++;
        for(Int neib:edge[x][i]){
            if(neib < i)continue;
            nums[grundy[x][neib]] = false;
        }
        grundysum[x][grundy[x][i]] += mod_pow(10, 18 * i, MOD2);
        grundysum[x][grundy[x][i]] %= MOD2;
    }
}

int main(){
    cin >> n;
    for(Int i = 0;i < 3;i++){
        cin >> m[i];
        for(Int j = 0;j < m[i];j++){
            cin >> a >> b;
            edge[i][a].push_back(b);
            edge[i][b].push_back(a);
        }
        calc(i);
    }

    Int ans = 0;
    for(Int i = 0;i < 600;i++){
        for(Int j = 0;j < 600;j++){
            ans += grundysum[0][i] * grundysum[1][j] % MOD2 * grundysum[2][i^j] % MOD2;
            ans %= MOD2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 21504
#include <stdio.h>
int main(){
  int a,b,t;

  scanf("%d%d",&a,&b);
  while(1){
  if(a == 0 && b == 0)break;

  else if(a <= b){
    printf("%d %d\n",a,b);}

  else if(a > b){
    t=a;
    a=b;
    b=t;
  
    printf("%d %d\n",a,b);}
  scanf("%d%d",&a,&b);}
  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;
#include<stdio.h>

//最大公約数をユークリッドの互除法で、再帰的に求める
ll gcd(ll x, ll y) {
	ll r = y%x;
	if (r == 0)return x;
	else gcd(r, x);
}

int main(void) {
	ll N;
	cin >> N;
	ll x = 0, y = 0;
	//a=ga',b=gb'とするとl=ga'b'
	x = 2 / gcd(2, N);
	y = N / gcd(2, N);
	cout << gcd(2, N)*x*y << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int inN = stdin.nextInt();
		String result = "Three";
		for (int i = 0; i < inN; i++) {
			if (stdin.next().equals("Y")) {
				result = "Four";
				break;
			}
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0;i < N;i++){
			A[i] = sc.nextInt();
		}
		sc.close();
		for(int i = 0;i < N;i++){
			if(A[i]%2==0 && A[i]%3 != 0 && A[i]%5 != 0){
				System.out.println("DENIED");
				return;
			}
		}
		System.out.println("APPROVED");


	}

}

Measured memory_bytes: 21972
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

//const int INF = INT_MAX / 2;




int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
ab, cd = [], []
N.times do |i|
    ab[i] = gets.split.map(&:to_i)
end
N.times do |i|
    cd[i] = gets.split.map(&:to_i)
end

ab.sort_by!{|arr| -arr[0]}
cd.sort_by!{|arr| arr[1]}

ans = 0
cd.each do |c, d|
    index = nil
    ab.length.times do |i|
        a, b = ab[i]
        if a < c && b < d
            ans += 1
            index = i
            break
        end
    end
    ab.delete_at(index) if index
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<set>
#include<string.h>
#include<queue>
#include<map>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
 
#define pb push_back
#define ii pair<int, int> 
#define vai freopen("in","r",stdin);
#define inf 0x3f3f3f3f
#define f first
#define s second

const ll INF = 1e18;
const int MOD = 1000000007;

const int maxn = 2e5 + 100;
const int MAX = 2e4 + 10;
 



 
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a , x ,b;
	cin >> a >> b >> x;
	
	if (x >= a && x <= a + b ){ cout <<"YES\n"; return 0;}
	cout << "NO\n";
}
 
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//---------------------------------------------------------------------------//
ll n,sum=0,b;
ll a[51];
ll dp[100][100][5000];
int main(){
        cin>>n>>b;
        for(int i=0; i<n; i++) {
                cin>>a[i];
        }
        dp[0][0][0]=1;
        for(int i=0; i<n; i++) {
                for(int j=0; j<n; j++) {
                        for(int s=0; s<2501; s++) {
                                if(dp[i][j][s]==0) continue;
                                dp[i+1][j][s]+=dp[i][j][s];
                                dp[i+1][j+1][s+a[i]]+=dp[i][j][s];
                        }
                }
        }
        for(int i=1; i<=n; i++) {
                sum+=dp[n][i][i*b];
        }
        cout<<sum<<endl;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_N = 110;
const int MAX_V = 100100;

const int INF = 1<<29;
int dp[100100];
vector< vector<int> > g;

int rec(int v) {
    if (dp[v] != -1) {
        return dp[v];
    }
    else {
        int res = 0;
        for (auto v1 : g[v]) {
            auto n = rec(v1)+1;
            res = res > n? res : n;
        }
        dp[v] = res;
        return res;
    }
}

int main()
{
    int n,m;
    cin >> n >> m;
    g.assign(n, vector<int>());

    for (int i=0; i<m; i++) {
        int from, to;
        cin >> from >> to;

        g[from-1].push_back(to-1);
    }

    for (int i=0; i<n; i++) {
        dp[i] = -1;
    }

    auto res = 0;
    for (int i=0; i<n; i++) {
        auto m = rec(i);
        res = res > m ? res: m;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8192