akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  while(1){
    string s;
    int a,b,c,d;
    cin >> s;
    if(s[0]=='#')break;
    int w=0;
    int h=1;
    int i,j,k;
    for(i=0;i<s.size();i++){
      if(h==1){
	if(s[i]!='/'){
	  if(s[i]=='b')w++;
	  else w+=s[i]-'0';
	}
	else h++;
      }
      else if(s[i]=='/')h++;
    }
    vector<vector<int> >m(h,vector<int>(w,0));
    i=0;
    j=0;
    for(k=0;k<s.size();k++){
      if(s[k]=='/')continue;
      if(s[k]=='b'){
	m[i][j]=1;
	j++;
      }
      else{
	int l=s[k]-'0';
	for(int I=0;I<l;I++)m[i][j+I]=0;
	j+=l;
      }
      if(j==w){
	i++;
	j=0;
      }
    }
    cin >> a >> b >> c >> d;
    m[a-1][b-1]=0;
    m[c-1][d-1]=1;
    int co=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(m[i][j]==1){
	  if(co>0){
	    cout << co;
	    co=0;
	  }
	  cout << 'b';
	}
	else co++;
      }
      if(co>0){
	cout << co;
	co=0;
      }
      if(i+1!=h)cout << '/' ;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
package main

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

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

func min(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m > v {
			m = v
		}
	}
	return m
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Candles
	var N, K int
	fmt.Scan(&N, &K)

	sc.Split(bufio.ScanWords)
	x := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = nextInt()
	}

	var l, r int
	var ans int = 1000000000
	for i := 0; i < N-K+1; i++ {
		l = x[i]
		r = x[i+K-1]
		ans = min(ans, abs(l)+abs(r-l), abs(r)+abs(r-l))
	}

	fmt.Println(ans)
}


