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

using namespace std;

int main()
{
    int n;
    int m;
    int total = 0;
    
    cin >> n >> m;
    
    int arr[n];
    
	for(int i = 0;i < n;i++){
	    cin >> arr[i];
	    total += arr[i];
	}
	int count = 0;
	while(n--){
		if(arr[n]*4*m >= total){
		    count++;
		}
	}
	
	(count >= m)?cout << "Yes": cout << "No";
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

x3 = (x2  - (y2-y1))
y3 = (y2  + (x2-x1))
x4 = (x3  - (x2-x1))
y4 = (y3  - (y2-y1))

print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;
 
int main() {
    int n,m;
    cin >> n >> m;
    int ans=n*(n-1)/2+m*(m-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#ABC 147 C 「Honest or Unkind」

n=int(input())
ans=0
A=[[] for _ in range(n)]

for i in range(n):
    a=int(input())
    for j in range(a):
        A[i].append(tuple(map(int,input().split())))
        
#-------------------------------------------------------------iをn桁２進数表記（[2:]で0bを切って、zfill()で左揃えへ）
for i in range(2**n):
    ii=str(bin(i))[2:].zfill(n)
#-------------------------------------------------------------#i個目の場合が証言をみたすか調べる：2**n個の組み合わせ
    chk=True
    cur=0
 
    for j in range(n):                                        #j個目の証言を満たすか調べる        
        if ii[j]=="0":
            continue
        else:
            cur+=1                                            #Count up 
            for x,y in A[j]:                                  #turpleで(x,y)を指定する
                if y==1 and ii[x-1]=="0":                     #Aとiiを比較
                    chk=False                                 #違っていたらFalseへ
                elif y==0 and ii[x-1]=="1":
                    chk=False
    if chk:                                                   #もしChk = Trueのままだったらn個全ての証言をみたすので、これまでのマックスと比べる
        ans=max(ans,cur)
print(ans)

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

int main(){
  string S;
  cin >> S;

  if(S == "Sunny")
    cout << "Cloudy" << endl;
  else if(S == "Cloudy")
    cout << "Rainy" << endl;
  else if(S == "Rainy")
    cout << "Sunny" << endl;

  return 0;
}

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

int main(void)
{
  int a, b, c;
  cin >> a >> b >> c;
  if(a < b && b < c)
    {
      cout << "Yes" << endl;
    }else
    {
      cout << "No" << endl;
    }
  return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;

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

        int n_row = sc.nextInt();
        int n = n_row % 10;

        if(n == 0 || n == 1 || n == 6 || n == 8){
            System.out.println("pon");
        }else if(n == 3){
            System.out.println("bon");
        }else{
            System.out.println("hon");
        }
    }
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, M, K; cin >> N >> M >> K;
        bool ok = false;
        rep(x, M + 1) {
            rep(y, N + 1) {
                ok |= N * x + M * y - 2 * x * y == K;
            }
        }
        cout << (ok ? "Yes" : "No") << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct LazySegmentTree {
private:
    int n;
    vector<ll> node,lazy;
    vector<bool> upd;
public:
    LazySegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        upd.resize(2*n-1,false);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[i*2+1],node[i*2+2]);
    }

    void eval(int k,int l,int r) {
        if (upd[k]) {
            node[k] = lazy[k];
            if (r-l > 1) {
                lazy[2*k+1] = lazy[2*k+2] = lazy[k];
                upd[2*k+1] = upd[2*k+2] = true;
            }
            lazy[k] = 0;
            upd[k] = false;
        }
    }

    void update(int a,int b,ll x,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        eval(k,l,r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = x;
            upd[k] = true;
            eval(k,l,r);
        } else {
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
    }

    ll getmin(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return INT64_MAX;
        eval(k,l,r);
        if (a <= l && r <= b) return node[k];
        ll vl = getmin(a,b,k*2+1,l,(l+r)/2);
        ll vr = getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    LazySegmentTree seg(vector<ll>(n,INT_MAX));
    for (int i = 0;i < q;++i) {
        int c,s,t;
        cin >> c >> s >> t;
        if (c) cout << seg.getmin(s,t+1) << endl;
        else {
            int x;
            cin >> x;
            seg.update(s,t+1,x);
        }
    }
    return 0;
}


Measured memory_bytes: 7876
package main
import "fmt"

func main(){
  var r int
  var D int
  var weight int
  var weight_next int

  fmt.Scan(&r)
  fmt.Scan(&D)
  fmt.Scan(&weight)

  for i:= 0; i < 10; i++ {
    weight_next = r * weight - D
    weight = weight_next
    fmt.Printf("%d\n", weight)
  }
}

Measured memory_bytes: 512
//============================================================================
// Name        : ITP_1_4_A.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
//	cout << a/b << " " << a%b << " " << (float)a/(float)b << endl;
	printf("%d %d %.5lf",a/b,a%b,(double)a/(double)b);
	return 0;
}

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

const int INF=1<<30;
int N;
long long K;
int A[200000];

signed main() {
  cin >> N >> K;
  for(int i=0; i<N; i++) { cin >> A[i]; A[i]--;} 

  vector<int> distance(200000, INF);
  distance[0] = 0;
  int current = 0;
  int d = 0;
  for(int i=0; i<N; i++) {
    int prev = current;
    current = A[prev];
    d++;
    if(distance[current] != INF) break;
    distance[current] = d;
    if(d == K) {
      cout << current + 1<< endl;
      return 0;
    }
  }

  //cerr << d << " " << current << " " << distance[current] << endl;
  int loop_size = d - distance[current];
  K -= d;
  K = K % loop_size;

  while(K--) {
    int prev = current;
    current = A[prev];
  }
  cout << current+1 << endl;
}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long

int gcd(int n,int m){return !m?n:gcd(m,n%m);}
int lcm(int n,int m){return n*m/gcd(n,m);}

signed main(){
    int N,M;
    string s,t;
    cin>>N>>M>>s>>t;

    int m = M / gcd(M,N);//L/N
    int n = N / gcd(M,N);//L/M

    rep(i,gcd(N,M)){
        if(s[i*n] != t[i*m]){
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<lcm(N,M)<<endl;

}

Measured memory_bytes: 512
#include<stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>
 
using namespace std;
 
#define BUF_SIZE 1024
 
struct Node{
    int data;
    Node* prev;
    Node* next;
};
 
class ConnectedList{
public:
    ConnectedList(){
        motherNode = new Node();
        motherNode->data = -1;
        motherNode->prev = motherNode;   
        motherNode->next = motherNode;
    };
    ~ConnectedList(){
        Node* tmpNode = motherNode->next;
        Node* nextNode;
        while(tmpNode != motherNode){
            nextNode = tmpNode->next;
            delete tmpNode;
            tmpNode = nextNode;
        }
        delete motherNode;
    };
    void insertNode(int x){
        Node* tmpNode = motherNode->next;
        motherNode->next = new Node();
        motherNode->next->data = x;
        motherNode->next->next = tmpNode;
        motherNode->next->prev = motherNode;
        tmpNode->prev = motherNode->next;
    };
    void deleteNode(int x){
        Node* tmpNode = motherNode->next;
        while(tmpNode != motherNode && tmpNode->data != x){
            tmpNode = tmpNode->next;
        }
        if(tmpNode != motherNode){  
            tmpNode->prev->next = tmpNode->next;
            tmpNode->next->prev = tmpNode->prev;
            delete tmpNode;
        }
    };
 
    void deleteFirst(){
        Node* tmpNode = motherNode->next;
        motherNode->next = motherNode->next->next;
        motherNode->next->prev = motherNode;
        delete tmpNode; 
    };
 
    void deleteLast(){
        Node* tmpNode = motherNode->prev;
        motherNode->prev = motherNode->prev->prev;
        motherNode->prev->next = motherNode;
        delete tmpNode; 
    };
 
    void showList(){
        Node* tmpNode = motherNode->next;
        printf("%d",tmpNode->data);
        tmpNode = tmpNode->next;
        while(tmpNode != motherNode){
            printf(" %d",tmpNode->data);
            tmpNode = tmpNode->next;
        }
        printf("\n");
    }
 
private:
    Node* motherNode;
};
 
 
int main(){
 
    char buf[BUF_SIZE];
    int n = atoi(fgets(buf,BUF_SIZE,stdin));
 
    ConnectedList list;
 
    for(int i = 0; i < n; i++){
 
        fgets(buf,BUF_SIZE,stdin);
 
        if(buf[6] == 'F'){
            list.deleteFirst();
        }else if(buf[6] == 'L'){
            list.deleteLast();
        }else{
            int S = 0;
             
            if(buf[0] == 'i'){  //insert x
 
                for(int i = 0; buf[i] != '\0';i++){
                    if(buf[i] >= '0' && buf[i] <= '9'){
                        S = 10*S + (buf[i] - '0');
                    }
                }
                list.insertNode(S);
            }else{  
                for(int i = 0;buf[i] != '\0';i++){
                    if(buf[i] >= '0' && buf[i] <= '9'){
                        S = 10*S + (buf[i] - '0');
                    }
                }
                list.deleteNode(S);
            }
 
        }
 
    }
 
    list.showList();
 
}



Measured memory_bytes: 34364
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t S;
  cin >> S;
  int64_t t = static_cast<int64_t>(sqrt(static_cast<double>(S)));
  ++t;
  const int64_t x1 = 1e9L;
  const int64_t y2 = (S + (x1 - 1)) / x1;
  const int64_t x2 = 1;
  const int64_t y1 = x1 * y2 - S;
  cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
  // const int64_t L = static_cast<int64_t>(T.length());
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main() {

    string num;
    cin>>num;

    bool contains7 = false;
    for (int i = 0; i < num.length(); i++)
        if (num[i] == '7')
            contains7 = true;

    if (contains7)
        cout<<"Yes\n";
    else cout<<"No\n";
    

    return 0;
}

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

int h,w;
int cnt = 0;

bool f(vector<vector<char>> &a, int i = 0, int j = 0) {
  cnt++;
  if (i == h-1 && j == w-1) return true;

  if (i+1 < h && j+1 && w && 
      a[i+1][j] == '#' && a[i][j+1] == '#') return false;

  bool fi = false, fj = false;
  if (i+1 < h && a[i+1][j] == '#') {
    fi = f(a, i+1, j);
  }
  if (j+1 < w && a[i][j+1] == '#') {
    fj = f(a, i, j+1);
  }

  if (fi || fj) return true;
  return false;
}

int main() {
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  int tot = 0;
  rep(i,h) rep(j,w) {
    cin >> a[i][j];
    if (a[i][j] == '#') tot++;
  }
  string ans = "Impossible";
  if (f(a) && cnt == tot) ans = "Possible";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n;
string s;

int main() {
	cin >> n >> s;
	
	RF(e, s) {
		int x = e - 'A';
		(x += n) %= 26;
		e = x + 'A';
	}
	
	cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
using namespace std;
static const int MAX_H = 10;

int h, w;
string s[MAX_H];

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

int main(){
	for(;;){
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0) break;
		for(int i = 0; i < h; i++) cin >> s[i];
		map<string, int> mpa;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				int sy = i;
				int sx = j;
				for(int k = 0; k < 8; k++){
					int cy = i;
					int cx = j;
					string str;
					str += s[sy][sx];
					mpa[str]++;
					for(;;){
						cy += dy[k];
						cx += dx[k];
						cy = (cy + h) % h;
						cx = (cx + w) % w;
						if(cy == sy && cx == sx) break;
						str += s[cy][cx];
						mpa[str]++;
					}
				}
			}
		}
		string res = "0";
		for(map<string, int>::iterator itr = mpa.begin(); itr != mpa.end(); itr++){
			if(itr->second < 2 || itr->first.length() < 2) continue;
			if(itr->first.length() > res.length() || (itr->first.length() == res.length() && itr->first < res)) res = itr->first;
		}
		cout << res << endl;
	}
}



Measured memory_bytes: 38100
#include <stdio.h>

int main() {
  int A, B, C, X;
  scanf("%d%d%d%d", &A, &B, &C, &X);
  
  int count = 0;
  
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        int total = 500 * i + 100 * j + 50 * k;
        if (total == X) count++;
      }
    }
  }
  
  printf("%d\n", count);	  
}

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

