akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

struct LazySegmentTree{
private:
  int N;
  vector<ll> node;
  vector<ll> lazy;
public:
  LazySegmentTree(vector<ll> v){
    int SZ=(int)v.size();
    N=1;
    while(N<SZ) N*=2;
    node.resize(2*N-1);
    lazy.resize(2*N-1,0);

    for(int i=0;i<SZ;i++) node.at(i+N-1)=v.at(i);
    for(int i=N-2;i>=0;i--) node.at(i)=max(node.at(2*i+1),node.at(2*i+2));
  }

  void eval(int k,int l,int r){
    if(lazy.at(k)==0) return;
    node.at(k)+=lazy.at(k);
    if(r-l>1){
      lazy.at(2*k+1)+=lazy.at(k);
      lazy.at(2*k+2)+=lazy.at(k);
    }
    lazy.at(k)=0;
  }

  void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
    if(r==-1) r=N;
    eval(k,l,r);
    if(r<=a || b<=l)  return;
    if(a<=l && r<=b){
      lazy.at(k)+=x;
      eval(k,l,r);
    }
    else{
      add(a,b,x,2*k+1,l,(l+r)/2);
      add(a,b,x,2*k+2,(l+r)/2,r);
      node.at(k)=max(node.at(2*k+1),node.at(2*k+2));
    }
  }

  ll getmax(int a,int b,int k=0,int l=0,int r=-1){
    if(r==-1) r=N;
    if(r<=a || b<=l)  return 0;
    eval(k,l,r);
    if(a<=l && r<=b)  return node.at(k);
    ll vl=getmax(a,b,2*k+1,l,(l+r)/2);
    ll vr=getmax(a,b,2*k+2,(l+r)/2,r);
    return max(vl,vr);
  }
};

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<vector<pair<int,int>>> la(N+1);
  for(int i=0;i<M;i++){
    int l,r,a;
    cin >> l >> r >> a;
    la.at(r).pb(mp(l,a));
  }

  LazySegmentTree seg(vector<ll>(N+1,0));
  for(int i=1;i<N+1;i++){
    ll mx=seg.getmax(0,i);
    seg.add(i,i+1,mx);
    for(int j=0;j<sz(la.at(i));j++){
      int l=la.at(i).at(j).fi;
      int a=la.at(i).at(j).se;
      seg.add(l,i+1,a);
    }
  }
  cout << seg.getmax(0,N+1) << endl;

  return 0;
}

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

int main()
{
	int a, p;
	scanf("%d %d", &a, &p);
	p += (a * 3) % 2;
	a = ((a * 3) / 2) + (p / 2);
	printf("%d\n", a);
	return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<vector<vector<double>>> dp;
  Solver(LL n) : n(n), dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1))){};

  void solve() {
    vector<int> cnt(4);
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      cnt[tmp]++;
    }
    cout << calc(cnt[1], cnt[2], cnt[3]) << endl;
  }
  double calc(int a, int b, int c) {
    if (dp[a][b][c] > 0) return dp[a][b][c];
    if (a == 0 && b == 0 && c == 0) return 0.0;
    double ret = (double)n / (double)(a + b + c);
    if (a > 0) ret += calc(a - 1, b, c) * (double)a / (double)(a + b + c);
    if (b > 0) ret += calc(a + 1, b - 1, c) * (double)b / (double)(a + b + c);
    if (c > 0) ret += calc(a, b + 1, c - 1) * (double)c / (double)(a + b + c);
    return dp[a][b][c] = ret;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> D = vector<int>(K);
	for(int i=0;i<K;i++){
		cin >> D.at(i);
	}

	for(int x=N;x<100000;x++){
		int tmp = x;
		int cnt = 0;
		vector<int> s;
		while(tmp!=0){
			s.push_back(tmp % 10);
			tmp /= 10;
		}
		bool flag = true;

		for(int i=0;i<K;i++){
			if(count(s.begin(), s.end(), D.at(i)) > 0) flag = false;
		}

		if(flag){
			cout << x << endl;
			break;
		}

	}

}


Measured memory_bytes: 256
n = int(input())
cards_list = list(map(int,input().split()))
cards_list.sort()
cards_list.reverse()
sum_alice = 0
sum_bob = 0
turn = 0

for val in cards_list:
    if turn == 0:
        sum_alice += val
        turn = 1
    else:
        sum_bob += val
        turn = 0

print(sum_alice-sum_bob)

Measured memory_bytes: 3060
cnt = 0
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v

