akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n, d = map(int, input().split())
    x = 2 * d + 1
    if n % x == 0:
        print(n // x)
    else:
        print((n // x) + 1)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29036
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 500 + 5;
int n,m;
string s[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> m >> n;
    for(int i = 0 ; i < m ; ++i){
        cin >> s[i];
    }
    for(int i = 0 ; i < m ; ++i){
        for(int j = 0 ; j < n ; ++j){
            if(j == 0 || s[i][j] == '#' || ((i & 1) && j + 1 < n))cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
    cout << endl;
    for(int i = 0 ; i < m ; ++i){
        for(int j = 0 ; j < n ; ++j){
            if(j == n - 1 || s[i][j] == '#' || (!(i & 1) && j != 0))cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
}


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> maze(h);
    maze.assign(h,"");
    int cnt = 0;
    rep(i,h)rep(j,w){
        char temp;
        cin >> temp;
        if(temp=='#') cnt++;
        maze[i].push_back(temp);
    }

    int dx[4] = {-1,1,0,0};
    int dy[4] = {0,0,-1,1};
    int dist[h][w];
    rep(i,h)rep(j,w) dist[i][j] = -1;
    dist[0][0] = 0;

    queue<P> q;
    q.push(make_pair(0,0));
    while(q.size()){
        P temp = q.front();
        q.pop();
        int y = temp.first;
        int x = temp.second;
        for(int i=0;i<4;i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(nx < 0 || ny < 0 || h <= ny || w <= nx) continue;
            if(maze[ny][nx]=='#' || dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[y][x]+1;
            q.push(make_pair(ny,nx));
        }
    }
    if(dist[h-1][w-1]!=-1) cout << h*w-cnt-1-dist[h-1][w-1] << endl;
    else cout << -1 << endl;


 }

Measured memory_bytes: 3616
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from typing import List
from heapq import heappush, heappop, heapify
import sys
from collections import defaultdict
INF = 10**6
def main(H, W, AB):
    cur = list(range(W))
    cur_f = BinaryIndexedTree(initial_values=[1] * W)
    rt = RemovableHeapq([0] * W)
    for i, (a, b) in enumerate(AB):
        a -= 1
        mr = -1
        while True:
            j = cur_f.bisect(lambda x: x <= cur_f.query(a - 1))
            if j >= W or j > b: break
            mr = cur[j]
            cur_f.add(j, -1)
            rt.remove(j - cur[j])
        if mr >= 0 and b < W:
            cur_f.add(b, 1)
            cur[b] = mr
            rt.push(b - mr)
        ans = -1
        if not rt.is_empty():
            ans = rt.get_min() + i + 1
        print(ans)

class RemovableHeapq:
    def __init__(self, l: List[int]):
        h = l[:]
        heapify(h)
        d = defaultdict(int)
        for e in l:
            d[e] += 1
        self.h, self.d = l, d

    def push(self, item: int):
        heappush(self.h, item)
        self.d[item] += 1

    def remove(self, item: int) -> bool:
        d = self.d
        if d[item] > 0:
            d[item] -= 1
            return True
        return False

    def get_min(self) -> int:
        h, d = self.h, self.d
        while True:
            m = h[0]
            if d[m] == 0:
                heappop(h)
            else:
                return m

    def is_empty(self) -> bool:
        h, d = self.h, self.d
        while h:
            if d[h[0]] == 0:
                heappop(h)
            else:
                break
        return len(h) == 0

class BinaryIndexedTree:
    def __init__(self, n=None, f=lambda x, y: x + y, identity=0, initial_values=None):
        assert(n or initial_values)
        self.__f, self.__id, = f, identity
        self.__n = len(initial_values) if initial_values else n
        self.__d = [identity] * (self.__n + 1)
        if initial_values:
            for i, v in enumerate(initial_values): self.add(i, v)

    def add(self, i, v):
        n, f, d = self.__n, self.__f, self.__d
        i += 1
        while i <= n:
            d[i] = f(d[i], v)
            i += -i & i

    def query(self, r):
        res, f, d = self.__id, self.__f, self.__d
        r += 1
        while r:
            res = f(res, d[r])
            r -= -r & r
        return res

    def bisect(self, func):
        '''func()がFalseになるもっとも左のindexを探す
        '''
        n, f, d, v = self.__n, self.__f, self.__d, self.__id
        x, i = 0, 1 << (n.bit_length() - 1)
        while i > 0:
            if x + i <= n and func(f(v, d[x + i])): v, x = f(v, d[x + i]), x + i
            i >>= 1
        return x

if __name__ == '__main__':
    input = sys.stdin.readline
    H, W = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(H)]
    main(H, W, AB)


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

public class Main {

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

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}

		Arrays.sort(a);
		long min = a[0];
		int zero = 0;

		int zerok=0;
		while (a[n - 2] != 0) {

			zero = 0;
			for (int i = zerok+1; i < n; i++) {
				a[i] = a[i] % min;
				if (a[i] == 0) {
					zero++;
				}
			}
			zerok+=zero;
			Arrays.sort(a);
			//show(a);
			min = a[zerok];
		}

		System.out.println(a[n - 1]);
	}
public static void show(long a[]){
	for(int i=0;i<a.length;i++){
	System.out.print(a[i]+" ");}
System.out.println();
}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> buttons(N);
  for (int i = 0; i < N; i++) cin >> buttons.at(i);

  int pushes = 0;
  set<int> pushed;
  int next = 0;
  pushed.insert(next);
  while (true) {
    pushes++;
    next = buttons.at(next) - 1;

    if (next == 1) {
      cout << pushes << endl;
      return 0;
    }

    auto result = pushed.insert(next);
    if (!result.second) {
      cout << -1 << endl;
      return 0;
    }
  }
}


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

int main() {
    string S;
    cin >> S;

    int num=1000;
    for (int i=0; i<S.length()-2; i++) {
        string sbuff;
        sbuff=S.substr(i, 3);
        int ibuff=stoi(sbuff);
        int diff=abs(753-ibuff);
        num=min(num, diff);
    }

    cout << num << endl;

    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
 
int main(){
    int money = 100000;
    int n;
 
    cin >> n;
    for(int i = 0; i< n; i++){
        money *= 1.05;
        if(money % 1000 != 0){
            money += 1000 - (money % 1000);
        }
    }
    cout << money << endl;
} 

Measured memory_bytes: 1160
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  if (int(s.size()) != a + b + 1 || s[a] != '-') {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < a + b + 1; ++i) {
    if (i != a && !isdigit(s[i])) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}



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

#define lli long long int

lli gcd(lli a, lli b) {
	return ((b == 0) ? a : gcd(b, a % b));
}

int main() {
	lli a, b, ans = 1;
	scanf("%lld %lld", &a, &b);
	a = gcd(a, b);
	b = sqrt(a);
	for (lli i = 2; i <= b; i++)
		if (a % i == 0) {
			ans++;
			while (a % i == 0)
				a /= i;
		}
	if (a > 1)
		ans++;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

int a[103];

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int n;
  std::cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    std::cin >> a[i];
    cnt += (i & 1) && (a[i] & 1);
  }
  std::cout << cnt;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
length = len(str(n))
c = [[0] * 10 for _ in range(10)]
for k in range(1, n + 1):
    s = str(k)
    first = int(s[0])
    last = int(s[-1])
    c[first][last] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)


Measured memory_bytes: 3064
n = int(input())
S = sorted([''.join(sorted(input())) for _ in range(n)])
t = len(set(S))
cnt = [1] * t
loop = 0

for i in range(0, t):
    for j in range(loop, n - 1):
        if S[j] == S[j + 1]:
            cnt[i] += 1
        else:
            loop = j + 1
            break
# print(cnt)

ans = 0
for i in range(0, t):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)


Measured memory_bytes: 16888
import sys

N = int(input())
num = list(map(int,input().split()))

lsum = 0
rsum = 0
for i in range(N):
	if (lsum<=rsum):
		lsum+=num.pop(0)
	else :
		rsum+=num.pop(-1)

if (rsum>lsum):
	print(rsum-lsum)
else :
	print(lsum-rsum)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long int
#define mem(x, a) memset(x,a,sizeof(x))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

const int maxn=1e5+5;
int n;
int v[maxn];
ll dp[maxn];

ll f(int i){
    if(i==n) return 0;
    if(dp[i]!=-1) return dp[i];
    ll res = abs(v[i]-v[i+1]) + f(i+1);

    if(i+2<=n) res=min(res,abs(v[i]-v[i+2]) + f(i+2));
    return dp[i]=res;
}

int main()
{
    fast_cin;
    mem(dp,-1);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> v[i];
    cout << f(1) <<"\n";
}


Measured memory_bytes: 6144
def main():
    N = int(input())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    l.sort(key=lambda x:x[1])
    s = 0
    for i, j in l:
        s += i
        if s > j:
            return('No')
    return('Yes')
print(main())



Measured memory_bytes: 31880
program pr3
  implicit none
  integer :: n, i, j, k, t
  integer :: f(10000)
  
  read(*,*) n

  do i = 1, int(sqrt(dble(n))) + 1
     do j = 1, int(sqrt(dble(n))) + 1
        do k = 1, int(sqrt(dble(n))) + 1
           t =  i*i + j*j + k*k + i*j + j*k + k*i
           if ( t <= 10000 ) then
              f(t) = f(t) + 1
           end if
        end do
     end do
  end do

  do i = 1, n
     write(*,'(i0)') f(i)
  end do
 
  stop
end program pr3


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);
vector<pair<ll, int>> factorize(ll);

// ================ Main Loop ================
int main() {
    ll n, ans = 0;
    cin >> n;
    vector<pair<ll, int>> fc;
    fc = factorize(n);
    set<ll> tb;
    for(auto fcitr : fc) {
        ll z = 1;
        for(int i = 1; i <= fcitr.second; i++) {
            z *= fcitr.first;
            tb.insert(z);
        }
    }

    for(auto tbitr : tb) {
        if(n % tbitr == 0) {
            n /= tbitr;
            ans++;
        }
    }
    /*
    map<ll, vector<pair<ll, int>>> fct;
    queue<ll> q;
    q.push(n);
    fct[n] = factorize(n);
    while(!q.empty()) {
        ll v = q.front();
        q.pop();
        for(auto itr : fct[v]) {
            // cout << itr.first << " " << itr.second << endl;
            z = 1;
            for(int i = 1; i <= itr.second; i++) {
                z *= itr.first;
                if(fct.count(n / z)) continue;
                fct[n / z] = factorize(n / z);
                q.push(n / z);
                ans++;
            }
        }
    }
    */
    cout << ans << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

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

//素因数分解 O(sqrt(n))
//exin: 75 out: {{3,1}, {5,2}}
vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for(int i = 2; (ll)i * i <= n; ++i) {
        if(n % i)
            continue;
        res.emplace_back(i, 0);
        while(n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1)
        res.emplace_back(n, 1);
    return res;
}


Measured memory_bytes: 3636
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    # return max({i | i*i < a*b})
    # binary search
    def square_range(a, b):
        left = a
        right = b - 1
        while left < right:
            center = (left + right + 1) // 2
            if center * center < a * b:
                left = center
            else:
                right = center - 1
        return left

    q = int(input())
    ans = [0] * q

    for lap in range(q):
        a, b = map(int, input().split())

        if a < b:
            mid = square_range(a, b)
        else:
            mid = square_range(b, a)

        if mid * (mid + 1) < a * b:
            ans[lap] = (2 * mid - 1)
        else:
            ans[lap] = (2 * mid - 2)
    
    for i in ans:
        print(i)

main()

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

int main() {
  int N;
  cin >> N;
  set<int> paper;
  int A;
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (paper.count(A)) {
      paper.erase(A);
    }
    else {
      paper.insert(A);
    }
  }
  cout << paper.size() << endl;
}

Measured memory_bytes: 8192
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <int> N;
    for (int i = 1000000; i; i /= 10) {
        if (n / i) {
            N.push_back(n / i % 10);
        }
    }

    int sz = N.size();
    if (sz == 1) {
        cout << n << '\n';
        return 0;
    }

    ll ans = 0;
    for (int a = 1; a <= n; a++) {
        int head;
        for (int i = 1000000; i; i /= 10) {
            if (a / i) {
                head = a / i;
                break;
            }
        }

        int tail = a % 10;

        if (tail == 0) continue;
        if (head == tail) ans++;

        int tmp = 1;
        for (int i = 1; i < sz - 1; i++) {
            ans += tmp;
            tmp *= 10;
        }

        if (N[0] > tail) {
            ans += tmp;
        } else if (N[0] == tail) {
            int n_sub = 0;
            for (int i = 1; i < sz; i++) {
                n_sub *= 10;
                n_sub += N[i];
            }

            ans += (n_sub - head + 10) / 10;
        }
    }

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

Measured memory_bytes: 888
import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv;

void main() {
  int[char] dic;

  foreach (c; readln.chomp) {
    if (c !in dic) {
      dic[c] = 1;
    } else {
      dic[c]++;
    }
  }

  writeln(dic.values.all!(n => n % 2 == 0) ? "Yes" : "No");
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    vector<bool> f(n,true);
    REP(i,n){
        if(i>=k&&t[i-k]==t[i]&&f[i-k]==true){
            f[i] = false;
            continue;
        }
        if(t[i]=='r') ans+=p;
        if(t[i]=='s') ans+=r;
        if(t[i]=='p') ans+=s;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    int sl = s.size();
    int tl = t.size();
    vector<vector<int>> lcs(sl + 1, vector<int>(tl + 1, 0));

    REP(i, sl) REP(j, tl) {
        if (s[i] == t[j]) {
            lcs[i + 1][j + 1] = lcs[i][j] + 1;
        } else {
            lcs[i + 1][j + 1] = max(lcs[i][j + 1], lcs[i + 1][j]);
        }
    }

    int l = lcs[sl][tl];
    string u;
    while (l > 0) {
        if (s[sl - 1] == t[tl - 1]) {
            u += s[sl - 1];
            sl--; tl--; l--;
        } else {
            if (lcs[sl][tl] == lcs[sl - 1][tl]) {
                sl--;
            } else {
                tl--;
            }
        }
    }
    reverse(ALL(u));
    if (!u.empty()) {
        cout << u << endl;
    }
}


Measured memory_bytes: 35584
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] lines = sc.nextLine().split(" ");
            Deque<Double> que = new ArrayDeque<>();
            Double a = 0.0;
            Double b = 0.0;
            for (String s:lines) {
                switch (s) {
                case "+":
                    a = que.pop();
                    b = que.pop();
                    que.push(b + a);
                    break;
                case "-":
                    a = que.pop();
                    b = que.pop();
                    que.push(b - a);
                    break;
                case "/":
                    a = que.pop();
                    b = que.pop();
                    que.push(b / a);
                    break;
                case "*":
                    a = que.pop();
                    b = que.pop();
                    que.push(b * a);
                    break;
                default:
                    que.push(Double.parseDouble(s));
                }
            }
            System.out.println(que.pop());
        }
    }
}