using namespace std;

int main()
{

int a,b;

cin>>a>>b;

string str="";
int num=0;
int c=1;

if(a==b){
    for(int i=0; i<a; i++){
    num+=(c*a);
    c*=10;
    }
}

else if(a>b){
    for(int i=0; i<a; i++){
    num+=(c*b);
    c*=10;
    }
}

else
{
    for(int i=0; i<b; i++){
    num+=(c*a);
    c*=10;
    }
}

cout<<num<<endl;


    return 0;
}


Measured memory_bytes: 256
x = int(input())
D = []
for i in range(x):
    d = int(input())
    D.append(d)
k = []
count = 1
d = max(D)
k.append(d)
D.remove(d)
for j in range(x-1):
    c = max(D)
    if c < d:
        k.append(c)
        d = c
        count += 1
    D.remove(c)

print(count)

Measured memory_bytes: 9064
function main()
    n = parse(Int64, readline())
    ary = map(x -> parse(Int64, x), split(readline()))
    ary = sort(ary, rev = true)
    #println(ary)

    alice = 0; bob = 0
    for i in 1:n
        if i % 2 != 0
            alice += ary[i]
        else
            bob += ary[i]
        end
    end
    println(alice - bob)
end

main()


Measured memory_bytes: 118384
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int K = sc.nextInt();
		long[] a = new long[x];
		long[] b = new long[y];
		long[] c = new long[z];
		for (int i = 0; i < x; i++) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i < y; i++) {
			b[i] = sc.nextLong();
		}
		for (int i = 0; i < z; i++) {
			c[i] = sc.nextLong();
		}
		sc.close();
 
		Arrays.parallelSort(a);
		Arrays.parallelSort(b);
		Arrays.parallelSort(c);

		PriorityQueue<Obj> pq = new PriorityQueue<Obj>(new Comparator<Obj>() {
			public int compare(Obj o1, Obj o2) {
				if (o1.v < o2.v) return 1;
				if (o1.v > o2.v) return -1;
				return 0;
			}
		});
		Set<Long> set = new HashSet<Long>();

		int ia = x - 1;
		int ib = y - 1;
		int ic = z - 1;
		Obj fo = new Obj(ia, ib, ic, a[ia] + b[ib] + c[ic]);
		pq.add(fo);
		long fl = ia * 10000L * 10000L + ib * 10000L + ic;
		set.add(fl);

		for (int i = 0; i < K; i++) {
			Obj obj = pq.poll();
			System.out.println(obj.v);
			ia = obj.a;
			ib = obj.b;
			ic = obj.c;
			if (ia > 0) {
				Obj o = new Obj(ia - 1, ib, ic, a[ia - 1] + b[ib] + c[ic]);
				if (!set.contains(o.key)) {
					pq.add(o);
					set.add(o.key);
				}
			}
			if (ib > 0) {
				Obj o = new Obj(ia, ib - 1, ic, a[ia] + b[ib - 1] + c[ic]);
				if (!set.contains(o.key)) {
					pq.add(o);
					set.add(o.key);
				}
			}
			if (ic > 0) {
				Obj o = new Obj(ia, ib, ic - 1, a[ia] + b[ib] + c[ic - 1]);
				if (!set.contains(o.key)) {
					pq.add(o);
					set.add(o.key);
				}
			}
		}
	}

	static class Obj {
		int a, b, c;
		long v, key;
		Obj(int a, int b, int c, long v) {
			this.a = a;
			this.b = b;
			this.c = c;
			this.v = v;
			this.key = a * 10000L * 10000L + b * 10000L + c;
		}
	}
}


