akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi std::vector<int>
#define vvi std::vector<std::vector<int> >
#define vpi std::vector<pi >
#define pi std::pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (int var = (from); var <= ((int)(to)); var++)
#define DOWNTO(var, from, to) for (int var = (from); var >= ((int)(to)); var--)
#define FOR(var, to)		  UPTO(var, 0, (to)-1)
#define DOWN(var, from)	   DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) std::cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) std::cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		FOR(i,n+1) {
			a[i].resize(i+1, 1);
			UPTO(j,1,i-1) a[i][j] = a[i-1][j] + a[i-1][j];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

#define gc(c) (c)=getchar()
int ri() {
	int c,s=0,r=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}
s64 rs64() {
	s64 r = 0;
	int c,s = 0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}

int int_less(const void *a, const void *b) {
	return (*(const int*)a - *(const int*)b);
}
int int_greater(const void *a, const void *b) {
	return (*(const int*)b - *(const int*)a);
}
std::string operator*(const std::string &s, int n){ std::string res; FOR(i,n) res += s; return res; }

template<class T> std::ostream& operator<<(std::ostream& os, std::vector<T> a) { for (auto i : a) os << i << " "; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, std::set<T> a) { for (auto i : a) os << i << " "; return os; }
template<class A, class B> std::ostream& operator<<(std::ostream&os, std::pair<A,B> a) { os << a.fi << "," << a.se; return os; }


int main() {
	std::string s;
	std::cin >> s;
	int cnt = 0;
	for (auto c : s) if (c == 'o') cnt++;
	cnt += 15 - s.size();
	std::cout << (cnt >= 8 ? "YES" : "NO") << std::endl;
	
	return 0;
}


Measured memory_bytes: 256
main = do
    n <- read <$> getLine :: IO Int
    putans $ answer n

answer :: Int -> [Int]
answer n = let x = ceiling $ (*) 0.5 $ (+) (-1) $ sqrt $ fromIntegral $ 1 + 8 * n
               sumx = round $ (fromIntegral x)*(1+fromIntegral x)/2.0
           in filter ((/=) (sumx - n)) [1..x]

putans :: [Int] -> IO [()]
putans = sequence . map (putStrLn . show)


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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
const int INF = 1e9 + 10;


vector<int> LIS(maxN, INF);
vector<int> adj[maxN];
vector<int> arr(maxN);
vector<int> ans(maxN, 0);

