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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
int main() {
    int n, k;
    cin >> n >> k;
    cout << modpow(k, n) << endl;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define INF 1000000000000000000
#define Rep(i, a, n) for (ll i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000000000000000000
#define ll long long
#define P pair<int,int>
#define cout_set(n) cout << setprecision(10) << (n) << endl; 
const double PI=3.14159265358979323846;
using namespace std;
const int mod = 1000000007; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

int main(){
    long double b;
    long double a; cin >> a >> b;
    ll ans = (a*b + 0.001);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{

    int n,x,ans,temp;
    while(cin>>n>>x)
    {
        ans=0x3f3f3f3f;
        for(int i=0;i<n;i++){
            scanf("%d",&temp);
            a[i]=abs(temp-x);
        }
        sort(a,a+n);
        ans=gcd(a[0],a[1]);
        for(int i=2;i<n;i++)
        ans=gcd(ans,a[i]);
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>

using namespace std;
typedef tuple<string, int, int> mytuple;

// タプルの最初の要素から順番に比較　もしその要素が同じなら次の要素で比較
bool mycompare( const mytuple &lhs, const mytuple &rhs ){
  if (std::get<0>(lhs) != std::get<0>(rhs)) return std::get<0>(lhs) < std::get<0>(rhs);
  if (std::get<1>(lhs) != std::get<1>(rhs)) return std::get<1>(lhs) > std::get<1>(rhs);
	return std::get<2>(lhs) < std::get<2>(rhs);
}

int main(){
	int N; cin >> N;
	vector<tuple<string, int, int> > SP(N);

	for(int i = 0; i < N; ++i){
	 cin >> get<0>(SP[i]) >> get<1>(SP[i]);
	 get<2>(SP[i]) = i;
	}

	sort(SP.begin(), SP.end(), mycompare);


		for(int i = 0; i < N; ++i){
			cout << get<2>(SP[i]) +1 << endl;
		}

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	flag := false
	for i := 0; i < len(s); i += 2 {
		if s[i:i+1] != "R" && s[i:i+1] != "U" && s[i:i+1] != "D" {
			flag = true
		}
		if i+1 < len(s) {
			if s[i+1:i+2] != "L" && s[i+1:i+2] != "U" && s[i+1:i+2] != "D" {
				flag = true
			}
		}
		if flag {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


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

using namespace std;

const int N = 21;
int n;
int val[N] , cost[N];

int main() {
    scanf("%d" , &n);
    for (int i = 0 ;i < n ;i++)
        scanf("%d" , val + i);
    for (int i = 0 ;i < n ;i++)
        scanf("%d" , cost + i);

    int mx = 0;
    for (int i = 0 ;i < (1 << n) ;i++) {
        int v = 0 , c = 0;
        for (int j = 0 ;j < n ;j++) {
            if (i & (1 << j)) {
                v += val[j];
                c += cost[j];
            }
        }
        mx = max(mx , v - c);
    }

    printf("%d" , mx);
}

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

using namespace std;

typedef long long ll;

const ll MAX_X = 1e6, MIN_X = -1e6;

int main(int argc, char const *argv[])
{
    int x, k;
    cin >> k >> x;
    vector<int> vec;
    for (int i = x-k+1; i <= x+k-1; ++i) {
        vec.emplace_back(i);
    }

    for (int i = 0; i < vec.size(); ++i) {
        cout << vec[i] << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  int count = 0;
  
  for(int i = 0;i < s.size();i ++){
    int karicount = 0;
    for(int j = 0;j < s.size() - i;j ++){
      if(s[i + j] == 'A' || s[i + j] == 'C' || s[i + j] == 'G' || s[i + j] == 'T'){
        karicount ++;
      }
      else break;
    }
    if(karicount > count)count = karicount;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int A[6010];
int mem[6010][6010][2];


int rec(int l, int r, bool f){
    if(r-l == N) return 0;
    int& res = mem[l][r][f];
    if(res != 0) return res;
    if(f){
        if(A[l-1] < A[r]) return res = rec(l, r+1, !f);
        return res = rec(l-1, r, !f);
    }
    return res = max(rec(l, r+1, !f)+A[r], rec(l-1, r, !f)+A[l-1]);
}


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> A[i], A[i+2*N] = A[i+N] = A[i];

    int ans = 0;
    rep(i, 0, N) chmax(ans, rec(i+N, i+N+1, 1)+A[i+N]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 108952
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int main(){
    int N;
    scanf("%d",&N);
    int d[100000];
    int i;
    for(i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    qsort(d,N,sizeof(int),asc);
    int K;
    if(d[N/2]!=d[N/2-1]){
        K=d[N/2]-d[N/2-1];
    }
    else {
        K=0;
    }
    printf("%d\n",K);
    return 0;
}

Measured memory_bytes: 892
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll A[3];
    rep(i, 3){
        cin >> A[i];
    }
    sort(A, A + 3);

    if(A[0] == 5 && A[1] == 5 && A[2] == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    string b;
    cin >> b;

    rep(i, b.size()){
        if(b[i] == 'A'){
            cout << 'T';
        }else if(b[i] == 'T'){
            cout << 'A';
        }else if(b[i] == 'G'){
            cout << 'C';
        }else{
            cout << 'G';
        }
    }
    cout << endl;

    return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans;
  rep(i, n) {
    x -= a[i];
    if (x < 0) {
      ans = i;
      break;
    }
    ans = i + 1;
  }
  if (x > 0) ans--;

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int solve(string s, char c){
    s.push_back(c);
    int N=s.size();
    int ret = 0;
    int cnt = 0;
    for(int i=N-1; i>=0; i--){
        if(s[i] == c) cnt = 0;
        else cnt++;
        ret = max(ret, cnt);
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 1000;
    for(char c='a'; c<='z'; c++)
        ans = min(ans, solve(s, c));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] x = new int[2];
		int gcd = 1;
		int lcm;
		int temp;
		while (scan.hasNext()) {
			for (int i = 0; i < x.length; i++) {
				x[i] = scan.nextInt();
			}
			if (x[0] > x[1]) {
				temp = x[1];
			} else {
				temp = x[0];
			}
			for (int i = 1; i <= temp; i++) {
				if (x[0] % i == 0 && x[1] % i == 0) {
					gcd = i;
				}
			}
			x[0] /= gcd;
			x[1] /= gcd;
			lcm = x[0] * x[1] * gcd;
			System.out.println(gcd + " " + lcm);
		}
	}
}

Measured memory_bytes: 19620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)

typedef pair<int, int> pint;
#define INF 1e9

struct w_union_find{
    // d_ws[a]はroot -> aの重み.
    vector<int> d_ws;
    vector<int> ps;
    w_union_find(int n = 1) : ps(n, -1), d_ws(n, 0){}

    int root(int a){
        if(ps[a] < 0){
            return a;
        }
        int r = root(ps[a]);
        d_ws[a] += d_ws[ps[a]];
        return ps[a] = r;
    }

    bool same(int a, int b){
        return root(a) == root(b);
    }

    int weight(int a){
        root(a);
        return d_ws[a];
    }

    int diff_weight(int a, int b){
        return weight(b) - weight(a);
    }

    bool unite(int a, int b, int w){
        if(same(a, b)){
            return diff_weight(a, b) == w;
        }

        w -= weight(b);
        w += weight(a);

        a = root(a);
        b = root(b);

        if(ps[a] > ps[b]){
            swap(a, b);
            w *= -1;
        }
        ps[a] += ps[b];
        ps[b] = a;
        d_ws[b] = w;

        return true;
    }

};

int main(){
    int N, M;
    cin >> N >> M;
    w_union_find uf(N);

    rep(i, M){
        int l, r, d;
        cin >> l >> r >> d;
        if(! uf.unite(l, r, d)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

  if(N%2==1){
    cout << (N-1)*(N-1)/2 << endl;
    FOR(i,1,N+1){
      FOR(j,i+1,N+1){
        if(j!=N-i){
          cout << i << " " << j << endl;
        }
      }
    }
  }else{
    cout << (N-2)*N/2 << endl;
    FOR(i,1,N+1){
      FOR(j,i+1,N+1){
        if(j!=N-i+1){
          cout << i << " " << j << endl;
        }
      }
    }
  }
}

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

int main()
{
    int n;

    cin >> n;
    int flag = 0;
    vector<int> vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec.at(i);
        if (i>=2){
            if((vec.at(i - 2) <= vec.at(i-1) && vec.at(i-1) <= vec.at(i)) || (vec.at(i - 2) >= vec.at(i-1) && vec.at(i-1) >= vec.at(i))){
                flag++;
            }
        }
    }
    cout << flag << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int rest = 11;
        int acc = 0;

        for(int i=0; i<5; i++){
            int tmp = scanner.nextInt();

            if(tmp % 10 < rest && tmp % 10 != 0){
                rest = tmp % 10;
            }

            acc += Math.ceil(tmp / 10.0) * 10;
        }

        if(rest != 11){
            acc -= 10;
            acc += rest;
        }
        System.out.println(acc);

    }
}


Measured memory_bytes: 21844
/**
 * @author derrick20
 * Easy
 */
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        if (N % 2 == 0) {
            out.println(N);
        }
        else {
            out.println(2 * N);
        }

        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        FastScanner(FileReader s) {
            br = new BufferedReader(s);
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException { return br.readLine(); }

        double nextDouble() throws IOException { return Double.parseDouble(next()); }

        int nextInt() throws IOException { return Integer.parseInt(next()); }

        long nextLong() throws IOException { return Long.parseLong(next()); }
    }
}

Measured memory_bytes: 20948
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

void makeNextLunLun(vector<int> &L){
	if(L.size()==0){
		L.push_back(1);
		return;
	}
	else if(L.size()==1){
		if(L[0] < 9){
			L[0]++;
		}
		else if(L[0] == 9){
			L[0] = 1;
			L.push_back(0);
		}
		return;
	}
	else{
		int carry = 1;
		int l = L.size();
		for(int i = l - 1; i >= 0; i--){
			if(i == l - 1){ //末尾
				if(L[i] <= L[i-1] && L[i] < 9){
					L[i]++;
					carry = 0;
					break;
				}
			}
			else if(i != 0){ //中間
				int a = L[i-1];
				int b = L[i];
				int c = L[i+1];
				if(b <= a){
					if(b < 9 && abs((b +1 - c)) <= 1){
						L[i]++;
						for(int j=i+1; j<l; j++){
							L[j] = max(0, L[j-1] - 1);
						}
						carry = 0;
						break;
					}
				}
				else if(b == a + 1){
					continue;
				}
			}
			else{ //先頭
				if(L[i] == 9){
					//桁上がりさせる
					carry = 1;
					break;
				}
				else{
					L[i]++;
					for(int j= 1; j<l; j++){
						L[j] = max(0, L[j-1]-1);
						carry = 0;
					}
				}
			}
		}
		//桁上がり
		if(carry == 1){
			L.clear();
			L.push_back(1);
			for(int i=0; i<l; i++){
				L.push_back(0);
			}
		}
	}


}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long K;
	cin >> K;

	if(K < 10){
		printf("%lld\n", K);
		return 0;
	}

	vector<int> v;
	for(int i=1; i<=K; i++){
		makeNextLunLun(v);
	}
	for(int i=0; i<v.size(); i++){
		printf("%d", v[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>

int s[1000000],sum1;

int search(int t){
  int left=0,right=sum1,mid=0;
  while(left < right){
    mid = (left+right)/2;
    if(t==s[mid]) return 1;
    if(t>s[mid]) left = mid +1;
    else if(t<s[mid]) right = mid;
  }
  return 0;
}
int main(){
  int i,j,sum2,sum3=0,t;
  scanf("%d",&sum1);
  for(i=0;i<sum1;i++) scanf("%d",&s[i]);
  scanf("%d",&sum2);
  for(j=0;j<sum2;j++){
      scanf("%d",&t);
      if(search(t)!=0) sum3++;
  }
  printf("%d\n",sum3);
  return 0;
}

Measured memory_bytes: 988
n, k = map(int, input().split())
p = list(map(int, input().split()))

s = 0
s_max = 0

for i in range(n):
    if i < k:
        s += p[i]
        if i == k-1:
            s_max = s
    else:
        s += p[i] - p[i-k]
        s_max = max(s_max, s)

print((k+s_max)/2)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
long long n;
stack<char>s;
int main()
{
	cin>>n;
	while(n)
	{
		n--;
		long long shang=n/26;
		long long yu=n%26;
		n=shang;
		s.push((char)('a'+yu));
	}
	while(!s.empty())
	{
		cout<<s.top();s.pop();
	}
}

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

using namespace std;



class Node{
//ノードはポインタでもっておこう
public:
  ///ノードの番号
  int num;
  //そのノードの親
  //rootの場合はnullptr
  Node* p=nullptr;
  //そのノードの子
  //葉でなければ少なくとも一つ持つ
  Node* l=nullptr;Node*r=nullptr;
  //rootもしくは片側のみノードでなければ持つ
  Node* s=nullptr;
  //そのノードの深さ(-1は未定義)
  //0で初期化
  int dep;
  int height;
};

int number(Node a){
  return a.num;
}

int parent(Node a){
  if(a.p!=nullptr){
    return (a.p)->num;
  }else{
    return -1;
  }
}

int sibling(Node a){
  if(a.s!=nullptr){
    return (a.s)->num;
  }else{
    return -1;
  }
}

Node root_Node(vector<Node> vn){
  int lv=(int)(vn.size());
  for(int i=0;i<lv;i++){
    if(vn[i].p==nullptr){return vn[i];}
  }
}

void depth(Node n){
  if(n.l!=nullptr){
    (n.l)->dep=n.dep+1;
    depth(*(n.l));
  }
  if(n.r!=nullptr){
    (n.r)->dep=n.dep+1;
    depth(*(n.r));
  }
}

vector<Node> leaf_Nodes(vector<Node> vn){
  vector<Node> vr;
  int lv=(int)(vn.size());
  for(int i=0;i<lv;i++){
    if(vn[i].l==nullptr and vn[i].r==nullptr){
      vr.push_back(vn[i]);
    }
  }
  return vr;
}

void height_sub(Node n){
  if(n.p!=nullptr){
    (n.p)->height=max(n.height+1,(n.p)->height);
    height_sub(*(n.p));
  }
}

void height(vector<Node> vn){
  int lv=(int)(vn.size());
  for(int i=0;i<lv;i++){
    height_sub(vn[i]);
  }
}


int Node_child_len(Node n){
  int c=0;
  if(n.l!=nullptr){c++;}
  if(n.r!=nullptr){c++;}
  return c;
}

string type(Node a){
  if(a.p==nullptr){
    return "root";
  }else if(a.l==nullptr and a.r==nullptr){
    return "leaf";
  }else{
    return "internal node";
  }
}

int main(){
  int n;cin >> n;
  vector<Node> tree(n);
  for(int i=0;i<n;i++){
    int num,l,r;cin >> num >> l >> r;
    tree[num].num=num;
    //-1の場合の場合分け
    if(l!=-1){
      tree[num].l=&tree[l];
      tree[l].p=&tree[num];
    }
    if(r!=-1){
      tree[num].r=&tree[r];
      tree[r].p=&tree[num];
    }
    if(l!=-1 and r!=-1){
      tree[l].s=&tree[r];
      tree[r].s=&tree[l];
    }
  }
  height(leaf_Nodes(tree));
  depth(root_Node(tree));
  for(int i=0;i<n;i++){
    Node tr=tree[i];
    cout << "node " << number(tr) << ": parent = " << parent(tr) << ", sibling = " << sibling(tr) << ", degree = " << Node_child_len(tr) << ", depth = " << tr.dep << ", height = " << tr.height << ", " << type(tr) << endl;
  }
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int a;
  string s;
  cin>>a>>s;
  if(a>= 3200) cout <<s<<endl;
  else cout<<"red "<<endl;
  
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,b[100],a[100][100];
  cin>>n>>m;
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j) cin>>a[i][j];
  for(int i=0;i<m;++i) cin>>b[i];
  for(int i=0;i<n;++i){
    int sum=0;
    for(int j=0;j<m;++j)
      sum+=a[i][j]*b[j];
    cout<<sum<<endl;
  }
  return 0;
}



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

using namespace std;

int main(){
	int n;
  cin >> n;
  vector<int> P(n), Psorted(n);
  for(int& i: P) cin >> i;
  Psorted = P;
  sort(Psorted.begin(), Psorted.end());
  int cnt = 0;
  for(int i = 0; i < n; i++) if(P[i] != Psorted[i]) cnt++;
  if(cnt == 0 || cnt == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 384
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

vector<int> B { 400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 5000 };

int main() {
  ll a, b;in(a),in(b);
  print(lcm(a, b));
  return 0;
}


Measured memory_bytes: 3612
//****************************//
/**********  main *************/
//****************************//
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for(i = 0; i < n; i++)
#define FOR(i, a, b) for(i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

double pi = 3.141592653589793;

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

int main() {

    std::cin.tie(0);

    int i,j,k;      //preset
    int res;
    int count=0;

    int l,r,d;
    cin >> l >> r >> d;

    for(i=l;i<=r;i++){
        if(i%d==0)count++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
long long h;
long long num(long long a)
{
	if (a==1)
		return 1;
	return num(a/2)*2+1;
}
int main()
{
	cin>>h;
	cout<<num(h)<<endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
N=int(input())
L=list(map(int,input().split()))
M=max(L)

def lcm(a, b):
    return a * b // gcd (a, b)

p=1
for i in L:
    p=lcm(i,p)
q=0
print(sum([(p-1)%i for i in L]))

Measured memory_bytes: 5844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,m;
    cin>>n;
    map<string,int> mp;
    rep(i,n){
        string s; cin>>s;
        mp[s]++;
    }
    cin>>m;
    rep(i,m){
        string s; cin>>s;
        mp[s]--;
    }
    int ans=0;
    for(auto& v: mp) ans=max(ans,v.second);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
//3変数の相加相乗平均の関係式より、p+q+r=Lでp, q, rが正数の時に、
//L/3=(p+q+r)/3 >= (pqr)^1/3
//よりVの最大値は(L/3)^3=L*L*L/27.0
int main (void)
{
  int L; //unsignedは使わなかった。
  scanf ("%d", &L);
  double V = ((double) L) * ((double) L) * ((double) L) / 27.0;
  printf ("%lf\n", V);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll          long long
#define int 		long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	//write here
	ll r,g,b,k;
	cin>>r>>g>>b;
	cin>>k;
	while (k>0 && g<=r){
		g*=2;
		k--;
	}
	while (k>0 && b<=g){
		b*=2;
		k--;
	}
	//cout<<r<<" "<<g<<" "<<b<<endl;
	if (r<g && g<b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return;
}

int32_t main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	
		solve();
	return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
using namespace std;

int N;
struct Pos {
	int x, y;
};

int main() {
	scanf(" %d", &N);
	for(int i = 0; i < N; i++) {
		if(i != 0) {
			puts("");
		}
		// arr[y][x]
		int arr[9][9];
		bool fail[9][9];
		memset(fail, 0, sizeof fail);

		for(int y = 0; y < 9; y++) {
			for(int x = 0; x < 9; x++) {
				scanf(" %d", &arr[y][x]);
			}
		}
		for(int x = 0; x < 9; x++) {
			int count[10];
			memset(count, 0, sizeof count);
			for(int y = 0; y < 9; y++) {
				count[arr[y][x]]++;
			}
			for(int i = 1; i <= 9; i++) {
				if(count[i] != 1) {
					for(int y = 0; y < 9; y++) {
						if(arr[y][x] == i)
							fail[y][x] = true;
					}
				}
			}
		}

		for(int y = 0; y < 9; y++) {
			int count[10];
			memset(count, 0, sizeof count);
			for(int x = 0; x < 9; x++) {
				count[arr[y][x]]++;
			}
			for(int i = 1; i <= 9; i++) {
				if(count[i] != 1) {
					for(int x = 0; x < 9; x++) {
						if(arr[y][x] == i)
							fail[y][x] = true;
					}
				}
			}
		}

		Pos p[9] = {{1, 1}, {1, 4}, {1, 7}, {4, 1}, {4, 4}, {4, 7}, {7, 1}, {7, 4}, {7, 7}};
		for(int i = 0; i < 9; i++) {
			int cx = p[i].x;
			int cy = p[i].y;
			int count[10];
			memset(count, 0, sizeof count);
			for(int x = -1; x <= 1; x++) {
				for(int y = -1; y <= 1; y++) {
					int nx = cx + x;
					int ny = cy + y;
					count[arr[ny][nx]]++;
				}
			}
			for(int j = 1; j <= 9; j++) {
				if(count[j] != 1) {
					for(int x = -1; x <= 1; x++) {
						for(int y = -1; y <= 1; y++) {
							int nx = cx + x;
							int ny = cy + y;
							if(arr[ny][nx] == j) {
								fail[ny][nx] = true;
							}
						}
					}
				}
			}
		}

		for(int y = 0; y < 9; y++) {
			for(int x = 0; x < 9; x++) {
				putchar(fail[y][x] ? '*' : ' ');
				printf("%d", arr[y][x]);
			}
			puts("");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define f first
#define sc second=
map<int, int> mp;
void solve() {
    ll n, x, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x;
        mp[x]++;
        sum += x;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        if (mp[a] == 0) {
            cout << sum << "\n";
            continue;
        }
        else {
            ll x = b - a;
            sum += x * mp[a];
            mp[b] += mp[a];
            mp[a] = 0;
            cout << sum << "\n";
        }
    }
    return;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    solve();
}


Measured memory_bytes: 7812
#include <bits/stdc++.h>
using namespace std;
int N, L;
int main() {
    cin >> N >> L;
    vector<string> s(N);
    for(int i = 0; i < N; ++i) {
        cin >> s.at(i);
    }

    sort(s.begin(), s.end());

    for(int i = 0; i < N; ++i) {
        cout << s.at(i);
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
value = 0
for i in range(N):
  value += B[A[i]-1]
  if i > 0 and A[i] == A[i-1]+1:
    value += C[A[i-1]-1]
print(value)

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

string padding (string str);

int main () {

    int N, M;
    scanf("%d %d", &N, &M);

    vector<tuple<int, int, int>> PY;
    for (int i = 0; i < M; i++) {
        int p, y;
        scanf("%d %d", &p, &y);

        PY.emplace_back(p, y, i);
    }

    sort(PY.begin(), PY.end());

    vector<string> ID(M);
    int cnt = 1;

    ID[get<2>(PY[0])] = padding(to_string(get<0>(PY[0]))) + padding(to_string(cnt));

    for (int i = 1; i < M; i++) {
        if (get<0>(PY[i]) != get<0>(PY[i-1])) cnt = 1;
        else cnt++;

        ID[get<2>(PY[i])] = padding(to_string(get<0>(PY[i]))) + padding(to_string(cnt));
    }

    for (int i = 0; i < M; i++) {
        cout << ID[i] << endl;
    }

    return 0;
}

string padding (string str) {

    int zeros = 6 - (int)str.size();

    for (int i = 0; i < zeros; i++) {
        str = "0" + str;
    }

    return str;
}


Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,D,X;
    cin>>N>>D>>X;

    vector<int>A(110);
    for(int i=0;i<N;i++)cin>>A[i];

    int sum=0;
   

    for(int i=0;i<N;++i){
        int tmp=(D-1)/A[i] +1;
        sum +=tmp;
        }
       
       
    
    cout<<sum+X<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

string s;

// bit_sum O(log n) for a query
// 1. set n;
// 2. init bit[n+1];

const int MAX_N = 100000;

ll bit[MAX_N+1], n;

ll bit_sum(int i){
  ll s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void bit_add(int i, ll x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}


int main(){
  cin >> s;
  int len = s.size();
  int place[len];

  map<char, int> mp;
  REP(i, len) {
    mp[s[i]]++;
  }
  map<char, int> ct;
  bool kisuu = false;
  for (auto x : mp) {
    if(x.second % 2 == 1) {
      if(kisuu) {
        cout << -1 << endl;
        return 0;
      } else {
        kisuu = true;
      }
    }
  }

  string right, left;

  REP(i, len) {
    char c = s[i];
    ct[c]++;

    if(ct[c] <= mp[c] / 2) {
      place[i] = 3;
      left += c;
    } else if(mp[s[i]] % 2 == 1 && ct[c] == mp[c] / 2 + 1) {
      place[i] = 2;
    } else {
      place[i] = 1;
      right += c;
    }
  }

  ll bubble = 0;

  n = 3;
  REP(i, n + 1) {
    bit[i] = 0;
  }

  REP(i, len) {
    bubble += bit_sum(place[i] - 1);
    bit_add(place[i], 1);
  }

  // cout << "firsr bubble: " << bubble << endl;
  //
  // cout << "left: " << left << ", right: " << right << endl;

  ct.clear();
  map<char, map<int, int> > place_mp;
  REP(i, len / 2) {
    char c = left[i];
    ct[c] ++;
    place_mp[c][ct[c]] = len / 2 - i;
  }
  ct.clear();
  int forbubble[len / 2];
  REP(i, len / 2) {
    char c = right[len / 2 - 1 - i];
    ct[c] ++;
    forbubble[i] = place_mp[c][ct[c]];
  }
  //
  // REP(i, len / 2) cout << forbubble[i] << ",";
  // cout << endl;

  n = len / 2;
  REP(i, n + 1) {
    bit[i] = 0;
  }
  REP(i, len / 2) {
    bubble += bit_sum(forbubble[i] - 1);
    bit_add(forbubble[i], 1);
  }

  cout << bubble << endl;

  return 0;
}


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

int main(){
    while(1){
        int H,W;
        cin>>H>>W; 
        if(H==0||W==0){
            break;
        } 
        for(int i= 1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    int n,temp,tot=0;
    cin>>n;
    map<int,int> a;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        a[temp]++;
        tot+=temp;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        a[c]+=a[b];
        tot+=(c*a[b]-b*a[b]);
        a[b]=0;
        cout<<tot<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b;
    cin>>a>>b;
    ll ans=a*b-a-b+1;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)
 
 
int main(){
 
	lli N,M,R;
	cin>>N>>M>>R;
	vector<lli> r(R);
	REP(i,R)cin>>r[i];
 
	vector<lli> a(M),b(M),c(M);
	lli dp[210][210];
	REP(i,210)REP(j,210)dp[i][j]=8000000000000000;
 
	REP(i,M){
		cin>>a[i]>>b[i]>>c[i];
		dp[b[i]][a[i]] = min(dp[b[i]][a[i]],c[i]);
		dp[a[i]][b[i]] = min(dp[a[i]][b[i]],c[i]);
	}
 
	/*ワーシャルフロイト法にて全部の街の経路をキメる*/
	for(lli k=1;k<=N;k++)for(lli i=1;i<=N;i++)for(lli j=1;j<=N;j++){
		dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
	}
 
	/*先頭とゴールを適当に決める*/
	lli ans=8000000000000000;

	sort(r.begin(),r.end());
	do{
		lli sum = 0;
		lli before = r[0];
		for(lli i=1;i<R;i++){
			lli next = r[i];
			if(DEBUG)cout<<"before="<<before<<"next = "<<next<<"dp="<<dp[before][next]<<endl;
			sum += dp[before][next];
			before = next;
		}
 
		ans = min(sum,ans);
	}while(next_permutation(r.begin(),r.end()));
 
	cout<<ans<<endl;
 
	return 0;
 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;
int N;
int main(){
	bool flg=false;
	cin>>N;
	REP(i,N){
		int a;
		cin>>a;
		if (a&1){
			flg=true;
		}
	}
	cout<<(flg ? "first" : "second")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include <iostream>
#include<math.h>

using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int N, K;
int a, b;
string s;
int d[100000 + 1];
char c[100000 + 1];

int main(void) {
    int x;
    cin >>x >> a >> b;



    cout << (x -a) % b << endl;
    return 0;
}




Measured memory_bytes: 764
fn main() {
    proconio::input! {
        n:usize
    }
    let mut ans = 0;
    //    let mut i = 1;
    let s = (n as f64).sqrt() as usize;
    let mut i = 1;
    while i * i <= n {
        let c = n / i;
        ans += i * c * (c + 1) / 2;
        // さらに、c について、いくつかまとめて計算。
        if c > i {
            let d = n / (i + 1);
            ans += (c * (c + 1) - d * (d + 1)) * i * (i + 1) / 4;
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2148
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
  FAST_IO  
  
  string input; cin >> input;
  int N = SZ(input), optimal = N;

  for(int idx = 1; idx < N; ++idx){
    if(input[idx] == input[idx - 1]) continue;
    int cur = max(idx, N - idx);
    min_self(optimal, cur);
  }

  cout << optimal << "\n";
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class zone{
public:
	int d,p;
	zone(int d,int p):d(d),p(p){}
};

bool operator < (zone a,zone b){
	return a.p>b.p;
}


int main()
{
	int n;
	long long m;
	while(cin>>n>>m && n!=0){
		vector<zone> V;
		for(int i=0;i<n;i++){
			int d,p; cin>>d>>p;
			V.push_back(zone(d,p));
		}
		sort(V.begin(),V.end());
		int ans=0;
		for(int i=0;i<V.size();i++){
			if(m-V[i].d>=0) m-=V[i].d;
			else{
				ans+=V[i].p*(V[i].d-m);
				m=0;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
vector<int> tree(100001);

int root(int x){
  if (tree[x] == x){
    return x;
  }
  else{
    return tree[x] = root(tree[x]);
  }
}

int main(){
  int n,m;
  int x,y,z;
  cin >>n>>m;
  for (int i=0; i<n; i++){
    tree[i] = i;
  }
  for (int i=0; i<m; i++){
    cin >>x>>y>>z;
    int rx=root(x);
    int ry=root(y);
    if (rx != ry){
      tree[rx]=ry;
    }
  }
  int count=0;
  for (int i=0; i<n; i++){
    if (tree[i]==i)count++;
  }
  cout << count << endl;
}
    

Measured memory_bytes: 640
#include <stdio.h>

#define MAX(x, y) ((x) > (y) ? (x) : (y))

int n;
int A[1<<18];
int B[1<<18];

void zeta(int n){
  int i, j;
  int m = 1 << n;
  for(i=1;i<m;i<<=1){
    for(j=0;j<m;j++){
      if(j&i){
        int max = MAX(A[j], A[j^i]);
        B[j] = MAX(MAX(max^A[j]^A[j^i], B[j]), B[j^i]);
        A[j] = max;
      }
    }
  }
}


int main(){
  int i, max;
  scanf("%d", &n);
  for(i=0;i<(1<<n);i++){
    scanf("%d", A+i);
  }
  zeta(n);
  max = 0;
  for(i=1;i<(1<<n);i++){
    max = MAX(max, A[i]+B[i]);
    printf("%d\n", max);
  }
  return 0;
}


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

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


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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

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

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

	int a,b,c;
	cin>>a>>b>>c;
	if (c-a-b>0 && 4*a*b<(c-a-b)*(c-a-b))
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>

using namespace std;

const static int MAX_N = 100000;
int n;
int m;

long long x[MAX_N];
long long y[MAX_N];

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> y[i];
  }

  long long sum_x = 0;
  for (int k = 1; k <= n; k++) {
    sum_x += ((long long)(k - 1) * x[k - 1]) - ((long long)(n - k) * x[k - 1]);
  }

  long long sum_y = 0;
  for (int k = 1; k <= m; k++) {
    sum_y += ((long long)(k - 1) * y[k - 1]) - ((long long)(m - k) * y[k - 1]);
  }

  long long ans = (sum_x % 1000000007) * (sum_y % 1000000007);
  ans = ans % 1000000007;

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


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

int main(){
  int n,j=0;
  int a[1000];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
 		j++;     
      }
    }
  }
  
  if(j==0) printf("APPROVED");
  else printf("DENIED");
     
 
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,S[1000];

void push(int x)//push x to stack
{
    top++;
    S[top]=x;
}
int pop()
{
    --top;
    return S[top+1];
}

int main()
{
    int a,b;
    top=0;
    char s[100];
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='+')
        {
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(s[0]=='-')
        {
            a=pop();
            b=pop();
            push(b-a);
        }
        else if(s[0]=='*')
        {
            a=pop();
            b=pop();
            push(a*b);
        }
        else
        push(atoi(s));
    }
    printf("%d\n",pop());
    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        BigInteger MAX = new BigInteger("100000000000000000000000000000000000000000000000000000000000000000000000000000000");
        int i = 0;
        Scanner sc = new Scanner(System.in);
        int dataSet = sc.nextInt();
        while ( i < dataSet ) {
            BigInteger inputedData1, inputedData2;
            inputedData1 = sc.nextBigInteger();
            inputedData2 = sc.nextBigInteger();
            if ( inputedData1.add(inputedData2).compareTo(MAX) < 0 ) {
                System.out.println(inputedData1.add(inputedData2));
            }else{
                System.out.println("overflow");
            }
            i++;
        }
    }
}

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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

int main() {
    int q = read();
    priority_queue<int> l;
    priority_queue<int, vector<int>, greater<int> > r;
    long long ans = 0;
    while (q--) {
        int t = read();
        if (t == 1) {
            int a = read(), b = read();
            ans += b;
            l.push(a);
            r.push(a);
            if (l.top() > r.top()) {
                int x = l.top(); l.pop();
                int y = r.top(); r.pop();
                ans += abs(x - y);
                l.push(y); r.push(x);
            }
        } else {
            printf("%d %lld\n", l.top(), ans);
        }
    }
    return 0;
}

Measured memory_bytes: 3828
#include<iostream>
int main(){int f[2],i,j;std::string r,a;while(std::cin>>r>>a,r!="0"&&a!="0"){for(f[0]=f[1]=i=0;i<4;i++)for(j=4;j-->0;)if(a[i]==r[j])f[i!=j]++;printf("%d %d\n",f[0],f[1]);}}

Measured memory_bytes: 0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BSportsFestival solver = new BSportsFestival();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSportsFestival {
        boolean[] use;
        int[][] fav;
        int[] cnt;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            use = new boolean[m];
            fav = new int[n][m];
            cnt = new int[m];
            Arrays.fill(use, true);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    fav[i][j] = in.nextInt() - 1;
                }
            }

            out.println(f());

        }

        int f() {
            int dec = 0;
            Arrays.fill(cnt, 0);
            for (int i = 0; i < fav.length; i++) {
                for (int j = 0; j < fav[i].length; j++) {
                    if (use[fav[i][j]]) {
                        cnt[fav[i][j]]++;
                        break;
                    }
                    if (j == fav[i].length - 1) return fav.length + 100;
                }
            }
            for (int i = 0; i < cnt.length; i++) {
                if (cnt[dec] < cnt[i]) dec = i;
            }
            use[dec] = false;
            return Math.min(cnt[dec], f());
        }

    }
}



Measured memory_bytes: 48168
n,k=map(int,input().split())
a=list(map(int,input().split()))
suma=sum(a)
import math
def func(x):
  chk=0
  for ai in a:
    # 長さx以下に分割するなら最小でtmp本にわかれる
    tmp=math.ceil(ai/x)
    chk+=tmp
  return chk<=n+k
l,r=0,max(a)
for _ in range(50):
  x=(l+r)/2
  if func(x):# k回ですべてx以下にできるなら、もっと小さくできそう
    l,r=l,x
  else:
    l,r=x,r
x=(l+r)/2
print(math.ceil(x))
#print(l,r,x)

Measured memory_bytes: 93852
import itertools
n, m = map(int, input().split())
s = [[0] * n for _ in range(m)]
for i in range(m):
    k, *si = map(int, input().split())
    for j in si:
        s[i][j - 1] = 1
p = list(map(int, input().split()))
l = list(itertools.product([0, 1], repeat=n))
ans = 0
for i in l:
    for index, j in enumerate(s):
        if sum([x * y for x, y in zip(i, j)]) % 2 != p[index]:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include<iostream>

using namespace std;
int n;
int main(){
  while(1){
    int res=1,top=1,bot=6,north=5,east=3,south=2,west=4,temp=0;
    string str;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str;
      if(str=="North"){
	temp=top;
	top=south;
	south=bot;
	bot=north;
	north=temp;
	res+=top;
      }
      else if(str=="East"){
	temp=top;
	top=west;
	west=bot;
	bot=east;
	east=temp;
	res+=top;
      }
      else if(str=="West"){
	temp=top;
	top=east;
	east=bot;
	bot=west;
	west=temp;
	res+=top;
      }
      else if(str=="South"){
	temp=top;
	top=north;
	north=bot;
	bot=south;
	south=temp;
	res+=top;
      }
      else if(str=="Right"){
	temp=south;
	south=east;
	east=north;
	north=west;
	west=temp;
	res+=top;
      }
      else if(str=="Left"){
	temp=south;
	south=west;
	west=north;
	north=east;
	east=temp;
	res+=top;
      }
    }
    cout<<res<<endl;
  }
}

Measured memory_bytes: 1212