def shellSort(A, n):
    gi = 2
    m = 1
    G = []
    for i in range(100):
        m += 1
        G.append(gi - 1)
        gi = gi * 2
        if n < gi - 1:
            break
    list.sort(G, reverse=True)
    for i in range(0, m-1):
        insertionSort(A, n, G[i])
    return G
      
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
G = shellSort(A, n)
G = [str(g) for g in G]
print(len(G))
print(" ".join(G))
print(cnt)
for a in A:
    print(a)


Measured memory_bytes: 45524
#include<stdio.h>

int main(){
	int top[3];
	int input;
	int i;
	for(i=0;i<3;i++){
		top[i] = 0;
	}
	for(i=0;i<10;i++){
		scanf("%d",&input);
		if(input > top[2]){
			top[2] = input;
			if(input > top[1]){
				top[2] = top[1];
				top[1] = input;
				if(input > top[0]){
					top[1] = top[0];
					top[0] = input;
				}
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",top[i]);
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
}

Measured memory_bytes: 18780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static class Task {
        public void solve(InputReader in, PrintWriter out) {
        	int n = in.nextInt();
        	if(n==1) {
        		out.println(in.nextInt());
        		return;
        	}
        	int ans = 0;
        	int prev = in.nextInt();
        	for(int i=1; i<n; i++) {
        		int curr = in.nextInt();
        		if(prev > curr)
        			ans+=prev-curr;
        		if(i==n-1)
        			ans+=curr;
        		prev = curr;
        	}
        	out.println(ans);
        }
        
        public void solve_again(InputReader in, PrintWriter out) {
        	int n = in.nextInt();
        	int curr = in.nextInt();
        	int ans = curr;
        	for(int i=1; i<n; i++) {
        		int next = in.nextInt();
        		if(next > curr)
        			ans+=next-curr;
        		curr = next;
        	}
        	out.println(ans);
        }
        
    }
	
    public static void main(String argds[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
        public long nextLong() {
            return Long.parseLong(next());
        }
    }	
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    double a, b;
    cin >> a >> b;
    int la = ceil(a / 0.08);
    int ua = floor((a+1) / 0.08);

    int lb = ceil(b / 0.1);
    int ub = floor((b+1) / 0.1);

    int ans = -1;
    for(int i=la; i<ua; i++){
        if(lb <= i && i < ub){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
n,m,x = map(int,input().split(' '))
a = list(map(int,input().split(' ')))
pos = 0
ans1 = 0
ans2 = 0
for i in range(0,m):
    if a[i] > x:
        pos = i
        break
for i in range (0,pos):
    ans1+=1
for i in range (pos,m):
    ans2+=1

print(min(ans1,ans2))





Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll x, ans;
  cin >> x;
  if (1800 <= x)
    ans = 1;
  else if (1600 <= x)
    ans = 2;
  else if (1400 <= x)
    ans = 3;
  else if (1200 <= x)
    ans = 4;
  else if (1000 <= x)
    ans = 5;
  else if (800 <= x)
    ans = 6;
  else if (600 <= x)
    ans = 7;
  else
    ans = 8;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define maxn 100005
#define maxm 100005
#define eps 1e-6
typedef long long ll;
using namespace std; 
const ll mod = 1e9 + 7;
inline int read(){
	int x = 0, f = 1;char ch = getchar();
	while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
	return x * f;
}

int n, m, y;
int main(){
	int i, j, x;
	n = read(), m =read(), y = read();
	if(m * y >= n) puts("Yes");
	else puts("No");
}
//

Measured memory_bytes: 3592
#include <stdio.h>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)
#define RREP(a, i, n) for (int i = n - 1; i >= 0; --i)

int max(int X, int Y) {
    return X > Y ? X : Y;
}

int min(int X, int Y) {
    return X < Y ? X : Y;
}

int abs(int X, int Y) {
    return X > Y ? X - Y : Y - X;
}

int dp(int N, int h[], int m[]) {
    int idx = N - 1;

    if ((-1) != m[idx]) {
        return m[idx];
    }

    if (2 == N) {
        return abs(h[idx], h[idx - 1]);
    } else if (3 == N) {
        m[idx - 1] = dp(N - 1, h, m);
        return min(abs(h[idx], h[idx - 2]), abs(h[idx], h[idx - 1]) + m[idx - 1]);
    } else {
        m[idx - 2] = dp(N - 2, h, m);
        m[idx - 1] = dp(N - 1, h, m);
        return min(abs(h[idx], h[idx - 2]) + m[idx - 2], abs(h[idx], h[idx - 1]) + m[idx - 1]);
    }
}

int main() {
    int N; // 2 <= N <= 10^5
    scanf("%d", &N);

    int h[N]; // 1 <= hi <= 10^4
    REP(0, i, N) {
        scanf("%d", &h[i]);
    }

    int m[N];
    REP(0, i, N) {
        m[i] = -1;
    }

    printf("%d\n", dp(N, h, m));

    return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define all(c) c.begin(),c.end()
#define pb push_back
using namespace std;
int h,w,n;
vector<string> st(vector<string> s,vector<vector<bool> > f){
	for(int i=0;i<w;i++){
		string t="";
		for(int j=h-1;j>=0;j--){
			if(isalpha(s[j][i])&&!f[j][i]){
				t+=s[j][i];
			}
		}
		for(int j=0;j<t.size();j++){
			s[h-1-j][i]=t[j];
		}
		for(int j=t.size();j<h;j++){
			s[h-1-j][i]='.';
		}
	}
	return s;
}
bool ret(vector<string> s,int cnt){
	vector<vector<bool> > f(h,vector<bool>(w));
	int sum=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			if(!isalpha(s[i][j]))
				continue;
			int a=1;
			for(int k=j;k<w-1;k++){
				if(s[i][k]==s[i][k+1]){
					a++;
				}else break;
			}
			if(a>=n){
				for(int k=0;k<a;k++){
					if(!f[i][k+j]){
						sum++;
					}
					f[i][k+j]=true;
				}
			}
		}
	}
	for(int i=0;i<w;i++){
		for(int j=0;j<h-1;j++){
			if(!isalpha(s[j][i]))
				continue;
			int a=1;
			for(int k=j;k<h-1;k++){
				if(s[k][i]==s[k+1][i]){
					a++;
				}else break;
			}
			if(a>=n){
				for(int k=0;k<a;k++){
					if(!f[k+j][i]){
						sum++;
					}
					f[k+j][i]=true;
				}
			}
		}
	}
	if(cnt-sum==0)
		return true;
	if(!sum)
		return false;
	return ret(st(s,f),cnt-sum);
	
}
int main(){
	while(cin>>h>>w>>n){
		int cnt=0;
		vector<string> s(h);
		for(int i=0;i<h;i++){
			cin>>s[i];
		for(int j=0;j<w;j++){
			if(s[i][j]!='.')
				cnt++;
		}
	}
	bool flag=false;
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			if(s[i][j]==s[i][j+1])
				continue;
			swap(s[i][j],s[i][j+1]);
			flag=ret(st(s,vector<vector<bool> >(h,vector<bool>(w))),cnt);
			if(flag){
				cout<<"YES"<<endl;
				break;
			}
			swap(s[i][j],s[i][j+1]);
		}
		if(flag)
			break;
	}
	if(!flag)
			cout<<"NO"<<endl;
	}
	return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, M;
    cin >> N >> M;

    vi vals(N);
    for (int i = 0; i < N; i++) {
        cin >> vals[i];
        --vals[i];
    }

    vvi adj(N);
    for (int e = 0, u, v; e < M; e++) {
        cin >> u >> v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }

    int ans = 0;

    vi comp(N, -1);
    for (int v = 0; v < N; v++) if (comp[v] == -1) {
        comp[v] = v;
        vi elts = {v};
        for (int i = 0; i < elts.size(); i++) {
            for (int j : adj[elts[i]]) if (comp[j] == -1) {
                comp[j] = v;
                elts.push_back(j);
            }
        }

        for (int j : elts) {
            if (comp[vals[j]] == v)
                ans++;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 7164
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var m     = int.Parse(spl[1]);

        if (m % n == 0) return (m / n);

        for(int i = m/n; i>1; i--) {
            if (m % i != 0) continue;
            if (m / i < n) continue;
            return i;
        }

        return 1;
    }
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

struct Book{
  string s;
  int p;
  int index;
  
  Book(string si, int pi, int index_i) {
    s = si;
    p = pi;
    index = index_i;
  }
};

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

  vector<Book> book;
  string s;
  int p;
  rep(i, N) {
    cin >> s >> p;
    book.push_back(Book(s, p, i+1));
  }
  
  sort(book.begin(), book.end(),
       [](const Book &a, const Book &b)
       {return a.s == b.s ? a.p > b.p : a.s < b.s;});

    
  rep(i, N) cout << book[i].index << endl;
  return 0;
}

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

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M;/* your task */; }
	int h2(int key){ return 1+(key%(M-1));/* your task */; }

int find(char str[]){

    /* your task */
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}

}

int insert(char str[]){

    /* your task */
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


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

using namespace std;

int n, ta, tb, ans;

int main() {
	scanf("%d", &n);
	while (n--) {
		scanf("%d%d", &ta, &tb);
		ans += tb - ta + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int n,m;
    cin>>n>>m;
    map<int,int> p;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        p[a]++;
        p[b]++;
    }
    rep(i,n){
        cout<<p[i]<<endl;
    }
}

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


def f(ABCD):
    vals = list(map(int, ABCD))

    a = vals.pop(0)
    exps = {a:str(a)}

    for val in vals:
        nextExps = {}
        for x, exp in exps.items():
            nextExps[x + val] = exp + '+' + str(val)
            nextExps[x - val] = exp + '-' + str(val)

        exps = nextExps

    return exps[7] + '=7'
            
            
def test():
    print("test mode")
    print(f('1222'))
    print(f('0290'))
    print(f('3242'))


def main():
    ABCD = input()
    print(f(ABCD))
    
if __name__ == '__main__':
    main()


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

#define MAX 100000
ll w[MAX];

using namespace std;

ll BugNum( ll Maxweight, ll CarNum, ll BugNum ){

    ll SumWeight = 0;
    ll CarCount = 0;
    ll i = 0;
    while ( CarCount < CarNum && i < BugNum ){
        SumWeight += w[i];
        if ( SumWeight > Maxweight ){
            CarCount++;
            SumWeight = 0;
            i--;
        }
        i++;
    }
    return i;

}

int main (void) {
    ll N, k;
    scanf("%lld %lld", &N, &k );
    REP(ll,i,0,N) scanf("%lld", &w[i]);
    ll left = 0;
    ll right = MAX * 10000;
    ll mid;

    /* binary search */
    while ( right - left > 1 ){
        mid = (left + right) / 2;
        int v = BugNum( mid, k, N );
        if ( v >= N ) right = mid;
        else left = mid;
    }

    printf("%lld\n", right);

    return 0;
}


Measured memory_bytes: 4000
using System;
using System.Linq;

namespace ABC148C
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            System.Console.WriteLine("{0}", Lcm(AB[0], AB[1]));
            Console.ReadLine();
        }
        public static long Gcd(long m, long n)
        {
            long temp;
            while (m % n != 0)
            {
                temp = n;
                n = m % n;
                m = temp;
            }
            return n;
        }
        public static long Lcm(long m, long n)
        {
            return m * n / Gcd(m, n);
        }
    }
}

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

