akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define MAXN 100000
using namespace std;
typedef long long LL;
vector<int> G[MAXN+5];
int N,ans;
int cnt[MAXN+5][21];
void DFS(int u,int fa)
{
	for(int i=0;i<(int)G[u].size();i++)
	{
		int v=G[u][i];
		if(v==fa)
			continue;
		DFS(v,u);
		for(int j=0;j<20;j++)
			cnt[u][j]+=cnt[v][j];
	}
	int val=0;
	for(int i=20;i>=0;i--)
		if(cnt[u][i]>=2)
		{
			val=i+1;
			break;
		}
	while(cnt[u][val]==1)
		val++;
	ans=max(ans,val);
	cnt[u][val]++;
	for(int i=0;i<val;i++)
		cnt[u][i]=0;
}
int main()
{
//	freopen("uninity.in","r",stdin);
//	freopen("uninity.out","w",stdout);
	scanf("%d",&N);
	int u,v;
	for(int i=1;i<N;i++)
	{
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	DFS(1,-1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 20736
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    
    l[a-1] = max(l[a-1], h[b-1])
    l[b-1] = max(l[b-1], h[a-1])

result = 0
for j in range(n):
    if h[j] > l[j]:
        result += 1
print(result)


Measured memory_bytes: 19992
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    string s;
    cin >> s;
    int n = s.size();

    int one = 0;
    int zero = 0;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1')
        {
            one++;
        }
    }

    zero = n - one;
    int ans = min(zero, one);
    Cout(ans * 2);

    return 0;
}


Measured memory_bytes: 512
import scala.io.StdIn


object Main{
    def main(args: Array[String]) = {
        val tmp = StdIn.readLine.split(" ").map(_.toInt)
        val n = tmp(0)
        val q = tmp(1)
        var queue = new scala.collection.mutable.Queue[(String, Int)]
        for(i <- 0 to n-1){
            val a = StdIn.readLine.split(" ")
            queue += ((a(0), a(1).toInt))
        }
        
        calc(q, queue)
        ddd.foreach(f => println(f._1 + " " + f._2))
        
    }
    
    var count = 0
    var ddd = new scala.collection.mutable.Queue[(String, Int)]
    
    
    def calc(c: Int, q: scala.collection.mutable.Queue[(String, Int)]): Unit = {
        if(q.isEmpty) return
        val a = q.dequeue
        val v = a._2 - c
        if(v > 0){
          q += ((a._1, v));
          count = count + c
        } else{
          count = count + a._2;
          ddd += ((a._1, count));
        }
        
        
        calc(c, q)
        
    }
}


Measured memory_bytes: 109616
#include<bits/stdc++.h>
using namespace std;
int a,b,c,ans,x,y;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	x=min(a,min(b,c));
	if(x==a){
		y=min(b,c);
	}
	if(x==b){
		y=min(a,c);
	}
	if(x==c){
		y=min(b,a);
	}
	ans=x+y;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))

startPoint = 0
maxD = 0
for i in range(n - 1):
    if(abs(a[i] - a[i+1]) >= maxD):
        startPoint = i
        maxD = abs(a[i] - a[i+1])

maxD = max(k - a[-1] + a[0], maxD)

