akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n,m,x,y;
  std::vector<int> xx;
  std::vector<int> yy;

  cin >> n >> m >> x >> y;

  for (int i = 0; i < n; i++) {
    int xi;
    cin >> xi;
    xx.push_back(xi);
  }
  xx.push_back(x);

  for (int i = 0; i < m; i++) {
    int yi;
    cin >> yi;
    yy.push_back(yi);
  }
  yy.push_back(y);

  sort(xx.begin(), xx.end());
  sort(yy.begin(), yy.end());

  if (xx[n] < yy[0])
    cout << "No War";
  else
    cout << "War";

  return 0;
}

Measured memory_bytes: 256
import bisect

def main():
    n = int(input())
    l = sorted(list(map(int, input().split())))
    count = 0
    for i in range(n-2):
        a = l[i]
        for j in range(i+1, n-1):
            b = l[j]
            kmax = bisect.bisect_left(l, a+b)
            #print("k", kmax, "j", j, "k-j", kmax-(j+1), a, b)
            count += max(kmax-(j+1),0)
    print(count)
    
if __name__ == "__main__":
    main()

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int A, B, C; cin >> A >> B >> C;
	cout << min(B / A, C) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	int n;
	cin>>n;
	int *a=new int[n];
	int sum=0;
	int sum2=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%4==0){
			sum++;
		}
		else if(a[i]%2==0){
			sum2++;
		}
	}
	if(sum>=n/2){
		cout<<"Yes"<<endl;
	}
	else if(sum+sum2/2>=n/2&&sum2>=2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, k, i;
    cin >> n >> k;
    vll a(n);
    vll dp(k + 1, 1);
    for(i = 0; i < n; i++)
    {
        cin >> a[i];
        dp[a[i]] = 0;
    }
    vll pre(k + 1, 0);
    for(i = 1; i <= a[0]; i++)
        pre[i] = pre[i - 1] + dp[i];
    for(i = 1; i <= k; i++)
    {
        dp[i] = 1;
        ll index = upper_bound(all(a), i) - a.begin() - 1;
        for(ll j = 0; j <= index; j++)
            if(dp[i - a[j]])
                dp[i] = 0;
    }
    (!dp[k]) ? cout << "First\n" : cout << "Second\n";
    return 0;
}

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

int main(void){
	char number[1001];
	int i, sum=0;
	
	while(1){
		scanf("%s", number);
		if(number[0] == '0'){
			break;
		}
		for(i=0; i<strlen(number); i++){
			sum += number[i] - '0';
		}
		printf("%d\n", sum);
		sum = 0;
	}	
	return 0;
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  for (int i = 0; i < N; i++)
    cin >> x.at(i);
  for (int i = 0; i < M; i++)
    cin >> y.at(i);
  int xmax=-100, ymin=100;
  for (int i = 0; i < N; i++)
    xmax = max(xmax, x.at(i));
  for (int i = 0; i < M; i++)
    ymin = min(ymin, y.at(i));
  if (max(X, xmax) < min(Y, ymin))
    cout << "No War" << endl;
  else
    cout << "War" << endl;
  return 0;
}



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

int main(void){
	char a[220],b[110];
	int Na,Nb,i,j,k;
	scanf("%s %s",a,b);
	Na=strlen(a);
	Nb=strlen(b);
	for(i=0;i<Na;i++){
		a[i+Na]=a[i];
	}
	for(j=0;j<2*Na;j++){
		if(a[j]==b[0]){
			for(k=0;k<Nb;k++){
				if(a[j+k]!=b[k])break;
				if(k==Nb-1){
					printf("Yes\n");
					goto last;
				}
			}
		}
		if(j==2*Na-1){
			printf("No\n");
		}
	}
	last:;
	return 0;
}

Measured memory_bytes: 524
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		float max = Float.MIN_VALUE;
		float min = Float.MAX_VALUE;

		while ((line = br.readLine()) != null) {
			float altitude = Float.parseFloat(line);

			if (altitude > max)
				max = altitude;
			else if (altitude < min)
				min = altitude;
		}
		System.out.println(max - min);
	}
}

Measured memory_bytes: 17044
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 9;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

int main() {
	file_read();
	LL D, T, S;
	cin >> D >> T>> S;
	if(S*T >= D) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    int i;
    for(i=0;i<n;i++)
        cin >> a[i];
    
    int alice=0,bob=0;
    sort(a,a+n);
    int j=0,k=1;
    if(n%2==0){
        while(j<=n-1){
            bob += a[j];
            j += 2;
        }
        while(k<=n-1){
            alice += a[k];
            k += 2;
        }
        
    }else{
        while(j<=n-1){
            alice += a[j];
            j += 2;
        }
        while(k<=n-1){
            bob += a[k];
            k += 2;
        }
    }
    cout << alice - bob << endl;
}  


Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