Measured memory_bytes: 29952
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    int ans = 0;
    for(int i = 1; i < n; i++) {
        ans += s[i] == s[i-1];
    }
    cout << min(ans + 2 * k, n - 1) << endl;
    return 0;
}


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

long long MOD = 1000000007;

int main() {
    string S;
    cin >> S;
    long long K;
    cin >> K;

    int cnt = 0;
    int a = 0;
    for ( int i = 0; i < S.length(); i++ ) {
        if ( S[i] == '1' ) { cnt++; }
        else { a = S[i]-'0'; break; }
    }

    if ( K <= cnt ) { cout << 1 << endl; }
    else { cout << a << endl; }

    return 0;
}

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

using namespace std;

char str[110],f[110][110];
int n;

int solve(int maxx)
{
	for(int i=1;i<=n;i++)f[1][i]=str[i];
	int size=n;
	for(int i=1;i<=n;i++)
	{
		bool flag=true;
		for(int j=2;j<=size;j++)
		{
			if(f[i][j]!=f[i][j-1])flag=false;
		}
		if(flag)
		{
			return i-1;
		}
		for(int j=1;j<size;j++)
		{
			if(f[i][j]==maxx||f[i][j+1]==maxx)f[i+1][j]=maxx;
			else f[i+1][j]=f[i][j];
		}
		size--;
	}
}