print(k - maxD)

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    vector<i32> a(9), u(9);
    for (auto& e : a) cin >> e;
    i32 n;
    cin >> n;
    for (i32 i = 0; i < n; i++) {
        i32 b;
        cin >> b;
        auto itr = find(begin(a), end(a), b);
        if (itr == end(a)) continue;
        i32 idx = distance(begin(a), itr);
        u[idx] = 1;
    }

    bool j = false;
    j |= u[0] && u[3] && u[6];
    j |= u[1] && u[4] && u[7];
    j |= u[2] && u[5] && u[8];
    j |= u[0] && u[1] && u[2];
    j |= u[3] && u[4] && u[5];
    j |= u[6] && u[7] && u[8];
    j |= u[0] && u[4] && u[8];
    j |= u[2] && u[4] && u[6];
    cout << (j ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
S = [["#"]*(W+2)] + [["#"] + [s for s in input()] + ["#"] for _ in range(H)] + [["#"]*(W+2)]

def search(sh,sw):

    if S[sh][sw] == "#":
        return -1
    ans = 0
    queue = [(sh,sw)]
    M = [[0]*(W + 2) for _ in range(H+2)]
    M[sh][sw] =  1

    while len(queue) > 0:
        h,w = queue.pop(0)
        if S[h + 1][w] == "." and M[h + 1][w] == 0:
            queue.append((h+1,w))
            M[h+1][w] = M[h][w] + 1
        if S[h - 1][w] == "." and M[h - 1][w] == 0:
            queue.append((h-1,w))
            M[h-1][w] = M[h][w] + 1
        if S[h][w + 1] == "." and M[h][w + 1] == 0:
            queue.append((h,w+1))
            M[h][w+1] = M[h][w] + 1
        if S[h][w - 1] == "." and M[h][w - 1] == 0:
            queue.append((h,w-1))
            M[h][w-1] = M[h][w] + 1
        
    for mm in M:
        ans = max(ans,max(mm))
    return ans-1


def main():
    ans = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            ans = max( ans, search(i,j) )
    print(ans)
    return 


if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    string s;
    cin >> n >> s;
    int l = 0;
    int r = 0;
    string ans = s;
    int r_accum_num = 0;
    int l_accum_num = 0;
    stack<char> st;
    rep(i, n) {
        if (st.empty()) st.push(s[i]);
        else if (st.top() == '(' && s[i] == ')') {
            st.pop();
        }
        else {
            st.push(s[i]);
        }
    }
    if (st.empty()) {
        cout << s << endl;
        return 0;
    }
    while(1) {
        if (st.empty()) break;
        if (st.top() == '(') ++l;
        if (st.top() == ')') ++r;
        st.pop(); 
    }
    ans = s;
    rep(i, l) ans += ')';
    rep(i, r) ans = '(' + ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.C
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			//decimal a = cin.NextLong();
			//string s = cin.Next();
			//decimal b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + s[3] - '0';
			//Console.WriteLine((long)Math.Floor((a * b) / 100));

			var a = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
			Console.WriteLine(Math.Floor(a[0] * a[1]));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

int main(){
  int n,m,i,j;
  cin >> n >> m;
  int a[101][101], b[101], c = 0;

  for(i = 1; i <= n; i++){
    for(j = 1; j <= m; j++){
      cin >> a[i][j];
    }
  }
  for(i = 1; i <= m; i++){
    cin >> b[i];
  }
  for(i = 1; i <= n; i++){
    for(j = 1; j <= m; j++){
      c += a[i][j] * b[j];
    }
    cout << c << endl;
    c = 0;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

#define NMAX 110
#define CMAX 1000000007
using namespace std;
typedef pair<int, int> pii;
int c[110][110] = {0};
int d[110][110] = {0};
int dist[110];
int path[110];

int Dijkstra(vector<int> *g, int s, int t){
    priority_queue<pair<int, pii>, vector<pair<int, pii> >, greater<pair<int, pii> > > q;
    q.push(make_pair(0, pii(s, s)));
    for(int i=0; i<NMAX; ++i){
        dist[i] = CMAX;
        path[i] = -1;
    }
    dist[s] = 0;
    int u, v, w;
    while(!q.empty()){
        u = q.top().second.second;
        v = q.top().second.first;
        w = q.top().first;
        dist[u] = min(dist[u], w);
        if(path[u] == -1)path[u] = v;
        q.pop();
        for(int i=0; i<g[u].size(); ++i){
            if(c[u][g[u][i]] && path[g[u][i]] == -1){
                q.push(make_pair(dist[u]+d[u][g[u][i]], pii(u,g[u][i])));
            }
        }
    }
    return dist[t];
}

int main(){
    // 逐次最短路法により最小費用流問題を解く．

    vector<int> g[NMAX], resig[NMAX];
    int u, v, s, t;
    int n, m, f;
    int x = 0, p[NMAX] = {0}, res = 0;
    int r[NMAX][NMAX] = {0}, e[NMAX][NMAX] = {0};
    cin>>n>>m>>f;
    for(int i=0; i<m; ++i){
        cin>>u>>v>>s>>t;
        c[u][v] = s;
        d[u][v] = t, d[v][u] = -t;
        r[u][v] = t, r[v][u] = -t;
        e[u][v] = 1, e[v][u] = -1;
        g[u].push_back(v);
        resig[u].push_back(v);
        resig[v].push_back(u);
    }

    int a, dx = 0, k;
    while(dx != f){
        if(Dijkstra(resig, 0, n-1) == CMAX){
            cout<<-1<<endl;
            return 0;
        }
        for(int i=0; i<n; ++i){
            p[i] -= dist[i];
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if(e[i][j])d[i][j] = r[i][j] + p[j] - p[i];
            }
        }
        a = f - dx;
        k = n-1;
        while(true){
            if(k == path[k]){
                break;
            }
            a = min(a, c[path[k]][k]);
            k = path[k];
        }

        k = n-1;
        while(true){
            if(k == path[k]){
                break;
            }
            c[k][path[k]] += a;
            c[path[k]][k] -= a;
            res += r[path[k]][k]*a;
            k = path[k];
        }
        dx += a;
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3368
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;

    cout << a[K-1] << endl;

    return 0;
}


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

using ll = long long;

const ll MOD = 998244353;

const int MAX_N = 100010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N, M, x, y;
    cin >> N >> M;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    init(N);
    rep(i, M) {
        cin >> x >> y;
        unite(x, y);
    }
    vector<pair<int, int>> b(N);
    int c = 0;
    map<int, bool> done;
    rep(i, N) {
        b[i] = make_pair(a[i], find(i));
        if (i == find(i)) {
            c++;
            done[i] = false;
        }
    }
    if (c == 1) {
        cout << 0 << endl;
        return 0;
    }
    sort(b.begin(), b.end());
    ll ans = 0;
    int j = 0, k = 0;
    rep(i, N) {
        if (done[b[i].second]) {
            if (k == c - 2) continue;
            else k++;
        } else j++;
        ans += b[i].first;
        done[b[i].second] = true;
    }
    if (j == c && k == c - 2) cout << ans << endl;
    else cout << "Impossible" << endl;
    //cout << c << j << k << ans << endl;
}

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

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007

using namespace std;

bool cmp(const pair<lli, lli> left, const pair<lli, lli> right) {
	return left.second > right.second;
}

lli f[1000000], rf[1000000];
lli inv(lli x) {
    lli res = 1;
    lli k = MOD - 2;
    lli y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    rep1(i, 1000000) f[i] = (f[i - 1] * i) % MOD;
    rep0(i, 1000001) rf[i] = inv(f[i]);
}
lli C(lli n, lli k) {
    lli a = f[n]; // = n!
    lli b = rf[n-k]; // = (n-k)!
    lli c = rf[k]; // = k!

    lli bc = (b * c) % MOD;

    return (a * bc) % MOD;
}

int main() {
    lli x,y;
    cin >> x >>y;

    lli m = (2*x-y)/3;
    lli n = x-2*m;
    if((2*x-y)%3 != 0 || m<0 || n<0){
        cout <<0;
        return 0;
    }
    init();
    cout << C(n+m,n); 


}

Measured memory_bytes: 15872
/*EX2_3
	L40S38*/

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,A ;
  scanf("%d\n",&N);//N*Nのマス目
  scanf("%d",&A);//Aマスを白く塗る
  cout << N*N-A << endl; 
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	ar := []rune{}
	result := 0
	for _, v := range s {
		if len(ar) > 0 && ar[len(ar)-1] != v {
			ar = ar[:len(ar)-1]
			result += 2
		} else {
			ar = append(ar, v)
		}
	}
	fmt.Println(result)
}

Measured memory_bytes: 3584
#include<stdio.h>

int main(void){
    int n,l;
    int sum=0;
    int ans;
    int i, j;
    scanf("%d",&n);
    scanf("%d",&l);
    for(i=1;i<=n;i++){
        sum = sum + l + i - 1;
    }
//    printf("sum=%d\n",sum);
    if(l  < 0 && l+n > 0){
        ans = sum;
    }
    if(l < 0 && l+n <= 0){
        ans = sum - (l + n - 1);
//        printf("aa\n");
    }
    if(l >= 0){
        ans = sum - l;
//        printf("ab\n");
    }
    printf("%d\n", ans);
    return 0;
    
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt(),k=sc.nextInt();
		long[] a=new long[n];
		long sum=0,count=0;
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
		}
		Arrays.parallelSort(a);
		for(int i=0;i<n-k;i++) {
			sum+=a[i];
		}
		//System.out.println(sum);

		System.out.println(sum);

	}

}


