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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

char cad[N_MAX];

int main()
{
	ss(cad);
	int k;
	si(k);
	vector<char> ini, fin;
	int curr = 1; // String original
	while(k--)
	{
		int t, f;
		char c;
		si(t);
		if(t == 1)
			curr *= (-1);
		else
		{
			si(f);
			scanf(" %c", &c);
			if(f == 1)
			{
				if(curr == 1)
					ini.push_back(c);
				else
					fin.push_back(c);
			}
			else
			{
				if(curr == 1)
					fin.push_back(c);
				else
					ini.push_back(c);
			}
		}
	}
	int n = strlen(cad);
	if(curr == 1)
	{
		for(int i = ini.size() - 1; i >= 0; i--)
			printf("%c", ini[i]);
		for(int i = 0; i < n; i++)
			printf("%c", cad[i]);
		for(int i = 0; i < fin.size(); i++)
			printf("%c", fin[i]);
		printf("\n");
	}
	else
	{
		for(int i = fin.size() - 1; i >= 0; i--)
			printf("%c", fin[i]);
		for(int i = n-1; i >= 0; i--)
			printf("%c", cad[i]);
		for(int i = 0; i < ini.size(); i++)
			printf("%c", ini[i]);
		printf("\n");

	}
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int num[100];
  int flag=1,tmp,count=0;
  int N,i,j;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&num[i]);        
  while(flag){
    flag=0;
    for(j=N-1;j>0;j--){
      if(num[j]<num[j-1]){
	tmp=num[j];
	num[j]=num[j-1];
	num[j-1]=tmp;
	flag=1;
	count++;
      }
    }
  }
  for(i=0;i<N;i++){
    printf("%d",num[i]);
    if(i!=N-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

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

int main() {
  string s, t;
  
  cin >> s >> t;
  
  int change_count = 0;
  int string_length = s.length();
  for(int i = 0; i < string_length; ++i) {
    if(s[i] != t[i]) {
      ++change_count;
    }
  }
  
  cout << change_count << endl;
}

Measured memory_bytes: 3860
import kotlin.math.sqrt

fun main(args: Array<String>) {
    val n = readInt()
    val x = mutableListOf<Int>()
    val y = mutableListOf<Int>()
    repeat(n) {
        val (j, k) = readIntList()
        x.add(j)
        y.add(k)
    }

    val perm = permute((0 until n).toList())

    var ans = 0.0

    perm.forEach { order ->
        order.forEachIndexed { index, i ->
            if (index < n - 1) {
                val next = order[index + 1]
                ans += sqrt(((x[i] - x[next]) * (x[i] - x[next]) + (y[i] - y[next]) * (y[i] - y[next])).toDouble())
            }
        }
    }

    println(ans / perm.size)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> permute(list: List<T>): List<List<T>> {
    if (list.size == 1) return listOf(list)
    val perms = mutableListOf<List<T>>()
    val sub = list[0]
    for (perm in permute(list.drop(1)))
        for (i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, sub)
            perms.add(newPerm)
        }
    return perms
}

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

vector<int> bit;

void convert(int x){
  if(x == 0) return;
  convert(x/4);
  bit.push_back(x%4);
}

int main(){
  int n;

  while(1){
    bit.clear();
    cin >> n;
    if(n == -1) break;
    convert(n);

    if(bit.size()>0){
      for(int i = 0; i < bit.size(); i++){
	cout << bit[i];
      }
      cout << endl;
    }
    else {
      cout << "0" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  cin >> n;
  int alln = 1 << n;
  vi a(alln);
  rep (i, alln) {
    cin >> a[i];
  }
  auto b = a;
  for (int i = n-1; i >= 0; --i) {
    rep (j, (1 << i)) {
      int maxi = max(b[2*j], b[2*j+1]);
      int mini = min(b[2*j], b[2*j+1]);
      b[j] = maxi - mini;
    }
  }
  printf("%d\n", b[0]);

  return 0;
}


Measured memory_bytes: 2432
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define cn first
#define pn second.first
#define tn second.second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int m, t, p, r; cin >> m >> t >> p >> r, t;){
        vector<vi> wc = vector<vi>(t, vi(p, 0));

        vector< pair<int, pii> > res(t);
        rep(i, t) res[i].tn = (-1) * i;

        rep(i, r){
            int tid, pid, tm, msg; cin >> tm >> tid >> pid >> msg;
            tid--, pid--;

            if(msg == 0){
                res[tid].cn--;
                res[tid].pn += wc[tid][pid] * 20 + tm;
            }
            else{
                wc[tid][pid]++;
            }
        }

        sort(all(res));
        cout << res[0].tn * (-1) + 1;
        range(i, 1, t){
            if(res[i - 1].cn == res[i].cn &&
               res[i - 1].pn == res[i].pn){
                cout << "=";
            }
            else cout << ",";
            cout << res[i].tn * (-1) + 1;
        }
        cout << endl;
    }

	return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
long long a, b;
 
int main()
{
	b = 0;
	scanf("%lld", &a);
	for(long long i=1;i<=a;i++)
	{
		b = i * i;
		if(b > a){
			b=(i-1)*(i-1);
			break;
		}
	}
	printf("%lld\n", b);
	return 0;
}

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

int X, Y, Z, A[100005], B[100005], C[100005];
long long l_sum[100005], r_sum[100005];
vector<int> V;
priority_queue<int, vector<int>, greater<int> > PQ;

bool cmp(int a, int b) {
	return A[a] - B[a] > A[b] - B[b];
}

int main() {
	scanf("%d%d%d", &X, &Y, &Z);
	for (int i = 0; i < X+Y+Z; i++) scanf("%d%d%d", &A[i], &B[i], &C[i]);
	for (int i = 0; i < X+Y+Z; i++) V.push_back(i);
	sort(V.begin(), V.end(), cmp);
	long long total = 0;
	for (int i = 0; i < X+Y+Z; i++) total += C[i];
	long long sum = 0;
	for (int i = 0; i < X; i++) {
		sum += A[V[i]] - C[V[i]];
		PQ.push(A[V[i]] - C[V[i]]);
	}
	for (int i = X; i <= X+Y+Z; i++) {
		l_sum[i] = sum;
		sum += A[V[i]] - C[V[i]];
		PQ.push(A[V[i]] - C[V[i]]);
		sum -= PQ.top();
		PQ.pop();
	}
	while (!PQ.empty()) PQ.pop();
	sum = 0;
	for (int i = X+Y+Z-Y; i < X+Y+Z; i++) {
		sum += B[V[i]] - C[V[i]];
		PQ.push(B[V[i]] - C[V[i]]);
	}
	for (int i = X+Y+Z-Y; i >= 0; i--) {
		r_sum[i] = sum;
		if (i > 0) {
			sum += B[V[i - 1]] - C[V[i - 1]];
			PQ.push(B[V[i - 1]] - C[V[i - 1]]);
			sum -= PQ.top();
			PQ.pop();
		}
	}
	long long ans = -1000000000000000000ll;
	for (int i = X; i <= X+Y+Z-Y; i++) ans = max(ans, l_sum[i] + r_sum[i]);
	printf("%lld\n", total + ans);
}


Measured memory_bytes: 3448
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
  
  node(node* r,node* l,node* p,int k){
      right = r;
      left = l;
      parent = p;
      key = k;
  }
};

typedef struct node*  Node ;
class BinaryTree{
    private: Node NIL = NULL;
    public: Node root = NIL;
    
    Node treeMinimum(Node x){
        Node min = x -> left;
        while((min != NIL) && (min = x -> left));
        return min;
    }
    
    Node treeMaximum(Node x){
        Node max = x -> right;
        while((max != NIL) && (max = x -> right));
        return max;
    }
    
    Node treeSearch(Node u, int k){
        Node r = root;
        while(r != NIL){
            if(r -> key == k) return r;
            if(k < r -> key){
                r = r -> left;
            } else{
                r = r -> right;
            }
        }
        return NIL;
    }
    
    Node treeSuccessor(Node x){
    
    
    }
    
    void treeDelete(Node z){
      Node min;
      Node c;
      if(z -> right != NIL){
          min = treeMinimum(z -> right);
          if(min != z){
              swap(z -> key,min -> key);
              free(min);
          } else{
              min -> right = NIL;
          }
      } else{
          z -> left -> parent = z -> parent;
          z -> parent -> left = z -> left;
          free(z);
      }
    }
    
    void insert(int k){
      Node y = NIL;
      Node x = root;
      Node z;
    
      z = new node(NIL,NIL,NIL,k);
      while(x != NIL){
          y = x;
          if(k < x -> key){
              x = x -> left;
          } else{
              x = x -> right;
          }
      }
      z-> parent = y;
      
      if(y != NIL){
          if(k < y -> key){
              y -> left = z;
          } else{
              y -> right = z;
          }
        } else{
              root = z;
          }
      }
    
    
    void inorder(Node u){
        if(u -> left != NIL) inorder(u -> left);
        printf(" %d",u -> key);
        if(u -> right != NIL) inorder(u -> right);
    }
    void preorder(Node u){
        printf(" %d",u -> key);
        if(u -> left != NIL) preorder(u -> left);
        if(u -> right != NIL) preorder(u -> right);
    }
};

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  BinaryTree bt;
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      bt.insert(x);
    } else if ( com[0] == 'p' ){
      bt.inorder(bt.root);
      printf("\n");
      bt.preorder(bt.root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      bt.treeDelete(bt.treeSearch(bt.root, x));
    }
  }

  return 0;
}




