akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    set<int> able;

    for (int bit = 1; bit < (1 << n); bit++) {
        int sum = 0;
        rep(i, n) {
            if ((bit >> i) & 1) {
                sum += A[i];
            }
        }
        able.insert(sum);
    }

    int q;
    cin >> q;
    rep(i, q) {
        int m;
        cin >> m;
        if (able.count(m)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


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


int main(){
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    double ans = v[0];
    for (int i = 1; i<n;i++){
        ans = ( ans + v[i])/2;
    }
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        // 主処理
        boolean judge = s.charAt(0) != s.charAt(1) || s.charAt(1) != s.charAt(2);
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
int dp[3009][3009];
int solve(int i,int j){
	if(i>=s1.length()||j>=s2.length())
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(s1[i]==s2[j])
		return dp[i][j]=1+solve(i+1,j+1);
	return dp[i][j]=max(solve(i+1,j),solve(i,j+1));
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>s1;
	cin>>s2;
	for(int i=0;i<3009;i++)
		for(int j=0;j<3009;j++)
			dp[i][j]=-1;
	int k=solve(0,0);
	string ans="";
	int i=0,j=0;
	while(i<s1.length()&&j<s2.length()){
		if(s1[i]==s2[j]){
			ans.push_back(s1[i]);
			i++;
			j++;
			continue;
		}
		if(dp[i][j+1]>dp[i+1][j])
			j++;
		else 
			i++;
	}
	cout<<ans;
}

Measured memory_bytes: 35968
#include <iostream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string.h>

using namespace std;

int N;
int a[5000];
int c[100000];

int main(int argc, char** argv) {
    cin >> N;
    int sum = 0;
    for (int i=0; i<N; i++) {
        cin >> a[i];
        sum += a[i] - 1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

const int MN = 100100;
int main() {
    cout << setprecision(20);
    int n, m;
    cin >> n >> m;
    int co[MN] = {};
    int ok[MN] = {};
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        co[x % m]++;
        mp[x]++;
    }
    for (auto p: mp) {
        ok[p.first % m] += p.second/2;
    }
    int sm = 0;
    sm += co[0]/2;
    if (m % 2 == 0) sm += co[m/2]/2;
    for (int l = 1; l < m; l++) {
        int r = m-l;
        if (l >= r) break;
        sm += min(co[l], co[r]);
//        cout << co[l] << " " << co[r] << " d " << l << endl;
        if (co[l] < co[r]) {
            int y = (co[r]-co[l])/2;
            sm += min(y, ok[r]);
        } else {
            int y = (co[l]-co[r])/2;
            sm += min(y, ok[l]);
        }
    }
    cout << sm << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N; cin >> N;
     vector<int> a(N);
     for(int i = 0; i < N; i++){
          cin >> a[i];
     }
     sort(a.begin(),a.end());
    
     int A = 0,B = 0;
     for(int i = N - 1;i >= 0; i -= 2){
          A += a[i];
     }
     for(int j = N - 2; j >= 0; j -= 2){
          B += a[j];
     }
     cout << A - B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str>>str2>>str3;
	cout<<"A"<<str2[0]<<"C";


	cout<<endl;
} 


Measured memory_bytes: 256
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var arr = o.getArray(0);
    var L = arr[0];
    var R = arr[1];
    var d = arr[2];

    var add = 0;
    if (L % d === 0) add = 1;

    var max = Math.floor(R / d);
    var min = Math.floor(L / d);
    return max - min + add;
}

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

using namespace std;

int a[100100];


int main()
{
//    freopen("int.txt","r",stdin);

    int a,c;
    while(cin>>a>>c&&a&&c)
    {
        for(int i=0; i<a; i++)
        {
            for(int j=0; j<c; j++)
            {
                if((i+j)%2==0)
                    cout<<"#";
                else
                    cout<<".";
            }
            cout<<endl;

        }
        cout<<endl;

    }
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    int32 s[n], t[m];
    REP(i,n)cin >> s[i];
    REP(j,m)cin >> t[j];
    vector<vector<int64>> dp(n+1, vector<int64>(m+1,0));
    FOR(i,1,n+1)FOR(j,1,m+1){
        dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + MOD) % MOD;
        if(s[i-1] == t[j-1]){
            dp[i][j] += dp[i-1][j-1] + 1;
            dp[i][j] %= MOD;
        }
    }
    ANS((dp[n][m] + 1) % MOD);
    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,m;
	cin >> n >> m;
	vector<vector<int>> road(n, vector<int>(n,0));
	FOR(i,0,m){
		int a,b;
		cin >> a >> b;
		road[a-1][b-1]++;
		road[b-1][a-1]++;
	}
	FOR(i,0,n){
		int cnt = 0;
		FOR(j,0,n){
			cnt += road[i][j];
		}
		ANS(cnt);
	}
	return 0;
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    string ans = "";
    while (1)
    {
        int amari = abs(N % (-2));
        N = (N - amari) / (-2);
        char add = amari + '0';
        ans = add + ans;
        if (N == 0)
        {
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <map>

/*
\cap_{u,v} \cup_{i\in (u,v) path} E_i
|E| - \cup_{u,v} \cap_{i\in (u,v) path} !E_i
|E| - \cup_{j} A_j

g(N) = |{E | {u,v\in M | \cap_{i\in (u,v) path} !E_i} = N}|

g(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} = N}|
G(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} \subseteq N}|
     = |{E | {u,v\in M-N | \cap_{i\in (u,v) path} !E_i}}|
*/

int n, m;
std::vector<int> E[50];
int D[50][50];

long long int M[20];
long long int A[1<<20];
std::map<std::pair<int, int>, int> edges;

long long int dfs(int u, int v, int p){
  if(u == v) return 0;
  for(int x: E[u]){
    if(x == p) continue;
    long long int b = dfs(x, v, u);
    if(b != -1) return (1LL << edges[{u, x}]) | b;
  }
  return -1;
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n-1; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    E[a-1].push_back(b-1);
    E[b-1].push_back(a-1);
    edges[{a-1,b-1}] = i;
    edges[{b-1,a-1}] = i;
  }
  scanf("%d", &m);
  for(int i = 0; i < m; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    M[i] = dfs(a-1, b-1, -1);   
  }
  for(int i = 0; i < (1<<m); i++){
    for(int j = ~i & ((1<<m)-1); j; j &= j-1) A[i] |= M[__builtin_ctzll(j)];
    A[i] = 1LL << (n-1-__builtin_popcountll(A[i]));
  }
  long long int ans = 0;
  for(int i = 0; i < (1<<m); i++){
    ans += (1-2*__builtin_parity(~i&((1<<m)-1)))*A[i];
  }

  printf("%lld\n", ans);
  return 0;
}


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

int main(){
  int m, f, r;

  while(true){
    cin >> m >> r >> f;

    int sum = m+r;
    if(m == -1 && r == -1 && f == -1){
      return 0;
    }else if(m == -1 || r == -1){
      cout << "F" << endl;
    }else if(sum >= 80){
      cout << "A" << endl;
    }else if(80 > sum && sum >= 65){
      cout << "B" << endl;
    }else if(65 > sum && sum >= 50){
      cout << "C" << endl;
    }else if(50 > sum && sum >=30){
      if(f >= 50){
        cout << "C" << endl;
      }else {
        cout << "D" << endl;
      }
    }else if(30 > sum){
      cout << "F" << endl;
    }
  }
}

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

int main(){
  int N,M,X,cnt1 = 0,cnt2 = 0;
  cin >> N >> M >> X;
  int a[N+1]={0},b[M];
  for(int i=0;i<M;i++)
    cin >> b[i];
  for(int j=0;j<M;j++)
    a[b[j]]++;
  for(int k=X;k<=N;k++)
    cnt1 += a[k];
  for(int l=0;l<=X;l++)
    cnt2 += a[l];
  cout << min(cnt1,cnt2) << endl;
}

Measured memory_bytes: 256
n,m,k=map(int, input().split())

mod=998244353
ans=0
c=1
for i in range(k+1):
    ans+=c*m*pow(m-1, n-1-i, mod)
    ans%=mod
    c*=(n-i-1)*pow(i+1, mod-2, mod)
    c%=mod
print(ans%mod)


Measured memory_bytes: 80176
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define R register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(R int i = a;i <= b;++i)
#define RFOR(i,a,b) for(R int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

LL N,A,B,C,D;

int main(){
    scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);
    FOR(k,0,N-1){
        if(k*C-(N-k-1)*D <= B-A && B-A <= k*D-(N-k-1)*C){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        self.n_groups = N  # グループ数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
        self.n_groups -= 1

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N, M = ints()
uf = UnionFind(N)
for _ in range(M):
    a, b = mina(*ints())
    uf.unite(a, b)

# あとはなるべく別々になるように
# →サイズを1ずつ引いて1グループ
# いやmaxのsizeか

print(-min(uf.parent))


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  multiset<int, greater<int>> s;
  rep(i, n) s.insert(a[i]);
  rep(i, n) {
    s.erase(s.find(a[i]));
    out(*s.begin());
    s.insert(a[i]);
  }
}


Measured memory_bytes: 13492
'use strict'
function Main(input){
  input=input.split(/\s+/);
  var H=input.shift()-0;
  var W=input.shift()-0;
  var N=input.shift()-0;
  var sr=input.shift()-0;
  var sc=input.shift()-0;
  var S=input.shift();
  var T=input.shift();
  var dp=[[sc,sc,sr,sr]];
  for(let i=0;i<N;i++){
    dp[i+1]=[];
    dp[i+1][0]=dp[i][0]-(S[i]==='L'?1:0);
    dp[i+1][1]=dp[i][1]+(S[i]==='R'?1:0);
    dp[i+1][2]=dp[i][2]-(S[i]==='U'?1:0);
    dp[i+1][3]=dp[i][3]+(S[i]==='D'?1:0);
    if(dp[i+1][0]===0||dp[i+1][1]===W+1||dp[i+1][2]===0||dp[i+1][3]===H+1){
      console.log('NO');
      return;
    }
    dp[i+1][0]=Math.min(dp[i+1][0]+(T[i]==='R'?1:0), W)
    dp[i+1][1]=Math.max(dp[i+1][1]-(T[i]==='L'?1:0), 1)
    dp[i+1][2]=Math.min(dp[i+1][2]+(T[i]==='D'?1:0), H)
    dp[i+1][3]=Math.max(dp[i+1][3]-(T[i]==='U'?1:0), 1)
  }
  console.log('YES');
}

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


Measured memory_bytes: 73676
N = int(input())
H = [int(i) for i in input().split()]

flag = False
for i in range(1,N):
    if H[i] - H[i-1] == 0:
        continue
    elif H[i] - H[i-1] < 0:
        flag = True
        break
    elif H[i] - H[i-1] > 0:
        H[i] -= 1

if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14396
import java.util.Arrays;
import java.util.Scanner;

class Main{
	static int max;
	static int[][] mjs;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int[] alp=new int[26];
		Arrays.fill(alp, 0);
		for(int i=0; i<s.length(); i++) {
			alp[s.charAt(i)-97]++;
		}
		mjs=new int[s.length()][s.length()];
		for(int i=0; i<s.length(); i++) {
			Arrays.fill(mjs[i],-1);
		}
		for(int i=0; i<s.length(); i++) {
			mjs[0][i]=s.charAt(i)-97;
		}
		int answ=114514;
		for(max=0; max<26; max++) {
			for(int i=1; i<s.length(); i++) {
				for(int j=0; j<s.length()-i; j++) {
					if(mjs[i-1][j]!=max && mjs[i-1][j+1]!=max) {
						if(mjs[i-1][j+1]==-1) {
							mjs[i][j]=mjs[i-1][j];
						}
						else {
							mjs[i][j]=mjs[i-1][j];
						}
					}
					if(mjs[i-1][j]==max || mjs[i-1][j+1]==max) {
						mjs[i][j]=max;
					}
				}
			}
			for(int i=0; i<s.length(); i++) {
				boolean ans=ac(i);
				if(ans) {
					answ=Math.min(i, answ);
				}
			}
		}
		System.out.println(answ);
	}
	public static boolean ac(int a) {
		for(int i=0; i<mjs[0].length; i++) {
			if(mjs[a][i]!=-1 && max!=mjs[a][i]) {
				return false;
			}
			else if(mjs[a][i]==-1) {
				break;
			}
		}
		return true;
	}
}

Measured memory_bytes: 23252
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();

		List<Integer> expList = new ArrayList<>();

		for (int i=1; i<=Math.sqrt(X); i++) {
			for (int j=2; j<10; j++) {
				if (Math.pow(i, j)<=X) {
					expList.add((int)Math.pow(i, j));
				}
			}
		}

		Collections.sort(expList);
		System.out.println(expList.get(expList.size()-1));
	}
}



Measured memory_bytes: 23764
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




int main() {
  string s;cin>>s; 
  int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
  if(a+b+c+d == 7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
  else if(a-b+c+d == 7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
  else if(a+b-c+d == 7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
  else if(a+b+c-d == 7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
  else if(a-b-c+d == 7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
  else if(a-b+c-d == 7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
  else if(a+b-c-d == 7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
  else if(a-b-c-d == 7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    string s1 = s.substr(0,n/2);
    string s2 = s.substr(n/2, n/2);
    if(s1 == s2) cout << "Yes" << endl;

    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import fractions

a,b,c,d=map(int,input().split())
g=(fractions.gcd(c,d))
l=int((c*d)/g)

print(b-a+1-int(b//c)+int((a-1)//c)-int(b//d)+int((a-1)//d)+int(b//l)-int((a-1)//l))


Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b,ans=0;
  cin>>n>>a>>b;
  if(n>=(a+b))ans+=(n/(a+b))*a;
  else{
  	cout<<min(n,a);
    return 0; 
  }
  n=n%(a+b);
  if(n>=a) ans+=a;
  if(n<a) ans+=n;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
 
int a[200000];
 
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    	scanf("%d",a+i);
	}
	sort(a,a+n);
	int flag=1;
	for(i=0;i<n-1;i++)
	{
		
		if(a[i]==a[i+1])
		{
			flag=-1;
			break;
		}
	}
    if(flag==1)
    printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll w, h;
ll ans;

int main() {
	cin.tie(0)->sync_with_stdio(0);
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
    cin >> w >> h;
    rep(i, 0, w) {
        ll p;
        cin >> p;
        q.push({p, 0});
    }

    rep(i, 0, h) {
        ll p;
        cin >> p;
        q.push({p, 1});
    }
    ++w, ++h;
    // 0 - col, 1 - row
    ll cols = 0, rows = 0;
    while (!q.empty()) {
        pair<ll, ll> v = q.top();
        q.pop();
        if (v.second == 0) {
            ans += (h - rows) * v.first;
            // cout << h - rows << ' ' << v.first << endl;
            ++cols;
        } else {
            ans += (w - cols) * v.first;
            // cout << w - cols << ' ' << v.first << endl;
            ++rows;
        }
    }
    cout << ans;
}


Measured memory_bytes: 7364
#include<stdio.h>
#define N 100
int main(){
  int M[N][N];
  int i,j;
  int n,u,k,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{

    int n, min, summ, a, d;
    int sum = 0;
    int s[100];
    int k[100];

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }

    //最小
    min = s[0];
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (s[i] > s[j])
            {
                min = s[i];
                s[i] = s[j];
                s[j] = min;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        sum = sum + s[i];
    }

    summ = sum;
    a = 0;
    d = 0;

    if (sum % 10 != 0)
        cout << sum;
    else
    {
        for (int i = 0; i < n; i++)
        {
            if (s[i] % 10 != 0)
            {
                a = s[i];
                d = 1;
            }
            if (d == 1)
            {
                cout << sum - a << endl;
                break;
            }
        }
        if (d == 0)
            cout << 0 << endl;
    }

    return 0;
};

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest


def resolve():
    s = input()

    odd = set(['R', 'U', 'D'])
    even = set(['L', 'U', 'D'])

    ans = True

    for i, ss in enumerate(s):
        if (i + 1) % 2 == 0 and ss in even:
            continue
        elif (i + 1) % 2 == 1 and ss in odd:
            continue
        else:
            ans = False
            break

    if ans:
        print('Yes')
    else:
        print('No')


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """RUDLUDR"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """DULL"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """UUUUUUUUUUUUUUU"""
        output = """Yes"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """ULURU"""
        output = """No"""
        self.assertIO(input, output)
    def test_入力例_5(self):
        input = """RDULULDURURLRDULRLR"""
        output = """Yes"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 6444
#include <stdio.h>

int main(void) {
	int K,S;
	int i,j,cnt=0;
	scanf("%d %d",&K,&S);
	for(i=0;i<=K;i++){
		for(j=0;j<=K;j++){
			if((S-i-j)>=0&&(S-i-j)<=K){
				cnt++;
			}
		}
	}
	printf("%d",cnt);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

/*
?????? 0<=a<=m
??¬??? d
0 <= a + d(n-1) <= m

-d(n-1) <= a <= m-d(n-1)
search all d -> m-d(n-1)<0 -> O(m/n)

-a/(n-1) <= d <= (m-a)/(n-1)
*/

int main(){
  ll n,m;
  cin>>n>>m;
  ll ans = m+1;
  ans %= MOD;
  if(n>1){
    ll dmax;
    {
      // find max m-x*(n-1) >= 0
      ll ok = 0, ng = 1e17/(n-1);
      while(ok+1<ng){
        ll x = (ok+ng)/2;
        if(m-x*(n-1)>=0){
          ok = x;
        }else{
          ng = x;
        }
      }
      dmax = ok;
    }
    ll add = 0;
    dmax %= MOD;
    m %= MOD;
    n %= MOD;
    if(n==0)n=MOD;
    add += dmax * (m+1) % MOD;
    add %= MOD;
    add += MOD - ( (n-1) * (dmax * (dmax+1) / 2 % MOD) ) % MOD;
    ans += add * 2ll % MOD;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3092
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n, k, s;
int res;

void dfs(int, int, int);

int main(void){
    for(; cin >> n >> k >> s, n; cout << res << endl){
        res = 0;
        dfs(0, 0, k);
    }

	return 0;
}

void dfs(int pre, int sum, int rest){
    if(rest-- == 0){
        if(sum == s) res++;
        return;
    }
    range(i, pre + 1, n + 1){
        dfs(i, sum + i, rest);
    }
}

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

int n,k;
int sum;
char s[100005];

int main()
{
	cin>>n>>k;
	scanf("%s",s+1);
	s[0] = 'R';
	s[n+1] = 'L';
	for(int i=0;i<=n;i++)
		if(s[i]=='R' && s[i+1]=='L')
			sum++;
	cout<<min(n-1,n-max(0,sum-k)*2+(s[1]=='L')+(s[n]=='R'))<<endl;
	
	return 0;
}

Measured memory_bytes: 384
/*

                                  In the name of Allah, Most Gracious, Most Merciful


*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;

//*** constant value ***
const long double PI = 3.141592653589793238;
const double EPS = 1e-6 ;
//*** constant value ***

//****** define ********
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define dd double
#define vll vector<ll>
#define vs vector<string>
#define fn(i,n) for(ll i = 0; i<n; i++)
#define f(i,a,b) for(i=a;i<b;i++)
#define f1(i,a,b) for(i=b-1;i>=a;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define vpl vector<pll>
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define tt cout<<"Came here"<<endl;
//****** define ********
void solve()
{
  ll n,k;
  cin>>n>>k;
  ll ans = n % k;
  ans = min (ans, k - ans);

  cout<<ans<<endl;

}

int main()
{
    IOS;
    ll tc = 1;
    while(tc--)
    {
        solve();
    }


return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

bool dfs(int key, vector<vector<int>> &v, vector<int> &w){
    bool flag=true;
    for(int i=0; i<v[key].size(); ++i){
        if(w[v[key][i]]<0){
            w[v[key][i]]=1-w[key];
            flag=flag&&dfs(v[key][i], v, w);
        }else{
            flag=flag&&(w[key]!=w[v[key][i]]);
        }
    }
    return flag;
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<int>> g(N+1);
    for(ll i=0; i<M; ++i){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> bw(N+1, -1);
    bw[1]=0;
    if(dfs(1, g, bw)){
        ll W=0;
        for(ll i=1; i<=N; ++i) W += bw[i];
        cout << W*(N-W)-M << endl;
    }else{
        cout << N*(N-1)/2-M << endl;
    }
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-------------------------------------------------


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

    int n;
	cin >> n;
	if (n % 4 == 0 || n % 7 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	REP(i, n / 4) {
		if ((n - i * 4) % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		} 
	}
	cout << "No" << endl;

    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<algorithm>
#include<cstdio>

using namespace std;

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

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};

const D EPS = 1e-8;

int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
  bool operator<(L a, L b) {return !near(a.a, b.a) ? a.a < b.a : a.b < b.b;}
}

D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

P vec(L a) {return a.b - a.a;}

enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(P a, P b, P c) {
  if (near(a, c) || near(b, c)) return ON;
  int s = sig(det(b - a, c - a));
  if (s) return s > 0 ? LEFT : RIGHT;
  return (a < b) == (b < c) ? FRONT : (c < a) == (a < b) ? BACK : ON;
}

bool iSS(L a, L b) {
  int cwa = ccw(a.a, a.b, b.a) | ccw(a.a, a.b, b.b);
  int cwb = ccw(b.a, b.b, a.a) | ccw(b.a, b.b, a.b);
  return ((cwa | cwb) & ON) || ((cwa & cwb) == (LEFT | RIGHT));
}

D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}
D dSS(L a, L b) {return iSS(a, b) ? 0 : min(min(dSP(a, b.a), dSP(a, b.b)), min(dSP(b, a.a), dSP(b, a.b)));}

int main() {
  int n;
  cin >> n;
  if (n > 10000) {
    cout << 0 << endl;
    return 0;
  }
  L s[n];
  rep (i, n) {
    D x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    s[i] = (L){P(x1, y1), P(x2, y2)};
    if (x1 > x2) swap(s[i].a, s[i].b);
  }
  sort(s, s + n);
  D res = 1e9;
  rep (i, n) for (int j = i - 1; j >= 0; --j) {
    if (sig(s[i].a.X - res, s[j].b.X) > 0) continue;
    res = min(res, dSS(s[i], s[j]));
  }
  printf("%.12Lf\n", res);
}

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

#define ll long long
#define vi vector<int>
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
    ll n;
    cin >> n;
    vi a(n);
    int maxi=0,maxj=0;
    REP(i,n){
        cin >> a[i];
        if(maxi<=a[i]){
            maxj=maxi;
            maxi=a[i];
        }
        else{
            maxj=max(maxj,a[i]);
        }
    }

    REP(i,n){
        if(maxi==a[i]){
            cout << maxj << endl;
        }
        else{
            cout << maxi << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
N = int(input())
alist = [int(i) for i in input().split()]
bestcost = 1000000000
besti = 1000000
for i in range(min(alist),max(alist)+1):
    cost = sum([(a-i)**2 for a in alist])
    if cost < bestcost:
        bestcost = cost
        besti = i

print(bestcost)


Measured memory_bytes: 2940
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t H, W, K;
  cin >> H >> W >> K;
  vector<vector<bool>> is_black(H, vector<bool>(W, false));
  // int64_t num_blk = 0;
  for (int64_t r = 0; r < H; ++r) {
    string s;
    cin >> s;
    for (int64_t c = 0; c < W; ++c) {
      if (s[c] == '#') {
        is_black[r][c] = true;
        // ++num_blk;
      }
    }
  }

  int64_t result = 0;
  for (int64_t b = 0; b < (1 << (H + W)); ++b) {
    vector<vector<bool>> remaining = is_black;
    bitset<12> bs(b);
    for (int64_t r = 0; r < H; ++r) {
      if (bs[r]) {
        for (int64_t c = 0; c < W; ++c) {
          remaining[r][c] = false;
        }
      }
    }
    for (int64_t c = 0; c < W; ++c) {
      if (bs[H + c]) {
        for (int64_t r = 0; r < H; ++r) {
          remaining[r][c] = false;
        }
      }
    }

    auto Count = [&]() -> int64_t {
      int64_t cnt = 0;
      for (int64_t r = 0; r < H; ++r) {
        for (int64_t c = 0; c < W; ++c) {
          if (remaining[r][c]) {
            ++cnt;
          }
        }
      }
      return cnt;
    };
    if (Count() == K) {
      ++result;
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>

using namespace std;

void Main()
{
    int N;
    cin >> N;
    vector<int> d(N, 0);
    for (int i = 0; i < N; i++) {
        int di;
        cin >> di;
        d[i] = di;
    }

    int result = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int k = i + 1; k < N; k++) {
            result += d[i] * d[k];
        }
    }
    cout << result;
}

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


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

ll dp[1 << 16], cost[1 << 16], mat[16][16];

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> mat[i][j];
        }
    }
    for(int msk = 1; msk < (1 << n); msk++) {
        int b = 31 - __builtin_clz(msk);
        cost[msk] = cost[msk ^ (1 << b)];
        for(int k = 0; k < b; k++) {
            if(msk & (1 << k))
                cost[msk] += mat[b][k];
        }
    }
    for(int msk = 1; msk < (1 << n); msk++) {
        for(int sm = msk; sm; sm = (sm - 1) & msk) {
            dp[msk] = max(dp[msk], dp[msk ^ sm] + cost[sm]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count[] = new int[n];
        for (int i = 1;i <= 447;++i){
            if((i * i + i) / 2 == n){
                int res[][] = new int[i + 1][i];
                int field[] = new int[n];
                for (int j = 0;j < n;++j){
                    field[j] = -1;
                }
                for (int j = 0;j < i;++j){
                    res[0][j] = j;
                    field[j] = 0;
                    ++count[j];
                }
                for (int j = 1; j < i + 1;++j){
                    boolean ps[] = new boolean[i + 1];
                    int c = 0;
                    for (int k = 0;k < n;++k){
                        if(count[k] == 2)continue;
                        if(field[k] >= 0){
                            if(ps[field[k]])continue;
                            res[j][c] = k;
                            ps[field[k]] = true;
                            field[k] = j;
                            ++count[k];
                            ++c;
                        }
                        else{
                            res[j][c] = k;
                            field[k] = j;
                            ++count[k];
                            ++c;
                        }
                        if(c == i)break;
                    }
                }
                System.out.println("Yes");
                System.out.println(i + 1);
                StringBuilder sb = new StringBuilder();
                for (int j = 0;j < i + 1;++j){
                    sb.append(i);
                    sb.append(' ');
                    for (int k = 0;k < i;++k){
                        sb.append(res[j][k] + 1);
                        if(k + 1 != i)sb.append(' ');
                        else sb.append('\n');
                    }
                }
                System.out.println(sb);
                return;
            }
        }
        System.out.println("No");
    }




}




Measured memory_bytes: 32408
N,M = map(int,input().split())

A = list(map(lambda x: -1*int(x),input().split()))
import heapq
que = heapq.heapify(A)

for _ in range(M):
    pop_min = -heapq.heappop(A)
    heapq.heappush(A,-(pop_min//2))
   
print(-sum(A))

Measured memory_bytes: 85440
#include<stdio.h>
#include<stdlib.h>

int n,v,i;
int e[100001][3],p[10001];
int r = 0;

int arrange(const void *,const void *);
int a(int );

int main()
{
  scanf("%d%d",&n,&v);

  for(i = 0;i <= n;i ++)
    {
      p[i] = i;
    }
	
  for(i = 0;i < v;i ++)
    {
      scanf("%d%d%d",&e[i][0],&e[i][1],&e[i][2]);
    }
	
  qsort(e,v,sizeof(int[3]),arrange);

  for(i = 0;i < v;i ++)
    {
      if(a(e[i][0])!=a(e[i][1]))
	{
	  r += e[i][2];
	  p[a(e[i][0])] = p[a(e[i][1])];
	}
    }
	
  printf("%d\n",r);
  return 0;
}

int arrange(const void *x,const void *y)
{
  return ((int*)x)[2] - ((int*)y)[2];
}


int a(int x)
{
  return p[x] == x?x:a(p[x]);
}




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

int main(){
    ll n;
    cin>>n;
    int ans=0;
    if(n/1000==2)ans++;
    if((n%1000)/100==2)ans++;
    if((n%100)/10==2)ans++;
    if((n%10==2))ans++;
    cout<<ans<<endl;
}


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

  cin >> h >> w;

  if(h == 1 || w == 1){
    cout << 1;
    return 0;
  }

  cout << (h * w + 1) / 2;

  return 0; 
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI sn;
void no(){
  cout<<"No"<<endl;
  exit(0);
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  sn.resize(300,0);
  string s;
  cin>>s;
  forv(i,s)
    sn[s[i]]=1;
  if(sn['N']!=sn['S'])
    no();
  if(sn['W']!=sn['E'])
    no();
  cout<<"Yes"<<endl;
  return 0;
}


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


int main()
{
	while (true)
	{
		string cards;
		int m;
		cin >> cards;

		if (cards == "-") {
			break;
		}

		cin >> m;

		for (int i = 0;i < m;i++) {
			int h;
			cin >> h;

			cards = cards.substr(h, cards.size() - h) + cards.substr(0, h);
		}

		cout << cards << endl;
	}

    return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int ans;

void dfs(int V,int W,int L,auto &vv,auto &ww,int ind,int sz,auto &dp){
	if(L-W<0)return;
	ans = max(ans,dp[L-W] + V);
	if(ind==sz)return;
	dfs(V,W,L,vv,ww,ind+1,sz,dp);
	dfs(V+vv[ind],W+ww[ind],L,vv,ww,ind+1,sz,dp);
}

int main(){
	
	int N;
	cin>>N;
	
	vector<int> V(N),W(N);
	for(int i=0;i<N;i++)scanf("%d %d",&V[i],&W[i]);
	
	vector<vector<int>> dp(512,vector<int>(100001,-Inf));
	for(int i=0;i<=100000;i++)dp[0][i] = 0;
	for(int i=1;i<min(512,N+1);i++){
		for(int j=0;j<=100000;j++){
			dp[i][j] = max(dp[i][j],dp[i/2][j]);
			if(j!=0)dp[i][j] = max(dp[i][j],dp[i][j-1]);
			int t = j-W[i-1];
			if(t<0)continue;
			dp[i][j] = max(dp[i][j],dp[i/2][t] + V[i-1]);
		}
	}
	
	int Q;
	cin>>Q;
	vector<int> vv(18),ww(18);
	for(int i=0;i<Q;i++){
		int v,L;
		scanf("%d %d",&v,&L);
		if(v<512){
			printf("%d\n",dp[v][L]);
			continue;
		}
		int t = 0;
		while(v>=512){
			vv[t] = V[v-1];
			ww[t] = W[v-1];
			t++;
			v/=2;
		}
		ans = 0;
		dfs(0,0,L,vv,ww,0,t,dp[v]);

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


Measured memory_bytes: 206604
// verified at https://judge.yosupo.jp/submission/3400
#ifndef Union_find_hpp
#define Union_find_hpp

#include <cassert>
#include <cstddef>
#include <vector>

class union_find
{
    std::vector<int> link;

public:
    explicit union_find(const size_t n) : link(n, -1) {}

    size_t find(size_t x)
    {
        assert(x < size());
        while(link[x] >= 0)
        {
            if(link[link[x]] >= 0) link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    size_t size() const { return link.size(); }

    size_t size(const size_t x)
    {
        assert(x < size());
        return -link[find(x)];
    }

    bool same(const size_t x, const size_t y)
    {
        assert(x < size() && y < size());
        return find(x) == find(y);
    }

    size_t unite(size_t x, size_t y)
    {
        assert(x < size() && y < size());
        if((x = find(x)) != (y = find(y)))
        {
            if(link[x] > link[y]) std::swap(x, y);
            link[x] += link[y];
            link[y] = x;
        }
        return x;
    }
}; // class union_find

#endif // Union_find_hpp

#include <iostream>
#include <tuple>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);

    int n,h,w; cin>>n>>h>>w;
    vector<vector<pair<int,int>>> cards(100000);
    for(int i=n,r,c,a; i--; )
    {
        cin>>r>>c>>a; --r,--c;
        cards[a].emplace_back(r,c+h);
    }
    union_find uf(h+w);
    long long ans{};
    vector<bool> ext(h+w);
    for(int i=100000; i; --i)
    {
        for(auto&& e:cards[i])
        {
            int r,c; tie(r,c)=e;
            r=uf.find(r),c=uf.find(c);
            if(r!=c)
            {
                if(ext[r] and ext[c]) continue;
                ext[uf.unite(r,c)]=ext[r]||ext[c];
                ans+=i;
            }
            else if(!ext[r])
            {
                ext[r]=true;
                ans+=i;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5,mod=1e9+7;
typedef long long ll;
ll f[N],sumf[N],dp[N],sumdp[N];
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
int n,h,d;
int main()
{
    f[0]=1;
    for(int i=1;i<N;i++) f[i]=f[i-1]*i%mod,sumf[i]=(sumf[i-1]+f[i])%mod;
    scanf("%d%d%d",&n,&h,&d);
    dp[0]=1;sumdp[0]=1;
    for(int i=1;i<=h;i++)
    {
        if(i-d-1>=0)
        dp[i]=(sumdp[i-1]-sumdp[i-d-1])*sumf[n]%mod;
    else dp[i]=sumdp[i-1]*sumf[n]%mod;
        sumdp[i]=(sumdp[i-1]+dp[i])%mod;
    }
    ll ans=dp[h]*f[n]%mod*inv(sumf[n])%mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 31488