Measured memory_bytes: 64928
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long lint;
using namespace std;
#define INF 1e18
int A,B,Q;



int main()
{
	cin >> A >> B >> Q;
	vector<lint> s(A);
	vector<lint> t(B);
	vector<lint> x(Q);
	rep(i,A)cin>>s[i];
	rep(i,B)cin>>t[i];
	rep(i,Q)cin>>x[i];
	//=== 以上入力

	s.push_back(INF);
	t.push_back(INF);
	s.insert(s.begin(),-INF);
	t.insert(t.begin(),-INF);
	vector<lint> ans;
	

	for (auto now : x) {


		int bs = upper_bound(s.begin(), s.end(), now) - s.begin();
		int bt = upper_bound(t.begin(), t.end(), now) - t.begin();

		lint tmp = INF;

		vector<lint> kouho;
		// 一方向ですむばあい
		//kouho.push_back(max(s[bs],t[bt]) - now);
		//kouho.push_back(max(now - max(s[bs-1]),now - t[bt-1]));
	//	kouho.push_back(min(abs(now - s[bs]),abs(now - t[bt])));
		// もどったりする
		// 2 * 2の4通りみてみる

//		kouho.push_back(abs(max(t[bt],s[bs]) - now));
	//	kouho.push_back(max(abs(t[bt-1] - now) ,abs(now - s[bs-1])));



		rep(i,2) rep (j,2) {
			lint ti = t[bt + i-1];
			lint si = s[bs + j-1];
		//	kouho.push_back(abs(now - ti) + abs(ti - si));
		//	kouho.push_back(abs(now - si) + abs(si - ti));

			kouho.push_back(abs(ti - si) + abs(ti - now));
			kouho.push_back(abs(ti - si) + abs(si - now));
		}

		lint answ = INF;
		for (auto k : kouho) {
			//if (k < INF) answ = min(answ,k);
			answ = min(answ, k);
		}
	cout << answ << endl;
	}
	// 以下出力用
	//for (auto a:ans) cout << a << endl;
	return 0;
}

