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


int main()
{
    int h,w;
    int sum=0;
    cin>>h>>w;
  
    int dist[10][10];
    int A[h][w];
    
    for(int i=0;i<10;i++)
    {
      for(int j=0;j<10;j++)
      {
         cin>>dist[i][j];
      }
    }
  
     for(int k=0;k<10;k++)
     {
       for(int i=0;i<10;i++)
       {
         for(int j=0;j<10;j++)
         {
             dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
         }
       }
     }
  

    for(int i=0;i<h;i++)
    {
       for(int j=0;j<w;j++)
       {
          cin>>A[i][j];
       }
    }
  
   for(int i=0;i<h;i++)
   {
     for(int j=0;j<w;j++)
     {
        if(A[i][j]!=-1)
        {
          int x=A[i][j];
          sum+=dist[x][1];  
        }
     }
   }
     

  cout<<sum<<endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const int MOD = 1000000007;

int main() {
  ll Ans = 0;  // 回答：

  ll N; cin >> N; // 元の個数
  ll K; cin >> K; // 最小選択数

  for(int i = K;i<=N+1;i++){
    Ans += i * ( N - i + 1 ) + 1;

  }


  Ans %= MOD;
  cout << Ans << endl;
}


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

using namespace std;

int main(void)
{
    int a[3];

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

    int count_f = 0,count_s = 0;
    for(int i = 0;i < 3;i++) {
	if(a[i] == 5)
	    count_f++;
	else if(a[i] == 7)
	    count_s++;
    }

    if(count_f == 2 && count_s == 1)
	cout<<"YES"<<endl;
    else
	cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;
long long a[100010];
pair<long long,long long> p[100010];
int main(){
	int i,j,n,m;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<m;i++){
		long long b,c;
		cin >> b >> c;
		p[i] = {c,b};
	}
	sort(a,a + n); sort(p,p + m);
	long long sum = 0;
	int now = 0;
	for(i=m-1;i>=0;i--){
		int cnt = p[i].second;
		for(j=now;j<n;j++){
			if(p[i].first>a[j]){
				a[j] = p[i].first;
				now = j + 1; cnt--;
				if(cnt==0) break;
			}else{
				break;
			}
		}
	}
	for(i=0;i<n;i++){
		sum += a[i];
	}
	cout << sum << endl;
}

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

struct Rect {
	int height;
	int pos;
	Rect(int height = 0, int pos = 0) : height(height), pos(pos) {}
};

int main()
{
	int h, w;
	while (scanf("%d %d", &h, &w), h){
		vector<vector<int> > grid( h + 1, vector<int>(w + 1) );
		for (int i = 1; i <= h; i++){
			for (int j = 0; j < w; j++){
				char c;
				scanf(" %c", &c);
				if (c == '.'){
					grid[i][j] += grid[i - 1][j] + 1;
				}
			}
		}
		
		int res = 0;
		for (int i = 1; i <= h; i++){
			stack<Rect> sta;
			for (int j = 0; j <= w; j++){
				Rect rect(grid[i][j], j);
				if (sta.empty()){
					sta.push(rect);
				}
				else if (sta.top().height < rect.height){
					sta.push(rect);
				}
				else if (sta.top().height == rect.height){
					continue;
				}
				else if (sta.top().height > rect.height){
					Rect t;
					while (sta.size() && sta.top().height >= rect.height){
						t = sta.top(); sta.pop();
						int width = j - t.pos;
						res = max(res, width * t.height);
						//printf("%d %d\n", width, t.height);
					}
					rect.pos = t.pos;
					sta.push(rect);
				}
			}
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 2100
package main

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	n, _ := strconv.Atoi(ReadString())
	return n
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func main() {
	n := readInt()
	as := readIntSlice(n)
	sort.Ints(as)
	tmp := make([]int, n)
	for i := 0; i < n; i++ {
		tmp[i] = as[n-1-i]
	}
	as = tmp
	var sum int
	for i := 1; i < n; i++ {
		if i == 1 {
			sum += as[0]
			continue
		}
		sum += as[i/2]
	}
	fmt.Println(sum)
}


Measured memory_bytes: 7472
s=str(input()[::-1])
word = ["maerd","esare","resare","remaerd"]
ans="YES"
i=0
while True:
    if i==len(s):
        break
    if s[i:i+5]==word[0]:
        i+=5
    elif s[i:i+5]==word[1]:
        i+=5
    elif s[i:i+6]==word[2]:
        i+=6
    elif s[i:i+7]==word[3]:
        i+=7
    else:
        ans="NO"
        break
print(ans)

Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll A,B;
  cin >> A >> B;
  
  if (B >= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
///                    BISMILLAHIR RAHMANIR RAHIM

int main()
{
  ll a,b,k,s,l;
   cin>>a>>b>>k;
   if(k<=a)
   {
       cout<<a-k<<" "<<b<<endl;
   }
   else
   {
       if((k-a)<=b)
       {
           cout<<"0"<<" "<<b-(k-a)<<endl;
       }
       else cout<<"0"<<" "<<"0"<<endl;
   }
}

/// A L H A M D U L I L L A H


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x =x->left;
    return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
    return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){

  if(k < u->key) u=u->left;

  else u=u->right;
  }
  return u;
  
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x=y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;
  if(y->parent==NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right =x;
  
  if(y!= z) z->key = y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  
}
void preorder(Node u){
  if(u ==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20496
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  int check=0;
  queue<long long> que;
  cin >> N;
  if(N == 2){
    cout << 1 << endl;
  }
  else{
  for(long long i=2;i*i <= N;i++){
    if(N % i == 0){
      que.push(i);
      if(i*i != N){
        que.push(N / i);
      }
    }
    if((N-1) % i == 0){
      que.push(i);
      if(i*i != N-1){
        que.push((N-1) / i);
      }
    }
  }
  while(!(que.empty())){
    long long n = N;
    long long num = que.front();
    que.pop();
    // cout << num << " ! " << endl;
    while(n % num == 0){
      n /= num;
    }
    if(n % num == 1){
      check++;
      //cout << num << endl;
    }
  }
  cout << check + 2 << endl;
}
}

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

using namespace std;

int main()
{
    long long N, M, K;
    vector<long long> A, B;

    cin >> N >> M >> K;
    A.resize(N + 1, 0);
    B.resize(M + 1, 0);
    int maxCountB = 0;
    int maxCountA = 0;
    for (int i = 1; i <= N; i++)
    {
        int a;
        cin >> a;
        A[i] = a + A[i - 1];
        if (A[i] <= K)
        {
            maxCountA = i;
        }
    }

    for (int i = 1; i <= M; i++){
        int b;
        cin >> b;
        B[i] = b + B[i - 1];
        if(B[i] <= K){
            maxCountB = i;
        }
    }
    int result = 0;
    for (int i = 0; i <= maxCountA; i++){
        for (int j = maxCountB; j >= 0; j--){
            if(A[i] + B[j] <= K){
                result = max(result, i + j);
                maxCountB = j;
                break;
            }
        }
    }
        cout << result << endl;
}

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

long gcd(long a, long b){
    long v0 = a, v1 = b, v2 = a%b;
    while(v2 != 0){
        v0 = v1;
        v1 = v2;
        v2 = v0%v1;
    }
    return v1;
}

int main() {
    long big = 1e6+100;
    long A, B;
    cin>>A>>B;
    long gcdab = gcd(A, B);
    bool isPrime[big];
    for(long i=0;i<big;++i){
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    isPrime[2] = true;
    for(long i=2;i<big;++i){
        if(isPrime[i]){
            for(long j=2;i*j<big;++j){
                isPrime[i*j] = false;
            }
        }
    }
    long ans = 1;
    for(long i=2;i<sqrt(gcdab);++i){
        if(isPrime[i]){
            if(gcdab % i==0){
                while(gcdab % i==0){
                    gcdab /= i;
                }
                ans++;
            }
        }
    }
    if(gcdab>1)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

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

    int N;
    cin >> N;

    list<int> a;
    for (int i = 0; i < N; i++) {
      int64_t c;
      cin >> c;
      if (i % 2 == 0) {
        a.push_back(c);
      } else {
        a.push_front(c);
      }
    }

    if (N % 2 == 1) {
      reverse(a.begin(), a.end());
    }

    for (auto i : a) {
      cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

double cross (double xa, double ya, double xb, double yb )
{
	return (xa*yb - xb*ya );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Parallelism", "r", stdin );
	int n;
	scanf ("%d", &n );
	rep (i, n ){
		double x1, y1, x2, y2, x3, y3, x4, y4;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		double d = cross (x2-x1, y2-y1, x4-x3, y4-y3 );
		if (fabs (d ) < EPS ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=998244353;

int main(){
    int n;cin>>n;
    vll a(n);rep(i,n)cin>>a[i];
    ll ans=(ll)0;
    rep(i,n-1){
        if(a[i]>a[i+1]){
            ans+=a[i]-a[i+1];
            a[i+1]=a[i];
        }
    }
    cout<<ans<<endl;
}

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


int main() {


    int x,y;
    cin>>x>>y;

    bool flg=false;
    for(int i=0;i<=100;i++){
      for(int j=0;j<=100;j++){
        if(i+j==x&&2*i+4*j==y){
          flg=true;
          break;
        }
      }
    }

    if(flg)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):

    N = len(S)
    ts = N
    for i in range(1, N):
        if S[i] != S[i-1]:
            ts = min(ts, max(i, N-i))
    print(ts)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

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

  int N, M, Q;
  cin >> N >> M >> Q;
  int imos[N+1][N+1];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      imos[i][j] = 0;
    }
  }

  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    imos[l][r]++;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      imos[i][j+1] += imos[i][j];
    }
  }

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    int ans = 0;
    for (int j = l; j <= r; j++) {
      ans += imos[j][r];
    }
    cout << ans << endl;
  }

}


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

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


	int N;
	cin >> N;
	int A[200000];
	rep(i, N) cin >> A[i];

	ll B[200001], C[200001];
	B[0] = 0;
	C[N] = 0;

	vector<int> V;
	ll mae = A[0];
	V.pb(0);
	rep(i, N) {
		ll a = A[i];
		B[i + 1] = B[i];
		if (mae >= a) {
			a *= 4;
			while (mae >= a) {
				V.pb(0);
				a *= 4;
			}
			V[(int)V.size() - 1]++;
		}
		else {
			while (mae < a) {
				int kari = V[(int)V.size() - 1];
				B[i + 1] += kari;
				if (V.size() > 1) {
					V.pop_back();
					V[(int)V.size() - 1] += kari;
				}
				mae *= 4;
			}
			V[(int)V.size() - 1]++;
		}
		mae = A[i];
	}
	V.clear();
	mae = A[N - 1];
	V.pb(0);
	for (int i = N - 1; i >= 0; i--) {
		ll a = A[i];
		C[i] = C[i + 1];
		if (mae >= a) {
			a *= 4;
			while (mae >= a) {
				V.pb(0);
				a *= 4;
			}
			V[(int)V.size() - 1]++;
		}
		else {
			while (mae < a) {
				int kari = V[(int)V.size() - 1];
				C[i] += kari;
				if (V.size() > 1) {
					V.pop_back();
					V[(int)V.size() - 1] += kari;
				}
				mae *= 4;
			}
			V[(int)V.size() - 1]++;
		}
		mae = A[i];
	}

	ll kotae = 1e18;
	rep(i, N + 1) {
		kotae = min(kotae, 2 * B[i] + 2 * C[i] + i);
	}
	co(kotae);

	Would you please return 0;
}

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

int main(){
  
  int i = 0,count = 0;
  string S;
  cin >> S;
  vector<char> S1(S.size() / 2);
  vector<char> S2(S.size() / 2);
  
  for(i;i < S.size() / 2;i++){
	if(S.at(i) != S.at(S.size() - (i + 1))){
		count++;
    }
  }
  cout << count << endl;
}

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

using namespace std;

typedef long long ll;

const ll mod = (ll)1e9+7;
const ll N = 4e5;
ll iv[N+1], f[N+1], f2[N+1];
ll nck(ll n, ll k){
    return f[n]*f2[n-k]%mod*f2[k]%mod;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    iv[1]=1;
    for(int i=2; i<=N; i++)
        iv[i]=mod-mod/i*iv[mod%i]%mod;
    f[0]=f2[0]=1;
    for(int i=1; i<=N; i++){
        f[i] = i*f[i-1]%mod;
        f2[i] = iv[i]*f2[i-1]%mod;
    }
    ll n, k;
    cin >> n >> k;
    ll ans = 2*mod+nck(2*n-1, n-1);
    for(int i=k+1; i<n; i++){
        ans -= (nck(n, i)*nck(n-1, n-i-1))%mod;
        ans %= mod;
        ans += 2*mod;
    }
    cout << ans%mod;
    return 0;
}


Measured memory_bytes: 9600
n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

sum_k = [0] * (n - k + 1)
pos_k = [0] * (n - k + 1)

pos_all = reduce(lambda x, y: x + y if y > 0 else x, a)

sum_k[0] = sum(a[:k])
pos_k[0] = reduce(lambda x, y: x + y if y > 0 else x, a[:k])

for i in range(1, n - k + 1):
	sum_k[i] = sum_k[i - 1] + a[i + k - 1] - a[i - 1]
	pos_k[i] = pos_k[i - 1] + (a[i + k - 1] if a[i + k - 1] > 0 else 0) - (a[i - 1] if a[i - 1] > 0 else 0)

result = 0

for i in range(n - k + 1):
	t = pos_all - pos_k[i] + (sum_k[i] if sum_k[i] > 0 else 0)
	if result < t:
		result = t

print result


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

int main() {
  int n;
  cin >> n;
  unordered_map<string, int> colors;

  for (int i = 0; i < n; i++) {
      string color;
      cin >> color;
      colors[color] = 1;
  }
  if (colors.size() == 3) {
      cout << "Three" << endl;
  } else if (colors.size() == 4) {
      cout << "Four" <<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int n, m;
	while(cin >> n, n) {
		int cnt[10] = {};
		rep(i,n) {
			cin >> m;
			cnt[m]++;
		}
		rep(i,10) {
			if(cnt[i]==0) cout << "-";
			else {
				rep(j,cnt[i]) cout << "*";
			}
			cout << endl;
		}
	}
}

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

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int total = 100 * r + 10 * g + b;

    string res = "NO";
    if (total % 4 == 0) {
        res = "YES";
    }

    cout << res << endl;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int a[200000];
int b[200000];
int main()
{
	int n,i;
	while(scanf("%d",&n)==1)
	{
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n;i++)
			b[i]=a[i];
		sort(a,a+n);
		int mid=n/2;
		for(i=0;i<n;i++)
		{
			if(b[i]<a[mid])
				printf("%d\n",a[mid]);
				else if(b[i]>=a[mid])
					printf("%d\n",a[mid-1]);
		}
	}
	return 0;
}


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

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

using namespace std;

int main() {
  int n;
  string s;
  std::cin >> n >> s;

  int x = 0, maxv = 0;
  rep(i, n) {
    if (s[i] == 'I') {
      x++;
    } else {
      x--;
    }
    maxv = max(maxv, x);
  }

  std::cout << maxv << std::endl;
  return 0;
}


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

int main() {
    // your code goes here
    long long n,i,ans=0,pb=5;
    cin >> n;
    if(n%2==1){
        cout << "0" << endl;
        return 0; 
    }
    n = n/2;
    while(pb<=n){
        ans+=((n-n%pb)/pb);
        pb = pb*5;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<char> S(N);
    for (int i = 0; i < N; i++){
        cin >> S.at(i);
    }
    vector<int> E(N,0);
    vector<int> W(N,0);
    for (int i = 0; i < N ; i++){
        if (i != N-1){
            W.at(i+1)=W.at(i);
            if(S.at(i)=='E') E.at(i)++;
            else W.at(i+1)++;
            E.at(i+1)=E.at(i);
        }
        else{
            if(S.at(i)=='E') E.at(i)++;
        }
    }
   
    int ans;
    int mans = N;
    int k;
    
    for (int i = 0; i < N; i++){
        ans = W.at(i) + (E.at(N-1) - E.at(i));
        
        if (mans > ans) mans = ans;
    }
    
    cout << mans << endl;
}

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

int main() {

	int n; cin >> n;
	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 = 0; i < n - 1; i++) {		
		sum += l[i];
	}

	if(l[n-1] < sum) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

void call(int n)
{
	int x;
	
	for(int i=1; i<=n; i++){
		x = i;
		if(x%3 == 0)
			cout << " " << i;
		else
			while(1){
				if(x%10 == 3){
					cout << " " << i;
					break;
				}
				else{
					x /= 10;
					if(x == 0)
						break;
				}
			}
	}
	cout << endl;
}

int main()
{
	int n;
	
	cin >> n;
	
	call(n);
	
	return 0;
}


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


int main(){
    int n; cin >> n;
    vector<int> x(n); vector<int> y(n);
    rep(i,n) cin >> x[i] >> y[i];
    auto dist = [&](int i, int j){
        double dx = x[i] - x[j];
        double dy = y[i] - y[j];
        return sqrt(dx*dx+dy*dy);
    };
    vector<int> p(n);
    rep(i,n) p[i] = i;
    double len=0;
    int cnt=0;
    do{
        rep(i, n-1){
            len +=dist(p[i], p[i+1]);
        }
        cnt++;
    } while (next_permutation(p.begin(), p.end()));
    double ans = len/cnt;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

def main():
    # input
    s = input()


    # calc
    temp = 1
    li = []
    if s[0]=='>':
        li.append(0)
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            temp += 1
        else:
            li.append(temp)
            temp = 1
    li.append(temp)
    if s[-1]=='<':
        li.append(0)

    # ans
    ans = 0
    temp = 0
    while temp < len(li):
        large = max(li[temp], li[temp+1])
        short = min(li[temp], li[temp+1])
        ans += large*(large+1)//2 + short*(short-1)//2
        temp += 2
    print(ans)


if __name__ == '__main__':
    main()


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

int a[505][505],b[300000][4];
int main()
{
    int n,m,cnt;
    cin>>n>>m;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                scanf("%d",&a[i][j]);
        cnt=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<m;j++)
            {
                if(a[i][j]&1)
                {
                    //a[i][j]--;
                    a[i][j+1]++;
                    b[cnt][0]=i;
                    b[cnt][1]=j;
                    b[cnt][2]=i;
                    b[cnt][3]=j+1;
                    cnt++;
                }
            }
        }
        for(int i=1;i<n;i++)
        {
            if(a[i][m]&1)
            {
               // a[i][m]--;
                a[i+1][m]++;
                b[cnt][0]=i;
                b[cnt][1]=m;
                b[cnt][2]=i+1;
                b[cnt][3]=m;
                cnt++;
            }
        }
        cout<<cnt<<endl;
        for(int i=0;i<cnt;i++)
        {
            for(int j=0;j<4;j++)
            {
                printf("%d%c",b[i][j],j==3?'\n':' ');
            }
        }


	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#define SENTINEL (1000000001)
#define putChar(c) ; *p = (c); ++p;

int c = 0;
int S[500000];
int L[250001];
int R[250001];
char str[5500010];
char *p = str;

static void Merge(int A[], int left, int mid, int right);
static void MergeSort(int A[], int left, int right);
static int getNum(void);
static void putNum(int n);

int main(void) {
	register int i;
	int n;
	
	fread(str, sizeof(char), 5500000, stdin);
	n = getNum();
	for (i = 0; i < n; ++i) {
		S[i] = getNum();
	}
	
	MergeSort(S, 0, n);
	
	--n;
	p = str;
	for (i = 0; i < n; ++i) {
		putNum(S[i]);
		putChar( ' ' );
	}
	putNum(S[i]);
	putChar( '\n' );
	
	putNum(c);
	putChar( '\0' );
	
	puts(str);

	return 0;
}

int getNum(void) {
	int n = 0;
	while ((*p >= '0') && (*p <= '9')) {
		n = n * 10 + (int)(*p - '0');
		++p;
	} 
	++p;
	return n;
}

void putNum(int n) {
	int d = n / 10;
	if (n < 10) {
		putChar( '0' + (char)n );
		return;
	}
	if (d) putNum(d);
	putChar( '0' + (char)(n % 10) );
}

void Merge(int A[], int left, int mid, int right) {
	int i = 0, j = 0, k = left;
	int n1 = mid - left;
	int n2 = right - mid;
	memcpy(L, A + left, n1 * sizeof(int));
	memcpy(R, A + mid, n2 * sizeof(int));
	L[n1] = R[n2] = SENTINEL;
	for (; k < right; ++k) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			++i;
		} else {
			A[k] = R[j];
			++j;
		}
	}
	c += k - left;
}

void MergeSort(int A[], int left, int right) {
	int mid;
	if (left + 1 >= right) {
		return;
	}
	mid = (left + right) >> 1;
	MergeSort(A, left, mid);
	MergeSort(A, mid, right);
	Merge(A, left, mid, right);
}

Measured memory_bytes: 9216
#include <stdio.h>

int main(void)
{
        int a=0,b=0,c=0;

        scanf("%d %d %d",&a,&b,&c);

        if(a < b && b < c){
                printf("Yes\n");
        }else{
                printf("No\n");
        }

        return 0;
}

Measured memory_bytes: 580
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int V = sc.nextInt();
        int E = sc.nextInt();
        int [][] List = new int[V][V];
        int [] list = new int[V];
        for(int [] L:List) Arrays.fill(L,0);
        Arrays.fill(list,0);
        for(int i=0;i<E;i++){
            int s = sc.nextInt();
            int t = sc.nextInt();
            List[s][t]=1;
            list[t]++;
        }
        ArrayList<Integer> L = new ArrayList<>();
        Deque<Integer> S = new ArrayDeque<>();
        for(int i=0;i<list.length;i++) if(list[i]==0) S.add(i);
        while(S.size()!=0){
            int v = S.poll();
            L.add(v);
            for(int i=0;i<V;i++){
                if(List[v][i]==1){
                    List[v][i]=0;
                    list[i]--;
                    if(list[i]==0)S.add(i);
                }
            }
        }
        for(int i:L) System.out.println(i);
    }
}


Measured memory_bytes: 557740
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int a[3][3];
	bool A[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
			A[i][j]=false;
		}
	}
	int n;
	cin>>n;
	vector<int>b(n);
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<n;k++){
				if(a[i][j]==b[k])A[i][j]=true;
			}
		}
	}
	bool ok=false;
	for(int i=0;i<3;i++){
		if(((A[i][0]&&A[i][1])&&A[i][2])){
			ok=true;
			break;
		}
	}
	for(int i=0;i<3;i++){
		if(((A[0][i]&&A[1][i])&&A[2][i])){
			ok=true;
			break;
		}
	}
	if(((A[0][0]&&A[1][1])&&A[2][2]))ok=true;
	if(A[0][2]&&A[1][1]&&A[2][0])ok=true;
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
L=[]
for i in range(n):
    x,y,h=map(int,input().split())
    L.append([x,y,h])
    if h!=0:
        Cx,Cy,Ch=x,y,h
