akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define H 500001

int id;
int a[H];

void maxHeapify(int i){
  int l, r, x, largest;
  l = i*2;
  r = i*2+1;
  if(l <= id && a[l] > a[i]){
    largest = l;
  }else{
    largest = i;
  }
  if(r <= id && a[r] > a[largest]){
    largest = r;
  }

  if(largest != i){
    x = a[i];
    a[i] = a[largest];
    a[largest] = x;
    maxHeapify(largest);
  }
}


int main(){
  int i;

  scanf("%d", &id);

  for(i = 1; i <= id; i++){
    scanf("%d", &a[i]);
  }

  for(i = id/2; i >= 1; i--){
    maxHeapify(i);
  }
  

  for(i = 1; i <= id; i++){
    printf(" %d", a[i]);
  }
  printf("\n");

  return 0;
}



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

int main(void)
{
    int n,i;
    long a,t[200000],m=LONG_MAX;
    scanf("%ld",&n);
    for(i=0;i<n;i++){
        scanf("%ld",&a);
        t[i]=a;
        if(0<i)t[i]+=t[i-1];
    }
    for(i=0;i<n-1;i++)if(m>labs(2*t[i]-t[n-1]))m=labs(2*t[i]-t[n-1]);
    printf("%ld",m);
    return 0;
}

Measured memory_bytes: 1664
/*

ÂÃÂÃ¨ÂÂ ÂÂ¦ÂÂ¸ÂAÂeÂmÂ[ÂhÂÂ©ÂÃ§ÂÃÂÃ±ÂÃÂÂÂ[ÂÂÂÃÂÃÂÃÂÂÂÂ£ÂÃ°ÂÂÂÃÂÃÂÂ¨ÂÂ¢ÂÂ½ÂÃ»ÂÂªÂÃ¦ÂÂ³ÂÂ»ÂÂ¤ÂB
  - Â_ÂCÂNÂXÂgÂÂÂ@
  - O(E log V)ÂÃÂÃÂÂ«ÂÃ©
  - O(VE log V)ÂÃ°ÂÃ¢ÂÃ©ÂKÂvÂÃÂÂ¢ÂiÂÂ±ÂÂ±ÂÃÂlÂÃ±ÂÂ¾Âj
  - dist[3002]ÂÃÂiÂ[

ÂmÂ[ÂhAÂÃÂmÂ[ÂhBÂÃ°ÂÃÂÃÂÂ®ÂGÂbÂWÂÃÂÃ£ÂÃÂÃÂÃ°ÂÂÂÃÂÃ©ÂÃÂÂ¼ÂÃ¨ÂÂ·ÂÃ©
  - ÂÂ±ÂÃÂÃÂÂ«ÂAÂGÂbÂWÂÃÂÃÂÃÂÃÂuÂÃÂÃÂÃ°ÂÂÂÃÂÃªÂÃÂÃªÂÃÂÂÂÂ£ÂÂªÂÃÂÃ¥ÂÃÂÃÂÃ©ÂÂ©ÂÃ°ÂlÂÂ¦ÂÃ©
  - ÂÂ»ÂÃÂÃÂuÂÃÂAÂmÂ[ÂhAÂÃ°ÂÃÂÃÂÃÂÃ ÂAÂmÂ[ÂhBÂÃ°ÂÃÂÃÂÃÂÃ ÂAÂÂ¯ÂÂ¶ÂÂÂÂ£ÂÃÂÃÂÃ±ÂÃÂÂÂ[ÂÂÂÃÂÃÂsÂÂ¯ÂÃ©ÂÃÂuÂÃÂÃÂÃ©
  - ÂÃ¦ÂÃÂÃÂAÂGÂbÂWÂÃÂÂ·ÂÂ³ÂÂªLÂÃÂÂ·ÂÃ©ÂÃÂAÂÃÂÃ°ÂÂÂÃÂÃ©ÂÃÂuÂÃÂA
  -- ÂmÂ[ÂhBÂÂ©ÂÃ§ (dist[A] - dist[B] + L) / 2 ÂÂ£ÂÃªÂÂ½ÂÃÂuÂÃÂÃÂÃ©
  -- ÂÂ½ÂÂ¾ÂÂµÂAdist[A] > dist[B]ÂÃÂÂ ÂÃ©

  - Â]ÂÃÂÃÂAÂÂ±ÂÃÂÃÂÂ«ÂÃÂÃÂÃ±ÂÃÂÂÂ[ÂÂÂÃÂÃÂÃÂÂÂÂ£ÂÃ
  -- dist[B] + (dist[A] - dist[B] + L) / 2

ÂÂ ÂÃÂÃÂAÂÂ±ÂÃªÂÃ°ÂSÂÃÂÃÂGÂbÂWÂÃÂÃÂÂ¢ÂÃÂvÂZÂÂµÂAÂÂ»ÂÃÂÃÂÃ¥ÂlÂÃ°ÂÃÂÃªÂÃÂÂ¢ÂÂ¢ÂB

ÂwÂÃ±ÂÂ¾ÂÂ±ÂÃ
  - Â_ÂCÂNÂXÂgÂÂÂÃ¢ÂÃ©ÂÃÂÂ«ÂAÂÃÂÂÂÃÂnÂ_ÂWÂÂÂÃ°openÂÃÂÃ¼ÂÃªÂÃÂÂ¨ÂÂ¯ÂÃ O(E log V) ÂÃÂÂ®ÂÃ¬ÂÂµÂÃÂÂ­ÂÃªÂÃ©
  - ÂÃ­ÂÂ´ÂÃ­ÂÂ´VÂÃÂÃÂÂÂÂªÂÃÂ_ÂCÂNÂXÂgÂÂÂÃ°ÂÃ¢ÂÃ§ÂÃÂÂ­ÂÃÂÂ¢ÂÂ¢

 */