string s;
int g;
//どれもy,xの順番
const int mi[3] = {2,1,0};
const int mul[3][3] = {{0,0,0},{0,1,1},{0,1,2}};
const int plu[3][3] = {{0,1,2},{1,1,2},{2,2,2}};
int p,r,q;
int cal(){
    int res = 0;
    int mm = 0;
    char cc = '.';
    bool flag = false;
    while(g < s.size()){
        int rres = 0;
        switch(s[g]){
            case '-':
                mm++;
                g++;
                break;
            case ')':
                g++;
                if(mm%2==1) return mi[res];
                return res;
            case '*':
                cc = '*';
                g++;
                break;
            case '+':
                cc = '+';
                g++;
                break;
            case '(':
                g++;
                rres = cal();
                flag = true;
                break;
            case 'P':
            case 'Q':
            case 'R':
                if(s[g] == 'P') rres = p;
                if(s[g] == 'Q') rres = q;
                if(s[g] == 'R') rres = r;
                flag = true;
                g++;
                break;
            default:

                rres = s[g]-'0';
                flag = true;
                g++;
                break;
        }
        if(flag){
            if(mm%2==1){
                rres = mi[rres];
                mm=0;
            }
//            cout << rres << " " << res << endl;
            if(cc == '*') res = mul[rres][res];
            if(cc == '+') res = plu[rres][res];
            if(cc == '.') res = rres;
            cc = '.';
            flag = false;
        }
    }
    if(mm%2==1) return mi[res];
    else return res;
}

