akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(void) {

	int n,i,j,u,k,tmp;
	int list[100][100]={};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&u);
		scanf("%d",&k);
		for(j=0;j<k;j++){
			scanf("%d",&tmp);
			list[u-1][tmp-1]=1;
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			printf("%d",list[i][j]);
			if(j==n-1){break;}
			printf(" ");
		}printf("\n");
	}

	return 0;
}

Measured memory_bytes: 652
#! /usr/bin/python 
# -*- coding: utf-8 -*- 
#===============================================================================
# Date created  : 2019-07-09T16:18:15+09:00
# Date modified : 2019-07-09T16:29:17+09:00
# Author        : soundscope
# Description   : unanswered
#===============================================================================

N , M = map(int,input().split())
L = sorted(list(map(int,input().split())))
X = []
for _ in range(M):
    B,C = map(int,input().split())
    X.append([B,C])
#print(L)
X = sorted(X,key = lambda X:-X[1])
#print(X)
ideal1 = []
for x in X:
    for i in range(x[0]):
        if N <= len(ideal1): break
        ideal1.append(x[1])
cand = []
cnt = 0
ideal1 = ideal1 + [0 for i in range(N)]
#print(ideal1)
for i in range(N):
    cnt += max(ideal1[i],L[i])
print(cnt)

X = sorted(X,key = lambda X:X[1])







Measured memory_bytes: 92056
#include <bits/stdc++.h>
using namespace std;
int main() {
	//input
	int64_t X;
	cin >> X;

	//calculation
	int64_t output = 1;
	int64_t money = 100;

	//output
	while (true) {
		money += money / 100;
		if (money >= X) {
			break;
		}
		output++;
	}
	cout << output << endl;


	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int P=1E9+7;
const int MAXN=610;

template<typename T1,typename T2>
	void Inc(T1 &a,T2 b){a+=b;if(a>=P) a-=P;}

template<typename T1,typename T2>
	void Dec(T1 &a,T2 b){a-=b;if(a<0) a+=P;}

template<typename T1,typename T2>
	T1 Add(T1 a,T2 b){a+=b;return a>=P?a-P:a;}

template<typename T1,typename T2>
	T1 Sub(T1 a,T2 b){a-=b;return a<0?a+P:a;}

int n,vis[MAXN],a[MAXN];
int f[2][MAXN][MAXN];

ll fac(int n){return n?fac(n-1)*n%P:1;}

int main()
{
	scanf("%d",&n);
	int t=n;
	for(int i=1,x,y;i<=2*n;i+=2)
	{
		scanf("%d%d",&x,&y);
		a[i]=x;a[i+1]=y;
		if(x!=-1&&y!=-1)
			vis[x]=vis[y]=2,t--;
		else
		{
			if(x!=-1)
				vis[x]=1;
			if(y!=-1)
				vis[y]=1;
			t-=x!=-1||y!=-1;
		}
	}
	int lst=0;
	f[lst][0][0]=1;
	for(int i=2*n;i;i--)
	{
		if(vis[i]==2)
			continue;
		memset(f[!lst],0,sizeof f[!lst]);
		if(!vis[i])
		{
			for(int j=0;j<=2*n;j++)
				for(int k=0;k<=2*n;k++)
					if(f[lst][j][k])
					{
						Inc(f[!lst][j+1][k],f[lst][j][k]);
						if(j)
							Inc(f[!lst][j-1][k],f[lst][j][k]);
						if(k)
							Inc(f[!lst][j][k-1],1ll*f[lst][j][k]*k%P);
					}
		}
		else
		{
			for(int j=0;j<=2*n;j++)
				for(int k=0;k<=2*n;k++)
					if(f[lst][j][k])
					{
						Inc(f[!lst][j][k+1],f[lst][j][k]);
						if(j)
							Inc(f[!lst][j-1][k],f[lst][j][k]);
					}
		}
		lst^=1;
	}
	printf("%lld\n",1ll*f[lst][0][0]*fac(t)%P);
}


Measured memory_bytes: 3200
# -*- coding: utf-8 -*-

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

D=dict()

for a in A:
    if a not in D:
        D[a]=1
    else:
        D[a]+=1
S=sum(A)

for i in range(Q):
    B,C=map(int,input().split())

    if B in D:
        #print(S)
        S-=D[B]*B
        #print(S)
        S+=D[B]*C
        #print(S)
        
        if C in D:
            D[C]+=D[B]
        else:
            D[C]=D[B]

        del D[B]

    print(S)



Measured memory_bytes: 20876
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
 
def main():
    n,q = map(int,ipt().split())
    way = [[] for i in range(n+1)]
    for i in range(n-1):
        a,b = map(int,ipt().split())
        way[a].append(b)
        way[b].append(a)
    pl = [0]*(n+1)
    for i in range(q):
        p,x = map(int,ipt().split())
        pl[p] += x
    ans = [-1]*(n+1)
    ans[0] = 0
    ans[1] = pl[1]
    q = [(1,0)]
 
    while q:
        qi,qp = q.pop()
        qa = ans[qi]
        for j in way[qi]:
            if j == qp:
                continue
            ans[j] = qa+pl[j]
            q.append((j,qi))
 
    print(" ".join(map(str,ans[1::])))
 
    return None
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 142380
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,n,x;
	cin >> a >> b >> n;
	x = min(b-1,n);
	ll ans = (a * x) / b - a * (x / b);
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

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

    auto decryptJ = [](const string &s) {
        return s.back() + s.substr(0, s.size() - 1);
    };

    auto decryptC = [](const string &s) { return s.substr(1) + s.front(); };

    auto decryptE = [](const string &s) {
        if (s.size() % 2 == 0) {
            return s.substr(s.size() / 2) + s.substr(0, s.size() / 2);
        }
        else {
            return s.substr(s.size() / 2 + 1) + s[s.size() / 2] +
                   s.substr(0, s.size() / 2);
        }
    };

    auto decryptA = [](const string &s) {
        auto r = s;
        reverse(begin(r), end(r));
        return r;
    };

    auto decryptP = [](const string &s) {
        auto r = s;
        for (auto &&c : r) {
            if (c < '0' || '9' < c) {
                continue;
            }

            c = (c - '0' + 10 - 1) % 10 + '0';
        }
        return r;
    };

    auto decryptM = [](const string &s) {
        auto r = s;
        for (auto &&c : r) {
            if (c < '0' || '9' < c) {
                continue;
            }

            c = (c - '0' + 1) % 10 + '0';
        }
        return r;
    };

    for (int i = 0; i < n; ++i) {
        string order, message;
        cin >> order;
        cin >> message;
        reverse(begin(order), end(order));

        for (auto &&c : order) {
            switch (c) {
            case 'J':
                message = decryptJ(message);
                break;
            case 'C':
                message = decryptC(message);
                break;
            case 'E':
                message = decryptE(message);
                break;
            case 'A':
                message = decryptA(message);
                break;
            case 'P':
                message = decryptP(message);
                break;
            case 'M':
                message = decryptM(message);
                break;
            }
        }
        cout << message << endl;
    }
}


