akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int A[N];
  int odd_even[2]={0,0};
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]%2==0){
      odd_even[1]++;
    }
    else odd_even[0]++;
  }
  
  
  while(odd_even[0]>=2){
    odd_even[0]-=2;
    odd_even[1]+=1;
  }
  while(odd_even[1]>=2){
    odd_even[1]-=2;
    odd_even[1]++;
  }
  cout<<((odd_even[0]+odd_even[1]==1)? "YES":"NO");
}

Measured memory_bytes: 640
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, K = map(int, input().split())
Upper = H//2 if H % 2 == 0 else H//2+1
for h in range(Upper):
    w = (K-W*h)/(H-2*h)
    if int(w) == w and 0 <= w <= W:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 39888
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N = read_int()
    answer = 0
    for A in range(1, N):
        count = N//A
        if N%A == 0:
            count -= 1
        answer += count
    return answer


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 70332
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k, q;
    cin >> n >> k >> q;
    vector<int> v(n+1,0);
    for(int i=0; i<q; ++i){
        int a; cin >> a;
        ++v[a];
    }
    for(int i=1; i<=n; ++i){
        cout << (k-(q-v[i])>0 ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
mod = 10 ** 9 + 7

from math import factorial

# comb init
nmax = 2000 + 1  # change here
fac = [0] * (nmax + 1)
finv = [0] * (nmax + 1)
inv = [0] * (nmax + 1)
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def comb(n, r):
    if n < r:
        return 0
    else:
        return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod


r = N - K
for b in range(1, K+1):
    print((comb(r+1, b) * comb(K - 1, b - 1)) % mod)


Measured memory_bytes: 42608
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


//sizeによる実装
class UnionFind {
public:
	vector<int> s, p, es;
	map<int, int>sizemp;

	UnionFind() {}
	UnionFind(int size) {
		s.resize(size, 0);
		p.resize(size, 0);
		es.resize(size, 0);
		sizemp[1] = size;
		rep(i, 0, size)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		s[x] = 1;
		es[x] = 0;
	}

	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	void unite(int x, int y) {
		x = findSet(x);
		y = findSet(y);
		es[x]++;
		if (x == y)return;
		if (s[x] < s[y])swap(x, y);
		int szx = size(x);
		int szy = size(y);
		sizemp[szx]--;
		sizemp[szy]--;
		sizemp[szx + szy]++;
		if (sizemp[szx] == 0)sizemp.erase(szx);
		if (sizemp[szy] == 0)sizemp.erase(szy);
		p[y] = x;
		s[x] += s[y];
		es[x] += es[y];
	}


	int findSet(int x) {
		if (x == p[x]) {
			return x;
		}
		else {
			return p[x] = findSet(p[x]);
		}
	}

	int size(int x) {
		return s[findSet(x)];
	}
	int esize(int x) {
		return es[findSet(x)];
	}
	int minsz() {
		auto beg = sizemp.begin();
		return beg->first;
	}
};
vector<int>near[101010];
vector<int>ng[101010];


int A[5][5];
int ok[5][5];

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

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	int N;
	cin >> N;
	int bingo = 0;
	for (int i = 0; i < N; i++) {
		int b;
		cin >> b;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (A[j][k] == b)ok[j][k] = 1;
			}
		}
		int cnttate = 0;
		int cntyoko = 0;
		int cntnaname = 0;
		int cntnaname2 = 0;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				cntyoko += ok[j][k];
			}
			if (cntyoko == 3)bingo = 1;
			cntyoko = 0;
		}
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				cnttate += ok[k][j];
			}
			if (cnttate == 3)bingo = 1;
			cnttate = 0;
		}
		for (int j = 0; j < 3; j++) {
			cntnaname += ok[j][j];
			cntnaname2 += ok[j][2-j];
		}
		if (cntnaname == 3)bingo = 1;
		if (cntnaname2 == 3)bingo = 1;
	}
	if (bingo == 0)puts("No");
	else puts("Yes");

	return 0;
}


Measured memory_bytes: 4992
#pragma GCC optimize(2)

#include<bits/stdc++.h>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define LINF 9223372036854775807
#define END(s) {cout<<s;return 0;}
#define CON(s) {cout<<s;continue;}
#define BRE(s) {cout<<s;break;}
#define pb push_back
#define All(a) a.begin(),a.end()  //with A in CAPITAL!!!
#define sz(a) (int)a.size()
#define F first
#define S second
using namespace std;

