akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  cin>>N;

  int Z,W;
  int a[N];
  cin>>Z>>W;

  rep(i,N){
    cin>>a[i];
  }

  if(N==1) {cout<< abs(a[N-1]-W) <<"\n"; return;}

  cout<< max(abs(a[N-2]-a[N-1]),abs(a[N-1]-W))<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	int x[n];
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
	}
	int mn=1e18;
	for(int i=1;i<=100;i++)
	{
		int ans=0;
		for(int j=0;j<n;j++)
		{
			ans+=(i-x[j])*(i-x[j]);
		}
		mn=min(mn,ans);
	}
	cout<<mn;
} 
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

ll wrp(ll a, ll b, ll c){
    return gcd(gcd(a, b), c);
}

int main() {
    ll k, cnt = 0;
    cin >> k;

    for(ll i = 1; i <= k; i++){
        for(ll j = 1; j <= k; j++){
            for(ll l = 1; l <= k; l++){
                cnt += wrp(i, j, l);
            }
        }
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3636
n = gets.chomp.to_i
ans = 0
hash = Hash.new(0)

n.times do |i|
    a = gets.chomp.to_i
    if hash[a] == 1
        hash[a] -= 1
    else
        hash[a] += 1
    end
end
hash.each do |i|
    if i[1] == 1
        ans += 1
    end
end
puts ans

Measured memory_bytes: 19060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int b=0;
  char a[3];
  cin>>a;
  for(int i=0;i<3;i++){
    if(a[i]=='o')
      b++;
  }
    cout<<700+b*100<<endl;

  
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char str[100001];
	scanf("%s", str);
	int i = 0;
	int count = 0;
	while (str[i])
	{
		if (str[i] == str[i + 1])
		{
			if(str[i] == '0')
			{
				count++;
				str[i + 1]++;
			}
			else if (str[i] == '1')
			{
				count++;
				str[i + 1]--;
			}
		}
		i++;
	}
	printf("%d\n", count);
	return (0);
}

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

using namespace std;

int dp1[1000001], dp2[1000001];

int main()
{
    fill(dp1, dp1 + 1000001, 1000000000);
    fill(dp2, dp2 + 1000001, 1000000000);
    
    dp1[0] = dp2[0] = 0;
    
    for (int i = 1; i * (i + 1) * (i + 2) <= 6000000; i++){
        int s = i * (i + 1) * (i + 2) / 6;
        
        if (s & 1){
            for (int j = 0; j + s <= 1000000; j++){
                dp2[j + s] = min(dp2[j + s], dp2[j] + 1);
            }
        }
        for (int j = 0; j + s <= 1000000; j++){
            dp1[j + s] = min(dp1[j + s], dp1[j] + 1);
        }
    }
    
    int n;
    
    while (scanf("%d", &n) && n){
        printf("%d %d\n", dp1[n], dp2[n]);
    }
    
    return (0);
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define sz              size()
#define pb              push_back
#define Fr              first
#define Sc              second
#define Log2(x)         (31^__builtin_clz(x))
#define endl            "\n"
#define int             ll
using namespace std;
typedef long long ll;
set<int> s;
int n;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    s.insert(n);
    s.insert(2);
    n--;
    if(n > 1) s.insert(n);
    for(int i = 2 ; i * i <= n ; i++) {
        if(n % i == 0) {
            if(n / i == i) s.insert(i);
            else s.insert(i), s.insert(n / i);
        }
    }
    n++;
    for(int i = 2 ; i * i <= n ; i++) {
        if(n % i == 0) {
            int c = n;
            while(c % i == 0) c /= i;
            if(c > i && c % i == 1) s.insert(i);
            else if(c == 1) s.insert(i);
            c = n;
            int t = n / i;
            while(c % t == 0) c /= t;
            if(c > t && c % t == 1) s.insert(t);
            else if(c == 1) s.insert(t);
        }
    }

    cout << s.sz << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(n):
  if i%2!=n%2:
    b.append(a[i])
  else:
    c.append(a[i])
b.reverse()
b.extend(c)
print(' '.join(map(str,b)))

Measured memory_bytes: 31480
#include <iostream>
#include <algorithm>
#define N 100
using namespace std;
struct data{
  string str;
  int n;
  bool operator<(const data & right)const{
    if(str!=right.str) return str<right.str;
    return n<right.n;
  }
};
int main(){
  int i=0;
  struct data d[N];
  while(1){
    cin >> d[i].str >> d[i].n;
    if(d[i].str=="") break;
    i++;
  }
  sort(d,d+i);
  cout << d[0].str << endl << d[0].n;
  for(int j=1;j<i;j++){
    if(d[j].str==d[j-1].str) cout << ' ' << d[j].n;
    else cout << endl << d[j].str << endl << d[j].n;
  }
  cout << endl;
  return 0;
}

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

template<typename T>
struct edge {
    int src, to;
    T cost;
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

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

ll powmod(ll a, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= a) %= MOD;
        (a *= a) %= MOD;
        n >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    int n; cin >> n;
    int zeros = 0;
    map<pair<ll,ll>, ll> mp;
    REP(i, n) {
        ll a, b; cin >> a >> b;
        if (a == 0 and b == 0) {
            ++zeros;
            continue;
        }

        if (a < 0 or (a == 0 and b < 0)) {
            a *= -1;
            b *= -1;
        }

        ll g = gcd(abs(a), abs(b));
        a /= g;
        b /= g;
        ++mp[{a, b}];
    }

    map<pair<ll,ll>, bool> used;
    ll ans = 1;
    for (auto& tp : mp) {
        if (used[tp.first]) continue;
        //used[tp.first] = 1;
        ll a, b, m; tie(a, b) = tp.first; m = tp.second;

        if (b > 0) {
            if (mp.count({b, -a})) {
                used[{b, -a}] = 1;
                (ans *= (powmod(2, m) + powmod(2, mp[{b, -a}]) - 1) % MOD) %= MOD;
            }
            else {
                (ans *= powmod(2, m)) %= MOD;
            }
        }
        else {
            if (mp.count({-b, a})) {
                used[{-b, a}] = 1;
                (ans *= (powmod(2, m) + powmod(2, mp[{-b, a}]) - 1) % MOD) %= MOD;
            }
            else {
                (ans *= powmod(2, m)) %= MOD;
            }
        }
    }

    if (--ans < 0) ans += MOD;

    (ans += zeros) %= MOD;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 28516
object methods {
  def solver(): Unit = {

    val tempList: Seq[Seq[String]] = {
      for (line <- io.Source.stdin.getLines()) yield {
        line.split(' ').toSeq
      }
    }.toSeq
    val N: Int = tempList(0)(0).toInt //電球の個数
    val K: Int = tempList(0)(1).toInt //操作回数
    val initBrightness: Seq[Int] = tempList(1).map(_.toInt)

    //K回更新：いもす法ならこの関数でO((N+N)*K)：ナイーブな解法ならO(N*N*K)
    val kUpBrightness: Seq[Int] = loop(1, K, N, initBrightness)

    //val kUpBrightness: Seq[Int] = UpdateBrightness(N, initBrightness)：いもす法では累積和が答え
    println(kUpBrightness.mkString(" "))
  }

  //累積和を使った計算（いもす法）：ランプの左始点に+1ランプの右切れ端に-1
  def UpdateByCumulativeSum(N: Int, BrightSeq: Seq[Int]): Seq[Int] = {
    //記録
    val illuminateNumCount: Array[Int] = Seq.fill(N)(0).toArray[Int]
    var i = 0
    var count: Boolean = true
    while (i < N) {
      val illuminateStart: Int = {
        if (i - BrightSeq(i) < 0) 0
        else i - BrightSeq(i)
      }
      val illuminateOut: Int = {
        if (i + BrightSeq(i) + 1 > BrightSeq.length -1) { //インデックス最大値よりも.lengthは1多い
          count = false
          BrightSeq.length
        } else {
          count = true
          i + BrightSeq(i) + 1
        }
      }
      illuminateNumCount(illuminateStart) += 1
      if (count) illuminateNumCount(illuminateOut) -= 1
      i += 1
    }
    //計測：ここで計算量はO(N+N)
    val cumulativeIlluminateNum: Seq[Int] = illuminateNumCount.scanLeft(0)((x, y) => x+y).toSeq 
    cumulativeIlluminateNum.drop(1) //累積和の一番最初はいらないのでそれを覗いたSeqを返す
  }

  def loop(k: Int, K: Int, N: Int, Brightness: Seq[Int]): Seq[Int] = {
    val CurrentBrightness = UpdateByCumulativeSum(N, Brightness)

    // 計算時間エラー起こった：O(logN)回の操作で収束するらしい。なにそれってかんじだが41回を上限とする
    if(k < K && k < 42) loop(k+1, K, N, CurrentBrightness)
    else CurrentBrightness
  }

}

object Main extends App {
  methods.solver()
}

Measured memory_bytes: 107840
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	var c = parseInt(tmp[2], 10);
  	var d = ""+a+b+c;
  	d%4 === 0? console.log('YES') : console.log('NO')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  long long a, b, c, d, t;
  cin >> a >> c >> b >> d >> t;
  if (d >= c) puts("NO");
  else {
    long long d1 = abs(a - b);
    long long d2 = c - d;
    if (t * d2 >= d1) puts("YES");
    else puts("NO");
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using pp = pair<int, int>;
const ll INF = 1e10;

ll N, A, B;
vector<ll> h;

bool f(ll k) {
    ll tmp = 0;
    for (int i = 0; i < N; i++) {
        ll rem = h[i] - B * k;
        if (rem > 0) tmp += (rem + (A - B - 1)) / (A - B);
    }
    return (tmp <= k);
}

ll binary_search(ll ok, ll ng) {
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

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

    cin >> N >> A >> B;
    h.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    cout << binary_search(INF, 0) << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]) {
    sc.next
    val s = sc.next
    val n = s.length
    println(1.until(n).map(
      i => s.splitAt(i)
    ).map({
      case (l, r) => l.distinct.count(x => r.contains(x))
    }).max)
  }
}


Measured memory_bytes: 27472
// B - Buffet
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int N; cin>>N;
	vi A(N), B(N), C(N-1);
	rp(i,N){cin>>A[i]; --A[i];}//Ai={0~N-1}
	rp(i,N) cin>>B[i];
	rp(i,N-1) cin>>C[i];

	int ans = 0;
	int now, pre = -N;//Ai={0~N-1}
	rp(i,N){
		now = A[i];
		ans += B[now];
		if(now==pre+1) ans += C[pre];
		pre = now;
	}
	cout<< ans <<endl;
}

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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,a,b,c,q,sum=0;
    map<int,int> m;
    cin>>n;

    forn(i,0,n){
    	cin>>a;
    	m[a]++;
    	sum+=a;
    }

    cin>>q;

    forn(i,0,q){
    	cin>>b>>c;
    	sum+=(c-b)*m[b];
    	m[c]+=m[b];
    	m.erase(b);
    	cout<<sum<<'\n';
    }
    
    return 0;
}

