akhauriyash/Code-Regression huggingface dataset:
// atcoder/hitachi2020/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.setf(std::ios_base::fixed);
  std::cout.precision(15);

  int a, b, m;
  while (cin >> a >> b >> m) {
    vec<int> x(a);
    vec<int> y(b);
    cin >> x >> y;
    int mn = *min_element(x.begin(), x.end()) + *min_element(y.begin(), y.end());
    for (int i = 0; i < m; ++i) {
      int p, q, r;
      cin >> p >> q >> r;
      --p;
      --q;
      setmin(mn, x[p] + y[q] - r);
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

using namespace std;
int main(){
    int A,B,C,result;
    cin >> A >> B >> C;
    int D = B /A;
    if(D>C){
        result = C;
    } else  {
        result = D;
    }
    cout << result << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int L[105];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> L[i];
	}
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = i+1; j < N; ++j)
		{
			for (int k = j+1; k < N; ++k)
			{
				int a = L[i], b = L[j], c = L[k];
				if (a == b || b == c || c == a) continue;
				int M = max(a,max(b,c));
				if (M < a+b+c-M) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    for(int i=0; i<M; ++i){
        cin >> a[i] >> b[i];
    }
    int answer[N];
    for(int i=0; i<N; ++i) answer[i]=0;
    for(int i=0; i<N; ++i){
        for(int j=0; j<M; ++j){
            if(a[j] == i+1) answer[i]++;
            if(b[j] == i+1) answer[i]++;
        }
    }
    for(int i=0; i<N; ++i){
        cout << answer[i] << endl;
    }
}

Measured memory_bytes: 256
n, x, y = map(int, input().split())
freq = [0 for i in range(n+1)]
for i in range(1, n+1):
  for j in range(i+1, n+1):
    dist = min(j-i, abs(i-x) + 1 + abs(y-j))
    freq[dist] += 1
for i in range(1,n):
  print(freq[i])

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>

using namespace std;

struct edge {
	static constexpr auto INF = std::numeric_limits<long long>::max();

	edge(int src, int dst, long long weight)
		: src(src), dst(dst), weight(weight)
	{
	}

	bool operator<(const edge& other) const
	{
		return std::tie(other.weight, src, dst) < std::tie(weight, other.src, other.dst);
	}

	int src;
	int dst;
	long long weight;
};

using graph = std::vector<std::vector<edge>>;

void add_edge(graph& g, int src, int dst, long long weight)
{
	g[src].emplace_back(src, dst, weight);
}

void dijkstra_shortest_paths(const graph& g, int s, std::vector<long long>& d, std::vector<int>& p)
{
	int n = g.size();
	d.assign(n, edge::INF);
	d[s] = 0;
	p.assign(n, -1);
	std::priority_queue<edge> q;
	q.emplace(-2, s, 0);
	while (!q.empty()) {
		auto e = q.top();
		q.pop();
		if (p[e.dst] != -1) {
			continue;
		}
		p[e.dst] = e.src;
		for (auto& f : g[e.dst]) {
			auto w = e.weight + f.weight;
			if (d[f.dst] > w) {
				d[f.dst] = w;
				q.emplace(f.src, f.dst, w);
			}
		}
	}
}

void dijkstra_shortest_paths(const graph& g, int s, std::vector<long long>& d)
{
	std::vector<int> p;
	dijkstra_shortest_paths(g, s, d, p);
}

int main()
{
	int H, W;
	int Ch, Cw;
	int Dh, Dw;
	vector<string> S;
	vector<vector<int>> best;

	cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
	--Ch;
	--Cw;
	--Dh;
	--Dw;
	S.resize(H);
	for (auto& x : S) {
		cin >> x;
	}

	auto ok = [&](int y, int x)
	{
		return 0 <= y && y < H && 0 <= x && x < W&& S[y][x] == '.';
	};

	auto idx = [&](int y, int x)
	{
		return y * W + x;
	};

	graph g(H * W);
	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			for (int dy = -1; dy <= +1; ++dy) {
				for (int dx = -1; dx <= +1; ++dx) {
					if (abs(dy) + abs(dx) != 1) {
						continue;
					}
					int y2 = y + dy;
					int x2 = x + dx;
					if (!ok(y2, x2)) {
						continue;
					}
					add_edge(g, idx(y, x), idx(y2, x2), 0);
				}
			}

			for (int dy = -2; dy <= +2; ++dy) {
				for (int dx = -2; dx <= +2; ++dx) {
					if (abs(dy) + abs(dx) <= 1) {
						continue;
					}
					int y2 = y + dy;
					int x2 = x + dx;
					if (!ok(y2, x2)) {
						continue;
					}
					add_edge(g, idx(y, x), idx(y2, x2), 1);
				}
			}
		}
	}

	long int goal = idx(Dh, Dw);
	vector<long long> d(H * W);
	dijkstra_shortest_paths(g, idx(Ch, Cw), d);

	if (d[goal] != edge::INF) {
		cout << d[goal] << endl;
	}
	else {
		cout << -1 << endl;
	}
}