int main(){
//	ios::sync_with_stdio(false);
	int n;
	char s[300005];
	cin>>n;
	gets(s),gets(s); //左w 右E 
	int change=0;
	for(int i=1;i<n;i++) change+=(s[i]=='E');
	int mn=change;
	for(int i=1;i<n;i++){
		if(s[i-1]=='W') change++;
		if(s[i]=='E') change--;
		mn=min(mn,change);
	}
	cout<<mn;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		for (int i=0;i<s.length();i++) {
			int a = s.charAt(i)-'A';
			a=(a+N)%26;
			System.out.print((char)(a+'A'));
		}
	}
}

Measured memory_bytes: 39432
n = int(input())
nums = input().split(" ")

status = 'APPROVED'
for i in range(n):
    if int(nums[i]) % 2 == 0:
        if int(nums[i]) % 3 != 0 and int(nums[i]) % 5 != 0:
            status = 'DENIED'
            break
print(status)


Measured memory_bytes: 2940
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

int main(){
	double n, m;
	while(~scanf("%lf %lf", &n, &m)){
		printf("%.10lf\n", n * 1.0 / m);
	}
	return 0;
}

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

using namespace std;
long long  a[1000000];
int h[1000000];long long  table[1000000];
int main()
{int N;
cin>>N;
for(int i=0;i<N;i++){
    cin>>h[i];


}
for(int i=0;i<N;i++){
if(i==0) table[i]=0;
else if(i==1) table[i]=abs(h[i]-h[i-1]);
else table[i]=min(abs(h[i]-h[i-1])+table[i-1],abs(h[i]-h[i-2])+table[i-2]);


}


    cout << table[N-1] << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

class DK {
public:
	struct edge {
		int to;
		ll cost;
	};

	int prev[100010];
	ll d[100010];
	int N;
	vector<edge> G[100010];//各頂点からの辺

	void dijkstra(int start) {
		fill(d, d + 100010, INF);
		d[start] = 0;
		fill(prev, prev + 100010, -1);

		priority_queue<P, vector<P>, greater<P>> que;
		que.push(P(0, start));

		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first)continue;
			for (int i = 0; i < G[v].size(); i++) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					prev[e.to] = v;
					que.push(P(d[e.to], e.to));
				}
			}
		}
	}

	vector<int> get_path(int goal) {
		vector<int> path;
		for (int t = goal; t != -1; t = prev[t]) {
			path.push_back(t);
		}//このままでは逆順なのでひっくり返す
		reverse(ALL(path));
		return path;
	}
};

DK dk;

ll k;

int main() {
	cin >> k;
	rep(i, k) {
		dk.G[i].push_back({ (int)((i + 1) % k),1 });
		dk.G[i].push_back({ (int)((10 * i) % k),0 });
	}
	dk.dijkstra(1);
	cout << dk.d[0] + 1 << endl;
}

Measured memory_bytes: 9592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n>>m;
    if(n<=m)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int n;
set <string > st;
int main()
{
  cin>>n;
  string s;
  for(int i=0;i<n;i++)
  {
    cin>>s;
    st.insert(s);
  }
  
  cout<<st.size()<<endl;
  
  return 0;
}


Measured memory_bytes: 19100
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n,l = gi
str = []
rep n do 
	str << gsf
end

str.sort!

puts str.join

