akhauriyash/Code-Regression huggingface dataset:
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
		print("vowel");
	else
		print("consonant");
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
import numpy as np

n,k = map(int,input().split())
lst = list(map(int,input().split()))
exp_val = [(l+1)/2 for l in lst]

cumsum = np.cumsum(exp_val)

for i in range(k-1, n):
    if i==k-1:
        val = cumsum[i]
    else:
        val = max(val, cumsum[i] - cumsum[i-k])
print(val)

Measured memory_bytes: 33892
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
int table[1002][1002];

int func(int stx, int sty, int nx, int ny);

signed main()
{
    Int(n);
    while (n) {
    vector< string > board(n);
    rep(i, n) {
        cin >> board[i];
    }

    memset(table, 0, sizeof(table));

    rep(i, n) {
        rep(j, n) {
            if (board[i][j] == '*') {
                table[i+1][j+1]++;
            }
        }
    }

    rep(i, n) {
        Rep(j, n) {
            table[i+1][j+1] += table[i+1][j];
        }
    }

    rep(j, n) {
        Rep(i, n) {
            table[i+1][j+1] += table[i][j+1];
        }
    }

    int ans = 0;

    Rep(i, n) {
        int stx = i-1, sty = 0, nx = i, ny = 1;
        int num = func(stx, sty, nx, ny);
        for (int add = 0; add + i <= n; add++) {
            int tmp = func(stx, sty, nx + add, ny + add);
            while (tmp != 0 && stx < nx + add && sty < ny + add) {
                stx++; sty++;
                tmp = func(stx, sty, nx + add, ny + add);
            }
            ans = max(ans, nx + add - stx);
        }
    }

    rep(i, n+1) {
        for (int j = i; j <= n; j++) {
            int tmp = table[i][j];
            table[i][j] = table[j][i];
            table[j][i] = tmp;
        }
    }

    Rep(i, n) {
        int stx = i-1, sty = 0, nx = i, ny = 1;
        int num = func(stx, sty, nx, ny);
        for (int add = 0; add + i <= n; add++) {
            int tmp = func(stx, sty, nx + add, ny + add);
            while (tmp != 0 && stx < nx + add && sty < ny + add) {
                stx++; sty++;
                tmp = func(stx, sty, nx + add, ny + add);
            }
            ans = max(ans, nx + add - stx);
        }
    }

    cout << ans << endl;

    cin >> n;
    }

    return 0;
}

int func(int stx, int sty, int nx, int ny)
{
    return table[nx][ny]+table[stx][sty]-table[stx][ny]-table[nx][sty];
}

Measured memory_bytes: 11968
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
#include <queue>
 

using namespace std;

int digit(long long x){
    int ans=0;
    while(x>0){
        x%=10;
        ans++;
    }
    return ans;
}