Measured memory_bytes: 3076
# !/usr/bin/env python3
# from heapq import *
#
# a = [*range(1, 10)]
# heapify(a)
# i = 0
# k = int(input())
# c = 0
# while True:
#    t = str(heappop(a))
#    i += 1
#    if i == k:
#        break
#    if t[-1] != "0":
#        heappush(a, int(t + str(int(t[-1]) - 1)))
#    heappush(a, int(t + t[-1]))
#    if t[-1] != "9":
#        heappush(a, int(t + str(int(t[-1]) + 1)))
# print(t)

from collections import deque

a = deque(range(1, 10))
for _ in range(int(input())):
    i = a.popleft()
    m = i % 10
    i = 10 * i + m
    if m > 0:
        a.append(i - 1)
    a.append(i)
    if m < 9:
        a.append(i + 1)
print(i // 10)


Measured memory_bytes: 18668
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<sstream>
#include<set>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)

using namespace std;
set<string> comb;
int T;
struct Kanglish
{
  vector<int> dict;
  Kanglish(){dict.resize(38,0);}
};


int getIndex(string s)
{
  if(s.size() == 1)return s[0]-'a';
  if(s == "ld")return 26;
  if(s == "mb")return 27;
  if(s == "mp")return 28;
  if(s == "nc")return 29;
  if(s == "nd")return 30;
  if(s == "ng")return 31;
  if(s == "nt")return 32;
  if(s == "nw")return 33;
  if(s == "ps")return 34;
  if(s == "qu")return 35;
  if(s == "cw")return 36;
  if(s == "ts")return 37;
  return -inf;
}

string toString(int index)
{
  if(0 <= index && index <= 25)return string(1,(char)('a'+index));
  if(index == 26)return "ld";
  if(index == 27)return "mb";
  if(index == 28)return "mp";
  if(index == 29)return "nc";
  if(index == 30)return "nd";
  if(index == 31)return "ng";
  if(index == 32)return "nt";
  if(index == 33)return "nw";
  if(index == 34)return "ps";
  if(index == 35)return "qu";
  if(index == 36)return "cw";
  if(index == 37)return "ts";
  assert(false);
}

void Convert(string *line)
{
  Kanglish vec[38];

  vector<string> sep;
  rep(i,T)
    {
      stringstream ss;
      ss << line[i];
      string s; 
      while(!(ss >> s).fail())
	{
	  int ssize = s.size();
	  rep(j,ssize)
	    {
	      if(j+1 < ssize && getIndex(s.substr(j,2)) != -inf)
		{
		  sep.push_back(s.substr(j,2));
		  j++;
		}
	      else 
		{
		  sep.push_back(s.substr(j,1));
		}
	    }
	  sep.push_back("$");
	}
    }
  rep(i,sep.size()-1)
    {
      //if(sep[i][0] == '$')cout << endl;
      //else cout << sep[i] << endl; 
      if(sep[i+1][0] == '$' || sep[i][0] == '$')continue;
      vec[getIndex(sep[i])].dict[getIndex(sep[i+1])]++;
    }

  //cout << "-----------" << endl;
  rep(i,38)
    {
      cout << toString(i) << " ";
      int p = 0;
      rep(j,vec[i].dict.size())
	{
	  if(vec[i].dict[p] < vec[i].dict[j])
	    {
	      p = j;
	    }
	}
      cout << toString(p) << " " << vec[i].dict[p] <<endl;
    }

}

int main()
{

  comb.insert("ld");
  comb.insert("mb");
  comb.insert("mp");
  comb.insert("nc");
  comb.insert("nd");
  comb.insert("ng");
  comb.insert("nt");
  comb.insert("nw");
  comb.insert("ps");
  comb.insert("qu");
  comb.insert("cw");
  comb.insert("ts");

  while(cin >> T)
    {
      cin.ignore();
      string line[T];
      rep(_,T)
	{
	  getline(cin,line[_]);
	}
      vector<Kanglish> vec[39];
      Convert(&line[0]);
    }
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N;
	cin >> N;

	vector<int> h(N);
	vector<int> a(N);

	for (auto& hi : h)
		cin >> hi;
	for (auto& ai : a)
		cin >> ai;

	map<int, uint64_t> m;
	m[0] = 0;
	forn(i, N)
	{
		auto it = m.lower_bound(h[i]);
		auto prit = prev(it);
		uint64_t pv = prit->second + a[i];
		if(it!= m.end() && it->first == h[i] && it->second >= pv)
			continue;
		while (it != m.end() && it->second <= pv)
		{
			m.erase(it++);
		}
		m.insert(it, { h[i], pv });
	}

	cout << m.rbegin()->second << endl;
	return 0;
}


Measured memory_bytes: 14336
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int N = IN();
	int ans = 1;
	while (true) {
		if (ans * 2 <= N) {
			ans *= 2;
		}
		else {
			OUT(ans);
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

long long GCD(long long a, long long b)
{
    if (b > a)
        swap(a, b);
    if (a % b == 0)
        return b;
    return GCD(b, a % b);
}
long long LCM(long long a, long long b)
{
    return a * b / GCD(a, b);
}
int main(void)
{
    long long A, B, C, D;
    set<long long> st;
    cin >> A >> B >> C >> D;
    long long lcm = LCM(C, D);
    long long disd = B / D - (A - 1) / D;
    long long disc = B / C - (A - 1) / C;
    long long disdc = B / lcm - (A - 1) / lcm;
    cout << B - A - disd - disc + disdc + 1;
}


Measured memory_bytes: 384
using System;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            long[] input = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long N = input[0];
            long[] point = new long[N];
            long K = input[1];
            long Q = input[2];
            for(var i=0;i<N;i++){
                point[i] = K;
            }
            long[] A = new long[Q];
            for(var i=0;i<Q;i++){
                A[i] = long.Parse(Console.ReadLine());
            }
            for(var i=0;i<Q;i++){
                point[A[i]-1]++;
            }
            for(var i=0;i<N;i++){
                Console.WriteLine(point[i]>Q?"Yes":"No");
            }
        }
    }
}

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