int main(){
    while(cin >> s,s[0]!='.'){
        int res = 0;
        rep(pp,3)rep(rr,3)rep(qq,3){
            g = 0;
            p = pp;
            r = rr;
            q = qq;
            if(cal()==2) res += 1;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

int dp[41][401][401];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    for (int j = 0; j <= N * 10; j++)
    {
        for (int k = 0; k <= N * 10; k++)
        {
            dp[0][j][k] = INF;
        }
    }
    dp[0][0][0] = 0;
    for (int i = 1; i <= N; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = 0; j <= N*10; j++)
        {
            for (int k = 0; k <= N*10; k++)
            {
                if (j - a >= 0 && k - b >= 0) {
                    dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - a][k - b] + c);
                }
                else {
                    dp[i][j][k] = dp[i - 1][j][k];
                }
            }
        }
    }
    int ans = INF;
    for (int i = 1; Ma*i <= N*10 && Mb*i <= N * 10; i++)
    {
        ans = min(ans, dp[N][Ma*i][Mb*i]);
    }
    if (ans != INF) {
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
    getchar(); getchar();
}

Measured memory_bytes: 25984
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct union_find {
  int32_t *parent;
  int32_t size;
} union_find;

void init_union_find (union_find * const u) {
  for (int32_t i = 0; i < u->size; ++i){
    u->parent[i] = -1;
  }
}