Measured memory_bytes: 26560
fun main() {
    nextInt()
    val list = nextIntList()
    println(list.filterIndexed { index, i ->
        index % 2 == 0 && i % 2 == 1
    }.size)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 36264
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
	String S = sc.next();
   
	if(S.charAt(0)==S.charAt(1) && S.charAt(0)==S.charAt(2)){
      System.out.println("No");
    }else{
		System.out.println("Yes");
    }
}
}

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

int main(){
    int N;
    vector<int> A, B;
    cin >> N;
    for (int i = 0; i <= N; ++i){
        int a;
        cin >> a;
        A.push_back(a);
    }

    for (int i = 0; i < N; ++i){
        int b;
        cin >> b;
        B.push_back(b);
    }

    long long ans = 0;
    for (int i = N-1; i >= 0; --i){
        int r = min(A[i+1], B[i]);
        int l = min(A[i], B[i] - r);
        ans += r+l;
        A[i] -= l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))
    

    s = 0
    x = 0
    r = 0
    l = 0
    count = 0
    while 1:
        while  r < N and s + A[r] == x ^ A[r]:
            s += A[r]
            x ^= A[r]
            r += 1
            
        count += r - l
        s -= A[l]
        x ^= A[l]
        l += 1


        if l >= N:
            break

    print count