void DFS(int node, int parent = -1){
	
	//TRATAR DE MODIFICARLO
	int indx = upper_bound(LIS.begin(), LIS.end(), arr[node]) - LIS.begin();
	int ant = LIS[indx];
	if(LIS[indx-1] < arr[node] && arr[node] < LIS[indx]){
		LIS[indx] = arr[node];
	}


	//Encontrar respuesta
	int siz = lower_bound(LIS.begin(), LIS.end(), INF) - LIS.begin();
	ans[node] = siz - 1;

	//Propagar
	for(auto& it : adj[node]){
		if(it == parent)continue;
		DFS(it, node);
	}

	//REGRESAR
	LIS[indx] = ant;
}

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int a, b;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	for(int i = 0; i < n-1; i++){
		cin >> a >> b;
		--a;--b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	LIS[0] = -INF;

	DFS(0);
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 27832
N, M = map(int, input().split())
max_l = 1
min_r = N
for _ in range(M):
    l, r = map(int, input().split())
    max_l = max(max_l, l)
    min_r = min(min_r, r)

print(max(0, min_r - max_l + 1))


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main()
{
    int A, B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    int b[101]={0};
    int a[101] = {0};
    for(int i=A;i<=B;i++)
        a[i]=1;
    for(int i=C;i<=D;i++)
        b[i]=1;
    int ans=0;
    for (int j = 0; j <101 ; ++j) {
        if (a[j]==1&&b[j]==1)
            ans++;
    }
    
    printf("%d",ans==0? 0:ans-1);
}

Measured memory_bytes: 128
# C - 4-adjacent

# _,a = input(),[int(x)%4 for x in input().split()]
# print("Yes" if a.count(1) + a.count(3) <= a.count(0) + (0 if a.count(2)>0 else 1) else "No")

n,a = int(input()),[int(x)%4 for x in input().split()]
# print("Yes" if n - a.count(2) - a.count(0) <= a.count(0) + (0 if a.count(2)>0 else 1) else "No")
# print("Yes" if n - a.count(2) <= a.count(0)*2 + (0 if a.count(2)>0 else 1) else "No")
# print("Yes" if n <= a.count(0)*2 + a.count(2) + (0 if a.count(2)>0 else 1) else "No")
print("Yes" if n//2 <= a.count(0) + a.count(2)//2 else "No")

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int f(char a, char b, char c) {
    set<char> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    return st.size() - 1;
}

int main() {
    int N; cin >> N;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    rep(i, N) ans += f(a[i], b[i], c[i]);
    cout << ans << endl;
}


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

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  ll MIN = 1e15;
  for (ll i = 0; i < 101; i++) {
    ll temp = 0;
    for (ll j = 0; j < N; j++) {
      temp += (A[j] - i) * (A[j] - i);
    }
    MIN = min (MIN, temp);
  }
  cout << MIN << '\n';
  return 0;
}

Measured memory_bytes: 256
D, G = map(int, input().split())
p = [0] * D
c = [0] * D

for i in range(D):
    p[i], c[i] = map(int, input().split())

ans = float('inf')

for i in range(1<<D):
    tmp_score = 0
    cnt = 0
    max_value = -1
    for j in range(D):
        if (i >> j) & 1 == 1:
            tmp_score += 100 * (j + 1) * p[j] + c[j]
            cnt += p[j]
        else:
            max_value = j

    if tmp_score < G:
        for k in range(1,p[max_value]):
            tmp_score += 100 * (max_value + 1)
            cnt += 1
            if tmp_score >= G:
                break
    
    if tmp_score >= G:
        if ans > cnt:
            ans = cnt

print(ans)


Measured memory_bytes: 3064
#include <cstdio>

const int maxn = 100005;
char buf[maxn];
int k;

void solve(int t) {
    char * s = buf, *l = NULL;
    while (*s) {
        if (*s > 'a') {
            int v = 'z' - *s + 1;
            if (v <= t) {
                t -= v;
                *s = 'a';
            } 
        }
        l = s + 1;
        if (*l == 0 && t > 0) {
            *s = (*s - 'a' +  t) % 26 + 'a';
            t = 0;
        }
        printf("%c", *s);
        ++s;
    }
    printf("\n");
}

int main() {
    scanf("%s", buf);
    scanf("%d", &k);
    solve(k);
    return 0;
}


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

using namespace std;

bool j(int s) {
	if (s == 0 || s > 12) return true;
	
	return false;
}

int main(void) {
	string s;
	int s1, s2;
	cin >> s;
	s1 = stoi(s.substr(0, 2));
	s2 = stoi(s.substr(2, 2));

	if (j(s1) && j(s2)) cout << "NA";
	else if (j(s1)) cout << "YYMM";
	else if (j(s2)) cout << "MMYY";
	else cout << "AMBIGUOUS";
	return 0;
}

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

const char CHAR_STR = '#';
const char CHAR_END = '.';

const int DIR_X[] = { 1, 0, -1,  0 };
const int DIR_Y[] = { 0, 1,  0, -1 };

typedef struct { int x; int y; } Point;

typedef struct
{
	int  h;
	int  w;
	char map [400][400];
	char flag[400][400];
} Parameter;

long long count_to_goal(Parameter * p, int x, int y)
{
	std::list<Point> stack;
	int num_str = 0;
	int num_end = 0;

	if ( p->flag[y][x] ) return 0;

	stack.push_back((Point){x, y});
	p->flag[y][x] = 1;

	for (; stack.size(); )
	{
		auto cur = stack.front();
		stack.pop_front();

		if ( p->map[cur.y][cur.x] == CHAR_STR ) num_str++;
		else num_end++;

		for (auto i = 0; i < 4; i++)
		{
			auto nex = cur;
			nex.x += DIR_X[i];
			nex.y += DIR_Y[i];

			if ((nex.x < 0) || (nex.x >= p->w) || (nex.y < 0) || (nex.y >= p->h))
				continue;
			if (p->flag[nex.y][nex.x])
				continue;
			if (p->map [nex.y][nex.x] == p->map [cur.y][cur.x] )
				continue;

			stack.push_back(nex);
			p->flag[nex.y][nex.x] = 1;
		}
	}

	return (long long)num_str * num_end;
}

int main(int argc, char * argv[])
{
	Parameter p;
	long long ret = 0;

	std::cin >> p.h;
	std::cin >> p.w;
	for (int y = 0; y < p.h; y++)
	{
		for (int x = 0; x < p.w; x++)
		{
			std::cin >> p.map[y][x];
			p.flag[y][x] = 0;
		}
	}

	for (int y = 0; y < p.h; y++)
	{
		for (int x = 0; x < p.w; x++)
		{
			if (p.flag[y][x] == 0)
				ret += count_to_goal(&p, x, y);
		}
	}

	std::cout << ret;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    int K, slen;
    cin >> s >> K;
    slen = s.length();
    vector<string> ss;
    for (auto j=0; j < slen; ++j) {
        for (auto k=j+1; k <= j+5 && k <= slen; ++k) {
            ss.push_back(s.substr(j, k-j));
        }
    }
    sort(ss.begin(), ss.end());
    ss.erase(unique(ss.begin(), ss.end()), ss.end());
    cout << ss[K-1] << endl;
}


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

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

    double ans;
    if (N % 2 == 1)
    {
        ans = ceil(N / 2.0) / N;
        printf("%.10f\n", ans);
    }
    if (N % 2 == 0)
    {
        ans = (N / 2.0) / N;
        printf("%.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
ll h, w, grid[200][200], dp[500][200][200];
ll p[] = {1, 0, 0, 1, 1, 1, 0, 0};
int main() {
  cin >> h >> w;
  REP(i, h) {
    REP(j, w) { cin >> grid[i][j]; }
  }
  REP(i, h + w - 2) {
    REP(X, min(w, i + 1)) {
      REP(x, min(w, i + 1)) {
        if (h <= i - X || h <= i - x)
          continue;
        ll y = i - x, Y = i - X, cost = grid[Y][X] + grid[y][x];
        // cost -= (X == x && grid[y][x]);
        cost -= (X == x ? grid[y][x] : 0);
        REP(k, 4) {
          dp[i + 1][X + p[k * 2]][x + p[k * 2 + 1]] = max(
              dp[i + 1][X + p[k * 2]][x + p[k * 2 + 1]], cost + dp[i][X][x]);
        }
      }
    }
  }
  cout << dp[h + w - 2][w - 1][w - 1] + grid[h - 1][w - 1] << endl;
}


Measured memory_bytes: 123520
import collections
K=int(input())

q = collections.deque([1,2,3,4,5,6,7,8,9])
for i in range(K-1):
    t = q.popleft()
    if t%10!=0:
        q.append(t*10+t%10-1)
    q.append(t*10+t%10)
    if t%10!=9:
        q.append(t*10+t%10+1)
print(q.popleft())

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

int main(){
  int a,b,c;
  int num = 0;
  cin >> a >> b >> c;
  
  for(int i = a; i <= b; i++){
  if(c%i==0){
    num += 1;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 3068
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            (long A, long B) = Slice2<long>();
            if (10 <= A + B)
                WriteLine("error");
            else
                WriteLine(A + B);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27504
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int k, n;
int a[5000010];

bool d(int mid) {
    if(a[mid] >= k) return true;
    else return false;
}

signed main() {
    cin >> n;
    rep(i,0,5000010) {
        if(i == 0) a[i] = 0;
        else a[i] = i + a[i-1];
        // cout << a[i] << endl;
    }

    k = n;
    while(1) {
        // cout << k << endl;
        if(k <= 0) break;
        int ub = n+1, lb = 0;
        while(ub - lb > 1) {
            int mid = (ub + lb) / 2;
            if(d(mid)) ub = mid;
            else lb = mid;
        }
        cout << ub << endl;
        k -= ub;
    }
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    vector<ll> A(N); rep(i,N)cin>>A.at(i);

    ll res = 0;
    ll two = 1;
    for(int i = 0; i < 60; i++){
        ll zero = 0, one = 0;
        for(ll n = 0; n < N; n++){
            if(A.at(n)&(1LL<<i))one++;
            else zero++;
        }
        //res += (zero*one*two)%MOD;
        ll add = (zero*one)%MOD*two%MOD;
        res = (res+add) %MOD;
        two = (two*2)%MOD;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 2560
n = int(input())
dic = {}
res = []

for i in range(n):
    com = input().split()
    if com[0] == "insert":
        dic[com[1]] = i
    elif com[0] == "find":
        if com[1] in dic:
            res.append("yes")
        else:
            res.append("no")
            
for i in res:
    print(i)


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

typedef long long ll;

using namespace std;

int main(){
    int x;
    cin >> x;

    int count = x / 100;
    int goal = x % 100;

    if(count * 5 >= goal) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define int long long int
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD = 1000000007;
const ll MOD1=1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
/*
 shuffle(x,x+n,rng) // shuffling elements of x in random order
 */

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n],b[n-1];
    for(int i=0;i<n-1;i++)
        cin>>b[i];
    a[0]=b[0];int s=a[0];
    for(int i=1;i<n;i++)
    {
        if(i<n-1)
        a[i]=min(b[i],b[i-1]);
        else
            a[n-1]=b[n-2];
        s+=a[i];
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (ll)1e17;
const ll MAX = 1e5+10;

ll N;
ll par[MAX];

ll root(ll x){
  if(par[x] == x) return x;
  return root(par[x]);
}

void unite(ll x, ll y){
  ll rx = root(x);
  ll ry = root(y);
  if(rx == ry) return;
  par[rx] = ry;
  par[x] = ry;
  par[y] = ry;
}

bool same(ll x, ll y){
  ll rx = root(x), ry = root(y);
  return rx == ry;
}


int main(){
  cin >> N;
  vector<pair<ll, ll> > x(N), y(N);
  vector<pair<ll, pair<ll, ll> > > s;
  ll ans = 0;
  
  for(ll i = 0; i < N; i++){
    ll xx, yy; cin >> xx >> yy;
    x[i] = make_pair(xx, i);
    y[i] = make_pair(yy, i);
  }
  
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for(ll i = 1; i < N; i++){
    ll dx = x[i].first - x[i-1].first;
    ll fx = x[i].second, sx = x[i-1].second;
    s.push_back(make_pair(dx, make_pair(fx, sx)));
    
    ll dy = y[i].first - y[i-1].first;
    ll fy = y[i].second, sy = y[i-1].second;
    s.push_back(make_pair(dy, make_pair(fy, sy)));
  }

  sort(s.begin(), s.end());
  
  for(ll i = 0; i < N; i++){
    par[i] = i;
  }
  
  ll M = s.size();
  for(ll i = 0; i < M; i++){
    ll des = s[i].first, fst = s[i].second.first, scd = s[i].second.second;
    if(!same(fst, scd)){
      ans += des;
      unite(fst, scd);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 11632
using System;
using System.Collections.Generic;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var NH = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToList();
            var N = NH[0];
            var H = NH[1];
            var bList = new List<int>();
            var aMax = 0;
            for (var i = 0; i < N; i++)
            {
                var ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
                if(aMax<ab[0])aMax=ab[0];
                bList.Add(ab[1]);
            }
            bList = bList
                .Where(b=>aMax<b)
                .OrderByDescending(i => i).ToList();
            var count = 0;
            foreach (var b in bList)
            {
                H -= b;
                count++;
                if (H <= 0)
                {
                    Console.WriteLine(count);
                    return;
                }
            }
            if (H % aMax != 0)
            {
                count++;
            }
            count += H / aMax;
            Console.WriteLine(count);
        }
    }


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

using namespace std;

using int64 = long long;

bool Solve() {
  int n;
  cin >> n;
  vector<int64> xs(n);
  unordered_map<int64, int> counter;
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    counter[xs[i]]++;
  }

  if (n % 3 != 0) {
    return counter[0] == n;
  }

  // n % 3 == 0
  int unit = n / 3;
  vector<int64> ys;
  for (const auto& entry : counter) {
    int64 val;
    int counter;
    tie(val, counter) = entry;
    // cout << "val: " << val << " counter: " << counter << endl;
    if (counter % unit != 0) return false;
    for (int i = 0; i < counter / unit ; i++) {
      ys.push_back(val);
    }
  }
  int64 z = 0;
  for (int y : ys) {
    z ^= y;
  }
  // cout << "z: " << z << endl;
  return z == 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string solution;
  if (Solve()) solution = "Yes";
  else solution = "No";
  cout << solution << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, k, s;
    cin >> n >> k >> s;
    rep (i, n - k) {
        if (s == 999999999) {
            cout << 1 << " ";
        } else {
            cout << 999999999 << " ";
        }
    }
    rep (i, k) {
        cout << s;
        if (i < k - 1) cout << " ";
        else cout << endl;
    }
    
    return 0;
}



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

using namespace std;
using i64 = int64_t;

int main()
{
    int n;
    cin >> n;
    unordered_map<string, i64> m;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ++m[s];
    }
    i64 a = 0;
    for(auto& x : m)
        a += x.second * (x.second - 1) / 2;
    cout << a << endl;
    return 0;
}




Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return (ans.x+m)%m;
}
int fact[N];
void calfac(int n ){
fact[0] = 1;
for(int i = 1 ; i <= n+2; i++){
 fact[i] = (((fact[i-1]%mod)*(i%mod))%mod + mod)%mod;
}
 }
int calc(int n , int r){
 if(r > n)return 0;
 if(r == n)return 1;
 int ans = 1;
 ans = ((ans%mod)*(fact[n])%mod + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[n-r] , mod)%mod) + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[r] , mod)%mod) + mod)%mod;
 return (ans+mod)%mod;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a , b;
cin>>a>>b;
if(b>=a){
 cout<<"unsafe"<<endl;
 return 0;
}
cout<<"safe"<<endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 100001
using namespace std;
vector<int> edges[MAXX];
bool visited[MAXX];
void dfs(int sv)
{
  visited[sv]=true;
  for(auto i:edges[sv]) if(!visited[i]) dfs(i);
}
void trozen()
{
  int n,m;
  cin>>n>>m;
  rep(i,m)
  {
    int x,y;
    cin>>x>>y;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  memset(visited,false,sizeof(visited));
  int cnt=-1;
  for(int i=1;i<=n;i++) if(!visited[i])
  {
    dfs(i);
    cnt++;
  }
  cout<<cnt<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}

Measured memory_bytes: 10428
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int n = sc.nextInt() - 1;
		int[] a = sc.nextIntArray(n);
		int b = sc.nextInt();
		long[][] dp = new long[n+1][21];
		dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for(int j = 0; j <= 20; j++) if (dp[i][j] > 0) {
				{
					int nj = j + a[i];
					if (0 <= nj && nj <= 20) {
						dp[i+1][nj] += dp[i][j];
					}
				}
				if (i > 0) {
					int nj = j - a[i];
					if (0 <= nj && nj <= 20) {
						dp[i+1][nj] += dp[i][j];
					}
				}
			}
		}
		out.println(dp[n][b]);

	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 17064
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T& a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U>& p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector< T > &v) { rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "b.cpp"

int main() {
  ll a, b, c, d;

  cin >> a >> b >> c >> d;

  bool f = 0;

  while (1) {
    if (f == 0) {
      c -= b;
    } else {
      a -= d;
    }

    if (a <= 0 or c <= 0) {
      break;
    }
    f ^= 1;
  }

  cout << (!f ? "Yes" : "No") << el;
}


Measured memory_bytes: 3608
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3117"

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

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
template <typename T>
using gtree = tree<T, null_type, less<T>, rb_tree_tag,
                   tree_order_statistics_node_update>;
// usage:
// find_by_order(int k):
// return the iterator of k-th smallest element (0-indexed)
// order_of_key(T key):  return the index of key in tree
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i],as[i]-=k;

  using ll = long long;
  using P = pair<ll, int>;
  gtree<P> G;
  ll sum=0,ans=0;
  G.insert(P(sum,-1));
  for(int i=0;i<n;i++){
    sum+=as[i];
    G.insert(P(sum,i));
    ans+=G.order_of_key(P(sum,i));
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 9392
from collections import deque
s = deque(input())
q = int(input())
lis = [list(input().split()) for _ in range(q)]
rev = 0
z = 0

for i in lis:
    if i[0] == "2":
        if (rev + int(i[1])) % 2 == 1:
            s.appendleft(i[2])
        else:
            s.append(i[2])
        z = 1
    else:
        if z == 1:
            rev += 1
        
if rev % 2 == 1:
    s = reversed(s)
print("".join(s))
    


Measured memory_bytes: 35188
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    int D,T,S;
    cin>>D>>T>>S;
    int ans=T*S;
    if(D<=ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 
const int MAXN=1100;
int f[MAXN][MAXN],p[MAXN];
int main() {
	int N,K;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;++i) {
		scanf("%d",&p[i]);
	}
	sort(p+1,p+N+1);
	long long ans=0;
	for(int i=1;i<=K;++i) {
		ans+=p[i];
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main() {
  int n,k;
  int i,j;
  int x;
  double y;
  double coin=1;
  double coin_p;
  double answer=0;

  cin >> n >> k;

  for(i=1;i<=n;i++) {
    coin = 1;

    if(i>=k) {coin = 1;}
    else {
      y = ceil(log2((double)k/(double)i));
      x = (int)y;

      for(j=1;j<=x;j++) {
        coin = coin*0.5;
      }
    }

    answer = answer + (1/(double)n)*coin;
  }

  cout << setprecision(12) << answer << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    ll n, k; cin >> n >> k;
    ll ans = 1e18 + 10LL;
    while(ans >= n)
    {
        if(n < k)
        {
            n = (-1 * n) % k;
            n += k;
        }
        else
        {
            n = n % k;
        }
        ans = min(ans, n);
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
N = int(input())

ans = 0
A_flag = 0
B_flag = 0
A_flag2 = 0
B_flag2 = 0

for i in range(N):
    S = input()
    ans += S.count('AB')

    if S[0] == 'B':
        B_flag += 1

    if S[-1] == 'A':
        A_flag += 1

    if S[0] != 'B' and S[-1] == 'A':
        A_flag2 = 1

    if S[0] == 'B' and S[-1] != 'A':
        B_flag2 = 1

if A_flag != B_flag:
    ans += min(A_flag,B_flag)
else:
    if A_flag+B_flag != 0:
        if A_flag2*B_flag2 == 0:
            ans += min(A_flag,B_flag) -1
        else:
            ans += min(A_flag,B_flag)
print(ans)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <array>
#include <fstream>
#include <deque>
#include <bitset>
#include <complex>
using namespace std;
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#define REVERSE(i,n) for(int (i) = n-1;(i) >= 0 ; --i)
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(auto(it,(c).begin());it != (c).end();)
#define cx real()
#define cy imag()
#define px first
#define py second
#define LL long long
#define int LL
#define inf  (1LL << 60)
#define mod 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c,n) memset(&c[0],0,sizeof(int)*n)
#define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << ""#a": " << a << endl;
#ifdef _DEBUG
#define debug_io fstream cin("input.txt");ofstream cout("output.txt");
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define pb(a) push_back(a)
template<class T>void scan(vector<T>& a, int n, istream& cin)
{
	T c; REP(i, n) { cin >> c; a.push_back(c); }
}
using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>;
using psi = pair<string, int>; using vvi = vector<vi>; using pss = pair<string, string>;
template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; }
int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
 
 
signed main()
{
	QUICK_CIN;
	//debug_input;
 
	int n,m;
	cin >> n >> m;
 
	int ret = 0;
 
	ret += min(n,m/2);
 
	m = max(m - ret * 2 , 0LL);
 
	ret += m / 4;
 
	cout << ret << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
   int a,b,c,i,cout=0;

   scanf("%d%d%d",&a,&b,&c);

   for (i=a; i<=b; i++) {
      if (c%i == 0)
         cout=cout+1;
   }

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

   return 0;

}

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

int main() {
  int n;cin>>n;
  n--;
  cout<<n/2<<endl;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  int i, j;
  vector<vector<long long>> c(2001, vector<long long>(2001, 0));
  for(i = 0; i <= 2000; i++)
  {
    c.at(i).at(0) = 1;
  }
  for(i = 1; i <= 2000; i++)
  {
    for(j = 1; j <= i; j++)
    {
      c.at(i).at(j) = (c.at(i-1).at(j) + c.at(i-1).at(j-1))%1000000007;
    }
  }
  for(i = 1; i <= k; i++)
  {
    cout << (c.at(n-k+1).at(i)*c.at(k-1).at(i-1))%1000000007 << endl;
  }
}


Measured memory_bytes: 31616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 10011

ll n, i, a[maxN], b[maxN];
ll na, nb;

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

    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= n; i++) cin >> b[i];

    for (i = 1; i <= n; i++) {
        if ((a[i] & 1) ^ (b[i] & 1)) {
            b[i]++;
            nb++;
        }

        if (a[i] > b[i]) {
            nb += a[i] - b[i];
            b[i] = a[i];
        } else {
            na += (b[i] - a[i]) / 2;
            a[i] = b[i];
        }
    }

    if (na >= nb)
        cout << "Yes";
    else
        cout << "No";


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
int main()
{
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],c[n];
    go(i,1,n+1)
    {
        cin>>a[i];
    }
    go(i,1,n+1)
    {
        cin>>b[i];
    }
    go(i,1,n+1)
    {
        cin>>c[i];
    }
    ll s = b[a[1]];
    go(i,2,n+1)
    {
        if(a[i]-a[i-1]==1)
        {
            s += b[a[i]] + c[a[i]-1];
        }
        else
        {
            s += b[a[i]];
        }
    }
    show(s);
}


Measured memory_bytes: 256
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int n, k;
int s[26];

int MAIN()
{
	memset(s, 0, sizeof(s));
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		string x;
		cin >> x;
		s[x[0]-'A'] ++;
	}
	int ans = 0;
	while(true)
	{
		sort(s + 0, s + 26);
		bool bad = false;
		for(int i = 25; i >= 25 - k + 1; i--)
		{
			if(s[i] == 0)
				bad = true;
			else
				s[i] --;
		}
		if(bad) break;
		ans ++;
	}
	cout << ans << endl;
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)


int main(){
    int a,b;
    cin>>a>>b;
    cout<<2*b-a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, X, T;
    cin >> N >> X >> T;

    int time = (N + X - 1) / X;

    cout << time * T << endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())

flag = "Y"
t = list(range(N))
x = list(range(N))
y = list(range(N))

for i in range(N):
    t[i], x[i], y[i] = map(int, input().split())

for i in range(N):
    if i==0:
        if t[0] < abs(x[0]) + abs(y[0]):
            flag = "N"
            
    if i>0:
        td = abs(t[i] - t[i-1])
        xd = abs(x[i] - x[i-1])
        yd = abs(y[i] - y[i-1])
        
        if td < abs(xd) + abs(yd):
            flag = "N"
        else:
            if td%2 == 1 and xd%2 == 0 and yd%2 == 0:
                flag = "N"
            elif td%2 == 1 and xd%2 == 1 and yd%2 == 1:
                flag = "N"
            elif td%2 == 0 and xd%2 == 1 and yd%2 == 0:
                flag = "N"
            elif td%2 == 0 and xd%2 == 0 and yd%2 == 1:
                flag = "N"

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

Measured memory_bytes: 14836
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

from collections import Counter

def all_zeros(a_list):
    return sum(a_list) == 0

def check(N, a_list):
    if all_zeros(a_list):
        print('Yes')
        return
    elif N % 3 == 0:
        x = N // 3
        if not all([v % x == 0 for v in Counter(a_list).values()]):
            print('No')
            return
        while not all_zeros(a_list):
            counter = Counter([a & 1 for a in a_list])
            if counter[0] == x or counter[0] == N:
                a_list = [a >> 1 for a in a_list]
            else:
                print('No')
                return
        print('Yes')
    else:
        print('No')

check(N, a_list)

Measured memory_bytes: 15980
#include <iostream>
using namespace std;
#define N_MAX 100

int main()
{
    int n;
    int b[N_MAX];

    cin >> n;
    for(int i = 0; i < n-1; ++i)
    {
        int t;
        cin >> t;
        b[i] = t;
    }
    int sum = 0;
    sum += b[0];
    for(int i = 0; i < n-2; ++i)
    {
        sum += min(b[i], b[i+1]);
    }
    cout << sum + b[n-2] << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
boat_list = list(map(int, input().split()))

total = sum(boat_list)

threshold = total / (4 * M)

judge_list = []

for i in range(len(boat_list)):
    if boat_list[i] >= threshold:
        judge_list.append(1)
    else:
        pass

if len(judge_list) >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    i64 n, q;
    cin >> n >> q;
    vector<i64> a(n), b(n), p(q), x(q);
    Graph G(n);
    for(int i = 0; i < n - 1; ++i){
        cin >> a[i] >> b[i];
        G[a[i] - 1].push_back(edge(a[i] - 1, b[i] - 1));
        G[b[i] - 1].push_back(edge(b[i] - 1, a[i] - 1));
    }
    vector<i64> ans(n), c(n);
    vector<bool> used((n), false);
    for(int i = 0; i < q; ++i){
        cin >> p[i] >> x[i];
        c[p[i] - 1] += x[i];
    }
    queue<i64> que;
    que.push(0);
    while (!que.empty()) {
        i64 v = que.front(); que.pop();
        used[v] = true;
        for(int i = 0; i < G[v].size(); ++i){
            edge e = G[v][i];
            i64 u = e.to;
            if (!used[u]) {
                que.push(u);
                c[u] += c[v];
            }
        }
    }
    for(int i = 0; i < n; ++i) cout << c[i] << endl;
}


Measured memory_bytes: 31488