akhauriyash/Code-Regression huggingface dataset:
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0);def f(v,c)s=m=H[v].size==1?A[v-1]:0;H[v].any?{|e|e==c&&next;s+=n=f(e,v);m=[m,n].max;n<0}||s<(x=2*A[v-1]-s)||x<2*m-s ?-1:x end;G=->{gets.split.map &:to_i};n,_=G[];A=G[];H=Hash.new{|h,k|h[k]=[]};(n-1).times{x,y=G[];H[x]<<y;H[y]<<x};puts f(1,0)==0?:YES: :NO

Measured memory_bytes: 198972
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 500005

enum Type{
	Range,
	Query,
};

struct Info{
	Info(Type arg_type,int arg_left,int arg_right,int arg_index){
		type = arg_type;
		left = arg_left;
		right = arg_right;
		index = arg_index;
	}
	bool operator<(const struct Info & arg) const{

		if(left != arg.left){
			return left < arg.left;
		}else{

			return type > arg.type;
		}
	}
	Type type;
	int left,right,index;
};


int N;
int C[SIZE],pre[SIZE],BIT[SIZE],ans[SIZE];
vector<Info> info;


void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc; //最後の1ビットを足した場所が次の★更新★場所

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc; //最後の1ビットを引いた場所が次の★加算★場所

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}

int calc(int left,int right){ //left～rightの区間の総和を、sum(1～right)-sum(1～left-1)で求める
	return getSum(right)-getSum(left-1);
}

int main(){

	int num_query;
	scanf("%d %d",&N,&num_query);

	for(int i = 0; i < N; i++)pre[i] = -1;
	for(int i = 0; i <= N; i++)BIT[i] = 0;

	for(int i = 0; i < N; i++){

		scanf("%d",&C[i]);
		C[i]--;

		if(pre[C[i]] != -1){

			info.push_back(Info(Range,pre[C[i]],i,i));
		}
		pre[C[i]] = i;
	}

	int left,right;
	for(int i = 0; i < num_query; i++){

		scanf("%d %d",&left,&right);
		left--,right--;

		info.push_back(Info(Query,left,right,i));
	}

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

	for(int i = info.size()-1; i >= 0; i--){

		if(info[i].type == Range){

			add(info[i].right,1);
			continue;
		}

		//info[i].type == Query
		int tmp = getSum(info[i].right);
		ans[info[i].index] = info[i].right-info[i].left+1-tmp;
	}

	for(int i = 0; i < num_query; i++){

		printf("%d\n",ans[i]);
	}

	return 0;
}


Measured memory_bytes: 26672
def dfs(b):
    s=str(b)
    for i in range(l-len(s)):
        s="0"+s
    l0=[]
    for z in range(l):
        l0.append(s[z])
    l1=[]
    l1=sorted(l0)
    s1=str()
    s2=str()
    for x in l1:
        s1=s1+x
        s2=x+s2
    i1=int(s1)
    i2=int(s2)
    return i2-i1
while True:
    a,l=map(int,input().split())
    if l==0:exit()
    la=[a]
    i=0
    f=0
    while f==0:
        i+=1
        a=dfs(a)
        for j in range(len(la)):
            if a==la[j]:
                print("{} {} {}".format(j,a,i-j))
                f=1
                break
        la.append(a)


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m,c;
  cin >> n >> m >> c;
  vector<vector<int>> a(n,vector<int>(m));
  vector<int> b(m);
  for (int i=0;i<m;i++) cin >> b[i];
  for (int i=0;i<n;i++)for(int j=0;j<m;j++) cin >> a.at(i).at(j);
  int tmp=0,cnt=0;;
  
  for (int i=0;i<n;i++){
    for (int j=0;j<m;j++){
      tmp+=(a.at(i).at(j))*b.at(j);
    }
    tmp+=c;
    if (tmp > 0) cnt++;
    tmp=0;
  }
  printf("%d",cnt);
 return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    string s; cin>>s;
    int lcnt=0,rcnt=n-1;
    while(1){
        while(1){
            if(s[lcnt]=='W') break;
            else lcnt++;
            if(lcnt==n) break;
        }
        while(1){
            if(s[rcnt]=='R') break;
            else rcnt--;
            if(rcnt==-1) break;
        }
        if(lcnt<rcnt){
            swap(s[lcnt],s[rcnt]);
            ans++;
        }
        else break;
    }
    cout<<ans<<endl;
}


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