union_find* new_union_find (const int32_t size) {
  union_find * const u = (union_find *) calloc (1, sizeof (union_find));
  u->parent = (int32_t *) calloc (size, sizeof (int32_t));
  u->size = size;
  init_union_find (u);
  return u;
}

int32_t root (union_find * const u, int32_t x) {
  if (u->parent[x] < 0) return x;
  return u->parent[x] = root (u, u->parent[x]);
}

void unite (union_find * const u, int32_t x, int32_t y) {
  x = root (u, x);
  y = root (u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    const int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}

#define MIN(a,b) ((a)<(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

int cmp_int (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d > 0 ? -1 : 1;
}

void run (void) {
  i32 n, r;
  scanf ("%" SCNi32 "%" SCNi32, &n, &r);
  i32 *p = ALLOC (n + 1, i32);
  for (i32 i = 1; i <= n; ++i) {
    scanf ("%" SCNi32, p + i);
  }
  union_find *u = new_union_find (n + 1);
  for (i32 i = 1; i <= n; ++i) {
    unite (u, i, p[i]);
  }
  i32 *size = ALLOC (n + 1, i32);
  for (i32 i = 1; i <= n; ++i) {
    size[root (u, i)]++;
  }
  SORT (size, n + 1, cmp_int);
  i32 len = 1;
  while (size[len] > 0) ++len;
  uint8_t *dp = ALLOC (r + 1, uint8_t);
  dp[0] = 1;
  for (i32 i = 0; i < len;) {
    i32 s = size[i];
    i32 c = 0;
    for (; i < len && size[i] == s; ++i) c++;
    i32 b = 1;
    while (c > 0) {
      i32 p = s * b;
      for (i32 j = r - p; j >= 0; --j) {
        dp[j + p] |= dp[j];
      }
      c -= b;
      b = MIN (2 * b, c);
    }
  }
  puts (dp[r] ? "Yes" : "No");
}

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



Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define PT pair<int, int>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, M, R;
int E[201][201];
int D[8][201];
int r[8];
int kotae;
int ima;
bool v[8];
void sagasu(int n, int prev) {
	if (n == R) kotae = min(kotae, ima);
	else {
		rep(i, R) {
			if (!v[i]) {
				v[i] = 1;
				if (prev >= 0) ima += D[prev][r[i]];
				sagasu(n + 1, i);
				if (prev >= 0) ima -= D[prev][r[i]];
				v[i] = 0;
			}
		}
	}
}

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


	cin >> N >> M >> R;
	rep(i, R) cin >> r[i];

	rep1(i, N) {
		rep1(j, N) E[i][j] = 1e9;
		E[i][i] = 0;
	}
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		E[a][b] = c;
		E[b][a] = c;
	}

	rep(i, R) rep1(j, N) D[i][j] = 1e9;
	rep(i, R) D[i][r[i]] = 0;

	priority_queue<PT, vector<PT>, greater<PT>> que;

	rep(k, R) {
		que.push(mp(0, r[k]));
		while (que.size()) {
			PT p = que.top();
			que.pop();
			int i = p.second;
			if (D[k][i] != p.first) continue;
			rep1(j, N) {
				ll d = D[k][i] + E[i][j];
				if (D[k][j] > d) {
					D[k][j] = d;
					que.push(mp(d, j));
				}
			}
		}
	}

	kotae = 1e9;
	sagasu(0, -1);

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

//            int max = 0;
//            for (int i = 0; i < A.length; i++) {
//                max = Math.max(max, A[i]);
//            }
//
//            int max2 = 0;
//            for (int i = 1; i < max; i++) {
//                max2 = Math.max(max2, f(i, A));
//            }

            int max2 = 0;
            for (int i = 0; i < A.length; i++) {
                max2 += A[i] - 1;
            }
            System.out.println(max2);
        }
    }

    private static int f(int n, int[] a) {
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += n % a[i];
        }
        return sum;
    }

}