typedef double db;
db eps=1e-9;
struct point {
	db x,y;
	point() {}
	point(db x,db y):x(x),y(y) {}
	void input() { scanf("%lf%lf",&x,&y); }
	void output() { printf("%.10f %.10f\n",x,y); }
	db len() { return sqrt(x*x+y*y); }
	db len2() { return x*x+y*y; }
};
point operator + (const point &a,const point &b) { return point(a.x+b.x,a.y+b.y);}
point operator - (const point &a,const point &b) { return point(a.x-b.x,a.y-b.y);}
point operator * (const point &a,const db &b) { return point(a.x*b,a.y*b);}
point operator / (const point &a,const db &b) { return point(a.x/b,a.y/b);}
db dot(const point &a,const point &b) { return a.x*b.x+a.y*b.y; }
db det(const point &a,const point &b) { return a.x*b.y-a.y*b.x; }
struct line {
	point a,b;
	line() {}
	line(point a,point b):a(a),b(b) {}
};
point proj(const line &a,const point &b) {
	return a.a+(a.b-a.a)*dot(a.b-a.a,b-a.a)/(a.b-a.a).len2();
}
point reflect(const line &a,const point &b) {
	return proj(a,b)*2-b;
}
int dblcmp(db x) {
	return fabs(x)<eps?0:(x>0?1:-1);
}
int relation(const line &a,const point &b) {
	int x=dblcmp(det(a.b-a.a,b-a.a));
	if (x==1) return 0; // COUNTER_CLOCKWISE
	else if (x==-1) return 1; // CLOCKWISE
	else {
		x=dblcmp(dot(b-a.a,a.b-a.a));
		if (x<-eps) return 2; // ONLINE_BACK
		else {
			x=dblcmp(dot(b-a.b,a.b-a.a));
			if (x>eps) return 3; // ONLINE_FRONT
			else return 4; // ON_SEGMENT
		}
	}
}

int q;
int main() {
	scanf("%d",&q);
	rep(i,0,q) {
		point p1,p2,q1,q2;
		p1.input(); p2.input(); q1.input(); q2.input();
		if (dblcmp(dot(p2-p1,q2-q1))==0) puts("1");
		else if (dblcmp(det(p2-p1,q2-q1))==0) puts("2");
		else puts("0");
	}
}

Measured memory_bytes: 2752
dish = [int(input()) for x in range(5)]

loss_max = 0
loss_total = 0
for i in dish:
    if i%10 != 0:
        loss_total+=(10 - i%10)
        if loss_max < 10 - i%10:
            loss_max = 10 - i%10

print(sum(dish) + loss_total - loss_max)

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

int a[110][110];
int dp[110][110];

int main(void){
	int n=0;
	while(1){
		string s;
		cin >> s;
		if(cin.eof()) break;
		stringstream ss(s);
		int index=0;
		ss >> a[n][index++];
		char tmp;
		while(!ss.eof()) ss >> tmp >> a[n][index++];
		n++;
	}

	rep(i,n/2){
		rep(j,105){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+a[i][j]);
			dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+a[i][j]);
		}
	}
	const int m=n/2;
	rep(i,n/2){
		rep(j,105){
			dp[m+i+1][j]=max(dp[m+i+1][j],dp[m+i][j]+a[m+i][j]);
			dp[m+i+1][j]=max(dp[m+i+1][j],dp[m+i][j+1]+a[m+i][j+1]);
		}
	}

	cout << dp[n-1][0]+a[n-1][0] << endl;
	return 0;
}

Measured memory_bytes: 1316
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}

static const ULLONG UL_HUGE_DIVIDER = 1000000007LLU;
static const LLONG LL_HUGE_DIVIDER = 1000000007LL;

//static void ABC111D_RobotArms();
static void ABC110B_1Dimensional();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC110B_1Dimensional();
	fflush(stdout);
	return 0;
}
#endif

static void ABC110B_1Dimensional()
{
	int N, M, X, Y;
	scanf(" %d %d %d %d", &N, &M, &X, &Y);

	int xi;
	int maxx = X;
	for (int i = 0; i < N; i++) {
		scanf(" %d", &xi);
		maxx = std::max(maxx, xi);
	}

	int yi;
	int miny = Y;
	for (int i = 0; i < M; i++) {
		scanf(" %d", &yi);
		miny = std::min(miny, yi);
	}

	const char* ans = "War\n";
	if (miny > maxx) ans = "No War\n";
	printf(ans);
}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    if N < 3:
        print(0)
        return
    seq = [0] * 11
    for i in range(11):
        total = ((i+1) * 7 + 2) * 9
        for j in range(5):
            if total % 11 == K:
                seq[i] += 1
            total += 9
        if i > 0:
            seq[i] += seq[i-1]
    ans = (N - 3) // 11 * seq[10] + seq[(N-3) % 11]
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
    int a, b, ans;
    double ansd;
    cin >> a >> b;
    ans = (a + b) / 2;
    ansd = (double)(a + b) / 2;
    if(ans == ansd) cout << ans;
    else cout << "IMPOSSIBLE";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int dp[2001][2001];