using namespace std;

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

ll A, B, C, sum;
int ans;

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

    cin >> A >> B >> C;

    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
        if (A == B && B == C) {
            cout << "-1";
            return 0;
        }

        ans++;

        sum = A + B + C;
        A = (sum - A) / 2;
        B = (sum - B) / 2;
        C = (sum - C) / 2;
    }

    cout << ans;


    return 0;
}


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

static const int MAX_N = 100000;

long long N, C;
long long x[MAX_N], v[MAX_N];
long long l[MAX_N], r[MAX_N];
long long lmax[MAX_N], rmax[MAX_N];

int main(int argc, char* argv[]){
  cin >> N >> C;
  for(int i = 0; i < N; i++)
	cin >> x[i] >> v[i];
  l[0] = v[0];
  r[N-1] = v[N-1];
  for(int i = 1; i < N; i++) l[i] = v[i]+l[i-1];
  for(int i = 0; i < N; i++) l[i] -= x[i];
  for(int i = N-2; i >= 0; i--) r[i] = v[i]+r[i+1];
  for(int i = 0; i < N; i++) r[i] -= (C-x[i]);
  lmax[0] = l[0];
  rmax[N-1] = r[N-1];
  for(int i = 1; i < N; i++) lmax[i] = max(lmax[i-1], l[i]);
  for(int i = N-2; i >= 0; i--) rmax[i] = max(rmax[i+1], r[i]);
  for(int i = 0; i < N-1; i++) l[i] = max(l[i], l[i]-x[i]+rmax[i+1]);
  for(int i = N-1; i >= 1; i--) r[i] = max(r[i], r[i]-(C-x[i])+lmax[i-1]);
  long long ans = 0;
  for(int i = 0; i < N; i++){
	if(l[i] > ans) ans = l[i];
	if(r[i] > ans) ans = r[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int A;
    int B;
    int C;
    int sum=0;
    int day=0;
    cin >> A >> B >> C;

    while(C>sum){
        for(int i=0; i<7; i++){
            if(C>sum){
                day++;
            }
            sum+=A;
        }
        sum+=B;
    }
    cout << day <<"\n";
    return 0;
}


Measured memory_bytes: 3116
#include <ios>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <iomanip>

typedef long long ll;

using namespace std;

int main() {
    int L; cin >> L;
    double a = L / 3.0;
    cout << fixed << setprecision(10) << pow(a, 3) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
const int mod = 1e9+7;
const int maxn = 8e3+5;
const double EPS = 1e-6;
using namespace std;
int main()
{
	ll a,b;
	ll d = 1;
	cin>>a>>b;
	while(1){
		a*=2;
		if(a>b) break;
		d++;
	}
	cout<<d;
	return 0;
}



Measured memory_bytes: 256
/* ***********************************************
Author: SnowyJune
Created Time :2017年11月05日 星期日 19时15分02秒
File Name :084D.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define lson(x) (x<<1)
#define rson(x) ((x<<1)|1) 
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5+10;

LL Pow[maxn],d1[maxn],d2[maxn],K;
int cnt;
bool vis[maxn], inq1[maxn],inq2[maxn];
LL spfa(LL K){
    queue<LL> Q1,Q2;
    while(!Q1.empty())Q2.pop();
    Q1.push(K);
    Q2.push(0);
    d1[K] = 0;
    d2[0] = 0;
    inq1[K] = true;
    inq2[0] = true;
    while(!Q1.empty() && !Q2.empty()){
        LL fr1 = Q1.front();
        LL fr2 = Q2.front();
        for(int i = 1; i <= cnt; i++){
            LL next = (Pow[i]+fr1) % K;
            if(inq1[next])continue;
            /*if(1 + d[fr] < d[next]){
                d[next] = d[fr] + 1;
                if(!inq[next]){
                    inq[next] = true;
                    Q.push(next);
                }
                if(next == 0)return;
            }*/
            d1[next] = d1[fr1] + 1;
            Q1.push(next);
            inq1[next] = true;
            if(inq2[next])return d1[next]+d2[next];
        }
        for(int i = 1; i <= cnt; i++){
            LL next = (K-Pow[i]+fr2)%K;
            if(inq2[next])continue;
            d2[next] = d2[fr2] + 1;
            Q2.push(next);
            inq2[next] = true;
            if(inq1[next])return d1[next]+d2[next];
        }
        Q1.pop();
        Q2.pop();
    }
}
void solve(LL K){
    while(K%2==0 && K != 0)K/=2;
    while(K%5==0 && K != 0)K/=5;
    if(K == 0){
        puts("0");
        return;
    }
    Pow[0] = 1;
    ms(vis,0);
    for(cnt = 1;; cnt++){
        Pow[cnt] = Pow[cnt-1] * 10 % K;
        if(vis[Pow[cnt]])break;
        vis[Pow[cnt]] = true;
    }
    cnt --;

    ms(d1,0x3f);
    ms(d2,0x3f);
    ms(inq1,0);
    ms(inq2,0);
    printf("%lld\n",spfa(K));
}
int main(){
#ifdef SNOWYJUNE 
//	freopen("input","r",stdin);
//  freopen("output","w",stdout);
#endif
    
   /* for(LL i = 2; i <= 100000; i++){
        solve(i);
        if(i%1000==0)printf("%d\n",i);
    }*/
    LL x;
    cin >> x;
    solve(x);
#ifdef SNOWYJUNE
	fclose(stdin);
#endif
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define N 2100
int n;
int a[N],vis[N],pos[N];
vector<int> v1[N],v2[N];
int cmp(int x,int y){return a[x]<a[y];}
void merge(int x,int y)
{
	vector<int> tmp;
	tmp.clear();
	int p1=0,p2=0;
	while(p1<v2[x].size()&&p2<v2[y].size())
	{
		if(v2[x][p1]<v2[y][p2])
			tmp.push_back(v2[y][p2]),p2++;
		else tmp.push_back(v2[x][p1]),p1++;
	}
	while(p1<v2[x].size())
		tmp.push_back(v2[x][p1]),p1++;
	while(p2<v2[y].size())
		tmp.push_back(v2[y][p2]),p2++;
	v2[x]=tmp;
}
void dfs(int x)
{
	vis[x]=1;
	for(int i=1;i<=n;i++)
		if(!vis[i]&&__gcd(a[x],a[i])!=1)
			v1[x].push_back(i);
	sort(v1[x].begin(),v1[x].end(),cmp);

	for(int i=0,t;i<v1[x].size();i++)
		if(!vis[t=v1[x][i]])
		{
			dfs(t);
			merge(x,t);
		}
	reverse(v2[x].begin(),v2[x].end());
	v2[x].push_back(a[x]);
	reverse(v2[x].begin(),v2[x].end());
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),pos[i]=i;
	sort(pos+1,pos+1+n,cmp);
	for(int i=1,t;i<=n;i++)
		if(!vis[t=pos[i]])
			dfs(t),merge(0,t);
	for(int i=0;i<n;i++)
		printf("%d ",v2[0][i]);
	return 0;
}