Measured memory_bytes: 27064
#include <bits/stdc++.h>
#include<set>
#define ll long long
#include <string>
using namespace std;
void fastio()
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

}
int main()
{
	fastio();
	string s;
	ll int n;
	cin>>n;
	ll int a[n],i,j;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll int g=__gcd(a[0],a[1]);
	for(i=2;i<n;i++)
	{
		g=__gcd(g,a[i]);
	}
	if(g>1)
	{
		cout<<"not coprime"<<endl;
		return 0;
	}
	map<ll  int ,ll int > m;
	for(i=0;i<n;i++)
	{
		ll int d=a[i];
		for(j=2;j*j<=d;j++)
		{

			if(d%j==0)
			{
				m[j]++;
				while(d%j==0)
				{
					d=d/j;

				}
			}
		}
		if (d!=1)
			m[d]++;

	}
	ll int fl=0;
	for(auto i: m)
	{
		if (i.second>1)
		{
			fl=1;
			break;
		}
	}
	if (fl==1)
		cout<<"setwise coprime"<<endl;
	else
		cout<<"pairwise coprime"<<endl;

}

Measured memory_bytes: 16212
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n==3||n==5||n==7){
		System.out.println("YES");}else{
		System.out.println("NO");}
		scan.close();
	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N, M;
string S;

int del[202020];
int Acnt[202020], Bcnt[202020];
vector<int>E[202020];



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

	cin >> N >> M >> S;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
		if (S[a] == 'A')Acnt[b]++;
		else Bcnt[b]++;
		if (S[b] == 'A')Acnt[a]++;
		else Bcnt[a]++;
	}

	queue<int>q;
	for (int i = 0; i < N; i++) {
		if (Acnt[i] == 0 || Bcnt[i] == 0) { q.push(i); del[i] = 1; }
	}

	while (q.size()) {
		int v = q.front();
		q.pop();
		fore(x,E[v]){
			if (del[x])continue;
			((S[v] == 'A') ? Acnt[x] : Bcnt[x]) -= 1;
			if (Acnt[x] == 0 || Bcnt[x] == 0) { q.push(x); del[x] = 1; }
		}
	}

	int ok = 0;
	for (int i = 0; i < N; i++)if (!del[i])ok = 1;
	if (ok)puts("Yes");
	else puts("No");

	return 0;
}

Measured memory_bytes: 13264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }

  sort(a.begin(),a.end());
  set<int> s;
  int ans=0;
  rep(i,n){
    if(i+1<n&&a[i]==a[i+1]){
      s.insert(a[i]);
      continue;
    }
    int ai=a[i];
    bool hit=false;
    rep_range(f,1,1000){
      if(ai%f==0){
        if(s.count(f)==1||s.count(ai/f)==1){
          hit=true;
          break;
        }
      }
    }
    if(!hit)ans++;

    s.insert(a[i]);
  }

  return ans;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 13556
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(n); rep(i, n) cin >> v[i];
	
	{
		bool ok = 1;
		rep(i, n - 1) if(v[i] >= v[i + 1]) ok = 0;
		if(ok){
			cout << 1 << endl;
			return 0;
		}
	}
	
	int lo = 1, hi = n, mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		map<int,int> p;
		rep(i, n - 1){
			if(v[i] < v[i + 1]) continue;
			int pos = -v[i + 1];
			while(p.size() && p.begin()->first < pos) p.erase(p.begin());
			while(pos < 0){
				if(++p[pos] >= mid){
					p.erase(pos);
					++pos;
				}
				else break;
			}
			if(pos == 0){
				lo = mid;
				goto END;
			}
		}
		hi = mid;
		END:;
	}
	cout << hi << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)



int main() {
  ll X; cin>>X;
  vector<ll> A(1001,0LL);
  for(ll i = 1; i <= 1000; i++) {
    ll tmp = i * i * i * i * i;
    A[(int)i] = tmp;
  }
  for(int i = 1000; i >= 0; i--) {
    for(int j = 1000; j >= 0; j--) {
      ll tmp = A[i] - A[j];
      if(tmp == X) {
	cout << i << " " << j << endl;
	return 0;
      }
      tmp = A[i] + A[j];
      if(tmp == X) {
	cout << i << " " << -j << endl;
	return 0;
      }

    }
  }
  return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(N, A, B));

        sc.close();
    }

    static int solve(int N, int A, int B) {
        return Math.min(N * A, B);
    }
}

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

int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  long long num = n%(a+b);
  long long div = n/(a+b);
  
  if(num == 0){
   cout<<div*a<<endl; 
  }
  else{
   		if(num >= a){
         cout<<((div*a) + a)<<endl; 
        }
    	else{
         	cout<<((div*a) +num)<<endl; 
        }
    
  }
 return 0; 
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var a = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            Console.WriteLine(a >= 3200 ? s : "red");
        }
    }
}


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

