akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
  int a, b;
  cin >> a >> b;
  std::string ka = std::to_string(a);
  std::string kb = std::to_string(b);
  // int kka = atoi(ka[0]);
  // int kkb = atoi(kb[0]);
  if (ka[0] < kb[0])
  {
    for (size_t i = 0; i < b; ++i)
    {
      cout << ka;
    }
    cout << endl;
  }
  else if (ka[0] > kb[0])
  {
    for (size_t i = 0; i < a; ++i)
    {
      cout << kb;
    }
    cout << endl;
  }
  else
  {
    if (a < b)
    {
      for (size_t i = 0; i < a; ++i)
      {
        cout << kb;
      }
      cout << endl;
    }
    else
    {
      for (size_t i = 0; i < b; ++i)
      {
        cout << ka;
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
  string s;
  cin>>s;
  ll mn=0;
  ll st=-1,end=0;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='R') {
    if(st<0) {st=i;end=i+1;}
      else end=i+1;
    }
    else {
    	st=-1;end=0;
    }
    //cout<<end<<" "<<st<<"\n";
    if(st!=-1)
    mn=max((end-st),mn);
  }
  cout<<mn<<endl;
  return 0;
}

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

static int A[310][310];
static bool used[310];
int N, M;

int rec(int ncol) {
    if (ncol == 1) return N;
    int id = -1,
        participants = 0;
    int counter[310] = {};

    for (int r = 0; r < N; r++) {
        int s = -1;

        for (int c = 0; c < M; c++) {
            if (used[A[r][c]]) continue;
            s = c;
            break;
        }
        counter[A[r][s]]++;
    }
    int s = -1;
    for (int c = 0; c < M; c++) {
        if (s < 0 or counter[c] > counter[s]) s = c;
    }
    used[s] = true;
    return min(counter[s], rec(ncol - 1));
}

int main() {
    cin >> N >> M;
    for (int r = 0; r < N; r++) {
        for (int c = 0; c < M; c++) {
            cin >> A[r][c];
            A[r][c]--;
        }
    }
    cout << rec(M) << endl;

    return 0;
}

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

int64_t MOD;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int H, W;
    cin >> H >> W >> MOD;
    string S[2000];
    for(int i=0; i<H; i++) cin >> S[i];
    static int64_t dp[2000][2000], coef[2000][2000], now[2000][2000], route[2000][2000];
    coef[0][0] = route[0][0] = 1;
    now[0][0] = S[0][0] - '0';
    int dx[] = {0, 1}, dy[] = {1, 0};
    for(int i=0; i<H; i++) for(int j=0; j<W; j++) for(int k=0; k<2; k++){
        int x = i+dx[k], y = j+dy[k];
        if(x==H || y==W) continue;
        add(route[x][y], route[i][j]);
        add(dp[x][y], dp[i][j]);
        if(S[x][y] == '+'){
            add(dp[x][y], now[i][j]);
            add(coef[x][y], route[i][j]);
        }else if(S[x][y] == '*'){
            add(coef[x][y], now[i][j]);
        }else{
            int d = S[x][y] - '0';
            add(coef[x][y], coef[i][j]);
            add(now[x][y], 10 * now[i][j] + coef[i][j] * d);
        }
    }
    int64_t ans = (dp[H-1][W-1] + now[H-1][W-1]) % MOD;
    cout << ans << endl;
    return 0;
}



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

int main() {
    int N;
    cin >> N;
    int p[N];
    for(int i = 0; i < N; i++)
        cin >> p[i];

    sort(p, p + N);

    p[N - 1] = p[N - 1] / 2;

    int sum = 0;
    for(int i = 0; i < N; i++)
        sum += p[i];

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

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


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



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

int n ,k;
cin>>n>>k;

map<int,int> m;
for(int index = 0 ;index < n;index++)
{
    int a ;
    cin>>a;
    m[a]++;
}
vector<int> s;
for(auto it = m.begin();it!=m.end();it++)
    s.push_back(it->second);

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


int ans = 0;
if(s.size()>=k)
for(int index = 0 ;index <s.size()-k;index++)
    ans+=s[index];

    cout<<ans<<endl;

 return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N, K;
    cin >> N >> K;
    int h[100000];
    ll dp[100000];
    for(int i=0;i<N;i++) cin >> h[i];
    dp[0] = 0;
    for(int i=1;i<N;i++){
        dp[i] = INT64_MAX;
        for(int j=1;(i-j)>=0 && j<=K;j++){
            dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]));
        }
    }

    cout << dp[N-1] << endl;
    
    return 0;
}