Measured memory_bytes: 3680
h, w = gets.split.map(&:to_i)

s = []
h.times do |i|
  s[i] = gets.split('')
end

BOM = '#'

result = []
h.times do |i|
  w.times do |j|
    if s[i][j] == BOM
      result[j] = BOM
    else
      array = []
      array << s[i-1][j-1] if i != 0 && j != 0
      array << s[i-1][j] if i != 0
      array << s[i-1][j+1] if i != 0 && j != w-1
      array << s[i][j-1] if j != 0
      array << s[i][j+1] if j != w-1
      array << s[i+1][j-1] if i != h-1 && j != 0
      array << s[i+1][j] if i != h-1
      array << s[i+1][j+1] if i != h-1 && j != w-1
      result[j] = array.count(BOM)
    end
  end
  puts result.join('')
end


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

using namespace std;

int main(){
  string s;
  cin >> s;
  int count=0;
  for(int i=0; i<3; i++){
    if(s[i]=='o')++count;
  }
  cout << 700+count*100;

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	int t1=0,t2=0;
	cin>>s;
	for(int i=0;i<3;i++)
	if(s[i]=='A')
	t1++;
	else
	t2++;
	if(t1==0||t2==0)
	printf("No");
	else
	printf("Yes");
    return 0;
}

Measured memory_bytes: 256
from collections import deque
a = deque(input())
b = deque(input())
c = deque(input())

tmp = a.popleft()
flag = 0
while flag == 0:
    if tmp == 'a':
        if len(a) == 0:
            print('A')
            flag = 1
            break
        else:
            tmp = a.popleft()
    elif tmp == 'b':
        if len(b) == 0:
            print('B')
            flag = 1
            break
        else:
            tmp =b.popleft()
    else:
        if len(c) == 0:
            print('C')
            flag = 1
            break
        else:
            tmp = c.popleft()

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