using ll = long long;

const int mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    string x(b - '0', a);
    string y(a - '0', b);
    cout << min(x, y) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
 
long long n, W;
long long weight[110], value[110];
 
long long dp[110][100100];
 
int main(){
  cin >> n >> W;
  for(int i = 0; i < n; ++i) cin >> weight[i] >> value[i];
  
  for(int w = 0; w <= W; ++w) dp[0][w] = 0;
  
  for(int i = 0; i < n; ++i){
    for(int w = 0; w <= W; ++w){
      if(w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }
  cout << dp[n][W] << endl;
}

Measured memory_bytes: 80128
#include <iostream>

bool a[1000000010];

int main(){
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        int t;
        std::cin >> t;
        if(a[t]){
            std::cout << "NO" << std::endl;
            return 0;
        }else{
            a[t] = true;
        }
    }
    std::cout << "YES" << std::endl;
    return 0;
}


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

const int MAXN = 3002;

double dp[MAXN][MAXN],P[MAXN];
int vis[MAXN][MAXN],N;

double solve(int pos,int heads){
	
	if(heads < 0) return 0.0;

	if(pos == 0){
		return (heads == 0);
	}

	if(vis[pos][heads]) return dp[pos][heads];
	vis[pos][heads] = 1;

	return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> P[i];
	}

	double tot = 0;
	for(int heads = 0;heads<=N;heads++){
		int tails = N - heads;
		if(heads > tails) tot += solve(N,heads);
	}

	printf("%.9lf\n",tot);

	return 0;

}

Measured memory_bytes: 105224
import sys
input = sys.stdin.readline
n = int(input())
degree = [ 0 for i in range(n) ]
connect_list = [ [] for i in range(n) ]
node_color = [0 for i in range(n)]
for i in range(n-1):
    a, b = [ int(v)-1 for v in input().split() ]
    connect_list[a].append([b,i])
    degree[a] += 1
    degree[b] += 1


maxcolor = max(degree)
search_list = [0]
node_color[0] = 0
color_list = [ k for k in range(1,maxcolor+1) ]

while search_list:
    new_search_list = []
    for i in search_list:
        p = 0
        for j, v in enumerate(connect_list[i]):
            a, b = v
            new_search_list.append(a)
            if node_color[i] == color_list[p]:
                p += 1
            node_color[a] = color_list[p]
            connect_list[i][j] = [b,color_list[p]]
            p += 1
    search_list = new_search_list

ans_list = []
for i in connect_list:
    for j in i:
        ans_list.append(j)

ans_list.sort()
print(maxcolor)
for i in ans_list:
    print(i[1])

Measured memory_bytes: 79688
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N, K;
    ll r, s, p;
    cin >> N >> K;
    cin >> r >> s >> p;
    string T;
    cin >> T;

    ll total = 0;
    rep(i,N){
    	char C = T[i];
    	if(C=='r') total += p;
    	else if(C=='s') total += r;
    	else total += s;
    }

    vector<bool> check(N,0);
    for(int i = 0; i+K < N; i++){
    	char C1 = T[i];
    	char C2 = T[i+K];
    	if(C1==C2){
    		if(C1=='r') total -= p;
    		else if(C1=='s') total -= r;
    		else total -= s;
    		T[i+K] = 'l';
    	}
    }

    cout << total << endl;
}

Measured memory_bytes: 512
#pragma comment(linker,"/STACK:102400000,102400000")
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <climits>
#include <cmath>
#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
const int N=2e5+10;
int arr[N],dp[N]; 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	dp[n-1]=0;
	for(int i=n-2;i>=0;i--){
		if(i==n-2){
		dp[n-2]=abs(arr[n-1]-arr[n-2]);	
		}
		else{
			dp[i]=min(abs(arr[i]-arr[i+1])+dp[i+1],abs(arr[i]-arr[i+2])+dp[i+2]);;
		}
	}
	printf("%d\n",dp[0]);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
typedef long long ll;
int n, m, k;

