akhauriyash/Code-Regression huggingface dataset:
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-11 21:23:01
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  ll N, K;
  cin >> N >> K;
  if (K == 0)
  {
    cout << N * N << endl;
    return 0;
  }
  ll ans = 0;
  for (ll b = K + 1; b <= N; b++)
  {
    ll s = (N + 1 + b - 1) / b;
    ll temp = (b - K) * s;
    ll minus = b - N % b - 1;
    temp -= min(b - K, minus);
    ans += temp;
    #if DEBUG == 1
    cerr << "b = " << b << ", temp = " << temp << endl;
    #endif
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long llint;

const llint MOD = 1000000007;
const int MAXN = 2001;

llint fact[MAXN], ifact[MAXN];
llint bin[MAXN][MAXN];
llint pref[MAXN][MAXN];
llint mat[MAXN][MAXN];

llint inv(llint x)
{
	int y = MOD - 2;
	llint ret = 1;
	
	while (y)
	{
		if (y % 2)
			ret = ret * x % MOD;
		
		x = x * x % MOD;
		y /= 2;
	}
	
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int a, b, i, j;
	llint sol = 0;
	
	cin>>a>>b;
	
	fact[0] = ifact[0] = 1;
	for (i = 1; i <= b; ++i)
	{
		fact[i] = i * fact[i - 1] % MOD;
		ifact[i] = inv(fact[i]);
	}
	
	for (i = 0; i <= b; ++i) for (j = 0; j <= i; ++j)
		bin[i][j] = fact[i] * ifact[j] % MOD * ifact[i - j] % MOD;
	
	for (i = 0; i <= b; ++i)
	{
		pref[i][0] = bin[i][0];
		for (j = 1; j <= b; ++j)
		{
			pref[i][j] = (pref[i][j - 1] + bin[i][j]) % MOD;
		}
	}
	
	for (j = 0; j <= b; ++j)
	{
		mat[0][j] = 1;
	}
	for (i = 1; i <= a; ++i)
	{
		for (j = 0; j <= b; ++j)
		{
			mat[i][j] = (mat[i - 1][j] + pref[j - 1][min(j - 1, i)]) % MOD;
		}
	}
	
	for (i = 0; i <= a; ++i)
	{
		for (j = 0; j <= min(a - i, b - 1); ++j)
			sol = (sol + bin[b - 1][j] * mat[a - i - j][j] % MOD) % MOD;
	}
	
	cout<<sol<<'\n';
}


Measured memory_bytes: 94080
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n, m; readV(n, m);
  string[] a; readC(n, a);
  string[] b; readC(m, b);

  foreach (y; 0..n-m+1)
    foreach (x; 0..n-m+1)
      if (a[y..y+m].map!(ai => ai[x..x+m]).array == b) {
        writeln("Yes");
        return;
      }

  writeln("No");
}


Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n;cin>>n;
  vector<int> t(n),out;
  for(int i=0;i<n;++i) cin >> t[i];
  while(t.size()>0){
    bool found=false;
    int t_size = t.size();
    for(int i=0;i<t_size;++i){
      if(t[t_size-1-i] == t_size-i){
        out.push_back(t[t_size-1-i]);
        t.erase(t.begin()+ t_size-1-i);
        found =true;
        break;
      }
    }
    if(!found) break;
  }
  if(t.size()==0){
    for(int i=0;i<n;++i){
      cout << out[n-1-i] << endl;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {

	int N, M;
	int X[100000];
	int sa[100000];
	int min, tmp;
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		cin >> X[i];
	}
	if (N >= M) {
		cout << "0" << endl;
		return 0;
	}
	sort(X, X + M);
	for (int i = 0; i < M; i++) {
		if (i + 1 == M)break;
		sa[i] = abs(X[i + 1] - X[i]);
	}
	sort(sa, sa + M);
	min = abs(X[M - 1] - X[0]);
	for (int i = 1; i <= N - 1; i++) {
		min -= sa[M - i];
	}
	cout << min << endl;


	return(0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 200005
lli arr[MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli s,w;
    cin>>s>>w;
    if(s <=w){
        cout<<"unsafe";
    }  
    else{
        cout<<"safe";
    }
}   

Measured memory_bytes: 3628
import collections
s = list(input())
c = collections.Counter(s)
p = list(c.items())
p.sort()
i=0
for k,v in p:
    if k == chr(ord("a")+i):
        i += 1
    else:
        print(chr(ord("a")+i))
        exit()
if i == 26:
    print("None")
else:
    print(chr(ord("a")+i))

Measured memory_bytes: 4340
// C - Cell Inversion
#include <bits/stdc++.h>

using namespace std;

#define	MOD	1000000007

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	string s;
	cin >> s;

	vector<int> a(2 * n);
	for (int i = 1; i < 2 * n; i++)
		if (s[i] == s[i - 1]) a[i] = a[i - 1] ^ 1;
		else a[i] = a[i - 1];

	if (s[0] == 'W' || s[n * 2 - 1] == 'W' || accumulate(a.begin(), a.end(), 0) != n) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 1;
	for (int i = 2 * n - 1, r = 0; i >= 0; i--)
		if (a[i]) r++;
		else ans = ans * r % MOD, r--;

	for (int i = 2; i <= n; i++) ans = ans * i % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, X;
  cin >> N >> X;
  vector<int> vec(N);
  vector<int> kyori(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    kyori.at(i) = abs(X-vec.at(i));
  }
  sort(kyori.begin(),kyori.end());
  int max = kyori.at(0);
  int D = 1;
  for(int d=max; d>1; d--){
    if(D != 1){
      break;
    }
    for(int i=0; i<N; i++){
      if(abs(vec.at(i)-X)%d != 0){
        break;
        }
      if(i == N-1){
        D = d;
        break;
        }
      }
    }
  cout << D << endl;
  }
    

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

using namespace std;

int main()
{
  
  long long int n;
  cin>>n;
  string s="";
  
 
  while(n!=0){
      int k = n%26;
      if(k==0){
          k=26;
      }
      s=s+(char)(k+96);
      n=n-k;
      n=n/26;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
  
  return 0; 
}

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

int main(){

  char red[107][14];
  char blue[107][14];
  int n,m,i,j,k;
  int max = -999999;
  int sum;

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

  scanf("%d", &m);
  for(i = 0;i < m;i++){
    scanf("%s", blue[i]);
  }

  for(i = 0;i < n;i++){
    sum = 0;
    for(j = 0;j < n;j++){
      if(strcmp(red[i],red[j]) == 0) sum++;
    }

    for(j = 0;j < m;j++){
      if(strcmp(red[i],blue[j]) == 0) sum--;
    }

    if(max < sum) max = sum;
  }

  if(max >= 0) printf("%d\n", max);

  else printf("0\n");

  return 0;
}

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

long long calc(long long a,long long b){
	long long d;
	if(a>=b){
		d = a/b;
		if(a == b*d){
			return b*(2*d-1);
		}else{
			return 2*b*d+calc(b,a-(b*d));
		}
	}else{
		return calc(b,a);
	}
}

int main(){
	long long n;
	long long x;
	cin >> n >> x ;
	cout << n+calc(n-x,x) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc157/tasks/abc157_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int[][] array = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				array[i][j] = sc.nextInt();
			}
		}

		int N = sc.nextInt();

		boolean[][] ansArray = new boolean[3][3];
		for (int h = 0; h < N; h++) {
			int number = sc.nextInt();
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (array[i][j] == number) {
						ansArray[i][j] = true;
					}
				}
			}
		}
		sc.close();

		boolean flag = false;

		////////
		for (int i = 0; i < 3; i++) {
			if (ansArray[i][0] && ansArray[i][1] && ansArray[i][2]) {
				flag = true;
			}
		}
		////////
		for (int i = 0; i < 3; i++) {
			if (ansArray[0][i] && ansArray[1][i] && ansArray[2][i]) {
				flag = true;
			}
		}
		//////// 斜めの確認
		if (ansArray[0][0] && ansArray[1][1] && ansArray[2][2]) {
			flag = true;
		}
		//////// 斜めの確認
		if (ansArray[0][2] && ansArray[1][1] && ansArray[2][0]) {
			flag = true;
		}
		////////
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 24020
#include<iostream>
#include<stdio.h>
#include<cmath>
 