Measured memory_bytes: 4200
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n";
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define vii vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define MOD LLONG_MAX
#define INF 1e18 + 5
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
const int mx = 1e5 + 9;
vector<int> in(mx);
vector<bool> vis(mx,false);
vector<vii> adj(mx);
vector<int> dist(mx,0);
void dfs(int node)
{
    vis[node] = true;
    for(int next : adj[node])
    {
        dist[next] = max(dist[next], dist[node] + 1);
        in[next]--;
        if(in[next]==0) dfs(next);
    }
    return;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    int t;
    t = 1;
    while (t--)
    {
        int n,m;
        cin >> n >> m;
        int a,b;
        rep(i,0,m)
        {
            cin >> a >> b;
            adj[a].pb(b);
            in[b]++;
        }
        rep(i,1,n+1)
        {
            if(!vis[i] && in[i]==0) dfs(i);
        }
        int ans = 0;
        rep(i,1,n+1) ans = max(ans,dist[i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 14976
from collections import deque

s = deque(input())
q = int(input())
re = False

for i in range(q):
    try:
        a,f,c = map(str, input().split())
    except ValueError:
        re = not re
        continue

    if f == "1":
        if not re:
            s.appendleft(c)
        else:
            s.append(c)
    else:
        if not re:
            s.append(c)
        else:
            s.appendleft(c)

if re:
    s = list(reversed(s))

print("".join(s))


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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i=0;i<h;i++){
    cin >> a.at(i);
  }
  
  for(int i=0;i< 2*h;i++){
    cout << a.at(i/2) << endl;
  }
  cout <<  endl;
  
  return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
info=[0]
for i in range(n):
    info.append(list(map(int,input().split())))
ans="TLE"
cost=10000
for i in range(1,n+1):
    if info[i][1]<=t and info[i][0]<cost:
        cost=info[i][0]
        ans=str(cost)
print(ans)

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

int main(){
	int n;
	while(cin >> n){
		int ans = 0;
		for(int a = 0;a < 10;a++){
			for(int b = 0;b < 10;b++){
				for(int c = 0;c < 10;c++){
					for(int d = 0;d < 10;d++){
						if(a+b+c+d == n)ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

graph  = [[] for _ in range(N+1)]
for _ in range(M):
    x,y = map(int,input().split())
    graph[x].append(y)
    graph[y].append(x)

visited = [0]*(N)
ans = 0

def DFS(pos):
    global visited
    global ans
    if sum(visited) == N:
        ans += 1
        return

    for i in graph[pos]:
        if visited[i-1]:
            continue
        visited[i-1] = 1
        DFS(i)
        visited[i-1] = 0
    return

visited[0] = 1
DFS(1)
print(ans)

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

int n, s;
vector<int> a, b;
int main()
{
	int i, t;
	cin >> n;
	while (n--) {
		scanf("%d", &t);
		if (t < 0) a.push_back(t);
		else b.push_back(t);
	}
	if (a.size() == 0) {
		sort(b.begin(), b.end());
		if (b.size() == 2) {
			cout << b[1] - b[0] << endl << b[1] << ' ' << b[0];
			return 0;
 		}
		for (i = 1; i < b.size(); i++) s += b[i];
		s -= b[0];
		cout << s << endl;
		printf("%d %d\n", b[0], b[1]);
		t = b[0] - b[1];
		for (i = 2; i < b.size() - 1; i++) printf("%d %d\n", t, b[i]), t -= b[i];
		printf("%d %d\n", b[b.size() - 1], t);
	} else if (b.size() == 0) {
		if (a.size() == 2) {
			cout << a[0] - a[1] << endl << a[0] << ' ' << a[1];
			return 0;
 		}
		sort(a.begin(), a.end(), greater<int>());
		for (i = 1; i < a.size(); i++) s -= a[i];
		s += a[0];
		cout << s << endl;
		printf("%d %d\n", a[0], a[1]);
		t = a[0] - a[1];
		for (i = 2; i < a.size(); i++) printf("%d %d\n", t, a[i]), t -= a[i];
	} else {
		for (i = 0; i < a.size(); i++) s -= a[i];
		for (i = 0; i < b.size(); i++) s += b[i];
		cout << s << endl;
		for (i = 1; i < b.size(); i++) printf("%d %d\n", a[0], b[i]), a[0] -= b[i];
		for (i = 1; i < a.size(); i++) printf("%d %d\n", b[0], a[i]), b[0] -= a[i];
		printf("%d %d\n", b[0], a[0]);
	}
    return 0;
}

Measured memory_bytes: 2424
#include <iostream>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a>=13){
        cout << b << endl;
    } else if(a>=6 and a<=12){
        cout << b/2 << endl;
    } else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    K = int(input())

    ans = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            x = gcd(a, b)
            for c in range(1, K + 1):
                ans += gcd(x, c)
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 76872
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, p[11];

  std::cin >> N;

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

  std::sort(p, p + N);

  p[N - 1] /= 2;

  std::cout << std::accumulate(p, p + N, 0) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,M,R,a[50],b[50],n[60],f[60][10];
int t[60];
bool canA[50][50][30],canB[50][50][30];		//[i,j) ??§k????????????????
bool tmp[50][50][60][10];			//[i,j)??§rule k ???l??????????????§?????????????
void calccan(int* a,int N,bool can[50][50][30]){
	rep(i,50) rep(j,50) rep(k,30) can[i][j][k]=0;
	rep(i,50) rep(j,50) rep(k,60) rep(l,10) tmp[i][j][k][l]=(i==j&&l==0);
	rep(i,N*2-1) can[i][i+1][a[i]]=1;
	rep1(len,N){
		for(int l=0;l+len<=2*N-1;l++){
			int r=l+len;
			rep(i,R) rep1(j,n[i]){
				for(int x=l;x<r;x++){
					if(tmp[l][x][i][j-1]&&can[x][r][f[i][j-1]]) tmp[l][r][i][j]=1;
				}
			}
			rep(i,R) if(tmp[l][r][i][n[i]]) can[l][r][t[i]]=1;
			rep(i,R) if(can[l][r][f[i][0]]) tmp[l][r][i][1]=1;
		}
	}
}
int main(){
	while(true){
		cin>>N>>M>>R;
		if(N==0) break;
		rep(i,N) cin>>a[i],a[i]--;
		rep(i,N) a[i+N]=a[i];
		rep(i,M) cin>>b[i],b[i]--;
		rep(i,M) b[i+M]=b[i];
		rep(i,R){
			cin>>n[i];
			rep(j,n[i]) cin>>f[i][j],f[i][j]--;
			cin>>t[i],t[i]--;
		}
		calccan(a,N,canA);
		calccan(b,M,canB);
		int ans=-1;
		rep(x,N) rep(y,M){		//start
			int dp[26][26]={};
			rep(i,N+1) rep(j,M+1) dp[i][j]=-1;
			dp[0][0]=0;
			rep(i,N+1) rep(j,M+1){
				if(dp[i][j]<0) continue;
				rep(k,30){
					rep1(c,N-i) rep1(d,M-j){
						if(canA[x+i][x+i+c][k]&&canB[y+j][y+j+d][k]) chmax(dp[i+c][j+d],dp[i][j]+1);
					}
				}
			}
			chmax(ans,dp[N][M]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4648
#include "bits/stdc++.h"
using namespace std;
#define ASC(vec) vec.begin(), vec.end()			// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, N) for (int i = 0; i < N; i++)
typedef long long ll;

int main() 
{
	int val; cin >> val;
	if (val % 2 == 0)
	{
		cout << (val / 2) * (val / 2) << endl;
	}
	else
	{
		cout << (val / 2) * (val / 2 + 1) << endl;
	}
}

Measured memory_bytes: 256
N, num_of_blue, num_of_red = map(int, input().split())

num_of_repetition = (N // (num_of_blue + num_of_red))
remainder_s = N % (num_of_blue + num_of_red)

count_b = num_of_blue * num_of_repetition + min(num_of_blue, remainder_s)

print(count_b)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                int n=0,w=0;
                cin>>n>>w;
                long long weight[n+1]={0},value[n+1]={0};
                for(int i=1;i<=n;i++)
                {
                    cin>>weight[i]>>value[i];
                }
                long long ans[n+1][w+1];
                for(long long i=0;i<n+1;i++)
                    ans[i][0]=0;
                for(long long i=0;i<=w;i++)
                    ans[0][i]=0;
                for(long long i=1;i<=n;i++)
                {
                    for(long long j=1;j<=w;j++)
                    {
                        if(weight[i]>j)
                            ans[i][j]=ans[i-1][j];
                        else
                        {
                            ans[i][j]=max(value[i],max(ans[i-1][j],value[i]+ans[i-1][j-weight[i]]));
                        }
                    }
                }
              /*  for(int i=0;i<=n;i++)
                {
                    for(int j=0;j<=w;j++)
                        cout<<ans[i][j]<<"\t";
                    cout<<endl;
                }*/
                cout<<ans[n][w];
                return 0;
            }


Measured memory_bytes: 79104
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x)&(-x)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define maxd 1000000007
typedef long long ll;
const int N=100000;
const double pi=acos(-1.0);
int n,cnt[30],q,pos[200200],op[2][200200];
char s[200200],t[10];

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int left(int mid)
{
	int now=mid;
	rep(i,1,q)
	{
		if (op[0][i]==pos[now]) now+=op[1][i];
		if (now>n) return 0;
		if (now<1) return 1;
	}
	return 0;
}

int rght(int mid)
{
	int now=mid;
	rep(i,1,q)
	{
		if (op[0][i]==pos[now]) now+=op[1][i];
		if (now>n) return 1;
		if (now<1) return 0;
	}
	return 0;
}

int main()
{
	n=read();q=read();
	scanf("%s",s);
	rep(i,1,n) pos[i]=s[i-1]-'A';
	rep(i,1,q)
	{
		scanf("%s",t);
		op[0][i]=t[0]-'A';
		scanf("%s",t);
		if (t[0]=='L') op[1][i]=-1;else op[1][i]=1;
	}
	int l=1,r=n,ansl=0,ansr=n+1;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (left(mid)) {ansl=mid;l=mid+1;}
		else r=mid-1;
	}
	l=1;r=n;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (rght(mid)) {ansr=mid;r=mid-1;}
		else l=mid+1;
	}
	//cout << ansl << " " << ansr << endl;
	printf("%d",n-ansl-(n-ansr+1));
	return 0;
}
	


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

int main(){
  int N,K,zaiko[128],a,flag;
  for(;cin>>N>>K,N||K;){
    flag=0;
    for(int i=0;i<K;i++)cin>>zaiko[i];
    for(int i=0;i<N;i++){
      for(int j=0;j<K;j++){
        cin>>a; zaiko[j]-=a;
        if(zaiko[j]<0)flag=1;
      }
    }
    puts(flag?"No":"Yes");
  }
  return 0;
}

Measured memory_bytes: 836
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main() {
  int A,B;
  cin >> A >> B;
  vector<int> X(3);
  X[0] = A+B;
  X[1] = A-B;
  X[2] = A*B;
  sort(X.begin(), X.end());
  cout << X[2] << endl;
}

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

typedef long long ll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
int fact[N], ifact[N];
int rt[N];
int c[N], w[N];
int mn[N];
int n, x, y;

int Find(int x) {
    return rt[x] == -1 ? x : rt[x] = Find(rt[x]);
}

void Union(int u, int v) {
    u = Find(u); v = Find(v);
    if (u == v) return ;
    rt[u] = v;
}

map<int, int> cnt[N];

void init() {
    fact[0] = 1;
    for (int i=1; i<N; ++i) fact[i] = (ll)fact[i-1] * i % MOD;
    ifact[0] = ifact[1] = 1;
    for (int i=2; i<N; ++i) ifact[i] = ((ll)MOD-MOD/i) * ifact[MOD%i] % MOD;
    for (int i=1; i<N; ++i) ifact[i] = (ll)ifact[i-1] * ifact[i] % MOD;
    
    memset(rt, -1, sizeof(rt));
}

int main() {
    init();
    scanf("%d%d%d", &n, &x, &y);
    for (int i=1; i<=n; ++i) scanf("%d%d", c+i, w+i);
    for (int i=1; i<=n; ++i) if (!mn[c[i]] || w[mn[c[i]]] > w[i]) mn[c[i]] = i;
    for (int i=1; i<=n; ++i) if (w[i] + w[mn[c[i]]] <= x) Union(i, mn[c[i]]);
    int p = min_element(w+1, w+n+1)-w, q = 0;
    for (int i=1; i<=n; ++i) if (c[i] != c[p] && (!q || w[q] > w[i])) q = i;
    for (int i=1; i<=n; ++i) {
        if (c[i] != c[p] && w[i] + w[p] <= y) Union(i, p);
        if (c[i] != c[q] && w[i] + w[q] <= y) Union(i, q);
    }
    for (int i=1; i<=n; ++i) ++cnt[Find(i)][c[i]];
    int ans = 1;
    //???
    for (int i=1; i<=n; ++i) {
        int sum = 0, cur = 1;
        for (auto it: cnt[i]) {
            sum += it.second;
            cur = (ll)cur * ifact[it.second] % MOD;
        }
        cur = (ll)cur * fact[sum] % MOD;
        ans = (ll)ans * cur % MOD;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    if(s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;

int main(){
    int N,C,ans=0,p; cin >> N >> C;
    for(int i=0; i<C; i++){
        cin >> p;
        ans+=p;
    }
    if(ans%(N+1)!=0) cout << ans/(N+1)+1 << endl;
    else cout << ans/(N+1) << endl;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#define INF 100000
using namespace std;

int check(string s, int length, int point) {
    if (s[point] != 'm') return INF;
    point++;
    
    if (s[point] != 'e') {
        point = check(s, length, point);
        if (point == INF) return INF;
    }
    point++;

    if (s[point] != 'w') {
        point = check(s, length, point);
        if (point == INF) return INF;
        if (s[point] != 'w') return INF;
    }
    point++;

    return point;
}

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

    int flag = check(s, s.length(), 0);
    if (flag == INF || flag < s.length()) cout << "Rabbit" << endl;
    else cout << "Cat" << endl;

    return 0;
}

Measured memory_bytes: 3244
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextString(scanner)
	q := getNextInt(scanner)
	seg := newSegment(n)
	for i := 0; i < n; i++ {
		seg.update(i, 1<<uint(s[i]-'a'), seg.or)
	}
	for i := 0; i < q; i++ {
		switch getNextInt(scanner) {
		case 1:
			seg.update(getNextInt(scanner)-1, 1<<uint(getNextString(scanner)[0]-'a'), seg.or)
		case 2:
			fmt.Fprintln(writer, pcount(seg.query(getNextInt(scanner)-1, getNextInt(scanner), 0, seg.or)))
		}
	}
}
func pcount(x uint32) int {
	y := 0
	for x > 0 {
		if x&1 == 1 {
			y++
		}
		x >>= 1
	}
	return y
}

type segment [][]uint32

func newSegment(n int) segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]uint32, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]uint32, 1))
	return seg
}
func (seg segment) update(i int, v uint32, f func(x, y uint32) uint32) {
	seg[0][i] = v
	for h := 1; h < len(seg); h++ {
		i >>= 1
		if i<<1+1 < len(seg[h-1]) {
			seg[h][i] = f(seg[h-1][i<<1], seg[h-1][i<<1+1])
		} else {
			seg[h][i] = seg[h-1][i<<1]
		}
	}
}
func (seg segment) query(l, r int, s uint32, f func(x, y uint32) uint32) uint32 {
	for h := 0; h < len(seg) && l < r; h++ {
		if l%2 == 1 {
			s = f(s, seg[h][l])
			l++
		}
		l >>= 1
		if r%2 == 1 {
			s = f(s, seg[h][r-1])
		}
		r >>= 1
	}
	return s
}
func (seg segment) or(x, y uint32) uint32 {
	return x | y
}


Measured memory_bytes: 7724
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
#include <set>
 
using namespace std;
 
int sqrtN = 512;
struct SqrtDecomposition{
    int N, K;
    vector <long long> data;
    vector <long long> bucketUpdatedLazy;
    vector <long long> bucketSum;
    vector <bool> needUpdate;
    SqrtDecomposition(int n){
        N = n;
        K = (N + sqrtN - 1) / sqrtN;
        data.assign(N + sqrtN, 0);
        bucketUpdatedLazy.assign(K, 0);
        needUpdate.assign(K, false);
        bucketSum.assign(K, 0);
    }
 
    void propagateLazy(int k){
        if(!needUpdate[k]){
            return;
        }
        for(int i = 0; i < sqrtN; i++){
            data[k * sqrtN + i] = bucketUpdatedLazy[k];
        }
        bucketSum[k] = bucketUpdatedLazy[k] * sqrtN;
        needUpdate[k] = false;
    }


    long long get(int x){
        propagateLazy(x / sqrtN);
        return data[x];
    }

    long long getSum(int x, int y){
        propagateLazy(x / sqrtN);
        propagateLazy((y - 1) / sqrtN);
        long long ans = 0;
        if(y - x < sqrtN){
            for(int i = x; i < y; i++){
                ans += data[i];
            }
            return ans;
        }
        for(int i = x / sqrtN + 1; i < y / sqrtN; i++){
            ans += bucketSum[i];
        }                  

        for(int i = x; i < (x / sqrtN + 1) * sqrtN; i++){
            ans += data[i];
        }
        for(int i = y / sqrtN * sqrtN; i < y; i++){
            ans += data[i];
        }
        return ans;
    }
 
    void update(int x, int y, long long a){
        if(y - x < sqrtN){
            propagateLazy(x / sqrtN);
            propagateLazy((y - 1) / sqrtN);
            for(int i = x; i < y; i++){
                bucketSum[i/sqrtN] += (a - data[i]);
                data[i] = a;
            }
            return;
        }
        for(int i = x / sqrtN + 1; i < y / sqrtN; i++){
            bucketUpdatedLazy[i] = a;
            needUpdate[i] = true;
            bucketSum[i] = a * sqrtN;
        }

        propagateLazy(x / sqrtN);
        for(int i = x; i < (x / sqrtN + 1) * sqrtN; i++){
            bucketSum[i/sqrtN] += (a - data[i]);
            data[i] = a;
        }
        propagateLazy((y - 1)/ sqrtN);
        for(int i = y / sqrtN * sqrtN; i < y; i++){
            bucketSum[i/sqrtN] += (a - data[i]);
            data[i] = a;
        }
    }
     
};

 
int main(){
    int n;
    int q;
    cin >> n >> q;
    SqrtDecomposition sq(n);
    for(int i = 0; i < q; i++){
        int com;
        int s;
        int t;
        int x;
        cin >> com;
        if(com == 0){
            cin >> s >> t >> x;
            sq.update(s, t + 1, x);
        } else {
            cin >> s >> t;
            cout << sq.getSum(s, t + 1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[101][101],b,c,d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;

long double dist(int i, int j){
    long double sum=0;
    rep(k,d)sum+=pow(abs(a[i][k]-a[j][k]),2.0);
    return sqrt(sum);
}

int main(){
    cin>>n>>d;
    rep(i,n)rep(j,d){
        cin>>a[i][j];
    }
    rep(i,n)rep(j,i+1,n){
        long double x = dist(i,j);
        if(ceil(x) == x)ans++;
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

vvint vv;
vll v;
bool ok = true;

ll dfs(int x, int pre){
	ll sum = 0;
	ll MX = 0;
	if(vv[x].size() == 1){
		return v[x];
	}
	for(int y: vv[x]){
		if(y == pre) continue;
		ll t = dfs(y, x);
		maxs(MX, t);
		sum += t;
	}

	ll ret = 2 * v[x] - sum;
	if(ret<0) ok=false;
	if(ret>v[x]) ok=false;
	if(MX-ret>sum-MX) ok=false;
	return ret;
}


bool mainmain(){
	int n;
	cin>>n;
	v=vll(n);
	rep(i,n) cin>>v[i];
	if(n==2){
		return v[0] == v[1];
	}
	vv = vvint(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		vv[a].PB(b);
		vv[b].PB(a);
	}
	int root = -1;
	rep(i,n){
		if(vv[i].size()>1) root = i;
	}
	assert(root>=0);
	ll ans = dfs(root, -1);
	return ans == 0 && ok;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    cout<<(mainmain()?"YES":"NO")<<endl;
}

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

const int MAX = 2e5 + 111;

int n, T;

int t[MAX];

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> T;
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    sort(t, t + n);
    int last = T;
    int ans = T;
    for (int i = 1; i < n; ++i) {
        if (t[i] + T > last) {
            ans += t[i] + T - max(last, t[i]);
            last = t[i] + T;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
s,t=input().split()
a,b=map(int,input().split())
u=input()
ans=[]
if u==s:
  ans.append(str(a-1))
  ans.append(str(b))
else:
  ans.append(str(a))
  ans.append(str(b-1))
print(" ".join(ans))

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

/*
STRLENGTHは入力される文字列の最大の長さ
CMDLENGTHは入力される命令の最大の長さ(広めに確保)
*/
#define STRLENGTH 1000
#define CMDLENGTH 10

//それぞれ文字列を出力、逆順、置き換える関数
void print(char *str, int start_point, int end_point);
void reverse(char *str, int start_point, int end_point);
void replace(char *dst, char *src, int start_point, int end_point);

int main(void)
{
	int i, start_point, end_point, data_count;
	//cmdは"print"、"revrese"、"replace"のいずれかが入力される
	char cmd[CMDLENGTH];
	//new_strは"replace"が入力された際に置き換える文字列を格納
	char str[STRLENGTH], new_str[STRLENGTH];

	//文字列とデータセットの個数を入力
	scanf("%s", str);
	scanf("%d", &data_count);

	//データセットの個数分繰り返す
	for(i = 0; i < data_count; i++){
		//命令、開始位置、終了位置を入力
		scanf("%s %d %d", cmd, &start_point, &end_point);

		//命令に応じた関数を呼び出す
		if(!(strcmp(cmd, "print"))){
			print(str, start_point, end_point);
		}
		else if(!(strcmp(cmd, "reverse"))){
			reverse(str, start_point, end_point);
		}
		else if(!(strcmp(cmd, "replace"))){
			scanf("%s", new_str);
			replace(str, new_str, start_point, end_point);
		}
	}

	return 0;
}

//start_pointからend_pointまでの文字列を出力する関数
void print(char *str, int start_point, int end_point)
{
	//outputに出力する文字列を格納
	int size;
	char output[STRLENGTH];

	//start_pointからend_pointまでの文字列をoutputにコピーし出力する
	size = (end_point - start_point) + 1;
	strncpy(output, &str[start_point], size);
	output[size] = '\0';

	printf("%s\n", output);
}

//start_pointからend_pointまでの文字列を逆順にする関数
void reverse(char *str, int start_point, int end_point)
{
	//workには逆順にする範囲の文字列を格納
	int i, size;
	char work[STRLENGTH];

	size = (end_point - start_point) + 1;
	strncpy(work, &str[start_point], size);

	//文字列を逆順にする
	for(i = 0; i < size; i++){
		*(str + start_point + i) = work[size - i - 1];
	}
}

//start_pointからend_pointまでの文字列を置き換える関数
void replace(char *dst, char *src, int start_point, int end_point)
{
	int i, size;

	size = (end_point - start_point) + 1;
	//文字を1つずつ置き換える
	for(i = 0; i < size; i++){
		*(dst + start_point + i) = *(src + i);
	}
}


Measured memory_bytes: 2112
#include <iostream>
#include <cstring>
#include <vector>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
vector<int>v[20];
int c[20],ans[20];
int n,m,x;
int minx=1e9;
int flag=0;
void dfs(int cur, int sum)
{
    if(cur==n+1)
    {
        //cout<<sum<<endl;
        int cnt=0;
       // For(i,0,m-1)cout<<ans[i]<<' ';
       // cout<<endl<<endl;
        For(i,0,m-1)if(ans[i]>=x)cnt++;
        if(cnt==m)
        {
            flag=1;
            minx=min(sum,minx);
        }
        return;
    }
    For(i,0,m-1)ans[i]+=v[cur][i];
    dfs(cur+1,sum+c[cur]);
    For(i,0,m-1)ans[i]-=v[cur][i];
    dfs(cur+1,sum);
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>x;
    int temp;
    For(i,1,n)
    {
        cin>>c[i];
        For(j,1,m)
        {
            cin>>temp;
            v[i].push_back(temp);
        }
    }
    dfs(1,0);
    if(flag)cout<<minx<<endl;
    else cout<<-1<<endl;
    return 0;
}


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

int main() {
    int N, K; cin>> N >> K;
    vector<int> S(N);
    rep(i, K){
        int d; cin >> d;
        rep(j, d){
            int A; cin >> A;
            S[A-1]++;
        }
    }

    int ans = 0;
    rep(i, N){
        if (S[i] == 0){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
//mangesh2102000

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

vector <int> g[100005];
int n;
int dp[100005][2];

int f(int node,int color,int parent)
{
	if(dp[node][color]!=-1)
		return dp[node][color];

	dp[node][color] = 1;

	for(int i=0;i<g[node].size();i++)
	{
		int child = g[node][i];

		if(child == parent)
			continue;

		int tmp;

		if(color == 0)
		{
			tmp = (f(child,1,node)) % mod;
		}
		else
		{
			tmp = (f(child,0,node) + f(child,1,node)) % mod;
		}

		dp[node][color] *= tmp;
		dp[node][color] %= mod;
	}

	return dp[node][color];
}


void solve(int t)
{
	cin >> n;
	int u,v;
	for(int i=0;i<n-1;i++)
	{
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}

	memset(dp,-1,sizeof(dp));

	int ans = f(1,0,0) + f(1,1,0);
    ans %= mod;

    cout << ans;
    //cout << "Case #" << t << ": ";    
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define mod 1000000007
#define inf (1LL<<60)
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;

int dp[10001][101][2];
int solve(string s,int D,int pos,int d,bool tight)
{
    if(dp[pos][d][tight]!=-1)
        return dp[pos][d][tight];
    int ub=tight?s[pos]-'0':9;
    if(pos==s.size()-1)
    {
        int a=0;
        for(int x=0;x<=ub;x++)
        {
            if(x%D==d)
                a++;
        }
        return a;
    }
    int ans=0;
    for(int x=0;x<=ub;x++)
        ans=(ans+solve(s,D,pos+1,(D+d-x%D)%D,tight==1&&x==ub))%mod;
    return dp[pos][d][tight]=ans;
}

signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof dp);
    string s;
    int D;
    cin>>s>>D;
    cout<<(mod+solve(s,D,0,0,1)-1)%mod;
}



Measured memory_bytes: 115712
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	string res(n, '?');
	function<void(int, int)> solve = [&](int u, int c){
		if(u == n){
			cout << res << "\n";
			return;
		}
		for(int i = 0; i <= c; ++ i){
			res[u] = i + 'a';
			solve(u + 1, c + (i == c));
		}
	};
	solve(0, 0);
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <iostream>
#include <climits>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define INF 1LL << 60;
#include <string>
#include <typeinfo>
#include <bitset>

int main(){
  ll D,G;
  cin >> D >> G;
  vector<int> p(D+100),c(D+100);
  int result = 1e9;
  
  for(int i=0; i < D; i++){
    cin >> p.at(i) >> c.at(i);
  }
  
  for(int i=0; i < (1 << D); i++){
    ll sum = 0;
    int ans = 0, rest = -1;
    for(int j=0; j < D; j++){
      if((i >> j & 1) == 1){
        sum += 100*(j+1)*p.at(j) + c.at(j);
        ans += p.at(j);
      }
      else{
        rest = j;
      }
    }  
    if(sum >= G){
      result = min(result , ans);
      continue;
    }
    else{
      if(rest == -1){
        break;
      }
      else{
        int loss = (G - sum -1)/(100*(rest+1)) + 1;
        if(loss >= p.at(rest) ){
          continue;
        }                         
        else{
          ans += loss;
        }
      }
      result = min(result, ans);
      continue;                           
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  131_A_ Security
//
//  Created by tolemy on 2019/07/18.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <iostream>

int main(int argc, const char * argv[]) {
    
    
    std::string s;
    std::cin >> s;
    
    for(int i=0;i<=s.size()-1;i++)
    {
        if(s[i] == s[i+1])
        {
            std::cout << "Bad" << std::endl;
            return 0;
        }
    }
    
    std::cout << "Good" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>

using namespace std;
using ll = long long;

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

	vector <vector <vector<int> > > adj(n);

	for (int i = 1; i < n; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;

		adj[u].push_back({ v, w });
		adj[v].push_back({ u, w });
	}


	vector<ll> kyori(n, -1);

	queue<int> q;
	kyori[0] = 0;
	q.push(0);

	int cnt = 1;
	while (cnt < n)
	{
		int oya = q.front();
		q.pop();
		for (auto node : adj[oya])
		{
			if (kyori[node[0]] < 0)
			{
				q.push(node[0]);
				kyori[node[0]] = node[1] + kyori[oya];
				cnt++;
			}
		}
	}

	for (ll i : kyori)
	{
		cout << i % 2 << endl;
	}

	return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;







int main() {

	ll l, r;
	cin >> l >> r;
	if (r - l > 2050) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = INF;
	FOR(i, l, r + 1) {
		FOR(j, l, r + 1) {
			if (i == j)continue;
			ans = min(ans, i*j % 2019LL);
		}
	}

	cout << ans << endl;

	return 0;
}

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

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

  if (S == "SSS") {
    cout << 0 << endl;
  }
  else if (S == "RRS" || S == "SRR") {
    cout << 2 << endl;
  }
  else if (S == "RRR") {
    cout << 3 << endl;
  }
  else {
      cout << 1 << endl;
  }

}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int N,k,ans=0;
	cin >> N >> k;

	ans = (N*3+k)/2;

	cout << ans << endl;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(){
    int W;
    int H;
    int x;
    int y;
    int r;
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
    if ((y-r<0 or x-r>W or x-r<0 or y-r>H) or (W<x+r or H<y+r)){
        cout << "No" <<"\n";
    }else{
        cout << "Yes" <<"\n";
    }
}


Measured memory_bytes: 3096
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdint>

int main() {
  constexpr int K = 9 * 2;
  int N;
  std::cin >> N;
  std::vector<std::vector<int>> counts(K + 1, std::vector<int>(K + 1));
  std::int64_t count = 0;
  for (int i = 0; i < N; ++i) {
    double a;
    std::cin >> a;
    auto value = static_cast<std::int64_t>(std::round(a * 1.0e9));
    int count2 = 0, count5 = 0;
    while (value % 2 == 0) {
      value /= 2;
      ++count2;
    }
    while (value % 5 == 0) {
      value /= 5;
      ++count5;
    }
    count2 = std::min(count2, K);
    count5 = std::min(count5, K);
    for (int i = K - count2; i <= K; ++i) {
      for (int j = K - count5; j <= K; ++j) {
        count += counts[i][j];
      }
    }
    ++counts[count2][count5];
  }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 3788
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return len(divisors)

N = int(input())
cnt = 0
for i in range(1,N+1,2):
    if divisors(i) == 8:
        cnt += 1
print(cnt)

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

int main()
{
    int R, C; cin >> R >> C;

    auto goal = vector<string>(R);
    for (auto& row : goal) cin >> row;

    auto answer = array<vector<string>, 2>{goal, goal};
    for (auto row = 0; row < R; row++)
        answer[0][row][0] = answer[1][row][C-1] = '#';
    for (auto row = 0; row < R; row++)
        for (auto column = 1; column < C-1; column++)
            answer[row%2][row][column] = '#';

    for (auto row : answer[0]) cout << row << endl;
    cout << endl;
    for (auto row : answer[1]) cout << row << endl;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define EPS (1e-10)    //誤差
typedef complex<double> P;

//実数同士の比較
bool EQ(double a, double b){
    return (abs(a - b) < EPS);
}

//外積
double cross(P a, P b){
    return (a.real() * b.imag() - a.imag() * b.real());
}

bool func(P a, P b, P c){
    return ((a.real() < b.real() + EPS && b.real() < c.real() + EPS) || (c.real() < b.real() + EPS && b.real() < a.real() + EPS));
}

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

// 点cが線分a,b上にあるかないか(3)
bool is_point_on_line(P a, P b, P c) {
  // |a-c| + |c-b| <= |a-b| なら線分上
  return (abs(a-c) + abs(c-b) < abs(a-b) + EPS);
}

int main(){
    
    P p0, p1;
    cin >> p0.real() >> p0.imag() >> p1.real() >> p1.imag();
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        P p2;
        cin >> p2.real() >> p2.imag();

        //sinの正負で場合分け
        if(EQ(cross(p1 - p0, p2 - p0), 0.0)){
            
            //線分上かどうか
            if(is_point_on_line(p0, p1, p2)){
                cout << "ON_SEGMENT" << endl;
            }else{

                if(dot(p2 - p0, p1 - p0) < 0){
                    cout << "ONLINE_BACK" << endl;
                }else{
                    cout << "ONLINE_FRONT" << endl;
                }
            }

        }else if(cross(p1 - p0, p2 - p0) > 0 - EPS){
            cout << "COUNTER_CLOCKWISE" << endl;
        }else if(cross(p1 - p0, p2 - p0) < 0 + EPS){
            cout << "CLOCKWISE" << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3256
def prime(n):
    flag = [True]*(n+1)
    flag[0] = flag[1] = False
    for i in range(2,int(n**0.5)+1):
        if flag[i]:
            for j in range(i**2, n+1, i):
                flag[j] = False
    return flag
flag = prime(123456*2)
while True:
    n = int(input())
    if n==0: break
    print(flag[n+1:2*n+1].count(True))

Measured memory_bytes: 11024
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var input = Reads();
            var h = input[0];
            var w = input[1];
            var s = new char[h][];
            for (int i = 0; i < h; i++)
            {
                s[i] = Console.ReadLine().ToCharArray();
            }
       
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    var count = 0;
                    if (s[i][j] == '.')
                    {
                        for (int k = -1; k <= 1; k++)
                        {
                            for (int l = -1; l <=1; l++)
                            {
                                if (i + k < h && -1 < i + k && j + l < w && -1 < j +l && s[i + k][j + l] == '#')
                                    count++;
                            }
                        }
                        s[i][j] = (char)('0' + count);
                    }
                    
                }
            }

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                { 
                    Console.Write(s[i][j]);
                }
                Console.WriteLine();
            }
            
         


            Console.Out.Flush();
        }
    }
}


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

using namespace std;

int n, t, a, x[1005], ans;

int main() {
	scanf("%d%d%d", &n, &t, &a);
	t *= 1000;
	a *= 1000;
	for (int i = 0; i < n; i++) {
		scanf("%d", x + i);
		x[i] = t - 6 * x[i];
		if (abs(x[i] - a) < abs(x[ans] - a))
			ans = i;
	}
	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 256