Measured memory_bytes: 1408
import itertools
h,w,k = map(int, input().split())
g = []
for _ in range(h):
  g.append(input())
ans = 0
for i in list(itertools.product([0,1], repeat=h)):
  for j in list(itertools.product([0,1], repeat=w)):
    e = 0
    for x in range(h):
      for y in range(w):
        if i[x] == 1 and j[y] == 1 and g[x][y]=='#':
          e+=1
    if e==k:
      ans+=1
print(ans)

Measured memory_bytes: 9216
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	cout << (n+1)/2;


	

    return 0;
}

Measured memory_bytes: 256
n = int(input())

s = [input() for i in range(n)]

order = "MARCH"

nums = [[name[0] for name in s].count(order[i]) for i in range(len(order))]

ans = 0
for i in range(0, 5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += nums[i] * nums[j] * nums[k]
            
print(ans)



Measured memory_bytes: 10520
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int a=scn.nextInt();
        int b=scn.nextInt();
        int answer=0;
        int max =Math.max(a,b);
        int min = Math.min(a,b);
        for(int i=0;;i++){
            if(max<=0&&min<=0||(a+b)%2==1){
                System.out.println("IMPOSSIBLE");
                break;
            }
            if(Math.abs(max)==Math.abs(min)){
                System.out.println(answer);
                break;
            }
            max--;
            min--;
            answer++;
        }
    }
}


Measured memory_bytes: 23764
N,M = map(int,input().split())

flag = [True] * N
wa = [0] * N

for i in range(M):

    p,s = input().split()
    p = int(p)
    p -= 1

    if s == "WA":

        if flag[p]:
            wa[p] += 1

    if s == "AC":

        flag[p] = False

ac = 0
wa2 = 0
for i in range(N):
    if not flag[i]:
        ac += 1
        wa2 += wa[i]



print (ac,wa2)


Measured memory_bytes: 4596
#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();

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

    int ans;
    ans = a - b * 2;
    
    if (ans <= 0) cout << "0" << endl;
    else cout << ans << endl;

    return 0;
    
}

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

int main() {
    string s;
    cin >> s;
  
	int ans = 0;
  	for(int i = 0; i < s.length(); i++) {
      if(s[i] == '+') ans++;
      else ans--; //条件より'+'でなければ'-'なので引く
    }
  
  	cout << ans << endl;;
  	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
#include<vector>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	ll r = a%b;
	a = b; b = r;
	return gcd(a, b);
}


int main() {

	ll n, t[100];
	ll ans;

	cin >> n;
	rep(i, 0, n) {
		cin >> t[i];
	}
	if (n == 1) {
		cout << t[0] << endl;
		return 0;
	}
	ans = t[0] / gcd(max(t[0], t[1]), min(t[0], t[1])) * t[1];
	rep(i, 1, n) {
		ans = t[i] / gcd(max(t[i], ans), min(t[i],ans)) * ans;
	}
	cout << ans << endl;


	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define INF 1000000000
#define PI 3.14159265358979323846

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<LL> vll;
//==============================================
struct node { int p, l, r; };
node N[30];
vi D(30), H(30);

int setDepth(int u, int p) {
	if (u == -1) return 0;

	D[u] = p;
	if (N[u].l != -1) setDepth(N[u].l, p + 1);
	if (N[u].r != -1) setDepth(N[u].r, p + 1);

	return 0;
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if (N[u].l != -1) {
		h1 = setHeight(N[u].l) + 1;
	}

	if (N[u].r != -1) {
		h2 = setHeight(N[u].r) + 1;
	}

	return H[u] = max(h1, h2);
}

int getSibling(int u) {
	if (N[u].p == -1) return -1;

	if (N[N[u].p].l != u && N[N[u].p].l != -1) {
		return N[N[u].p].l;
	}
	if (N[N[u].p].r != u && N[N[u].p].r != -1) {
		return N[N[u].p].r;
	}

	return -1;
}

int getDegree(int u) {
	int deg = 0;
	if (N[u].l != -1) deg++;
	if (N[u].r != -1) deg++;

	return deg;
}

void print(int u) {
	cout << "node " << u << ": ";
	cout << "parent = " << N[u].p << ", ";
	cout << "sibling = " << getSibling(u) << ", ";

	cout << "degree = " << getDegree(u) << ", ";
	cout << "depth = " << D[u] << ", ";
	cout << "height = " << H[u] << ", ";

	if (N[u].p == -1) {
		cout << "root";
	}
	else if (N[u].l == -1 && N[u].r == -1) {
		cout << "leaf";
	}
	else {
		cout << "internal node";
	}

	cout << "\n";
}

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

	int n;
	cin >> n;

	REP(i, n) {
		N[i].p = N[i].l = N[i].r = -1;
	}

	int id, inputLeft, inputRight;
	REP(i, n) {
		cin >> id >> inputLeft >> inputRight;

		N[id].l = inputLeft;
		N[id].r = inputRight;

		if (inputLeft != -1) N[inputLeft].p = id;
		if (inputRight != -1) N[inputRight].p = id;
	}

	int r;
	REP(i, n) {
		if (N[i].p == -1) {
			r = i;
		}
	}

	setDepth(r, 0);
	setHeight(r);

	REP(i, n) {
		print(i);
	}
	return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long long MAX_E = 101010;


struct edge{
    int u, v, cost;
};

edge es[MAX_E];

bool comp(const edge &e1, const edge &e2){
    return e1.cost < e2.cost;
}

class UnionFind{
public:

    //親の番号を格納する. Parentだった場合は−(the size)とする
    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]); //親をつなぎ替える
    }
    
    //size関数を作る
    //自分の所属するグループの頂点数を調べる
    long long size(int A){
        return -Parent[root(A)]; //親をとりたい
    }
    
    //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; //すでにくっついてる
        }
            
        //大きい方に小さい方をくっつけたい
        //大小が逆だったらひっくり返す
            
        if(size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        
        //BのParentをAに変更する
        Parent[B] = A;
        
        return true; //くっついた
    }
    
};