Measured memory_bytes: 26040
#include <bits/stdc++.h>
using namespace std;
const int N = 12;

int n, m;
vector<int> a[N];
int p[N];

bool c[1 << N];
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int k;
        cin >> k;
        while (k--)
        {
            int x;
            cin >> x;
            a[i].push_back(x - 1);
        }
    }
    for (int i = 0; i < m; ++i)
        cin >> p[i];
    int ans = 0;
    for (int x = 0; x < (1 << n); ++x)
    {
        int y = 0;
        for (int i = 0; i < m; ++i)
        {
            int q = 0;
            for (int j = 0; j < a[i].size(); ++j)
            {
                if ((x & (1 << a[i][j])))
                    ++q;
            }
            if (q % 2 == p[i])
                y = (y | (1 << i));
        }
        if ((y == (1 << m) - 1))
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int r,c,k;cin >> r >> c >> k;
  vector<string> m(r);
  int mi;
  mi = c-1;
  for(int i=0;i<r;i++) cin >> m[i];
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++) if(m[i][j]=='#'){
      mi = min(mi,j);
    }
  }
  int f[r][c];memset(f,-1,sizeof(f));
  int j = mi;
  int st = 0;
  while(j<c){
    vector<int> ff;
    bool al = false;
    for(int i=0;i<r;i++){
      if(m[i][j]=='#') {++st,al = true;}
      if(!al) f[i][j] = st+1;
      else f[i][j] = st;
    }
    if(j==mi){
      for(int jj=0;jj<j;jj++){
        for(int i=0;i<r;i++) f[i][jj] = f[i][j];
      }
    }
    if(!al){
      for(int i=0;i<r;i++) f[i][j] = f[i][j-1];
    }
    j++;
  }
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++) cout << f[i][j] << " ";
    cout << endl;
  }  
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 1280
def resolve():
    # 入力
    N = int(input())

    # 次の文字列のいずれかが登場したら条件にあわない
    ng_list_3 = [
        'AGC',
        'GAC',
        'ACG'
    ]
    ng_list_4 = [
        #'AAGC',
        #'ACGC',
        'AGGC',
        'ATGC',
        #'AGAC',
        #'AGCC',
        #'AGGC',
        'AGTC'
    ]

    # 文字列の先頭から探索
    
    memo = dict()
    # 文字列sの後ろにn文字をつなげるパターンの個数
    def count(s, n):
        # Sが条件に当てはまるか
        if len(s) >= 4:
            l4 = s[-4:]
            if l4 in ng_list_4:
                return 0
        
        if len(s) >= 3:
            l3 = s[-3:]
            if l3 in ng_list_3:
                return 0

        # 短縮
        if len(s) >= 4 and (s[-4:], n) in memo:
            return memo[(s[-4:], n)]
        
        # 最後までいったら
        if n == 0:
            return 1
        
        x = [
            count(s + 'A', n - 1),
            count(s + 'C', n - 1),
            count(s + 'G', n - 1),
            count(s + 'T', n - 1),
        ]
        x = sum(x) % (10**9 + 7)

        if len(s) >= 4:
            memo[(s[-4:], n)] = x
        
        return x

    print(count('', N))
    
