akhauriyash/Code-Regression huggingface dataset:
GROUPS = [ [2], [4, 6, 9, 11], [1, 3, 5, 7, 8, 10, 12] ]

def get_group(num):
  for (i, g) in enumerate(GROUPS):
    if num in g:
      return i
  return -1

(x, y) = (int(tok) for tok in input().split())
print("Yes" if get_group(x) == get_group(y) else "No")

Measured memory_bytes: 3060
#include <cstdio>

#define N 100001
int n;
int a[N],b[N];
long long int ans;

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++)
		scanf("%d %d",&a[i],&b[i]);

	for(int i=n-1; i>=0; i--){
		int t = (a[i] +ans) % b[i];
		if(t != 0)
			ans += b[i] - t;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 896
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::string s;

int main(void){
	int h,w,i,j;
	std::cin >> h >> w;
	for(i=1; i<=h; ++i){
		for(j=0; j<w; ++j){
			std::cin >> s;
			if(s=="snuke"){
				printf("%c%d\n",'A'+j,i);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>

int main(void)
{
    int num[3];
    int tmp;
    int i, j;
    
    for(i = 0; i < 3; i++){
        scanf("%d%*c", &num[i]);
    }
    for(i = 0; i < 3; i++){
        for(j = i; j < 3; j++){
            if(num[j] > num[i]){
                tmp = num[i];
                num[i] = num[j];
                num[j] = tmp;
            }
        }
    }
    printf("%d\n", num[0] * 10 + num[1] + num[2]);
    
    return 0;
}


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

const int MOD = 1e9 + 7;
vector<long long> fact, fact_inv;

long long pow_mod(long long x, long long n) {
    long long res = 1;
    while (n) {
        if (n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

long long cmb(int n, int r) {
    if (r < 0 || r > n) return 0;
    return (fact[n] * (fact_inv[r] * fact_inv[n - r] % MOD)) % MOD;
}

int main() {
    int N, K;  cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    // fact, fact_inv の前処理
    fact.resize(N + 1);
    for (int i = 0; i <= N; ++i) {
        if (i == 0) fact[i] = 1;
        else fact[i] = fact[i - 1] * i % MOD;
    }
    fact_inv.resize(N + 1);
    for (int i = N; i >= 0; --i) {
        if (i == N) fact_inv[i] = pow_mod(fact[N], MOD - 2);
        else fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
    }

    long long sum_max = 0;
    for (int i = K - 1; i < N; ++i) {
        sum_max = (sum_max + cmb(i, K - 1) * A[i] % MOD) % MOD;
    }
    long long sum_min = 0;
    for (int i = 0; i <= N - K; ++i) {
        sum_min = (sum_min + cmb(N - i - 1, K - 1) * A[i] % MOD) % MOD;
    }

    long long ans = sum_max - sum_min;
    while (ans < 0) {
        ans += MOD;
    }
    cout << ans % MOD << endl;

    // DUMP(sum_max, sum_min);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
string b;
int a;
int main() {
    cin >> a >> b;
    if(a >= b.size()) cout << b << endl;
    else if(a < b.size()){
        for(int i = 0;i < a;i++){
            cout << b.at(i);
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
from collections import*
(h,w,m),*z=[tuple(map(int,o.split()))for o in open(0)]
s=set(z)
y,x=[Counter(t).most_common()for t in zip(*z)]
a,b=y[0][1],x[0][1]
p=[i for i,v in y if v==a]
q=[i for i,v in x if v==b]
for i in p:
  for j in q:
    if(i,j)not in s:exit(print(a+b))
print(a+b-1)

Measured memory_bytes: 141404
# coding:utf-8

import math

def main():
    n = int(raw_input())
    an = map(int,raw_input().split())
    mi = min(an)
    mx = max(an)
    total = mx - mi
    an.remove(mi)
    an.remove(mx)
    for a in an:
        total += abs(a)
    print total
    if n == 2:
        print mx,mi
    else:
        for a in an:
            if a < 0:
                print mx,a
                mx = mx - a
            else:
                print mi,a
                mi = mi - a
        print mx,mi

if __name__ == "__main__":
    main()



Measured memory_bytes: 11324
sx, sy, tx, ty = gets.chomp.split(' ').map(&:to_i)

x_length = tx - sx
y_length = ty - sy

first = 'R' * x_length + 'U' * y_length
second = 'U' + 'L' * (x_length + 1) + 'D' * (y_length + 1) + 'R'
third = 'U' * y_length + 'R' * x_length
fourth = 'R' + 'D' * (y_length + 1) + 'L' * (x_length + 1) + 'U'

print("#{first + second + third + fourth}\n")

Measured memory_bytes: 1916
n = int(input())
s = ""

if n == 0:
    print("0")

while abs(n) > 0:
    if(abs(n) % 2 == 0):
        s = "0" + s
    else:
        s = "1" + s
        n -= 1
    n = n // (-2)
print(s)

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

bool flip(bool f) {
    return !f;
}

int main() {
    deque<char> q;
    string S;  cin >> S;
    for (int i = 0; i < (int)S.size(); ++i) {
        q.push_back(S[i]);
    }
    // DUMP(q);

    bool rev = false;
    int Q;  cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int t;  cin >> t;
        if (t == 1) rev = flip(rev);
        else {
            int f;  char c;  cin >> f >> c;  --f;
            if ((f & !rev) || (!f & rev)) q.push_back(c);
            else q.push_front(c);
        }
    }
    // DUMP(q);

    if (rev) {
        for (auto itr = prev(q.end()); itr != prev(q.begin()); --itr) cout << *itr;
    }
    else {
        for (auto itr = q.begin(); itr != q.end(); ++itr) cout << *itr;
    }
    cout << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

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

const int MAXY = 1001, MAXM = 21;

int sumy[MAXY];

int main()
{
    REP(MAXY)
    {
        if(i % 3 == 0) sumy[i] = 20  * 10;
        else sumy[i] = 20 * 5 + 19 * 5;
    }

    int n, y, m, d;
    while(cin >> n && n)
    {
        REP(n)
        {
            cin >> y >> m >> d;
            int ans = 0;
            for(int j = y+1;j<1000;j++)ans += sumy[j];

            if(y % 3 == 0) ans += (10 - m)  * 20;
            else ans += ( (10 - m)/2 )* 20 + ( (10-m) /2 + (10 - m)%2) * 19;

            if(y % 3 == 0 || m % 2 == 1) ans += 20 - d + 1;
            else ans += 19 - d + 1;

            cout << ans << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int N,a,b;
    cin >> N >> a >> b;

    if((a*N)>b){
        cout << b << endl;
    }
    else {
        cout << N*a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

struct unionfind {
    vector<int> d;
    unionfind(int n=0) : d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

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

    int n, m;
    cin >> n >> m;
    unionfind uf(n);

    vector<int> a(n);
    rep(i, n) cin >> a[i], a[i]--;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }
    int ans = 0;
    rep(i, n) {
        if (uf.same(i, a[i])) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int a,b,c;
cin >> a >> b >> c;

if(a == b && c!= b){
    cout << "Yes" << endl;
    return 0;
}
if(a == c && c!= b){
    cout << "Yes" << endl;
    return 0;
}
if(b == c && c!= a){
    cout << "Yes" << endl;
    return 0;
}

cout << "No" << endl;


return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<set>
using namespace std;
const int maxn=3e5+5;
set<pair<int,int> > all;
int num1[maxn],num2[maxn],arr1[maxn],arr2[maxn];
bool Less1(int a,int b)
{
    return num1[a]>num1[b];
}
bool Less2(int a,int b)
{
    return num2[a]>num2[b];
}
int main()
{
    int h,w,m;
    scanf("%d%d%d",&h,&w,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        all.insert(make_pair(x,y));
        num1[x]++; num2[y]++;
    }
    for(int i=1;i<=h;i++)
        arr1[i]=i;
    sort(arr1+1,arr1+h+1,Less1);
    for(int i=1;i<=w;i++)
        arr2[i]=i;
    sort(arr2+1,arr2+w+1,Less2);
    int maxx1=num1[arr1[1]],maxx2=num2[arr2[1]];
    for(int i=1;i<=h&&num1[arr1[i]]==maxx1;i++)
        for(int j=1;j<=w&&num2[arr2[j]]==maxx2;j++)
            if(!all.count(make_pair(arr1[i],arr2[j])))
            {
                printf("%d\n",maxx1+maxx2);
                return 0;
            }
    printf("%d\n",maxx1+maxx2-1);
    return 0;
}


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

int main(){
    int n,m;//m<=min(n,5)
    cin >> n >> m;

    int ans = 0;

    int step = 1900 * m + (n-m) * 100;

    cout << step * pow(2,m) << endl;
}   


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main() {
  	int k; cin >> k;
	cout << 360/  __gcd(360,k) << endl;
}


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

struct edge{int to,cost;};

int N,M,r;
vector<edge>G[1000];

int main(){
    cin>>N>>M>>r;
    for(int i=0;i<M;i++){
        int s,t,d;
        cin>>s>>t>>d;
        G[s].push_back((edge){t,d});
    }

    int dist[1000];
    fill_n(dist,N,1e9);
    dist[r]=0;
    for(int i=0;;i++){
        bool update=false;
        for(int j=0;j<N;j++)if(dist[j]!=1e9)for(int k=0;k<G[j].size();k++){
            edge &e=G[j][k];
            if(dist[e.to]>dist[j]+e.cost){
                update=true;
                dist[e.to]=dist[j]+e.cost;
            }
        }

        if(!update)break;
        if(i>=N){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }

    }

    for(int i=0;i<N;i++){
        if(dist[i]==1e9)cout<<"INF"<<endl;
        else cout<<dist[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
void solve() {
	var(int, c);
	if (c == 1) {
		print("Hello World");
		return;
	}
	var(int, a, b);
	print(a + b);
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = s.nextInt(), w = s.nextInt();

		int[][] item = new int[n + 1][2];

		for (int i = 1; i <= n; i++) {
			item[i][0] = s.nextInt();// ??????

			item[i][1] = s.nextInt();// ??????
		}

		int[][] dp = new int[n + 1][w + 1];

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

		}

		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= w; j++) {
				if (item[i][1] <= j) {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - item[i][1]] + item[i][0]);
				} else {
					dp[i][j] = dp[i - 1][j];
				}
			}
		}
		int ans = 0;
		for (int i = 0; i <= w; i++) {
			ans = Math.max(ans, dp[n][i]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 31216
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, i;
	scanf("%d", &n);
	double a[n], k=0.0, ans;

	rep(i,n){
		scanf("%lf", &a[i]);
		k += 1.0/a[i];
	}
	ans = 1.0/k;
	printf("%.10f", ans);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using namespace std;

void SolveA()
{
	int n, cnt = 0;
	scanf("%d", &n);

	while (n >= 3)
	{
		n = n - 3;
		cnt++;
	}

	printf("%d\n", cnt);
}

void SolveB()
{
	int n;
	scanf("%d", &n);

	string s = "";
	for (int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		s.append(str);
	}
	

	bool isPink = false;

	if (s.find('Y') != string::npos)
	{
		isPink = true;
	}

	if (isPink)
	{
		printf("Four\n");
	}
	else
	{
		printf("Three\n");
	}
}

void SolveC()
{
	long long int n;
	cin >> n;

	vector<string> strs;
	for (long long int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		strs.push_back(str);
	}
}

void SolveD()
{
	int H, W, D;
	scanf("%d %d %d", &H, &W, &D);
	
	int posx[90001], posy[90001];
	
	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W; w++)
		{
			int A;
			scanf("%d", &A);
			posx[A] = w + 1;
			posy[A] = h + 1;
		}
	}

	vector<int> d;
	d.resize(90001, 0);

	// 累積和の導出
	for (int i = D + 1; i <= H * W; i++)
	{
		d[i] = d[i - D] + abs(posx[i] - posx[i - D]) + abs(posy[i] - posy[i - D]);
	}

	int Q;
	scanf("%d", &Q);

	while (Q--)
	{
		int L, R;
		scanf("%d %d", &L, &R);
		printf("%d\n", d[R] - d[L]);
	}
}

long long int c[5];
void EditSolveC()
{
	long long int N;
	cin >> N;

	for (long long int i = 0; i < N; i++)
	{
		string s;
		cin >> s;

		if (s[0] == 'M') c[0]++;
		if (s[0] == 'A') c[1]++;
		if (s[0] == 'R') c[2]++;
		if (s[0] == 'C') c[3]++;
		if (s[0] == 'H') c[4]++;
	}

	long long int ans = 0;
	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 5; j++)
		{
			for (int k = j + 1; k < 5; k++)
			{
				ans += c[i] * c[j] * c[k];
			}
		}
	}

	cout << ans << endl;
}

int main()
{
	//SolveA();
	//SolveB();
	//SolveC();
	//SolveD();

	EditSolveC();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;



int main() {
  int N,x; cin >> N >> x;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  
  sort(a.begin(),a.end());
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (x >= a[i]) {
      x -= a[i];
      count++;
    } else x = 0;
  }
  
  if (x > 0) count--;
  
  cout << count << endl;
}

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

constexpr int MAX = 500100;

int gSize;
int gHeap[MAX];

int GetLeft( int i ){
  return i * 2 + 1;
}

int GetRight( int i ){
  return i * 2 + 2;
}

void MaxHeapify( int i ){
  int l = GetLeft( i );
  int r = GetRight( i );
  int largest = 0;

  if( l < gSize && gHeap[l] > gHeap[i] ){
    largest = l;
  }else{
    largest = i;
  }

  if( r < gSize && gHeap[r] > gHeap[largest] ){
    largest = r;
  }

  if( largest != i ){
    swap( gHeap[largest], gHeap[i] );
    MaxHeapify( largest );
  }
}


void BuildMaxHeap(){
  for( int i = ( gSize - 2 ) / 2; i >= 0; i-- ){
    MaxHeapify( i );
  }
}

int main(){
  cin >> gSize;
  for( int i = 0; i < gSize; i++ ) cin >> gHeap[i];

  BuildMaxHeap();

  for( int i = 0; i < gSize; i++ ){
    cout << " " << gHeap[i];
  }
  cout << endl;
}



Measured memory_bytes: 4956
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX 100
#define INFTY INT_MAX
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];
int prim();
int main(){
  int i,j;
  int e;
  scanf("%d",&n);
  if(n < 1 || n > 100)
    exit(1);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d",&e);
      if(e == -1)
	M[i][j] = INFTY;
      else
	M[i][j] = e;
    }
  }

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

  return 0;
}

int prim(){
  int i, j;
  int u, minv, sum = 0;
  int d[MAX], p[MAX], color[MAX];

  for(i = 0; i < n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    
    if(u == -1)
      break;
    
    color[u] = BLACK;
    
    for(j = 0; j< n; j++){
      if(color[j] != BLACK && M[u][j] != INFTY){
	if(d[j] > M[u][j]){
	  d[j] = M[u][j];
	  p[j] = u;
	  color[j] = GRAY;
	}
      }
    }    
  }

  for(i = 0; i < n; i++){
    if(p[i] != -1)
      sum += M[i][p[i]];
  }

  return sum;  
}



Measured memory_bytes: 2112
# 今日の曜日を表す文字列 Sが与えられます。
# Sは SUN,MON,TUE,WED,THU,FRI,SAT のいずれかであり、
# それぞれ日曜日、月曜日、火曜日、水曜日、木曜日、金曜日、土曜日を表します。
# 次の日曜日 (あす以降) が何日後か求めてください。

# 標準入力から曜日（S）を取得する
input_weekday = input()

# 次の日曜日はあと何日後かを計算して出力する
result = 0
if input_weekday == 'SUN':
    result = 7
elif input_weekday == 'MON':
    result = 6
elif input_weekday == 'TUE':
    result = 5
elif input_weekday == 'WED':
    result = 4
elif input_weekday == 'THU':
    result = 3
elif input_weekday == 'FRI':
    result = 2
elif input_weekday == 'SAT':
    result = 1

print(result)


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

cnt = 0

for i in range(n-1):
    if a[i]+a[i+1]<=x:
        pass
    else:
        if (a[i+1]+a[i])-x > a[i+1]:
            cnt += (a[i+1]+a[i])-x
            a[i+1] = 0

        else:
            cnt += (a[i+1]+a[i])-x
            a[i+1] -= (a[i+1]+a[i])-x

print(cnt)


Measured memory_bytes: 63856
#include <bits/stdc++.h>
#define ll long long
#define mod (ll)(1e9+7)
#define inf (ll)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define prique priority_queue
using namespace std;
typedef pair<ll,ll> P;
signed main(){
	string s;
	cin>>s;
	if(s=="Sunny")puts("Cloudy");
	else if(s=="Cloudy")puts("Rainy");
	else puts("Sunny");
}


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

using namespace std;

using int64 = long long;

constexpr int64 MOD = 1e9 + 7;

template<typename T> void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

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

  int n; fastin(n);
  vector<int64> a(n);
  for (int i = 0; i < n; ++i) fastin(a[i]);

  bool dp[n][61];

  for (int i = 0; i < n; ++i) {
    bitset<61> bs(a[i]);
    for (int j = 0; j < 61; ++j) {
      dp[i][j] = bs.test(j);
    }
  }

  int64 dp2[n][61];

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 61; ++j) {
      if (i == 0) {
        dp2[i][j] = dp[i][j];
      } else {
        dp2[i][j] = dp[i][j] + dp2[i - 1][j];
      }
    }
  }

  int64 ans = 0;

  for (int i = 1; i < n; ++i) {
    bitset<61> bs(a[i]);
    for (int j = 0; j < 61; ++j) {
      if (bs.test(j)) {
        ans += (1LL << j) % MOD * (i - dp2[i - 1][j]) % MOD;
      } else {
        ans += (1LL << j) % MOD * dp2[i - 1][j] % MOD;
      }
    }
  }

  ans %= MOD;

  printf("%lld", ans);

  return 0;
}


Measured memory_bytes: 163456
#include <bits/stdc++.h>
#define mmp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
const int MN = 100100;
const ll INFL = 1LL<<61;
typedef vector<ll> vl;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
bitset<MN> bs;
vpl st[MN];
vl ed[MN];
typedef vector<pl> vpl;
ll res[MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	priority_queue<pl,vector<pl>,greater<pl> > pq;
	ll n,m;
	cin >> n >> m;
	fill(res,res+n,INFL);
	for(int i=0;i<m;i++) {
		ll a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		st[a].push_back(mmp(i,c));
		ed[b+1].push_back(i);
	}
	pq.push({INFL,m});
	res[0] = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<ed[i].size();j++) {
			bs.set(ed[i][j]);
		}
		while(bs[pq.top().second]) {
			pq.pop();
		}
		res[i] = min(res[i],pq.top().first);
		for(int j=0;j<st[i].size();j++) {
			ll id = st[i][j].first,co = st[i][j].second;
			ll psh = min(co+res[i],INFL);
			pq.push(mmp(psh,id));
		}
	}
	if(res[n-1] == INFL) {
		cout << -1 << '\n';
	} else {
		cout << res[n-1] << '\n';
	}
}


Measured memory_bytes: 12280
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	string s = ReadLine();

	int ans = 0;
	char curr = '\0';

	for (int i = 0; i < n; i++)
	{
	    char c = s[i];
	    if (curr != c)
	    {
		ans++;
		curr = c;
	    }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 11232
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 1;
        for (int i = 1; i <= n; i++) {
            ans = ans * i % 1000000007;
        }
        System.out.println(ans);

    }
}

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

int main(){
  int n, t, a;
  cin >> n;
  ll ans1 = 1, ans2 = 1;
  for(int i=0; i<n; ++i){
    cin >> t >> a;
    if(ans1 /t > ans2 /a){
      if(ans1 %t == 0){
        ans2 = ans1 /t *a;
      }else{
        ans1 = (ans1 /t +1) *t;
        ans2 = ans1 /t *a;
      }
    }else if(ans1 /t == ans2 /a){
      if(ans1 %t == 0 && ans2 %a == 0) continue;
      ans1 = (ans1 /t +1) *t;
      ans2 = ans1 /t *a;
    }else{
      if(ans2 %a == 0){
        ans1 = ans2 /a *t;
      }else{
        ans2 = (ans2 /a +1) *a;
        ans1 = ans2 /a *t;
      }
    }
    //cout << "i:" << i << " r:" << ans1 << " l:" << ans2 << endl;
  }
  cout << ans1 + ans2 << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

bool compare_pair(pair<ll, ll> a, pair<ll, ll> b){
    if(a.first == b.first){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> req(m);
    rep(i, m)cin >> req[i].first >> req[i].second;

    sort(ALL(req), compare_pair);

    ll amos = 0;
    ll bmos = 1000000;
    ll ans = 1;
    ll now = 0;
    rep(i, m){
        while(req[i].first == now)i++;
        now = req[i].first;
        // cout << req[i].first << "->" << req[i].second << endl;
        // cout << amos << "&" << bmos << endl;
        if(bmos > req[i].first){
            amos = max(amos, req[i].first);
            bmos = min(bmos, req[i].second);
        }
        else {
            ans++;
            amos = req[i].first;
            bmos = req[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
n = int(input())
s = input()

ans = 0

for i in range(n):
    one = s[0:i]
    other = s[i:]
    now = 0
    one = set(one)

    for j in one:
        for k in other:
            if j == k:
                now += 1
                break

    ans = max(now, ans)

print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

bool ask(const int &a, const int &b) {
    char c;
    cout << "? " << a << " " << b << endl;
    cin >> c;
    return c == 'Y';
}

void nxt(int &a, const int &M) { a = (a + 1) % M; }

vector<bool> solve(int A, int B) {
    vector<int> vec;
    int N = A + B;
    rep(i, N) {
        if(vec.empty()) {
            vec.push_back(i);
            continue;
        }
        if(ask(i, vec.back()))
            vec.push_back(i);
        else {
            vec.pop_back();
            B--;
        }
        if(vec.size() > B) break;
    }
    int Honest = vec.front();
    vector<bool> ret(N);
    rep(i, N) {
        if(i == Honest)
            ret[i] = true;
        else
            ret[i] = ask(Honest, i);
    }
    return ret;
}

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

    int A, B;
    cin >> A >> B;
    if(A <= B) {
        cout << "Impossible" << endl;
        return 0;
    }

    vector<bool> ans = solve(A, B);
    cout << "! ";
    for(bool b : ans)
        cout << b;
    cout << endl;

    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define all(v) v.begin(),v.end()
# define pl(s)  std::cout << s << endl;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1e9+7;

void addM(ll & a, ll b){
    a = (a+b) % MOD;
}

// numを二進数化した時に2^nのビットがonであるかを判定する
bool is_nth_bit_on(int num, int n){
    return (num >> n) & 1;
}

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    // dp[i][j]:1:1からi：j（i行目のj列目）に移動する場合の数
    auto dp = make_vec<ll>(101,8);

    // i本目から次行のj本目に移動する場合の数
    auto num = make_vec<ll>(8,8);

    // あみだクジの場合の数を事前準備
    REP(b,1<<(W-1)){
        // 隣合うビットが立っていないかの確認
        bool ok = true;
        REP(i,W-2){
            if(is_nth_bit_on(b, i) && is_nth_bit_on(b, i+1)){
                ok = false;
                break;
            }
        }
        if(!ok) continue;

        vector<int> P(W);iota(all(P),0);

        // i番目のフラグがONである＝その橋を渡って、i番目とi+1番目が次行で入れ替わる
        // i番目のフラグがOFFである＝i番目はそのまま次行に行く
        REP(i,W-1) if(is_nth_bit_on(b, i)) swap(P[i], P[i+1]);

        // 算出結果を数え上げていく
        REP(i,W) addM(num[i][P[i]],1);
    }

    // DP実行
    dp[0][0] = 1;
    REP(i,H) REP(j,W) {
        // そのまま次行に遷移
        addM(dp[i+1][j], dp[i][j] % MOD * num[j][j] % MOD);
        // 右のくじに移動して、次行に遷移
        if(j+1<W)  addM(dp[i+1][j+1], dp[i][j] % MOD * num[j][j+1] % MOD);
        // 左のくじに移動して、次行に遷移
        if(j-1>=0) addM(dp[i+1][j-1], dp[i][j] % MOD * num[j][j-1] % MOD);
    }

    pl(dp[H][K-1]);
    return 0;
}

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

using i64 = int64_t;

int main(){
    i64 n;
    cin >> n;
    if(n%2)cout << 0;
    else{
        i64 ans = 0, tmp = 5;
        while(tmp <= n){
            ans += (n / (tmp * 2));
            tmp *= 5;
        }
        cout << ans;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    # サイコロの出た目が1から考えてみる?
    #    i = 1
    #cnt = 0
    #while i < k:
    #    cnt += 1
    #    i *= 2
    # これじゃだめ 最大から -1...じゃなくて
    # 1から...のほうがいい
    # 逆に少ない方から考える
    # 1から
    ans = 0
    for i in range(1,n+1):
        # 何回かけれるか
        a = 1
        m = i
        while m < k:
            m *= 2
            a *= (1/2)
        ans += a
    ans /= n
    print("%.12f"%(ans))
if __name__ == '__main__':
  main()


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

using namespace std;

const int MAXN  = 1e5+5;
int pref[MAXN];
int pref2[MAXN];
int check(int x,int y){
    if(x==0){
        return pref[y]%3;
    }
    return (pref[y]-pref[x-1])%3;
}

int check2(int x,int y){
    if(x==0){
        return pref2[y]%3;
    }
    return (pref2[y]-pref2[x-1])%3;
}
int main(){
    string s,t;
    cin>>s>>t;
    int q;
    cin>>q;
    if(s[0] == 'A'){
        pref[0] = 1;
    }else{
        pref[0] = 2;
    }
    for(int i=1;i<s.length();i++){
        if(s[i] == 'A'){
            pref[i] = pref[i-1]+1;
        }else{
            pref[i]  =pref[i-1]+2;
        }
    }
    if(t[0] == 'A'){
        pref2[0] = 1;
    }else{
        pref2[0] = 2;
    }
    for(int i=1;i<t.length();i++){
        if(t[i] == 'A'){
            pref2[i] = pref2[i-1]+1;
        }else{
            pref2[i] = pref2[i-1]+2;
        }
        //cout<<pref2[i]<<endl;
    }
    while(q--){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--;
        b--;
        c--;
        d--;
        int val1 = check(a,b);
        int val2 = check2(c,d);
       
        if(val1 == val2){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=2e5+51,MOD=998244353;
ll length;
ll pw[MAXN],prefix[MAXN],suffix[MAXN];
char s[MAXN],t[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
int main()
{
	length=read(),scanf("%s%s",s,t),pw[0]=1,prefix[0]=t[0]-'a';
	for(register int i=1;i<length;i++)
	{
		pw[i]=(li)pw[i-1]*26%MOD;
		prefix[i]=(t[i]-'a'+(li)prefix[i-1]*26%MOD)%MOD;
	}
	for(register int i=length-1,j=0;i>=0;i--,j++)
	{
		suffix[i]=(suffix[i+1]+(li)pw[j]*(s[i]-'a')%MOD)%MOD;
	}
	for(register int i=0,j=length-1;i<length;i++,j--)
	{
		if(suffix[i]==prefix[j])
		{
			return printf("%d\n",(length<<1)-j-1),0;
		}
	}
	printf("%d\n",length<<1);
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n;
    vector<int> v;
    cin >> n;

    int tmp;
    REP(i, n) {
        cin >> tmp;
        v.push_back(tmp);
    }
    vector<int> rev_ordered_v = v;
    sort(rev_ordered_v.begin(), rev_ordered_v.end(), greater<int>());
    int r1 = 0;
    int mxc = 0;
    int r2 = 0;
    for (auto e : rev_ordered_v) {
        if (r1 == 0) {
            r1 = e;
            mxc++;
        } else if ((r1 != 0) && (e == r1)) {
            mxc++;
        } else if ((r1 != 0) && (r2 == 0) && (e != r1)) {
            r2 = e;
        } else {
            break;
        }
    }
    for (auto e : v) {
        if ((e == r1) && (mxc > 1)) {
            cout << r1 << endl;
        } else if ((e == r1) && (mxc == 1)) {
            cout << r2 << endl;
        } else {
            cout << r1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

void solve(long long N, long long Z, long long W, std::vector<long long> a){
    if(N==1){
        cout << abs(W-a[N-1]) << endl;
        return;
    }
    cout << max(abs(a[N-1]-a[N-2]),abs(W-a[N-1])) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long Z;
    scanf("%lld",&Z);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, Z, W, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000000000000
#define test int t; cin>>t;
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()

using namespace std;

ll nxt(){
    ll x;
    cin>>x;
    return x;
}

ll it;

void dfs(int i, int j){
    it++;
    if(i+1<3000) dfs(i+1,j);
    if(j+1<3000) dfs(i,j+1);
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS

    ll n = nxt(), k = nxt();
    vector<ll>p(n),c(n);
    generate(all(p),nxt);
    generate(all(c),nxt);

    vector<bool> visited(n,0);
    vector<vector<ll>>groups;
    ll res = LLONG_MIN;
    for(int i = 0; i<n; i++){
        if(!visited[i]){
            visited[i] = true;
            vector<ll> g;
            int j = i;
            while(!visited[p[j]-1]){
                j = p[j]-1;
                visited[j] = true;
                g.pb(c[j]);
            }
            g.pb(c[i]);
            groups.pb(g);
        }
    }

    for(vector<ll> g: groups){
        ll m = g.size();
        if(m>k){
            for(int i = 0; i<m; i++){
                ll kk=k;
                int j=i;
                ll tmp = 0;
                while(kk--){
                    tmp+=g[j%m];
                    j++;
                    res = max(res,tmp);
                }
            }
        }
        else{
            for(int i = 0; i<m; i++){
                ll kk=m;
                int j=i;
                ll tmp = 0;
                while(kk--){
                    tmp+=g[j%m];
                    j++;
                    res = max(res,tmp);
                }
            }

            ll tot = 0;
            for(int i = 0; i<m; i++){
                tot+=g[i];
                res = max(res,tot);
            }

            if(k/m>1){
                ll ttot = max(tot, (k/m-1)*tot);
                for(int i = 0; i<m; i++){
                    ll kk=m;
                    int j=i;
                    ll tmp = 0;
                    while(kk--){
                        tmp+=g[j%m];
                        j++;
                        res = max(res,tmp);
                        res = max(res, ttot+tmp);
                    }
                }
            }

            tot = max(tot,(k/m)*tot);
            res = max(res,tot);
            ll rem = k%m;
            for(int i = 0; i<m; i++){
                ll kk=rem;
                int j=i;
                ll tmp = 0;
                while(kk--){
                    tmp+=g[j%m];
                    j++;
                    res = max(res,tmp);
                    res = max(res, tot+tmp);
                }
            }
        }
    }
    
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)
 
int main(void) {
  int n,m,ans=0;
  cin>>n>>m;

  vector<vector<int>> s(m);
  
  rep(i,0,m){
    int cnt;
    cin>>cnt;
    s[i].resize(cnt);
    rep(j,0,cnt){
      cin>>s[i][j];
      s[i][j]--;
    }
  }
  
  vector<int> lis(m);
  rep(i,0,m){cin>>lis[i];}
  
  for(int i=0;i<(1<<n);i++){
    bool ok=true;
    rep(j,0,m){
      int cnt=0;
      for(int id : s[j]){
        if((i>>id)&1){
          cnt++;
        }
      }
      cnt=cnt%2;
      if(cnt!=lis[j]){ok=false;}
    }
    if(ok==true){ans++;}
  }
  
  cout<<ans<<endl;
  
  return 0;
}

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

typedef long long ll;

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    ll a, b, x;
    cin >> a >> b >> x;

    if (a) cout << b/x - (a-1)/x << endl;
    else cout << b/x + 1 << endl;
    
}


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

using namespace std;

int main()
{
    int n;
    while( cin >> n ) {
        if ( n == 0 )
            break;

        int y;
        cin >> y;

        double m = 0.0;
        int bb = -1;
        for( int iii=0; iii<n; ++iii ) {
            int b, r, t;
            cin >> b >> r >> t;

            double const v = 
                ( t == 1 )
                ? ( 10000.0 * ( 1.0 + static_cast<double>( y ) * ( static_cast<double>( r ) / 100.0 ) ) )
                : ( 10000.0 * pow( 1.0 + ( static_cast<double>( r ) / 100.0 ), y ) );
            
            if ( v > m ) {
                m = v;
                bb = b;
            }
        }
        
        cout << bb << endl;

    }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, p;
  string s;
  cin >> s;
  n = s.size(), p = 2019;
  if (10%p == 0) {
    ll ans = 0;
    rep(r,n) {
      if ((s[r]-'0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
 
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int main(){
	int n, l;
  cin >> n >> l;
  int a[n];
  int sum = 0;
  for(int i=1;i<=n;i++) {
    a[i] = l+i-1; 
    sum += a[i];
//    cout << a[i] << " ";
  }
//  cout << endl;
//  cout << sum << endl;

  int min = abs(a[1]);
  for(int i=2;i<=n;i++) {
    if(min > abs(a[i])) min = abs(a[i]);
  }
  if(a[1] < 0) min = -min;
  cout << sum - min << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0;i<N;i++){
    cin >> v[i];
  }
  int index = distance(v.begin(),max_element(v.begin(),v.end()));
  v[index] = v[index] / 2;
  
  cout << accumulate(v.begin(), v.end(), 0) << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scan(&a, &b, &c, &x)

	ans := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if 500*i+100*j+50*k == x {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
    return (x&(-x));
}
void solve(){
    int n; cin>>n;
    vl a(n); bhar(a);
    map<ll,ll> m;
    rep(i,n) m[a[i]]++;
    ll ans=0;
    for(auto x:m){
        ans+=x.S*(x.S-1)/2;
    }
    ll tmp=ans;
    rep(i,n){
        ans-=(m[a[i]]*(m[a[i]]-1)/2);
        ans+=(m[a[i]]-1)*(m[a[i]]-2)/2;
        cout<<ans<<endl;
        ans=tmp;
    }
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
        solve();
    }
}

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

int main() {
  int n, h, w;
  cin >> n >> h >> w;

  int ans = 0;
  for(int i=0;i<n;i++) {
    int a, b;
    cin >> a >> b;

    if(a >= h && b >= w) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;
using Polygon=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

enum {
    ONLINE_FRONT=-2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK,
};

int ccwise(Point a, Point b, Point c) {
    b -= a; c -= a;

    if (cross_prod(b, c) > 0) {
        return COUNTER_CLOCKWISE;
    } else if (cross_prod(b, c) < 0) {
        return CLOCKWISE;
    } else if (dot_prod(b, c) < 0) {
        return ONLINE_BACK;
    } else if (norm(b) < norm(c)) {
        return ONLINE_FRONT;
    } else {
        return ON_SEGMENT;
    }
}

enum {
    OUT_OF_LINE,
    ON_LINE,
    IN_LINE,
};

int contains(const Polygon &g, const Point &p) {
    bool in=false;
    size_t V=g.size();
    for (size_t i=0; i<V; ++i) {
        Point a=g[i]-p, b=g[(i+1)%V]-p;
        if (imag(a) > imag(b)) swap(a, b);
        if ((imag(a) <= 0) && (imag(b) > 0) && (cross_prod(a, b) < 0))
            in = !in;

        if (abs(cross_prod(a, b)) < EPS && dot_prod(a, b) <= EPS)
            return ON_LINE;
    }
    return in? IN_LINE : OUT_OF_LINE;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Polygon g(n);
    for (size_t i=0; i<n; ++i) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        g[i] = Point(x, y);
    }

    size_t q;
    scanf("%zu", &q);

    for (size_t i=0; i<q; ++i) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        Point p(x, y);

        printf("%d\n", contains(g, p));
    }
    return 0;
}

Measured memory_bytes: 2748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    int x;
    cin>>x;
    if(x==0) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3628