int main()
{
	scanf("%s",str+1);
	n=strlen(str+1);
	int ans=1e9;
	for(int i='a';i<='z';i++)ans=min(ans,solve(i));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    string S;
    cin >> S;
    int R = 0;
    int MAXR = 0;

    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == 'R') {
            ++R;
        } else {
            R = 0;
        }

        MAXR = max(MAXR, R);
    }

    cout << MAXR << endl;

    return 0;
}

Measured memory_bytes: 3624
N = int(input())
rc = [list(map(int, input().split())) for _ in range(N)]

DP = [[(0, -1, -1)]*(N) for _ in range(N)]
DP[0] = [(0, r, c) for r, c in rc]

for i in range(1, N):
    for j in range(N-i):
        lis = []
        for k in range(i):
            s, r, c = DP[k][j]
            s2, r2, c2 = DP[i-k-1][j+k+1]
            lis.append((r*c*c2+s+s2, r, c2))
        DP[i][j] = min(lis)
print(DP[-1][0][0])


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

int main(){
  long long n,m;
  cin >> n >> m;
  long long ans;
  if(n>=2&&m>=2){
    ans = (m-2)*(n-2);
  }else if(n==1&&m>=2){
    ans = m-2;
  }else if(m==1&&n>=2){
    ans = n-2;
  }else{
    ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    //変数time, hour, minute, secondを宣言
    int time, hour, minute, second;
    
    //変数timeに値を入力する
    time = sc.nextInt();    
    
    //hour(時間) minute(分) second(秒)の計算
    hour = time / 3600;
    minute = (time % 3600) / 60;
    second = (time % 3600) % 60 ;
    
    //hour(時間) minute(分) second(秒)を出力する
    System.out.println(hour + ":" + minute + ":" + second);
    
    }
}


/*覚えよう！！

・変数に計算結果を代入する：面積　＝　縦　×　横
　※計算は変数名でも数値でもいける

・四則演算：足し算｢＋｣、引き算｢－｣、掛け算｢＊｣、割り算｢／｣
　1 + 2 = 3;
　4 - 3 = 1;
　2 * 5 = 10;
　8 / 2 = 4;

・余りの計算：割り算の余り｢％｣
  5 % 3 = 2;
  
  
・printlnの複数表示：｢＋｣を使用
　例：println("Kobe" + "Kagikou"); = KobeKajikou
　　　println("明治 + 20 + "年"); = 明治20年　数値が入ってもOK！


*/