Measured memory_bytes: 2044
/*
title:

url:D - Grid Repainting

全体の白色の数から最短経路を引けばいい。
最短経路を求めるには、幅優先探索を用いる。
アリ本の迷路の最短路問題とほぼ同じ
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int h, w;
    cin >> h >> w;
    string data[h];
    REP(i, h)
    {
        cin >> data[i];
    }

    queue<pint> q;
    q.push(make_pair(0, 0));
    int d[h][w];
    int n_white = 0;
    REP(i, h)
    {
        REP(j, w)
        {
            d[i][j] = INF;
            if (data[i][j] == '.')
                n_white++;
        }
    }
    d[0][0] = 1;

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

    while (q.size())
    {
        pint tmp = q.front();
        q.pop();
        if (tmp.first == h - 1 && tmp.second == w - 1)
            break;
        for (int i = 0; i < 4; i++)
        {
            int nx = tmp.first + dx[i];
            int ny = tmp.second + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                data[nx][ny] != '#' && d[nx][ny] == INF)
            {
                d[nx][ny] = d[tmp.first][tmp.second] + 1;
                q.push(make_pair(nx, ny));
            }
        }
    }

    if (d[h - 1][w - 1] == INF)
    {
        cout << -1 << endl;
        return 0;
    }
    else
    {
        cout << n_white - d[h - 1][w - 1] << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

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

      int maxNum = -1;
      int minNum = Integer.MAX_VALUE;
      for(int i = 0; i < n; i++) {
        int num = sc.nextInt();
        arr[i] = num;
        maxNum = Math.max(maxNum, num);
        minNum = Math.min(minNum, num);
      }
      int half = maxNum / 2;
      int res = minNum;
      for(int num : arr) {
        if(num == maxNum) continue;
        if(Math.abs(num - half) < Math.abs(res - half))
          res = num;
      }
      System.out.println(maxNum + " " + res);
  }
}

Measured memory_bytes: 50088
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
		
	int a, b;
	cin >> a >> b;
	if (a > 0)
		cout << "Positive" << endl;
	else if (a <= 0 && b >= 0)
		cout << "Zero" << endl;
	else
	{	
		b = min(b, -1);
		if ((b - a + 1) & 1)
			cout << "Negative" << endl;
		else
			cout << "Positive" << endl;
	}	

	return 0;
}



Measured memory_bytes: 256
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    int n = input<int>();
    vector<pair<int, int>> a(n);

    for (int i = 0; i != n; ++i)
        cin >> a[i].first >> a[i].second;

    std::sort(ALL(a), [](pair<int, int> x, pair<int, int> y) {return make_pair(x.first + x.second, x.first) < make_pair(y.first + y.second, y.first);});

    vector<int> f(n + 1); // given that last taken
    // person is i and there are j + 1 taken persons now, what is the minimum height now.

    f[0] = 0;
    std::fill(f.begin() + 1, f.end(), TYPEMAX(int));
    
    for (int i = 0; i != n; ++i)
        for (int j = n; j > 0; --j)
            if (f[j - 1] <= a[i].first)
                f[j] = min(f[j], f[j - 1] + a[i].second);

    cout << std::find(ALL(f), TYPEMAX(int)) - f.begin() - 1 << "\n";
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main() {
  
  int H,W,K;
  cin >> H >> W >> K;

  vector<vector<char>> S(H,vector<char>(W));
  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      cin >> S[i][j];
    }
  }

  int ans = 10000000;
  for(int bit = 0;bit < 1<<(H-1);bit++) {
    int num = 0,ln = 0;
    vector<int> c(1,0),l(H+1,0);
    for(int i = 0;i < H-1;i++) {
      if((bit>>i)&1) {
        num++;
        c.push_back(i+1);
      }
    }
    c.push_back(H);

    for(int i = 0;i < W;i++) {
      bool can = true;
      for(int j = 1;j < c.size();j++) {
        for(int k = c[j-1];k < c[j];k++) {
            if(S[k][i]=='1') l[j]++;
        }
      }
      
      int L = l.size();
      for(int j = 0;j < L;j++)  {
        if(l[j] > K) {
          if(ln==i) {
            can = false;
          }else ln = i;
          num++;
          i--;
          l.assign(L,0);
          break;
        }
      }

      if(!can) {
        num = 100000000;
        break;
      }

    }


    ans = min(ans,num);

  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int x,y,ans=0;
	cin >> x >> y;

	if (y == 100)
		ans += x * 1000;
	else if (y >= 10)
		ans += x * 100;
	else
		ans += x * 10;
	ans += y;
	bool check = false;
	int i = 1;
	while (1) {
		if (i*i == ans) {
			check = true;
			break;
		}
		else if (i*i > ans)
			break;
		i++;
	}
	if (check)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
inf = float("inf")
dp = [[inf]*100 for _ in [0]*100]
for i in range(10):dp[i][i] = 0
d = [list(map(int, input().split())) for i in range(10)]
m = [list(map(int, input().split())) for i in range(N)]
ans = 0
 
for i in range(10):
    for j in range(10):
        dp[i][j] = d[i][j]
for k in range(10):
    for i in range(10):
        for j in range(10):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
c=0
for i in range(N):
    for j in range(M):
        if m[i][j] != 1 :
            if m[i][j] != -1 :
                c+=dp[m[i][j]][1]
print(c)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, k; cin >> n >> k;
    VL a(n); cin >> a;

    function<ll(int)> solve = [&](int bit) {
        ll ret = 0, maxa = 0;
        FOR(i, 0, n) {
            if (bit & (1 << i)) {
                if (a[i] <= maxa) {
                    ret += maxa + 1 - a[i];
                    ++maxa;
                }
                else maxa = a[i];
            }
            else chmax(maxa, a[i]);
        }
        return ret;
    };

    ll ans = LLINF;
    FOR(bit, 0, 1 << n) {
        int cnt = 0;
        FOR(i, 0, n)if (bit & (1 << i))++cnt;
        if (cnt == k)chmin(ans, solve(bit));
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    string res = "No";
    if(N == M)res = "Yes";


    cout << res << endl;

    return 0;
}


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

int main(void)
{
	int a,b,n;
	int as, bs;

	while(cin >> n, n){
		as = bs = 0;
		for(int i = 0; i < n; i++){
			cin >> a >> b;
			if(a > b)
				as += a + b;
			else if(b > a)
				bs += a + b;
			else{
				as += a;
				bs += b;
			}
		}

		cout << as << ' ' << bs << endl;
	}


	return 0;
}

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


int main() {
long long A,B,K;
cin >> A >> B >> K;

if(A>=K){
    cout<<A-K<<' '<<B<<endl;
    
}
else if((A+B)>=K){
cout<<0<<' '<<(A+B)-K<<endl;
}
else{
    cout<<0<<' '<<0<<endl;
}
}


Measured memory_bytes: 256
import re
A,B,C = map(int,input().split())
#N = str(input())
#K = int(input())
#A = list(map(int,input().split()))
if A==B==C and A%2==0 and B%2==0 and C%2==0:
    print(-1)
    exit()
flag=True
co=0
if A%2!=0 or B%2!=0 or C%2!=0:
    flag=False
while flag==True:
    co+=1

    a=B/2 + C/2
    b=A/2 + C/2
    c=B/2 + A/2
    if a%2!=0 or b%2!=0 or c%2!=0:
        flag=False
    A=a
    B=b
    C=c

print(co)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60; // 十分大きい値とする

int main() {
    // 入力
    int N; cin >> N;
    vector<long long> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    vector<long long> dp(N, INF);

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
 
const int mod=998244353;
const int maxn=4e5+7;
ll fac[maxn],inv[maxn];
 
ll power(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
 
void init(){
    fac[0]=1,fac[1]=1;
    for(int i=2;i<=maxn;i++) fac[i]=fac[i-1]*1ll*i%mod;
    inv[maxn]=power(fac[maxn],mod-2)*1ll;
    for(int i=maxn-1;i>=0;i--) inv[i]=inv[i+1]*1ll*(i+1)%mod;
}
 
ll c(ll n,ll m){
    if(m==0) return 1;
    if(n<m) return 0;
    if(n==m) return 1;
    return fac[n]*1ll*inv[m]*1ll%mod*inv[n-m]%mod;
}
 
 
int main (){
    init();
    int n,a,b;
    ll k,ans=0;
    scanf("%d %d %d %lld",&n,&a,&b,&k);
    if(k==0) { puts("1"); return 0;}
    for(int  x=1;x<=n;x++){
        if((k-a*x)%b) continue;
        ll y=(k-a*x)/b;
        ans=(ans+c(n,x)*1ll%mod*c(n,y)*1ll%mod)%mod;
    }
    printf("%I64d\n",ans);
    return 0;
}
/**
Tricks&Orz.....RE需谨慎！！！！！
题意：输入4个数 n,a,b,k  选的颜色的最多的数量  涂红色所能获得的分 涂蓝色所能获得的分 获得分数之和为k
其实和颜色没有很大的关系;
大意:选择若干个a,b和a+b,使得所选数的总和等于k的方案数;
分析：不要被a+b干扰了  就差不多能出来了  2333...
首先我们可以得到  a*x+b*y=k  枚举x 得到y ans=ans+c(n,x)*c(n,y);
大概意思就是 给定一个初始值为0的数组 然后让你将a和b填入该数组中 只要和为k就NICE了 问方案数 想清楚就可以miao了
 题目质量很良心 RE都能卡我这么久的
 
*/


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