int main(){
    int N;
    cin >> N;
    int high = 0;
    vector<int> h(N);

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

    for(int i = 1; i < N ; i++){
        if(h[0] <= h[i] && high <= h[i]){
            high = h[i];
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
//作者：中国江苏南京朱泽齐
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	string s;
	cin>>s;
	int ans=0,sol;
	for(int i=0;i<=s.size();i++){
		if(s[i]=='A'){
			for(int j=s.size();j>i;j--){
				if(s[j]=='Z'){
					sol=j-i+1;
					break;
				}
			}
			ans=max(ans,sol);
		}
	}
	cout<<ans<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
	ll n, c, k, t[100000], ans = 0;
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++)cin >> t[i];
	sort(t,t+n);
	ll x = t[0] + k, y=1;
	for (int i = 1; i < n; i++) {
		if (x < t[i]) {
			if(y>0)ans++;
			x = t[i] + k;
			y = 1;
		}
		else {
			y++;
			if (y >= c) {
				ans++;
				if (i != n - 1)x = t[i + 1] + k;
				y -= c;
			}
		}
	}
	if (y > 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define crap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main() {
	crap;
	ll n,W;
	cin >> n >> W;
	ll wt[n],val[n];
	for( int i=0; i<n; i++ ){
	    cin >> wt[i] >> val[i];
	}
	ll dp[n+1][W+1];
	for( int i=0; i<=n; i++ ){
	    for( int j=0; j<=W; j++ ){
	        if( i==0 || j==0){
	            dp[i][j] = 0;
	        }
	        else if( wt[i-1] <= j ){
	            dp[i][j] = max( (val[i-1] + dp[i-1][j-wt[i-1]]), dp[i-1][j] );
	        }
	        else{
	            dp[i][j] = dp[i-1][j];
	        }
	    }
	}
	cout << dp[n][W];

	return 0;
}

Measured memory_bytes: 82444
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        map<int,int> m;
        map<string,vector<int>> d;
        string name;
        map<string,int> vote;
        rep(i,n){
            int k;
            cin >> name >> k;
            if(k == 0) vote[name] = 0;
            rep(j,k){
                int a;
                cin >> a;
                m[a]++;
                d[name].emplace_back(a);
            }
        }

        for(auto itd : d){
            //show(itd.first)
            for(auto itv : itd.second){
                vote[itd.first] += n - m[ itv ] + 1;
                //show(n - m[ itv ])
            }
        }

        int mini = 1e8;
        for(auto it : vote){
            if(mini > it.second){
                mini = it.second;
                name = it.first;
            }
        }
        cout << mini << ' ' << name << endl;
    }
}

Measured memory_bytes: 3120
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, H;
int A[100010], B[100010];

int solve() {
    int rest = H, cnt = 0;
    int dam = A[0];
    rep(i,0,N) {
        if(dam > B[i]) break;
        rest -= B[i];
        cnt++;
        if(rest <= 0) return cnt;
    }

    cnt += (rest + dam - 1) / dam;
    return cnt;
}
 
signed main() {
    cin >> N >> H;
    rep(i,0,N) {
        cin >> A[i] >> B[i];
    }
    sort(A, A+N, greater<int>());
    sort(B, B+N, greater<int>());

    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
str_to_int = {"W":0, "E":1}
input_ = input()
row = [str_to_int[input_[n]] for n in range(N)]

min_change_count = N+2

west_cum_sum = 0
east_cum_sum = 0
west_cum_sums = []
east_cum_sums = []
for n in range(N):
    if row[n] == 0:
        west_cum_sum += 1
    if row[N-n-1] == 1:
        east_cum_sum += 1
    west_cum_sums.append(west_cum_sum)
    east_cum_sums.append(east_cum_sum)
    
east_cum_sums = east_cum_sums[::-1]
    
min_count = min(east_cum_sums[1], west_cum_sums[N-2])
for n in range(1, N-1):
    count = west_cum_sums[n-1] + east_cum_sums[n+1]
    if count < min_count:
        min_count = count
        
print(min_count)

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

int main()
{
    std::string S,T;
    std::cin>>S>>T;
    int ans=0;
    for(int i=0;i<3;i++){
        if(S[i]==T[i]){ans++;}
    }
    std::cout<<ans<<std::endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var n int
	fmt.Scan(&n)
	t := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i])
	}
	for i := 0; i < n; i++ {
		ans = lcm(ans, t[i])
	}
	fmt.Println(ans)
	return
}

Measured memory_bytes: 1776
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

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

  bool flag = true;
  int num = 0;

  int r; cin >> r;
  int g; cin >> g;

  cout << 2 * g - r << endl;
  
  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
using namespace std;
string p[3];
int main(void){
    int n;cin>>n;
    set<string> st;
    for(int i=0;i<n;i++){
        cin>>p[0]>>p[1]>>p[2];
        sort(p,p+3);
        string s=p[0]+p[1]+p[2];
        st.insert(s);
    }
    cout<<n-st.size()<<endl;
    return 0;
}


Measured memory_bytes: 3336
a,b,c,d=map(int,input().split())
ans1=b//c-(a-1)//c
ans2=b//d-(a-1)//d

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
    
e=(c*d)//gcd(c,d)
ans3=b//e-(a-1)//e

ans=b-a+1-ans1-ans2+ans3