Measured memory_bytes: 22784
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repr(i,n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string s; cin >> s;
    if ((s == "hi") || (s == "hihi") || (s == "hihihi") || (s == "hihihihi") || (s == "hihihihihi")) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define INF (int)1e8
#define EPS 1e-9

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vvi num(W, vi(H));

  rep(i, N) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
      case 1:
        rep(i, W) rep(j, H) {
          if (i < x) num[i][j]++;
        }
        break;
      case 2:
        rep(i, W) rep(j, H) {
          if (i >= x) num[i][j]++;
        }
        break;
      case 3:
        rep(i, W) rep(j, H) {
          if (j < y) num[i][j]++;
        }
        break;
      case 4:
        rep(i, W) rep(j, H) {
          if (j >= y) num[i][j]++;
        }
        break;
    }
  }

  int res = 0;
  rep(i, W) rep(j, H) {
    if (!num[i][j]) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n; cin>>n;
    while(n--){
        int amin = 0;
        int bmin = 0;
        int tmp;
        bool ans = true;
        for(int i=0;i<10;++i){
            cin>>tmp;
            if(tmp <= amin && tmp <= bmin){
                ans = false;
            }
            if(!ans) continue;
            if(tmp > amin && tmp > bmin){
                if(bmin > amin)
                    bmin = tmp;
                else
                    amin = tmp;
            }else if(tmp > amin)
                amin = tmp;
            else
                bmin = tmp;
        }
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i%3 == 0) {
            cout << " " << i;
        }
        else {
            for (int x = i; x; x/=10) {
                if (x%10 == 3) {
                    cout << " " << i;
                    break;
                }
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3092
N = int(input())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    if i == 0:
        ans += B[0]
    elif i == N - 1:
        ans += B[-1]
    else:
        ans += min(B[i - 1], B[i])

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
 
int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
 
int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}
 
int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
 
int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/
 
signed main(){
  int k,x;
  cin>>k>>x;
  if(500*k>=x) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long n,k,s,i,j;
    cin>>n>>k>>s;

    for(i=1;i<=n;i++)
    {
        if(i<=k)printf("%lld ",s);
        else
        {
            if(s==1)
                printf("%lld ",s+5);
            else
            {
                if(s==1000000000)
                {
                    printf("%lld ",s-1);
                }
                else
                {
                    printf("%lld ",s+1);
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1280
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  vector<tuple<int, int, int>> d;
  rep(i,n){
    cin>>a[i]>>b[i];
    c[i] = b[i]-a[i];
    d.pb(tie(b[i], a[i], c[i]));
  }
  sort(all(d));
  dump(a);
  dump(b);
  dump(c);
  dump(d);

  int now = 0;
  rep(i, n){
    int e,t,s;
    tie(e,t,s) = d[i];
    now += t;
    if (now > e){
      dump(i, now, s, t, e);
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 12784
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n, a, b;
        cin >> n >> a >> b;
        vl h(n);
        rep(i, n) h[i] = inl();

        ll s = -1;
        ll e = *max_element(all(h));
        while (e - s > 1) {
            ll m = (s + e) / 2;
            bool ok = false;
            vl ch(h);
            rep(i, n) ch[i] -= m * b;
            ll tmp = m;
            rep(i, n) if (ch[i] > 0) tmp -= ceil(double(ch[i]) / (a - b));
            if (tmp >= 0) ok = true;
            if (ok) {
                e = m;
            } else {
                s = m;
            }
        }
        cout << e << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

using namespace std;

int main()
{
    double  N;
    cin >> N;
    int n = 0;
    n = N;
    if (n%2 == 1) {
        cout<<(n/2+1)/N<<endl;
    }else {
        cout<<(n/2)/N<<endl;;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
 
static class MainClass {
  public struct arch{
  }
 
  public static void Main (string[] args) {
    var temp = Console.ReadLine().Split(' ').Select(long.Parse);
    var N = temp.ElementAt(0);
    var K = temp.ElementAt(1);
    var c = 0;
    while(true){
      c++;
      if(Math.Pow(K, c) > N) break;
    }
    var ans = c;
    Console.WriteLine(ans);
 
  }
  
}


Measured memory_bytes: 11220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Numerics;
using System.Diagnostics;

class Program
{
    public void Slove()
    {
        string[] inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int k = int.Parse(inputs[1]);
        int[] dp = Enumerable.Range(0, n)
            .Select(x => int.MaxValue)
            .ToArray();
        dp[0] = 0;
        int[] hs = Console.ReadLine().Split().Select(int.Parse).ToArray();
        foreach(int i in Enumerable.Range(0, n))
        {
            foreach(int j in Enumerable.Range(1, k).TakeWhile(x => i - x >= 0))
            {
                dp[i] = Math.Min(dp[i], dp[i - j] + Math.Abs(hs[i] - hs[i - j]));
            }
        }   
        Console.WriteLine(dp[n - 1]);
    }
    static void Main(string[] args)
    {
        var p = new Program();
        p.Slove();
    }
}


Measured memory_bytes: 28384
import math
n=int(input())
ansl=[0]*(n+1)  
c=0
x=0
y=0
z=0
rn=int(float(math.sqrt(n)))
for x in range(1,rn+1):
    for y in range(1,rn+1):
        for z in range(1,rn+1):
            if x**2+y**2+z**2+x*y+y*z+z*x<=n:
                ansl[x**2+y**2+z**2+x*y+y*z+z*x]+=1
for i in range(n):                
    print(ansl[i+1])

Measured memory_bytes: 68932
///   BISMILLAHIR RAHMANIR RAHEEM
///   ALLAH IS WATCHING ME
///   ALLAH save us from COVID-19.Amin.

///   █▀█─█──█──█▀█─█─█
///   █▄█─█──█──█▄█─█▄█
///   █─█─█▄─█▄─█─█─█─█

///   كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
///   Every soul shall taste death.



#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

///  order_of_key return number of elements less than x.
///  find_by_order return index.

using namespace std;
using namespace __gnu_pbds;


#define MOHAMMAD  ios::sync_with_stdio(0);cin.tie(0);
#define all(x)    (x).begin(), (x).end()
#define AE        cout << fixed << setprecision(10);

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

//***********************************************  The END **********************************************************************************************************************************




int main()
{

    // MOHAMMAD
   char ch;
   cin >> ch;
   int c = ch - 'a';
   if(c>=0) cout << 'a';
   else cout << 'A';
}

/*





  Alhamdulillah
*/



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a%2==1 && b%2==1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main(){
  int N,D;
  cin >> N >> D;
  long X,Y;
  int count = 0;
  for(int i=0; i<N; i++){
    cin >> X >> Y;
    if(sqrt(X*X + Y*Y) <= D) count++;
    //cout << X << ' ' << Y << endl;
    //cout << count << endl;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
using namespace std;

int main() {
	int s,s1,s2,s3,s4;
	cin >> s;
	s1 = s%10;
	s = s / 10;
	s2 = s % 10;
	s = s / 10;
	s3 = s % 10;
	s = s / 10;
	s4 = s % 10;
	if (s1==s2||s2==s3||s3==s4) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
#define N 500000
typedef long long LLI;

int main(void){
  int n;
  int cnt[10010];
  
  for (int i=0; i<=10000; i++) cnt[i]=0;
  cin >> n;
  for (int i=0; i<n; i++){
    int t;
    cin >> t;
    cnt[t]++;
  }
  for (int i=0; i<=10000; i++){
    while (cnt[i]--){
      cout << i;
      cout << (--n?" ":"\n");
    }
  }
  return 0;
}


Measured memory_bytes: 3136
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;

class in {
  int n;
public:
  in() {}
  in(int n_) : n(n_){};
  template <class T> operator T() { T ret; cin >> ret; return ret; }
  template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
  u64 a;
  friend ostream& operator<<(ostream& os, const modint& m);
public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
ostream& operator<<(ostream& os, const mint& m){ return os << m.a; }
//}}}

int main(){
  int N = 3;
  vector<int> A = in(N);

  int sum = 0;
  rep(i, 3){
    sum += A[i];
  }

  bool ans = sum >= 22;
  puts(ans ? "bust" : "win");
  return 0;
}


Measured memory_bytes: 256
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define up(a,b) max(a,b)
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
void add(ll& a, ll b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
void mul(ll& a, ll b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
void up_self(ll& a, ll b){a = up(a,b);}
void min_self(ll& a, ll b){a = min(a,b);}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
void strrev(string& s){int n = (s.size());for(int i = 0 ; i < n/2; i++)swap(s[i],s[n-1-i]);}
int main()
{
	
	int n; cin>>n;
	map<int,int> f;
	for(int i = 1 ; i < n ;i++)
	{
		int k; cin>>k;
		f[k]++;
	}
	for(int i = 1; i <= n; i++)
		cout<<f[i]<<endl;
  	return 0;
}

Measured memory_bytes: 13004
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

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


Measured memory_bytes: 3568
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func maxInt(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func knap(count, weightLimit int, weights []int, vals []int) int {
	values := make([][]int, count + 1)
	for i := 0; i < count + 1; i++ {
		values[i] = make([]int, weightLimit + 1)
	}

	for i := 1; i <= count; i++ {
		for j := 0; j <= weightLimit; j++ {
			values[i][j] = values[i - 1][j]
			if weights[i - 1] <= j {
				values[i][j] = maxInt(values[i][j], values[i-1][j-weights[i - 1]] + vals[i - 1])
			}
		}
	}
	return values[count][weightLimit]
}

func ScanInt() int {
	sc.Scan()
	res, _ := strconv.Atoi(sc.Text())
	return res
}

func ScanIntArray(size int) []int {
	res := make([]int, size)
	for i := 0; i < size; i++ {
		sc.Scan()
		res[i], _ = strconv.Atoi(sc.Text())
	}
	return res
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	count := ScanInt()
	weightLimit := ScanInt()
	weights := make([]int, count)
	vals := make([]int, count)
	for i := 0; i < count; i++ {
		weights[i] = ScanInt()
		vals[i] = ScanInt()
	}
	fmt.Println(knap(count, weightLimit, weights, vals))
}


Measured memory_bytes: 81792
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	// ------ ここまでテンプレ ------ //
	
	long a = read.to!long;
	long b = read.to!long;
	long k = read.to!long;
	
	long ans;
	long cnt;
	foreach_reverse(i; 1 .. 200){
		if(a % i == 0 && b % i == 0){
			cnt += 1;
			if(cnt == k) ans = i;
		}
	}
	
	ans.writeln;
	
}


Measured memory_bytes: 256
/*
	連立方程式を解くプログラム
	小数点以下第4位を四捨五入しなければならない。
*/

#include<stdio.h>
#include<math.h>

int main(void){
	double a,b,c,d,e,f;
	double x,y;


	while(scanf("%lf %lf %lf %lf %lf %lf",&a ,&b ,&c ,&d ,&e ,&f) != EOF){

		//ガウスの掃き出し法
		y = ( f+(c/a)*(-d) ) / ( e+(b/a)*(-d) );
		x = c/a-(b/a)*y;

/*
		//クラメールの公式を使っています
		x = (c*e-b*f)/(a*e-b*d);
		y = (a*f-c*d)/(a*e-b*d);
*/

		printf("%.3lf %.3lf\n",x ,y);
	}

	return 0;
}

Measured memory_bytes: 652
#include<iostream>
#define int long long
using namespace std;
int n,a[200001],b[200001],s[200001],q[200001];
char t[5];
inline int sum(int l,int r){return s[r]-s[l-1];}
signed main()
{
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(i>1)cin>>t;
		cin>>a[i];
		cnt+=b[i]=t[0]=='-';
		s[i]=s[i-1]+a[i];
		q[i]=q[i-1]+(b[i]?-a[i]:a[i]);
	}
	int ans=(cnt<2?q[n]:-(1ll<<40));
	for(int i=n,j=n+1;i;i--)
		if(b[i])
		{
			if(j<=n)ans=max(ans,q[i-1]-sum(i,j-1)+sum(j,n));
			j=i;
		}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int K, A, B, X;
    cin >> K >> A >> B;
    X = 0;
    while (A > K * X)
    {
        X++;
    }
    if (K * X <= B)
    {
        cout << "OK" << endl;
    }
    else
    {
        cout << "NG" << endl;
    }
}


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



// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
int mod = 2;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};






//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }


int main() {

  ll p;
  cin>>p;
  mod=p;
  combination c(p-1);
  vector<ll>a(p);
  rep(i,p){
    cin>>a[i];
  }
  vector<mint> b(p);
/*
mint test=comb(10,2);
cout<<test<<"test"<<endl;
*/
  rep(i,p){
    if (a[i]==1){
      mint temp=1;
      rep(j,p){
    //    cout<<i<<'i'<<temp<<endl;
        mint now=c(p-1,j);
      //  cout<<now.x<<"now"<<j<<'j'<<p-1<<endl;
         now*=temp;
        b[p-1-j]-=now;

      //  b[p-1-j]=b[p-1-j]%p;
        temp*=-i;
    //    cout<<i<<'i'<<temp<<"after"<<endl;

      }
    }
  //  cout<<i<<'i'<<endl;
  }
  b[0]=a[0];
rep(i,p){
  cout<<b[i].x<<' ';
}


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int p[N],d[N];
int find(int x)
{
	if(p[x]!=x)p[x]=find(p[x]);
	return p[x];
}
int main()
{
	cin.tie(0);ios::sync_with_stdio(0);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		d[i]=1;
		p[i]=i;
	}
	int maxn=1;
	while(m--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		int pa=find(a),pb=find(b);
		if(pa==pb)continue;
		else
		{
			d[pb]+=d[pa];
			p[pa]=pb;
		}
		maxn=max(maxn,d[pb]);
	}
	//if(maxn==0) printf("%d\n",n);
	 printf("%d\n",maxn);
	return 0;
}


Measured memory_bytes: 5324
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << "\n"
#define endwith return
constexpr int mod = 1000000007;
using namespace std;
int input() { int t; cin >> t; return t; }
int n, a25[2345678], ans, c[2345678];
string s;
//(a^p)%mod
int f1(int a, int p) {
	if (p == 1)return a;
	if (p % 2)return f1(a, p - 1) * a % mod;
	else return f1(a * a % mod, p / 2) % mod;
}
//pでわる→ *= f1(p, mod - 2);
signed main() {
	a25[0] = 1; c[0] = 1;
	cin >> n >> s;
	for1(i, n + s.size()) {
		a25[i] = a25[i - 1] * 25 % mod;
		c[i] = c[i - 1] * (n+s.size()-i+1) % mod;
		c[i] = c[i] * f1(i, mod - 2) % mod;
	}
	ans = 1; for0(v, n + s.size())ans = ans * 26 % mod;
	for0(i, s.size()) {
		int k = c[i] * a25[n + s.size() - i] % mod;
		ans -= k; if (ans < 0)ans += mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 35584
#include <iostream>

int main() {
    int h,w;
    while(true) {
        std::cin >> h >> w;
        if((h|w) == 0) break;
        std::string s(w, '#');
        for(auto i=0; i<h; i++) {
            std::cout << s << std::endl;
        }
        std::cout << std::endl;
    }
}



Measured memory_bytes: 3156