long long dp[2000][2000] = {0};

int main() {
  long long N;
  cin >> N;
  P b[2000];
  rep(i, N) {
    long long temp;
    cin >> temp;
    b[i] = {temp, i+1};
  }
  P a[2000];
  sort(b, b+N);

  rep(i, N) {
    a[i] = b[N-i-1];
  }

  for(long long k = 0; k < N; k++) {
    for(long long x = 0; k - x >= 0; x++) {
      long long y = k - x;
      dp[x+1][y] = max(dp[x+1][y], dp[x][y] + a[x+y].first * abs(a[x+y].second - x-1));
      dp[x][y+1] = max(dp[x][y+1], dp[x][y] + a[x+y].first * abs(a[x+y].second - N + y));
    }
  }
  // for(long long k = 0; k <= N; k++) {
  //   for(long long x = 0; k - x >= 0; x++) {
  //     long long y = k - x;
  //     cout << dp[x][y] << " ";
  //   }
  //   cout << endl;
  // }
  long long ans = 0;
  rep(i, N+1) {
    long long j = N - i;
    ans = max(ans, dp[i][j]);
  }
  cout << ans << endl;
  return 0;
}

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

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

    for (int i = min(a,b);i > 0;i--){
        if (a % i == 0 && b % i == 0){
            k--;
            if (k == 0){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

int main()
{
    ll x; cin >> x;
    ll ans = x / 11 * 2;
    if (x % 11 > 6) ans += 2;
    else if (x % 11) ans += 1;

    cout << ans << endl;

    return 0;
}
    

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

int main(){
    int total, step;
    vector<int> person;
    vector<int>::iterator it;
    int i, m;

    while(1){
        //get input
        cin >> total >> step;

        //finish condition
        if(total == 0 && step == 0) break;

        //init
        for(i = 1; i <= total; i++){
            person.push_back(i);
        }
        it = person.begin();
        
        while(1){
            //answer
            if(person.size() == 1){
                cout << person[0] <<endl;
                person.clear();
                break;
            }

            //step forward
            for(m = 0; m < (step - 1); m++){
                it++;                
                if(it == person.end()){
                    it = person.begin();
                }
            }

            //delete
            person.erase(it);
            if(it == person.end()){
                it = person.begin();
            }

//            for(int k = 0; k < person.size(); k++){
//                cout << *it <<"is erased " << person[k] << endl;
//            }
        }
    }

    return 0;
}

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

using namespace std;

int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  int largest = (b / k) * k;
  if (a <= largest) {
  puts("OK");
  } else {
  puts("NG");
  }
 return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vs vector<string>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define vvpll vector<vpll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll T;cin>>T; while(T--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
#define pi 3.14159265358979323846
#define MOD 1000000007
#define MAX 2000000000000000000
#define MAXN 1000005
const ll infinity =1e18;
 
  double dp[3000][3000];
   //ll ch[100][100005];      // initial declaration of array outside the main.
 //string s[1002];
double p[3000];
  



 int main(){

//	fast_io
	//Test{

	//}
	int n;
      cin>>n;
      //cout<<n;
      for(ll i=0;i<n;i++)cin>>p[i];
      	//base case
      	dp[0][0]=1-p[0];
        dp[0][1]=p[0];
      	//transition state
         for(ll i=1;i<n;i++)
         	for(ll j=0;j<3000;j++)
         	{
         		dp[i][j]+=(1-p[i])*dp[i-1][j];
                if(j>0)
         		dp[i][j]+=p[i]*dp[i-1][j-1];
         	}

     	//ans
         	double ans=0;
         	for(ll i=n/2+1;i<3000;i++)
                 ans+=dp[n-1][i];
            
         cout<<setprecision(9);
         cout<<fixed;
         


            cout<<ans;
            return 0;
}

Measured memory_bytes: 74012
import java.util.Scanner;

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

        switch(sc.nextInt() % 7) {
        case 0:
            System.out.println("thu");
            break;
        case 1:
            System.out.println("fri");
            break;
        case 2:
            System.out.println("sat");
            break;
        case 3:
            System.out.println("sun");
            break;
        case 4:
            System.out.println("mon");
            break;
        case 5:
            System.out.println("tue");
            break;
        case 6:
            System.out.println("wed");
            break;
        }
    }
}

Measured memory_bytes: 26204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;



/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    string s,t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string picked_str; cin >> picked_str;
    
    if (picked_str == s) {
        a--;
    }
    if (picked_str == t) {
        b--;
    }
    cout << a << " " << b << endl;
    
}


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


int main()
{
	int n;
	char ch;
	cin >> n;
	int flag = 0;
	for(int i = 1;i <= n;i++){
		cin >> ch;
		if(ch == 'Y') flag = 1;
	}
	if(flag) cout << "Four" << endl;
	else cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,s[200],i,box,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		s[i]=0;
	}
	for(i=0;i<n;i++){
		scanf("%d",&a);
		while(1){
			if(a%2==0){
				s[i]++;
				a=a/2;
			}
			else{
				break;
			}
		}
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(s[i]>s[j]){
				box=s[i];
				s[i]=s[j];
				s[j]=box;
			}
		}
	}
	printf("%d\n",s[0]);
	return 0;
	}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << ((h2 - h1) * 60 + m2 - m1 - k) << '\n';

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
const int N=100100;
long long n,m,t3,t4,a[N*2],sum;
long long ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>t3;
    for(int i=2;i<=n;++i)
    {
        int d,t1,t2;
        cin>>t4;
        t1=t3;t2=t4;
        if(t2<t1) t2+=m;
        d=t2-t1;
        ans+=d;
        if(d>1)
        {
            a[t1+2]++;
            a[t2+1]-=d;
            a[t2+2]+=d-1;
        }    
        t3=t4;
    }
    sum=0;
    for(int i=1;i<=2*m;++i)
    {
        sum+=a[i];
        a[i]=sum;
    }
    sum=0;
    long long maxx=0;
    for(int i=1;i<=2*m;++i)
    {
        sum+=a[i];
        a[i]=sum;
    }
    for(int i=m+1;i<=2*m;++i)
    {
        a[i-m]+=a[i];
        maxx=max(a[i-m],maxx);
    }
    cout<<ans-maxx<<endl;      
    return 0;
}

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