print(ans)

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B_011_50
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //new Logic_A().Start();
            new Logic_B().Start();
            Console.ReadLine();
        }

        public class Logic_B
        {
            public void Start()
            {
                var N = Convert.ToInt32(Console.ReadLine());
                var T = Console.ReadLine().Split(' ');
                var M = Convert.ToInt32(Console.ReadLine());
                var drinkList = new List<Drink>();

                for (int i = 0; i < M; i++)
                {
                    var S = Console.ReadLine().Split(' ');
                    var P = Convert.ToInt32(S[0]);
                    var X = Convert.ToInt32(S[1]);
                    drinkList.Add(new Drink() { p = P, x = X });
                }

                foreach (var drink in drinkList)
                {
                    var sumTime = 0;

                    for (int i = 0; i < T.Length; i++)
                    {
                        if (drink.p == i + 1)
                        {
                            sumTime += drink.x;
                        }
                        else
                        {
                            sumTime += Convert.ToInt32(T[i]);
                        }
                    }

                    Console.WriteLine(sumTime);
                }
            }

            public class Drink
            {
                internal int p;
                internal int x;
            }
        }

        public class Logic_A
        {
            public void Start()
            {
                var str = Console.ReadLine().Split(' ');
                var a = Convert.ToInt32(str[0]);
                var b = str[1];
                var c = Convert.ToInt32(str[2]);

                Console.WriteLine(b[0] == '+' ? a + c : b[0] == '-' ? a - c : 0);
            }
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define HORIZONTAL 1
#define VERTICAL 2
#define ALL 1+2+4+8+16
int main()
{
  int n,d,p,q;
  int num,block;
  while(cin>>n,n){
    vector<int>field;
    vector<int>::reverse_iterator it;
    queue<int>next;

    while(n-->0){
      cin>>d>>p>>q;
      if(d==HORIZONTAL){
	block=0;
	while(p-->0)block ^= 1<<(q+p-1);
	next.push(block);
      }else{
	block=1<<(q-1);
	while(p-->0)next.push(block);
      }
    }

    block=ALL;
    field.push_back(block);
    while(next.size()){
      block=next.front();
      next.pop();

      if(block==ALL)continue;

      if(field.back()&block){
	field.push_back(block);
	continue;
      }

      for(it=field.rbegin();it!=field.rend();it++){
	if(*it&block){
	  it--;
	  *it^=block;
	  if(*it==ALL){
	    it++;
	    field.erase(it.base());
	  }
	  break;
	}
      }
    }


    num=-5;
    for(it=field.rbegin();it!=field.rend();it++){
      for(int i=1;i<=16;i=i<<1){
	if(*it&i)num++;
      }
    }
    cout<<num<<endl;
  }
}

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

int main() {
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0; i < 4; i++) {
		if (s.at(i) == '2')ans++;
	}
	cout << ans << endl;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  string ans = "No";
  if (a == b && a != c) ans = "Yes";
  if (a == c && a != b) ans = "Yes";
  if (c == b && a != c) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  int ans=0;
  cin>>A>>B;
  if(A>B){
    ans+=A;
    A--;
    }
  else{
    ans+=B;
    B--;
  }
  ans+=max(A,B);
  cout<<ans<<endl;
  }

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

using namespace std;

using ll = long long;