resolve()

Measured memory_bytes: 8740
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] point = new int[N+1];
        for (int i = 1; i < N+1; i++) {
            point[i] = sc.nextInt();
        }
        StringBuilder sb = new StringBuilder();
        for (int i = K+1; i < N+1; i++) {
            if (point[i-K] < point[i]) {
                sb.append("Yes").append("\n");
            } else {
                sb.append("No").append("\n");
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 60528
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define clr(a,v) memset((a),(v),sizeof(a))

std::string s;
int x, y;
bool fl;
std::vector<int> vs[2];
bool dp[2][20010];

int main()
{
  std::cin >> s >> x >> y;

  int cnt = 0;
  rep( i, s.size() )
  {
    if( s[i] == 'F' )
      ++cnt;
    else
    {
      vs[fl].push_back( cnt );
      cnt = 0;
      fl ^= true;
    }
  }

  if( cnt )
    vs[fl].push_back( cnt );

  bool ans = true;

  dp[0][10000] = true;
  rep( i, vs[0].size() ) 
  {
    rep( j, 20001 )
      dp[(i+1)%2][j] = false;

    rep( j, 20001 )
    {
      if( j+vs[0][i] < 20000 )
        dp[(i+1)%2][j+vs[0][i]] |= dp[i%2][j];

      if( i && j-vs[0][i] >= 0 )
        dp[(i+1)%2][j-vs[0][i]] |= dp[i%2][j];
    }
  }

  if( !dp[vs[0].size()%2][x+10000] )
    ans = false;

  clr( dp, false );
  dp[0][10000] = true;
  rep( i, vs[1].size() )
  {
    rep( j, 20001 )
      dp[(i+1)%2][j] = false;

    rep( j, 20001 )
    {
      if( j+vs[1][i] <= 20000 )
        dp[(i+1)%2][j+vs[1][i]] |= dp[i%2][j];
      if( j-vs[1][i] >= 0 )
        dp[(i+1)%2][j-vs[1][i]] |= dp[i%2][j];
    }
  }

  if( !dp[vs[1].size()%2][y+10000] )
    ans = false;

  std::cout << (ans ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  long long a, b, x, y, ans = -1;
  cin>>a>>b;
  
  rep(i, 100000000){
    x = i * 8/100;
    y = i /10;
    
    if(x==a&& y == b) {
    ans = i;
    break;
    }
  }
  //cout<<5*(8/100)
 
  cout<<ans<<endl;
  return 0;
}

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

const int N = 100005;

int n, m;
int d[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	while(m--) {
		int u, v; cin >> u >> v;
		d[u] ^= 1; d[v] ^= 1;
	}
	for (int i = 2; i <= n; ++i) if (d[i] == 1) return printf("NO\n"), 0;
	printf("YES\n");
}

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

using ull = unsigned long long;

int main()
{
  ull x, y;
  cin >> x >> y;

  int ans = 1;
  while (true)
  {
    x *= 2;
    if (x > y)
    {
      break;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
};


Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[],int N){
  int i;
  for(i = 0; i < N; i++){
    if(i > 0 )printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int i,j,v;

  for(i = 1;i < N;i++){
    v = A[i];
    j = i - 1;

    while(A[j] > v && j >= 0){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A,N);
  }
}

int main(){
  int i,N;
  int A[100];

  scanf("%d",&N);
  for(i = 0;i<N;i++)scanf("%d",&A[i]);

  trace(A,N);
  insertionSort(A,N);
  
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	string s;
	cin >> s;
	rep(i, s.length()) {
		if (i % 2 == 0) cout << s[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 512
n,k = map(int,input().split())
a = list(map(int,input().split()))

ok = max(a)
ng = 0
for _ in range(50):
    mid = (ok+ng)//2
    if(mid==0):
        print(1)
        exit()
    cnt = 0
    for ai in a:
        cnt += (ai-1)//mid
    if(cnt <= k):
        ok = mid
    else:
        ng = mid

print(ok)

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

#define watch(x) cerr << "\n" \
					  << (#x) << " is " << (x) << endl
const double PI = 3.141592653589793238463;
const int MOD = 1000000007;
const long long MAXI = ULONG_MAX;

/*
$alil03

URL: url

Solution Begins here
*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	int dp[n + 1][3];
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	dp[1][0] = a[0];
	dp[1][1] = b[0];
	dp[1][2] = c[0];
	for (int i = 2; i <= n; i++)
	{
		dp[i][0] = a[i - 1] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i - 1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i - 1] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]});
}

Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int[] m = new int[N];
        for(int i = 0;i < N;i++){
            m[i] = sc.nextInt();
            X -= m[i];
        }
        Arrays.sort(m);
        int count = N;
        while(X >= m[0]){
            X -= m[0];
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int total = 0, rck = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'g') {
            if (rck) {
                total++;
                rck--;
            } else rck++;
        } else {
            if (rck) rck--;
            else {
                rck++;
                total--;
            }
        }
    }
    cout << total << "\n";
    return 0;
}

Measured memory_bytes: 512
type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI32()]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextI64()]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF32()]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [for _ in 0 .. n - 1 -> this.NextF64()]

    member public __.Tuple2List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]]
    
    member public __.Tuple3List n (f : int -> 'a list) =
        [for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]]

end

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let s = scanner.Next()
    let ss = s.ToCharArray(0, (String.length s)) |> Array.sort |> Array.toList


    let bc x y i =
        if
            x = y then i + 1
        else
            if i % 2 = 0 then 1 else -1

    let rec b c co = function
        | (x::xs) ->
            let i = bc x c co
            if i = -1 then
                "No"
            else
                b x i xs
        | x -> if co % 2 = 0 then "Yes" else "No"

    b ' ' 0 ss |> printfn "%s"

    0


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

	int main (){
		int W,H;
		for (;;){
			cin >>W>>H;
			if(W==0&&H==0)
				break;

			for (int i=0;i<W;i++){
				for (int j=0;j<H;j++){
					cout<<"#";
				}
				cout <<endl;
			}cout <<endl;
		}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int FB, F, B;
  FB = N / 15;
  F = N / 3;
  B = N / 5;
  
  long long ans = 0;
  
  for(int i = 1; i <= N; i++) {
    ans += i;
  }
  
  for(int i =1 ; i <= F; i++) {
    ans -= i*3;
  }
  
  for(int i =1 ; i <= B; i++) {
    ans -= i*5;
  }
  
  for(int i =1 ; i <= FB; i++) {
    ans += i*15;
  }  
  
  cout << ans << endl;
}

Measured memory_bytes: 3600
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

if n == m:
    if a == b:
        print('Yes')
    else:
        print('No')
    exit()

for i in range(n-m+1):
    for j in range(n-m+1):
        c = [l[j:j+m] for l in a[i:i+m]]
        if c == b:
            print('Yes')
            exit()

print('No')



Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

    int count5 = 0;
    int count7 = 0;
    
    REP(i, 3) {
        int a;
        cin >> a;
        if (a == 5)
            count5++;
        if (a == 7)
            count7++;
    }

    cout << (count5 == 2 && count7 == 1 ? "YES" : "NO") << endl;
    
    return 0;
}


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

using namespace std;

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

    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        int match = (a[i] == b[i]) + (a[i] == c[i]) + (b[i] == c[i]);
        if (match == 1) {
            count += 1;
        } else if (match == 0) {
            count += 2;
        }
    }

    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

void main()
{
    auto k = readln.chomp.to!long;
    writeln((k/2) * (k - (k/2)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;

int gcd(int a,int b){ //a>b
    int tmp=a%b;
    a=b;
    b=tmp;
    if(b!=0){
        return gcd(a,b);
    }else{
        return a;
    }
}


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

    int k;
    cin >>k;
    ll sum=0;
    vector<vector<int>> cmb(k,vector<int> (k,0));
    ++k;
    ll g;
    fr(a,1,k){
        fr(b,a,k){
            g=gcd(a,b);
            cmb.at(a-1).at(b-1)=g;
            cmb.at(b-1).at(a-1)=g;
        }
    }
    --k;
    fr(a,0,k){
        fr(b,0,k){
            fr(c,0,k){
                sum+=cmb.at(a).at(cmb.at(b).at(c)-1);
            }
        }
    }
    cout << sum << "\n";
}   

Measured memory_bytes: 3724
// Last Change: 05/20/2019 19:08:14.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

class UnionFind {
private:
  ll unionSize;
  vector<long long> vec;

private:
  long long FindRoot(long long ipt) {
    if (vec[ipt] == ipt) {
      return ipt;
    } else {
      vec[ipt] = FindRoot(vec[ipt]);
      return vec[ipt];
    }
  }

public:
  UnionFind() = delete;
  UnionFind(const UnionFind &another) = delete;
  UnionFind(long long size) : unionSize(size) {
    vec.resize(size);
    for (long long i = 0; i < size; ++i) {
      vec[i] = i;
    }
  }

  ll GetUnionSize() {
    return unionSize;
  }

  bool Same(long long a, long long b) {
    return FindRoot(a) == FindRoot(b);
  }

  void Union(long long a, long long b) {
    long long x = FindRoot(a);
    long long y = FindRoot(b);

    //改造部
    if (x != y) {
      --unionSize;
    }

    vec[y] = x;
  }
};

int main() {
  ll N, M;
  cin >> N >> M;

  UnionFind unf(N);
  ll x, y, z;
  for (ll i = 0; i < M; ++i) {
    cin >> x >> y >> z;
    unf.Union(x, y);
  }

  ll separateNum = unf.GetUnionSize();
  cout << separateNum << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 1024
#include <iostream>


using namespace std;

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

    long long int result = 0, first, second;

    first = W/2 + W%2;
    second = H/2 + H%2;


    if (H==1 || W==1) {
        result += 1;
        cout << result << endl;
    } else {
        result += (long long int)(first*second);
        result += (long long int)((W-first)*(H-second));

        cout << (long long int)(result) <<endl;
    }

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    for(auto& i : v) cin >> i;
    sort(v.begin(), v.end());

    double ans = 0.0;
    for(int i = 1; i < n; ++i)
    {
        v[i] = (v[i] + v[i - 1]) / 2.0;
    }
    cout << v.back() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int min(int a ,int b){
    if(a>b){
        return(b);
    }else{
        return(a);
    }
}
int max(int a ,int b){
    if(a<b){
        return(b);
    }else{
        return(a);
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    int dan[n+1];
    for(int i=0;i<=n;i++){
        dan[i]=0;
    }
    for(int i=0;i<m;i++){
        int aa;
        cin>>aa;
        dan[aa]=-1;
    }
    if(dan[0]!=-1){
        dan[0]=1;
    }else{
        dan[0]=0;
    }
    if(dan[0]!=-1&&dan[1]!=-1){
        dan[1]=1;
    }else{
        dan[1]=0;
    }
    
    for(int i=2;i<=n;i++){
        if(dan[i]!=-1){
            dan[i]=dan[i-1]+dan[i-2];
        }else{
            dan[i]=0;
        }
        dan[i]=dan[i]%1000000007;
    }
    cout<<dan[n]<<endl;
    return(0);
}

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

int main(){
  string s;
  cin >> s;
  bool flag = true;
  for(int i = 0; i < s.length(); i++){
    if (i % 2 == 0 && s[i] == 'L') flag = false;
    else if(i % 2 == 1 && s[i] == 'R') flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A);
	rep(i, N - 2) {
		if (A[i] == A[i + 1] && A[i + 1] == A[i + 2]) {
			cout << 0 << endl;
			return 0;
		}
	}
	vector<lint>X;
	vector<lint>Y;
	rep(i, N - 1) {
		if (A[i] == A[i + 1]) {
			X.push_back(A[i]);
			X.push_back(24 - A[i]);
			A[i] = -1;
			A[i + 1] = -1;
		}
	}
	rep(i, N) {
		if (A[i] != -1) {
			Y.push_back(A[i]);
		}
	}
	lint x = X.size();//kotei
	lint y = Y.size();//ugokasu

	

	lint cnt = 10000;
	lint ans = 0;

	
	for (int S = 0; S < 1 << y; S++) {
		cnt = 10000;
		//作成
		vector<int>V;
		rep(i, y) {
			V.push_back(S >> i & 1);
		}
		//操作
		vector<lint>CY = Y;
		rep(i, y) {
			if (V[i] == 0) {
				CY[i] = CY[i];
			}
			else {
				CY[i] = 24 - CY[i];
			}
		}
		CY.insert(CY.end(), X.begin(), X.end());
		CY.push_back(0);

		

		rep(i, CY.size()) {
			rep(j, CY.size()) {
				if (i != j) {
					cnt = min(cnt, min(24-abs(CY[i] - CY[j]),abs(CY[i]-CY[j])));
				}
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << enld;
}

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

bool judg(std::string s, int begin, int end){
    int length = (end - begin) / 2;
    std::string S1 = {}, S2 = {};
    
    for(auto i = 0; i < length; i++){
        S1 += s.at(begin + i);
        S2 += s.at(end - i);
    }

    if(S1.empty() && S2.empty() && s.size() != 3){
        return false;
    }

    return S1 == S2;
}

int main(){
    std::string S;
    std::cin >> S;
    int length = S.size();

    if(judg(S, 0, length - 1) && judg(S, 0, (length - 1) / 2 - 1) && 
        judg(S, (length + 1) / 2, length - 1)){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[2001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = ++(h->size);
	data tmp;
	h->obj[i] = x;
	while (i > 1) {
		if (h->obj[i].key > h->obj[i>>1].key) {
			tmp = h->obj[i>>1];
			h->obj[i>>1] = h->obj[i];
			h->obj[i] = tmp;
			i >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j = i << 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, N;
	data d;
	max_heap h;
	h.size = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(d.key));
		d.id = i;
		push(d, &h);
	}
	
	int j;
	long long dp[2][2001] = {}, ans = 0;
	while (h.size > 0) {
		d = pop(&h);
		for (i = h.size % 2, j = N - h.size; j > 0; j--) dp[i][j] = dp[i^1][j-1] + (long long)(d.key) * (d.id - j);
		dp[i][0] = dp[i^1][0] + (long long)(d.key) * (h.size + 1 - d.id);
		for (j = N - h.size - 1; j > 0; j--) dp[i][j] = (dp[i][j] > dp[i^1][j] + (long long)(d.key) * (h.size + 1 + j - d.id))? dp[i][j]: dp[i^1][j] + (long long)(d.key) * (h.size + 1 + j - d.id);
	}
	for (j = 0; j <= N; j++) if (dp[0][j] > ans) ans = dp[0][j];
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1784
def gifts(li):
    if li[1] == "BTC":
        return float(li[0]) * 380000 
    else:
        return float(li[0])
n = int(input())
li_xu = []
sum = 0
for i in range(n):
    li_xu = input().split()
    sum += gifts(li_xu)
print(sum)


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long
#define MX 100010

int n;
int total;
vector<int> G[MX];
int colr[MX];

void DFS(int x,int pre,int c,int &tot)
{
    if (colr[x]==-c) return;
    tot++;
    for (int i=0;i<G[x].size();i++)
        if (G[x][i]!=pre)
            DFS(G[x][i],x,c,tot);
}

void dfs(int u,int pre,int s,int &ok)
{
    if (u==n)
    {
        ok=s;
        return;
    }
    for (int i=0;i<G[u].size();i++)
    {
        if (ok) break;
        if (G[u][i]!=pre)
            dfs(G[u][i],u,s+1,ok);
    }
    if (ok)
    {
        if (u!=1&&s<=ok/2) colr[u]=1;
        if (u!=n&&s>ok/2) colr[u]=-1;
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    colr[1]=1; //hei
    colr[n]=-1;//bai

    int ok=0;
    dfs(1,-10,0,ok);
/*
    for (int i=1;i<=n;i++)
        printf("%d ",colr[i]);
    printf("\n");
*/

    int num_1=0;
    DFS(1,-10,1,num_1);
    int num_2=0;
    DFS(n,-10,-1,num_2);
    if (num_1-num_2>=1)
        printf("Fennec\n");
    else
        printf("Snuke\n");
    return 0;
}

Measured memory_bytes: 13952