Measured memory_bytes: 6452
import collections
N=int(input())
NUM=[i for i in range(1,N+1)]
H=list(map(int, input().split()))
L_NUM=[x+y for (x,y) in zip(NUM,H)]
R_NUM=[x-y for (x,y) in zip(NUM,H)]

L_dict=collections.Counter(L_NUM)
R_dict=collections.Counter(R_NUM)

ANS=0
for i in L_dict.keys():
    cnt=L_dict[i]*R_dict[i]
    ANS+=cnt
print(ANS)

Measured memory_bytes: 71208
#!/usr/bin/env python3


def solve(n, ss):
    num_ab = sum(s.count("AB") for s in ss)
    num_both = sum(s[-1] == "A" and s[0] == "B" for s in ss)
    num_right_a = sum(s[-1] == "A" for s in ss) - num_both
    num_left_b = sum(s[0] == "B" for s in ss) - num_both
    # B --- A
    res = num_ab 
    if num_both > 0:
        res += num_both - 1
        if num_right_a > 0:
            num_right_a -= 1
            res += 1
        if num_left_b > 0:
            num_left_b -= 1
            res += 1
    # (X)B --- A(X)
    res += min(num_right_a, num_left_b)
    return res


def main():
    n = int(input())
    ss = [input() for _ in range(n)]
    res = solve(n, ss)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 47356