int B[2001][2001];
int W[2001][2001];

int main(){
    int n;
    cin >> n;
    vector<int>a(2*n);
    vector<char>c(2*n);
    vector<int>ib(n+1);
    vector<int>iw(n+1);
    rep(i,2*n){
        cin >> c[i] >> a[i];
        if(c[i]=='B'){
            ib[a[i]] = i;
        }else{
            iw[a[i]] = i;
        }
    }
    for(int i=1;i<=n;i++){
        int bid = ib[i];
        int cnt = 0;
        for(int j=0;j<bid;j++){
            if(c[j]=='B'){
                if(a[j]>i){
                    cnt++;
                }
            }else{
                B[i][a[j]-1]++;
            }
        }
        for(int j=n-1;j>=0;j--){
            B[i][j] += B[i][j+1];
        }
        for(int j=n;j>=0;j--){
            B[i][j] += cnt;
        }
    }
    for(int i=1;i<=n;i++){
        int wid = iw[i];
        int cnt = 0;
        for(int j=0;j<wid;j++){
            if(c[j]=='W'){
                if(a[j]>i){
                    cnt++;
                }
            }else{
                W[i][a[j]-1]++;
            }
        }
        for(int j=n-1;j>=0;j--){
            W[i][j] += W[i][j+1];
        }
        for(int j=n;j>=0;j--){
            W[i][j] += cnt;
        }
    }
    // rep(i,n+1){
    //     rep(j,n+1){
    //         cerr << "i:" << i << " j:" << j << " " << B[i][j] << endl;  
    //     }
    // }
    // rep(i,n+1){
    //     rep(j,n+1){
    //         cerr << "i:" << i << " j:" << j << " " << W[i][j] << endl;  
    //     }
    // }
    rep(i,n+1){
        rep(j,n+1){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i!=0){
                dp[i][j] = min(dp[i][j],dp[i-1][j] + B[i][j]);
            }
            if(j!=0){
                dp[i][j] = min(dp[i][j],dp[i][j-1] + W[j][i]);
            }
        }
    }
    cout << dp[n][n] << endl;
    return 0;
}

Measured memory_bytes: 47360
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a >= b && a >= c) {
			System.out.print(a * 10 + b + c);
		} else if (b >= c && b >= a) {
			System.out.print(b * 10 + c + a);
		} else {
			System.out.print(c * 10 + a + b);
		}
	}
}

Measured memory_bytes: 21844
import sys


def main():
    x, y, z, k = [int(n) for n in input().split()]
    va = sorted([int(n) for n in input().split()], reverse=True)
    vb = sorted([int(n) for n in input().split()], reverse=True)
    xy = min(x*y, k)
    vab = (sorted([a + b for a in va for b in vb], reverse=True))[:xy]
    vc = sorted([int(n) for n in input().split()], reverse=True)
    xyz = min(x*y*z, k)
    print(*((sorted([ab + c for ab in vab for c in vc], reverse=True))[:xyz]), sep="\n")


main()


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

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

typedef pair< int, int > pii;

int n, p[1010], d[1010];
vector< vector< pii > > edges;
int deg[1010];

pii diam(int v, int d, int p) {
	pii res(v, d);
	//cout << "cur(" << v << "," << d << "," << p << ")" << endl;
	for_(i,0,(int)edges[v].size()) {
		pii e = edges[v][i];
		int u = e.first;
		
		if (u != p && deg[u] != 1) {
			pii p = diam(u, d + e.second, v);
			if (p.second > res.second) res = p;
		}
	}
	
	return res;
}