for j in range(101):
    for k in range(101):
        H=Ch+abs(Cx-j)+abs(Cy-k)
        flag=True
        for l in L:
            if l[2]!=max(H-abs(l[0]-j)-abs(l[1]-k),0):
                flag=False
                break
        if flag:
            print(j,k,H)
            exit()

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

int main() {
  int n;
  cin >> n;
  vector<int>b(n);
  rep(i,0,n){
    cin >> b[i];
    b[i]--;
    if(b[i] > i){
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int>ans;
  while(b.size() > 0){
    for(int i = b.size()-1;i >= 0;i--){
      if(b[i] == i){
        ans.push_back(b[i]);
        b.erase(b.begin()+i);
        break;
      }
    }
  }
  for(int i = ans.size()-1;i >= 0;i--) cout << ans[i]+1 << endl;
}

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

using namespace std;

const int N = 100005;

int a[N], b[N], c[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &b[i]);
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &c[i]);
  }
  sort(c + 1, c + n + 1);
  long long res = 0;
  int l = 0, r = 0;
  for (int i = 1; i <= n; ++i) {
    while (l <= n && a[l] < b[i]) {
      ++l;
    }
    while (r <= n && c[r] <= b[i]) {
      ++r;
    }
    res += 1LL * (l - 1) * (n - r + 1);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    int A, B;
    cin >> A >> B;
    int res = A - B * 2;
    res = max(0, res);
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        String S = in.readLine();

        Integer a = Integer.parseInt(S.substring(0, 2));
        Integer b = Integer.parseInt(S.substring(2, 4));

        boolean yymm = false;
        boolean mmyy = false;
        if (1 <= b && b <= 12) {
            yymm = true;
        }
        if (1 <= a && a <= 12) {
            mmyy = true;
        }

        if(yymm && mmyy){
            System.out.println("AMBIGUOUS");
        }else if (yymm){
            System.out.println("YYMM");
        }else if (mmyy){
            System.out.println("MMYY");
        }else{
            System.out.println("NA");
        }


    }


    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (0 <= (y - r) && (y + r) <= H && 0 <= (x - r) && (x + r) <= W) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <queue>