/*前回の内容！！

・変数の宣言は｢型｣と｢変数名｣の２つ必要
　例：型＿変数名　→　int x;
　
・キーボードから入力するときは・・・｢ import java.util.Scanner; ｣ と ｢  Scanner sc = new Scanner(System.in) ; ｣が必要

・入力するとき・・・変数名 = sc.nextInt(); nextの後は型を書く、頭文字は大文字　
　※  scは変更しても大丈夫しかし全て変更後の文字に統一　例：nyuryoku

・println・・・画面に出力するときに使用

・文字列の表示・・・"〇〇〇の間に入力"ことが約束

*/


Measured memory_bytes: 26224
$n=<>;chomp $n;
@lib = ();
$hash = +{};
for (my $i = 0; $i < $n; $i++) {
    ($name, $point) = split / /, <>;
    push @lib, +{ 'name' => $name, 'point' => $point};
    $hash->{$point} = $i+1;
}

@lib = sort { $a->{name} cmp $b->{name} || $b->{point} <=> $a->{point}} @lib;

foreach my $rest (@lib) {
    print "$hash->{$rest->{point}}\n";
}


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

int main(void){
	int a, b, c, d;
	cin >> a;
	d = a%10;
	a /= 10;
	c = a%10;
	a /= 10;
	b = a%10;
	a /= 10;
	if(a+b+c+d==7){
		cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
		return 0;
	}
	if(a+b+c-d==7){
		cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
		return 0;
	}
	if(a+b-c+d==7){
		cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
		return 0;
	}
	if(a+b-c-d==7){
		cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
		return 0;
	}
	if(a-b+c+d==7){
		cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
		return 0;
	}
	if(a-b+c-d==7){
		cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
		return 0;
	}
	if(a-b-c+d==7){
		cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
		return 0;
	}
	if(a-b-c-d==7){
		cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
		return 0;
	}

}

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

using namespace std;

int d[1111] = { 1 };
int main() {
	int h, w, p = 1e9 + 7;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string a;
		cin >> a;
		for (int j = 0; j < w; j++) {
			if (a[j] == '#') d[j] = 0;
			else if (j) (d[j] += d[j - 1]) %= p;
		}
	}
	cout << d[w - 1] << endl;
	return 0;
}


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

public class Main {

    static int n, k;
    static int[] w;

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        n = sc.nextInt();
        k = sc.nextInt();
        w = new int[n];

        long sum = 0;
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
            sum += w[i];
        }

        System.out.println(solve(sum));
    }

    static int check(long x) {
        int i = 0;
        for (int j = 0; j < k; j++) {
            long sum = 0;
            while (sum + w[i] <= x) {
                sum += w[i];
                i++;
                if (i == n) return n;
            }
        }
        return i;
    }

    static long solve(long sum) {
        long left = 0;
        long right = sum;
        long mid = 0;
        while (left != right-1) {
            mid = (left + right) / 2;
            int cnt = check(mid);
            if (cnt >= n)
                right = mid;
            else
                left = mid;
        }
        return right;
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 43692
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    char a,b;cin>>a>>b;
    if(a==b)cout<<"H"<<endl;
    else cout<<"D"<<endl;
}


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

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f

typedef long long ll;
typedef pair <int, int> pii;
const ll mod=1e9+7;
const int N=1e5+5;

ll n, k;
ll a[102], dp[102][N];

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

  cin >> n >> k;
  for(int i=1; i<=n; i++) cin >> a[i];

  dp[1][0]=1;
  for(int j=1; j<=k; j++){
    if(j<=a[1]) dp[1][j]=1;
    dp[1][j]=(dp[1][j]+dp[1][j-1])%mod;
  }
  ll sum=a[1];
  for(int i=2; i<=n; i++){
    sum+=a[i];
    dp[i][0]=1;
    for(int j=1; j<=k; j++){
      if(j<=sum){
        if(j<=a[i]) dp[i][j]=dp[i-1][j]%mod;
        else dp[i][j]=((dp[i-1][j]-dp[i-1][j-a[i]-1])%mod + mod)%mod;
      }
     dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
    }
  }

  if(k==0) cout << 1 << endl;
  else cout << ((dp[n][k]-dp[n][k-1])%mod+mod)%mod << endl;
}

Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <map>


typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple

