akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	long long ret=0;
	init_C(1100000);
	for(int i=0;i<=a;i++){
		if(i%2==0){
			ret=(ret+Comb(a,i)*Comb(b,i)%mod*Comb(b-i,a-i)%mod*Comb(b-i,a-i)%mod*fact[i]%mod*fact[a-i]%mod*fact[a-i])%mod;
		}else{
			ret=(ret+mod-Comb(a,i)*Comb(b,i)%mod*Comb(b-i,a-i)%mod*Comb(b-i,a-i)%mod*fact[i]%mod*fact[a-i]%mod*fact[a-i]%mod)%mod;

		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 27504
import sys


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i ^= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())
    bit = Bit(n)
    a = list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(n):
        bit.add(i+1, a[i])
    for x in sys.stdin.buffer.readlines():
        q, p, x = map(int, x.split())
        if q:
            print(bit.sum(x) - bit.sum(p))
        else:
            bit.add(p+1, x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 90168
import scala.io.StdIn._

object Main{
    def main(args:Array[String]){
        val s = readLine.split(" ")
        if (s(0).last == s(1).head && s(1).last == s(2).head) {
            printf("YES\n")
        } else {
            printf("NO\n")
        }
    }
}

Measured memory_bytes: 27304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,K; cin >> A >> B >> K;
    vector<int> X = {A,B};
    for(int i = A + 1; i < A + K; i++)
    {
        if(i <= B)
        {
            X.push_back(i);
        }
    }
    for(int i = B; i >  B - K; i--)
    {
        if(i >= A)
        {
            X.push_back(i);
        }
    }
    sort(X.begin(),X.end());
    int cnt = -1;
    for(int i:X)
    {
        if(cnt != i)
        {
            cout << i << endl;
        }
        cnt = i;
    }
    
}

Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;

int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}