Measured memory_bytes: 304212
def main():
    S = input()
    T = input()
    # Sのi文字目をTの先頭として，それらの文字列の一致度を見る．

    st = set()
    for i in range(len(S)-len(T)+1):
        cnt = 0
        for s, t in zip(S[i:i+len(T)], T):
            cnt += s == t
        st.add(cnt)
    print(len(T) - max(st))


if __name__ == '__main__':
    main()

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

using vi = vector<int>;

int main()
{
    vi v(3);

    cin >> v[0] >> v[1] >> v[2];

    sort(begin(v), end(v));

    int ans = v[0] + v[1];

    cout << ans << endl;

    return 0;
}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}


int main() {
	string s;
	cin >> s;
	int n = s.length();
	int k = nxt();

	if (*min_element(all(s)) == *max_element(all(s))) {
		cout << 1ll * n * k / 2 << "\n";
		return 0;
	}

	if (s[0] != s.back()) {
		long long ans = 0;
		int cnt = 0;
		char last = 0;
		for (char c : s) {
			if (c != last) {
				ans += cnt / 2;
				cnt = 0;
			}
			++cnt;
			last = c;
		}
		ans += cnt / 2;
		cout << ans * k << "\n";
		return 0;
	}

	int f = 0, l = n - 1;
	while (s[f] == s[0]) {
		++f;
	}
	while (s[l] == s[n - 1]) {
		--l;
	}
	long long ans = 0;
	int cnt = 0;
	char last = 0;
	for (int i = f; i <= l; ++i) {
		char c = s[i];
		if (c != last) {
			ans += cnt / 2;
			cnt = 0;
		}
		++cnt;
		last = c;
	}
	ans += cnt / 2;
	ans *= k;
	ans += (f + n - 1 - l) / 2 * 1ll * (k - 1);
	ans += f / 2;
	ans += (n - 1 - l) / 2;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function tsort(e::Array{Int,2},n,m)
	g = [Int[] for i in 1:n]
	d = zeros(Int,n)
	v = zeros(Int,n)
	for i in 1:m
		push!(g[e[1,i]],e[2,i])
		d[e[2,i]] += 1
	end
	s = Int[]
	for i in 1:n
		if d[i] == 0
			push!(s,i)
		end
	end
	l = Int[]
	while !isempty(s)
		t = pop!(s)
		push!(l,t)
		for i in 1:length(g[t])
			d[g[t][i]] -= 1
			if d[g[t][i]] == 0
				push!(s,g[t][i])
			end
		end
	end
	if length(l) == n
		l
	else
		false
	end
end

function main()
	n,m = readline() |> split |> parseMap
	e = zeros(Int,2,n-1+m)
	g = [Int[] for i in 1:n]
	for i in 1:n-1+m
		e[:,i] = readline() |> split |> parseMap
		push!(g[e[2,i]],e[1,i])
	end
	ts = tsort(e,n,n+m-1)
	nm = zeros(Int,n)
	for i in 1:n
		nm[ts[i]] = i
	end
	t = zeros(Int,n)
	for i in n:-1:1
		mx = 0
		mi = 0
		for j in g[ts[i]]
			if nm[j]>mx
				mx = nm[j]
				mi = j
			end
		end
		t[ts[i]]=mi
	end
	for i in 1:n
		println(t[i])
	end
end

main()

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int l;

string find_ans(string s)
{
    int ans[l+2][l+2];
    memset(ans,0,sizeof(ans));
    string res="";
    int len=0,i,j,index=0;
    for(i=1; i<=l; i++)
    {
        for(j=i+1; j<=l; j++)
        {
            if(s[i-1] == s[j-1]  &&  ans[i-1][j-1] < (j-i))
            {
                ans[i][j]=ans[i-1][j-1]+1;
                if(ans[i][j] > len)
                {
                    len=ans[i][j];
                    index=max(i,index);
                }
            }
            else
            {
                ans[i][j]=0;
            }
        }
    }
    if(len > 0)
    {
        for(i=index-len+1;i<=index;i++)
        {
            res.push_back(s[i-1]);
        }
    }
    return res;
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("input.txt","w",stdout);

    string s;
    cin >> l >> s;
    s=find_ans(s);
    cout << s.SZ;
    return 0;
}


Measured memory_bytes: 98048
def main():
    n, m, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    c = 0
    ac = 0
    for ai in a:
        if ac + ai > k:
            break
        c += 1
        ac += ai
    m = (c, 0)
    d = 0
    for bi in b:
        while ac + bi > k:
            if c <= 0:
                break
            ac -= a[c - 1]
            c -= 1
        if ac + bi > k:
            break
        d += 1
        ac += bi
        if c + d > sum(m):
            m = (c, d)
    print(sum(m))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40572
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(str[0]);
        int m=Integer.parseInt(str[1]);
        int x=Integer.parseInt(str[2]);
        int arr[][]=new int[n][m+1];
        for(int i=0;i<n;i++)
        {
            str=br.readLine().split(" ");
            for(int j=0;j<=m;j++)
            arr[i][j]=Integer.parseInt(str[j]);
        }
        boolean b=true;
        for(int i=1;i<=m;i++)
        {
            int sum=0;
            for(int j=0;j<n;j++)
            {
                sum+=arr[j][i];
            }
            if(sum<x)
            {
                b=false;
                break;
            }
        }
        if(b)
        {
            /*Arrays.sort(arr,new comp());
            int sum[]=new int[m];
            for(int i=1;i<=m;i++)
            {
                for(int j=0;j<n;j++)
                sum[i-1]+=arr[j][i];
            }
            int minind=0,minsum=sum[0];
            for(int i=1;i<m;i++)
            {
                if(minsum<sum[i])
                {
                    minind=i;
                    minsum=sum[i];
                }
            }
            boolean arr[]=new boolean[n];
            for(int i=n-1;i>=0;i--)
            {
                
            }*/
            int min=(int)(1e9);
            for(int i=0;i<(1<<n);i++)
            {
                int cost=0;
                int sum[]=new int[m];
                for(int j=0;j<n;j++)
                {
                    if((i&(1<<j))>0)
                    {
                        cost+=arr[j][0];
                        for(int k=1;k<=m;k++)
                        sum[k-1]+=arr[j][k];
                    }
                }
                boolean check=true;
                for(int j=0;j<m;j++)
                {
                    if(sum[j]<x)
                    {
                        check=false;
                        break;
                    }
                }
                if(check)
                min=Math.min(min,cost);
            }
            pw.println(min);
        }
        else
        pw.println(-1);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 34424
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    char s[11], ans[11];
    ll a=0;
    scanf("%s", s);
    rep(i, 0, strlen(s)){
        if(s[i]=='B') {
            if(a>0) a--;
            ans[a] = '\0';
        }
        else {
            ans[a] = s[i];
            ans[a+1] = '\0';
            a++;
        }
    }
    printf("%s\n", ans);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;


int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a > 0 && c > 0){
		c = c - b;
		if( c <= 0){
			cout<<"Yes"<<endl;
			break;
		}

		a = a - d;
		if( a <= 0){
			cout<<"No"<<endl;
			break;
		}

	}
	return 0;
}