if __name__ == '__main__':
    main()

Measured memory_bytes: 27140
import math

n, m = map(int, input().split())

if abs(n-m) == 0:
    print((2* (math.factorial(n)%(1000000007))*(math.factorial(m)%(1000000007)))%1000000007)
elif abs(n-m) == 1:
    print(((math.factorial(n)%(1000000007))*(math.factorial(m)%(1000000007)))%1000000007)
else:
    print(0)


Measured memory_bytes: 4108
#include<stdio.h>

long long inp_c, i1, out_s;

long long inp_a[200005], pside[200005], mside[200005];

long long readNumber() {
	long long temp_func;
	scanf("%lld", &temp_func);
	return temp_func;
};
long long printNumber(long long temp_func) {
	printf("%lld ", temp_func);
	return 0;
};

long long additiver(const long long inp_nf) {
	
	return (inp_nf * (inp_nf - 1)) / 2;
	
};

int main() {
	
	inp_c = readNumber();
	
	for (i1 = 1; i1 <= inp_c; i1++) {
		
		inp_a[i1] = readNumber();
		
		if ((i1 + inp_a[i1] > 0) && (i1 + inp_a[i1] < 200000)) {
			
			pside[i1 + inp_a[i1]]++;
			
		};
		
		if ((i1 - inp_a[i1] > 0) && (i1 - inp_a[i1] < 200000)) {
			
			mside[i1 - inp_a[i1]]++;
			
		};
		
	};
	
	for (i1 = 1; i1 <= 200000; i1++) {
		
		out_s += pside[i1] * mside[i1];
		
	};
	
	printNumber(out_s);
	
}

Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to, cost; };
pair< int, int > dfs(const vector<vector<edge>> &g, int idx, int par) {
  pair< int, int > ret(0, idx);
  for(auto &e : g[idx]) {
    if(e.to == par) continue;
    auto cost = dfs(g, e.to, idx);
    cost.first += e.cost;
    ret = max(ret, cost);
  }
  return ret;
}

int tree_diameter(const vector<vector<edge>> &g) {
  auto p = dfs(g, 0, -1);
  auto q = dfs(g, p.second, -1);
  return (q.first);
}