#include <limits>	

using namespace std;

const long INFINITE = numeric_limits<long>::max();

struct v_type{
	int id;
	long d;
	v_type(int id): id(id), d(INFINITE){} 
	void display(){
		if(d == INFINITE){
			cout << "INF" << endl;
		}else{
			cout << d << endl;
		}
	}
};

class Graph{
	vector<v_type> v_list;
	vector<vector<pair<int, long>>> adj_list;
	int V;
	int E;
public:
	Graph(int V, int E, vector<pair<pair<int, int>, long>> edges){
		this->V = V;
		this->E = E;
		for(auto i = 0; i < V; ++i) v_list.push_back({i});
		adj_list = vector<vector<pair<int, long>>>(V, vector<pair<int, long>>());
		for(auto edge: edges){
			int src = edge.first.first;
			int dest = edge.first.second;
			long d = edge.second;
			adj_list[src].push_back({dest, d});
		}
	}

	void dijsktra(int r){
		v_list[r].d = 0.0;
		auto comp = [](v_type u, v_type v){ return u.d > v.d; };
		priority_queue<v_type, vector<v_type>, decltype(comp)> q(comp);
		q.push(v_list[r]);

		while(!q.empty()){
			v_type top = q.top();
			q.pop();
			int src = top.id;
			for(auto dest_p: adj_list[src]){
				int dest = dest_p.first;
				long d = dest_p.second;
				if(v_list[dest].d > v_list[src].d + d){
					v_list[dest].d = v_list[src].d + d;
					q.push(v_list[dest]);
				}
			}
		}
		for(auto i = 0; i < V; ++i) v_list[i].display();
	}
};