#include <iostream>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

typedef pair<int,int> P;

int dist[3002];
vector<P> t[3002]; //first:cost, second:id

void dijk(vector<int> &sv){
  priority_queue<P, vector<P>, greater<P> > open; //first:cost, second:id

  for(int i = 0; i < 3002; i++){
    dist[i] = INT_MAX;
  }

  for(int i = 0; i < sv.size(); i++){
    open.push(P(0, sv[i]));
  }

  while(!open.empty()){
    P p = open.top(); open.pop();
    if(dist[p.second] <= p.first) continue;
    dist[p.second] = p.first;

    for(int i = 0; i < t[p.second].size(); i++){
      P next = t[p.second][i];
      open.push(P(p.first + next.first, next.second));
    }
  }
}

int main(){
  int n, m, k;

  while(cin >> n >> m >> k){
    for(int i = 0; i < n; i++){
      t[i].clear();
    }

    for(int i = 0; i < m; i++){
      int a, b, cost;
      cin >> a >> b >> cost;
      a--;
      b--;
      t[a].push_back(P(cost, b));
      t[b].push_back(P(cost, a));
    }

    vector<int> sv;

    for(int i = 0; i < k; i++){
      int a;
      cin >> a;
      sv.push_back(a - 1);
    }

    dijk(sv);

    double ans = 0;

    for(int i = 0; i < n; i++){
      for(int j = 0; j < t[i].size(); j++){
        int l = t[i][j].first;
        int a = i;
        int b = t[i][j].second;

        if(dist[a] < dist[b]) swap(a, b);

        ans = max(ans, (dist[a] - dist[b] + l) / 2.0 + dist[b]);
      }
    }

    cout << (int)(ans + 0.5) << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
int main(void) {
    int wd,jap,arith,pj,pa,dj,da;
    scanf("%d%d%d%d%d",&wd,&jap,&arith,&pj,&pa);
    dj=ceil(1.0*jap/pj);
    da=ceil(1.0*arith/pa);
    if (dj>da) {
        printf("%d\n",wd-dj);
    } else {
        printf("%d\n",wd-da);
    }
    return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
0 0 2
2 0 2

output:
1.00000000 -1.73205080 1.00000000 1.73205080
"""

import sys
from math import sin, cos, atan2, acos


class Circle(object):
    __slots__ = ('centre', 'radius')

    def __init__(self, centre=float('inf'), radius=-1):
        self.centre = complex(centre)
        self.radius = float(radius)


def arg(p_vector):
    return atan2(p_vector.imag, p_vector.real)


def polar(a, r):
    return a * cos(r) + a * sin(r) * 1j


def get_circles_cross_points(c1, c2):
    centre_distance = abs(c1.centre - c2.centre)
    a = acos((pow(c1.radius, 2) + pow(centre_distance, 2) - pow(c2.radius, 2)) /
             (2 * c1.radius * centre_distance))
    t = arg(c2.centre - c1.centre)
    p1, p2 = c1.centre + polar(c1.radius, t + a), c1.centre + polar(c1.radius, t - a)

    if p1.real < p2.real:
        ans = (p1, p2)
    elif p1.real == p2.real:
        if p1.imag < p2.imag:
            ans = (p1, p2)
        else:
            ans = (p2, p1)
    else:
        ans = (p2, p1)
    return ans


def solve(_circle_info):
    for i, circle in enumerate(_circle_info):
        cx, cy, r = map(int, circle)
        circles[i].centre = cx + cy * 1j
        circles[i].radius = r

    cp1, cp2 = get_circles_cross_points(*circles)
    print('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag))
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    circle_info = map(lambda x: x.split(), _input)

    circles = [Circle() for _ in range(2)]
    solve(circle_info)

Measured memory_bytes: 8084
#include<bits/stdc++.h>
using namespace std;
int a,b,c,ans=1e9;
int abx(int k)
{
	return k>0?k:-k;
}
int maxn(int k,int s)
{
	return k>s?s:k;
}
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	ans=maxn(ans,abx(b-a)+abx(c-b));
	ans=maxn(ans,abx(c-a)+abx(b-c));
	ans=maxn(ans,abx(a-b)+abx(c-a));
	ans=maxn(ans,abx(c-b)+abx(a-c));
	ans=maxn(ans,abx(a-c)+abx(b-a));
	ans=maxn(ans,abx(c-b)+abx(a-b));
	printf("%d",ans);
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n;
vector<pair<ll, ll>> s;
int main() {
	cin >> n;
	REP(i, n) {
		if (i % 3 == 0 or i == 0 or i == n - 1) {
			REP(j, n)if ((i + j) % 2 == 1)s.push_back(make_pair(j, i));
		}
		else if (i % 2 == 1) s.push_back(make_pair(0, i));
	}
	cout << s.size() << endl;
	REP(i, s.size()) cout << s[i].first << " " << s[i].second << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

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

	map<int, int> m;
	rep(i, K) {
		int d;
		cin >> d;
		rep(j, d) {
			int x = 0;
			cin >> x;
			m[x] += 1;
		}
	}

	int result = 0;
	rep(i, N) {
		if (m[i+1] == 0) result += 1;
	}

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


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


void solve() {
    string s;
    long long k;
    cin >> s >> k;
    int n = (int) s.size();
    vector<string> a(n);
    int pos = 0;
    for (int i = 0; i < n; i++) {
        if(s[i] != '1') {
            pos = i;
            break;
        }
    }
    if(k >= pos + 1) {
        cout << s[pos];
    }
    else {
        cout << s[k - 1];
    }

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


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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n;
const int MOD = 1e9+7;

struct mat{
	vector<vector<int>> t;
	mat(){
		t.resize(n, vector<int>(n));
	}
	mat operator* (const mat& b) const{
		mat c = mat(); 
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				for(int k = 0;k < n;k++){
					c.t[i][k] = (c.t[i][k] + t[i][j]*b.t[j][k]%MOD)%MOD;
				}
			}
		}
		return c;
	}
};

void solve(){
	cin >> n;
	int k;
	cin >> k;
	//int grid[n][n];
	vector<vector<int>> grid(n,vector<int>(n));
	for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) cin >> grid[i][j];
	mat ans = mat();
	for(int i = 0;i < n;i++) ans.t[i][i] = 1;
	mat m = mat();
	m.t = grid;
	while(k){
		if(k&1) ans = ans * m;
		m = m*m;
		k>>=1;
	}
	int ans2 = 0;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			ans2 = (ans2 + ans.t[i][j])%MOD;
		}
	}
	cout << ans2 << "\n";
}

signed main(){
	fastio
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 3720
import math
a,b,h,m = map(int,input().split())

h = h + m/60

rotH = (360 * h/12 ) % 360
rotM = (360 * h ) % 360


totalRot = abs(rotM - rotH)


cosineR = math.sqrt(a**2 + b**2 - 2*(a*b*math.cos(math.radians(totalRot))))

print(cosineR)

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

const int mod = 1000000007;


int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> red_temp(a), blue_temp(b);
    rep(i, a) cin >> red_temp[i];
    rep(i, b) cin >> blue_temp[i];
    sort(red_temp.rbegin(), red_temp.rend());
    sort(blue_temp.rbegin(), blue_temp.rend());


    PQ_ASK red, blue;
    rep(i, x) {
        red.push(red_temp[i]);
    }
    rep(i, y) {
        blue.push(blue_temp[i]);
    }

    vector<ll> white(c);
    rep(i, c) cin >> white[i];
    sort(white.rbegin(), white.rend());

    for (ll w : white) {
        if (red.top() < blue.top()) {
            if (w > red.top()) {
                red.pop();
                red.push(w);
            }
        } else {
            if (w > blue.top()) {
                blue.pop();
                blue.push(w);
            }
        }
    }


    ll ans = 0;

    while (!red.empty()) {
        ans += red.top();
        red.pop();
    }
    while (!blue.empty()) {
        ans += blue.top();
        blue.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 4084
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadLineInt();
            var ans = a + a * a + a * a * a;
            Console.WriteLine(ans);
        }


        #region 使いまわし
        static string ReadLineStr() { return Console.ReadLine(); }
        static int ReadLineInt() { return Convert.ToInt32(Console.ReadLine()); }
        static (int, int) ReadLineInt2()
        {
            var temp = Console.ReadLine().Split(' ');
            return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));
        }
        static List<int> ReadLineIntList()
        {
            var data = new List<int>();
            foreach (var temp in Console.ReadLine().Split(' '))
            {
                data.Add(Convert.ToInt32(temp));
            }

            return data;
        }

        static long ReadLineLong() { return Convert.ToInt64(Console.ReadLine()); }
        #endregion
    }
}


Measured memory_bytes: 27400
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int A, B, C, D, E;
	cin >> A >> B >> C >> D;

	E = (min(B, D) - max(A, C) > 0) ? min(B, D) - max(A, C) : 0;
	cout << E << endl;
	return 0;
}

Measured memory_bytes: 256
import math
import fractions
from functools import reduce
n,k=map(int,input().split())
a=list(map(int,input().split()))

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
b=gcd(*a)
if max(a)-k>=0 and (max(a)-k)%b==0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 16300
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

int n;
vector<ll> dp(1<<18, 0);
vector<bool> flg(1<<18, false);
vector<vector<ll>> a(20, vector<ll>(20, 0));

ll f(int S){
    if(flg[S]) return dp[S];
    flg[S]=1;

    // 切らない場合を計算
    ll tmp=0;
    rep(i, 0, n) rep(j, i+1, n) if(S&1<<i && S&1<<j) tmp+=a[i][j];
    ll ret=tmp;
    // どこで切るか考える
    for(int T=(S-1)&S; T>0; T=(T-1)&S){
        chmax(ret, f(T)+f(S^T));
    }
    return dp[S]=ret;
}

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

    cin >> n;
    rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];

    cout << f((1<<n)-1) << '\n';

	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>

using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N);
    vector<int> c(M), d(M);
    for (int i = 0; i < N; i++){
        cin >> a.at(i) >> b.at(i);
    }
    for (int i = 0; i < M; i++){
        cin >> c.at(i) >> d.at(i);
    }
    vector<int> ans(N);
    for (int i = 0; i < N; i++){
        int min = 1e9;
        int x = 0;
        for (int j = 0; j < M; j++){
            if ((x = (abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j)))) < min){
                min = x;
                ans.at(i) = j+1;
            }
        }
    }
    for (int i = 0; i < N; i++){
        cout << ans.at(i) << endl;;
    }
    return 0; 
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, k, q) = readLine()!!.split(" ").map { it.toInt() }
    val sankasya = Array(n){ 0 }
    for (i in 0 until q){
        val a = readLine()!!.split(" ").map { it.toInt() }[0]
        sankasya[a-1] += 1
    }
    for (i in 0 until n){
        if (sankasya[i] + k > q){
            println("Yes")
        } else {
            println("No")
        }
    }
}


Measured memory_bytes: 54084
#include <iostream>

using namespace std;

int main(void) {
	char b;
	cin >> b;
	char res;
	if (b == 'A') {
		res = 'T';
	}
	else if (b == 'T') {
		res = 'A';
	}
	else if (b == 'C') {
		res = 'G';
	}
	else {
		res = 'C';
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    x, y = list(map(lambda x: int(x)-1, input().split()))
    edges[x].append(y)


def memoize(f):
    memo = [-1]*n

    def memoized(args):
        if memo[args] != -1:
            return memo[args]
        else:
            memo[args] = f(args)
            return memo[args]
    return memoized


@memoize
def longest_path(v):
    retval = 0
    for v2 in edges[v]:
        retval = max(retval, longest_path(v2)+1)
    return retval


ans = 0
for i in range(n):
    ans = max(ans, longest_path(i))
print(ans)

Measured memory_bytes: 109616
#include <iostream>
#include<vector>
using namespace std;
int A[500100];
int cnt=0;
 void Merge (int left, int mid, int right){
     int n1=mid-left;
     int n2=right -mid;
     vector<long long> L(n1+1,0), R(n2+1,0);
     for(int i=0;i<n1;i++) L[i]=A[left+i];
     for(int i=0;i<n2;i++) R[i]=A[mid+i];
     L[n1]=1e12;
     R[n2]=1e12;
     int i=0;
     int j=0;
 
 for(int k=left;k<right;k++){
     if(L[i]<=R[j]){
         A[k]=L[i];
         i=i+1;
     }
     else{
         A[k]=R[j];
         j=j+1;
     }
     cnt++;
 }
    // Your code here!
    
}

void MergeSort(int left ,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        MergeSort(left,mid);
        MergeSort(mid,right);
        Merge(left,mid,right);
    }
}

int n;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    
    MergeSort(0,n);
    
    for(int i=0;i<n;i++){
        if(i!=n-1) cout<<A[i]<<" ";
        else cout<<A[i]<<endl;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 8596
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

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

    VI ok(n + 1, 1);
    REP(i,m){
        ok[in()] = 0;
    }

    VL dp(n + 1);
    dp[0] = 1;
    FOR(i,1,n){
        if (!ok[i]) continue;
        dp[i] = dp[i - 1];
        if (i > 1) dp[i] = (dp[i] + dp[i - 2]) % mod;
    }
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, K;

int main() {
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}
	return 0;
}

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

typedef struct
{
  int I, U, A, P;
} Team;

class solve
{
public:
  bool operator()(const Team& lhs, const Team& rhs)
  {
    if (lhs.A == rhs.A) {
      if (lhs.P == rhs.P)
	return lhs.I < rhs.I;
      return lhs.P < rhs.P;
    }
    return lhs.A > rhs.A;
  }
};

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

    vector<Team> team(n);
    for (int i = 0; i < n; ++i)
      cin >> team[i].I >> team[i].U >> team[i].A >> team[i].P;
    sort(team.begin(), team.end(), solve());

    int advance = 0;
    vector<int> univ(1000, 0);
    for (int i = 0; i < n; ++i) {
      if (advance < 10) {
	if (univ[team[i].U-1] < 3) {
	  cout << team[i].I << endl;
	  ++univ[team[i].U-1];
	  ++advance;
	}
      } else if (advance < 20) {
	if (univ[team[i].U-1] < 2) {
	  cout << team[i].I << endl;
	  ++univ[team[i].U-1];
	  ++advance;
	}
      } else if (advance < 26) {
	if (univ[team[i].U-1] < 1) {
	  cout << team[i].I << endl;
	  ++univ[team[i].U-1];
	  ++advance;
	}
      }
    }

  }
  return 0;
}

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


using namespace std;
using ll = long long;


const ll M = 1000000007;


int main() {
    vector<ll> count(60, 0);

    ll N;
    cin >> N;

    for (ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        for (ll j = 0; j < 60; j++) {
            count[j] += (a >> j) & 1;
        }
    }

    ll a = 0;
    for (ll i = 0; i < 60; i++) {
        ll t = ((((1LL << i) % M) * count[i]) % M * (N - count[i])) % M;
        a = (a + t) % M;
    }
    cout << a << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N=3;
    vector<int> c(4);
    int a,b;
    for (int i=0;i<N;i++) {
        cin >> a >> b;
        c[a-1]++;
        c[b-1]++;
    }
    string ans;
    for (int i=0;i<4;i++) {
        if (c[i]<1 || 2<c[i]) {
            ans = "NO";
            break;
        }
    }
    if (ans.empty()) ans = "YES";
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


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

	
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int h1, m1, h2, m2;
    cin >> h1 >> m1 >> h2 >> m2;
    int t1 = h1 * 60 + m1;
    int t2 = h2 * 60 + m2;
    int k;
    cin >> k;
    cout << t2 - t1 - k << '\n';
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <cstring>
#include <utility>
#include <cmath>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second 
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl "\n"


void print() { cout << endl; }

template <typename T, typename... Types>
void print(T arg, Types... args) {
    cout << arg << " ";
    print(args...);
}

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef vector < int > vi;

const int mod = 1e9 + 7;
const int N = 2e5 + 7;


ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}
 
 
ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
 
ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
 
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

string dp[N+10];


int main()
{
    IOS;
    int n;
    cin >> n;
    dp[1] = '1';
    for (int i = 2; i < 10; i++)
    {
        dp[i] = ('0' + i);
    }
    int cur = 1, i = 10;
    while (i < N)
    {
        int l = dp[cur].size()-1;
        char x = dp[cur][l];
        for (char k = x-1; k <= x+1; k++)
        {
            if (k <= '9' and k >= '0')
            {
                dp[i] = dp[cur] + k;
                i++;
            }
        }
        cur++;
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 13952
#include <iostream>
#include <queue>
#include <map>
#include <climits>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> NODE;
#define pos first
#define depth second

bool info[100][100];

int bfs(int s,int d){
	queue<NODE> Q;
	bool done[100]={false};
	
	Q.push( make_pair(s,0) );
	while( !Q.empty() ){
		/* queueツづ個静ヲツ督ェツづ個ノツーツドツづーツ訪ツ姪「ツ催渉づ敖づ可つオツづowツ陛渉青板づ可禿シツづェツ、ツキツδーツつゥツづァツ偲ヲツづィツ渉慊つュ */
		NODE now = Q.front();
		Q.pop();
		done[now.pos] = true;

		if(now.pos == d){
			return now.depth;
		}

		for(int next=0;next<100;next++){
			if( !done[next] && info[now.pos][next] ){
				Q.push( make_pair(next,now.depth+1) );
			}
		}
	}
	return INT_MAX;
}

int main(){
	int n,r,k,t,p,s,d,v;
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r >> k;
		r--;
		for(int j=0;j<k;j++){
			cin >> t;
			t--;
			info[r][t] = true;
		}
	}	
	
	cin >> p;
	for(int i=0;i<p;i++){
		cin >> s >> d >> v;
		s--;d--;
		if(v > bfs(s,d) )cout << bfs(s,d)+1 << endl;
		else cout << "NA" << endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  char c1, c2, c3, c4;
  c1 = s.at(0); c2 = s.at(1); c3 = s.at(2); c4 = s.at(3);

  int flag = 0;
  if(c1 == c2 && c3 == c4 && c1 != c3) flag = 1;
  if(c1 == c3 && c2 == c4 && c1 != c2) flag = 1;
  if(c1 == c4 && c2 == c3 && c1 != c2) flag = 1;
  
  if(flag){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

a, b, x = map(int, input().split())
print(b // x - (a - 1) // x)

Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>

int jdg_str(char s[100], char t[100], int l){

	int i;
	int ret = 0;

	for(i=0;i<l;i++){
		if(s[i] == t[i]){ continue; }
		else{
			if(s[i] > t[i]){ ret = 1; break; } 
			else{ ret = 0; break; } 
		}
	}

	return ret;
}

int main(void){
	int n,l;
	char s[100][101];
	int i,j;
	char b[101];

	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++){
		scanf("%s",&s[i]);
	}

	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(jdg_str(s[i], s[j], l) == 1){
				strcpy(b,s[j]);
				strcpy(s[j],s[i]);
				strcpy(s[i],b);
			}
		}
	}

	for(i=0;i<n;i++){
		printf("%s",s[i]);
	}
	printf("\n");


	return 0;
}

Measured memory_bytes: 128
N, X = map(int, input().split())

length = [1]
paty = [1]
for i in range(N):
  length.append(3 + length[-1] * 2)
  paty.append(1 + paty[-1] * 2)

def num_paty(n, f, t):
  global length
  global paty

  if f >= length[n] or t < 0:
    ret = 0
  elif f <= 0 and t >= length[n]-1:
    ret = paty[n]
  else:
    half = length[n] // 2
    ret = 1 if f <= half and t >= half else 0
    ret += num_paty(n-1, f-1, t-1)
    ret += num_paty(n-1, f-half-1, t-half-1)
  return ret

print(num_paty(N, 0, X-1))

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {

    int X, N; cin >> X >> N;
    map<int,bool> mp;
    REP(i, N) {
        int p; cin >> p; mp[p] = true;
    }

    int ans;
    REP(i, 100) {
        if (mp.count(X - i) == 0) {
            ans = X - i;
            break;
        }
        if (mp.count(X + i) == 0) {
            ans = X + i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3584
#include <string>
#include <iostream>

using namespace std;

int main() {

	string s;

	cin >> s;

	for(int i=0; i<s.size(); i++) {
		if(s[i]=='A') {
			s[i]='X';
		}
		else if(s[i]=='B') {
			s[i]='Y';
		}
		else if(s[i]=='C') {
			s[i]='Z';
		}
		else {
			s[i]-=(char)3;
		}
		cout << s[i];
	}
	cout << endl;

	return 0;

}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    
    ll N,P,A,zero=0,one=0,cn=0,con=0;
    cin>>N>>P;
    rep(i,0,N){
        cin>>A;
        if(A%2==0)zero++;
        else one++;
    }
    if(one==0&&P==1)cout<<0<<endl;
    else if(one==0&&P==0)cout<<(ll)pow(2,N)<<endl;
    else cout<<(ll)pow(2,N-1)<<endl;


}






Measured memory_bytes: 256
n = int(input())
x = input()
ones = 0
for i in x:
    if i=='1':
        ones += 1
mods = [0, 0]
for i in range(n):
    if x[n-i-1]=='1':
        if ones>1:
            mods[0] += pow(2, i, ones-1)
        mods[1] += pow(2, i, ones+1)
if ones>1:
    mods[0] %= ones-1
mods[1] %= ones+1
def f(x):
    if x==0:
        return 1
    cnt = 1
    while x>0:
        p = bin(x).count('1')
        x %= p
        cnt += 1
    return cnt
for i in range(n-1, -1, -1):
    if x[n-i-1]=='1' and ones==1:
        print(0)
        continue
    if x[n-i-1]=='1':
        init = (mods[0] - pow(2, i, ones-1))%(ones-1)
    else:
        init = (mods[1] + pow(2, i, ones+1))%(ones+1)
    print(f(init))

Measured memory_bytes: 9480
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

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

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    int m;
    m = 0;
    if (m < abs(a - b)) {
        m = abs(a - b);
    }
    if (m < abs(a - c)) {
        m = abs(a - c);
    }
    if (m < abs(a - d)) {
        m = abs(a - d);
    }
    if (m < abs(a - e)) {
        m = abs(a - e);
    }
    if (m < abs(b - c)) {
        m = abs(b - c);
    }
    if (m < abs(b - d)) {
        m = abs(b - d);
    }
    if (m < abs(b - e)) {
        m = abs(b - e);
    }
    if (m < abs(c - d)) {
        m = abs(c - d);
    }
    if (m < abs(c - e)) {
        m = abs(c - e);
    }
    if (m < abs(d - e)) {
        m = abs(d - e);
    }
    if (m > k) {
        printf(":(");
    } else {
        printf("Yay!");
    }

    /* --------------------------------- */
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
from subprocess import*
call(('pypy3','-c',"""
I=lambda:list(map(int,input().split()))
n,W=I()
g=[0]+[I()for _ in range(n)]
vm=n*1000+1
dp=[[0]+[10**18]*vm]+[[0]*vm for _ in range(n)]
for i in range(1,n+1):
    w,v=g[i]
    for j in range(vm):
        k=j-v
        if k<0:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i-1][k]+w)
for j in range(vm)[::-1]:
    if dp[n][j]<=W:
        print(j)
        break
"""))

Measured memory_bytes: 123188
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<T>())
#define REVERCE(x) reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<int> a(n);

	REP(i, n) {
		cin >> a[i];
	}

	const itn kMod = 1'000'000'007;
	int res = 0;

	const itn kBit = 60;

	vector<pair<int, int>> bit_count(kBit);
	REP(i, kBit) {
		bit_count[i] = pair<int, int>(0, 0);
	}

	int msk;
	int point;

	REP(i, n) {
		msk = 1ll << kBit;
		point = kBit;
		while(point){
			msk >>= 1;
			point--;
			if (a[i] & msk) {
				bit_count[point].second++;
			}
			else {
				bit_count[point].first++;
			}
		}
	}

	point = kBit;
	msk = 1ll << kBit;

	while (point) {
		point--;
		msk >>= 1;
		res += std::fmod(((long double)bit_count[point].first * bit_count[point].second) * msk, kMod);
		res %= kMod;
	}

	cout << res;

	return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

const int N = 2e5 + 10;
struct P { ll a, b; } p[N];
bool cmp(const P &a, const P &b) {
	return a.b < b.b;
}

int main() {
	int n = read();
	for (int i = 0; i < n; i++) p[i].a = read(), p[i].b = read();
	sort(p, p + n, cmp);
	ll t = 0;
	for (int i = 0; i < n; i++) {
		t += p[i].a;
		if (t > p[i].b) { puts("No"); return 0; }
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    
    int m[10];
    
    for(int i=0; i<10 ; i++)cin >> m[i];
    sort(m,m+10);
    
    cout<<m[9]<<endl;
    cout<<m[8]<<endl;
    cout<<m[7]<<endl;
    
    
}



Measured memory_bytes: 3136
/**
 * C - Switches
 * https://atcoder.jp/contests/abc128/tasks/abc128_c
 **/
#include<iostream>
#include<vector>

using namespace std;

const int MAX_N = 10;

int main() {
    int N, M;
    // vector<int> p(M);
    cin >> N >> M;
    vector<vector<int>> s(M);   // 電球の対応スイッチ番号リスト
    for(int i=0; i<M; i++) {
        int ki;
        cin >> ki;
        for(int j=0; j<ki; j++) {
            int tmp_s;
            cin >> tmp_s;
            s[i].push_back(tmp_s);
        }
    }

    vector<int> p(M);
    for(int i=0; i<M; i++) {
        int tmp_p;
        cin >> tmp_p;
        p[i] = tmp_p;
    }

    // Nbitの全探索
    int ans = 0;
    for(int bit=0; bit < (1<<N); ++bit) {
        // 000101 (1がスイッチがon) を決定
        bool flag = true;
        for(int i=0; i<M; i++) {
            // 対象の電球を固定
            int count = 0;
            for(auto x:s[i]) {
                if(bit & (1<<(x-1))) {
                    count++;
                }
            }
            if(count%2!=p[i]) {
                flag = false;
                break;
            }
        }
        if(flag) {
            ans++;
        } 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#B - Problem Set

# -*- coding: utf-8 -*-
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

D_count = Counter(D)
T_count = Counter(T)

for t_key, t_val in T_count.items():
    if(t_key in D_count):
        if(t_val > D_count[t_key]):
            print("NO") 
            exit()
    else:
        print("NO")
        exit()

print("YES")

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

int main() {
  int N,K;
  cin >> N >> K;
  int sum = 1;
  for(int i = 0; i < N; i++){
    if((sum * 2) - (sum + K) > 0){
      sum += K;
    } else {
      sum *= 2;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3608
from collections import *
H,W=map(int,input().split())
CH,CW=map(int,input().split())
CH,CW=CH-1,CW-1
DH,DW=map(int,input().split())
DH,DW=DH-1,DW-1
S=[input() for i in range(H)]
Q=deque()
INF=10**9
D=[[INF]*W for i in range(H)]
D[CH][CW]=0
Q.append((CH,CW))
w4x=[[0,1,0,-1],[]]
w4y=[[1,0,-1,0],[]]
for i in range(5):
  for j in range(5):
    if abs(i-2)+abs(j-2)<=1:
      continue
    w4x[1].append(i-2)
    w4y[1].append(j-2)
v=0
w=0
d=0
while len(Q):
  v=Q.popleft()
  for j in range(2):
    for i in range(len(w4x[j])):
      w=(v[0]+w4y[j][i],v[1]+w4x[j][i])
      if min(w)<0 or w[0]>=H or w[1]>=W:
        continue
      if S[w[0]][w[1]]=='#':
        continue
      d=D[v[0]][v[1]]+j
      if D[w[0]][w[1]]>d:
        D[w[0]][w[1]]=d
        if j:
          Q.append(w)
        else:
          Q.appendleft(w)
if D[DH][DW]==INF:
  print(-1)
else:
  print(D[DH][DW])

Measured memory_bytes: 94452
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main () {
    let s: String = input();
    let s: Vec<char> = s.chars().collect();
    let mut buf: Vec<char> = Vec::new();
    let mut count = 0;
    let mut pre: Vec<char> = Vec::new();
    for i in 0..s.len() {
        buf.push(s[i]);
        if pre != buf {
            count += 1;  
            pre = buf.to_vec();
            buf = Vec::new();          
        }
    }
    println!("{}", count);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
#include <iomanip>
#include <set>
using namespace std;
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int x,y;
    cin>>x>>y;
    long long ans;
    if(x%y==0){cout<<-1<<endl;return 0;}else{
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    import heapq,bisect
    s = input()
    K = int(input())

    n = len(s)

    L = set()
    for i in range(n):
        for j in range(i+1,min(n+1,i+6)):
            L.add(s[i:j])

    L = list(L)
    L.sort()
    print(L[K-1])
main()

Measured memory_bytes: 10456
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    def __init__(self):
        self.count = 0

    def shell_sort(self):
        array_length = int(input())
        array = []
        # array = list(map(int, sys.stdin.readlines()))
        # array_length = 10
        # array = [15, 12, 8, 9, 3, 2, 7, 2, 11, 1]
        for m in range(array_length):
            array.append(int(input()))

        G = [1]
        while True:
            g = G[0] * 3 + 1
            if g > array_length:
                break
            G.insert(0, g)

        g_length = len(G)
        result = []
        for j in range(g_length):
            result = self.insertion_sort(array=array, array_length=array_length, g=G[j])
            # print(result, 'r', G[j])

        print(g_length)
        print(*G)
        print(self.count)
        print(*result, sep='\n')

    def insertion_sort(self, array, array_length, g):
        # write your code here

        for i in range(g, array_length):
            v = array[i]
            j = i - g
            while j >= 0 and array[j] > v:
                array[j + g] = array[j]
                j -= g
                self.count += 1
            array[j + g] = v

        # print(" ".join(map(str, array)))
        return array


if __name__ == '__main__':
    solution = Solution()
    solution.shell_sort()

Measured memory_bytes: 63020
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n;
	double ans=0;
	vector<double> v;

	cin>> n;
	v.resize(n);
	for(int i=0;i<n;i++) cin>> v[i];

	for(int i=0;i<n;i++){
		ans+=1.0/v[i];
	}

	cout<< 1.0/ans << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

const int MaxN = 1e5;
int x, y, z;
LL l[MaxN + 5], r[MaxN + 5];
struct People {
	LL g, s, b;
}a[MaxN + 5];
priority_queue<LL, vector<LL>, greater<LL> >p;

bool cmp(People a, People b) {
	return (a.g - a.s) < (b.g - b.s);
}

int main()
{
	scanf("%d%d%d", &x, &y, &z); 
	for(int i = 1; i <= x + y + z; i++) 
		scanf("%lld%lld%lld", &a[i].g, &a[i].s, &a[i].b);
	sort(a + 1, a + x + y + z + 1, cmp);
	for(int i = 1; i <= y; i++) {
		l[y] += a[i].s;
		p.push(a[i].s - a[i].b);
	}
	for(int i = y + 1; i <= x + y + z; i++) {
		LL w = p.top(); l[i] = l[i - 1]; l[i] += a[i].b;
		if(w < (a[i].s - a[i].b)) {
			l[i] -= w; l[i] += (a[i].s - a[i].b);
			p.pop(); p.push(a[i].s - a[i].b);
		}
	}
	while(!p.empty()) p.pop();
	for(int i = x + y + z; i > y + z; i--) {
		r[y + z + 1] += a[i].g;
		p.push(a[i].g - a[i].b);
	}
	for(int i = y + z; i >= 1; i--) {
		LL w = p.top(); r[i] = r[i + 1]; r[i] += a[i].b;
		if(w < (a[i].g - a[i].b)) {
			r[i] -= w; r[i] += (a[i].g - a[i].b);
			p.pop(); p.push(a[i].g - a[i].b);
		}
	}
	LL sum = 0;
	for(int i = y; i <= y + z; i++) 
		sum = max(sum, l[i] + r[i + 1]);
	printf("%lld\n", sum);
}

Measured memory_bytes: 4472
#include<stdio.h>
int main(){
  int i,j,n,q,S[10000],T[1000],a,b,c,d,count=0,count2=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }
  for(a=0;a<q;a++){
    for(b=0;b<n;b++){
      if(T[a]==S[b]) {
        count++;
        count2++;
        if(count2>=2){
          count--;
        }
      }
    }
    count2=0;
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2068