signed main(){

  int n; cin >> n;
  vector<vector<edge>> G(n);
  for(int i = 0; i < n-1; i++){
    int s,t; cin >> s >> t;
    s--, t--;
    G[s].push_back({t,1});
    G[t].push_back({s,1});
  }

  int res = tree_diameter(G);
  if(res % 3 != 1){
    cout << "First" << endl;
  }else{
    cout << "Second" << endl;
  }

  return 0;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  int n;
  cin >> n;
  n--;
  
  int c[n] = {};
  int s[n] = {};
  int f[n] = {};

  for(int i=0;i<n;i++){
    cin >> c[i] >> s[i] >> f[i];
  }

  for(int i=0;i<n;i++){
    int time = s[i]+c[i];
    for(int j=i+1;j<n;j++){
      if(time<=s[j]){
        time = s[j]+c[j];
        continue;
      }
      else{
        int diff = time-s[j];
        if(diff%f[j]!=0){
        	time += f[j]-diff%f[j];
        }
        time += c[j];
      }
    }
    cout << time << endl;
  }

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



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

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

  sort(h.begin(),h.end());
  int ans = 1000000000;
  for (int i = 0; i <= N-K; i++) {
    ans = min(h.at(i+K-1) - h.at(i),ans);
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
l=[]    
acnt=0
wcnt=0
tcnt=0
rcnt=0
for _ in range(int(input())):
    l= list(map(str,input().split('\n')))
    for i in range(len(l)):
        if l[i]=='AC':
            acnt+=1
        elif l[i]=='WA':
            wcnt+=1
        elif l[i]=='TLE':
            tcnt+=1
        else:
            rcnt+=1
    
print("AC x "+str(acnt))
print("WA x "+str(wcnt))
print("TLE x "+str(tcnt))
print("RE x "+str(rcnt))

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define all(x) x.begin(),x.end()
#define int long long

/* 
ll exp(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}



int nCrModPFermat(int n, int r, int p)
{
   if (r==0)
      return 1;
    int fac[n+1];
    fac[0] = 1;
    for (int i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;
 
    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}
*/
/*struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
 
*/
 
/*vector<bool> sieve(100007,true);
 
void help(){
     sieve[0] = false;
     sieve[1] = false;
 
     for(int i=2;i*i<100007;++i){
        if(sieve[i]){
            for(int j=i*i;j<100007;j+=i)
                sieve[j] = false;
 
        }
     }
 
}*/
/*
ll expo(ll a,ll b){ll r=1;a=a%mod;while(b){if(b%2)r=(r*a)%mod;a=(a*a)%mod;b=b/2;}
return r;}
 
 
 */
 
 const int mod = 1000000007;
  const int N = 200009;
  
  

    int32_t main() {
     fastIO
     
     string s;
     cin>>s;

     for(int i=0;i<s.size();++i)
     {
        if(i&1)
        {
            if(s[i]=='R')
            {
                cout<<"No";
                return 0;
            }
        }
        else
        {
          if(s[i]=='L')
            {
                cout<<"No";
                return 0;
            }  
        }
     }

     cout<<"Yes";
     return 0;
      }
// always test the corner cases ALWAYS;

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long x[100000], dp[100001];
int main()
{
	long long n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	for(long long i = 0; i < n; ++i)
	{
		scanf("%lld", &x[i]);
		dp[i + 1] = 1 << 30;
	}
	for(long long i = 0; i < n - 1; ++i)
	{
		dp[i + 1] = dp[i] + min(a * (x[i + 1] - x[i]), b);
	}
	printf("%lld\n", dp[n - 1]);
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main() {
    string b;
    cin >> b;

    if(b == "A"){
        cout << "T";
    }
    if(b == "T"){
        cout << "A";
    }
    if(b == "C"){
        cout << "G";
    }
    if(b == "G"){
        cout << "C";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
using namespace std;
int input();
string IntToString(int);

int main() {
  int N=input();
  vector<string>W(N);
  char l;
  bool handan=true;
  for(int i=0;i<N;i++){
    cin>>W.at(i);
    if(i==0){
      l=W.at(i).at(W.at(i).length()-1);
    }else{
      if(W.at(i).at(0)!=l){
        handan=false;
      }else{
        l=W.at(i).at(W.at(i).length()-1);

      }
    }


  }
  
  bool x=true;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(W.at(i)==W.at(j)){
        x=false;
      }

    }
  }
  if(x&&handan){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }




  
  
  

  


}
int input(){
  int x;
  cin>>x;
  return x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int a, b;
    cin >> a >> b;
    vector<int> av;
    int ans = 0;
    for ( int i = a; i <= b; i++ ) {
        int tmp_a = i;
        av.clear();
        while(1) {
            if ( tmp_a == 0 ) break;
            av.push_back(tmp_a%10);
            tmp_a /= 10;
        }
//        rep(i, av.size()) cout << av[i];
//        cout << endl;
        bool ok = true;
        rep(j, av.size()/2 ) {
            if ( av[j] != av[av.size()-1-j] ) {
                ok = false;
                break;
            }
        }
        if ( ok ) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#ABC132 D
import math
def cmb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, K = map(int, input().split())
for i in range(K):
    try:
        print((cmb(N - K + 1, i + 1) * cmb(K - 1, i)) % ((10 ** 9) + 7))
    except:
        print(0)

Measured memory_bytes: 3316
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









const int N=1e5+10;
int n,n2,c[8];
char s[N];





void solve()
{
	for(int i=0;i<3;i++)c[i]=0;
	cin>>s;
	n=strlen(s);
	for(int i=0;i<n;i++)
	{
		c[s[i]-'a']++;
	}
	n2=n/3;
	for(int i=0;i<3;i++)
	{
		if(c[i]<n2||c[i]>n2+1)
		{
			cout<<"NO\n";
			return;
		}
	}
	cout<<"YES\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int b=0; b<N; b++){
        cin >> a[b];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    int ans = 0;
    for(int i=0; i<N; i++){
        if(i%2==0){
            ans += a[i];
        }else{
            ans -= a[i];
        }
    }
    cout << ans << endl;
}

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

namespace joi2019_yo_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            while (x[2] > 0)
            {
                x[2] -= x[0]; ret++;
                if (ret % 7 == 0) x[2] -= x[1];
            }
            Console.WriteLine(ret);
        }
    }
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int a, b;
  int v, w;
  cin >> a >> v;
  cin >> b >> w;
  int t;
  cin >> t;
  if (a < b && a + v * t >= b + w * t) {
    cout << "YES" << endl;
  } else if (a > b && a - v * t <= b - w * t) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,ans=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        long long int a;
        cin>>a;
        ans=lcm(ans,a);
    }
    cout<<ans;
}

Measured memory_bytes: 3556
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

int main()
{
    int n,k,m;
    k=0;
    scanf("%d",&n);
    m=n;
    while(n>0)
    {
        k+=n%10;
        n=n/10;
    }
    if (m%k==0) printf("Yes\n");
    else printf("No\n");
     return 0;
}


Measured memory_bytes: 256
import sys

class HashTable:
    def __init__(self, size):
        self.size = size
        self.table = [None for _ in range(size)]

    def get_char(self, ch):
        if ch == 'A':
            return 1
        elif ch == 'C':
            return 2
        elif ch == 'G':
            return 3
        elif ch == 'T':
            return 4

    def get_key(self, string):
        sum = 0
        p = 1
        for s in string:
            sum += self.get_char(s) * p
            p *= 5
        return sum

    def hash1(self, key):
        return key % self.size

    def hash2(self, key):
        return 1 + key % (self.size - 1)

    def insert(self, string):
        key = self.get_key(string)
        i = 0
        while True:
            h = (self.hash1(key) + i * self.hash2(key)) % self.size
            if self.table[h] is None:
                self.table[h] = string
                return
            elif self.table[h] == string:
                return
            i += 1

    def find(self, string):
        key = self.get_key(string)
        i = 0
        while True:
            h = (self.hash1(key) + i * self.hash2(key)) % self.size
            if self.table[h] == string:
                return True
            elif self.table[h] is None:
                return False
            i += 1

h = HashTable(1046527)
n = int(input())
for _ in range(n):
    cmd = sys.stdin.readline().split()
    if cmd[0] == 'insert':
        h.insert(cmd[1])
    elif cmd[0] == 'find':
        if h.find(cmd[1]):
            print('yes')
        else:
            print('no')



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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    cout<<a[n-1]-a[0]<<endl;
    return 0;
}


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