package main

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

type Tup struct {
	x int
	y int
}

func main() {
	sc := NewScanner()
	H, W, D := sc.NextInt(), sc.NextInt(), sc.NextInt()
	mp := map[int]Tup{}
	for i := 0; i < H; i++ {
		l := strings.Split(sc.NextLine(), " ")
		for j := 0; j < W; j++ {
			p, _ := strconv.Atoi(l[j])
			mp[p] = Tup{i + 1, j + 1}
		}
	}

	memo := make([][]int, D+1)
	for i := 0; i <= D; i++ {
		memo[i] = make([]int, H*W/D+1)
		for j := i + D; j <= H*W; j += D {
			k := j - D
			memo[i][j/D] = memo[i][j/D-1] + abs(mp[j].x-mp[k].x) + abs(mp[j].y-mp[k].y)
		}
	}

	Q := sc.NextInt()
	for i := 0; i < Q; i++ {
		L, R := sc.NextInt(), sc.NextInt()
		total := memo[L%D][R/D] - memo[L%D][L/D]
		fmt.Println(total)
	}

}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 12940
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define MOD 1001
#define MAX 10001
int fibo[MAX];
int p[MAX];
int getfibo(int n)
{  
	if(n<1)return 1;
	if(fibo[n])return fibo[n];
	return fibo[n]=(getfibo(n-1)+getfibo(n-2))%MOD;
}
int root(int a)
{  
	return p[a]<0?a:(p[a]=root(p[a]));
}
int find(int a,int b)
{
  return root(a)==root(b);
}
void merge(int a,int b)
{  
	p[root(a)]=root(b);
}
int main(void)
{  
	fibo[0]=1;
	fibo[1]=2;
	int a,d,i,j;
	while(scanf("%d%d",&a,&d)==2)
	{    
		memset(p,-1,sizeof(p));
		for(i=1;i<=a;i++)
		{      
			for(j=1;j<=a;j++)
			{
				if(abs(getfibo(i)-getfibo(j))<d)
				{          
					if(!find(i,j))merge(i,j);
				}
			}
		}    
		int b[MAX]={0},res,c=0;
		for(i=1;i<=a;i++)
		{
		  res=root(i);
		  if(!b[res])
		  {        
			  b[res]=1;c++;
		  }
		}
		printf("%d\n",c); 
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int h = sc.NextInt();
        int w = sc.NextInt();
        int k = sc.NextInt();

        string[] c = new string[h];
        for (int i = 0; i < h; i++)
        {
            c[i] = sc.Next();
        }

        int ans = 0;
        int lr = 1 << h;
        int lc = 1 << w;
        for (int i = 0; i < lr; i++)
        {
            for (int j = 0; j < lc; j++)
            {
                int cnt = 0;
                for (int l = 0; l < h; l++)
                {
                    for (int m = 0; m < w; m++)
                    {
                        if(c[l][m] == '#' && (i & (1 << l)) == 0 && (j & (1 << m)) == 0)
                        {
                            cnt++;
                        }
                    }
                }

                if (cnt == k)
                {
                    ans++;
                }
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  const int nMAXSIZ = cnrvnMtrx.size() - 1;
  for (int i = 1; i <= nMAXSIZ; ++i)  rvvnDetDP[i][i] = 0;

  for (int nDif = 1; nDif <= nMAXSIZ - 1; ++nDif)
    for (int nBgn = 1; nBgn <= nMAXSIZ - nDif; ++nBgn)
    {
      int nEnd = nBgn + nDif;
      for (int nx = nBgn; nx <= nEnd - 1; ++nx)
        rvvnDetDP[nBgn][nEnd] =
          min(rvvnDetDP[nBgn][nEnd],
              rvvnDetDP[nBgn][nx] + rvvnDetDP[nx + 1][nEnd] 
                                  + cnrvnMtrx[nBgn - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nEnd]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

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

const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int h, w, n;
    cin >> h >> w >> n;
    cout << (n - 1) / max(h, w) + 1 << endl;
}

Measured memory_bytes: 256
import math

if __name__ == '__main__':
    n = int(input())
    ans = float('inf')

    a = 1
    while a <= math.sqrt(n):
        if n % a == 0:
            b = n // a
            f = max(math.floor(math.log10(a) + 1), math.floor(math.log10(b) + 1))
            ans = min(f, ans)

        a += 1

    print(ans)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

string r = "qwertasdfgzxcvb";
string l = "yuiophjklnm";

//ture -> right false -> left
bool check(char c) {
	bool flag = false;
	rep(i, sz(r)) {
		if (r[i] == c)flag = true;
	}
	return flag;
}

int main() {
	while (true) {
		string s; cin >> s;
		if (s == "#")break;

		vector<bool> f;
		rep(i, sz(s)) {
			f.pb(check(s[i]));
		}
		int cnt = 0;
		rep(i, sz(f) - 1) {
			if (f[i] != f[i + 1])cnt++;
		}
		cout << cnt << endl;
	}
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N;
string S[100010];
map<string, int> mp;

void _main() {
    cin >> N;
    REP (i, N) {
        cin >> S[i];
        mp[S[i]]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 6780
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int x, n, tmp=INT_MAX, tmpp=INT_MAX;
    int p[max], a[max];
    int ans[max], sa, j=0;
    int i;
    
    for (i=0; i<=110; i++) {
        a[i]=0;
        ans[i]=0;
    }
    
    scanf("%d%d", &x, &n);
    rep(i, n){
        scanf("%d", &p[i]);
        a[p[i]]++;
    }
    
    for (i=0; i<=110; i++) {
        if (a[i]==0) {
            sa=abs(x-i);
            if (sa<tmp) {
                tmp=sa;
                ans[j]=i;
                //printf("%d, ", ans[j]);
                j++;
            }
        }
    }
    
    qsort(ans, j+1, sizeof(int), down_comp);
    
    printf("%d", ans[0]);
    
    return 0;
}



Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    i64 S;
    cin >> S;
    const i64 x1 = 1e9;
    i64 x2 = (x1 - (S%x1)) % x1;
    i64 y2 = (S+x2) / x1;
    cout << 0 << " " << 0 << " " << x1 << " " << 1 << " " << x2 << " " << y2 << endl;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
order = []
for i in range(n):
    tmp = [a[i], i+1]
    order.append(tmp)
order.sort(key=lambda x: (x[0], -x[1]))
for i in range(n):
    print(order[i][1], end=" ")
print("\n")

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e2 + 10;
const int mod = 1e9 + 7;


map<int,int> mp;

int32_t main(){
	boost;

	int a , b;

	cin >> a >> b;

	if(a == b){
		cout << "Draw";
	}
	else if(a == 1){
		cout << "Alice";
	}
	else if(b == 1){
		cout << "Bob";
	}
	else if(a > b)
		cout << "Alice";
	else
		cout << "Bob";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N=1e5+100;
int n,q,m;
ll l[N],tag[N],c[N];

void solve(ll x,ll v){
	if (!x) return;
	int p=upper_bound(l+1,l+1+m,x)-l-1;
	if (!p){c[1]+=v,c[x+1]-=v; return;}
	tag[p]+=(x/l[p])*v;
	solve(x%l[p],v);
}

int main(){
	scanf("%d%d",&n,&q); l[m=1]=n;
	rep (i,1,q){
		ll x; scanf("%lld",&x);
		while (m&&l[m]>=x) m--; l[++m]=x;
	}
	tag[m]=1;
	for (int i=m;i>1;i--){
		tag[i-1]+=tag[i]*(l[i]/l[i-1]);
		solve(l[i]%l[i-1],tag[i]);
	}
	c[1]+=tag[1]; c[l[1]+1]-=tag[1];
	rep (i,1,n) c[i]+=c[i-1], printf("%lld ",c[i]);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
int main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12){
		if(b == 31){
			cout<<1;
		}else{
			cout<<0;
		}
	}else{
		if(a == 2 && c != a){
			cout<<1;
		}else if(a == 2 && c == a){
			cout<<0;
		}else{
			if(b == 30){
				cout<<1;
			}else{
				cout<<0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n, m;
    cin >> n >> m;
    vector<tuple<ll, ll, ll>> segh, segv;
    map<ll, ll> zipx, zipy;
    zipx[0] = 0;
    zipy[0] = 0;
    rep(i, n){
        ll a, b, c;
        cin >> a >> b >> c;
        zipx[a] = 0;
        zipx[b] = 0;
        zipy[c] = 0;
        segh.emplace_back(a, b, c);
    }
    rep(i, m){
        ll a, b, c;
        cin >> a >> b >> c;
        zipx[a] = 0;
        zipy[b] = 0;
        zipy[c] = 0;
        segv.emplace_back(b, c, a);
    }
    vector<ll> xs, ys;
    for(auto& i : zipx){
        i.second = xs.size();
        xs.push_back(i.first);
    }
    for(auto& i : zipy){
        i.second = ys.size();
        ys.push_back(i.first);
    }
    
    ll h = xs.size()*2;
    ll w = ys.size()*2;
    vector<vector<ll>> field(h, vector<ll>(w));
    rep(i, n){
        ll a = zipx[get<0>(segh[i])]*2;
        ll b = zipx[get<1>(segh[i])]*2;
        ll c = zipy[get<2>(segh[i])]*2;
        for(ll j = a; j <= b; j++) field[j][c] = -1;
    }
    rep(i, m){
        ll a = zipy[get<0>(segv[i])]*2;
        ll b = zipy[get<1>(segv[i])]*2;
        ll c = zipx[get<2>(segv[i])]*2;
        for(ll j = a; j <= b; j++) field[c][j] = -1;
    }

    queue<pair<ll,ll>> q;
    ll sx = zipx[0]*2, sy = zipy[0]*2;
    field[sx][sy] = 1;
    q.emplace(sx,sy);
    ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
    while(!q.empty()){
        ll x = q.front().first, y = q.front().second;
        q.pop();
        rep(i, 4){
            ll xx = x + dx[i], yy = y + dy[i];
            if(xx < 0 || xx >= h) continue;
            if(yy < 0 || yy >= w) continue;
            if(field[xx][yy] != 0) continue;
            field[xx][yy] = 1;
            q.emplace(xx,yy);
        }
    }
    ll ans = 0;
    rep(x, h){
        rep(y, w){
            if(field[x][y] != 1) continue;
            if(x == 0 || x == h-1 || y == 0 || y == w-1){
                cout << "INF" << endl;
                return 0;
            }
            if(x%2 == 0 || y%2 == 0) continue;
            ll xx = xs[x/2+1] - xs[x/2], yy = ys[y/2+1] - ys[y/2];
            ans += xx * yy;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 285484
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int ans = 0;

void binary(vector<int>& a,int b){
    a[0]++;
    for(int i=0;i<b;i++){
        if(a[i]==2){
            a[i] = 0;
            a[i+1]++;
        }
    }
}

int check(vector<vector<char>> C,vector<int> h,vector<int> w,int H,int W,int K){
    int count = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(h[i]==1||w[j]==1){
                C[i][j] = '0';
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(C[i][j]=='#') count++;
        }
    }
    if(count==K) return 1;
    else return 0;
}

int main(){
    int H,W,K;cin>>H>>W>>K;
    vector<vector<char>> C(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> C[i][j];
        }
    }
    vector<int> h(H+1);
    vector<int> w(W+1);
    int ans = 0;
    while(h[H]!=1){
        w[W] = 0;
        while(w[W]!=1){
            ans += check(C,h,w,H,W,K);
            binary(w,W);
        }
        binary(h,H);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;

int main(){
    double px,py;
    scanf("%lf %lf", &px, &py);
    double cx,cy,r;
    scanf("%lf %lf %lf", &cx, &cy, &r);
    double d1 = r * r / ((cx - px) * (cx - px) + (cy - py) * (cy - py));
    double d2 = r * sqrt((cx - px) * (cx - px) + (cy - py) * (cy - py) - r * r) / ((cx - px) * (cx - px) + (cy - py) * (cy - py));
    double xIntersect = cx + d1 * (px - cx);
    double yIntersect = cy + d1 * (py - cy);
    double ansx1,ansx2,ansy1,ansy2;
    ansx1 = xIntersect + d2 * (py - cy);
    ansy1 = yIntersect - d2 * (px - cx);
    ansx2 = xIntersect - d2 * (py - cy);
    ansy2 = yIntersect + d2 * (px - cx);
    
    if(fabs(ansx1 - ansx2) < 1e-10 && ansy1 > ansy2){
        swap(ansx1, ansx2);
        swap(ansy1, ansy2);
    } else if (ansx1 - ansx2 > 1e-10){
        swap(ansx1, ansx2);
        swap(ansy1, ansy2);
    }
    printf("%.10lf %.10lf\n%.10lf %.10lf\n", ansx1, ansy1, ansx2, ansy2);
    return 0;
}


Measured memory_bytes: 2744
from sys import stdin
from operator import itemgetter

def list_align(l):
    try :
        return int(l) * -1
    except:
        return l

n = int(stdin.readline().rstrip())
shops = [list(map(lambda x:list_align(x), stdin.readline().rstrip().split())) + [i+1] for i in range(n)]
shops.sort()
for i in range(n):
    print(shops[i][2])



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

using namespace std;

pair<int, int> x[222222];
int b[222222];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		x[i].second = i;
		scanf("%d", &x[i].first);
	}
	sort(x, x + n);
	for (int i = 0; i < n / 2; i++) {
		b[x[i].second] = x[n / 2].first;
		b[x[i + n / 2].second] = x[n / 2 - 1].first;
	}
	for (int i = 0; i < n; i++)
		cout << b[i] << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define ll (long long)
#define PI (acos(-1))

int main()
{
  int N, K;
  cin >> N >> K;
  
  vector<int> d(K);
  vector<vector<int>> A(K, vector<int>(N));
  vector<int> have(N);
  int who;

  

  for (int i = 0; i < K; i++)
  {
    cin >> d[i];

    for (int j = 0; j < d[i]; j++)
    {
      cin >> who;
      have[who - 1] = 1;
    }
  }

  int num = 0;
  for (int i = 0; i < N; i++)
  {
    if (have[i] == 0)
    {
      num++;
    }
  }
  cout << num << endl;
}


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

int main(void){
	int n;

	scanf("%d",&n);
	if(n<=111){
		printf("%d",111);
	}else if(n<=222){
		printf("%d",222);
	}else if(n<=333){
		printf("%d",333);
	}else if(n<=444){
		printf("%d",444);
	}else if(n<=555){
		printf("%d",555);
	}else if(n<=666){
		printf("%d",666);
	}else if(n<=777){
		printf("%d",777);
	}else if(n<=888){
		printf("%d",888);
	}else{
		printf("%d",999);
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const ll max_n = 200010;

ll fact[max_n];
bool fact_init = false;

ll mod(ll a, ll b){
  a %= b;
  return a < 0 ? a + b : a;
}

ll powmod(ll a, ll b){
  if(b == 0) return 1;
  if(b & 1) {
    return a * powmod(a, b - 1) % MOD;
  } else {
    ll d = powmod(a, b / 2) % MOD;
    return d * d % MOD;
  }
}

ll sub(ll a, ll b){
  a %= MOD, b %= MOD;
  a -= b;
  return a < 0 ? a + MOD : a;
}

ll inv(ll a){
	return powmod(a, MOD - 2);
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2; i < max_n; i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= powmod(fact[k],MOD-2);
	ret %= MOD;
	ret *= powmod(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, a, b, c;
	cin >> n >> a >> b >> c;

	ll awin = a * inv(a + b) % MOD;
    ll bwin = b * inv(a + b) % MOD;
    ll num = 100 * inv(100 - c) % MOD;

    ll ret = 0;
    for(int i = 0; i <= n - 1; i++){
        ret += comb(n - 1 + i, i) * powmod(awin, n) % MOD * powmod(bwin, i) % MOD * (n + i) % MOD;
        ret += comb(n - 1 + i, i) * powmod(bwin, n) % MOD * powmod(awin, i) % MOD * (n + i) % MOD;
    }

    cout << ret % MOD * num % MOD << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
using namespace std;

bool isPrime(int x) {
	if (x < 2) return false;
	if (x == 2) return true;
	if (x % 2 == 0) return false;
	double s = sqrt(x);
	for (int i = 3; i <= s; i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

int main() {
	int n, e;
	int count = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> e;
		if (isPrime(e)) count++;
	}
	cout << count << endl;

	return 0;
}

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

int n, a, cnt_odd;

int main(){
    scanf("%d", &n);
    while (n--){
        scanf("%d", &a);
        cnt_odd += (a & 1);
    }

    printf((cnt_odd & 1) ? "NO" : "YES");

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e5 + 5;

int n,m;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>m;
  vector<pair<int,int>> v(m);

  for (int i=0; i<m; i++) {
    cin>>v[i].second>>v[i].first;
  }

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

  int ans = 0;
  int last = -1;
  for (int i=0; i<m; ) {
    int j = i+1;
    while (j<m && v[j].first==v[i].first) j++;
    if (v[j-1].second >= last) {
      ans++;
      last = v[i].first;
    }
    
    i = j;
  }

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


Measured memory_bytes: 1024
N,K=  list(map(int,input().split(" ")))
S = input()

S1 = list(S)
# L → R に変換

lim = 0
flag = False
for i in range(N):
    if S1[i] == "L":
        S1[i] = "R"
        flag = True
    elif flag :
        lim += 1
        flag = False

    if lim == K:
        break
# print(S1)

S2 = list(S)
lim = 0
flag = False
for i in range(N):
    if S2[i] == "R":
        S2[i] = "L"
        flag = True
    elif flag:
        lim += 1
        flag = False

    if lim == K:
        break

anss =[0,0]
for i,s in enumerate([S1,S2]):
    Rcot = 0
    Lcot = 0
    for k in range(N - 1):  #Rのカウント
        if s[k] == "R" and  s[k + 1] == "R":
            Rcot += 1
    for k in range(1,N ):  #Rのカウント
        if s[k ] == "L" and  s[k -1] == "L":
            Rcot += 1
    anss[i] = Rcot + Lcot
print(max(anss))


# before = S[0]
# acc = []
# cot = 1
# for c in S[1:]:
#     if c == before:
#         cot += 1
#     else:
#         acc.append(cot )
#         cot = 1
#     before = c
# acc.append(cot )
#
# print(acc)
# cot  = 0
# Sl = list(S)
# for i,temp in enumerate(acc):
#     if i % 2 == 0:
#         for j in range()
#     cot += temp
#
#


# evens = (acc[::2])
# odds = (acc[1::2])
#
#
# evens_sorted = sorted(evens,reverse=True)
# el = min(K , len(evens_sorted))
#
# odds_sorted = sorted(odds,reverse=True)
# ol = min(K , len(odds_sorted))
#
#
# even_sum = sum(evens) + sum(odds_sorted[:ol]) + ol
# odd_sum = sum(odds)+ sum(evens_sorted[:el]) + el
#
# print(max(even_sum,odd_sum))


Measured memory_bytes: 54156
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = []
    for i in range(n):
        e = LI()
        u = e[2:]
        for i in range(len(u)):
            u[i] -= 1
        v.append(u)
    d = [-1]*n
    d[0] = 0
    q = deque([0])
    while q:
        x = q.popleft()
        nd = d[x]+1
        for y in v[x]:
            if d[y] < 0:
                d[y] = nd
                q.append(y)
    for i in range(n):
        print(i+1,d[i])
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 6104
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int mx = 100005;

int dtime = 0;
int n, m, par[mx], low[mx], start[mx];
vector<int> adj[mx];
bool vis[mx];
vector<pair<int, int>> bdg;

void dfs(int n, int p = -1) {
  vis[n] = true;
  par[n] = p;
  start[n] = dtime++;
  low[n] = start[n];
  
  for (int h : adj[n]) {
    if (!vis[h]) {
      dfs(h, n);
      // printf("Low[%d] = min(%d, %d) = %d\n", n, low[n], low[h], min(low[n], low[h]));
      low[n] = min(low[h], low[n]);
      if (low[h] > start[n]) {
	bdg.push_back({min(n, h), max(n, h)});
      }
    } else if (h != p) {
      low[n] = min(low[n], start[h]);
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v;
    adj[u].pb(v); adj[v].pb(u);
  }
  dfs(0);
  sort(bdg.begin(), bdg.end());
  for (auto p : bdg) cout << p.first << " " << p.second << endl;
}



Measured memory_bytes: 7240
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int INF = 1001001001;

vector<int> to[100005], co[100005];


int main() {
    int n;
    cin >> n;
    rep(i,n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        w %= 2;
        to[u].push_back(v); co[u].push_back(w);
        to[v].push_back(u); co[v].push_back(w);
    }
    vector<int> ans(n, INF);
    ans[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 0; i < to[v].size(); i++) {
            int u = to[v][i];
            int d = co[v][i];
            if (ans[u] != INF) continue;
            ans[u] = ans[v]^d;
            q.push(u);
        }
    }
    rep(i,n) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
int main() {
    string str;
    cin>>str;
    int n = str.length(),maxVal=-1;
    for(int i=0;i<n;i++){
        int count=0;
        for(int j=i;j<n;j++){
            if(str[j] == 'A' || str[j] == 'G' || str[j] == 'C' || str[j] == 'T'){
                count++;
            }else break;
        }
        maxVal = max(maxVal,count);
    }
    cout<<maxVal<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int P, Q, R;
	cin >> P >> Q >> R;

	vector<int> number({ P, Q, R });

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

	cout << number[0] + number[1];

	return 0;
}


Measured memory_bytes: 3600
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
typedef struct{LL x;LL i;}H;
LL i,j,k,m,n,s,x,p[2][2040];
H w[2040];
int C(H a,H b){return a.x<b.x;}
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(;i<n;i++)
	{
		cin>>w[i].x;
		w[i].i=i+1;
	}
	sort(w,w+n,C);
	for(i=0;i++<n;)p[0][i]=abs(i-w[0].i)*w[0].x;
	for(i=0;++i<n;)
	{
		for(j=i;j++<n;)
		{
			p[i&1][j]=max(p[!(i&1)][j-1]+abs(w[i].i-j)*w[i].x,p[!(i&1)][j]+abs(w[i].i-j+i)*w[i].x);
		}
	}
	cout<<p[(n-1)&1][n];
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    if(S.back()=='s'){
        cout << S+"es" << endl;
    } else {
        cout << S+'s' << endl;

    }

}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
  //freopen("input.txt", "r", stdin);
  ll n, k;
  while (~scanf("%lld%lld", &n, &k)) {
    ll buf = n % k;
    printf("%lld\n", min(buf, (-1LL) * (buf - k)));
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define MAX 150

void DepthFirstSearch(int);
 
int graph[MAX][MAX];
int d[MAX],f[MAX];
int t=0, n;

int main()
{
  int u, k, v;
  int i, j;
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++){
	scanf("%d%d", &u, &k);
	for(j=0; j<k; j++){
	  scanf("%d", &v);
	  graph[u-1][v-1] = 1;
	}
  }
  
  for(i=0; i<n; i++){
	if(d[i]==0) DepthFirstSearch(i);
  }
  
  for(i=0; i<n; i++){
	printf("%d %d %d\n", i+1, d[i], f[i]);
  }

  return 0;
}

void DepthFirstSearch(int i)
{
  int j;
  t++;
  d[i] = t;
 
  for(j=0; j<n; j++){
	if(graph[i][j]!=0 && d[j]==0){
	  DepthFirstSearch(j);
	}
  }
  t++;
  f[i]=t;
}

Measured memory_bytes: 656
#include<iostream>

#define     MIN_NUMBER       (0)
#define     MAX_NUMBER       (9)
#define     MIN_N_NUMBER     (1)
#define     MAX_N_NUMBER     (50)

using namespace std;

int main(){
	int n,cnt = 0;
	int a,b,c,d;

	while(cin >> n){
		// 入力値のチェック
		if((n < ((int)(MIN_N_NUMBER))) || (n > ((int)(MAX_N_NUMBER)))){
			cerr << "Error!!" << endl;
			return -1;
		}

		// 4重ループ
		for(a=((int)MIN_NUMBER);a<=((int)MAX_NUMBER);a++){
			for(b=((int)MIN_NUMBER);b<=((int)MAX_NUMBER);b++){
				for(c=((int)MIN_NUMBER);c<=((int)MAX_NUMBER);c++){
					for(d=((int)MIN_NUMBER);d<=((int)MAX_NUMBER);d++){
						if((a + b + c + d) == n){
							cnt++;
						}
					}
				}
			}
		}

		// 出力
		cout << cnt << endl;

		// cntのクリア
		cnt = 0;
	}

	return 0;
}

Measured memory_bytes: 1160