Measured memory_bytes: 3632
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 配列数 - 取得
	int liCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liCnt);

	// 最大値 - 取得
	int liSum = 0;
	for (i = 0; i < liCnt; i++) {

		// 配列 - 取得
		int liVal;
		fscanf(szpFpI, "%d", &liVal);

		// 最大値 - 加算
		liSum += liVal - 1;
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	
	// 結果 - セット
	sprintf(lc1Out, "%d\n", liSum);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

#define MAX 20

int a[MAX+1], b[MAX+1];
int sum[MAX];
int a_size, b_size, sum_size;

void culc(int carry) {
	if(sum_size<a_size && sum_size<b_size)
		sum[sum_size] = a[sum_size] + b[sum_size] + carry;
	else if(sum_size>=a_size && sum_size<b_size)
		sum[sum_size] = b[sum_size] + carry;
	else if(sum_size<a_size && sum_size>=b_size)
		sum[sum_size] = a[sum_size] + carry;
	else if(sum_size>=a_size && sum_size>=b_size)
		sum[sum_size] = carry;

	if(sum[sum_size]>9) {
		sum[sum_size] -= 10;
		carry = 1;
	} else {
		carry = 0;
	}
	if( (++sum_size<a_size || sum_size<b_size) || carry==1  )
		culc(carry);
	return;
}

int main(void) {
	int n;
	int i, j;
	int x, carry;

	while(scanf("%d", &n) != EOF) {
		sum_size = 0;
		sum[sum_size++] = 1;
		for(i = 2; i <= n; i++) {
			a_size = sum_size;
			b_size = sum_size+1;
			if(i%10) {
				carry = 0;
				for(j = 0; j < a_size; j++) {
					x = sum[j]*(i%10) + carry;
					a[j] = x%10;
					carry = x/10;
				}
				if(carry) {
					a[a_size++] = carry;
				}
			} else {
				a_size = 0;
			}
			if(i/10) {
				carry = 0;
				b[0] = 0;
				for(j = 1; j <= b_size; j++) {
					x = sum[j-1]*(i/10) + carry;
					b[j] = x%10;
					carry = x/10;
				}
				if(carry) {
					b[b_size++] = carry;
				}
			} else {
				b_size = 0;
			}
			sum_size = 0;
			culc(0);
		}
		for(j = sum_size-1; j >= 0; j--) {
			printf("%d", sum[j]);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define MOD 1000000007
using namespace std;

int main(){
  int k, x;
  cin >> k >> x;
  if (k * 500 >= x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
 } 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int n, l;
	cin >> n >> l;
	vector <int> A(n + 1);
	int sum = 0, ans = MOD;
	for (int i = 1; i <= n; i++)
	{
		sum += l + i - 1; 
	}
	for (int i = 1; i <= n; i++)
	{
		if(abs(sum - (l + i - 1) - sum) < abs(sum - ans))
		{
			ans = sum - (l + i - 1);
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
// 草
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

LL I, O, T, J, L, S, Z;

int main() {
  scanf("%lld%lld%lld%lld%lld%lld%lld", &I, &O, &T, &J, &L, &S, &Z);

  LL cnt = min(I, min(J, L));
  LL ans;
  if (cnt == 0) {
    ans = (I/2) * 4 + (J/2) * 4 + (L/2) * 4 + O * 2;
  } else {
    ans = (I/2) * 4 + (J/2) * 4 + (L/2) * 4 + O * 2;
    ans = max(ans, 6 + ((I-1)/2) * 4 + ((J-1)/2) * 4 + ((L-1)/2) * 4 + O * 2);
  }
  printf("%lld\n", ans/2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  string s;
  cin >> s;
  vector<int> dp(1<<26,1e9);
  dp[0]=0;
  ll x=0;
  for(char c:s) {
    x^=1<<(c-'a');
    for(ll i=0;i<26;i++) dp[x]=min(dp[x],dp[x^(1<<i)]+1);
  }
  cout << max(1,dp[x]) << endl;
}

Measured memory_bytes: 265788
<?php
//error_reporting(0);
//$X = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
$l[]=explode(" ",trim(fgets(STDIN)));
$l[]=explode(" ",trim(fgets(STDIN)));

$total = 0;
for($i=0;$i<$N;$i++) {
  $total = max($total,kei($i+1));
}
printf("%d\n",$total);

function kei($x) {
  global $l,$N;
  //x行で下に移動した場合の合計を返す
  $sum = 0;
  for($i=0;$i<$x;$i++) {
    $sum += $l[0][$i];
  }
  for($i=$x-1;$i<$N;$i++) {
    $sum += $l[1][$i];
  }
  return $sum;
}


Measured memory_bytes: 3956
n = gets.chomp.to_i
@a_array = gets.chomp.split(' ').map(&:to_i)
@b_array = gets.chomp.split(' ').map(&:to_i)

@output = 0

@b_array.each_with_index do |b, i|
  carry_over = b - @a_array[i]
  if carry_over <= 0 # b が a を超えない場合
    @output += b
  else # b が a を超えている場合
    if @a_array[i+1] >= carry_over
      @output += b
      @a_array[i+1] -= (b - @a_array[i])
    else
      @output += @a_array[i] + @a_array[i+1]
      @a_array[i+1] = 0
    end
  end
end

puts @output


Measured memory_bytes: 17572
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=100005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int a[MAXN],f[MAXN];
map<int,int> mp[MAXN];
int find(int x){ return f[x]==x?f[x]:f[x]=find(f[x]); }
int main()
{
	int n=read(),m=read(),ans=0;
	for (int i=1;i<=n;i++) a[i]=read(),f[i]=i;
	for (int i=1;i<=m;i++)
	{
		int u=find(read()),v=find(read());
		if (u!=v) f[u]=v;
	}
	for (int i=1;i<=n;i++) mp[find(i)][i]=1;
	for (int i=1;i<=n;i++)
		if (mp[find(i)][a[i]]) ans++;
	printf("%d\n",ans);  
	return 0;
}

Measured memory_bytes: 18496
n = gets.to_i
ans = []
if(n > 0)
  st = n.abs.to_s(2)
  i = -1
  while(-(st.size)<= i)
    if (st[i]=="0")
        ans.push(0)
      else
      if(i%2 == 1)
        ans.push(1)
      else
        ans.push(1)
        st = (st.to_i(2)+2**(i.abs-1)).to_s(2)
      end
    end
    i -= 1
  end 
  puts ans.join.reverse
else
st = n.to_i.abs.to_s(2)
i = -1
while(-(st.size)<= i)
  
  if (st[i]=="0")
      ans.push(0)
    else
    if(i%2 == 0)
      ans.push(1)
    else
      ans.push(1)
      st = (st.to_i(2)+2**(i.abs-1)).to_s(2)
    end
  end
  i -= 1
  end 
  puts ans.join.reverse
end

Measured memory_bytes: 1788
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int gcd(int i, int j) {
    int tmp;
    if (i < j) {
        tmp = i;
        i = j;
        j = tmp;
    }
    while ( (tmp = i % j) != 0 ) {
        i = j;
        j = tmp;
    }
    return j;
}

int main() {
    int K;
    cin >> K;
    long ret = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1;c <= K; c++) {
                ret += gcd(gcd(a,b),c);
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3632
import std.algorithm : map, group, filter, sort;
import std.array : array;
import std.conv : to;
import std.range : take, empty, iota;
import std.stdio : readln, writeln;
import std.string : split, chomp, join;

void main()
{
  for(int n; (n = readln.chomp.to!int) != 0; ){
    string[] words;

    foreach(i; iota(n))
      words ~= readln.chomp.split;

    words.sort;
    auto wc = group(words);
    auto c = readln[0];

    auto wcf = wc.filter!(a => a[0][0] == c).array;
    sort!"a[1] == b[1] ? a[0] < b[0] : a[1] > b[1]"(wcf);

    string output = wcf.map!"a[0]".take(5).array.join(" ");

    writeln(output.length ? output : "NA");
  }
}

Measured memory_bytes: 2076
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;


int main(void){
    int N,cnt=0;
    cin>>N;
    REP(i,10){
        if(N<=cnt){
            cout<<cnt<<endl;
            return 0;
        }
        cnt+=111;
    }
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

typedef struct _item{
	int value;
	vector<string> resipi;
}item;

vector<string>::iterator vp;

map<string,item> minlist;
map<string,item>::iterator mp;

int n,m;

int main(){
	
	
	while(cin>>n,n){
		
		minlist.clear();
		
		for(int i=0;i<n;i++){
			string name;
			int v;
			cin>>name>>v;
			minlist[name].value=v;
		}
		
		cin>>m;
		
		for(int i=0;i<m;i++){
			string name;
			cin>>name;
			
			int o;
			cin>>o;
			for(int j=0;j<o;j++){
				string genryou;
				cin>>genryou;
				minlist[name].resipi.push_back(genryou);
			}
		}
		
		int flag=1;
		
		
		while(flag){
			flag=0;
			for(mp=minlist.begin();mp!=minlist.end();mp++){
				int tvalue=0;
				if(mp->second.resipi.size()==0)continue;
				for(vp=mp->second.resipi.begin();vp!=mp->second.resipi.end();vp++){
					tvalue+=minlist[*vp].value;
				}
				if(tvalue<(mp->second.value)){
					mp->second.value=tvalue;
					flag=1;
				}
			}
		}
		
		string target;
		cin>>target;
		cout<<minlist[target].value<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int arr[502];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s, t; cin >> s >> t;

    int a = 0;

    for(int i = 0; i < 3; ++i)
        if(s[i] == t[i])
            ++a;

    cout << a;

    return 0;
}


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

typedef long long int LLI;

int main()
{
    LLI max;
    int n;
    LLI cnt=0;
    scanf("%I64d %d",&max,&n);
    for(int i=0;i<n;i++){
        int pnt;
        scanf("%d",&pnt);
        cnt+=pnt;
    }
    if(cnt>=max) printf("Yes");
    else printf("No");
    return 0;
}

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

int main()
{
	string s,t;
	int f=0;
	cin>>s>>t;
	for(char i='a';i<='z';++i) {
		if(s+i==t) f=1;
	}
	puts(f?"Yes":"No");
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

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

int main(){
  ll n,x;cin>>n>>x;
  vector<ll> v(n);
  rep(i,n){
    cin>>v[i];
  }
  v.pb(x);
  sort(all(v));
  // 距離差の最大公約数を出せば良い．
  vector<ll> diff(n);
  rep(i,n){
    diff[i]=v[i+1]-v[i];
  }
  ll ans=diff[0];
  rep(i,n){
    ans=gcd(ans,diff[i]);
  }
  cout<<ans<<endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M; cin >> N >> M;
  vector<int> H(N + 1); for(int i = 1; i <= N; ++i) cin >> H[i];
  vector<int> A(M), B(M); REP(i, M) cin >> A[i] >> B[i];

  vector<int> ans(N + 1);
  for(int i = 1; i <= N; ++i) ans[i] = 0;

  REP(i, M) {
    ans[A[i]] = max(ans[A[i]], H[B[i]]);
    ans[B[i]] = max(ans[B[i]], H[A[i]]);
  }

  int cnt = 0;
  for(int i = 1; i <= N; ++i) {
    if(H[i] > ans[i]) cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 4844
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; 

const int N=100010, INF=1000000000;
int n, mina=INF, maxa=-1, cnt;
int a[N];

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; ++i){
		scanf("%d", &a[i]);
		mina = min(mina, a[i]);
		maxa = max(maxa, a[i]);
	}
	if(maxa-mina>1){ puts("No"); return 0; }
	if(maxa==mina){ printf("%s\n", (maxa<=n/2 || maxa==n-1) ? "Yes" : "No" ); return 0; }
	for(int i=1; i<=n; ++i) if(a[i]==mina) cnt++;
	maxa-=cnt; n-=cnt; if(maxa<=0){ puts("No"); return 0; }
	printf("%s\n", (maxa<=n/2) ? "Yes" : "No" );
}


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

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    cout << A + B + C + max(max(A, B), C) * (int(pow(2, K)) - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())

children_map = [None] * n
vals = [0] * n

for i in range(1, n):
    a, b = map(int, input().split())
    children_map[b - 1] = a - 1

for j in range(q):
    p, x = map(int, input().split())
    vals[p - 1] += x

for i in range(n):
    parent = children_map[i]
    if parent is not None:
        vals[i] += vals[parent]

print(*vals)

Measured memory_bytes: 66976
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n=in();
	string snake;
	while(n--){
		cin>>snake;
		int i;
		bool a=true,b=true;
		if(snake.size()<6||snake.size()%2!=0){
			a=false;
			b=false;
		}
		for(i=0;i<snake.size();i++){
			if(i==0){
				if(snake[i]!='>'){
					a=false;
					b=false;
				}
			}
			if(i==1){
				if(snake[i]!='\'')a=false;
				if(snake[i]!='^')b=false;
			}
			if(i*2==snake.size()){
				if(snake[i]!='#')a=false;
			}
			if(i==snake.size()-1){
				if(snake[i]!='~'){
					a=false;
					b=false;
				}
			}
			if(i==snake.size()-2){
				if(snake[i]!='~')b=false;
			}
			if(i!=0&&i!=1&&i*2!=snake.size()&&i!=snake.size()-1){
				if(snake[i]!='=')a=false;
			}
			if(i%2==0&&i!=0&&i!=snake.size()-2){
				if(snake[i]!='Q')b=false;
			}
			if(i%2==1&&i!=1&&i!=snake.size()-1){
				if(snake[i]!='=')b=false;
			}
		}
		if(a){
			cout<<"A\n";
		}else if(b){
			cout<<"B\n";
		}else{
			cout<<"NA\n";
		}
	}
	return 0;
}

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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/


  int N,X;

  cin>>N>>X;

  int L[101];

  int cnt=0,ans=1;
  
  for(int i=0;i<N;i++){

    cin>>L[i];

    cnt+=L[i];

    if(cnt<=X)
      ans++;
  }

  cout<<ans<<endl;


  
  
  return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int t[256][256];
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				scanf("%1d", &t[i][j]);

		int maxLen = 0;
		for (int i = 0; i < n; ++i)
		{
			int v, h;
			v = h = 0;
			for (int j = 0; j < n; ++j)
			{
				if (t[i][j])
					maxLen = max(maxLen, ++v);
				else
					v = 0;
				if (t[j][i])
					maxLen = max(maxLen, ++h);
				else
					h = 0;
			}
			int a, b, c, d;
			a = b = c = d = 0;
			for (int j = 0; i+j < n; ++j)
			{
				if (t[j][i+j])
					maxLen = max(maxLen, ++a);
				else
					a = 0;
				if (t[i+j][j])
					maxLen = max(maxLen, ++b);
				else
					b = 0;
				if (t[j][n-1-i-j])
					maxLen = max(maxLen, ++c);
				else
					c = 0;
				if (t[i+j][n-1-j])
					maxLen = max(maxLen, ++d);
				else
					d = 0;
			}
		}
		printf("%d\n", maxLen);
	}

	return 0;
}

Measured memory_bytes: 1136
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int a[200000];
ll boom[3];
int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<n; i++)
        if(s[i]=='R') boom[0]++;
        else if(s[i]=='G') boom[1]++;
        else boom[2]++;
    ll sum=boom[0]*boom[1]*boom[2];
    for(int i=0; i<n; i++)
        for(int j=1; j<n; j++)
        {
            if(i+2*j>=n) break;
            if(s[i]!=s[i+j]&&s[i]!=s[i+2*j]&&s[i+j]!=s[i+2*j])
                sum--;
        }
    if(sum<0) sum=0;
    cout<<sum<<endl;
}



Measured memory_bytes: 3660
import java.util.Scanner;
import java.math.BigInteger;

class Main {
    private static BigInteger gcd(BigInteger a, BigInteger b) {
        if (a.mod(b).equals(BigInteger.ZERO)) {
            return b;
        } else {
            return gcd(b, a.mod(b));
        }
    }

    private static BigInteger lcm(BigInteger a, BigInteger b) {
        BigInteger gcd = gcd(a, b);
        return a.multiply(b).divide(gcd);
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int n = scanner.nextInt();
            if (n == 0) {
                break;
            }
            BigInteger[][] dv = new BigInteger[n][2];
            for (int i = 0; i < n; i++) {
                dv[i][0] = BigInteger.valueOf(scanner.nextInt());
                dv[i][1] = BigInteger.valueOf(scanner.nextInt());
            }
            BigInteger lcmV = dv[0][1];
            for (int i = 1; i < n; i++) {
                lcmV = lcm(dv[i][1], lcmV);
            }
            for (int i = 0; i < n; i++) {
                dv[i][0] = dv[i][0].multiply(lcmV).divide(dv[i][1]);
            }
            BigInteger lcmD = dv[0][0];
            for (int i = 1; i < n; i++) {
                lcmD = lcm(dv[i][0], lcmD);
            }
            for (int i = 0; i < n; i++) {
                System.out.println(lcmD.divide(dv[i][0]));
            }
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){fastio
    ll n,m,k;cin>>n>>m>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll dp[n][k];memset(dp,0,sizeof(dp));
    rep(i,0,n-1){
        dp[i][0]=a[i];
    }
    //rep(i,0,n-1)cout<<dp[i][0]<<" ";cout<<endl;
    rep(j,1,k-1){
        deque<ll>dq;
        rep(i,0,n-1){
            while(dq.size()!=0&&dp[dq.back()][j-1]<dp[i][j-1]){
                dq.pop_back();
            }
            if(i>=j)dp[i][j]=dp[dq.front()][j-1]+a[i]*(j+1);
            dq.push_back(i);
            if(dq.front()==i-m){
                dq.pop_front();
            }
            //cout<<dp[i][j]<<" ";
            //cout<<dq.size()<<" ";
        }//cout<<endl;
    }/*
    rep(j,0,k-1){
        rep(i,0,n-1){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
      }*/
    
    ll ans=0;
    rep(j,0,n-1)Max(ans,dp[j][k-1]);
    cout<<ans<<endl;
    
    return 0;
}
/*
 5 2 3
 10 3 8 9 2
 */



Measured memory_bytes: 235520
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(ll i=0;i< (n);i++)
#define rep1(i,n) for(ll i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const static ll MOD = (1e+9)+7;

ll modpow(ll a,ll n){
    if(n==0)return 1;
    if(n%2==1)return a*modpow(a,n-1)%MOD;
    ll t = modpow(a,n/2) % MOD;
    return t*t % MOD;
}

int main(){
    ll n;cin>>n;
    vector<bool> A(n,0);
    ll num_w=0;
    rep(i,n){
        char tmp;cin>>tmp;
        if(tmp == '#')A[i]=1;
        else num_w++;
    }
    vector<ll> lst(n+1,-1);
    lst[0] = num_w;
    rep1(i,n){
        if(A[i-1]==1){
            lst[i] = lst[i-1]+1;
        }else{
            lst[i] = lst[i-1]-1;
        }
    }
    ll ans = MOD;
    rep(i,n+1){
        ans = min(ans,lst[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  int ans = 1e9;
  for (int i = 0; i < N; i++) cin >> x.at(i);
  
  for (int i = 0; i < N - K + 1; i++) {
    int l = min(abs(x.at(i)),abs(x.at(i+K-1))) + abs(x.at(i+K-1)-x.at(i));
    ans = min(ans,l);
  }
    
  cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <climits>
#include <queue>

#define INF (INT_MAX/3);

using namespace std;

class Edge{
    public:
        int to;
        int cost;
};

typedef pair<int, int> D_V;


int main(){
    int n;
    int a, b, c;
    while(true){
        cin >> n;
        if(n == 0) break;
        int max_n = 0;
        vector<Edge> edge[46];
        for(int i = 1; i <= n; i++){
            cin >> a >> b >> c;
            max_n = max(max_n, a);
            max_n = max(max_n, b);
            Edge e1, e2;
            e1.to = b;
            e1.cost = c;
            e2.to = a;
            e2.cost = c;
            edge[a].push_back(e1);
            edge[b].push_back(e2);
        }
        int d[46];
        int ans = INF;
        int ans_c;
        int sum;
        priority_queue<D_V, vector<D_V>, greater<D_V> > q;
        for(int s = 0; s <= max_n; s++){
            for(int i = 0; i <= max_n; i++){
                d[i] = INF;
            }
            d[s] = 0;
            
            q.push(D_V(d[s], s));
            
            while(!q.empty()){
                D_V d_v = q.top();
                q.pop();
                int v = d_v.second;

                if(d[v] < d_v.first) continue; 

                for(int i = 0; i < edge[v].size(); i++){
                    Edge e = edge[v][i];
                    if(d[e.to] > d[v] + e.cost){
                        d[e.to] = d[v] + e.cost;
                        q.push(D_V(d[e.to], e.to));
                    }
                }
            }
           
            sum = 0;
            for(int i = 0; i <= max_n; i++){
                sum += d[i];
            }
            if(ans > sum){
                ans = sum;
                ans_c = s;
            }
        }

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

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};


int main(){
	
	int N;
	cin>>N;
	unionfind uf(1000005);
	vector<int> A(N);
	bool f = true;
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
		if(A[i]!=1&&uf.check(0,A[i])){
			f=false;
		}
		uf.unite(0,A[i]);
	}
	
	if(f){
		for(int i=2;i<=1000000;i++){
			int cnt = 0;
			for(int j=i;j<=1000000;j+=i){
				if(uf.check(0,j))cnt++;
			}
			if(cnt>1){
				f=false;
				break;
			}
		}
		
		if(f){
			cout<<"pairwise coprime"<<endl;
			return 0;
		}
	}
	
	int g = 0;
	for(int i=0;i<N;i++){
		g = gcd(g,A[i]);
	}
	
	if(g==1)cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
	
	return 0;
}


Measured memory_bytes: 15032
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1][3],dp[n+1][3];
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

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

long long kaijo(long long n, long long m){
  m %= 1000000007;
  if(n == 0 || n == 1) return(m);
  else return kaijo (n - 1, m * n);
}

int main(){
  long long N, M, count;
  cin >> N >> M;
  if(N == M) count = 2 * kaijo(N, 1) * kaijo(M , 1);
  else if(N == M + 1|| M == N + 1) count = kaijo(N, 1) * kaijo(M , 1);
  else count = 0;
  count %= 1000000007; 
  cout << count << endl;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int ans = 0;
        for(int i = 0; i < n - 2; i++){
            if(s.charAt(i) == 'A' && s.charAt(i + 1) == 'B' && s.charAt(i + 2) == 'C') ans += 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int main (int argc, char* argv[]) {
	int h, w, hh, ww;
	cin >> h >> w >> hh >> ww;
	cout << (h * w - w * hh - h * ww + hh * ww) << endl;
}


Measured memory_bytes: 256
n=int(input())
M=[list(map(int,input().split()))for _ in[0]*n]
d=[0]+[1e4]*~-n
p=[-1]*n
b=[1]*n
while 1:
 m,u=1e4,-1
 for i in range(n):
  if m>d[i]and b[i]:m,u=d[i],i
 if u<0:break
 b[u]=0
 for v in range(n):
  if b[v]and 1+M[u][v]and d[v]>M[u][v]:
   d[v],p[v]=M[u][v],u
print(sum(M[i][p[i]]for i in range(n)if p[i]+1))


Measured memory_bytes: 5904