int main(){
	int V, E;
	int r;
	cin >> V >> E >> r;
	vector<pair<pair<int, int>, long>> edges;
	for(auto i = 0; i < E; ++i){
		int src, dest;
		long d;
		cin >> src >> dest >> d;
		edges.push_back({{src, dest}, d});
	}
	Graph g(V, E, edges);
	g.dijsktra(r);
}	


Measured memory_bytes: 33224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

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

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


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

  if (n % 2 == 0) {
    cout << n << endl;
  } else {
    cout << n * 2 << endl;
  }

  return 0;
}


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

int main() {string s,x,y;int q,t,f,b=0;cin>>s>>q;
            char c;
  for(int i=0;i<q;i++){
    cin>>t;if(t==1){b++;}
    else{cin>>f>>c;if((f+b)%2==1){x=c+x;}
         else{y=y+c;}}}
 if(b%2){reverse(s.begin(),s.end());
        reverse(x.begin(),x.end());
        reverse(y.begin(),y.end());
        cout<<y+s+x<<endl;}
else{cout<<x+s+y<<endl;}
    }

Measured memory_bytes: 1512
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    string S;
    cin>>S;
    set<char> s;
    for(int i=0;i<S.size();i++) s.insert(S[i]);
    
    if(S.size()!=26){
        char cha;
        for(cha='a';cha<='z';cha++) if(!s.count(cha)) break;
        cout<<S<<cha<<endl;
        return 0; 
    }else{
        vector<char> v;
        for(int i=0;i<26;i++) v.push_back(S[i]);
        if(next_permutation(v.begin(),v.end())){
            string t="";
            for(int j=0;j<v.size();j++){
                t+=v[j];
                if(v[j]!=S[j]) break;
            }
            cout<<t<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; ++i)
    cin >> h[i];
  sort(h.begin(), h.end());
  int ret = 1e+9;
  for (int i = 0, j = k - 1; j < n; ++i, ++j) {
    ret = min(ret, h[j] - h[i]);
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 640
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
    if s[i].startswith("M"):
        m = m + 1
    if s[i].startswith("A"):
        a = a + 1
    if s[i].startswith("R"):
        r = r + 1
    if s[i].startswith("C"):
        c = c + 1
    if s[i].startswith("H"):
        h = h + 1
march = [m, a, r, c, h]
choice = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            if i != j and i != k and j != k:
                choice = choice + march[i] * march[j] * march[k]
print(int(choice/6))

Measured memory_bytes: 9772
#include<iostream>
#include<map>
#include<vector>
using namespace std;
const int maxn = 100011;
int n, sz[maxn], id[maxn], g[maxn], top[maxn], up[maxn], pref[maxn], depth[maxn];
struct info{
	int v, c, w;
}par[maxn];
vector < info > edge[maxn];
map < int, pair < int, int > > val[maxn];
void operator += (pair < int, int > &a, pair < int, int > b){
	a.first += b.first;
	a.second += b.second;
}
pair < int, int > operator -(const pair < int, int > &a, const pair < int, int > &b){
	return {a.first - b.first, a.second - b.second};
}
int get_lca(int a, int b){
	while(g[a] != g[b])
		if(depth[top[g[a]]] < depth[top[g[b]]])b = up[g[b]];
		else a = up[g[a]];
	return depth[a] < depth[b] ? a : b;
}
void dfs1(int now, int last = 0){
	static int now_d = 0;
	depth[now] = now_d;
	++now_d;
	sz[now] = 1;
	if(last){
		for(int i = 0;i < edge[now].size();++i)
			if(edge[now][i].v == last){
				edge[now].erase(edge[now].begin() + i);
				break;
			}
	}
	for(int i = 0;i < edge[now].size();++i){
		dfs1(edge[now][i].v, now), sz[now] += sz[edge[now][i].v];
		(par[edge[now][i].v] = edge[now][i]).v = now;
		if(sz[edge[now][i].v] > sz[edge[now][0].v])swap(edge[now][i], edge[now][0]);
	}
	--now_d;
}
void dfs2(int now){
	static int x = 1;
	static int now_g = 0;
	id[now] = x++;
	g[now] = now_g;
	pref[id[now]] = par[now].w;
	val[par[now].c][id[now]] = {par[now].w, 1};
	if(!top[now_g])top[now_g] = now, up[now_g] = par[now].v;
	if(!edge[now].empty()){
		dfs2(edge[now][0].v);
		for(int i = 1;i < edge[now].size();++i)
			++now_g, dfs2(edge[now][i].v);
	}
}
inline void build(){
	for(int i = 1;i <= n;++i){
		pref[i] += pref[i - 1];
		for(auto it = val[i].begin();next(it) != val[i].end();++it){
			next(it)->second += it->second;
		}
	}
}
int get_w(int a, int stop){
	int res = 0;
	for(;g[a] != g[stop];a = up[g[a]])
		res += pref[id[a]] - pref[id[top[g[a]]] - 1];
	return res + pref[id[a]] - pref[id[stop]];
}
pair < int, int > get_c(int a, int stop, int c){
	pair < int, int > res = {0, 0};
	// cout << "get_c " <<a << ' ' << stop << '\n';
	for(;g[a] != g[stop];a = up[g[a]]){
		// cout << id[a] << ' ' << id[top[g[a]]]<< '\n';
		res += (prev(val[c].upper_bound(id[a]))->second - prev(val[c].lower_bound(id[top[g[a]]]))->second);
	}
	res += (prev(val[c].upper_bound(id[a]))->second - prev(val[c].upper_bound(id[stop]))->second);
	return res;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int q;
	cin >> n >> q;
	for(int i = 1;i <= n;++i)val[i][0] = {0, 0};
	for(int a, b, c, d, i = 1;i < n;++i){
		cin >> a >> b >> c >> d;
		edge[a].push_back({b, c, d});
		edge[b].push_back({a, c, d});
	}
	dfs1(1);
	dfs2(1);
	build();
	//for(int i = 1;i <= n;++i)cout << id[i] << ' ';cout << '\n';
	//for(int i = 1;i <= n;++i)cout << top[g[i]] << ' ';cout << '\n';
	pair < int, int > i, j;
	for(int x, y, a, b, lca, res;q--;){
		cin >> x >> y >> a >> b;
		lca = get_lca(a, b);
		res = get_w(a, lca) + get_w(b, lca);
		i = get_c(a, lca, x), j = get_c(b, lca, x);
		//cout << res << ' ';
		//cout << i.first <<' ' << i.second << ' ' << j.first << ' ' << j.second << '\n';
		cout << res - i.first - j.first + (i.second + j.second) * y << '\n';
	}
}


Measured memory_bytes: 33152
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    int n, cnt = 0;
    while(cin>>n){
        REP(i, 10){
            REP(j, 10){
                REP(k, 10){
                    REP(l, 10){
                        if(i+j+k+l == n)
                            cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
        cnt = 0;
    }
}


Measured memory_bytes: 2948
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

const string YES = "YES";
const string NO = "NO";

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
  vector<ll> v(N+1, 0);
  for(int i=0; i<M; i++) {
    v[a[i]]++;
    v[b[i]]++;
  }
  for(auto &x:v) {
    if(x%2!=0) {
      std::cout << NO << std::endl;
      return;
    }
  }
  std::cout << YES << std::endl;
  return ;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> a(M);
  std::vector<long long> b(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&a[i]);
    scanf("%lld",&b[i]);
  }
  solve(N, M, std::move(a), std::move(b));
  return 0;
}



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

int main(int argc, const char * argv[]) {
    int N,K,X,Y;
    cin >> N >>K >> X >> Y;
    
    long long ans ;
    if(N>K){
        ans = K*X + (N-K)*Y;
    }else{
        ans = N*X;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
//#define int long long
#define deb(x) cout<<#x <<" = "<<x<<"\n";
using namespace std; 

#define F first
#define S second

signed main() 
{
	//freopen("input.txt", "r", stdin);
	
	int a, b, c; cin>>a>>b>>c;
	cout<<max({ a*10 + b + c, b*10 + a + c, c*10 + a + b });
	
	
} 


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
#define pqasc priority_queue<long long, vector<long long>, greater<long long>>

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ul = unsigned long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int c,a,b; cin>>c>>a>>b;
  cout<<c*a/2<<endl;
  
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt(),y=sc.nextInt();
        sc.close();
        int gt=0;
        if(x<=3)gt+=(4-x)*100000;
        if(y<=3)gt+=(4-y)*100000;
        if(x==1&&y==1)gt+=400000;
        System.out.println(gt);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;




template< typename T >
pair< T, int > dfs(const WG< T > &g, int idx, int par) {
  pair< T, 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;
}

template< typename T >
T tree_diameter(const WG< T > &g) {
  auto p = dfs(g, 0, -1);
  auto q = dfs(g, p.second, -1);
  return (q.first);
}


main(){
  int n;
  cin>>n;
  WG<int> es(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    es[a].PB(edge<int>(b,1));
    es[b].PB(edge<int>(a,1));
  }

  int res=tree_diameter(es);

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

}


Measured memory_bytes: 33024
#include <iostream>

using namespace std;

int main() {
	int N, K;

	cin >> N >> K;

	long long a = 0, b = 0;
	for (int i = 1; i <= N; i++) {
		if (i % K == 0) a++;
		else if (i% K == K / 2) b++;
	}

	if (K % 2 == 0) cout << a * a * a + b * b * b << endl;
	else cout << a * a * a << endl;
	return 0;
}

Measured memory_bytes: 256