using namespace std;
int main () {
    int n;
    while(cin >> n,n!=0){
        double ave,hensa[99],sum=0,s[999];
        for(int i=0;n>i;i++){
            cin >> s[i];
            sum+=s[i];
        }
        ave=sum/n;
        sum=0;
        for(int i=0;n>i;i++){
            sum+=(s[i]-ave)*(s[i]-ave);
        }
        printf("%.6f\n",sqrt(sum/n));
    }
}


Measured memory_bytes: 3296
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	n := func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	arrB := scanArrayInt()
	arrA := make([]int, n)
	arrA[0], arrA[1] = arrB[0], arrB[0]
	for i := 1; i < n-1; i++ {
		if arrA[i] > arrB[i] {
			arrA[i] = arrB[i]
		}
		arrA[i+1] = arrB[i]
	}
	sum := 0
	for i := 0; i < n; i++ {
		sum += arrA[i]
	}
	fmt.Println(sum)
}
func scanArrayInt() []int {
	var ret = []int{}
	stdin.Scan()
	for _, s := range strings.Split(stdin.Text(), " ") {
		i, _ := strconv.Atoi(s)
		ret = append(ret, i)
	}
	return ret
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
#include <queue>

using namespace std;

int main(){
	int dp[31];
	dp[0] = 1;
	dp[1] = 1;
	for(int i=2;i<31;i++){
		dp[i] = 0;
		for(int j=1;j<=3;j++){
			if(i-j<0)break;
			dp[i] += dp[i-j];
		}
	}
	for(int i=0;i<31;i++){
		dp[i] = (dp[i]+3649)/3650;
	}
	while(true){
		int x;
		scanf("%d",&x);
		if(x==0)break;
		printf("%d\n",dp[x]);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

vector<vector<int>> G(100010);
map<pair<int, int>, pair<int,int>> M;
int sm = 0;

void coli(int x, int c, int p) {
	int col = 0;if (c == col)col++;
	for (int i : G[x]) {
		if (i == p)continue;
		M[make_pair(min(i, x), max(i, x))].first = col;
		coli(i, col, x);
		col++;if (col == c)col++;
	}
	return;
}

int main(){
	int N, a, b;
	cin >> N;
	for (int i = 0;i < N - 1;i++) {
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
		M.insert({ make_pair(a,b),{0,i} });
	}
	int si = 0;
	for (int i = 0;i < N;i++) {
		if (sm < G[i].size()) {
			sm = G[i].size();
			si = i;
		}
	}

	int sc = 0;
	for (int i : G[si]) {
		M[make_pair(min(i, si), max(i, si))].first = sc;
		coli(i, sc, si);
		sc++;
	}

	vector<int> ans(N - 1);
	for (auto i : M) {
		ans[i.second.second] = i.second.first;
	}
	cout << sm << endl;
	for (int i = 0;i < N - 1;i++) {
		cout << ans[i] + 1 << endl;
	}
}

Measured memory_bytes: 15616
# from math import factorial,sqrt,ceil,gcd
from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M,Q = map(int,input().split())
times = Q
abcds = []
for _ in range(times):
    abcds.append(list(map(int,input().split()))) # 行列の場合
AnoMoto = list(range(1,M+1))
# print(AnoMoto)
# lenA = len(arrA)
ans = 0
for lisA in combinations_with_replacement(AnoMoto,N):
    # print(lisA)
    num = 0
    for abcd in abcds:
        a,b,c,d = abcd
        if lisA[b-1] - lisA[a-1] == c:
            num += d
        ans = max(ans,num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < n; i++)
int main(){
  int m, d;
  cin >> m >> d;
  int c = 0;
  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= d; j++){
      int a = j / 10;
      int b = j % 10;
      if(a >= 2 && b >= 2 && a * b == i)c++;
    }
  }
  cout << c << endl;  
}

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

int main(void) {
	using namespace std;
	long long int N, K;
	cin >> N >> K;
	vector<pair<int, int>> v;
	for(int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end());
	long long int sum = 0;
	for(int i = 0; i < N; ++i) {
		sum += v[i].second;
		if(K <= sum) {
			cout << v[i].first << '\n';
			return 0;
		}
	}
	return 0;
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  ll na;
  na = abs(n);
  string s;
  char c;
  ll buf = 1;
  if(n != 0)
  for(i = 0; n != 0 /*&& i < 10*/; i++, buf *= -2){
    c = (n % (buf * 2) != 0) + '0';
    //cout << na % 2 << endl;
    s.push_back(c);
    if(c == '1') n -= buf;
    //cout << buf spa n spa s << endl;
  }
  else s.push_back('0');
  reverse(ALL(s));
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)] #n行に１つずつ入力される整数
l_li = []
r_li = []
for l, r in li:
    l_li.append(l)
    r_li.append(r)