int a[maxn], b[maxn];
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    int mx_a = 1e9 + 1, mx_b = 1e9 + 1, ans = 1e9 + 1;
    for(int i=0;i<n;i++){
        scanf("%d", a + i);
        mx_a = min(mx_a, a[i]);
    }
    for(int i=0;i<m;i++){
        scanf("%d", b + i);
        mx_b = min(mx_b, b[i]);
    }
    ans = mx_a + mx_b;
    for(int i=0;i<k;i++){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        ans = min(ans, a[x - 1] + b[y - 1] - z);
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4736
import java.util.Arrays;
import java.util.Scanner;

public class Main {


  public static void main(String[] args) {
	Scanner in = new Scanner(System.in);

	int N = in.nextInt();
	int p[] = new int[N+1];
	int ans = 0;
	Arrays.fill(p, 0);

	for(int cnt = 0;cnt < N; cnt++){
		p[cnt] = in.nextInt();
	}

	for(int cnt = 0; cnt < N; cnt++){
		if(p[cnt] == cnt+1){
			int tmp = p[cnt];
			p[cnt] = p[cnt+1];
			p[cnt+1] = tmp;
			ans++;
		}
	}

	System.out.println(ans);

}
}

Measured memory_bytes: 50684
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int sum = 0;
		char ans[] = sc.next().toCharArray();		
		char board[][] = new char[n][];
		
		for(int i = 0; i < n; i++){
			board[i] = sc.next().toCharArray();
		}
		
		for(int i = 0; i < n; i++){
			search:for(int k = 0; k < board[i].length; k++){
				if(board[i][k] == ans[0]){
					for(int j = k+1; j < board[i].length; j++){
						if(board[i][j] == ans[1]){
							int diff = j - k;
							int a = 2;
//							int c = 2;
							for(int h = j + diff; h < board[i].length; h += diff){
								if(board[i][h] == ans[a] && a == ans.length - 1){
									sum++;
									break search;
								}else if(board[i][h] == ans[a]){
//									c++;
									a++;
								}else{
									break;
								}
							}
						}
					}
				}
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 27860
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		switch (N % 10) {
			case 3:
				System.out.println("bon");
				break;
			case 0:
			case 1:
			case 6:
			case 8:
				System.out.println("pon");
				break;
			default:
				System.out.println("hon");
				break;
		}
	}
}


Measured memory_bytes: 26988
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long int a,b,c,d,p,q,r,s,res,t,A,B;
cin>>a>>b>>c>>d;
s=(c*d)/(__gcd(c,d));
if(a%c!=0){
    A=((a/c)+1)*c;
}
else{A=a;}
if(a%d!=0){p=((a/d)+1)*d;}
else{p=a;}
if(a%s!=0){r=((a/s)+1)*s;}
else{r=a;}
if(b%d!=0){
    B=((b/d))*d;
}
else{B=b;}

if(b%c!=0){q=((b/c))*c;}
else{q=b;}
if(b%s!=0){t=((b/s))*s;}
else{t=b;}
res=(b-a)+1-((((q-A)/c)+1)+(((B-p)/d)+1)-(((t-r)/s)+1));

cout<<res<<endl;
return 0;

}


Measured memory_bytes: 256
process.stdin.resume()
process.stdin.setEncoding('utf8')
var g_input = ''
process.stdin.on('data', function(chunk) {
    g_input += chunk
})
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/))
})
function main(input){
  input = input[0].split(" ")
  a = Number(input[1]) - Number(input[0])/Number(input[2])
  if(0<=a){
    console.log('Yes')
  }else{
    console.log('No')
  }
}

Measured memory_bytes: 29992
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>

using namespace std;
using ll = long long;
const int BIG = 100000007;

using range = struct{
    ll min,max;
};

int main(){
    ll n;
    cin >> n;
    vector<range> veca(n,{0,0});
    vector<range> vecb(n,{0,0});
    for(int i = 0;i < n;++i){
        ll a,b;
        cin >> a >> b;
        veca[i].min = a;
        veca[i].max = b;
        vecb[i].min = a;
        vecb[i].max = b;
    }

    sort(veca.begin(),veca.end(),[](const auto& left, const auto& right){
        return left.min < right.min;
    });

    sort(vecb.begin(),vecb.end(),[](const auto& left, const auto& right){
        return left.max < right.max;
    });


    if(n % 2 == 1){
        cout << (vecb[n / 2].max - veca[n / 2].min + 1) << endl;
    }
    else{
        cout << ((vecb[n / 2 - 1].max + vecb[n / 2].max) - (veca[n / 2 - 1].min + veca[n / 2].min) + 1) << endl;
    }
}


Measured memory_bytes: 9168
n, m = map(int, input().split())

prefectures = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    prefectures[p-1].append((y, i))

ans = [None] * m
for i, p in enumerate(prefectures):
    p.sort()
    for j, (y, k) in enumerate(p):
        ans[k] = "%06d%06d" % (i+1, j+1)

print(*ans, sep='\n')


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

#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll d[100];
int main(){
  ll n,ans=0;
  cin>>n;
  rep(i,0,n)cin>>d[i];
  rep(i,0,n){
    rep(j,i+1,n){
      ans+=d[i]*d[j];
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256