int main() {
	while (cin >> n, n) {
		memset(deg, 0, sizeof(deg));
		for_(i,0,n-1) cin >> p[i];
		for_(i,0,n-1) cin >> d[i];
		
		int ans = 0;
		
		edges.assign(n, vector< pii >());
		
		for_(i,0,n-1) {
			++deg[i+1];
			++deg[p[i]-1];
			edges[i+1].push_back(pii(p[i]-1, d[i]));
			edges[p[i]-1].push_back(pii(i+1, d[i]));
			ans += 3 * d[i];
		}
		
		for_(i,0,n) if (deg[i] == 1) ans -= 2 * edges[i][0].second;
		
		for_(i,0,n) {
			if (deg[i] != 1) {
				pii f = diam(i, 0, -1);
				pii s = diam(f.first, 0, -1);
				ans -= s.second;
				break;
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int counter=0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++) {
                if(x==i*500 + j*100 + k*50){
                    counter++;
                }

            }
        }
    }
    cout << counter;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
using vi=vector<int>;
using vll=vector<ll>;
int gcd(int x,int y){
  int u,v,r;
  u=min(x,y);
  v=max(x,y);
  r=v%u;
  while(r>0){
    v=u;
    u=r;
    r=v%u;
  }
  return u;
}

int main() {
  char a;
  cin>>a;
  if('A'<=a && a<='Z') cout<<'A'<<endl;
  else cout<<'a'<<endl;
}

Measured memory_bytes: 3632
(defun f (a b n i acc pred)
  (if (= i n)
      acc
      (let ((x (aref a i))
            (y (aref b i)))
        (if (eq x y)
            (f a b n (1+ i)
               (mod (* acc (case pred ('first 3) ('tate 2) ('yoko 1)))
                    1000000007)
               'tate)
            (f a b n (+ i 2)
               (mod (* acc (case pred ('first 6) ('tate 2) ('yoko 3)))
                    1000000007)
               'yoko)))))

(let* ((n (read))
       (a (read-line))
       (b (read-line)))
  (princ (f a b n 0 1 'first))
  (terpri))



Measured memory_bytes: 15976
#include <iostream>

using namespace std;

const long long INF = 1145141919810;
int h[100005];
long long dp[100005];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            if (i + j >= n) break;
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1408
def work(n, t, a):
    if t[-1] != a[0]:
        return 0

    middle = 0
    for i in xrange(n):
        if t[i] == a[i]:
            if t[i] != t[-1] or t[i] != a[0]:
                return 0
            middle = i
            break
    for i in xrange(middle, n):
        if t[i] < a[i]:
            return 0

    record = [None] * n
    left, right = 0, n - 1

    while left <= right and t[left] < a[left]:
        if not left or t[left] > t[left-1]:
            record[left] = 1
        else:
            record[left] = t[left]
        left += 1
    
    record[left] = 1
    while left < right and a[right] <= t[right]:
        if right == n - 1 or a[right] > a[right+1]:
            record[right] = 1
        else:
            record[right] = a[right]
        right -= 1

    ans = 1
    for i in xrange(n):
        ans = (ans*record[i]) % (10**9+7)
    return ans


n = int(raw_input())
t = map(int, raw_input().split())
a = map(int, raw_input().split())

print work(n, t, a)


Measured memory_bytes: 14540
import java.util.*;

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

        int i = 0;
        int o = 0;
        String sub = "ABC";
        int n = sc.nextInt();
        String s = sc.next();

            while ((i = s.indexOf(sub, i)) != -1) {
                o++;
                i++;
            }


        System.out.println(o);
    }
}

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

// float pinf = std::numeric_limits<float>::infinity();
//double pinf = INFINITY;
// これはどうやって使う？ #define INFINITY inf;
const int INF = 100000000;

void floyd_warshall(vector<vector<int>>& K) {
	for (int k = 0; k < K.size(); k++) {
		for (int i = 0; i < K.size(); i++) {
			for (int j = 0; j < K.size(); j++) {
				if (K.at(i).at(k) + K.at(k).at(j) < K.at(i).at(j)) {
					K.at(i).at(j) = K.at(i).at(k) + K.at(k).at(j);
				}
			}
		}
	}
}

int main(void) {
	// 隣接行列の作成
	int n, m;
	cin >> n >> m;
	vector<vector<int>> K(n, vector<int>(n, INF));
	int a, b, c, d;
	while(m--) {
		cin >> a;
		cin.ignore();
		cin >> b;
		cin.ignore();
		cin >> c;
		cin.ignore();
		cin >> d;
		K.at(a-1).at(b-1) = c;
		K.at(b-1).at(a-1) = d;
	}

	int s, g, V, P;
	cin >> s;
	cin.ignore();
	cin >> g;
	cin.ignore();
	cin >> V;
	cin.ignore();
	cin >> P;

//	for(auto x:K) {
//		for(auto i:x) {
//			cout << i;
//		}
//		cout << " " << endl;
//	}
	floyd_warshall(K);

	int ans;
	ans = V - P - K.at(s-1).at(g-1) - K.at(g-1).at(s-1);
	cout << ans << endl;

//	for(auto x:K) {
//		for(auto i:x) {
//			cout << i;
//		}
//		cout << " " << endl;
//	}
}



Measured memory_bytes: 3140
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <queue>

using namespace std;
typedef pair <int,int> P;
typedef long long int ll;

int getHigh(ll A)
{
	if(A==0) return -1;
	int ret=0;
	while(1)
	{
		A/=2;
		if(A==0) break;
		ret++;
	}
	return ret;
}
int main()
{
	ll A,B;
	scanf("%lld %lld",&A,&B);
	if(A==B)
	{
		puts("1");
		return 0;
	}
	ll ret=0;
	while(A>0)
	{
		int a=getHigh(A),b=getHigh(B);
		if(a==b)
		{
			A-=1LL<<a;
			B-=1LL<<b;
		}
		else break;
	}
	int b=getHigh(B);
	ret+=(1LL<<b)-A;
	ll T=B-(1LL<<b);
	int t=getHigh(T)+1;
	//printf("%lld %lld : %d %d\n",A,B,b,t);
	ll bt=0;
	for(int i=0;i<t;i++)
	{
		if(A%2==1) bt|=1LL<<i;
		A/=2;
		b--;
	}
	ll add=(1LL<<b)-A;
	if(A>0)
	{
		add++;
		ret-=bt;
	}
	ret+=add*(1LL<<t);
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main (){
  int a,b,c,d,e,i,j,k,x;
  scanf("%d %d",&a,&b);
  if(b<10) {
    x=10*a+b;
  } else if(b<100) {
    x=100*a+b;
  } else {
    x=1000*a+b;
  }
  for(i=1;i<=10000;i++){
    if (x==i*i) {
      printf("Yes\n");
      return 0;
    }
    if (x<i*i) {
      printf("No\n");
      return 0;
    }
  }
  return 0;
}

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

const ll mod=1e9+7;

ll fpow(ll a,ll p){
	ll res=1LL;
	while(p){
		if(p&1LL) res=res*a%mod;
		a=a*a%mod;
		p>>=1LL;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<ll> cnt(n,0);
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		cnt[x]++;
	}
	if((n&1)&&(cnt[0]!=1)){
		cout<<0;
		return 0;
	}
	if(n%2==0&&(cnt[0]!=0)){
		cout<<0;
		return 0;
	}
	for(int i=1;i<n;++i)
		if(cnt[i]!=2&&cnt[i]!=0){
			cout<<0;
			return 0;
		}
	ll res=fpow(2LL,n/2);
	cout<<res;
}



Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
vector<ll> v(10000010,0);

int main()
{
ll n ;
cin >> n ;
rep(i,n){
  ll j=i+1;
  while(j<=n){
    v[j]++;
    j+=(i+1);
  }
  ans+=(i+1)*v[i+1];
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 81260
A, B, C, D = map(int, input().split())
bc = B // C
bd = B // D
ac = (A - 1) // C
ad = (A - 1) // D
def gcd(C, D):
    while D:
        C, D = D, C % D
    return C
def lcm(C, D):
    return C * D // gcd(C, D)
bcd = B // lcm(C, D)
acd = (A - 1) // lcm(C, D)
a = bc - ac
b = bd - ad
c = bcd - acd
print((B + 1 - A) - (a + b - c))

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

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    vector<int> h_max(n);
    rep(i,n){
        if(i == 0) h_max[i] = h[i];
        h_max[i] = max(h[i],h_max[i-1]);
    }

    int ans =0;
    rep(i,n){
        if(h_max[i] == h[i]) ans++;
    }
    cout << ans << endl;
}


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

int main(){
	int sec , h , m , s;
	cin >> sec;
	h = sec / 3600;
	m = sec % 3600;
	s = m % 60;
	m = m / 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int m; cin >> m;
    cout << 24 + 24 - m << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int field[10][10000];

int main()
{
	while(true)
	{
		int C,R;
		scanf("%d%d",&R,&C);
		if(R==0&&C==0) break;
		for(int i=0;i<R;i++)
		{
			for(int j=0;j<C;j++)
			{
				scanf("%d",&field[i][j]);
			}
		}
		int ans=0;
		for(int i=0;i<(1<<R);i++)
		{
			int tmp=0;
			for(int j=0;j<C;j++)
			{
				int cnt=0;
				for(int k=0;k<R;k++)
				{
					if(field[k][j]+((i>>k)&1)==1)
					{
						cnt++;
					}
				}
				cnt=max(cnt,R-cnt);
				tmp+=cnt;
			}
			ans=max(ans,tmp);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1416
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,K,i;cin>>N>>K;ll X[N];
  REP(i,N)cin>>X[i];
  FOR(i,K,N){
    if(X[i]>X[i-K])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

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

	
	int [] hash, pos;
	int max, n;
	int size = 400;
	ArrayList<String> anslist;
	HashSet<String> dup;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			max = sc.nextInt();
			hash = new int[size + 1];
			for(int i = 0 ; i < n * (n - 1) / 2 - 1; i++){
				hash[sc.nextInt()]++;
			}
			pos = new int[n];
			pos[0] = 0;
			pos[n-1] = max;
			anslist = new ArrayList<String>();
			dup = new HashSet<String>();
			dfs(0,0,n-1);
			for(int i = 0 ; i < anslist.size(); i++){
				System.out.println(anslist.get(i));
			}
			System.out.println("-----");
		}
	}
	
	private void dfs(int deep, int left, int right) {
		if(deep == n - 2){
			//System.out.println(Arrays.toString(pos));
			String str = tostr();
			if(dup.contains(str)) return;
			dup.add(str);
			anslist.add(str);
			return ;
		}
		
		int cand = max;
		for(;hash[cand] <= 0;cand--){
			if(cand == 0) break;
		}
		int pair = max - cand;
		if(hash[cand] < 0 || hash[pair] < 0) return ;
		pos[left + 1] = pair;
		dfs2(deep, left, right, pair, 0);
		pos[left + 1] = 0;
		pos[right - 1] = cand;
		dfs2(deep, left, right, cand, 1);
		pos[right - 1] = 0;
		
	}

	private void dfs2(int deep, int left, int right, int cand, int digit) {
		int nright = -1, nleft = -1;
		if(digit == 1){
			nright = right -1;
			nleft = left;
		}
		else{
			nright = right;
			nleft = left + 1;
		}
		
		for(int i = 0 ; i <= left; i++){
			if(hash[cand - pos[i]] <= 0){
				return ;
			}
		}
		
		for(int i = 0 ; i <= left; i++){
			hash[cand - pos[i]]--;
		}
		
		boolean flg = false;
		for(int i = right; i < n; i++){
			if(hash[pos[i] - cand] <= 0){
				flg = true;
				break;
			}
		}
		
		if(! flg){
			for(int i = right; i < n; i++){
				hash[pos[i] - cand]--;
			}
			
			dfs(deep + 1, nleft, nright);
			
			for(int i = right; i < n; i++){
				hash[pos[i] - cand]++;
			}
		}
		for(int i = 0 ; i <= left; i++){
			hash[cand - pos[i]]++;
		}
	}

	private String tostr() {
		StringBuilder sb = new StringBuilder();
		for(int i = 1; i< pos.length; i++){
			sb.append(" " + (pos[i] - pos[i-1]));
		}
		return sb.substring(1);
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
alp = "abcdefghijklmnopqrstuvwxyz"
s = input()
K = int(input())
N = len(s)
T = ""
for i in range(N):
    n = alp.index(s[i])
    if i==N-1:
        T+=alp[(n+K)%26]
    else:
        if n!=0 and K>=26-n:
            T+="a"
            K-=(26-n)
        else:T+=alp[n]
print(T)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define INF 200005
#define MOD 1000000007

int main()
{
    //freopen("output.txt","r",stdin);
    //freopen("input.txt","r",stdin);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    cin >> n;
    string a;
    cin >> a;
    int counter=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]!=a[i-1])
        {
            counter++;
        }
    }
    printf("%d\n",counter);
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;

bool compare_by_b(pair<string, int> a, pair<string, int> b) {
    return a.first == b.first && a.second < b.second;
}

int main(void){
    ll n;
    cin >> n;
    vector<pair<pair<string,ll>,ll> > pairs(n);
    for(ll i = 0;i < n; i++){
        pair<string,ll> tmp;
        cin >> tmp.first >> tmp.second;
        tmp.second *= -1;
        pairs[i] = make_pair(tmp,i + 1);
    }
    // 辞書順ソート
    sort(pairs.begin(),pairs.end());
    for(ll i = 0;i < n;i++){
        cout << pairs[i].second << endl;
    }
    return 0;
}


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

int dp[100005][3];

int main(){
    
    int n; 
    cin>>n;
    
    int v[n][3];
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++)
            cin>>v[i][j];
    }
    
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    
    for(int i=1; i<n; i++){
        
        for(int j=0; j<3; j++){
            int x = INT_MIN;
            for(int k=0; k<3; k++){
            if(j!=k){
            dp[i][j] = max((dp[i-1][k])+v[i][j],x);
            x = dp[i][j];
            }
            }
        }
        
    }
 //   cout<<dp[n-1][0]<<" "<<dp[n-1][1]<<" "<<dp[n-1][2]<<endl;
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    
}



Measured memory_bytes: 5880
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int n;
  cin>>n;
  int a[n];
  vector<int> counter(100010,0);
  REP(i,n){
    cin>>a[i];
    counter[a[i]]++;
  }
  int even=0;
  int ans=0;
  REP(i,100010){
    if(counter[i]%2==1){
      ans++;
    }else if(counter[i]==0){
      continue;
    }else{
      even++;
    }
  }
  if(even%2==0){
    ans += even;
  }else{
    ans += even-1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int count=0;
   double a,b;
   for(int i=0;i<n;i++){
       cin>>a>>b;
       if(sqrt((a*a)+(b*b))<=d)
       count++;
   }
cout<<count;
    return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

bool G[10][10];

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

    rep(i,m){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a][b] = G[b][a] = true;
    }

    vector<int> ord(n);
    for (int i = 0; i < n; ++i) ord[i] = i;

    int res = 0;
    do{
        if(ord[0] != 0) break;
        bool ok = true;
        for (int i = 0; i + 1 < n; ++i){
            int from = ord[i];
            int to = ord[i+1];
            if(!G[from][to]) ok = false;
        }
        if(ok) res++;
    }
    while (next_permutation(ord.begin(),ord.end()));

    cout << res << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  int N, X, Y, mindis = 0, ans = 0, check;
  cin >> N >> X >> Y ;
  int dist[N] ;
  for(int i=0;i<N;i++){
    dist[i] = 0 ;
  }
  for(int i=1;i<X;i++){
    for(int j=(i+1);j<(X+1);j++){
      dist[j-i]++ ;
    }
    for(int j=(X+1);j<Y;j++){
      mindis = min((j-X),(Y-j+1)) + (X-i) ;
      dist[mindis]++ ;
    }
    for(int j=Y;j<N+1;j++){
      mindis = (X-i) + (j-Y) + 1 ;
      dist[mindis]++ ;
    }
  }
  for(int i=X;i<Y;i++){
    for(int j=(i+1);j<Y;j++){
      mindis = min((j-i),((i-X)+(Y-j+1)) ) ;
      dist[mindis]++ ;
    }
    mindis = min((Y-i),(i-X+1)) ;
    for(int j=Y;j<(N+1);j++){
      dist[mindis+(j-Y)]++ ;
    }
  }
  for(int i=Y;i<N;i++){
    for(int j=(i+1);j<(N+1);j++){
      dist[j-i]++ ;
    }
  }
  for(int i=1;i<N;i++){
    cout << dist[i] << endl ;
  }
  return 0 ;
}  

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    int a;
    int b,c;
    b=c=0;
    cin >> a;
    string str1,str2;
    for(int i=0;i<a;i++){
        cin >> str1 >> str2;
        if(str1 == str2){
            b+=1;
            c+=1;
        }
        if(str1>str2){
            b+=3;
        }
        if(str1<str2){
            c+=3;
        }
    }
    cout << b << " " << c<< endl;
    }


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int a[] = {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;
  k--;
  cout << a[k] << endl;
}


Measured memory_bytes: 256
def translation(string):
    roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50,
             'C': 100, 'D': 500, 'M': 1000 }
    ans = 0
    for i in range(len(string)):
        if i == len(string)-1 or \
            roman[string[i]] >= roman[string[i+1]]:
            ans += roman[string[i]] * 1
        else:
            ans += roman[string[i]] * -1
    return ans

while True:
    try: start = input()
    except: break
    
    ans = translation(start)
    print(ans)



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

int main () {
  int n;
  cin >> n;
  int one = n % 10;
  if (one == 2 || one == 5 || one == 4
      || one == 7 || one == 9) {
  	cout << "hon" << endl; 
  } else if (one == 3) {
    cout << "bon" << endl;
  } else {
    cout << "pon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

constexpr ll MOD = 1e9+7;

ll pow_mod(ll a , ll p, ll MOD){
    if( p < 2){
        ll ans = 1;
        while(p--){
            ans =  (ans * a) % MOD;
        }
        return ans;
    }else{
        if( p % 2){
            ll ans = pow_mod(a, p / 2, MOD);
            ans = (ans * ans) % MOD;
            ans = (a * ans) % MOD;
            return ans;
        }else{
            ll ans = pow_mod(a , p /2, MOD);
            ans = (ans * ans) % MOD;
            return ans;
        }
    }
}

void solve(){
    int n;
    read(n);
    vl a(n);
    REP(i, n) cin >> a[i];
    
    ll sum = 0, square_sum = 0;
    REP(i,n){
        sum += a[i];
        if( sum > MOD){
            sum  = sum % MOD;
        }
        ll a2 = a[i] * a[i];
        if( a2 > MOD){
            a2 = a2 % MOD;
        }
        square_sum += a2;
        if(square_sum > MOD){
            square_sum = square_sum % MOD;
        }
    }
    ll sum_sq = sum * sum; 
    if( sum_sq > MOD){
        sum_sq = sum_sq % MOD;
    }
    ll ans_1 = (sum_sq - square_sum + MOD) % MOD;
    ll inverse_2 = pow_mod(2, MOD-2, MOD);
    ans_1 = (ans_1 * inverse_2) % MOD;
    cout << ans_1  << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



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

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

    static class FaceProducesUnhappiness {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            char[] chars = in.next().toCharArray();
            long start = 0;
            for (int i = 1; i < chars.length; i++) {
                if (chars[i - 1] == chars[i]) {
                    start++;
                }
            }
            out.println(Math.min(start + 2 * k, n - 1));
        }

    }
}



Measured memory_bytes: 39884
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			@SuppressWarnings("unused")
			int n = scanner.nextInt(), k = scanner.nextInt() - 1;
			char[] s = scanner.next().toCharArray();
			// 大文字から小文字へ変換
			s[k] += 'a' - 'A';
			System.out.println(s);
		}
	}
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  rep(i,n) a[i] -= i+1;
  sort(all(a));

  ll sad = 0;
  ll cent;
  if(n%2 == 1){
    cent = a[n/2];
  }
  else{
    cent = (a[n/2]+a[n/2-1])/2;
  }

  rep(i,n) sad += abs(cent-a[i]);

  cout << sad << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n,0);
    vector<int> cnt;
    int ans=0;
    REP(i,n)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    a.push_back(-1);
    int c=1;
    for(int i=0; i<n; i++)
    {
        if(a[i]==a[i+1]) ++c;
        else
        {
            cnt.push_back(c);
            c=1;
        }
    }
    sort(cnt.begin(),cnt.end());
    if(cnt.size()<=k)
    {
        cout<<ans<<endl;
        return 0;
    }
    else if(cnt.size()>k)
    {
        for(int i=0; i<cnt.size()-k; i++)
        {
           ans+=cnt[i];
        }
    }

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

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

int main() {
  int n,m;
  cin>>n>>m;
  bool check[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) check[i][j]=false;
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    check[a-1][b-1]=true;
    check[b-1][a-1]=true;
  }
  int a[n-1];
  for(int i=0;i<n-1;i++) a[i]=i+1;
  int ans=0;
  do{
    bool temp=true;
    for(int i=0;i<n-1;i++){
      if(i==0 && !check[0][a[0]]) temp=false;
      if(i>=1 && !check[a[i-1]][a[i]]) temp=false; 
    }
    if(temp) ans++;
  }while(next_permutation(a,a+n-1));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int K; cin >> K;
	vector<ll> a(K);
	for (int i = 0; i < K; i++) {
		cin >> a[i];
	}
	bool flag = true;
	vector<pair<ll, ll>> p(K);
	p[K - 1].first = 2, p[K - 1].second = 2;
	for (int i = K - 1; i >= 1; i--) {
		p[i - 1].first = a[i - 1] * ((p[i].first + a[i - 1] - 1) / a[i - 1]);
		p[i - 1].second = a[i - 1] * ((p[i].second + a[i] - 1) / a[i - 1]);
		//cout << "i-1=" << i-1 << " " << p[i-1].first << " " << p[i-1].second << endl;
		if (!(p[i].first <= p[i-1].first || p[i - 1].second <= p[i].second)||p[i-1].first>p[i-1].second) {
			flag = false;
			break;
		}
		
	}
	if (flag&&a[K-1]==2) {
		ll mn = 0, mx = 0;
		mn = p[0].first;
		mx = p[0].second + a[0] - 1;
		cout << mn << " " << mx << endl;
	}
	else cout << -1 << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    vector<int>prev(N*2);
    for(int i=0;i<N*2;i++)prev[i]=i+1;

    while(M--){
        int t;
        cin>>t;
        vector<int>next(N*2);
        if(t){
            for(int i=t;i<N*2;i++)next[i-t]=prev[i];
            for(int i=0;i<t;i++)next[N*2-t+i]=prev[i];
            prev=next;
        }
        else{
            for(int i=0;i<N;i++){
                next[i*2]=prev[i];
                next[i*2+1]=prev[i+N];
            }
            prev=next;

        }
    }

    for(int i=0;i<N*2;i++)cout<<prev[i]<<endl;
    return 0;
}

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

int main(){
	int H, W, i, j;

	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
			
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( int i=a;i<b;i++)
#define REPR(i,a,b) for(int i=a;i>=b;i--)
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 998244353
#define PI 3.14159265358979323846
const ll N = 200007;

struct LessSecond
{
    template<typename T, typename U>
    bool operator()(const std::pair<T, U> &x, const std::pair<T, U> &y) const
    {
        return x.second < y.second;
    }
};

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

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

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        ll n;
        cin >> n;
        ll r = 1 + (n - 1) / 1000;
        cout << 1000 * r - n << endl;
    }
    return 0;
}



Measured memory_bytes: 3640
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut iterator = iterator.next().unwrap().split("/");
    let year: usize = iterator.next().unwrap().parse().unwrap();
    let month: usize = iterator.next().unwrap().parse().unwrap();
    let day: usize = iterator.next().unwrap().parse().unwrap();
    if month <= 4 {
        "Heisei".to_string()
    } else {
        "TBD".to_string()
    }
}


Measured memory_bytes: 2136