using namespace std;

struct mylist{
    mylist* left;
    mylist* right;
    int num;
    mylist(int a){
        left= nullptr;
        right= nullptr;
        num=a;
    }
};

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    vector<bool> suv(n,true);
    mylist* head=new mylist(0);
    mylist* tail=head;
    for (int i = 1; i < n; ++i) {
        mylist* t=tail;
        t->right=new mylist(i);
        t->right->left=t;
        tail=t->right;
    }
    head->left=tail;
    tail->right=head;
    mylist* t=head;
    for (int i = 0; i < m; ++i) {
        int o;
        cin>>o;
        bool d=false;
        if(o%2==0)d=true;
        for (int j = 0; j < o; ++j) {
            if(d)t=t->right;
            else t=t->left;
        }
        t->left->right=t->right;
        t->right->left=t->left;
        suv[t->num]=false;
        t=t->right;
    }
    for (int i = 0; i < q; ++i) {
        int w;
        cin>>w;
        if(suv[w])cout<<1<<endl;
        else cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 9360
#include <iostream>
using namespace std;
int main(void){
int value;
int a;

cin >> value;

a = (value % 10); 
value /= 10;

if(a == 3){
    cout << "bon" << endl;
}else if(a == 0 || a==1 || a==6 || a==8){
    cout << "pon" << endl;
}else{
    cout <<"hon" <<endl;
}

}


Measured memory_bytes: 3624
A,B,M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [[0 for k in range(3)] for k in range(M)]

m = 0
while m < M:
    c[m][0],c[m][1],c[m][2]= map(int, input().split())
    m = m + 1

result = min(a) + min(b)

i = 0
for i in range(M):
    num = a[c[i][0]-1] + b[c[i][1]-1]-c[i][2]
    if result > num:
        result = num
    i = i + 1

print(result)


Measured memory_bytes: 32500
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define VI vector<int>
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define br(c,y,n) cout << ((c)? y : n) << endl

int main()
{
    VI a(3);
    rep(i,3)in(a.at(i));
    sortall(a);
    YES(a.at(0)==5&&a.at(1)==5&&a.at(2)==7);
    return 0;
}


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 n;
  cin >> n;

  int res = n % 10;
  if (res == 3) {
    cout << "bon" << endl;
  } else if (res == 1 || res == 0 || res == 6 || res == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define mod 1000000007
#define inf 1<<30
#define mp(a,b) make_pair(a,b)
#define len(u,N) u.begin(),u.begin()+N

ll H,W;
ll N;
ll a[10010];
ll g[110][110];

int main() {
    cin >> H >> W;
    cin >> N;
    rep(i,N) cin >> a[i];
    ll active = 1;
    ll activecnt = 0;

    rep(i,H){
        if (i % 2 == 0)
        rep(j,W){
            g[i][j] = active;
            activecnt ++;
            if (activecnt >= a[active-1]){
                active++;
                activecnt = 0;
            }
        }
        else{
            for(ll j=W-1; j>=0; j--){
                g[i][j] = active;
                activecnt ++;
                if (activecnt >= a[active-1]){
                    active++;
                    activecnt = 0;
                }
            }
        }
    }
    rep(i,H){
        rep(j,W){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }
  
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
const int mod = 1000000007;
//const int mod = 998244353;
 
 
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
 
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}


int main(int argc, const char * argv[]) {

    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(),A.end(),greater<int>());
    
    ll sum = A[0];
    
    ll cnt=1;
    for(ll i=1;i<N-1;i++){
        if(i%2==1){
            sum += A[cnt];
        }else{
            sum += A[cnt];
            cnt++;
        }
    }
    
    cout << sum << endl;
    
    return 0;
}


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

int N, M, temp;
const int max1 = (10e+5) + 1;
pair<int,int> way[max1];
int ans = 0;


int main() {
  while(cin >> N >> M && N != 0) {
    ans = 0;
    for(int i = 0;i < max1 ; i++) way[i] = make_pair(0,0);
    for(int i = 0;i < N ; i++) cin >> way[i].second >> way[i].first;
    sort(way, way+N);
    reverse(way, way+N);
    //for(int i = 0;i < N ; i++) cout <<  way[i].second << ' ' << way[i].first;
    int i = 0;
    while(way[i].first != 0){
      if(M >= way[i].second){
        M -= way[i].second;
        i++;
        continue;
      }
      if(M >= 0){
        ans += (way[i].second - M)*way[i].first;
        M = 0;
        i++;
        continue;
      }
      ans += way[i].second * way[i].first;
      i++;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 10900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NM = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            List<long[]> list = new List<long[]>();
            for(int z = 0; z < NM[0]; z++)
            {
                list.Add(Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray());
            }
            long[] min = new long[NM[0]];
            long[] number = new long[NM[0]];
            for (int j = 0; j < NM[1]; j++)
            {
                long[] points = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
                for(int x = 0; x < NM[0]; x++)
                {
                    //キョリ
                    long sum = Math.Abs(points[0] - list[x][0]) + (Math.Abs(points[1] - list[x][1]));
                    //何も無い時
                    if (j == 0)
                    {
                        min[x] = sum;
                        number[x] = j + 1;
                    }
                    else
                    {
                        //若い番号優先
                        if (sum < min[x])
                        {
                            //比較
                            min[x] = sum;
                            number[x] = j + 1;
                        }
                    }
                }
            }
            for(int w = 0; w < number.Count(); w++)
            {
                Console.WriteLine(number[w]);
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 27916
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const LL MOD = 1000000007LL;
using namespace std;

int main() {
	int A, B;
	string op;
	cin >> A >> op >> B;
	if (op == "+") {
		cout << A + B << endl;
	}
	else {
		cout << A - B << endl;
	}
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int u = 0;
		int x;
		while (true) {
			x = sc.nextInt();
			if (x == 0) {
				break;
			}System.out.println("Case " + (++u) + ": " + x);
		}
	}
}



Measured memory_bytes: 41196
#include<bits/stdc++.h>
int main() {
	int num1, num2, num3, num4, num5;
	std::cin >> num1 >> num2 >> num3 >> num4 >> num5;
	if (num1 == 0)std::cout << 1;
	else if (num2 == 0)std::cout << 2;
	else if (num3 == 0)std::cout << 3;
	else if (num4 == 0)std::cout << 4;
	else if (num5 == 0)std::cout << 5;

}


Measured memory_bytes: 3644
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  map<int,pair<int,int>> table;
  bool hyou[3][3];
  int temp;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> temp;
      table[temp] = make_pair(i,j);
      hyou[i][j] = false;
    }
  }
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> temp;
    if(table.find(temp) == table.end()) continue;
    hyou[table[temp].first][table[temp].second] = true;
  }
  string ans = "No";
  for(int i=0;i<3;i++){
    if(hyou[i][0]&&hyou[i][1]&&hyou[i][2]) ans = "Yes";
    if(hyou[0][i] && hyou[1][i] && hyou[2][i])ans = "Yes";
  }
  if(hyou[0][0] && hyou[1][1] && hyou[2][2]) ans = "Yes";
  if(hyou[2][0] && hyou[1][1] && hyou[2][0]) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256