int main() {
    long long n;
    cin >> n;
    
    int ans = n%10;
    
    if(ans == 3) cout << "bon" << endl;
    else if(ans == 0 || ans == 1 || ans == 6 || ans == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
 }


Measured memory_bytes: 3580
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

def binary_search(data, value):
    left = 0
    right = len(data) 

    while left < right:
        mid = (left + right) // 2
        if data[mid] == value:
            return 1
        elif data[mid] < value:
            left = mid + 1
        else:
            right = mid
    return 0

count = 0
for i in t:
    exist = binary_search(s, i)
    count = count + exist

print(count)




Measured memory_bytes: 16708
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto mk = readln.split.to!(uint[]);
    auto M = mk[0];
    auto K = mk[1];

    if (K == 0) {
        foreach (a; 0..2^^M-1) {
            write(a, " ");
            write(a, " ");
        }
        write(2^^M-1, " ");
        writeln(2^^M-1);
        return;
    }

    uint c;
    foreach (a; 1..2^^M) {
        if (a == K) continue;
        c ^= a;
    }

    if (c == K) {
        foreach (a; 0..2^^M) {
            if (a == K) continue;
            write(a, " ");
        }
        write(K, " ");
        foreach_reverse (a; 0..2^^M) {
            if (a == K) continue;
            write(a, " ");
        }
        writeln(K);
    } else {
        writeln("-1");
    }
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //long longをllで表せる
 
int main() {
  
  char s1;
  
  cin >> s1;

if(s1 >= 'a' && s1<= 'z'){
  cout << "a" << endl;}
  
  else if(s1 >= 'A' && s1<= 'Z'){
  cout << "A" << endl;}
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;

// ツ組ツづ敖債づュツつケツづーツ仰づ淞づゥツ古カツ篠ョ
ll dp[101][101];
ll cmb(int a,int b){
	if(a<b)return 0;
    else if(dp[a][b]!=-1)return dp[a][b];
    else if(a==b)return 1;
    else if(b==1)return dp[a][b]=a;
    else if(b==0)return 1;
    return dp[a][b]=((cmb(a-1,b)+cmb(a-1,b-1)));
}

ll n,m;
string dfs(int pos,int ones,ll mm){
    if(pos==n)return "";
    else if(ones==0)return '0'+dfs(pos+1,ones,mm);
    // ツ債。ツ嘉アツづ個湘ェツ渉環づー1ツづ可つキツづゥツつゥ0ツづ可つキツづゥツつゥ
    ll cnt=cmb(n-pos-1,ones-1);
    if(cnt>=mm)return '1'+dfs(pos+1,ones-1,mm);
    return '0'+dfs(pos+1,ones,mm-cnt);
}

int main(){
    for(int i=0;i<101;i++)for(int j=0;j<101;j++)dp[i][j]=-1;
    while(cin>>n>>m&&!(n==0&&m==0)){
        ll mul=1;
        for(int i=0;i<n;i++)mul*=2;
        m=mul-m+1;
        ll sum=0;
        // 1ツづ個青板づーツつ「ツつュツづつづ可つキツづゥツつゥ
        for(int i=n;i>=0;i--){
            sum+=cmb(n,i);
            if(sum>=m){
                sum-=cmb(n,i);
                string res=dfs(0,i,m-sum);
                cout<<res<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define FIN freopen("entrada.txt", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define MOD 1000000007
#define ull unsigned long long int
#define ll  long long int
#define pii pair<int, int>
#define pb push_back
#define MAX int(10e5+2)

const int INF = 0x3f3f3f3f;
using namespace std;

ll a, b, c, k;

void solve() {
   ll resp=0;
   if(a>k) {
      resp+=(k);
      cout << resp << "\n";
      return;
   } else {
      resp+=a;
      k-=a;
   }

   if(b>k) {
      cout << resp << "\n";
      return;
   } else {
      k-=b;
   }

   resp-=(k);
   cout << resp << "\n";
   return;

}

int main() {

   //IO

   cin >> a >> b >> c >> k;

   solve();


   return 0;
}


Measured memory_bytes: 3644
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
V<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
bool odd=false;
for(int i=0;i<n;i++)if(a[i]%2)odd=true;
if(odd)cout<<"first"<<endl;
else cout<<"second"<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class215
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var que = new PriorityQueue<long>(N, (x, y) => -x.CompareTo(y));
            for (int i = 0; i < N; i++)
                que.Push(A[i]);

            for(int i = 0; i < M; i++)
            {
                var r = que.Pop();
                r /= 2;
                que.Push(r);
            }

            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                ans += que.Pop();
            }
            Console.WriteLine(ans);
        }
    }
    public class PriorityQueue<T>
    {
        public long Size { get; private set; } = 0;
        public long MaxSize { get; private set; } = 0;
        private T[] m_heap;
        private Comparison<T> Comp = null;

        public PriorityQueue(long maxSize, Comparison<T> comp)
        {
            if (maxSize <= 0)
                throw new Exception();
            MaxSize = maxSize;
            m_heap = new T[maxSize];

            Comp = comp;
        }

        public void Push(T x)
        {
            if (Size == MaxSize)
            {
                T[] new_heap = new T[MaxSize << 1];
                Array.Copy(m_heap, new_heap, MaxSize);
                m_heap = new_heap;
                MaxSize <<= 1;
            }

            long i = Size++;
            while (i > 0)
            {
                long p = (i - 1) / 2;
                if (Comp(m_heap[p], x) <= 0)
                    break;
                m_heap[i] = m_heap[p];
                i = p;
            }
            m_heap[i] = x;
        }

        public T Pop()
        {
            if (Size == 0)
                throw new Exception("Queue is empty.");

            T result = m_heap[0];
            T x = m_heap[--Size];
            long i = 0;
            while (i * 2 + 1 < Size)
            {
                long c1 = i * 2 + 1, c2 = i * 2 + 2;
                if (c2 < Size && Comp(m_heap[c2], m_heap[c1]) < 0)
                    c1 = c2;
                if (Comp(m_heap[c1], x) >= 0)
                    break;
                m_heap[i] = m_heap[c1];
                i = c1;
            }
            m_heap[i] = x;

            return result;
        }
    }
}


Measured memory_bytes: 30044
# 最初に入れておくとinputが早くなる
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

L, R = map(int, input().split())

ans = 2018

for i in range(L, min(L+2020, R+1)):
    for j in range(i+1, min(L + 2020, R+1)):
        #print(i, j, (i % 2019) * (j % 2019) % 2019)
        ans = min(ans, (i % 2019) * (j % 2019) % 2019)
print(ans)

Measured memory_bytes: 3060
N, M = map(int, input().split())
edges = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    edges.append([a-1, b-1])

nodes = [0]*N

mat = [[0]*N for _ in range(N)]

for s, g in edges:
    nodes[s] += 1
    nodes[g] += 1
    mat[s][g] = 1
    mat[g][s] = 1

ans = 0


def check(nodes):
    return all(n != 1 for n in nodes)


ans = 0
while not check(nodes):
    for i in range(N):
        if nodes[i] == 1:
            for j in range(N):
                if mat[i][j]:
                    mat[i][j] = 0
                    mat[j][i] = 0
                    ans += 1
                    nodes[i] -= 1
                    nodes[j] -= 1
                    break
print(ans)


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

int main(){
    int n, k, i;
    int ans = 0;
    cin >> n >> k;
    int x[n+1];
    for(i = 0; i < n; i++) cin >> x[i];

    for(i = 0; i < n; i++){
        if(x[i] * 2 < abs(k - x[i]) * 2){
            ans += x[i] * 2;
        }else{
            ans += abs(k - x[i]) * 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def solve1(n, a, b, s):
    ans = ["No" for i in range(len(s))]

    #print("|     i|s[i]|     a|     b|ans[i]|")
    #print("----------------------------------")

    for i in range(len(s)):
        if s[i] == "a":
            if a > 0:
                ans[i] = "Yes"
                a -= 1
            elif b > 0:
                ans[i] = "Yes"
                b -= 1
        elif s[i] == "b":
            if b > 0:
                ans[i] = "Yes"
                b -= 1

        #print(f"|{i:6d}|{s[i]:4s}|{a:6d}|{b:6d}|{ans[i]:6s}|")

    return ans


n, a, b = map(int, input().split(" "))
s = input()

print("\n".join(solve1(n, a, b, s)))


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

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

    int cnt[10][10] = {};
    // ex.注目する数字が「25」のとき、cnt[2][5]に1を加える

    for (int n = 1; n <= N; n++)
    {
        int n_end = n % 10;
        int n_begin = n;
        while (n_begin >= 10)
        {
            n_begin /= 10;
        }

        cnt[n_begin][n_end]++;
    }

    /*
    for (int i = 0; i <= 9; i++)
    {
        for (int j = 0; j <= 9; j++) cout << cnt[i][j] << " ";
        cout << endl;
    }
    cout << endl;
    */

    int ans = 0;

    // 頭と尾が違うとき
    for (int i = 1; i <= 9; i++)
    {
        for (int j = i + 1; j <= 9; j++)
        {
            ans += cnt[i][j] * cnt[j][i] * 2;
        }
    }

    // 頭と尾が同じとき
    for (int k = 1; k <= 9; k++)
    {
        ans += cnt[k][k] * cnt[k][k];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#define N 300005
using namespace std;

int n, a[N], ans[N];
priority_queue<int> pq;
int main()
{
	int i, j, tq, t;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%d", &t);
		a[t]++;
	}
	for (i = 1; i <= n; i++) pq.push(-a[i]);
	for (i = n - 1; i > 0; i--) {
		tq = -pq.top(), pq.pop();
		ans[i] = tq;
        while (tq > 0) {
			t = -pq.top(), pq.pop();
			if (pq.empty() || t + tq <= -pq.top()) pq.push(-t - tq), tq = 0;
			else tq -= -pq.top() - t + 1, pq.push(pq.top() - 1);
        }
	}
	printf("%d\n", n);
	for (i = 1; i < n; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;  
typedef vector<ll> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef vector<vi> vvi;
#define F first
#define S second
#define pb emplace_back
#define M 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for(int i = a; i<= b; i++)
#define ws " "
#define all(c) c.begin(), c.end()
#define ln "\n" 
 
void printarray(int ar[], int n) {
    for (int i = 0; i < n; i++) {
        cout << ar[i] << ws;
    }
    cout << ln;
}

int memo[3001][3001];
int ar[3001], sum[3001] = {0};

int dp(int start, int end) {
    if (start > end) {
        return 0;
    }
    int ans = 0;
    if (memo[start][end] != 0) {
        return memo[start][end];
    }
    ans = sum[end] - sum[start - 1];
    ans -= min(dp(start + 1, end), dp(start, end - 1));
    memo[start][end] = ans;
    return ans;
}

void init() {
    for (int i = 0; i <= 3000; i++) {
        for (int j = 0; j <= 3000; j++) {
            memo[i][j] = 0;
        }
    }
}

main() {
    IOS;
    int n;
    cin >> n;
    init();
    for (int i = 1; i <= n; i++) {
        cin >> ar[i];
        sum[i] = sum[i - 1] + ar[i];
    }
    cout << dp(1,n) - min(dp(1, n -1), dp(2, n));

}
 
/*  Check for base cases such as n == 1
    and cases like it where code can fail */

Measured memory_bytes: 70784
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static int Gcd(int a, int b)
    {
	if (a < b){ return Gcd(b, a); }
	while (b != 0)
	{
	    var r = a % b;
	    a = b;
	    b = r;
	}
	return a;
    }

    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var x = ReadIntArray();
	int a = x[0], b = x[1], t = x[2];

	int ans = 0;
	for (int i = 1; i * a <= t; i++)
	{
	    ans += b;
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define foreach(r,n,p) for(r::iterator it=p.begin();it!=p.end();++it)
#define MAX2N 250000
char p[250000]={};
using namespace std;
int main()
{
    memset(p,0,sizeof(p));
    p[0] = 1;
    p[1] = 1;
    for(int i=2;i<MAX2N;i++)
    {
        if(p[i] == 0)
        for(int j=2*i;j<MAX2N;j+=i)
        {
            p[j] = 1;
        }

    }
    int n;
    while(cin >> n)
    {
        if(n==0)break;
        int ans = 0;
        for(int i=n+1;i<=2*n;i++)
        {
            if(p[i]==0) ans++;

        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 0
N=input()
def GoodInteger(N):
    for i in N:
        if N.count(i)==2:
            return print("No")
        elif (N.count(i)==1 and  len(set(N))==2 and (N.index(i)==0 or N.index(i)==3)) or N.count(i)==4:
            return print("Yes")
    return print("No")
GoodInteger(N)

Measured memory_bytes: 3060
#include <stdio.h>
#define MAXN 100005

int main() {
  int i, l, r, m, ans;
  int n, value;
  int A[MAXN];
  while(scanf("%d", &n) != EOF && n != 0) {
    for(i = 0; i < n; ++i) scanf("%d", &A[i]);
    scanf("%d", &value);
    l = 0;
    r = n-1;
    ans = 0;
    while(l <= r) {
      ++ans;
      m = (l + r) / 2;
      if(A[m] == value) {
        break;
      } else if(A[m] < value) {
        l = m+1;
      } else if(A[m] > value) {
        r = m-1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 608
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void dfs(int from,int *vertex,int *cost,int *next,int *start,int64 *dp,int *stack,int n){
  int i;
  for(i=0;i<n;i++) dp[i]=-1;
  dp[from]=0;
  stack[0]=from;
  int top=1;
  while(top>0){
    int v=stack[--top];
    int p;
    for(p=start[v];p!=-1;p=next[p]){
      int u=vertex[p];
      if(dp[u]==-1){
	dp[u]=dp[v]+cost[p];
	stack[top++]=u;
      }
    }
  }
  return;
}

void add(int a,int b,int c,int *v,int *cost,int *next,int *start,int p){
  v[p]=b;
  cost[p]=c;
  next[p]=start[a];
  start[a]=p;
  return;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *vertex=(int *)malloc(sizeof(int)*2*(n-1));
  int *cost=(int *)malloc(sizeof(int)*2*(n-1));
  int *next=(int *)malloc(sizeof(int)*2*(n-1));
  int *start=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) start[i]=-1;
  for(i=0;i<n-1;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    a--;b--;
    add(a,b,c,vertex,cost,next,start,2*i);
    add(b,a,c,vertex,cost,next,start,2*i+1);
  }
  int q,k;
  scanf("%d%d",&q,&k);
  k--;
  int64 *dp=(int64 *)malloc(sizeof(int64)*n);
  int *stack=(int *)malloc(sizeof(int)*n);
  dfs(k,vertex,cost,next,start,dp,stack,n);
  while(q--){
    int x,y;
    scanf("%d%d",&x,&y);
    x--;y--;
    printf("%lld\n",dp[x]+dp[y]);
  }
}

int main(void){
  run();
  return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N;
string s;
int white[222222];
int black[222222];

signed main() {
  cin >> N >> s;
  rep (i, N) {
    white[i+1] = s[i] == '.';
    black[i+1] = s[i] == '#';
  }

  for (int i = 0; i <= N; i++) {
    black[i+1] += black[i];
  }
  for (int i = N; i >= 1; i--) {
    white[i-1] += white[i];
  }

  int ans = 1e18;
  rep (i, N+1) {
    int t = black[i] + white[i+1];
    chmin(ans, t);
  }
  // print1(black, black+N+1);
  // print1(white, white+N+1);

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define ff first
#define tcase int _; cin>> _; for( ; _; --_)
#define ss second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	for(;exp; exp>>=1){
		if(exp % 2 == 1) total = mod(((mod(total, m)) * (mod(base, m))), m);
		base= mod((mod(base, m) * mod(base, m)), m);
	}
	return total;
}

int n;

void solve(){
    cin >> n;
    vi a(n);
    
    vi pref(n, 0);

    for(int i = 0; i < n; ++i){
        cin>> a[i]; 
        if(i == 0) pref[0] = a[0];
        else pref[i] = mod(pref[i - 1] + a[i], MOD); 
    }

    int s = 0LL;
    
    for(int i = n-1; i >= 1; --i)
        s = mod(s + mod(pref[i - 1] * a[i], MOD), MOD);
    cout<< s<< endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x,y,z=1;
  std::cin >> x;
  std::vector<int> v(x);
  rep(i,x)std::cin >> v[i];
  sort(all(v));
  rep(i,x){
    if(log10(z)+log10(v[i])<=18&&z*v[i]<=1000000000000000000){
      z*=v[i];
    }else {
      std::cout << -1 << '\n';
      return 0;
    }
  }
  std::cout << z << '\n';
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        s[k-1]=s[k-1]-'A'+'a';
        cout<<s<<endl;
    }

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  //INPUT
  llint N,K;
  cin >> N>>K;
  vector<llint> H(N);
  rep(i,0,N) {
    cin >> H[i];
  }


  //SOLVE
  llint ans=0;

  rep(i,0,N) {
    if (H[i] >= K) {
      ans++;
    }
  }

  //OUTPUT
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
vector<int>v[maxn];
priority_queue<int>q;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    cerr<<n<<" "<<m<<endl;
    int a,b;
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
    }
    int ans=0;
    for(int i=1;i<=m;i++){
        for(auto c:v[i]) q.push(c);
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    printf("%d\n",ans);
}

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

int main(){

    int n,m;

    cin >> n >> m;

    vector<string> a(n),b(m);

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

    rep(i,m) cin >> b[i];

    for(int i=0;i<=n-m;i++){
        for(int j=0;j<=a[0].size()-b[0].size();j++){
            bool f=true;
            for(int k=0;k<m;k++){
                for(int l=0;l<b[0].size();l++){
                    if(a[i+k][j+l]!=b[k][l]){
                        f=false;
                        break;
                    }
                }
            }
            if(f){
                cout << "Yes" <<endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a;
  int tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    a.push_back(tmp);
  }
  sort(a.begin(),a.end(),greater<int>() );
  int bob=0;
  int alice=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      alice+=a[i];
    }else{
      bob+=a[i];
    }
  }
  cout<<alice-bob<<endl;
}


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

typedef long long ll;

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

    ll L0 = 2;
    ll L1 = 1;
    ll L;

    if (n == 1) {
        L = L1;
    } else {
        for (int i = 2; i <= n; i++) {
            L = L0 + L1;
            L0 = L1;
            L1 = L;
        }
    }

    cout << L << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
    int W;
    int H;
    int i;
    int j;
    while (1) {
        cin >> H >> W;
        if (H==0) {
            if (W==0) break;
        }
        for (j=0;j<W;j++) {
            cout << "#";
        }
        cout << endl;
        for (i=1;i<H-1;i++) {
            for (j=0;j<W;j++) {
                if (j==0) {
                    cout << "#";
                } else if (j==W-1) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        for (j=0;j<W;j++) {
            cout << "#";
        }
        cout << endl << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
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; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

struct LR{
  int id, type, num;
  LR(){}
  LR(int a, int b, int c){
    id = a; type = b; num = c;
  }
};

//当初は複雑なことをしようとしていたため、修正後となっては無駄なことを多くしている

int main(){
  ll N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  vector<LR> box(0);
  vector<LR> lbox(0), rbox(0);
  int idnum = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'L'){
      int counter = 0;
      for(int j = i; j < S.size(); j++){
        if(S.at(j) == 'L') counter++;
        else break;
      }
      box.push_back(LR(idnum, 'L', counter));
      lbox.push_back(LR(idnum, 'L', counter));
      idnum++;
      i += counter-1;
    }
    else{
      int counter = 0;
      for(int j = i; j < S.size(); j++){
        if(S.at(j) == 'R') counter++;
        else break;
      }
      box.push_back(LR(idnum, 'R', counter));
      rbox.push_back(LR(idnum, 'R', counter));
      idnum++;
      i += counter-1;
    }
  }

  ll ans = 0;
  int X = box.size();
  for(int i = 0; i < X; i++){
    ll counter = box.at(i).num;
    while(i+1 < X && box.at(i).type == box.at(i+1).type){
      counter += box.at(i+1).num;
      i++;
    }
    ans += counter - 1;
  }

  int bnum = box.size();
  int counter = 0;
  while(bnum >= 2 && counter < K){
    counter++;
    if(bnum >= 3){
      bnum -= 2;
      ans += 2;
    }
    else{
      bnum--;
      ans++;
    }
  }

  cout << ans << endl;
  //or(auto x: box) cout << x.id << ' ' << (char)x.type << ' ' << x.num << endl;
}

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

int main(){
	int N, M, i, j;
	scanf("%d%d", &N, &M);
	vector<vector<int>> AB(100001, vector<int>(0));
	for(i = 0; i < N; i++){
		int A, B;
		scanf("%d%d", &A, &B);
		AB[A].push_back(B);
	}
	priority_queue<int> pq;
	int ans = 0;
	for(i = 0; i <= M; i++){
		for(j = 0; j < AB[i].size(); j++){
			pq.push(AB[i][j]);
		}
		if(pq.size() > 0){
			ans += pq.top();
			pq.pop();
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

inline
int gcd(int x, int y) {
	if (x % y == 0) return y;
	else return gcd(y, x % y);
}

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

	int n, k; cin >> n >> k;
	vector<int> a(n);
	REP(i, n) cin >> a[i];

	int g = a[0];
	REP(i, n) g = gcd(g, a[i]);

	if (k <= *max_element(a.begin(), a.end()) && k % g == 0)
		cout << "POSSIBLE" << '\n';
	else
		cout << "IMPOSSIBLE" << '\n';
	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main (void){
  int n, a, b, r, x , tmp;

  scanf("%d", &n);

  a = 2;
  b = n;
  
    x = a * b;
    if(a < b){
      tmp = a;
      a = b;
      b = tmp;
    }

    r = a % b;
    while(r != 0){
      a = b;
      b = r;
      r = a % b;
    }

  printf("%d\n", x/b);
  
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    n += 3;

    vector<vector<int> > s(n);
    for(int i=0; i<n; ++i)
        s[i].assign(i+2, 0);

    for(int i=0; i<m; ++i){
        int y, x, a;
        cin >> y >> x >> a;

        ++ s[y][x];
        -- s[y][x+1];
        -- s[y+a+1][x];
        ++ s[y+a+2][x+1];
        ++ s[y+a+1][x+a+2];
        -- s[y+a+2][x+a+2];
    }

    for(int i=0; i<n-1; ++i){
        for(int j=0; j<i+2; ++j){
            s[i+1][j] += s[i][j];
        }
    }

    for(int i=0; i<n; ++i){
        for(int j=0; j<i+1; ++j){
            s[i][j+1] += s[i][j];
        }
    }

    for(int i=-n; i<2; ++i){
        for(int j=0; j<n-1; ++j){
            if(i+j >= 0)
                s[j+1][i+j+1] += s[j][i+j];
        }
    }

    int ret = 0;
    for(int i=0; i<n; ++i){
        for(int j=0; j<i+2; ++j){
            if(s[i][j] > 0)
                ++ ret;
        }
    }
    cout << ret << endl;

    return 0;
}

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

/*label[0]~[5]が1~6に対応（ややこしいけど）*/
class Dice{
    public:
        int label[6];
        void North();
        void South();
        void East();
        void West();
        void Right();/*supplementary function for Dice2*/
};

void Dice::North(){
    int temp=label[0];
    label[0]=label[1];
    label[1]=label[5];
    label[5]=label[4];
    label[4]=temp;
}

void Dice::South(){
    int temp=label[0];
    label[0]=label[4];
    label[4]=label[5];
    label[5]=label[1];
    label[1]=temp;
}

void Dice::East(){
    int temp=label[0];
    label[0]=label[3];
    label[3]=label[5];
    label[5]=label[2];
    label[2]=temp;
}

void Dice::West(){
    int temp=label[0];
    label[0]=label[2];
    label[2]=label[5];
    label[5]=label[3];
    label[3]=temp;
}

/*rotate horizontally*/
void Dice::Right(){
    int temp=label[1];
    label[1]=label[2];
    label[2]=label[4];
    label[4]=label[3];
    label[3]=temp;
}

int main(){
    Dice dice;
    for(int i=0; i<6; i++){cin >> dice.label[i];}
    int q, frontNum, topNum;
    cin >> q;
    while(q--){
        cin >> frontNum >> topNum;
        if(dice.label[2]==frontNum){dice.West();}
        else if(dice.label[3]==frontNum){dice.East();}
        /*まず両サイドの可能性を潰す*/
        /*縦回転のみで探索できるようになる*/

        while(dice.label[0]!=frontNum){dice.North();}
        while(dice.label[1]!=topNum){dice.Right();}

        cout << dice.label[2] << endl;

    }

    return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>

long long int lcd(long long int,long long int);
long long int r;
int main(void){
    //printf(" ");
    long long int m1=1,m2=1,j1,j2;
    long long int n,b,c;
    long long int l=1;
    scanf("%lld",&n);
    for(int i=0; i<n; i++){
        scanf("%lld %lld",&b,&c);
        j1=(m1-1)/b;
        j2=(m2-1)/c;
        if(j2>j1){
            j1=j2;
        }
        m1 = b * (j1+1);
        m2 = c * (j1+1);
        //printf("%lld %lld\n",m1,m2);
    }
    printf("%lld\n",(m1/b)*(b+c));
    return 0;
}
long long int lcd(long long int p,long long int q){
    if(p<q){
        r=p;
        p=q;
        q=r;
    }
        p=p%q;
    if(p!=0){
        return lcd(p,q);
    }
    else{
        return q;
    }
}


Measured memory_bytes: 128
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		System.out.println(N*(N+1)/2);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21716
from collections import deque
from functools import reduce
f = lambda a: (a+1) % M
g = lambda a, b: a * b % M
init = 1

N, M = map(int, input().split())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
T = []
while Q:
    i = deque.popleft(Q)
    T.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BU = [0] * N # Bottom Up
TD = [1] * N # Top Down
for i in T[::-1]:
    BU[i] = reduce(g, [f(BU[j]) for j in X[i]]) if len(X[i]) else init

for i in T:
    B = [1] * (len(X[i]) + 1)
    for k, j in enumerate(X[i]):
        B[k+1] = g(B[k], f(BU[j]))
    a = init
    for k in range(len(X[i]))[::-1]:
        j = X[i][k]
        TD[j] = f(g(TD[i], g(a, B[k])))
        a = g(a, f(BU[j]))

for t in [g(a, b) for a, b in zip(BU, TD)]:
    print(t)


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,T;
    string S;
    cin >> N >> T;

    vector<ll> t(N);
    REP(i,N){
        cin >> t.at(i);
    }

    ll ans = 0;

    for (ll i = 0; i < N-1; i++) {
        if(t.at(i+1)-t.at(i)>T){
            ans += T;
        }
        else{
            ans += t.at(i + 1) - t.at(i);
        }
    }
    ans += T;
    cout << ans << endl;
    
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define Task ""
using namespace std;
const int N=100005;
int n, k, a[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    --k;
    int id=1, ans=0;
    while(id+k<=n) {
        ++ans;
        id+=k;
    }
    if(id<n) ++ans;
    cout << ans;
    return 0;
}


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

string h;

int main(int argc, const char * argv[]) {
  
 
    cin >> h;
    
    sort(h.begin(),h.end());
    
    if(h=="abc") cout << "Yes";
    else cout << "No";
    
    
    return 0;
}

Measured memory_bytes: 384
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

int power(int x, int y) {
    int res = 1;
    while(y) {
        if(y & 1) 
            res = res * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return res;
}

int dp[N];

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n, k;
        cin >> n >> k;

        // 4 4 4 4... -> ye 1, 2 ke gcd me add ho raha hai
        // Fix : dp[i] -= d[j] for all factors j
        for(int i = 1; i <= k; i++) 
            dp[i] = power(k / i, n);
        for(int i = k; i >= 1; i--) {
            for(int j = 2 * i; j <= k; j += i)
                dp[i] = (dp[i] - dp[j] + mod) % mod;
        }

        int ans = 0;
        for(int i = 1; i <= k; i++) {
            // cout << i << ": " << dp[i] << '\n';
            ans = (ans + i * dp[i]) % mod;
        }
        cout << ans << '\n';
    }
    
    return 0;
}



Measured memory_bytes: 4392
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;

int main(void) {
	int a[3][3] = {0};
	
	for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			cin >> a[i][j];
		}
	}
	
	int n;
	cin >> n;
	
	int b[n];
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	
	bool check[3][3] = {false};
	for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			for(int k = 0; k < n; ++k) {
				if( a[i][j] == b[k] ) check[i][j] = true;
			}
		}
	}
	
	string ans = "No";
	for(int i = 0; i < 3; ++i) {
		if( check[i][0] && check[i][1] && check[i][2] ) ans = "Yes";
	}
	
	for(int i = 0; i < 3; ++i) {
		if( check[0][i] && check[1][i] && check[2][i] ) ans = "Yes";
	}
	
	if( check[0][0] && check[1][1] && check[2][2] ) ans = "Yes";
	if( check[0][2] && check[1][1] && check[2][0] ) ans = "Yes";
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main(){
    int n;
    int k;
    cin>>n>>k;
    vi arr(n+k,(int)10e6);
    vi dp(n+k,0);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int term;
    for(int i=n-2;i>=0;i--){
        int mini=INT_MAX;
        for(int j=1;j<=k;j++){
            term=abs(arr[i]-arr[i+j]) + dp[i+j];
            if( term < mini ){
                mini = term;
            }
        }
        dp[i]=mini;
    }
    cout<<dp[0]<<"\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
using namespace std;

const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
int H,W,ans;
char fld[20][20];

void dfs(int y,int x){
    int ny,nx;
    ans++; fld[y][x] = '#';
    for(int i=0;i<4;i++){
        ny = y+dy[i]; nx = x+dx[i];
        if(0<=ny && ny<H && 0<=nx && nx<W && fld[ny][nx]=='.') dfs(ny,nx);
    }
}

int main(){
    int sy,sx;
    while(cin>>W>>H,H||W){
        ans = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>fld[i][j];
                if(fld[i][j]=='@') sy = i, sx = j;
            }
        }
        dfs(sy,sx);
        printf("%d\n",ans);
    }
}

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

int n, a[100004];

int main() {
	cin>>n;
	for(int i = 0 ;i<n;i++)	cin>>a[i];
	int ans = 0, cnt = 0;
	for(int i = 0;i<n-1;i++){
		if(a[i]>=a[i+1])	cnt++;
		else{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout<<ans;
	return 0;
}

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

using namespace std;

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

	vector<int> H(N, 0);

	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}
	int Ha = H[N - 1];

	bool is_d = true;
	for (int i = N - 2; i >= 0; --i) {
		if (H[i] > Ha + 1) {
			is_d = false;
			break;
		}
		else if (H[i] == Ha + 1) {
			continue;
		}
		else if (H[i] < Ha + 1) {
			Ha = H[i];
		}
	}

	if (is_d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 640