int main() {
    int x;
    cin >> x;
    int shimo2 = x%100, y = 5;
    int num = 0;
    while(shimo2) {
        if(shimo2/y > 0) {
            num += shimo2/y;
            shimo2 %= y;
        }
        y--;
    }
    if(x/100 >= num) cout << 1 << '\n';
    else cout << 0 << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c)){
		if(b-a==c-b){
			printf("YES\n");
		} 
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int x,y;
    scanf("%d %d",&x,&y);
    while(x!=0 || y!=0) {
        if(x<=y)
            printf("%d %d\n",x,y);
        else
            printf("%d %d\n",y,x);
        scanf("%d %d",&x,&y);
    }
    return 0;
}

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

int main()
{
  int A, B;
  cin >> A >> B;
  
  int x = A + B;
  int y = A - B;
  int z = A * B;
  
  int ans = max(max(x, y), z);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
	long long N,ans=0;
	cin >> N;
	for (long long i = 1; i <= ceil(sqrt(N))+5; i++)
	{
		if (N % i == 0&&N/i>i+1)ans += (N / i) - 1;
	}
	cout << ans;
}


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

lli fac[2000000], mod = 1000000007;

lli bigmod(lli a, lli b, lli m)
{
    lli gg = a%m;
    lli ret = 1;
    while(b){
        if(b%2){
            ret = (ret*gg) % m;
        }
        gg = (gg*gg) % m;
        b/=2;
    }
    return ret;
}