int main() {
	int n, k;
	int l[55];
	cin >> n >> k;
	rep(i, n) {
		cin >> l[i];
	}
	sort(l, l + n,greater<int>());
	int ans = 0;
	rep(i, k) {
		ans += l[i];
	}
	cout << ans << endl;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,m,k;
        cin>>n>>m>>k;
        vector<int> a(n),b(m);
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<m;i++)cin>>b[i];
        for(int i=1;i<n;i++)a[i]+=a[i-1];
        for(int i=1;i<m;i++)b[i]+=b[i-1];
        int ans = upper_bound(all(b),k) - b.begin();
        for(int i=0;i<n;i++)
        {
            if(k-a[i]<0)break;
            int from_b = upper_bound(all(b),k-a[i]) - b.begin();
            ans = max(ans,from_b+i+1);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;cin>>n;
    cout<<n*(n-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

int main(){

  llong n;
  int value[4], weight[4];
  vector<pair<double, int >> v;

  int w = 25;
  REP(i,4){
    scanf("%d", &value[i]);
    v.pb(MP((double)w / value[i], i));
    weight[i] = w;
    w *= 2;
  }

  scanf("%lld", &n);
  n *= 100;

  sort(v.begin(), v.end(), greater<pair<double, int>>());

  llong res = 0;
  REPI(itr,v){
    int i = itr->second;
    res += (n / weight[i]) * value[i];
    n -= (n / weight[i]) * weight[i];
    if(n == 0) break;
  }

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



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

int main(void){
    int N , M;
    cin >> N >> M;
    vector<bool> a(200000);
    vector<bool> b(200000);
    for (int i = 0;i < 200000; i++){
        a[i] = 0;
        b[i] = 0;
    }
    if (N < 3 && N > 200000 && 1 > M && M > 200000){
        return 0;
    }
    for (int i = 0;i < M; i++){
        long long from,to;
        cin >> from >> to;
        if(from == 1){
            a[to] = true;
        }
        if(to == N){
            b[from] = true;
        }
    }
    for (int i = 0;i < N; i++){
        if(a[i] && b[i]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
string w;
int cnt[150];
int main()
{
	cin >> w;
	for(int i = 0; w[i]; i++) {
		cnt[w[i] - 97]++;
	}
	int i;
	for(i = 0; i < 26; i++) {
		if(cnt[i] % 2 == 1){
			break;
		}
	}
	if(i == 26){
		cout << "Yes";
	}else{
		cout << "No";
	}
    return 0;
}


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

long long f(long long a, long long b) {
    if (a == 0) {
        int i = (b + 1) / 2;
        int j = (b + 1) % 2;
        if (i % 2 == 0) {
            if (j == 0) {
                return 0;
            }
            else return b;
        }
        else {
            if (j == 0) {
                return 1;
            }
            else {
                return (b ^ 1);
            }
        }
        
    }
    else {
        return (f(0, a - 1) ^ f(0, b));
    }
}

int main() {
    long long a,b;
    cin >> a >> b;
    cout << f(a,b) << endl;
}

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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;

    vector<p64> xy(n);
    for (auto& e : xy) cin >> e.first >> e.second;

    map<p64, i64> cnt;
    cnt[{ INF, INF }] = 0;
    for (auto& e : xy) {
        for (auto& f : xy) {
            if (e == f) continue;
            cnt[{ e.first - f.first, e.second - f.second }]++;
        }
    }

    i64 ans = INF;
    for (auto& e : cnt) ans = min(ans, n - e.second);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>

using lint = long long;

constexpr lint INF = std::numeric_limits<lint>::max() / 3;

lint cost(lint a, lint b) {
    return std::max(0LL, b - a);
}

int main() {
    int n, k;
    std::cin >> n >> k;

    std::vector<lint> hs(n);
    for (auto& h : hs) std::cin >> h;
    hs.insert(hs.begin(), 0);
    hs.push_back(0);

    std::vector<std::vector<lint>>
        dp(n + 2, std::vector<lint>(k + 1, INF));
    dp[0][0] = 0;

    for (int i = 1; i <= n + 1; ++i) {
        for (int j = 0; j < i; ++j) {
            int p = i - j - 1;
            for (int l = 0; l + p <= k; ++l) {
                dp[i][l + p] = std::min(dp[i][l + p],
                                        dp[j][l] + cost(hs[j], hs[i]));
            }
        }
    }

    std::cout << *min_element(dp[n + 1].begin(), dp[n + 1].end()) << std::endl;
    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right)
{
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r)
{
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++) {
        if (A[j].value <= x.value) {
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r)
{
    int q;
    if (p < r) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main(int argc, char const *argv[])
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for (i = 0; i < n; i++) {
        // マージソートとクイックソートの結果を比べる
        if (A[i].suit != B[i].suit) stable = 0;
    }
    
    if (stable == 1) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
    for (i = 0; i < n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}



Measured memory_bytes: 4084
from collections import Counter, deque
from itertools import product

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]


def bfs():
    dist = [[float('inf') for _ in range(W)] for _ in range(H)]
    mx = [1, 0, -1, 0]
    my = [0, 1, 0, -1]

    sx, sy = 0, 0
    gx, gy = W - 1, H - 1

    que = deque()
    que.append((sx, sy))
    dist[sy][sx] = 0

    while que:
        x, y = que.popleft()
        if x == gx and y == gy:
            break

        for dx, dy in zip(mx, my):
            nx = x + dx
            ny = y + dy
            if 0 <= nx < W and 0 <= ny < H:
                if maze[ny][nx] != '#' and dist[ny][nx] == float('inf'):
                    que.append((nx, ny))
                    dist[ny][nx] = dist[y][x] + 1

    return dist[gy][gx]


res = bfs()
if res == float('inf'):
    ans = -1
else:
    white = 0
    for i, j in product(range(H), range(W)):
        if maze[i][j] == '.':
            white += 1
    ans = white - res - 1
print(ans)


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

int main(){
  int n;
  int coin[] = {500, 100, 50, 10, 5, 1};

  while(cin >> n, n){
    n = 1000 - n;
    int sum = 0;
    for(int i = 0; i < 6; i++){
      sum += n / coin[i];
      n %= coin[i];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
import itertools
p = list(itertools.permutations(range(8)))
n = int(input())
k = [list(map(int,input().split())) for i in range(n)]
for d in p:
    f = True
    for r,c in k:
        if d[r]!=c:
            f = False
    if not f:continue
    for i in range(8):
        for j in range(8):
            if i==j:continue
            if i+d[i]==j+d[j]:
                f = False
            if i-d[i]==j-d[j]:
                f = False
    if f:
        for i in d:
            s = ['.']*8
            s[i]='Q'
            print(''.join(s))


Measured memory_bytes: 10464
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
class FastIO
{
    static const int rdata_sz = (1 << 22), wdata_sz = (1 << 22);
    char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
    char tmp_s[10];

public:
    FastIO()
    {
        fread(rdata, 1, rdata_sz, stdin);
        rb = rdata;
        wb = wdata;
    }
    ~FastIO()
    {
        fwrite(wdata, 1, wb - wdata, stdout);
    }

    template <typename T>
    inline void read(T &x)
    {
        bool neg = false;
        x = 0;
        while ((*rb < '0' || *rb > '9') && *rb != '-')
            ++rb;
        while ('0' <= *rb && *rb <= '9')
        {
            x = 10 * x + (*rb - '0');
            ++rb;
        }
        if (neg)
            x = -x;
    }

#define pc(x) *(wb++) = x
    template <typename T>
    inline void write(T x)
    {
        if (x == 0)
        {
            pc('0');
            pc(' ');
            return;
        }
        char *t = tmp_s;
        while (x)
        {
            T y = x / 10;
            *(t++) = (x - y * 10) + '0';
            x = y;
        }
        while (t != tmp_s)
            pc(*(--t));
        pc(' ');
    }
#undef pc
};
int par[500001];
int ran[500001];
//要素xが所属する木の根を再帰的に発見する
inline int root(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]); //経路圧縮
}
//要素xが属する木と要素yが属する木の併合
inline void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
        return; //同じ木に属してたらそのまま
    if (ran[rx] < ran[ry])
    {
        par[rx] = ry; //根がryの木に併合
    }
    else
    {
        par[ry] = rx; //根がrxの木に併合
        if (ran[rx] == ran[ry])
            ran[rx]++;
    }
}
//要素xが属する木と要素yが属する木が同じならtrueを返す
inline bool same(int x, int y)
{
    return root(x) == root(y);
}
int main()
{
    FastIO io;
    int N, Q;
    io.read(N);
    io.read(Q);
    for (int i = 0; i < N; i++)
    {
        par[i] = i;
        ran[i] = 0;
    }
    for (int i = 0; i < Q; i++)
    {
        int a, b, c;
        io.read(a);
        io.read(b);
        io.read(c);
        if (a == 1)
            if (same(b, c))
                io.write(1);
            else
                io.write(0);
        if (a == 0)
            unite(b, c);
    }
    return 0;
}


Measured memory_bytes: 7300
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] stringArray = br.readLine().split("\\s");

        Deque<Integer> que = new ArrayDeque<>();
        int a = 0;
        int b = 0;
        for (int i = 0; i < stringArray.length; i++) {
            switch (stringArray[i]) {
            case "+":
                a = que.pollFirst();
                b = que.pollFirst();
                que.addFirst(b + a);
                break;
            case "-":
                a = que.pollFirst();
                b = que.pollFirst();
                que.addFirst(b - a);
                break;
            case "/":
                a = que.pollFirst();
                b = que.pollFirst();
                que.addFirst(b / a);
                break;
            case "*":
                a = que.pollFirst();
                b = que.pollFirst();
                que.addFirst(b * a);
                break;
            default:
                que.addFirst(Integer.parseInt(stringArray[i]));
            }
        }
        System.out.println(que.pop());
    }
}


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

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))

int h,w,n,num;
int mp[111][111];

int main()
{
    cin>>h>>w;
    cin>>n;
    int row=1,loc=1;
    F(i,1,n)
    {
        cin>>num;
        int j=0;
        while(j<num)
        {
            //printf("row=%d\n",row );
            if(row&1)
            {
                while(loc<=w)
                {
                    mp[row][loc]=i;
                    j++;loc++;
                    //printf("i=%d j=%d loc=%d row=%d\n", i,j,loc,row);
                    if(loc==(w+1)) {row++,loc=w;goto loop;}
                    if(j==num) goto loop;
                }
            }
            else
            {
                while(loc>=1)
                {
                    mp[row][loc]=i;
                    j++;loc--;
                    //printf("i=%d j=%d loc=%d\n", i,j,loc);
                    if(loc==0) {row++,loc=1;goto loop;}
                    if(j==num) goto loop;
                }
            }
        loop:;
        }
    }
    F(i,1,h)F(j,1,w) printf("%d%c",mp[i][j],j==w?'\n':' ' );
    return 0;
}

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

const int MAXN = 2e5 + 10;
bool a[MAXN], dl[MAXN];
int n, m, deg[MAXN][2];
vector<int> Mat[MAXN];
queue<int> del;

void ers(int v) {
	for (int i = 0; i < Mat[v].size(); i++) {
		if (dl[Mat[v][i]])
			continue;
		deg[Mat[v][i]][a[v]]--;
		if (deg[Mat[v][i]][0] == 0 || deg[Mat[v][i]][1] == 0)
			del.push(Mat[v][i]), dl[Mat[v][i]] = true;
	}
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		char tmp;
		cin >> tmp;
		a[i] = (tmp == 'A');
	}
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		Mat[u].push_back(v);
		Mat[v].push_back(u);
		deg[u][a[v]]++;
		deg[v][a[u]]++;
	}
	for (int i = 1; i <= n; i++)
		if (deg[i][0] == 0 || deg[i][1] == 0)
			del.push(i), dl[i] = true;
	while (!del.empty()) {
		ers(del.front());
		del.pop();
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += !dl[i];
	if (ans)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 12544
import Data.List
 
main = do
  getLine
  xs <- map read . words <$> getLine :: IO [Int]
  let a = map (\x -> (head x, length x)) . group . sort $ xs
  print $ solve a
 
solve :: [(Int, Int)] -> Int
solve [] = 0
solve (x:xs)
  | snd x >= fst x = snd x - fst x + solve xs
  | otherwise      = snd x + solve xs

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

int main() {
    int N;
  	float A[10010]; 
    cin >> N;
  	for(int i=0; i<N; i++) cin >> A[i];
  
  	float ans = 0;
   	if (N==1) {
      ans =	A[0];
    } else {
      sort(A, A+N);
      float a = 0;
      for(int i=0; i<N-1; i++) {
      	float second = 2;
        a = (A[i]+A[i+1])/second;
        A[i+1] = a;
      }
      ans = a;
    }
  	cout << ans << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<bool> prime(51, true);
  for(int i=2;i<=int(sqrt(50));i++){
  	for(int j=2*i;j<=50;j+=i){
      prime[j]=false;
    }
  }
  vector<int> prime_num;
  for(int i=2;i<51;i++){
  	if(prime[i])prime_num.push_back(i);
  }
  int n_prime=(int)prime_num.size();
  vector<int> prime_cnt(n_prime, 0);
  for(int i=1;i<=n;i++){
    int t=i;
  	for(int j=0;j<n_prime;j++){
      int cnt=0;
      while(t%prime_num[j]==0){t/=prime_num[j];cnt++;}
      prime_cnt[j]+=cnt;
    }
  }
  int p2, p4, p14, p24, p74;
  p2=p4=p14=p24=p74=0;
  for(int i=0;i<n_prime;i++){
  	if(prime_cnt[i]>=74)p74++;
    else if(prime_cnt[i]>=24)p24++;
    else if(prime_cnt[i]>=14)p14++;
    else if(prime_cnt[i]>=4)p4++;
    else if(prime_cnt[i]>=2)p2++;
  }
  int ans=0;
  ans += p74;
  ans += (p74+p24)*(p74+p24-1) + (p74+p24)*(p2+p4+p14);
  ans += (p74+p24+p14)*(p74+p24+p14-1) + (p74+p24+p14)*p4;
  ans += p2*(p74+p24+p14+p4)*(p74+p24+p14+p4-1)/2
    + (p74+p24+p14+p4)*(p74+p24+p14+p4-1)*(p74+p24+p14+p4-2)/2;
  cout<<ans<<endl;
}

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

int main() {
  int n; cin >> n;
  ll k; cin >> k;
  vector<int> v;
  ll c[100001] = {};
  for (int i = 0; i < n; i++) {
    int a, b; cin >> a >> b;
    if (c[a] == 0) v.push_back(a);
    c[a] += b;
  }
  sort(v.begin(), v.end());
  ll sum = 0;
  for (int i = 0; i < v.size(); i++) {
    sum += c[v[i]];
    if (sum >= k) {
      cout << v[i] << endl;
      break;
    }
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s; cin>>s;
    if(s<="2019/04/30") cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
    return 0;
}


Measured memory_bytes: 256
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

	set<int> yes,no;

	rep(i,8) no.insert(i);
	int n;
	cin >> n;
	int x;
	int ext = 0;
	rep(i,n){
		cin >> x;
		x /= 400;
		if(x >= 8) ext++;
		else{
			yes.insert(x),no.erase(x);
		}
	}

	cout << max(int(yes.size()),1) << " " << yes.size() + ext << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define si(n) scanf("%d",&n);
#define pi(n) printf("%d\n",n);
#define pl(n) printf("%lld\n",n);
#define sl(n) scanf("%lld",&n);
#define pd(n) printf("%lf\n",n);
#define ss(s) scanf("%s",s);
#define ps(s) printf("%s\n",s);
#define ll long long int
#define pb push_back
#define maxn 100005
#define sqrtn 317
#define maxm 2e9
#define pii pair<int,int>
#define eps 1e-9
#define mod 1000000007
using namespace std;
int arr[maxn];
int main()
{
    ll ans=0;
    int n;si(n);
    for(int i=1;i<=n;i++)
        si(arr[i]);
    int rem=0;
    for(int i=1;i<=n;i++)
    {
        if(rem&arr[i]>0)
        {
            ans++;
            arr[i]--;
        }
        ans=ans+arr[i]/2;
        rem=arr[i]%2;

    }
    pl(ans);

}


Measured memory_bytes: 640
# @Author: Amit Dwivedi
# @Date:   2019-12-22 11:55:43
# @Last Modified by:   Amit Dwivedi
# @Last Modified time: 2019-12-22 12:02:10
ll= lambda : list(map(int,input().split()))
testcases=1
# testcases=int(input())
for testcase in range(testcases):
	[a]=ll()
	[b] = ll()
	x =[1,2,3]
	for i in x:
		if(i!=a and i!=b):
			print(i)

	

Measured memory_bytes: 2940
import bisect


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += (a * c)

print(ans)


Measured memory_bytes: 22720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int h[200005]={0};
int used[200005]={0};
int main(){
  string S;
  cin>>S;
  int n=S.size();
//  cout<<n<<endl;
  ll ans=0;
for(int j=1;j<=n;j++){
  if(S[j-1]=='A')h[j]=1;
  else if(S[j-1]=='B')h[j]=2;
  else h[j]=3;
}
  int i=1;
    ll a =0;
  while(i<=n){

    if(h[i]==2&&h[i+1]==3){
      ans+=a;
      i+=2;
    }
    else if(h[i]==1){
      a++;
      i++;
    }
    else{
      i++;
      a=0;
    }

  }
  cout<<ans<<endl;
}


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

#define int long long
#define scan(a,n)  for(int i = 0; i < n;i++)cin >> a[i];
#define print(a,n)  for(int i = 0;i < n;i++)cout <<a[i] <<' ';cout<<endl;
#define endl  '\n'
#define vi  vector<int>
#define inf 1e17
// Tushar Goyal : Chalie Shuru karte hai
#define db(...) 		__f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}


int dp[401][401];
int sum[401][401];
// sum[i][j] denotes the sum from index =i to index = j in vector a;
vi a(401);

int cost(int i, int j)
{
	if (i == j )return 0;
	if (dp[i][j] != -1)return dp[i][j];

	int mincost = inf;
	// transition time is O(n)
	for (int k = i ; k < j ; k++)
	{
		mincost = min(mincost, sum[i][j] + cost(i, k) + cost(k + 1, j));
	}

	return dp[i][j] = mincost;
}

void preprocess(vi a, int n)
{

	// O(n^2)
	for (int i = 0 ; i < n ; i++)
	{
		for (int j = i ; j < n; j++)
		{
			sum[i][j] = a[j];
			if (i != j)sum[i][j] += sum[i][j - 1];
		}
	}

}

void solve()
{
	int n; cin >> n;
	scan(a, n);
	// print(a, n);

	memset(dp, -1, sizeof dp);
	memset(sum, 0, sizeof sum);
	preprocess(a, n);

	/*	for (int i = 0 ; i < n ; i++)
		{
			for (int j = i ; j < n; j++)
			{
				db(i, j, sum[i][j]);
			}
		}
	*/

	cout << cost(0, n - 1) << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 6204
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N;
        is >> N;
        if(!is) return;
        
        cout << N * N * N << endl;


    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_A.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


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

//?????????????????????
template <typename TYPE>
class DList {
public:
	//????????????
	struct Node {
		TYPE value;
		Node* prev;
		Node* next;
	};

public:
	DList() { m_eol.prev = m_eol.next = &m_eol; }
	virtual ~DList() { Clear(); }

	//??????????????????????????????
	Node*		GetFirst() { return m_eol.next; }
	const Node* GetFirst() const { return m_eol.next; }

	//??????????????????????????????
	Node*		GetLast() { return m_eol.prev; }
	const Node* GetLast() const { return m_eol.prev; }

	//??????????????????????????????
	const Node* Eol() const { return &m_eol; }

	//?????????????????????????????´?????????????????\
	Node* Insert(Node* next, const TYPE& value) {
		assert(next != NULL);
		Node* node = new Node();
		Node* prev = next->prev;

		node->value = value;
		node->prev = prev;
		node->next = next;
		prev->next = node;
		next->prev = node;
		return node;
	}

	//?????????????????????????????????
	void Erase(Node* node) {
		assert(node != NULL);
		if (node == &m_eol) { return; }

		Node*prev = node->prev;
		Node* next = node->next;
		prev->next = next;
		next->prev = prev;
		delete node;
	}

	//????????????????????????????????\
	Node* Unshift(const TYPE& value) {
		return Insert(m_eol.next, value);
	}

	//??????????????????????????????
	void Shift() {
		Erase(m_eol.next);
	}

	//????????????????????????????????\
	Node* Push(const TYPE& value) {
		return Insert(m_eol.prev, value);
	}

	//??????????????????????????????
	void pop() {
		Erase(m_eol.prev);
	}

	//??????????????????????????????????????????????????????
	void Del1(TYPE& value) {
		Node* next;
		for (Node* node = m_eol.next; node != &m_eol; node = next) {
			next = node->next;
			if (node->value == value) {
				Erase(node);
				break;
			}
		}
	}

	//?????¨??????
	void Clear() {
		Node* next;
		for (Node* node = m_eol.next; node != &m_eol; node = next) {
			next = node->next;
			delete node;
		}
		m_eol.prev = m_eol.next = &m_eol;
	}

private:
	Node m_eol;
};

typedef DList<int> List;
typedef List::Node Node;

void Show(const List& list) {
	const Node* eol = list.Eol();
	const Node* head = eol->next;
	cout << head->value;
	for (const Node* node = head->next; node != eol; node = node->next) {
		cout << " " << node->value;
	}
	cout << "\n";
}

int main(void) {
	int n, m;
	string order;
	List list;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> order;
		if (order == "insert") {
			cin >> m;
			list.Unshift(m);
		}
		else if (order == "delete") {
			cin >> m;
			list.Del1(m);
		}
		else if (order == "deleteFirst") {
			list.Shift();
		}
		else if (order == "deleteLast") {
			list.pop();
		}
	}

	Show(list);

	return 0;
}

Measured memory_bytes: 34364
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <numeric>

using namespace std;

int main() {
    string s;
    cin >> s;
 
    int n = s.size();

    int ans = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            string t = s.substr(i, j);

            if (t.find_first_not_of("ACGT") == string::npos) {
                ans = max(ans, (int)t.size());
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    string s;
    cin >> n >> s;

    string buf="", buf2="";
    rep(i, n){
        if(i < n/2){
            buf += s[i];
        }else{
            buf2 += s[i];
        }
    }

    ans(buf==buf2);

    return 0;
}


Measured memory_bytes: 256
import sys

class Node():
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left, self.right = None, None

def insert(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        else:
            x = x.right
    
    if y == None:
        root = Node(z)
    elif z < y.key:
        y.left = Node(z)
    else:
        y.right = Node(z)
        
def find(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        elif z > x.key:
            x = x.right
        else:
            print("yes")
            return
    print("no")
        
def preorder(x):
    return f" {x.key}" + preorder(x.left) + preorder(x.right) if x else ""

def inorder(x):
    return inorder(x.left) + f" {x.key}" + inorder(x.right) if x else ""
        
input()
root = None
for s in sys.stdin:
    if s[0] == "p":
        print(inorder(root))
        print(preorder(root))
    elif s[0] == "f":
        find(int(s[5:]))
    else:
        insert(int(s[7:]))


Measured memory_bytes: 53440
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int Maxn = 1e6;

int N, s1, s2, t1, t2;
char s[Maxn + 5];
vector<int> t;

int main() {
	scanf("%d %d %d %d %d", &N, &s1, &s2, &t1, &t2);
	scanf("%s", s + 1);
	for(int i = s1; i < max(t1, t2); i++)
		if(s[i] == '#' && s[i + 1] == '#') {
			puts("No");
			return 0;
		}
	if(t1 < t2) {
		puts("Yes");
		return 0;
	}
	for(int i = s2 - 1; i <= t2 - 1; i++)
		if(s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 384
# 解説と提出#12551970を参考に作成
# 今いる都市と銀貨の所持数を状態として、
#   ①その都市から移動可能な別の都市に移動する
#   ②金貨を銀貨に交換する
# のどちらかを行い、実施後の(同都市・同所持銀貨枚数での)最小時間を計測していく。
# 最小時間が更新された場合、さらにその状態から①・②を行う。
# これによって全都市・全銀貨所持枚数毎の最小時間を割り出す。
# 都市の銀貨所持枚数毎の最小時間の中での最小時間がその都市へ行くための最小時間になる。
#   ※1: 都市への移動は移動可能な枚数の銀貨を持っている場合のみ可能
#   ※2: 銀貨の最大所持枚数は (N - 1) * max(Ai) とする
#        -> 一番遠い都市に移動する場合にかかりうる最大の銀貨枚数

from heapq import heappop, heappush


def solve():
    n, m, s = map(int, input().split())
    graph = [[] for _ in range(n)]
    # グラフ作製
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        graph[u - 1].append([v - 1, a, b])
        graph[v - 1].append([u - 1, a, b])
    ce = [[int(i) for i in input().split()] for _ in range(n)]
    # 初期値マップ作製
    maxSilver = 50 * 49  # max(a) * (n - 1)
    inf = float('inf')
    ns_map = [[inf] * (maxSilver + 1) for _ in range(n)]
    # スタート時の値設定と探索
    q = [[0, 0, min(maxSilver, s)]]  # 累計時間, 都市, 所持銀貨
    ns_map[0][min(maxSilver, s)] = 0  # スタート地点の時刻は0
    while q:
        ti, ni, si = heappop(q)
        # 移動
        for g in graph[ni]:
            n2, ai, bi = g
            if si >= ai and ns_map[n2][si - ai] > ti + bi:
                ns_map[n2][si - ai] = ti + bi
                # ★heapq で累計時間が少ない情報から先に処理するようにする.
                # これによって処理速度が全然違う
                heappush(q, [ti + bi, n2, si - ai])
        # 換金
        ci, di = ce[ni]
        ti += di
        si = min(si + ci, maxSilver)
        if ns_map[ni][si] > ti:
            ns_map[ni][si] = ti
            heappush(q, [ti, ni, si])
    for i in range(1, n):
        print(min(ns_map[i]))


if __name__ == '__main__':
    solve()


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

using namespace std;
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int inf = 1000000007;
const int N = 300 + 7;
const int multipleTest = 0;

int a[N][N];
int n;

int r[N];

int get(int u) {
    return (r[u] < 0) ? u : r[u] = get(r[u]);
}

void uni(int u, int v) {
    if (r[u] > r[v]) swap(u, v);
    r[u] += r[v];
    r[v] = u;
}

viii edge;

void solve() {
    cin >> n;
    rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
    ll res = 0;
    rep(i, 0, n) rep(j, i + 1, n) {
            bool ok = true;
            rep(k, 0, n) if (k != i && k != j) {
                if (a[i][k] + a[k][j] < a[i][j]) {
                    puts("-1");
                    return;
                }
                if (a[i][k] + a[k][j] == a[i][j]) ok = false;
            }
            if (ok) res += a[i][j];
        }
    cout << res;
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
        solve();
    }
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
  double a,b,h,m,ans,t;
  cin>>a>>b>>h>>m;
  t=abs((h/12+m/720)-m/60);
  ans=a*a+b*b-2*a*b*cos(2*M_PI*t);
  ans=pow(ans,0.5);
  printf("%.11f",ans);
}


Measured memory_bytes: 4356
use std::io::{self,Read};

fn main(){
  let (n, r) : (i32, i32) = {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf);
    let mut nr = buf.split_whitespace();
    
    ( nr.next().unwrap().parse().unwrap(),
      nr.next().unwrap().parse().unwrap())
  };
  
  if n >= 10 {
    println!("{}", r);
  } else {
    println!("{}", r + 100 * (10 - n)); 
  }
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"

using namespace std;

int main (){
	int a,b;
while(cin >> a >> b){
	if(a == 0 && b == 0) break; 
	for(int i = 1;i <= a;i++){
		if(i % 2 == 1){
			for(int x = 1;x <= b;x++){
				if(x % 2 == 1) cout <<"#";
				else cout << ".";
			}
		}else{
			for(int y = 1;y <= b;y++){
				if(y % 2 == 1)cout << ".";
				else cout << "#";
			}
		}
		cout << endl;

		}

	cout << endl;

}


return 0;
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    int dp[n],ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    if(n==0)
    {
        cout<<0;
        return 0;
    }
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        dp[i]=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(j<=i)
            dp[i]=min(dp[i-j]+abs(ar[i]-ar[i-j]),dp[i]);
        }

    }
    cout<<dp[n-1];
    return 0;
}


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

int main()
{
  uint64_t a, b, n;
  cin >> a >> b >> n;

  uint64_t x = b - 1;
  if (x > n)
  {
    x = n;
  }
  cout << floor(a * x / b) << endl;
}


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
const int INF = 1e9;
#define MAX 100
int al(char c) {
	if (c == 'a') { return 25; }
	else if (c == 'b') { return 0; }
	else if (c == 'c') { return 1; }
	else if (c == 'd') { return 2; }
	else if (c == 'e') { return 3; }
	else if (c == 'f') { return 4; }
	else if (c == 'g') { return 5; }
	else if (c == 'h') { return 6; }
	else if (c == 'i') { return 7; }
	else if (c == 'j') { return 8; }
	else if (c == 'k') { return 9; }
	else if (c == 'l') { return 10; }
	else if (c == 'm') { return 11; }
	else if (c == 'n') { return 12; }
	else if (c == 'o') { return 13; }
	else if (c == 'p') { return 14; }
	else if (c == 'q') { return 15; }
	else if (c == 'r') { return 16; }
	else if (c == 's') { return 17; }
	else if (c == 't') { return 18; }
	else if (c == 'u') { return 19; }
	else if (c == 'v') { return 20; }
	else if (c == 'w') { return 21; }
	else if (c == 'x') { return 22; }
	else if (c == 'y') { return 23; }
	else if (c == 'z') { return 24; }
}
int a[26];
int main(void) {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		a[al(s[i])] += 1;
	}
	bool f = true;
	for (int i = 0; i < 26; ++i) {
		if (a[i] % 2 != 0) {
			f = false;
			break;
		}
	}
	cout << (f ? "Yes" : "No") << endl;
	return 0;
}

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

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

int main(){
	int K, g, G, sum;
	g = G = sum = 0;
	cin >> K;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= i; j++) {
			for (int k = 1; k <= j; k++) {
				g = gcd(i, j);
				G = gcd(g, k);
				if ((i == j || j == k) && i != k) {
					G = 3*G;
					sum += G;
				}
				else if (i == j && j == k) {
					sum += G;
				}
				else {
					G = 6*G;
					sum += G;
				}
			}
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int cnt[3],k;
    cin >> cnt[0] >> cnt[1] >> cnt[2] >> k;
    vector<vector<ll>> cake(3);
    priority_queue<pair<ll,tuple<int,int,int>>> que;
    map<tuple<int,int,int>,bool> mp;

    for(int i = 0; i < 3; i++){
        for(ll j = 0; j < cnt[i]; j++){
            ll a; cin >> a;
            cake[i].push_back(a);
        }
    }
    for(int i = 0; i < 3; i++) sort(cake[i].begin(),cake[i].end(),greater<ll>());
    que.push({cake[0][0]+cake[1][0]+cake[2][0],make_tuple(0,0,0)});
    mp[make_tuple(0,0,0)] = true;
    for(int i = 0; i < k; i++){
        tuple<int,int,int> now = que.top().second; 
        ll sum = que.top().first;
        que.pop();
        vector<int> num(3);
        num[0] = get<0>(now);
        num[1] = get<1>(now);
        num[2] = get<2>(now);
        if(num[0] < cnt[0]-1 && !mp[make_tuple(num[0]+1,num[1],num[2])]){
            que.push({sum-cake[0][num[0]]+cake[0][num[0]+1],make_tuple(num[0]+1,num[1],num[2])});
            mp[make_tuple(num[0]+1,num[1],num[2])] = true;
        }
        if(num[1] < cnt[1]-1 && !mp[make_tuple(num[0],num[1]+1,num[2])]){
            que.push({sum-cake[1][num[1]]+cake[1][num[1]+1],make_tuple(num[0],num[1]+1,num[2])});
            mp[make_tuple(num[0],num[1]+1,num[2])] = true;
        }
        if(num[2] < cnt[2]-1 && !mp[make_tuple(num[0],num[1],num[2]+1)]){
            que.push({sum-cake[2][num[2]]+cake[2][num[2]+1],make_tuple(num[0],num[1],num[2]+1)});
            mp[make_tuple(num[0],num[1],num[2]+1)] = true;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 896
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            cur = min(c[a], c[b])
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 107028