using namespace std;
int const N = 200005;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
int main()
{
	ll n;
	cin >> n;
	ll ans = 0;
	for (int a = 1; a <= n; a++)
		for (int b = 1; b <= n; b++)
			for (int c = 1; c <= n; c++)
				ans += gcd(gcd(a, b), c);
	cout << ans;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define sz(x) (int)(x.size())
using namespace std;

long long n, m;

signed main() 
{
    cin >> n >> m;
    long long x[m];
    for (int i = 0; i < m; i++) 
        cin >> x[i];
  
    sort(x, x + m);
    int ans = x[m - 1] - x[0];
    if(m > 1) 
    {
        vector<int> d(m - 1);
        for(int i = 0; i < m - 1; i++) 
            d[i] = x[i + 1] - x[i];
        
        sort(d.rbegin(), d.rend());
        for(int i = 0; i < min(n - 1, 1ll*sz(d)); i++) 
            ans -= d[i];
        
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <map>
using namespace std;
using Int = long long;
int main()
{
    map<string, int> score;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        score[s]++;
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        string s;
        cin >> s;
        score[s]--;
    }
    int m = 0;
    for (auto p : score) {
        m = max(m, p.second);
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(void){
    map<string, int> m;
    int n, max;
    string str;
    cin>> n;
    for (int i=0; i<n; i++) {
        cin >> str;
        m[str]++;
    }
    for (const auto& x:m) {
        if(x.second > max) max = x.second;
    }
    for (auto it = m.begin(); it != m.end(); it++) {
        if(it->second == max) cout << it->first << endl;
    }
    return 0;
}

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

 using namespace std;
 int main(){
 int A,B,C;
   cin >>A>>B>>C;
   int ans = max<int>({10*A+B+C,10*B+A+C,10*C+A+B});
   cout << ans << endl;
 }

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	int N, W[100];
	cin >> N;

	int sum = 0;
	for (int i = 0; i < N; i++){
		cin >> W[i];
		sum += W[i];
	}

	int currentSum = 0;
	int ans = 1e9;
	for (int i = 0; i < N - 1; i++){
		currentSum += W[i];
		ans = min(ans, abs(sum - 2 * currentSum));
	}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

void ProblemD();

int main() {
  ProblemD();
  return 0;
}
typedef struct {
  uint64_t x;
  set<uint32_t> branch;
} TreeType;

void ProblemD() {
  uint32_t N, Q;
  cin >> N >> Q;
  vector<TreeType> Tree(N);
  priority_queue<pair<uint32_t, uint32_t>> que;
  for (uint32_t i = 0; i < (N - 1); ++i) {
    uint32_t a, b;
    cin >> a >> b;
    que.push(make_pair(a, b));
  }
  vector<pair<uint32_t, uint32_t>> operation(Q);
  for (uint32_t i = 0; i < Q; ++i) {
    cin >> operation[i].first >> operation[i].second;
  }
  pair<uint32_t, uint32_t> p;
  while (!que.empty()) {
    p = que.top();
    que.pop();
    Tree[p.first - 1].branch.insert(p.second - 1);
  }
  for (uint32_t i = 0; i < Q; ++i) {
    Tree[operation[i].first - 1].x += operation[i].second;
  }
  queue<uint32_t> pque;
  pque.push(0);
  uint32_t tmp;
  while (!pque.empty()) {
    tmp = pque.front();
    pque.pop();

    for (auto itr = Tree[tmp].branch.begin(); itr != Tree[tmp].branch.end();
         ++itr) {
      pque.push(*itr);
      Tree[*itr].x += Tree[tmp].x;
    }
  }

  for (uint32_t i = 0; i < N; ++i) {
    cout << Tree[i].x << " ";
  }
  cout << endl;
}


Measured memory_bytes: 26480
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  if (N == 1)
    cout << "Hello World" << endl;
  else
  {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int a , b , c , d;
    bool L = 0;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0)
    {
        if(L == 0)
            c -= b , L = 1 - L;
        else a -= d , L = 1 - L;
    }
    if(a <= 0)
        cout << "No\n";
    else cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3624
/*
 *  WATCH THIS
 */
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll N = 1e5 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7;

void debug() { cerr << endl; }

template<typename Head, typename... Tail>
void debug(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug(T...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  ll minn = min(v[0], v[1]);
  ll x = (v[0] > v[1] ? 1 : 0);
  ll first = 1000;
  for (int i = x; i < n - 1; ++i) {
    if (v[i + 1] < v[i]) {
      ll buy = first / minn;
      first = first % minn;
      ll sells = v[i] * buy;
      first += sells;
      minn = v[i + 1];
    }
  }
  if (minn != v[n - 1]) {
    ll buy = first / minn;
    first = first % minn;
    ll sells = v[n - 1] * buy;
    first += sells;
  }
  cout << max((ll) 1000, first) << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main(){
  string dir;
  while(1){
  int dice[3] = {1,2,3},d,n;
  cin>>n;
  int s=1;
  if(!n)break;
  for(;n>0;n--){
    cin>>dir;
    int a,b;
    if(dir=="North")a=1,b=0;
    if(dir=="East")a=0,b=2;
    if(dir=="West")a=2,b=0;
    if(dir=="South")a=0,b=1;
    if(dir=="Right")a=2,b=1;
    if(dir=="Left")a=1,b=2;
    d = dice[a];
    dice[a] = 7-dice[b];
    dice[b] = d;
    s+=dice[0];
  }
  cout<<s<<endl;
  }
  return 0;
}

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

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> l(m), r(m);
    for(ll i = 0; i < m; i++){
        cin >> l[i] >> r[i];
    }
    ll maxl = *max_element(l.begin(), l.end());
    ll minr = *min_element(r.begin(), r.end());
    ll ans = max((ll)0, minr - maxl + 1);
    cout << ans << endl;



}


Measured memory_bytes: 1792
H,W = map(int, input().split())


h = 0
w = 0
w1 = w2 = 0

if H == 1 or W ==1:
    print(1)
elif W % 2 == 1:#横が奇数
    w = int(W /2) + 1
    if H % 2 == 1:#縦が奇数
        h = int(H / 2) + 1
        w1 = h * w
        w2 = (w-1) * (h-1)
        print(w1 + w2)
    else:#縦が偶数
        h = int(H / 2)
        w1 = w * h
        w2 = (w-1) * h
        print(w1 + w2)
else:#横が偶数
    w = int(W / 2)
    print(w * H)



Measured memory_bytes: 3064
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    si = str(i)
    if len(si) != N:
        continue
    flg = True
    for sc in SC:
        if int(si[sc[0]-1]) != sc[1]:
            flg = False
    if flg:
        print(i)
        exit()
print('-1')


Measured memory_bytes: 40048
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;

int main() {
  INIT;
  
  int a, b;
  char op;
  cin >> a >> op >> b;

  if(op == '+'){
    cout << a+b << endl;
  }else{
    cout << a-b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
set<int> st;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int P[200010];
    rep(i, N) cin >> P[i];
    int ans = 0;
    bool same = false;
    int cnt = 0;
    rep(i, K) st.insert(P[i]);
    rep(i, K - 1) {
        if(P[i] > P[i + 1]) cnt++;
    }
    if(cnt == 0) same = true;
    else ans++;
    rep(i, N - K) {
        bool change = false;
        int minimam = *st.begin();
        int maximam = *--st.end();
        st.erase(P[i]); st.insert(P[K + i]);
        if(P[i] > P[i + 1]) cnt--;
        if(P[K - 1 + i] > P[K + i]) cnt++;
        if(cnt == 0) same = true;
        else {
            if(minimam == P[i] && maximam < P[K + i]) ans += 0;
            else ans++;
            //cout << minimam << " " << maximam << " " << P[i] << " " << P[K + i] << endl;
        }
    }
    cout << ans + same << endl;


    return 0;
}
// 0 1 2 3 4
//  o o o o

// 0 2 1 4 3
//  o x o x

// 0 1 2 4 3
//  o o o x

// 0 2 1 3 4
//  o x o o

// 2 0 1 3 7 5 4 6 8 9
//  x o o o x x o o o
//  x o o
//    o o o 
//      o o x
//        o x x
//          x x o
//            x o o 
//              o o o 

// [0 2 1] 4 3 -> 0 1 2 4 3
// 0 [2 1 4] 3 -> 0 1 2 4 3

// [3 7 5 4] 6 -> 3 4 5 7 6
// 3 [7 5 4 6] -> 3 4 5 6 7

Measured memory_bytes: 13684
a, b, c, k = map(int, input().split())
# print(a)
# print(b)
# print(c)
# print(k)

# sum = (1) * (a) + (0) * (k-a) + (-1) * (k-a-b)

if k > a:
  sum = (1) * (a) + (-1) * (k-a-b)
elif k == a:
  sum = (1) * (a)
else:
  sum= sum = (1) * (k)

# if k-a <= b:
#   sum = sum + (0) * (k-a)
# else:
#   sum = sum + (0) * b

# sum = sum + (-1) * (k-a-b)

# print('sum')
print(sum)

Measured memory_bytes: 8964
#include <stdio.h>
int main()
{
    int i;
    scanf("%d", &i);
    int k = -1;
    int tab[i][3];
    while (++k < i)
        scanf("%d %d %d", &tab[k][0], &tab[k][1], &tab[k][2]);
    k = 0;
    while (++k < i)
    {
        tab[k][0] = tab[k][0] + ((tab[k - 1][1] >= tab[k - 1][2]) ? tab[k - 1][1] : tab[k - 1][2]);
        tab[k][1] = tab[k][1] + ((tab[k - 1][0] >= tab[k - 1][2]) ? tab[k - 1][0] : tab[k - 1][2]);
        tab[k][2] = tab[k][2] + ((tab[k - 1][1] >= tab[k - 1][0]) ? tab[k - 1][1] : tab[k - 1][0]);
    }
    if (tab[i - 1][0] > tab[i - 1][1])
    {
        if (tab[i - 1][0] > tab[i - 1][2])
            printf("%d", tab[i - 1][0]);
        else
            printf("%d", tab[i - 1][2]);
    }
    else
    {
        if (tab[i - 1][1] > tab[i - 1][2])
            printf("%d", tab[i - 1][1]);
        else
            printf("%d", tab[i - 1][2]);
    }
}

Measured memory_bytes: 1280
//
//  main.cpp
//  CF_2016予選_B
//
//  Created by Joe Mori on 2020/05/28.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include <iostream>
#include<bits/stdc++.h>
int main(int argc, const char * argv[]) {
    int a,b,n,a_j=0,b_j=0;
    std::string str;
    std::cin>>n>>a>>b>>str;
    for(int i=0;i<n;i++){
        if(str.at(i)=='a'&&a_j+b_j<a+b){
            std::cout<<"Yes"<<std::endl;
            a_j++;
        }else if(str.at(i)=='b'&&b_j<b&&a_j+b_j<a+b){
            std::cout<<"Yes"<<std::endl;
            b_j++;
        }else
            std::cout<<"No"<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  if ((a == "H" && b == "H") || (a == "D" && b == "D")) {
    cout << "H" << endl;
  }
  else {
    cout << "D" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
words_dic = {}

for i in range(n):
  word = input()
  if word in words_dic.keys():
    words_dic[word] += 1
  else:
    words_dic[word] = 0

max_num = max(words_dic.values())

for word, i in sorted(words_dic.items(), key=lambda x:x[0]):
  if i == max_num:
    print(word)

Measured memory_bytes: 46556
import * as fs from 'fs';

//in
// 4
//out
// 0.5
const main = (inp: string) => {

    const n = parseInt(inp);

    if (n % 2 === 0) {
        console.log(n / 2 / n);
    } else {
        console.log((n + 1) / 2 / n);
    }
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 19
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a[MAXN];
map<P,ll> mp[MAXN][MAXN];
void update(ll &a,ll b) {a=min(a,b);} 
ll solve(int l,int r,int xl,int xr)
{
    if(l+1==r) return 0;
    if(mp[l][r].find(P(xl,xr))!=mp[l][r].end()) return mp[l][r][P(xl,xr)];
    mp[l][r][P(xl,xr)]=INF;
    for(int mid=l+1;mid<r;mid++) update(mp[l][r][P(xl,xr)],solve(l,mid,xl,xl+xr)+solve(mid,r,xl+xr,xr)+1LL*(xl+xr)*a[mid]);
    return mp[l][r][P(xl,xr)];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    printf("%lld\n",solve(1,n,1,1)+a[1]+a[n]);
    return 0;
}



Measured memory_bytes: 16512
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int s,g;
        scanf("%d%d",&s,&g);
        int pos=s;
        printf("%d",s);
        bool flag=false;
        while(pos!=g){
            if(pos>5){
                if(pos==9)pos=5,flag=true;
                else pos++;
            }
            else if(pos==0){
                flag=false;
                pos++;
            }
            else{
                if(flag)pos--;
                else if(pos>g)pos--;
                else pos++;
            }
            printf(" %d",pos);
        }
        puts("");
        }
    return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int gcd(int p,int q){
    if(p%q==0)
    return q;
    return gcd(q,p%q);
}
int main(){
    int n,ans=0;
    cin>>n;
    for(int i=1;n>=i;++i){
        for(int j=1;n>=j;++j){
            for(int k=1;n>=k;++k){
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(100000000)
from collections import defaultdict
N = int(input())
tree = defaultdict(list)
for i in range(N-1):
    u,v,w = map(int,input().split())
    tree[u].append((v,w))
    tree[v].append((u,w))

ans = {}
reached = [False] * (N+1)

def dfs(u,v,s):
    reached[v] = True
    if s % 2 == 0: ans[v] = 0
    else: ans[v] = 1
    for n in tree[v]:
        if not reached[n[0]]:
            dfs(v,n[0],s+n[1])

ans[1] = 0
reached[1] = True
for v in tree[1]:
    dfs(1,v[0],v[1])

for i in range(N):
    print(ans[i+1])

Measured memory_bytes: 93216
#include <iostream>

using namespace std;

int main()
{   // m is to keep max value in the process
    int x, n, m;
    char s[101];
    x = m = 0;
    
    cin >> n >> s;
    for (int i =0; i < n; i ++) {
        x = (s[i]=='I' ? x+1 : x-1);
        m = max(m, x);
    }

    cout << m << endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 28)
#define LLINF (1LL << 60)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main()
{
    string s;
    cin>>s;

    int len = s.length();
    if (s[len-1]=='s'){
        cout << s << "es" << endl;
    }
    else{
        cout << s << "s" << endl;
    }
        return 0;
}


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

int main() 
{
    int n,k;
    cin>>n;
    cin>>k;
    int a[n];
    int dp[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    
    for(int i=2;i<n;i++)
    {
        int min1=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
                min1=min(dp[i-j]+abs(a[i]-a[i-j]),min1);
        }
        dp[i]=min1;
    }
    
    cout<<dp[n-1]<<endl;
    
	return 0;
}


Measured memory_bytes: 1152
n=int(input())
a=list(map(int,input().split()))
if max(a)>=min(a)+2:
    print('No')
elif max(a)==min(a):
    if max(a)==n-1 or 2*max(a)<=n:
        print('Yes')
    else:
        print('No')
else:
    mi=0
    ami=min(a)
    for i in a:
        if i==ami:
            mi+=1
    ma=n-mi
    if mi<ami+1 and 2*(ami+1-mi)<=ma:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 13964
K,N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
P=[]
for i in range(len(A)-1):
    a = abs(A[i+1] -A[i])
    P.append(a)
P.append(abs(K - A[-1] + A[0]))
P.sort()
del P[-1]
ans = sum(P)
print(ans)

Measured memory_bytes: 26420