lli ncr(lli n, lli r)
{
    lli ret = (fac[n]*bigmod(fac[r], mod-2, mod))%mod;
    ret = (ret*bigmod(fac[n-r], mod-2, mod))%mod;
    return ret;
}


int main()
{
    fac[0] = 1;
    for(lli i=1; i<2000000; i++){
        fac[i] = (fac[i-1]*i)%mod;
    }
    lli x, y;
    cin >> x >> y;
    if((x+y)%3LL != 0LL){
        printf("0\n");
        return 0;
    }
    lli dif = abs(x-y);
    lli n = (x+y)/3LL;
    if(dif>n){
        printf("0\n");
        return 0;
    }
    lli r = ((dif+1)/2)+(n/2);

    lli ans = ncr(n, r);
    cout << ans << "\n";

    return 0;
}


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

typedef long long ll;
using namespace std;
int memo[100001][4];
int A[100001], B[100001], C[100001];
int get_val(int prev, int n) {
	if(prev==1) {
			return A[n];
	} else if(prev==2) {
			return B[n];
	} else if(prev==3) {
			return C[n];
	}
	return 0;
}

int calc(int n, int prev) {
	if(n==1) {
		return get_val(prev, n);
	}
	
	if(memo[n][prev]!=-1) {
		return memo[n][prev];
	}
	
	int mx = INT_MIN;
	for (int i=1; i<=3; i++) {
		if(i!=prev) {
			int val = get_val(prev, n);
			mx = max(mx, calc(n-1, i) + val);
		}
	}
	
	memo[n][prev] = mx;
	
	return memo[n][prev];
}

int main() {
 	int n;
 	cin>>n;
 	
 	for (int i=1; i<=n; i++) {
 		cin>>A[i] >>B[i] >>C[i];
 		memo[i][1] = -1;
 		memo[i][2] = -1;
 		memo[i][3] = -1;
 	}
 	
 	cout << calc(n+1, -1);
  	
	return 0;
}

Measured memory_bytes: 9216
#include<vector>
#include<cmath>
#include<complex>
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<float.h>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

int main(void){
	int N;
	cin >> N;
	N *= 2;
	vector<int> l(N);
	for(int i=0;i<N;i++) cin >> l[i];
	sort(l.begin(), l.end());
	int sum = 0;
	for(int i=N-2;i>=0;i-=2){
		sum += l[i];
	}
	cout << sum << endl;
	
	
	return 0;
}


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

int main(void){
    long N;
    scanf("%lu", &N);

    long min = pow(10, 12);
    for(long i=1; i<=sqrt((double)N)+1; i++){
        if(N%i == 0){
            long j = i - 1 + N/i - 1;
            if(j <= min) min = j;
        }
    }
    printf("%lu", min);

    return 0;

}