int kruskal(int V, int E){
    
    sort(es, es+E, comp);
    
    UnionFind uni(V);
    
    int res = 0;
    
    for (int i = 0; i < E; i++){
        edge e = es[i];
        
        if (uni.root(e.u) != uni.root(e.v)){
            uni.connect(e.u, e.v);
            res += e.cost;
        }
    }
    
    return res;
}




int main(){
    
    int V, E;
    cin >> V >> E;
    
    for (int i = 0; i < E; i++){
        int s, t, w;
        cin >> s >>t >> w;
        
        es[i] = (edge){s, t, w};
    }
    
    cout << kruskal(V, E) << endl;
    return 0;
}


Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int ans[110000];
int treesize[110000];
int root[110000];

struct Unionfind {
  vector<int> par;

  Unionfind(int n) : par(n) {
    rep(i,n) par[i] = i;
  }

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

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if(rx==ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  Unionfind tree(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.unite(a,b);
    ans[a]--; ans[b]--;
  }
  rep(i,n) root[i] = tree.root(i);
  rep(i,k) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    if(root[c]==root[d]) {
      ans[c]--; ans[d]--;
    }
  }
  rep(i,n) treesize[root[i]]++;
  rep(i,n) {
    int r = root[i];
    ans[i] += (treesize[r] - 1);
  }
  rep(i,n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0, bf = 0;
	rep(i, n){
		int in;
		cin >> in;
		sum += fabs(bf - in);
		a.at(i) = in;
		bf = in;
	}
	a.push_back(0);
	sum += fabs(a.at(n-1) - 0);
	rep(i, n){
		int ans = sum, b2n, n2a, n = a.at(i);
		if(i == 0) b2n = 0;
		else b2n = a.at(i-1);
		n2a = a.at(i+1);
		if((b2n <= n && n <= n2a) || (n2a <= n && n <= b2n)){
		}else{
			if(fabs(b2n - n) < fabs(n - n2a)){
				ans -= 2 * fabs(b2n - n);
			}else{
				ans -= 2 * fabs(n -n2a);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1656
n=int(input())
a=sorted(list(map(int,input().split())))
m=max(a)
b=[1]*m
c=[0]*m
for i in a:
  c[i-1]+=1
  if b[i-1]:
    for j in range(i*2-1,m,i):
      b[j]=0
x=0
for i in range(m):
  if b[i] and c[i]==1:
    x+=1
print(x)

Measured memory_bytes: 140064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	
	public static void Main(string[] args)
	{
		_memo = new Dictionary<int, double>();
		var s = Input();
		var n = s[0].ToInt();
		var k = s[1].ToInt();
		var p = Input().ToInt();
		
		double cura = 0;
		for(int i = 0; i < k-1; i++)
		{
			var r = GetRate(p[i]);
			cura += r;
		}
		
		double maxr = 0;
		for(int i = k-1; i < n; i++)
		{
			var r = GetRate(p[i]);
			cura += r;
			maxr = (double)Math.Max(maxr, cura);
			cura -= (double)GetRate(p[i-(k-1)]);
		}
		Console.WriteLine(maxr);
		
	}
	private static Dictionary<int, double> _memo;
	
	private static double GetRate(int v)
	{
		if(_memo.ContainsKey(v))
			return _memo[v];
		long wa = 0;
		for(int i = 1; i <= v; i++)
		{
			wa += i;
		}
		var p = (double)wa / v;
		_memo.Add(v, p);
		return p;
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 40720
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  int A[5];
  int mod=10;
  rep(i,5){
     cin>>A[i];
     if(A[i]%10==0){
         continue;
     }
     else{
         mod=min(mod,A[i]%10);
     }
  }
  int sum=0;
  rep(i,5){
      if(A[i]%10==0){
          sum+=A[i];
      }
      else{
          sum+=A[i]+10-A[i]%10;
      }
      
  }
  sum-=10-mod;
  
  cout<<sum<<endl;
}

Measured memory_bytes: 3640
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

H1, M1, H2, M2, K = read_ints()


minu = H2 * 60 + M2 - (H1 * 60 + M1)

# K分勉強したいだけであって開始地点はいつでもいい

print((minu - K))


Measured memory_bytes: 65124
n, x = [int(i) for i in input().split()]

while not (n == 0 and x == 0):
    test = [[i,j,k] for i in range(1, n+1) for j in range(i+1, n+1) for k in range(j+1, n+1) if i + j + k == x]
    print(len(test))
    n, x = [int(i) for i in input().split()]


Measured memory_bytes: 5812
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl

void solve() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  for (auto &it: arr) {
    cin >> it;
  }
  ll mx = arr[0];
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (mx > arr[i]) {
      ans += mx - arr[i];
    }
    mx = max(mx, arr[i]);
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll test = 1;
  //cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}



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

bool isAbleTravel();

int main()
{
  int count;
  cin >> count;
  string result = "Yes";
  for(int i = 0; i < count; i++)
  {
    if(!isAbleTravel())
      result = "No";
  }
  cout << result;
  return 0;
}
bool isAbleTravel()
{
  int dest, x, y;
  cin >> dest >> x >> y;

  if((x + y) % 2 != dest % 2)
    return false;
  if(x + y > dest)
    return false;
  return true;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#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 <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
double ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

ll cost[202020];
void dfs(ll pos,ll old,ll num){
    num += cost[pos];
    cost[pos]=num;
    rep(i,0,graph[pos].size()){
        if(graph[pos][i].to != old){
            dfs(graph[pos][i].to,pos,num);
        }
    }
    return;
}
int main(){
    cin>>N>>Q;
    graph = AdjList(N);
    rep(i,0,N-1){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        graph[a[i]].push_back(Edge{b[i],1});
        graph[b[i]].push_back(Edge{a[i],1});
    }
    rep(i,0,Q){
        cin>>p[i]>>x[i];
        p[i]--;
        cost[p[i]]+=x[i];
    }
    dfs(0,0,0);
    rep(i,0,N-1){
        cout<<cost[i]<<" ";
    }
    cout<<cost[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 37376
#include <iostream>

int memo[100][100][100][100] = {0};

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

int main() {

    int a, b, c, x;
    std::cin >> a >> b >> c >> x;

    int result = f(a, b, c, x);
    std::cout << result << std::endl;

    return 0;
}


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

int main()
{
 string a,b,c;
 cin  >>a>>b>>c;
 
 int s1=a.size()-1;
 int s2=b.size()-1;
 int s3=c.size()-1;

 if(a[s1]==b[0]&&b[s2]==c[0]){cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}

return 0;}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

var dp [103][100010]int

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	w := make([]int, n+2)
	v := make([]int, n+2)
	for i := 0; i < n; i++ {
		w[i] = nextInt()
		v[i] = nextInt()
	}

	for i := 1; i <= n+1; i++ {
		for j := 0; j <= k; j++ {
			if j >= w[i-1] {
				take := dp[i-1][j-w[i-1]] + v[i-1]
				notake := dp[i-1][j]
				dp[i][j] = max(take, notake)
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}

	fmt.Println(dp[n][k])
	//fmt.Println(dp)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 80720
#include<bits/stdc++.h>
using namespace std;
long long euclid(long long a, long long b){
    while(1){
        a%=b;
        if(!a) break;
        swap(a,b);
    }
    return b;
}
int main(){
    long long A,B;
    cin >> A >> B;
    long long gcd;
    gcd = euclid(A,B);
    long long ans=1;
    long long G=gcd;
    long long divnum;
    long long div=2;
    if(gcd%div==0){
            ans++;
            while(1){
                gcd/=div;
                if(gcd%div) break;
            }
            
        }
    for(div=3; div<=gcd; div+=2){
        if(div*div>gcd){
            ans++;
            break;
        }
        if(gcd%div==0){
            ans++;
            while(1){
                gcd/=div;
                if(gcd%div) break;
            }
            
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>

typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_

#define BIG 10000000000 //10

#define LAST 10000000 //10^7

int main(void) {
	int N;
	cin >> N;
	vector<string> S(N);
	vector<int> C(4);

	for (int n = 0; n < N; n++) {
		cin >> S[n];
		if (S[n] == "AC") {
			C[0]++;
		}
		else if (S[n] == "WA") {
			C[1]++;
		}
		else if (S[n] == "TLE") {
			C[2]++;
		}
		else if (S[n] == "RE") {
			C[3]++;
		}
	}

	cout << "AC x " << C[0] << endl;
	cout << "WA x " << C[1] << endl;
	cout << "TLE x " << C[2] << endl;
	cout << "RE x " << C[3] << endl;
	return 0;
}


Measured memory_bytes: 6300
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val n = new BufferedReader(new InputStreamReader(System.in)).readLine().toLong
    val sqrt_of_n = Math.sqrt(n).toLong

    System.out.println(
      (sqrt_of_n to 2 by -1).find(d => n % d == 0) match {
        case Some(d) => n / d + d - 2L
        case None => n + 1L - 2L
      }
    )
  }
}


Measured memory_bytes: 37656
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int k = sc.nextInt();
		char main = s.charAt(k-1);
		String p = "";
		for(int i = 0;i < s.length();i ++) {
			char c = s.charAt(i);
			if(c != main) p += "*";
			else p += c;
		}
		System.out.println(p);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (k and b <= a)
		b *= 2, --k;
	while (k and c <= b)
		c *= 2, --k;
	//cout << a << " " << b << " " << c << endl;
	if (a < b and b < c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3612
import math

def is_prime(x):
  if x<=1:
    return True
  else:
    for i in range(2,int(math.sqrt(x))+1):
      if x%i==0:
        return True
    return False
      

X = int(input())
x=X

while(is_prime(x)):
  x+=1

print(x)

Measured memory_bytes: 2940
import heapq
import math

def main():
    N, M = [int(i) for i in input().split()]
    L = [float(i) * -1 for i in input().split()]

    heapq.heapify(L)

    for _ in range(M):
        max = heapq.heappop(L) * -1
        discounted = max / 2
        heapq.heappush(L, discounted*-1)
    
    floor_L = [math.floor(-i) for i in L]
    print(sum(floor_L))

if __name__ == "__main__":
    main()

Measured memory_bytes: 13640
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
using namespace std;

typedef vector<vector<char> > vvchar;


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


int solve(int n, const string *a){
	vvchar def(n + 2, vector<char>(n + 2));
	vvchar v1 = def;

	int at = -1;
	int st = 0;
	int bit = 1;
	for(int y = 0; y < n; ++y){
		for(int x = 0; x < n; ++x){
			if( a[y][x] == '@' ){
				at = (y + 1) << 3 | (x + 1);
			}
			else if( a[y][x] == '#' ){
				v1[y + 1][x + 1] = 1;
				st |= bit;
			}

			bit <<= 1;
		}
	}
	
	if( st == 0 ){	return 0;	}

	queue<int> q;
	q.push(st | (at << 25));
	q.push(-1);

	set<int> visit;
	visit.insert( q.front() );

	int t = 1;
	while( q.size() > 1 ){
		st = q.front();
		q.pop();
		
		if( st < 0 ){
			++t;
			q.push(-1);
		}
		else{
			v1 = def;
			int atx = (st >> 25) & 7;
			int aty = (st >> 28) & 7;

			int mask = 1;
			for(int y = 1; y <= n; ++y){
				for(int x = 1; x <= n; ++x){
					if( st & mask ){
						v1[y][x] = 1;
					}
					mask <<= 1;
				}
			}

			for(int i = 0; i < 8; ++i){
				int ny = aty + dy[i];
				int nx = atx + dx[i];
				if( ny <= 0 || ny > n || nx <= 0 || nx > n ){
					continue;
				}
				if( v1[ny][nx] != 0 ){
					continue;
				}

				v1[ny][nx] = 2;

				int nst = 0;
				bit = 1;
				for(int y = 1; y <= n; ++y)
				for(int x = 1; x <= n; ++x){
					int cnt = 0;

					for(int j = 0; j < 8; ++j){
						if( v1[y + dy[j]][x + dx[j]] ){
							++cnt;
						}
					}

					if( v1[y][x] == 0 ){
						if( cnt == 3 ){
							nst |= bit;
						}
					}
					else if( v1[y][x] == 1 ){
						if( cnt == 2 || cnt == 3 ){
							nst |= bit;
						}
					}
					
					bit <<= 1;
				}

				v1[ny][nx] = 0;

				if( nst == 0 ){
					return t;
				}
				
				nst |= ny << 28 | nx << 25;
				if( visit.insert(nst).second ){
					q.push(nst);
				}
			}
		}
	}

	return -1;
}

int main(){
	int n;
	string a[5];

	while( cin >> n, n != 0 ){
		for(int i = 0; i < n; ++i){
			cin >> a[i];
		}

		cout << solve(n, a) << '\n';
	}
}

Measured memory_bytes: 1484
#include <stdio.h>
int main(void){
    int x,n,sum,i,j,k;
    while(1){
        scanf("%d %d",&n,&x);
        int count = 0;
        if(n==0 && x==0){
            break;
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                for(k=1;k<=n;k++){
                    sum =i+j+k;
                    if(i<j && j<k &&x==sum){
                        count++;
                    }
                }
            }
        }
        printf("%d\n",count);
       
    }
    return 0;
}



Measured memory_bytes: 2084
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
  int tmp;

  cin >> tmp;
  if (tmp >= 30)
  {
    cout << "Yes"
         << "\n";
  }
  else
  {
    cout << "No"
         << "\n";
  }

  return 0;
}

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

int main()
{
  int N, K;
  int h[110000];
  int res=0;
  cin >> N >> K;

  rep(i,N) cin >> h[i];

  rep(i,N){
    if(h[i]>=K) res++;
  }
  
  cout << res << endl;
}



Measured memory_bytes: 640
// 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

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

		if(n==0)
			break;

		int T[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(i==j){
					T[i][j] = 0;
				}
				else{
					T[i][j] = INF;
				}
			}
		}

		int m = 0;		

		for(int i=0; i<n; i++){
			int a, b, c;
			cin >> a >> b >> c;

			T[a][b] = T[b][a] = c;

			if(a+1>m){
				m = a+1;
			}
			if(b+1>m){
				m = b+1;
			}
		}
//???????????§???????????????
//????????????????????????
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
					}
				}
			}
		}
//????°???????????????¢???
		int town;//????????????
		int x=INF;//????????????
		for(int i=0;i<m;i++){
			int r=0;//i?????§???????????????
			for(int j=0;j<m;j++){
				r=r+T[i][j];
			}
			if(r<x){
				x=r;
				town=i;
			}
		}
		cout<<town<<' '<<x<<endl;

	}

	return 0;
}

Measured memory_bytes: 3012
from collections import defaultdict
import bisect
S = input()
T = input()

d = defaultdict(list)

for i, s in enumerate(S):
    d[s].append(i)

ans = 0
now = -1
for t in T:
    arr = d[t]
    if len(arr) == 0:
        print(-1)
        exit()
    idx = bisect.bisect_right(arr, now)
    if idx == len(arr):
        ans += 1
        now = arr[0]
    else:
        now = arr[idx]
print(ans * len(S) + now + 1)

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    set<ll> A;
    rep(i,N){
        ll AI;
        cin >> AI;
        if(A.find(AI)==A.end()){
            A.insert(AI);
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

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

#define PUTLINE cout<<__LINE__<<endl;

class Team{
public:
	int i,u,a,p;
	bool operator<(Team team)const{return a>team.a?true:a<team.a?false:p<team.p?true:p>team.p?false:i<team.i;}
};

Team teams[310];
int uni[1100];

int main() {
	for(;;){
		int n;
		memset(uni,0,sizeof(uni));
		cin>>n;
		if(n==0)break;
		rep(i,n)cin>>teams[i].i>>teams[i].u>>teams[i].a>>teams[i].p;
		sort(teams,teams+n);
		int clear=0;
		rep(i,n){
			if(clear<10){
				if(uni[teams[i].u]<3){
					cout<<teams[i].i<<endl;
					clear++;
					uni[teams[i].u]++;
				}
			}else if(clear<20){
				if(uni[teams[i].u]<2){
					cout<<teams[i].i<<endl;
					clear++;
					uni[teams[i].u]++;
				}
			}else if(clear<26){
				if(uni[teams[i].u]<1){
					cout<<teams[i].i<<endl;
					clear++;
					uni[teams[i].u]++;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

const int MaxN = 3e5;
typedef long long LL;
typedef unsigned long long ULL;

LL ans,n,sum;
LL f[MaxN + 5],e[MaxN + 5],a[MaxN + 5];

priority_queue<LL>q2;
priority_queue<LL,vector<LL>,greater<LL> >q1;

int main(){
	ans = -(1LL << 60);
	cin >> n;
	for(int i = 1;i <= 3*n;i++){
		cin >>a[i];
	}
	for(int i = 1;i <= 3*n;i++){
		q1.push(a[i]);
		sum += a[i];
		f[i] = sum;
		if(q1.size() > n){
			sum -= q1.top();
			f[i] = sum;
			q1.pop();
		}
	}
	sum = 0;
	for(int i = 3*n;i >= 1;i--){
		q2.push(a[i]);
		sum += a[i];
		e[i] = sum;
		if(q2.size() > n){
			sum -= q2.top();
			e[i] = sum;
			q2.pop();
		}
	}
	for(int i = n;i <= n*2;i++){
		ans = max(ans,f[i] - e[i + 1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>

using namespace std;


int main() {
  int n;
  scanf("%d", &n);

  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i]);
  }

  int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += (d[i] * d[j]);
    }
  }
  cout << sum << endl;
}


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

int main(void)
{
	char s[101];
	
	while(scanf("%s", s) != EOF) {
		long long int sum = 0;
		int i;
		
		for(i = 0; i < strlen(s); i++) {
			switch(s[i]) {
				case 'I': {
					if(s[i + 1] == 'V') sum += 4;
					else if(s[i + 1] == 'X') sum += 9;
					else sum += 1;
				} break;
				case 'V': {
					if(s[i - 1] == 'I') continue;
					else sum += 5;
				} break;
				case 'X': {
					if(s[i - 1] == 'I') continue;
					if(s[i + 1] == 'L') sum += 40;
					else if(s[i + 1] == 'C') sum += 90;
					else sum += 10;
				} break;
				case 'L': {
					if(s[i - 1] == 'X') continue;
					else sum += 50;
				} break;
				case 'C': {
					if(s[i - 1] == 'X') continue;
					if(s[i + 1] == 'D') sum += 400;
					else if(s[i + 1] == 'M') sum += 900;
					else sum += 100;
				} break;
				case 'D': {
					if(s[i - 1] == 'C') continue;
					sum += 500;
				} break;
				case 'M': {
					if(s[i - 1] == 'C') continue;
					sum += 1000;
				} break;
			}
		}
		printf("%lld\n", sum);
	}
	
	return 0;
}


Measured memory_bytes: 540
using System;
using System.Text;

class Program
{
    static void Main()
    {
        new Program().Solve();
    }

    public void Solve()
    {
        string s = Console.ReadLine();
        int k = int.Parse(Console.ReadLine());
        var t = new StringBuilder();
        for (int i = 0; i < s.Length; i++)
        {
            if (i == s.Length - 1)
            {
                t.Append((char) ((s[i] - 'a' + k) % 26 + 'a'));
                k = 0;
            }
            else if (s[i] == 'a')
            {
                t.Append('a');
            }
            else if ('z' + 1 - s[i] <= k)
            {
                t.Append('a');
                k -= 'z' + 1 - s[i];
                if (k == 0) break;
            }
            else
            {
                t.Append(s[i]);
            }
        }
        if (t.Length < s.Length) t.Append(s.Substring(t.Length));
        Console.WriteLine(t);
    }
}

Measured memory_bytes: 13288
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n, x;
	cin >> n >> x;
	vector<ll> b(n), l(n), r(n);
	ll res = 0;
	vector<pair<ll, ll>> a(n);
	rep(i, n) {
		cin >> b[i] >> l[i] >> r[i];
		res += b[i] * l[i];
		a[i].first = (x - b[i]) * r[i] + b[i] * l[i];
		a[i].second = i;
	}
	if (res == 0) {
		cout << 0;
		return 0;
	}
	sort(rall(a));
	vector<ll> ps(n + 1);
	rep(i, n)
		ps[i + 1] = ps[i] + a[i].first;
	int mc = 0;
	while (ps[mc] < res)
		mc++;
	ll ans = mc * x;
	rep(i, n) {
		int j = a[i].second;
		ll cs = (mc - 1 <= i ? ps[mc - 1] : ps[mc] - a[i].first);
		if (cs + b[j] * l[j] >= res)
			ans = min(ans, (res - cs + l[j] - 1) / l[j] + (mc - 1) * x);
		else if (cs + b[j] * l[j] + (x - b[j]) * r[j] >= res) {
			ans = min(ans, (res - cs - b[j] * l[j] + b[j] * r[j] + r[j] - 1) / r[j] + (mc - 1) * x);
		}
	}
	cout << ans;
}

Measured memory_bytes: 6272
# -*- coding: utf-8 -*-


def main():
    s = input()
    k = int(input())

    prev = s[0]
    count = 1
    pair = list()

    # 文字と連続する回数を数える
    for cur in s[1:]:
        if cur == prev:
            count += 1
        else:
            pair.append((prev, count))
            prev = cur
            count = 1

    if count >= 1:
        pair.append((prev, count))

    # Sの文字が1種類かどうか
    if len(pair) == 1:
        print(len(s) * k // 2)
    else:
        first = pair[0]
        last = pair[-1]
        ans = 0

        # 両端が同じ文字の種類
        if first[0] == last[0]:
            for a, count in pair[1:-1]:
                ans += count // 2

            print(ans * k + first[1] // 2 + last[1] // 2 + (first[1] + last[1]) // 2 * (k - 1))
        else:
            for a, count in pair:
                ans += count // 2

            print(ans * k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            Console.WriteLine(!s.Where((c, i) => (i + 1) % 2 == 1).Contains('L') && !s.Where((c, i) => (i + 1) % 2 == 0).Contains('R') ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int main(void)
{
	int s=0,h=0,ft=0,t=0,f=0,o=0,money=1000,genkin,sum=0;
	scanf("%d",&genkin);
	while(genkin!=0){
	money=money-genkin;
	s=money/500;
	money=money-s*500;
	h=money/100;
	money=money-h*100;
	ft=money/50;
	money=money-ft*50;
	t=money/10;
	money=money-t*10;
	f=money/5;
	money=money-f*5;
	o=money/1;
	sum=s+h+ft+t+f+o;
	printf("%d\n",sum);
	sum=0;
	money=1000;
	scanf("%d",&genkin);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;

const int maxn = 4e5+5;
const int mod =  1e9 + 7;
int arr[maxn];

struct Bit_Tree {
	int bit[maxn] = {};
	
	void upd(int x,int val) {
		for (int i = x; i < maxn; i += lowbit(i)) bit[i] = (bit[i] + val) % mod;
	}	
	
	int qry(int l) {
		int ret = 0;
		for (int i = l; i; i -= lowbit(i)) ret = (ret + bit[i]) % mod;
		return ret;	
	}	
} bit;

main() {
	IOS
	int n, k;
	cin >> n >> k;
	k++;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	bit.upd(1, 1);
	bit.upd(min(k, 1 + arr[1]) + 1, -1);
	for (int i = 2; i <= n; i++) {
		if (arr[i] == 0) continue;
		for (int j = k; j >= 1; j--) {
			int val = bit.qry(j);
			int r = min(j + arr[i], k) + 1;
//			cout << j << " " << r << " " << val << "\n";
			bit.upd(j, val);	 
			bit.upd(r, -val + mod);
			bit.upd(j, -val + mod);
			bit.upd(j+1, val);
//			cout << val << " ";
		}	
//		cout << "\n"; 
	}
//	for (int i = 1; i <= k; i++) cout << bit.qry(i) << " \n"[i==k];
	
	cout << bit.qry(k) << "\n";
	
}



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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int r;
	cin >> r;
    cout<<3*r*r;
	return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

N,K = map(int,input().split(' '))
S = list(input())

pre = ''
cnt = 0
f = False
K_cnt = 0

for i in range(N):
    k = S[i]
    if pre==k:
        cnt += 1
        #flag立っていてかつ最後までそんまま
        if i==N-1:
            if K_cnt<K:
                if f:
                    cnt += 1
    else:
        if f:
            if K_cnt<K:
                cnt += 2
                K_cnt += 1
                f = False
        else:
            if not i==0:
                f = True
                if i==N-1:
                    if K_cnt<K:
                            cnt += 1
    pre = k
print(cnt)

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

int main(void){
  string s;
  cin >> s;
  s = s.substr(5, 2);
  if(s[5] == '1') cout << "TBD" << endl;
  else{
    if(s[6] == '4' || s[6] == '3' || s[6] == '2' || s[6] == '1') cout << "Heisei" << endl;
    else cout << "TBD" << endl;
  }
  return 0;
}


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

int lis(vector<int> A) {
    int length = 0;
    vector<int> L;
    L.push_back(-1);
    for (int i = 0; i < A.size(); i++) {
        if (L[length] < A[i]) {
            L.push_back(A[i]);
            length++;
        } else {
            vector<int>::iterator it = lower_bound(L.begin(), L.end(), A[i]);
            *it = A[i];
        }
    }

    return length;
}

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

    cout << lis(A) << endl;

    return 0;
}


Measured memory_bytes: 4408
#include <iostream>
#include <string>
using namespace std;
 
int main(void){

  
  int n,m;
 // string s;
  
  cin >> n >> m;
 // cin >> s;
  


  cout << (n*(n-1)/2) + (m*(m-1)/2) << endl;
  
  return 0;
}

Measured memory_bytes: 256