int main(){

    ll d, t, s;
    cin >> d >> t >> s;
    cin.ignore();

    if(s * t >= d){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;


}

Measured memory_bytes: 3632
#include "stdio.h"

int main(void){
  int x,y,i,j,k;
  for(i = 0; i <10000;i++){
    scanf("%d %d", &x, &y);
    if((x == 0) && (y == 0))break;
    for(k = 0; k < x; k++){
      for(j = 0; j < y; j++){
        if(((k+j)%2) == 0){
          printf("#");
        }else{
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
}



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
int a,b,n;
  cin >> a >> b;
  n = (b - 1) / (a - 1);
  if((b - 1) % (a - 1) != 0)
  {
    n++;
  }
  
  cout << n << endl;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 200100;
//#define int long long
const int INF = 1e9;

const ll MOD = (ll)1e9 + 7LL;

ll mult(ll a, ll b){
  return (a * b) % MOD;
}

ll add(ll a, ll b){
  return (a + b) % MOD;
}

ll f[MAXN];
void precalc(){
  f[0] = 1LL;
  for (int i = 1; i < MAXN; i++){
    f[i] = mult(f[i-1], i);
  }
}

ll binpow(ll a, ll b){
  ll res = 1LL;
  while (b){
    if (b & 1LL) res = mult(res, a);
    a = mult(a, a);
    b >>= 1LL;
  }
  return res;
}

ll cnk(ll k, ll n){
  //f[n] / f[k] / f[n-k]
  ll fk = binpow(f[k], MOD-2LL);
  ll fnk = binpow(f[n-k], MOD-2LL);
  return mult(f[n], mult(fk, fnk));
}

void solve(){
  precalc();
  ll h, w, a, b;
  cin >> h >> w >> a >> b;

  ll ans = 0LL;
  for (int i = b; i < w; i++){
    ll res = mult(cnk(h-a-1, i+h-a-1), cnk(a-1, a+w-i-2));
    //cerr <<cnk(h-a-1, i+h-a-1) << ' ' << cnk(a-1, a+w-i-2) <<' '<< res << '\n';
    ans = add(ans, res);
  }
  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 5200
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N;
	cin>>N;
	while(N--){
		int out=0,fld[4]={},score=0;
		string S;
		while(out<3){
			cin>>S;
			if(S=="HIT"){
				for(int i=3;i>=0;i--) fld[(i+1)%4] = fld[i];
				fld[1] = 1;
				score += fld[0]; fld[0] = 0;
			}
			else if(S=="HOMERUN"){
				fld[0] = 1;
				for(int i=0;i<=3;i++){
					score += fld[i];
					fld[i] = 0;
				}
			}
			else out++;
		}
		printf("%d\n",score);
	}
    return 0;
}

Measured memory_bytes: 1220
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def maximal_rectangle(H):
    """ヒストグラムに対して、極大長方形を計算。
    各 i に対して、[l,r) が高さ H[i] となるような l, r を計算する。
    アリ本 p.299～p.300
    """
    N = len(H)
    L = np.empty(N, np.int32)
    R = np.empty(N, np.int32)
    st = np.zeros(N, np.int32)
    # 左端の計算
    t = 0
    for i in range(N):
        while t and H[st[t - 1]] >= H[i]:
            t -= 1
        L[i] = 0 if t == 0 else st[t - 1] + 1
        st[t] = i
        t += 1
    # 右端の計算
    t = 0
    for i in range(N - 1, -1, -1):
        while t and H[st[t - 1]] >= H[i]:
            t -= 1
        R[i] = N if t == 0 else st[t - 1]
        st[t] = i
        t += 1
    return L, R

signature = '(i8[:],)'
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('maximal_rectangle', signature)(maximal_rectangle)
    cc.compile()

from my_module import maximal_rectangle

A = np.array(read().split(), np.int64)[1:]

N = len(A)
L, R = maximal_rectangle(A)
coef = (np.arange(N) - L + 1) * (R - np.arange(N))
x = np.sum(coef * A)
print(x)

Measured memory_bytes: 39708
import Text.Printf

solve :: Int -> Int ->[(Int,Int,Int)]
solve n yen =
   [(x,y,n-x-y)| x<-[0..n], y<-[0..n-x], x*10000+y*5000+(n-x-y)*1000==yen]

print3 (x,y,z)=
  printf "%d %d %d\n" x y z
  
main = do
  [n, yen] <- map read . words <$> getLine :: IO [Int]
  let anss = solve n yen 
  print3 $ if null anss then (-1,-1,-1) else head anss




Measured memory_bytes: 764
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	sum := 0
	var a [3]int
	for i := 0; i < 3; i++ {
		a[i] = nextInt()
		sum += a[i]
	}

	if sum%2 != 0 {
		fmt.Println("No")
	} else {
		half := sum / 2
		is_half_exist := false
		for i := 0; i < 3; i++ {
			if a[i] == half {
				is_half_exist = true
				break
			}
		}
		if is_half_exist {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 640
while True:
    s = input()
    if s == "0":
        break
    L = list(s)
    P = [0]*2
    for i in range(len(L)-1):
        if L[i+1] == "A":
            P[0] += 1
        else:
            P[1] += 1

    if P[0] > P[1]:
        P[0] += 1
    else:
        P[1] += 1
    
    print(*P)
    


Measured memory_bytes: 5556
import sys
input=sys.stdin.readline
def calc(k):
    ret=0
    for a,b in AB:
        if a|k==k:
            ret+=b
    return ret

n,k=map(int,input().split())
AB=[tuple(map(int,input().split())) for _ in range(n)]
ans=calc(k)
b=k.bit_length()
for d in range(1,b):
    tmp=k>>d
    if tmp%2==0:
        continue
    tmp<<=d
    tmp-=1
    ans=max(ans,calc(tmp))
print(ans)

Measured memory_bytes: 54492
#include<stdio.h>
void printFrame(int,int);
int main(void)
{
  int w,h;
  for(;;)
    {
      scanf("%d%d",&h,&w);
      if(h==0&&w==0) break;
      printFrame(h,w);
    }
  return 0;
}
void printFrame(int h,int w)
{
  int i,j;
  for(i=0;i<h;i++)
    {
      for(j=0;j<w;j++)
        {
          if(i==0||i==h-1||j==0||j==w-1) printf("#");
          else printf(".");
        }
      printf("\n");
    }
  printf("\n");
}



Measured memory_bytes: 1984
N = int(input())
A = list(map(int,input().split()))

ans = 1000
diff = [0 for _ in range(N)]

for i in range(1, N):
    if A[i] == A[i - 1]:  diff[i] = 0
    elif A[i] > A[i - 1]: diff[i] = 1
    else:  diff[i] = -1

money = 1000
kabu = 0

for i in range(1, N):
    if kabu == 0:
        if diff[i] == 1:
            kabu = money // A[i - 1]
            money -= A[i - 1] * kabu
    else:
        if diff[i] == -1:
            money += kabu * A[i - 1]
            kabu = 0
    
    ans = max(ans, money)

money += kabu * A[-1]
ans = max(ans, money)

print(ans)

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

using namespace std;

set<int> base;

struct UnionFind {
  vector<int> data;
  UnionFind(int n):data(n, -1){}
  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return;
    //if(data[x] < data[y]) swap(x, y);
    if(!base.count(x)) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }
};

struct edge {
  int from, to, cost;
  edge(){}
  edge(int from, int to, int cost):from(from), to(to), cost(cost){}
  bool operator < (const edge& e) const {
    return cost > e.cost;
  }
};

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;

vector<edge> es;

int main() {
  int n, t, k;
  int T = 0;
  while(cin >> n >> t >> k, n || t || k) {
    base.clear();
    es.clear();
    for(int i = 0; i < n-1; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      es.emplace_back(a, b, c);
    }
    UnionFind uf(n);
    for(int i = 0; i < t; i++) {
      int d; cin >> d; --d;
      base.insert(d);
    }
    vector<int> ans;
    sort(es.begin(), es.end());
    for(int i = 0; i < n-1; i++) {
      for(edge& e : es) {
	if(!uf.same(e.from, e.to)) {
	  int x = uf.find(e.from), y = uf.find(e.to);
	  if(base.count(x) && base.count(y)) {
	    ans.push_back(e.cost);
	  }
	  uf.unite(x, y);
	}
      }
    }
    sort(ans.begin(), ans.end());
    int total = 0;
    for(int i = 0; i < k; i++) total += ans[i];
    cout << "Case " << ++T << ": " << total << endl;
  }
  return 0;
}

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

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

using namespace std;

const int IINF = INT_MAX;
int n,m,dp[1<<15],cost[1<<15],memory[1<<15],b[15],a[15];

int main(){
  while( cin >> n >> m, n|m ){
    rep(i,n) cin >> b[i] >> a[i];
    rep(i,(1<<n)) dp[i] = IINF;
    rep(i,(1<<n)) {
      memory[i] = m,cost[i] = 0;
      rep(j,n)if( (i>>j) & 1){
	memory[i] += b[j];
	cost[i]   += a[j];
      }
      memory[i] -= cost[i];
      assert( memory[i] >= 0 );
    }

    dp[0] = 0;
    rep(used,(1<<n))if(dp[used]!=IINF){
      rep(chose,(1<<n))if( !(used&chose) && ( cost[chose] <= memory[used] ) ){
	dp[used|chose] = min(dp[used|chose],dp[used]+1);
      }
    }
    if( dp[(1<<n)-1] == IINF ) puts("Impossible");
    else cout << dp[(1<<n)-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1364
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int N = int.Parse(strs[0]);
            int Q = int.Parse(strs[1]);

            string s = Console.ReadLine();

            int[] amount = new int[N];
            amount[0] = 0;
            for (int i = 1; i < N; i++)
            {
                if (s[i - 1] == 'A' && s[i] == 'C')
                {
                    amount[i] = amount[i - 1] + 1;
                }
                else
                {
                    amount[i] = amount[i - 1];
                }
            }

            for (int i = 0; i < Q; i++)
            {
                strs = Console.ReadLine().Split(' ');
                int l = int.Parse(strs[0]);
                int r = int.Parse(strs[1]);
                l--;
                r--;

                Console.WriteLine(amount[r] - amount[l]);
            }
        }
    }
}

Measured memory_bytes: 16324
import java.util.*;
import java.io.*;
import java.math.*;

class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String s = in.next();
		if(s.matches("a|e|i|o|u")){
			System.out.println("vowel");
		}else{
			System.out.println("consonant");
		}
	}
}

Measured memory_bytes: 23508
import java.util.*;
public class Main {
    public static void main(String[] args) {
        int val;
        Scanner sc = new Scanner(System.in);

        int r = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());

        for (int i = 0; i < 10; i++) {
            x = r * x - D;
            System.out.println(x);
        }
    }
}

Measured memory_bytes: 21716
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();

		if (A == 1)
			A = 14;
		if (B == 1)
			B = 14;

		if (A > B) {
			System.out.println("Alice");
		} else if (A == B) {
			System.out.println("Draw");
		} else {
			System.out.println("Bob");
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27120
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,m;
    cin >> n >> m;
    vector<int> v(m);
    rep(i,m) cin >> v[i];
    vector<int> dis;
    sort(v.begin(),v.end());
    rep(i,m-1){
        dis.push_back(abs(v[i]-v[i+1]));
    }
    ll ans = 0;
    sort(dis.begin(),dis.end());
    rep(i,(int)dis.size()-n+1){
        ans += dis[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1276