void solve(long long a, long long b)
{
    cout << (a <= b ? a : (a - 1)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    solve(a, b);
    return 0;
}


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

int i,j,k,h,w,min,ans,mat[700][700],max[700][700];
char c;

int main(){
	while(scanf("%d %d",&h,&w)*h*w){
		for(i=0;i<h;i++){
			k=0;
			scanf("\n");
			for(j=0;j<w;j++){
				scanf("%c",&c);
				if(c=='.')k++; else k=0;
				mat[i][j]=k;
			}
		}

		ans=0;
		for(j=w-1;j>=0;j--){
			for(k=h-1;k>=0;k--){
				min=mat[k][j];
				for(i=1;i+k<h;i++){
					if(min>mat[i+k][j])min=mat[i+k][j];
					if(min==0)break;
					if(min*(i+1)>ans)ans=min*(i+1);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  lint n; cin >> n;
  vector<lint> a(n,0),b(n,0),c(n,0); for(lint i=0;i<n;i++) { cin >> a[i]; }

  for(lint i=0;i<n;i++) {
    while(true) {
      if(a[i] %2 == 0) {
        a[i] /= 2;
        b[i]++;
      } else if(a[i] %2 == 1) {
        break;
      }
    }
  } // for each elem.

  sort(b.begin(),b.end());
  for(lint i=0;i<n;i++) {
    if(i%2 == 0) { c[i] = b[i/2]; }
    else if(i%2 == 1) { c[i] = b[(n-1)-(i/2)]; }
  }

  for(lint i=0;i<n-1;i++) {
    if(c[i]+c[i+1] < 2) { cout << "No\n"; return 0; }
  }

  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 2560
N = int(input())

red = [0] * N
blue = [0] * N

for _ in range(N):
    red[_] = list(map(int, input().split()))

for _ in range(N):
    blue[_] = list(map(int, input().split()))

red = sorted(red, key=lambda x: (x[0], x[1]))
blue = sorted(blue, key=lambda x: (x[0], -x[1]), reverse=False)

ans = 0
# print("red:", red)
# print("blue:", blue)

for bp in blue:
    # print("check bp:", bp)
    rem = None
    
    if len(red) > 0:
        cand = None
        for rp in red:
            if bp[0] > rp[0] and bp[1] > rp[1]:
                if cand is None:
                    cand = rp
                else:
                    if cand[1] < rp[1]:
                        cand = rp

        # gen pair
        ans += 1 if cand is not None else 0
        rem = cand
        # print("pair with:", cand)

    if rem is not None:
        red.remove(rem)

print(ans)

Measured memory_bytes: 3064
n=int(input())
s_list=[input() for _ in range(n)]

import collections
s_counter = collections.Counter(s_list)

import sys
max_count = s_counter.most_common()[0][1]

s_list_keys = list(s_counter.keys())
s_list_values = list(s_counter.values())

list_ans = []

for i in range(len(s_list_keys)):
    if s_list_values[i] == max_count:
        list_ans.append(s_list_keys[i])

list_ans.sort()

for i in range(len(list_ans)):
    print(list_ans[i])

Measured memory_bytes: 45068
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long h[100005],tem;
long long n,a,b;
bool check(long long mid)
{
	long long res=0;
	for(int i=0;i<n;i++)
	{
		tem=(long long)(h[i])-(long long)(mid*b);
		if(tem>0) res+=(long long)(tem/a)+(tem%a!=0);
	}
	return res<=mid;
}
int main()
{
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	a-=b;
	long long l=0,r=1e9,mid,res=1e15;
	while(r>l+1)
	{
		mid=(l+r)/2ll;
		if(check(mid))
		{
			r=mid;
			res=min(mid,res);
		}
		else l=mid;
	}
	cout<<res;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include "cpp/Solution.h"

using namespace std;

int main() {
    int l,r,d;
    cin >> l >>r >>d;
    int ans = 0;
    for(int i = l;i <= r;i++){
        if(i%d == 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3620
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
L = input()

dp = [[0] * 2 for _ in range(len(L) + 1)]

dp[0][0] = 2
dp[0][1] = 1
for i in range(1, len(L)):
    if L[i] == '1':
        dp[i][0] = 2 * dp[i - 1][0] % MOD
        dp[i][1] = (dp[i - 1][1] * 3 + dp[i - 1][0]) % MOD
    else:
        dp[i][0] = dp[i - 1][0]
        dp[i][1] = (3 * dp[i - 1][1]) % MOD
print(sum(dp[len(L) - 1]) % MOD)
# print(dp)



Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=1; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    int ans;
    rep(i, 10000000){
        if(i*i > n){
            ans = (i-1)*(i-1);
            break;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll i,j,a,b,ans=0;
	scanf("%lld%lld",&a,&b);
	if(a==b) return puts("1"),0;
	for(i=60;i>=0;--i){
		if((b>>i&1)^(a>>i&1))break;
		if(a>>i&1)a^=1LL<<i;
	}
	for(j=i-1; j>=0; --j)
		if(b>>j&1){
			ans+=(1LL<<(j+1))-1;
			break;
		}
	ans += ((1LL<<i)-a)<<1;
	if(j!=-1&&a<=(1LL<<(j+1))-1)ans-=(1LL<<(j+1))-a;
	printf("%lld\n",ans+(i!=0));
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [[]]*N
for i in range(N):
    A[i] = int(input())
    
base_ans = max(A)
index = A.index(base_ans)

if A.count(base_ans) >= 2:
    for i in range(N):
        print(base_ans)
else:
    ans_list=[base_ans]*N
    A.remove(base_ans)
    ans_min = max(A)
    ans_list[index]=ans_min
    for i in range(N):
        print(ans_list[i])

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

struct Edge {
  int to, weight;
  Edge(int t, int w) :to(t), weight(w) {}
};

struct Graph {
  vector<vector<Edge>> edges;

  Graph(int N) :edges(N) {}

  void addEdge(int a, int b) { addEdge(a, b, 1); }

  void addEdge(int a, int b, int w) {
    edges[a].emplace_back(b, w);
  }
};

int main() {
  int N, M; cin >> N >> M;
  vector<pair<int, int>> Weights;
  vector<int> D(N);
  rep(i, N) {
    cin >> D[i];
    Weights.emplace_back(D[i], i);
  }

  Graph G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    x--; y--;
    G.addEdge(x, y, i);
    G.addEdge(y, x, i);
  }

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

  vector<int> ans(M, 1e9);
  vector<int> color(N, -1);
  rep(i, N) {
    int d = Weights[i].first, now = Weights[i].second;
    if (color[now] != -1) continue;

    for (Edge e : G.edges[now]) {
      if (color[e.to] != -1) {
        color[now] = color[e.to] ^ 1;
        ans[e.weight] = d;
        break;
      }
      else if (D[e.to] == d) {
        color[now] = 0;
        color[e.to] = 1;
        ans[e.weight] = d;
        break;
      }
    }

    if (color[now] == -1) {
      cout << -1 << endl;
      return 0;
    }
  }

  rep(i, N) {
    if (color[i]) cout << "W";
    else cout << "B";
  }
  cout << endl;
  rep(i, M) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 12660
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  cout << max(0, - a * 60 - b + c * 60 + d - e) << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
main()
{
        int i, j, l, k, n, count[4][13] = {0};
        scanf("%d", &n);
        for(i = 0; i < n; i++){
                scanf("%*c%c %d", &l, &k);
                switch(l){
                case 'S':
                        count[0][k - 1] = 1;
                        break;
                case 'H':
            count[1][k - 1] = 1;
                        break;
                case 'C':
            count[2][k - 1] = 1;
            break;
                case 'D':
            count[3][k - 1] = 1;
            break;
                }
        }
        for(j = 0; j < 4; j++){
                switch(j){
                case 0:
                        l = 'S';
                        break;
                case 1:
                        l = 'H';
                        break;
                case 2:
                        l = 'C';
                        break;
                case 3:
                        l = 'D';
                        break;
                }
                for(i = 0; i < 13; i++){
                        if(!count[j][i]){
                                printf("%c %d\n", l, i + 1);
                        }
                }
        }
 }

Measured memory_bytes: 1808
H,W,K=map(int,input().split())
C=[input() for i in range(H)]

t=0	
for h in range(2**H):
  for w in range(2**W):
    b=0
    for i in range(H):
      if h&2**i:
        continue
      for j in range(W):
        if w&2**j:
          continue
        if C[i][j]=='#':
          b+=1
    if b==K:
      t+=1

print(t)


Measured memory_bytes: 9044
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 */

public class Main {

	public static void printlnYN(boolean b){
		if(b) System.out.println("Yes");
		else System.out.println("No");
	}

	public static void main(String[] args) throws IOException {
      /*
		File file = new File("input.txt");
		Scanner sc = new Scanner(file);
		System.out.println("***ファイル入力***");
        */

		Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
    	String S = sc.next();

    	int min = 0;
    	for(int i = 1; i < N; i++){
			if(S.charAt(i) == 'E'){
				min++;
			}

		}

    	int d = min;
    	for(int i = 1; i < N; i++){
    		if(S.charAt(i-1) == 'W') d++;
    		if(S.charAt(i) == 'E') d--;
    		if(d < min) min = d;
    	}

    	System.out.println(min);

	}
}

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

int main(){
    
    int m,n;
    cin >> m >> n;
    
    long long sum=0;
    int x;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        sum+=x;
    }
    if(m-sum <0)
    {
        cout<<"-1";
    }
    else if(m-sum>=0){
        cout<<m-sum;
    }
    return 0;
}


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

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args) throws IOException{
		NScanner sc = new NScanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[6];
		for(int i = 0; i < 6; ++i)
			a[i] = sc.nextInt();
		Dice d1 = new Dice(a);
		boolean match = false;
		for(int ii = 1; ii < n; ++ii){
			int[] b = new int[6];
			for(int i = 0; i < 6; ++i)
				b[i] = sc.nextInt();
			Dice d2 = new Dice(b);
			
			if(d1.equals(d2)){
				match = true;
			}else{
				ent: for(int i = 0; i < 4; ++i){
					d2.turnE();
					if(d1.equals(d2)){
						match = true;
						break ent;
					}
					for(int j = 0; j < 4; ++j){
						d2.turnN();
						if(d1.equals(d2)){
							match = true;
							break ent;
						}
						for(int k = 0; k < 4; ++k){
							d2.turnE();
							if(d1.equals(d2)){
								match = true;
								break ent;
							}
						}

					}
				}
			}
			if(match) break;
		}
		System.out.println(match ? "No" : "Yes");
	}

}

class Dice{
	int Top, Front, Right, Left, Back, Bottom;

	Dice(int[] a){
		Top = a[0];
		Front = a[1];
		Right = a[2];
		Left = a[3];
		Back = a[4];
		Bottom = a[5];
	}

	void turnN(){
		int tmp = Top;
		Top = Front;
		Front = Bottom;
		Bottom = Back;
		Back = tmp;
	}

	void turnS(){
		int tmp = Top;
		Top = Back;
		Back = Bottom;
		Bottom = Front;
		Front = tmp;
	}

	void turnE(){
		int tmp = Top;
		Top = Left;
		Left = Bottom;
		Bottom = Right;
		Right = tmp;
	}

	void turnW(){
		int tmp = Top;
		Top = Right;
		Right = Bottom;
		Bottom = Left;
		Left = tmp;
	}

	boolean equals(Dice D){
		if(Top != D.Top)
			return false;
		if(Front != D.Front)
			return false;
		if(Right != D.Right)
			return false;
		if(Left != D.Left)
			return false;
		if(Back != D.Back)
			return false;
		if(Bottom != D.Bottom)
			return false;
		return true;
	}
}

class NScanner{

	private BufferedReader br;
	private StringTokenizer tok;

	public NScanner(InputStream is) throws IOException{
		br = new BufferedReader(new InputStreamReader(is));
		getLine();
	}

	private void getLine() throws IOException{
		while(tok == null || !hasNext()){
			tok = new StringTokenizer(br.readLine());
		}
	}

	public boolean hasNext(){
		return tok.hasMoreTokens();
	}

	public String next() throws IOException{
		if(hasNext()){
			return tok.nextToken();
		}else{
			getLine();
			return tok.nextToken();
		}
	}

	public int nextInt() throws IOException{
		if(hasNext()){
			return Integer.parseInt(tok.nextToken());
		}else{
			getLine();
			return Integer.parseInt(tok.nextToken());
		}
	}

	public long nextLong() throws IOException{
		if(hasNext()){
			return Long.parseLong(tok.nextToken());
		}else{
			getLine();
			return Long.parseLong(tok.nextToken());
		}
	}

	public double nextDouble() throws IOException{
		if(hasNext()){
			return Double.parseDouble(tok.nextToken());
		}else{
			getLine();
			return Double.parseDouble(tok.nextToken());
		}
	}
}


Measured memory_bytes: 24680
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll res1=a*b,res2=c*d;
    ll res=max(res1,res2);
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed main(){
    int n;
    cin>>n;
    int d[1001]={};
    for(int i=2;i<=n;i++){
        int t=i;
        for(int j=2;j<=i;j++){
            if(t%j==0){
                d[j]++;
                t/=j;
                j--;
            }
        }
    }
    int ans=1;
    for(int i=1;i<=n;i++){
        ans*=d[i]+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int score = 0;
    rep(i, n-1) if (s[i] == s[i+1]) ++score;
    cout << min(score+k*2, n-1) << endl;
    return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,max=-1,ans=0;
  int a,b;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(max<a){
      max=a;
      ans=b;
    }
  }
  cout<<max+ans<<endl;
  return(0);
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

sigma = 0
for i in range(n-1):
    # print(i,a[i],b[a[i]-1])
    sigma += b[a[i]-1]
    # print(a[i] +1 ,a[i+1],a[i] +1 == a[i+1])
    if a[i] +1 == a[i+1]:
        # print(c[a[i]-1])
        sigma += c[a[i]-1]
    # print(sigma)
sigma += b[a[n-1]-1]
print(sigma)

Measured memory_bytes: 3064
def gcd(a, b):
    if a < b:
        a, b = b, a
    return b if a % b == 0 else gcd(b, a%b)
def solve(k):
    ans = 0
    for a in range(1, k+1):
        for b in range(1, k+1):
            d = gcd(a, b)
            if d in [1,2,3,5,7,11,13]:
                num = k // d
                ans += num * d + (k - num)
            else:
                for c in range(1, k+1):
                    ans += gcd(c, d)
    return ans

k = int(input())
print(solve(k))

Measured memory_bytes: 9212
S = list(input())
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
chk = 0
for i in range(1, len(S)+1):
  if i % 2 != 0 and S[i-1] in odd:
    chk = chk + 1
  if i % 2 == 0 and S[i-1] in even:
    chk = chk + 1
    
if chk == len(S):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<ll>());
  ll ans = 0;
  rep2(i, 1, n) ans += a[i / 2];
  cout << ans << endl;
}

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

int main()
{
        ll N; cin >> N;
        vector<ll> M(5, 0);
        rep(i,N) {
                string S; cin >> S;
                if (S[0] == 'M') M[0]++;
                else if (S[0] == 'A') M[1]++;
                else if (S[0] == 'R') M[2]++;
                else if (S[0] == 'C') M[3]++;
                else if (S[0] == 'H') M[4]++;
        }

        ll ans = 0;
        for (int i = 0; i < 5; ++i) {
                for (int j = i+1; j < 5; ++j) {
                        for (int k = j+1; k < 5; ++k) {
                                ans += (M[i] * M[j] * M[k]);
                        }
                }
        }
        cout << ans << endl;


}


Measured memory_bytes: 3556
import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let r = Int(split[0])!
let D = Int(split[1])!
var x2000 = Int(split[2])!

func calculateWeight(year: Int) -> Int {
	var oneYearAgoWeight = 0
	var weight = 0
	if year > 2001 {
      	oneYearAgoWeight += calculateWeight(year - 1)
  		weight = r * oneYearAgoWeight - D
	} else if year == 2001 {
    	weight = r * x2000 - D
    } else {
    	print("Error")
    }
	return weight
}

var i = 2001
while i < 2011 { 
	print(calculateWeight(i))
	i += 1
}

Measured memory_bytes: 7780
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    int cursum = 0;
    mp[0]++;
    rep(i, n) {
        cursum += a[i];
        cursum %= m;
        mp[cursum]++;
    }

    int ans = 0;
    for(auto &x : mp) {
        ans += x.second * (x.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
W, H, x, y, r= map(int, input().split())
flag = True
if (x+r) > W:
    flag = False

elif (x-r) < 0:
    flag = False

elif (y+r) > H:
    flag = False

elif (y-r) < 0:
    flag = False


if flag:
    print("Yes")

else:
    print("No")
    


Measured memory_bytes: 5596
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N;
	cin >> N;
	VI A(N);
	REP(i, N)
		cin >> A[i];
	SORT(A);
	int sum = 0,t=0;
	REP(i, N-1) {
		sum += A[i];
		if (sum * 2 < A[i + 1]) {
			t = i+1;
			continue;
		}
	}
	cout << N - t << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int H, W;
int Wcnt[2005][2005];
int Hcnt[2005][2005];
char S[2005][2005];

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        Wcnt[i][j] = 0;
        Hcnt[i][j] = 0;
      } else {
        Wcnt[i][j] = 1;
        Hcnt[i][j] = 1;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] != '#' && S[i][j + 1] != '#') {
        Wcnt[i][j + 1] += Wcnt[i][j];
      }
    }
  }

  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (S[j][i] != '#' && S[j + 1][i] != '#') {
        Hcnt[j + 1][i] += Hcnt[j][i];
      }
    }
  }

  for (int i = 0; i < H; i++) {
    int mx = -1;
    for (int j = W - 1; j >= 0; j--) {
      if (S[i][j] != '#' && mx == -1) {
        mx = Wcnt[i][j];
      } else if (S[i][j] != '#' && mx != -1) {
        Wcnt[i][j] = mx;
      } else {
        mx = -1;
      }
    }
  }

  for (int i = 0; i < W; i++) {
    int mx = -1;
    for (int j = H - 1; j >= 0; j--) {
      if (S[j][i] != '#' && mx == -1) {
        mx = Hcnt[j][i];
      } else if (S[j][i] != '#' && mx != -1) {
        Hcnt[j][i] = mx;
      } else {
        mx = -1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(Wcnt[i][j] + Hcnt[i][j] - 1, ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 35584
N = gets.to_i
S = gets.chomp.chars
Q = gets.to_i
qu = []
Q.times {
    qu << gets.chomp.split(" ")
}

s = Hash.new{|h, k| h[k] = []}
(0...N).each {|i|
    s[S[i]] << (i+1)
}

qu.each {|f, a, b|
    if f == '1' then
        a_i = a.to_i
        if S[a_i-1] != b then
            idx = s[S[a_i-1]].bsearch_index{|x| x >= a_i}
            s[S[a_i-1]].delete_at(idx)
            S[a_i-1] = b
            idx = s[b].bsearch_index{|x| x >= a_i}
            idx.nil? ? s[b] << a_i : s[b].insert(idx, a_i)
        end
    else
        l, r = [a.to_i, b.to_i]
        ans = 0
        (0..25).each {|i|
            sl = s[(97+i).chr].bsearch{|x| x >= l}
            ans += 1 if (not sl.nil?) && sl <= r
        }
        puts ans
    end
}

Measured memory_bytes: 53820
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define inf 2147483647
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
inline void read(T&);
template<class T>
inline void write(const T&);

typedef long long ll;
typedef const long long & cll;
typedef const int & ci;

const int N = 105;

int ans[N], id;

int main () {
    int a, b, k;
    read(a), read(b), read(k);
    for (int i = 1; i <= a && i <= b; ++i) {
        if (a % i == 0 && b % i == 0) {
            ans[++id] = i;
        }
    }
    std::sort(ans + 1, ans + id + 1, std::greater<int>());
    write(ans[k]), EL;
    return 0;
}

template<class T>
void read(T &Re) {
    T k = 0;
    char ch = getchar();
    int flag = 1;
    while (!isNum(ch)) {
        if (ch == '-') {
            flag = -1;
        }
        ch = getchar();
    }
    while (isNum(ch)) {
        k = (k << 1) + (k << 3) + ch - '0';
        ch = getchar();
    }
    Re = flag * k;
}
template<class T>
void write(const T &Wr) {
    if (Wr < 0) {
        putchar('-');
        write(-Wr);
    } else {
        if (Wr < 10) {
            putchar(Wr + '0');
        } else {
            write(Wr / 10);
            putchar((Wr % 10) + '0');
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

ll digit_sum(ll n) {
	ll s = 0;
	while (n != 0) s += n % 10, n /= 10;
	return s;
}

int main(void) {


	int N,result = 9 * 10;
	cin >> N;

	for (int i = 1; i < N; i++) {
		ll a = i, b = N - i;

		CHMIN(result,(int)(digit_sum(a) + digit_sum(b)));

	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

	cin >> N >> M;
	M /= gcd(N, M);
	for (int i = 2; i*i <= M; i++) {
		long long int box = i;
		long long int div = 1;
		while (box < M) {
			box *= i;
			if (M%box == 0)div *= i;
		}
		M /= div;

	}
	cout << M<< endl;
	return 0;
}



Measured memory_bytes: 3188
'use strict'

const Main = (input) => {
  const X = parseInt(input.trim())

  let resultArr = [1]

  for (let i = 1; i <= X; i++) {
    for (let j = 1; j < Math.sqrt(X); j++) {
      for (let k = 2; k < Math.sqrt(X); k++) {
        if (Math.pow(j, k) === i) {
          if (resultArr.indexOf(i) === -1) {
            resultArr.push(i)
          }
        }
      }
    }
  }

  let result = Math.max.apply(null, resultArr)

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 21064
import sys
input = sys.stdin.readline

N,M=map(int, input().split())
B=[tuple(map(int, input().split())) for _ in range(M)]

P=list(range(N+1))
C=[1 for _ in range(N+1)]
C[0] = 0

def root(x):
    t = x
    stack = []
    while P[t] != t:
        stack.append(t)
        t = P[t]
    for c in stack: P[c] = t
    return t

def unite(a,b):
    ra = root(a)
    rb = root(b)
    C[ra] += C[rb]
    C[rb] = 0
    P[rb] = ra

def same(a,b):
    return root(a) == root(b)

def count(x):
    return C[root(x)]

ans=[0]*(M+1)
ans[M] = N * (N-1)

for i in range(M-1,-1,-1):
    a,b = B[i]
    if same(a,b):
        ans[i] = ans[i+1]
        continue
    ans[i] = ans[i+1] - count(a) * count(b)
    unite(a,b)

for i in range(1,M+1):
    print(ans[i] - ans[0])

Measured memory_bytes: 70876
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> v;
int h,w,k;
v x(v a,v b){
	if(a.size()==b.size())return max(a,b);
	return (a.size()>b.size())?a:b;
}
int main(){
	while(cin>>w>>h&&h){
	v d[75][75],s;r(i,h)r(j,w){
		char z;cin>>z;z-='0';
		if(!(z/10)&&(z||d[i][j].size())){
			d[i][j].push_back(z);
			d[i+1][j]=x(d[i+1][j],d[i][j]);
			d[i][j+1]=x(d[i][j+1],d[i][j]);
		}s=x(s,d[i][j]);
	}r(i,s.size())cout<<s[i];cout<<endl;
	}return 0;
}

Measured memory_bytes: 3468
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	vector<string> s1 = {"SUN" , "MON" , "TUE" , "WED" , "THU" 
		, "FRI", "SAT"};
	vector<string> s = s1;
	for (auto &el : s1) s.push_back(el);
	string in;
	cin >> in;
	int idx = 0;
	for (int i = 0; i < sz(s); i++) {
		if (s[i] == in) {
			idx = i;
			break;
		}
	}
	for (int i = idx + 1; i < sz(s); i++) {
		if (s[i] == "SUN") {
			cout << i - idx << "\n";
			return 0;
		}
	}
}



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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
S = input()

# ランレングス圧縮
A = []
# 番兵
if S[0] == '0':
    A.append(0)
cur = S[0]
cnt = 1
for i, s in enumerate(S[1:], 1):
    if s != cur:
        A.append(cnt)
        cnt = 1
        cur = s
    else:
        cnt += 1
A.append(cnt)

# 例外処理
if len(A) == 1:
    print(N)
    exit()

# 番兵
if S[-1] == '0':
    A.append(0)

M = len(A)
ans = sm = sum(A[:K*2+1])
for i in range(K*2+1, M):
    sm += A[i]
    # 今回増やすのが0の区間なら、後ろ2つ減る
    if i % 2 == 1:
        if i-K*2 >= 0:
            sm -= A[i-K*2]
        if i-K*2-1 >= 0:
            sm -= A[i-K*2-1]
    ans = max(ans, sm)
print(ans)


Measured memory_bytes: 4724
import java.util.*

fun main(args: Array<String>) {
    val S = readLine()!!
    val T = readLine()!!

    val uf = UnionFind(52)
    val sts = TreeSet<Char>(S.toList())
    val stt = TreeSet<Char>(T.toList())

    for (i in S.indices) {
        uf.unite((S[i] - 'a').toLong(), T[i] - 'a' + 26L)
    }

    var f = true

    for (i in 0..25L) for (j in i + 1 .. 25L) {
        f = f && !uf.same(i + 26, j + 26)
        f = f && !uf.same(i, j)
    }

    if (f) {
        println("Yes")
    } else {
        println("No")
    }
}

/**
 * A disjoint set data structure with path compression and union by size.
 *
 * Each element is represented by an index (0-indexed).
 */
class UnionFind(n: Long) {
    val size = n.toInt()

    private val parent: Array<Long>
    private val cardinality: Array<Long>

    init {
        parent = Array(size) { -1L }
        cardinality = Array(size) { 1L }
    }

    /**
     * Find a root element of a set `x` belongs to.
     */
    fun find(x: Long): Long {
        return if (parent[x.toInt()] == -1L) {
            x
        } else {
            parent[x.toInt()] = find(parent[x.toInt()])
            parent[x.toInt()]
        }
    }

    /**
     * Unite sets contain two elements `x` and `y`.
     * If `x` and `y` already belong to a same set, nothing happens.
     *
     * @return If `x` and `y` belong to a same set, return false.
     */
    fun unite(x: Long, y: Long): Boolean {
        val u = find(x).toInt()
        val v = find(y).toInt()
        if (u == v) {
            return false
        }

        val newSize = cardinality[v] + cardinality[u]

        if (cardinality[u] < cardinality[v]) {
            parent[u] = v.toLong()
            cardinality[v] = newSize
        } else {
            parent[v] = u.toLong()
            cardinality[u] = newSize
        }

        return true
    }

    /**
     * Check whether `x` and `y` belongs to a same set.
     *
     * @return `true` if `x` and `y` are in a same set.
     */
    fun same(x: Long, y: Long): Boolean {
        return find(x) == find(y)
    }

    /**
     * Get a size of a set `x` belongs to.
     */
    fun getCardinalityOf(x: Long): Long {
        return cardinality[find(x).toInt()]
    }
}


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

int main(){
    int h1,h2,m1,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int t = (h2-h1)*60+m2-m1;
    cout<<t-k<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;

int x, tt;

int main(){
	cin>>x;
	for(int i = 1; ; i++){
		if((i * x) % 360 == 0){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std ;
int main()
{


    int  n , d , i , j;
    cin>>n>>d;
  i= n/((d*2)+1);
  j=n%((d*2)+1);
  if(j!=0)
  {
      cout<<i+1;
  }
    else
        cout<<i;


}


Measured memory_bytes: 384
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
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;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

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

	if (a + W < b)cout << b - a - W << endl;
	else if (b + W < a) cout << a - b - W << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int	
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxe(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int n;
	cin >> n;
	int ans = 0;
	int maxh = 0;

	for (int i = 0; i < n; ++i)
	{
		int h;
		cin >> h;

		if (chmaxe(maxh, h))
		{
			++ans;
		}
	}

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

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

S = _S()

if 'RRR'in S:
    print(3)
elif 'RR' in S:
    print(2)
elif 'R' in S:
    print(1)
else:
    print(0)

Measured memory_bytes: 27192
#include <bits/stdc++.h>
#define maxn 302333
using namespace std;
set<int> Row[maxn], Col[maxn];
pair<int, int> row[maxn], col[maxn];
int main() {
	int H, W, M;
	scanf("%d%d%d", &H, &W, &M);
	for(int i = 1, h, w; i <= M; ++i) {
		scanf("%d%d", &h, &w);
		Row[h].insert(w);
		Col[w].insert(h);
	}
	for(int i = 1; i <= H; ++i) {
		row[i].first = Row[i].size();
		row[i].second = i;
	}
	for(int i = 1; i <= W; ++i) {
		col[i].first = Col[i].size();
		col[i].second = i;
	}
	sort(row + 1, row + H + 1, greater<decltype(row[0])> ());
	sort(col + 1, col + W + 1, greater<decltype(row[0])> ());
	int A = row[1].first + col[1].first, C = 0, Ans = A - 1;
	for(int i = 1; i <= H; ++i) {
		if(row[i].first < row[1].first) break;
		if(C > M) break;
		int id = row[i].second;
		for(int j = 1; j <= W; ++j) {
			if(col[j].first < col[1].first) break;
			if(C > M) break;
			if(Row[id].count(col[j].second)) {
				++C;
			} else {
				Ans = A;
				break;
			}
		}
		if(C > M) break;
		if(Ans == A) break;
	}
	printf("%d\n", Ans);
	return 0;
}

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

const int INF = 1e9 + 7;

int n, w, a[105], b[105];
long long dp[100005];
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> w;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}

	fill(&dp[0], &dp[0] + 100001, INF);
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 100000; j >= 0; j--) {
			if (j >= b[i]) dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
		}
	}

	for (int i = 100000; i >= 0; i--) {
		if (dp[i] <= w) {
			cout << i << '\n';
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1024
n = gets.strip.to_i
arr = Array.new(10) { Array.new(10, 0) }
 
1.upto(n) do |a|
  s = a.to_s
  arr[s[0].to_i][s[-1].to_i] += 1
end

count = 0
1.upto(n) do |a|
  s = a.to_s
  count += arr[s[-1].to_i][s[0].to_i]
end

puts count

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <set>
#include <map>
using namespace std;

void solve(vector<string> arr) {
    /*
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            cout << arr[i][j];
            if ((j+1)%3 == 0) {
                cout << " ";
            }
        }
        cout << endl;
        if ((i+1)%3 == 0) {
            cout << endl;
        }
    }
    */

    int i = 0;
    for (int k = 0; k < 3; k++) {
        int tmp = k;
        for (int j = 1; j <= 3; j++) {
            arr[i][tmp] = arr[i][tmp] == '1' ? '2' : '1';
            tmp+=3;
            i+=1;
        }
    }


    /*
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            cout << arr[i][j];
            if ((j+1)%3 == 0) {
                cout << " ";
            }
        }
        cout << endl;
        if ((i+1)%3 == 0) {
            cout << endl;
        }
    }
    */
    for (string s : arr) {
        cout << s << endl;
    }

}

int main()
{
    string s, t;
    cin >> s >> t;
    int tot = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            tot++;
        }
    }

    cout << tot << endl;



}


Measured memory_bytes: 3860
n,m = map(int,input().split())
ls = [[x for x in input() + '#'] for i in range(n)] + [['#']*(m+1)]
yokodp = [[0 for x in range(m+1)] for i in range(n+1)]
for i in range(n+1):
    yoko = 0
    for j in range(m+1):
        if ls[i][j] == '#':
            yokodp[i][j] = yoko
            yoko = 0
        else:
            yoko += 1
for i in range(n,-1,-1):
    check = 0
    for j in range(m,-1,-1):
        if yokodp[i][j] != 0:
            check = yokodp[i][j]
        if ls[i][j] == '.':
            yokodp[i][j] = check
tatedp = [[0 for x in range(m+1)] for i in range(n+1)]            
for j in range(m+1):
    tate = 0
    for i in range(n+1):
        if ls[i][j] == '#':
            tatedp[i][j] = tate
            tate = 0
        else:
            tate += 1
for j in range(m,-1,-1):
    for i in range(n,-1,-1):
        if tatedp[i][j] != 0:
            check = tatedp[i][j]
        if ls[i][j] == '.':
            tatedp[i][j] = check
ans = 0
for i in range(n):
    for j in range(m):
        if ls[i][j] == '.':
            ans = max(ans,tatedp[i][j] + yokodp[i][j] - 1)
n = 0
for i in range(100):
  n += 1
print(ans)


Measured memory_bytes: 249052
def div(n)
  count = 0
  while n%2==0 do
    count += 1
    n /= 2
  end
  return count
end
a=gets.to_i
b=gets.chomp.split(" ").map(&:to_i)
c=[]
b.each do |j|
  c<<div(j)
end
puts c.min
    

Measured memory_bytes: 1788