Measured memory_bytes: 128
from collections import deque
n, d, a = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(n)]
XH.sort()
# X:座標、 C:倒すための必要爆発回数
XC = [[x, (h - 1) // a + 1] for x, h in XH]
      
q = deque([])
accum_dmg = 0
ans = 0

for x, c in XC:
  # q[-][0]は爆発が届く右端の座標
  # 爆発が届いていない地点に来たら累積ダメージを減らす
  while q and x > q[0][0]:
    _, dmg = q.popleft()
    accum_dmg -= dmg
    
  cnt = max(0, c - accum_dmg)
  ans += cnt
  accum_dmg += cnt
  
  if cnt:
    q.append([x + 2 * d, cnt])
print(ans)

Measured memory_bytes: 86988
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
const int maxn = 200200;

void solve()
{
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b >> u;
    if (s == u) a--;
    if (t == u) b--;
    cout << a << ' ' << b << endl;
}


int main()
{
    int t;
    solve();
    return (0);
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double norm(const Point &p){ return dot(p,p); }

istream &operator >> (istream &is,Point &p){ 
  return is >> p.x >> p.y;
}

typedef Point Vector;

struct Line{
  Point s,t;
  Line(){}
  Line(Point s,Point t) : s(s),t(t) {}
};

Point projection(Line l,Point p){
  Vector b = l.t-l.s;
  double t = dot(p-l.s,b)/norm(b);
  return l.s+b*t;
}

Point reflection(Line l,Point p){
  return p+(projection(l,p)-p)*2.0;
}

int main(){
  Line l;
  int Q;
  Point p;
  cin >> l.s >> l.t >> Q;
  while(Q--){
    cin >> p;
    Point p2 = reflection(l,p);
    printf("%.10f %.10f\n",p2.x,p2.y);
  }
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, K;
int V[55];

int ans = 0 ;

int main() {
    ios_base::sync_with_stdio(false);

    cin >> N >> K;
    for(int i = 0; i < N; i++)
        cin >> V[i];

    for(int l = 0; l <= N; l++) {
        for(int r = 0; l + r <= N && l + r <= K; r++) {
            vector <int> s;
            for(int i = 0; i < l; i++)
                s.push_back(V[i]);
            for(int i = 0; i < r; i++)
                s.push_back(V[N - 1 - i]);
            sort(s.begin(), s.end());
            int sum = accumulate(s.begin(), s.end(), 0);
            for(int i = 0; i < s.size() && i < K - l - r; i++) {
                if (s[i] >= 0)
                    break;
                sum -= s[i];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)
#define ll long long
#define pb push_back

int n,m;

int main(){
	while(cin>>n>>m&&n){
		stack<int> A,B,C,X,Y,Z;
		int a,b,ans=INF;
		cin>>a;rep(i,a){cin>>b;X.push(b);}
		cin>>a;rep(i,a){cin>>b;Y.push(b);}
		cin>>a;rep(i,a){cin>>b;Z.push(b);}
		rep(i,2){
			if(i==0){A=X;B=Y;C=Z;}
			else{A=Z;B=Y;C=X;}
			int step=0;
			for(;;){
				if(step==m+1||A.size()==n||C.size()==n)break;
				if(B.empty()||!A.empty()&&A.top()>B.top()){
					B.push(A.top());
					A.pop();
				}
				else{
					A.push(B.top());
					B.pop();
				}
				step++;
				if(step==m+1||A.size()==n||C.size()==n)break;
				if(C.empty()||!B.empty()&&B.top()>C.top()){
					C.push(B.top());
					B.pop();
				}
				else{
					B.push(C.top());
					C.pop();
				}
				step++;
			}
			ans=min(ans,step);
		}
		cout<<(ans<=m?ans:-1)<<endl;
	}
}

Measured memory_bytes: 0
N = int(input())
s = []
for i in range(N):
    j = int(input())
    s.append(j)

s = sorted(s)
S = sum(s)
if S % 10 != 0:
    print(S)
else:
    for a in s:
        if a % 10 != 0:
            print(S - a)
            break
    else:
        print(0)


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



int main(){
    ll n,x;cin>>n>>x;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll mini[n];
    ll hoge[n];
    ll ans=inf;
    ll sum;
    rep(i,0,n-1){
        if(i==0){
            rep(j,0,n-1){
                mini[j]=a[j];
                hoge[j]=j;
            }
        }else{
            rep(j,0,n-1){
                if(mini[j]>a[(j-i+n)%n]){
                    mini[j]=a[(j-i+n)%n];
                    hoge[j]=(j-i+n)%n;
                }
            }
        }
        sum=0;
        rep(j,0,n-1){
            sum+=a[hoge[j]];
        }
        ans=min(ans,sum+i*x);
        
        
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void)
{
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);
    vector<vector<ll>> dp_cost(N+1, vector<ll>(N+1));
    for(int i=0;i<N;i++){
        cin >> H.at(i);
    }
    if(K==N){
        cout << 0;
        return 0;
    }
    for(int i=0;i<N;i++){
        dp_cost.at(1).at(i) = H.at(i);
    }
    for(int i=2;i<=N;i++){
        for(int j=i-1;j<N;j++){
            // 生き残っている数が1少ないところにjが加わる．i:生存数
            if(j==i-1){
                // すべて生き残っている
                if(j==0){
                    dp_cost.at(i).at(j) = H.at(j);
                }else{
                    dp_cost.at(i).at(j) = H.at(0);
                    for(int k=0;k<j;k++){
                        dp_cost.at(i).at(j) += max(0ll, H.at(k+1) - H.at(k));
                    }
                }
            }else{
                // 生き残っていないものもある．生存数が1小さいときと比べて自分が増えている
                ll min_v = dp_cost.at(i-1).at(i-1) + max(0ll, H.at(j) - H.at(i-1));
                for(int k=i-2;k<j;k++){
                    min_v = min(min_v, dp_cost.at(i-1).at(k) + max(0ll, H.at(j) - H.at(k)));
                }
                dp_cost.at(i).at(j) = min_v;
            }
        }
    }
    ll min_v = dp_cost.at(N-K).at(max(0, N-K-1));
    for(int i=max(0, N-K-1);i<N;i++){
        min_v = min(min_v, dp_cost.at(N-K).at(i));
    }
    // for(int i=0;i<5;i++){
    //     cout << "i=" << i;
    //     for(int j=0;j<5;j++){
    //         cout << dp_cost.at(i).at(j) << ", ";
    //     }
    //     cout << endl;
    // }
    
    cout << min_v;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
int n,a[100001];

int seach(int k){
  int L=0,M,R=n;
  while(L<R){
    M=(L+R)/2;
    if(a[M]>k) R=M;
    else L=M+1;
  }
  return L;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
  a[n]=1e9+1;
  int q,k,ans=0;
  cin>>q;
  while(q--) scanf("%d",&k),ans+=a[seach(k)-1]==k; 
  cout <<ans<<endl;   
}

Measured memory_bytes: 1632
#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
using ll = long long;

ll op(ll a, ll b) {
  return max(a, b);
}
ll e() {
  return 0;
}
int main () {
  int N, K;
  cin >> N >> K;
  segtree<ll, op, e> S(300001);

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    S.set(a, S.prod(max(a-K, 0), min(a+K+1, 300001)) + 1);
  }

  cout << S.prod(0, 300001) << endl;
}

Measured memory_bytes: 13812
#include<iostream>
#include<algorithm>
#define INF 1e6+5
using namespace std;

int main()
{
int n, c=0;
	int low=INF;
cin>>n;
while(n--)
{

	int p=0;
	cin>>p;
	if(p<low)
	{
		c++;
		low=p;
	}
}
cout<<c;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

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

	return 0;

}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

const int inf = 1001001000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int digitlen(int i){
    int t = i;
    int count = 0;
    while(t){
        count++;
        t /= 10;
    }
    return count;
}

int main(){
    int a,b;
    cin >> a >> b;
    a = a * pow(10, digitlen(b)) + b;
    for(int i = 0; i < sqrt(a)+1; i++){
        if(a == i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 256
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, a, b = ns()

    if n == 2:
        print(1)
        exit(0)

    if a > b:
        print(0)
        exit(0)

    if n==1:
        if a==b:
            print(1)
            exit(0)
        else:
            print(0)
            exit(0)

    minimum_sum = a * n + (b - a)
    maximum_sum = b * n - (b - a)
    print(maximum_sum - minimum_sum + 1)


if __name__ == '__main__':
    main()


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll W,n;
  cin >> n >> W;
  VLL w(n), v(n);
  rep(i,n){
    cin >>w[i] >> v[i];
  }

  VVLL dp(n+1,VLL(W+1,0));

  rep(i,n){
    //in
    rep(j,W+1){
      if(j+w[i] <= W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}


Measured memory_bytes: 80256
import sys
input=lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(200000)
mod=10**9+7
n=int(input())
edge=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
inf=10**6
Par=[inf]*n
Par[0]=-1
Chk=[0]
while Chk:
  c=Chk.pop()
  for next in edge[c]:
    if Par[next]==inf:
      Par[next]=c
      Chk.append(next)

C=[-1]*n
def ch(x):
  ret=0
  if x!=0 and len(edge[x])==1:
    C[x]=0
    return C[x]
  else:
    for e in edge[x]:
      if e==Par[x]:
        continue
      else:
        ret+=ch(e)+1
    C[x]=ret
    return C[x]
ch(0)

H=[0]*n
H[0]=1
H[1]=pow(2,mod-2,mod)
for i in range(2,n):
  H[i]=(H[i-1]*H[1])%mod

ans=0
for i in range(n):
  if len(edge[i])==1:
    continue
  else:
    A=[]
    for e in edge[i]:
      if e==Par[i]:
        A.append(n-1-C[i])
      else:
        A.append(C[e]+1)
    cur=1+(len(edge[i])-1)*H[-1]
    for a in A:
      cur-=H[n-1-a]
    ans=(ans+cur)%mod
print((ans*H[1])%mod)

Measured memory_bytes: 171064