print(max(min(r_li) - max(l_li) +1, 0))

Measured memory_bytes: 72280
#include<iostream>

using namespace std;
typedef long long ll;

ll N;

int main(){
    cin >> N;
    ll a, odd, two, four;
    odd = 0;
    two = 0;
    four = 0;
    for(ll i=0; i<N; i++){
        cin >> a;
        if(a%4==0){
            four += 1;
        }else if(a%2==0){
            two += 1;
        }else{
            odd += 1;
        }
    }

    if(four>=odd){
        cout << "Yes" << endl;
    }else if(four==odd-1 && two==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    //system("chcp 65001");

    int A,B,C;
    cin >> A >> B >> C;

    int ans = B/A;

    if(ans >= C)
    {
        cout << C;
    }
    else
    {
        cout << ans;
    }
    

    //cout << N;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int h, m, hh, mm, k;
  cin >> h >> m >> hh >> mm >> k;
  int r = hh * 60 + mm;
  int l = h * 60 + m;
  cout << (r - l - k) << endl;
}

Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  rep(i,0,s.size())if(s[i]=='?')s[i]='D';
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3788
N,Q = gets.chomp.split(" ").map(&:to_i)
S = gets
a = 0
arr = Array.new
arr[0] = 0
for j in 0..N-2 do
  if S[j] == "A" and S[j+1] == "C" then
    a += 1
  else
  end
  arr[j+1] = a
end
for i in 1..Q do
  l,r = gets.chomp.split(" ").map(&:to_i)
puts arr[r-1] - arr[l-1]
end

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


int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t= 1;
	// cin>>t;

	while(t--){
		string s;
		cin>>s;

		ll n = s.length();
		ll i=0,j=0;
		ll ans = 0;
		while(i<n and j<n){
			if(s[j] == 'R') ++j;
			else{
				ans = max(ans,j-i);
				++j;
				i=j;
			}
		}

		ans = max(ans,j-i);
		cout<<ans<<"\n";

	}

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>

using namespace std;

bool IsPrime(int n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  const auto m = (int)sqrt(n);
  for (int i = 3; i <= m; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}

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

  int N;
  cin >> N;

  int n = 0;
  int A[55] = {0};
  for (int i = 11; i <= 55555 && n < N; ++i) {
    if (i % 5 == 1 && IsPrime(i)) {
      A[n] = i;
      ++n;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (i > 0) cout << " ";
    cout << A[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n,m;
    cin >> n >> m;
    vector<int> k(m);
    vector< vector<int>> s(m);
    rep(i,m){
        cin >> k[i];
        rep(j,k[i]){
            s[i].resize(k[i]);
            cin >> s[i][j];
        }
    }
    vector<int> p(m);
    rep(i,m)cin >> p[i];
    int ans = 0;
    for(int bit = 0; bit < (1<<n); bit++){
        vector<int> b;
        for(int i = 0;i<bit;i++){
            if(bit & (1<<i))b.push_back(i+1);
        }
        int on = 0;
        for(int i = 0;i<m;i++){
            bool is = true;
            int cnt = 0;
            for(int j : s[i]){
                if(find(b.begin(),b.end(),j) != b.end()){
                    cnt++;
                }
            }
            if(is == true && cnt%2 == p[i])on++;
        }
        if(on == m)ans++;
    }
    cout << ans << endl;

    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int max = sc.nextInt();
		
		long result = 0;
		
		for(long l = 1; l <= max; l++){
		
			if(!(l%15 == 0) && !(l%5 == 0) && !(l%3 == 0)) {
				
				result += l;
				
			}
		
        }
          
		sc.close();
		
      	System.out.println(result);
      
	}
	
}

Measured memory_bytes: 35812
/*
      author  : nishi5451
      created : 15.08.2020 21:02:53
*/

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


int main(){
    int n;
    cin >> n;
    vector<ll> l(n);
    rep(i,n) cin >> l[i];
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if(l[i]==l[j] || l[j]==l[k] || l[k]==l[i]) continue;
                ll sum = l[i]+l[j]+l[k];
                ll x =max(l[i],max(l[j],l[k]));
                if(x < sum-x) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll t=(c-a-b)*(c-a-b)-4*a*b;
    if(t>0 and (c-a-b)>0)cout<<"Yes";
    else cout<<"No";
    //cout<<sqrt(a)+sqrt(b)<<" "<<sqrt(c);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int ok = true, i;
	vector<int> d(26, 0);
	string s;
	cin >> s;
	for (i = 0; i < s.size(); i++)
		d[s[i] - 'a']++;
	for (i = 0; i < 26; i++) {
		if (d[i] & 1) {
			ok = false;
			break;
		}
	}
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, Y) = Slice2<long>();
            for (var fu = 0; fu <= 2000; ++fu)
                for (var hi = 0; hi <= 2000; ++hi)
                {
                    var fh = 10000 * fu + 5000 * hi;
                    var no = (Y - fh) / 1000;
                    if (0 <= no && N == fu + hi + no)
                    {
                        WriteLine($"{fu} {hi} {no}");
                        return;
                    }
                }
            WriteLine("-1 -1 -1");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27516
# -*- coding: utf-8 -*-
#DISCO A
import sys
import math
import collections
#sys.setrecursionlimit(100000)

#n=int(input())

tmp = input().split()
x,y = list(map(lambda a: int(a), tmp))

total=0

if(x==1)and(y==1):
	total+=400000
if(x==1):
	total+=300000
if(x==2):
	total+=200000
if(x==3):
	total+=100000
if(y==1):
	total+=300000
if(y==2):
	total+=200000
if(y==3):
	total+=100000
print(total)


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
int main(){
  ll sum = 0;
  int n;
  cin >> n;
  vector<int> v(2e5,0);
  int temp;
  for(int i=0;i<n;i++){
    cin >> temp;
    sum += temp;
    v[temp]++;
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int b,c;
    cin >> b >> c;
    sum += (c-b) * v[b];
    cout << sum << endl;
    v[c] += v[b];
    v[b] = 0;
  }
}

Measured memory_bytes: 4040
#include<stdio.h>
int main(void){
int H,W,i,j;
while(1){
scanf("%d%d",&H,&W);
if(H==0 && W==0) break;

for(i=0;i<H;i++){
 for(j=0;j<W;j++){
 if(i==0 || i==H-1)
 printf("#");
else if(j==0 || j==W-1)
 printf("#");
else
 printf(".");
}
 printf("\n");
}
 printf("\n");
}
return 0;
}



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

int main() {
    int x;
    for(int i = 1; ; ++i) {
        cin >> x;
        if (x == 0) {
            break;
        }
        else {
            cout << "Case " << i << ": " << x << endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 3020
#include <iostream>
#include <vector>
#include <complex>
#include <string>
#include <sstream>
#include <cstdio>
#define EPS 1e-10
#define EQ(a,b) (abs(a - b) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))

using namespace std;

typedef complex<double> P;

double dot (P a, P b) {
    return (a.real() * b.real() + a.imag() * b.imag());
}

P crossNormalVector (P a, P b, P p) {
    double t = dot(b-a, p-a) / (abs(b-a) * abs(b - a));
    return a + t * (b - a);
}

P rot_pi (P x, P p) {
    return P(((p.real() - x.real()) * -1) + x.real(), ((p.imag() - x.imag()) * -1) + x.imag());
}

int main ()
{
    string str;
    while (cin >> str) {
        double x1, y1, x2, y2, py, px;
        stringstream ss;
        for (int i = 0; i < str.size(); i++)
            if (str[i] == ',') str[i] = ' ';
        ss << str;
        ss >> x1 >> y1 >> x2 >> y2 >> px >> py;
        P a = P(x1, y1), b = P(x2, y2), p = P(px, py);
        P x = crossNormalVector (a, b, p);
        P res = rot_pi (x, p);
        printf("%.6f %.6f\n", res.real(),res.imag());
    }

    return 0;
}

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

int const N = 2e5 + 41;

vector<int> st;
int a[N], n, l[N], r[N];
long long ans;

void buildL(){
	for(int i=0;i<n;++i){
		while(st.size()){
			int lp = st.back();
			if(a[lp] < a[i]){
				break;
			}
			st.pop_back();
		}
		if(st.size() == 0){
			l[i] = -1;
		}else{
			l[i] = st.back();
		}
		st.push_back(i);
	}
}

void buildR(){
	st.clear();
	for(int i=n-1;i>=0;--i){
		while(st.size()){
			int rp = st.back();
			if(a[rp] < a[i]){
				break;
			}
			st.pop_back();
		}
		if(st.size() == 0){
			r[i] = n;
		}else{
			r[i] = st.back();
		}
		st.push_back(i);
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
	}
	buildL();
	buildR();
	for(int i=0;i<n;++i){
		ans += (r[i]-i) * 1LL * (i-l[i]) * 1LL * a[i];
	}
	printf("%lld\n",ans);




	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  ll K;
  cin >> N >> K;
  vector<int> a(N), b(N);
  vector<pair<int, int>> pr(N);
  REP(i, N){
    cin >> a[i] >> b[i];
    pr[i].first = a[i];
    pr[i].second = b[i];
  }

  sort(pr.begin(), pr.end());
  ll sum = 0;
  REP(i, N){
    sum += pr[i].second;
    if(sum >= K){
      cout << pr[i].first << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()

	if s[0] == s[1] && s[0] == s[2] {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}

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


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

int main() {
	
	fastio;
    // 1 0 -1 k
    rd4(ll, a, b, c, k)
    ll sm = 0;
    
    // a used;
    sm += min(a, k);
    k -= sm;
    
    // remove b
    k -= min(k, b);
        
    // remove c
    sm -= min(k, c);
    
    
    cout << sm;
    
    
    
    
    
    
    
    
    
    
    return 0;
    
    
    
    
}

Measured memory_bytes: 3640
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, M) = reads()

result = 0

k = min(N, M // 2)
(N, M) = (N - k, M - 2 * k)
result += k

k = M // 4
result += k

print(result)


Measured memory_bytes: 4196
using System;
using static System.Console;
using System.Linq;

namespace Contest
{
  class A
  {
    static void Main(string[] args)
    {
      string[] inputs = ReadLine().Split();
      int A = int.Parse(inputs[0]);
      int B = int.Parse(inputs[1]);
      
      WriteLine(B % A != 0 ? B-A : A+B);
    }
  }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int n,m,c,ans=0;
  	cin>>n>>m>>c;
  	vector<int> v(m);
  	for(int i=0;i<m;i++) cin>>v[i];
  	for(int i=0;i<n;i++){
      int t=0,k;
      for(int j=0;j<m;j++) {cin>>k;t+=k*v[j];}
      if(t+c>0) ans++;
    }
  	cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
using namespace std;

#define bll long long
#define dou double
#define For(i,a,b) for (int i=(a),_##i=(b); i<=_##i; ++i)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Cpy(a,b) memcpy(a,b,sizeof(b))

const int maxn=2e5+100;
int N;
char s[maxn];
int match[maxn];
vector <int> pos[30];
int tr[maxn];

void add(int x,int v,int len,int a[])
{
    for (int i=x; i<=len; i+=(i&(-i))) a[i]+=v;
}

int que(int x,int a[])
{
    int ret=0;
    for (int i=x; i; i-=(i&(-i))) ret+=a[i];
    return ret;
}

long long solve()
{
    static int p[maxn];
    static int num[maxn];
    long long ans=0;
    int tot=0;
    int m=0;
    For(i,1,N)
    {
        if (match[i]>i)
        {
            num[i]=num[match[i]]=++tot;
            ans+=i-tot;
        }
        else if (match[i]<i)
        {
            p[++m]=num[i];
        }
        else
        {
            p[++m]=(N>>1)+1;
        }
    }
    memset(tr,0,sizeof(tr[0])*(m+2));
    For(i,1,m)
    {
        ans+=que(p[i],tr);
        add(p[i],1,m,tr);
    }
    return ans;
}

int main()
{
    for (; scanf("%s",s+1)!=EOF; )
    {
        N=strlen(s+1);
        For(i,0,25) pos[i].clear();
        For(i,1,N) pos[s[i]-'a'].push_back(i);
        int odd=0;
        For(i,0,25)
        {
            if (((int)pos[i].size())&1) ++odd;
            int j=0,k=pos[i].size()-1;
            for (; j<=k; ++j,--k) match[pos[i][j]]=pos[i][k],match[pos[i][k]]=pos[i][j];
        }
        if (odd>1)
        {
            printf("-1\n");
        }
        else
        {
            printf("%lld\n",solve());
        }
    }
    return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	cin>>n>>m;
	vector<string>in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	rep(i,n)cout<<in[i];
	cout<<endl;
}
 
 







Measured memory_bytes: 256
n = gets.to_i
min_f = 20
a = 1
while a * a <= n do
  b = n / a
  if a * b == n
    f = [a.to_s.length, b.to_s.length].max
    min_f = f if min_f > f
  end
  a += 1
end
puts min_f


Measured memory_bytes: 1788
#include<cstdio>
#include<queue>
#include<unordered_set>
using namespace std;
struct edge
{
	int e, nxt;
};
int m;
edge a[200100];
int st[100100];
int n, u, v;
bool vv[100100];
int main()
{
	scanf("%d%d%d", &n, &u, &v);
	for (int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		a[++m].e = y; a[m].nxt = st[x]; st[x] = m;
		a[++m].e = x; a[m].nxt = st[y]; st[y] = m;
	}
	unordered_set<int> f[2]; // fronts after kth step
	unordered_set<int> p[2]; // visited after kth step
	f[0].insert(u); p[0].insert(u);
	queue<int> vq[2]; vq[0].push(v); vv[v] = true;
	int ans = 0;
	while(true)
	{
		// takahashi's turn
		for (auto x : f[ans & 1])
		{
			for (int j = st[x]; j; j = a[j].nxt)
			{
				int y = a[j].e;
				if (p[!(ans & 1)].count(y)) continue;
				if (vv[y]) continue;
				p[!(ans & 1)].insert(y);
				f[!(ans & 1)].insert(y);
			}
		}
		if (p[!(ans & 1)].empty()) break; // takahashi ran into aoki
		f[ans & 1].clear();
		while (!vq[ans & 1].empty())
		{
			int x = vq[ans & 1].front(); vq[ans & 1].pop();
			for (int j = st[x]; j; j = a[j].nxt)
			{
				int y = a[j].e;
				if (vv[y]) continue;
				vv[y] = true; vq[!(ans & 1)].push(y);
				if (p[0].count(y)) p[0].erase(y);
				if (p[1].count(y)) p[1].erase(y);
				if (f[!(ans & 1)].count(y)) f[!(ans & 1)].erase(y);
			}
		}
		ans++;
		if (p[ans & 1].empty()) break; // aoki erased all positions
	}
	printf("%d\n", ans);
	return 0;
}


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

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] L = new int[N];
    
    for (int i = 0; i < N; i++) {
      L[i] = Integer.parseInt(sc.next());
    }
    
    Arrays.sort(L);
    
    int count = 0;
    for (int i = 0; i < N-2; i++) {
      for (int j = i+1; j < N-1; j++) {
        int min = j+1;
        int max = N;
        if (L[i] + L[j] <= L[min]) {
          continue;
        }
        int k;
        while (true) {
          k = (min + max) / 2;
          if (L[i] + L[j] > L[k]) {
            min = k;
          } else {
            max = k;
          }
          if (max - min <= 1) {
            break;
          }
        }
        count += min - j;
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 26696
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

double dis(const vector<double>& x,
	   const vector<double>& y,
	   const double p) {

    const int n = x.size();
    double d = 0.0;

    if( p == -1 ) {
	for(int i=0; i<n; i++) {
	    d = max(d,abs(x[i]-y[i]));
	}
	return d;
    }

    for(int i=0; i<n; i++) {
	d += pow(abs(x[i]-y[i]),p);
    }
    return pow(d,1/p);
}

int main() {
    int n; cin >> n;
    vector<double> x,y;
    for(int i=0; i<n; i++) {
	double t; cin >> t;
	x.push_back(t);
    }
    for(int i=0; i<n; i++) {
	double t; cin >> t;
	y.push_back(t);
    }

    for(int i=1; i<=3; i++)
	printf("%.10f\n",dis(x,y,i));
    printf("%.10f\n",dis(x,y,-1));

}

Measured memory_bytes: 3416
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>

using namespace std;

int main() {
int N, Q;
string S;
    cin >> N >> S >> Q;
    const int sq =  static_cast<int>(sqrt(N));
    vector< bitset<26> > backet(N / sq);
    for(int i = 0; i < (N / sq) * sq; i++) {
        char c = S[i];
        backet[i / sq][c - 'a'] = true;
    }

    for(int i = 0; i < Q; i++) {
        int c;
        cin >> c;
        if(c == 1) {
            int j;
            char cc;
            cin >> j >> cc;
            j--;
            S[j] = cc;
            if (j >= (N / sq) * sq) continue;
            backet[j / sq].reset();
            for(int k = 0; k < sq; k++) {
                backet[j / sq][S[(j / sq) * sq + k] - 'a'] = true;
            }
            continue;
        }
        int l, r;
        cin >> l >> r;
        bitset<26> chs;
        int it = l - 1;
        while(it < r) {
            if(it % sq == 0 && it + sq <= r) {
            /* 
                cout << endl;
                cout << S << endl;
                cout << backet[it / sq] <<" "<< it << "-" << it + sq << endl;
            */
                chs |= backet[it / sq];
                it += sq;
                continue;
            }
            chs[S[it] - 'a'] = true;
            it++;
        }
        cout << chs.count() << endl;
    }
    return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a,b,c,d; 
int main()
{
   cin>>a>>b>>c>>d;
    int x=(a+d-1)/d;
    int y=(c+b-1)/b;
    cout<<(x>=y?"Yes":"No");

return 0;
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  int N,K;
  cin >> N >> K;
  if(1+ (K-1) * 2 <= N){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

vector<int> choice;
string name[10];
int weight[10];
int s[10];
bool done[10];
int n;
pair<double,vector<int> > ret;
void bt(){
	int test;
	for(int i=0;i<choice.size();i++){
		test = 0;
		for(int j=i+1;j<choice.size();j++){
			test+=weight[choice[j]];
		}
		if(s[choice[i]] < test)return;
	}
	if(choice.size() == n){
		double G=0,DIV=0;	
		for(int i=0;i<choice.size();i++){
			G += (i+1)*weight[choice[i]];
			DIV += weight[choice[i]];
		}
		ret = min(ret,make_pair(G/DIV,choice));
	}
	
	for(int i=0;i<n;i++){
		if(!done[i]){
			done[i] = true;
			choice.push_back(i);
			bt();
			done[i] = false;
			choice.pop_back();
		}
	}
}

int main(){
	while(cin >> n, n){
		ret = make_pair(1<<21,0);
		for(int i=0;i<n;i++){
			cin >> name[i] >> weight[i] >> s[i];
		}
		bt();
		for(int i=0;i<ret.second.size();i++){
			cout << name[ret.second[i]] << endl;
		}
	}
}
		

Measured memory_bytes: 912
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

// dist[v] に頂点 s から頂点 v への距離を入れる関数
void dijkstra(int s, Graph &G, vector<ll> &dist){
  fill(all(dist), INF);
  dist[s] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;//距離が小さい順に取り出す
  pq.push(P(0,s)); // 頂点 s からスタート

  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;// 既に v に辿り着く短い経路有ならスルー (これはただの高速化)

    for(auto e : G[v]){// v から行ける頂点 nv 達を走査
      int nv = e.to;
      ll w = e.weight;
      if(dist[nv] > dist[v] + w){
        dist[nv] = dist[v] + w;
        pq.push(P(dist[nv], nv));
      }
    }
  }
}

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};



int main(){
  int n; cin >> n;
  vl c(n); rep(i,n) cin >> c[i];
  sort(all(c));

  vl t(n+1,1);
  rep(i,n) t[i+1] = (t[i] * 2)%MOD;

  ll ans = 0;
  rep(i,n) {
    int l = i, r = n-i-1;
    ll tmp = t[r];
    if(r != 0) tmp = (t[r] + t[r-1] * r)%MOD;
    tmp = (tmp * t[l])%MOD;
    tmp = (tmp * c[i])%MOD;
    ans = (ans + tmp)%MOD;
  }
  ans = (ans * t[n])%MOD;
  cout << ans << endl;
}

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

using namespace std;

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

	vector<int> tmp(2*k, 1e9);

	for (int i = 0; i < k; i++)
	{
		tmp[i] = a + i;
	}

	int l = 0;

	for (int i = 0; i < k; i++, l++)
	{
		tmp[k + i] = b - l;
	}

	set<int> s;

	for (auto x : tmp)
	{
		if (x < a || x > b)
		{
			continue;
		}
		s.insert(x);
	}

	for (auto x : s)
	{
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int count_mid_length(const std::string &str, int left, int right, int k, const char &base) {
	--k;
	do {
		++k; --left; ++right;
	} while (left >= 0 && right < str.length() && str[left] == str[right] && str[left] == base);
	return k;
}
int main() {
	std::string str;
	std::cin >> str;
	if (str.length() % 2 == 0) {
		std::cout <<  count_mid_length(str, str.length() / 2, str.length() / 2 - 1, str.length() / 2, str[str.length() / 2]);
	}
	else {
		std::cout << count_mid_length(str, str.length() / 2 + 1, str.length() / 2 - 1, str.length() / 2, str[str.length() / 2]);
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

#define N 12

using namespace std;

int xdir[4] = {0, 1, 0, -1};
int ydir[4] = {1, 0, -1, 0};

char island[N][N+2];

void dfs(int y, int x)
{
  island[y][x] = '0';

  for(int i = 0; i < 4; ++i){
    int next_x = x + xdir[i];
    int next_y = y + ydir[i];

    if(0 <= next_x && next_x < N &&
       0 <= next_y && next_y < N &&
       island[next_y][next_x] == '1'){
      dfs(next_y, next_x);
    }
  }
}

int main()
{
  do {
    for(int i = 0; i < N; ++i)
      fgets(island[i], sizeof island[i]/ sizeof island[i][0], stdin);

    int count = 0;
    for(int i = 0; i < N; ++i)
      for(int j = 0; j < N; ++j)
	if(island[i][j] == '1'){
	  ++count;
	  dfs(i, j);
	}

    cout << count << endl;

  } while(fgets(island[0], sizeof island[0]/sizeof island[0][0], stdin) != NULL);

  return 0;
}

Measured memory_bytes: 1124
#include<stdio.h>
int a[10],b=0,c=0;
bool tube[10];
bool dfs(int i){
    if(i==10) return true;
    bool flagb,flagc;
    if(b>=a[i]&&c>=a[i]) return false;
    if(b<a[i]){
        int oldb=b;
        b=a[i];
        flagb=dfs(i+1);
        b=oldb;
        if(flagb) return true;
    }
    if(c<a[i]){
        int oldc=c;
        c=a[i];
        flagc=dfs(i+1);
        c=oldc;
        if(flagc) return true;
    }
    return flagb||flagc;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            scanf("%d",a+j);
        }
        if(dfs(0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1008
#include "bits/stdc++.h"
using namespace std;

int main()
{
	char* input;
	input = (char*)malloc(sizeof(char) * 3);
	scanf("%s", input);

	for(int i=0;i<3;i++)
	{
		input[i] = (input[i]=='1')?'9':'1';
	}
	printf("%s\n", input);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a,b,c,d,e,k;
  bool Acase = false,Bcase = false,Ccase = false,Dcase = false;
  cin>>a>>b>>c>>d>>e>>k;
  if(b-a <= k && c-a <= k && d-a <= k && e-a <= k){
    Acase = true;
  }
   if(c-b <= k && d-b <= k && e-b <= k){
    Bcase = true;
  }
   if(d-c <= k && e-c <= k){
    Ccase = true;
  }
   if(e-d <= k){
    Dcase = true;
  }
  if(Acase && Bcase && Ccase && Dcase){
    cout<<"Yay!"<<endl;
  }
  else
  {
    cout<<":("<<endl;
  }
}

Measured memory_bytes: 256