akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    long long ar_rk[100];
    cin >> N;
    ar_rk[0] = 2;
    ar_rk[1] = 1;
    for (int i = 2; i <= N; i++)
        ar_rk[i] = ar_rk[i - 1] + ar_rk[i - 2];
    cout << ar_rk[N] << endl;

    return 0;
}


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

int N;
vector<long long> A;

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

    cin >> N;
    A.resize(N);

    for (auto &a : A)
        cin >> a;

    long long full_sum = accumulate(A.begin(), A.end(), 0LL);
    long long sum = 0;
    long long best = full_sum;

    for (int i = 0; i < N; i++) {
        sum += A[i];
        best = min(best, abs(sum - (full_sum - sum)));
    }

    cout << best << '\n';
}


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

typedef long long ll;

const int MAXN = 3010;
const int MOD = 1e9 + 7;

string s;
int vis[MAXN][MAXN],ok[MAXN][MAXN];
ll dp[MAXN][MAXN],somatorio[MAXN][MAXN];
int N;

ll solve(int pos, int ultimo);

ll calc(int pos,int ultimo);

ll solve(int pos,int ultimo){

	if(vis[pos][ultimo]) return dp[pos][ultimo];
	vis[pos][ultimo] = 1;

	if(ultimo > pos + 1) return dp[pos][ultimo] = 0;

	if(pos == 0) return dp[pos][ultimo] = 1;

	if(s[pos-1] == '>'){
		ll tot = calc(pos-1,N) - calc(pos-1,ultimo - 1);
		return dp[pos][ultimo] = ((tot + MOD) % MOD);
	}
	else{
		ll tot = calc(pos-1,ultimo-1);
		return dp[pos][ultimo] = (tot % MOD);
	}

}

ll calc(int pos,int ultimo){

	if(ultimo == 0) return 0;

	if(ok[pos][ultimo]) return somatorio[pos][ultimo];
	ok[pos][ultimo] = 1;

	ll tot = solve(pos,ultimo) + calc(pos,ultimo - 1);
	return somatorio[pos][ultimo] = (tot % MOD);

}

int main(){

	cin >> N;
	cin >> s;

	ll tot = 0;
	for(int i = 1;i<=N;i++){
		tot += solve(N-1,i);
	}

	tot %= MOD;

	cout << tot << endl;

	return 0;

}

Measured memory_bytes: 426400
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rank = [0] * (n + 1)

  def find_root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.find_root(self.root[x])
      return self.root[x]
  
  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)

    if x == y:
      return

    elif self.rank[x] > self.rank[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    
    else:
      self.root[y] += self.root[x]
      self.root[x] = y

      if self.rank[x] == self.rank[y]:
        self.rank[y] += 1
    
  def same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def size(self, x):
    return -self.root[self.find_root(x)]

N, M = list(map(int, input().split()))

tree = UnionFind(N)

for i in range(M):
  a, b = list(map(int, input().split()))
  tree.unite(a, b)
res = 0

for i in range(N):
  res = max(res, tree.size(i))

print(res)

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

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

char M[12][12];

void dfs(int sx, int sy) {
  M[sy][sx] = '0';
  for(int i = 0; i < 4; i++) {
    int nx = sx + dx[i], ny = sy + dy[i];
    if(0<=nx&&nx<12 && 0<=ny&&ny<12 && M[ny][nx]-'0') dfs(nx, ny);
  }
}

int main() {
  int m;
  string s;
  
  while(1) {
    if(!(cin >> M[0][0])) break;
    
    for(int i = 0; i < 12; i++) for(int j = 0; j < 12; j++) {
	if(i == 0 && j == 0) continue;
	cin >> M[i][j];
      }
    
    m = 0;
    for(int i = 0; i < 12; i++) {
      for(int j = 0; j < 12; j++) {
	if(M[i][j]-'0') {
	  dfs(j, i);
	  m++;
	}
      }
    }
    cout << m << endl;
  }

  return 0;
}

Measured memory_bytes: 1144
A, B, C, D = list(input())
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            s = '{}{}{}{}{}{}{}'.format(A, op1, B, op2, C, op3, D)
            if eval(s) == 7:
                print('{}=7'.format(s))
                exit()

Measured memory_bytes: 38444
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
using namespace std;
int main(){
    int N;
    cin >> N;
    N = N % 1000;
    if(N != 0){
        N = 1000 - N;
    }
    cout << N << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s, t;
  int ans =0;
  cin >> s >> t;
  for(int i = 0; i < 3; i++) {
  	if(s[i] == t[i]) {
    	ans++;}
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    int n,q,p1,p2,p,l,r,mid;
    char s[200010],d[200000][3],t[200000][3];
    scanf("%d %d",&n,&q);
    scanf("%s",s);
    for(int i=0;i<q;i++){
        scanf("%s %s",t[i],d[i]);
    }
    p1=-1;
    p2=n;
    l=0;
    r=n-1;
    while(l<=r){
        mid=(l+r)/2;
        p=mid;
        for(int i=0;i<q;i++){
            if(p!=-1&&p!=n&&t[i][0]==s[p]){
                if(d[i][0]=='R'){
                    p++;
                }
                else{
                    p--;
                }
            }
        }
        if(p==-1){
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
    p1=r;
    l=0;
    r=n-1;
    while(l<=r){
        mid=(l+r)/2;
        p=mid;
        for(int i=0;i<q;i++){
            if(p!=-1&&p!=n&&t[i][0]==s[p]){
                if(d[i][0]=='R'){
                    p++;
                }
                else{
                    p--;
                }
            }
        }
        if(p==n){
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    p2=l;
    if(p1>=p2){
        printf("0\n");
    }
    else{
        printf("%d\n",n-(p1+1)-(n-p2));
    }
}

Measured memory_bytes: 1536
using System;

class Program{
    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var a=new int[n];
        for(var i=0; i<n; i++){
            a[i]=int.Parse(Console.ReadLine());
        }

        var cnt=0;
        for(var i=0; i<n; i++){
            var ai=a[i];
            if(ai!=2 && ai%2==0){
                continue;
            }
            var flag=true;
            for(var j=3; j*j<=ai; j+=2){
                if(ai%j==0){
                    flag=false;
                    break;
                }
            }
            if(flag){
                cnt++;
            }
        }

        Console.WriteLine(cnt);
    }
}

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

# CODE FESTIVAL 2016 qual A
# Problem B

if __name__ == '__main__':
    n, a, b = list(map(int, input().split()))
    s = input()
    a_count = 0
    b_count = 0
    a_b_count = 0

    for si in s:
        if (si == 'a') and (a_b_count < a + b):
            a_count += 1
            print('Yes')
        elif (si == 'b') and (a_b_count < a + b) and (b_count < b):
            b_count += 1
            print('Yes')
        else:
            print('No')

        a_b_count = a_count + b_count


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S; cin >> S;
  int l = S.length();
  int r[l+1] = {};
  r[1] = 1; r[2] = 1+(S[1]!=S[0]);
  repr(i,3,l+1) {
    if (S[i-1]==S[i-2]) r[i] = r[i-3] + 2;
    else r[i] = r[i-1] + 1;
  }
  // debug(r,r+l+1);
  cout << r[l] << endl;
  return 0;
}

Measured memory_bytes: 1412
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/08/10 20:56:34
 *******************************/
#include <bits/stdc++.h>
#define reg register
#define MAXN 2505
#define MAXE 5005
using namespace std;
const int mod = 1e9 + 7;
int N, M, P;
int head[MAXN], to[MAXE], nex[MAXE], val[MAXE], tote;
int dist[MAXN], rec[MAXN];
bool vis[MAXN], able[MAXN];
struct edges {
    int u, v, c;
}e[MAXE];
inline int Rd() {
    int x = 0; char ch = getchar();
    while(ch < '0' || ch > '9') ch = getchar();
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    return x;
}
inline void add_edge(int u, int v, int c) {
    nex[++tote] = head[u], to[tote] = v, val[tote] = c, head[u] = tote;
    return;
}
void dfs(int str) {
    able[str] = vis[str] = true;
    for(int i = head[str]; i; i = nex[i])
        if(!vis[to[i]])
            dfs(to[i]);
    return;
}
void clear() {
    tote = 0;
    memset(head, 0, sizeof head);
    memset(vis, 0, sizeof vis);
    memset(nex, 0, sizeof nex);
    memset(to, 0, sizeof to);
    return;
}
void SPFA() {
    queue<int> que; que.push(1);
    for(reg int i = 2; i <= N; ++i) dist[i] = -mod;
    while(!que.empty()) {
        int s = que.front(); que.pop(), vis[s] = false;
        if(!able[s]) continue;
        for(int i = head[s]; i; i = nex[i]) {
            if(dist[to[i]] < dist[s] + val[i]) {
                dist[to[i]] = dist[s] + val[i];
                if(!vis[to[i]]) {
                    vis[to[i]] = true, ++rec[to[i]];
                    if(rec[to[i]] >= N) {
                        if(able[to[i]]) {
                            puts("-1");
                            exit(0);
                        }
                        continue;
                    }
                    que.push(to[i]);
                }
            }
        }
    }
    return;
}
int main() {
    N = Rd(), M = Rd(), P = Rd();
    for(reg int i = 1; i <= M; ++i) {
        e[i].u = Rd(), e[i].v = Rd(), e[i].c = Rd();
        add_edge(e[i].v, e[i].u, 0);
    }
    dfs(N);
    clear();
    for(reg int i = 1; i <= M; ++i)
        add_edge(e[i].u, e[i].v, e[i].c - P);
    SPFA();
    if(dist[N] < 0) dist[N] = 0;
    cout << dist[N] << endl;
    return 0;
}


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

int f(int x,int y,int z);
int main() {
    int N;
    cin >> N;
    
    for (int n = 1; n <= N; ++n){
      int ans = 0;
      int max = int(sqrt(n));
      for (int x = 1; x <= max; ++x){
        if (f(x, 1, 1) > n) break;
        for (int y = 1; y <= max; ++y){
          if (f(x, y, 1) > n) break;
          for (int z = 1; z <= max; ++z){
            int ff = f(x, y, z);
            if (ff > n) break;
            if (ff == n) ans +=1;
          } 
        } 
      }
      cout << ans << endl;
    }
    
}

int f(int x,int y,int z) {
  return x * x + y * y + z * z + x * y + y * z + z * x;;
}

Measured memory_bytes: 3572
//***___*********___*****___****___***___*********//
/*  |   \  |   | |   |   |   \  |     |     |   |  **
/*  |   |  |   | |___|   |   _  |__   |___  |___|  **
/*  |   |  |   | |   \   |  | | |         | |   |  **
/*  |___/  |___| |    \  |__| | |___  ____| |   |  **
//*************************************************/
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ff double
#define endl "\n"
#define M 1000000007
#define forever while(1)
#define ll long long
#define pb push_back
#define vi vector<long long>
#define mii map<int,int>
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');
using namespace std;
void fastscan(int &x)
{
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
}
int main()
{
    int n,m;
    cin>>n>>m;
    n=n-2*m;
    if(n<0)
        cout<<0<<endl;
    else
        cout<<n<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,c,d,start,end;

  scanf("%d %d %d %d",&a,&b,&c,&d);

  start=a;
  end=b;

  if(a<c)start=c;
  if(b>d)end=d;

  if(end-start>0)printf("%d\n",end-start);
  if(end-start<=0)printf("0\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
 
using namespace std;
 
int main() {
  long long int h,w;
  cin >> h >> w;
  if( h == 1 || w == 1 ){
    cout << 1  << "\n";
    return 0;
  }

  cout << (h*w+1)/2  << "\n";
  return 0;
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  ll x;
  cin >> N >> x;

  vector<ll> v(N);
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }

  ll ans = 0;
  for(int i = 0; i < N-1; i++){
    ll tmp = 0;
    if(v[i] + v[i+1] >= x){
      if(v[i] <= x){
        // i+1だけ減らす
        tmp += v[i] + v[i+1] - x;
        v[i+1] -= tmp;
      } else {
        // iとi+1両方減らす i+1を優先して減らす
        tmp += v[i+1];
        v[i+1] = 0;
        tmp += v[i] - x;
        v[i] -= x;
      }
    }
    ans += tmp;
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
mod = 10**9 + 7


n = int(input())
A = list(map(int, input().split()))


A = [format(a, "060b")[::-1] for a in A]

answer = 0
for i in range(60):
    x, y = 0, 0
    for a in A:
        if a[i] == "0":
            x += 1
        else:
            y += 1
    answer += (x * y) * 2**i
    answer %= mod


print(answer)


Measured memory_bytes: 129592
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<lint> items;
    for(int i = 0; i < N; i++){
        lint A;
        cin >> A;
        items.push(A);
    }
    for(int i = 0; i < M; i++){
        lint top = items.top();
        items.pop();
        items.push(top / 2);
    }
    lint ans = 0;
    for(int i = 0; i < N; i++){
        lint top = items.top();
        items.pop();
        ans += top;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
def solve(string):
    n, *abcd = map(int, string.split())
    abcd = [(ac, bd) for ac, bd in zip(abcd[::2], abcd[1::2])]
    ab = abcd[:n]

    candidate = []
    ans = 0
    ps = sorted(abcd, key=lambda x: x[0])
    for p in ps:
        if p in ab:
            candidate.append(p)
            candidate = sorted(candidate, key=lambda x: x[1], reverse=True)
        else:
            for i, _p in enumerate(candidate):
                if _p[1] < p[1]:
                    ans += 1
                    candidate.pop(i)
                    break
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,T=map(int,input().split())
    l=[]
    for i in range(N):
        A,B=map(int,input().split())
        l.append((A,B))
    l.sort()
    dp=[[0]*T for _ in range(N)]
    for i in range(N-1):
        for t in range(T-1):
            dp[i+1][t+1]=max(dp[i+1][t+1],dp[i][t+1])
            if t+1>=l[i][0]:
                dp[i+1][t+1]=max(dp[i+1][t+1],dp[i][t+1-l[i][0]]+l[i][1])
    ans=0
    B_sorted=[x[1] for x in l]
    for i in range(1,N):
        ans=max(ans,dp[i][T-1]+max(B_sorted[i:]))
    print(ans)
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 113884
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int count = 0;
  for(;;){
    bool ok = true;
    for(int j=0;j<N;j++){
      if(A.at(j)%2!=0){
        ok = false;
      }
    }
    if(ok){
      for(int k=0;k<N;k++){
        A.at(k)/=2;
      }
      count++;
    }
    else{
      break;
    }
  }
  cout<<count<<endl;
  return 0;
}

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

typedef long long int lli;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;

#define INF 1000000000
#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define foreach(v,c) for(typeof((c).begin()) v=(c).begin();v!=(c).end();++v)
#define all(a) a.begin(),a.end()
#define in(a,b) ((b).find(a)!=(b).end())
#define fill(a,v) memset(a,v,sizeof a)
#define sz(a) ((int)(a.size()))
#define mp make_pair
#define pb push_back

int dp[110000];
int h[110000];
int n;
int main(){
  fastIO
  cin>>n;
  for(int i = 0; i < n; i++){
    cin>>h[i];
  }
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2; i < n; i++){
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout<<dp[n - 1]<<endl;
}

Measured memory_bytes: 1024
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	string s;
	cin>>s;
	if(s[0] == s[1] && s[1] == s[2] && s[1] == 'R') finish(3);
	if(s[0] == s[1] && s[1] == 'R') finish(2);
	if(s[1] == s[2] && s[1] == 'R') finish(2);
	if(s[1] == 'R' || s[0] == 'R' || s[2] == 'R') finish(1);
	finish(0);
	 
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


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

using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int t = s.size();
    string ans = "";
    for(int i=0;i<t;i++){
        int c =s[i]-'A';
        c = (n+c)%26;
        ans+='A'+c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(" ").map(String::toInt).toMutableList()
    if (n != array.size) return

    var min = 101
    var minIndex = 101
    var i = 0
    var count = 0
    while (n - 1 > i) {
        (i..(n - 1)).forEach { index ->
            if (min > array[index]) {
                min = array[index]
                minIndex = index
            }
        }
        if (minIndex != i) {
            val temp = array[minIndex]
            array[minIndex] = array[i]
            array[i] = temp
            count++
        }
        min = 101
        i++
    }

    array.forEachIndexed { index, num ->
        if (index == array.size - 1) println(num.toString()) else print(num.toString() + " ")
    }
    println(count)
}


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

int digit(ll A){
  int a = 0;
  while(A  != 0){
    a++;
    A /= 10;
  }

  return a;
}

int main(){
  ll N;
  cin >> N;
  int N1 =  floor(sqrt(N));
  int min = digit(N);
  for(ll i = 1LL; i <= N1; ++i){
    if((N % i) == 0){
      const ll B = N / i;
      const int f = max(digit(i), digit(B));
    //  cout << f << " " << digit(i) << " "<< digit(B) << endl;
      if(min > f){
        min = f;
      //  cout << f << endl;
      }
    }else{
      continue;
    }
  }

  cout << min << endl;
  return 0;
}


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

int main()
{
	std::string input, output;
	std::cin >> input;
	if (input == "Sunny")
	{
		output = "Cloudy";
	}
	else if (input == "Cloudy")
	{
		output = "Rainy";
	}
	else if (input == "Rainy")
	{
		output = "Sunny";
	}
	else { output = "Not Such Weather"; }
	std::cout << output << std::endl;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	deque<char> dq;
	for (size_t i = 0; i < s.length(); i++)
	{
		if (s[i] != 'B') dq.push_back(s[i]);
		else
		{
			if (!dq.empty()) dq.pop_back();
		}
	}
	while (!dq.empty())
	{
		cout << dq.front();
		dq.pop_front();
	}
	return 0;
}

Measured memory_bytes: 256
// きさま！ 見ているなッ！

#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>
#include<thread>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;
int N;
vec cha;

void solve(int d,int cl)
{
	for (int i = 0; i <= cl; ++i)
	{
		cha[d - 1] = i;

		if (d == N)
		{
			for (int c : cha)
			{
				cout << (char)((char)c + 'a');
			}
			cout << endl;
		}
		else
		{
			solve(d + 1, max(cl, i + 1));
		}
	}
}

int main()
{
	cin >> N;
	cha=vec(N);
	solve(1,0);

	return 0;
}

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

const int MAXN = 1000;
const int MAXV = MAXN * (MAXN-1) / 2;
vector<vector<int>> to(MAXV);

vector<int> dp(MAXV);
vector<bool> visited(MAXV, false);
vector<bool> calculated(MAXV, false);

int dfs(int v){

	if(visited[v] && !calculated[v]) return -1; // find roop!
	if(calculated[v]) return dp[v];
	
	visited[v] = true;
	int res = 1;
	for(int p : to[v]){
		int tmp = dfs(p);
		if(tmp == -1) return -1;
		res = max(res, tmp+1);
	}
	dp[v] = res;
	calculated[v] = true;
	return dp[v];
}

int main(){
	
	int n;
	cin >> n;
	
	vector<vector<int>> a(n, vector<int>(n-1));
	rep(i,n){
		rep(j,n-1){
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	
	// 試合組み合わせにidをつける
	vector<vector<int>> id(n, vector<int>(n));
	int matchId = 0;
	rep(i,n){
		for(int j = i+1; j < n; j++){
			id[i][j] = matchId++;
		}
	}
	
	rep(i,n){
		for(int j = 0; j < i; j++){
			id[i][j] = id[j][i];
		}
	}
	
	rep(i,n){
		rep(j,n-1){
			int from = a[i][j];
			a[i][j] = id[i][from];
		}
	}
	
	rep(i,n){
		rep(j,n-2){
			to[a[i][j]].push_back(a[i][j+1]);
		}
	}
	
	rep(i,matchId){
		int tmp = dfs(i);
		if(tmp == -1){
			puts("-1");
			return 0;
		}
	}
	
	int res = 0;
	rep(i,dp.size()) res = max(res, dp[i]);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 37632
from collections import Counter
n=int(input())
a=[dict(Counter(list(input()))) for i in range(n)]

d=a[0]
for i in a[1:]:
  dl=[]
  for j in d:    
    if j in list(i):
      d[j]=min(d[j],i[j])
    else:
      dl.append(j)
      
  for j in set(dl):  
    del d[j]
    
c=[]
for i in list(d):
  c.append(i*d[i])
c.sort()
m=""
for i in c:
  m=m+i
print(m)

Measured memory_bytes: 3316
import numpy as np
n = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
for i in range(n):
  if i % 2 == 0: # Alice
    alice += a.pop(np.argmax(a))
  else: # Bob
    bob += a.pop(np.argmax(a))
print(alice - bob)

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

int s[111111];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    s[0]=s[n+1]=0;
    int sum=0;
    for(int i=1;i<=n+1;i++)
    {
        sum+=abs(s[i]-s[i-1]);
    }
    for(int i=1;i<=n;i++)
    {
        int t=sum;
        t-=(abs(s[i]-s[i-1])+abs(s[i]-s[i+1])-abs(s[i+1]-s[i-1]));
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664
local a, b, c, x, y = io.read("*n", "*n", "*n", "*n", "*n")
if(a + b <= c * 2) then
  print(a * x + b * y)
else
  local both = math.min(x, y)
  local price = both * c  * 2
  x, y = x - both, y - both
  price = price + x * math.min(c * 2, a)
  price = price + y * math.min(c * 2, b)
  print(price)
end


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

typedef long long ll;
const int N=200005;
int n,m,q,head[N],now=0;
struct node
{
	int t,next;
}adj[N];
struct A
{
	int col,tim;
}f[N][11],ans[N];
void add(int s,int t)
{
	adj[++now]=(node){t,head[s]};
	head[s]=now;
}
int main()
{
	#ifdef Kay
		freopen ("ATC.in","r",stdin);
		freopen ("ATC.out","w",stdout);
	#endif
	scanf ("%d %d",&n,&m);
	int i,s,t,d,c,j,k;
	for (i=1;i<=m;i++)
	scanf ("%d %d",&s,&t),add(s,t),add(t,s);
	scanf ("%d",&q);
	for (i=1;i<=q;i++)
	{
		scanf ("%d %d %d",&s,&d,&c);
		f[s][d]=(A){c,i};
	}
	for (j=10;j>=0;j--)
	for (i=1;i<=n;i++)
	{
		if (f[i][j].tim>ans[i].tim) ans[i]=f[i][j];
		if (j)
		{
			for (k=head[i];k;k=adj[k].next)
			if (f[i][j].tim>f[adj[k].t][j-1].tim) f[adj[k].t][j-1]=f[i][j];
		}
	}
	for (i=1;i<=n;i++) printf ("%d\n",ans[i].col);
	return 0;
}


Measured memory_bytes: 12416
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main(void) {
    int N, M;
    cin >> N >> M;

    vector<int> ac(N, 0);
    vector<int> wa(N, 0);
    int ac_count = 0;
    for (int i = 0; i < M; i++) {
        int p;
        string S;
        cin >> p >> S;
        p--;
        if (S == "AC") {
            if (ac[p] == 0) {
                ac_count++;
                ac[p] = 1;
            }
        } else {
            if (ac[p] == 0) {
                wa[p]++;
            }
        }
    }

    int wa_count = 0;
    for (int i = 0; i < N; i++) {
        if (ac[i] == 1) {
            wa_count += wa[i];
        }
    }
    cout << ac_count << " " << wa_count << endl;

    return 0;
}



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

int main(){
  int N,sum,p[10];
  cin >> N;
  for (int i=0; i<N; ++i) cin >> p[i];
  int max = p[0];
  for (int i=0; i<N; ++i){
    if(max<p[i]) max = p[i];
  }
  for (int i=0; i<N; ++i) {
      sum += p[i];
  }
   sum -= max/2;
   cout << sum << endl;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	int arr[n + 1];
	vector<int> dp(n + 1, INT_MAX);
	
	for(int i = 0; i < n; i++)
		cin >> arr[i];
//	dp[1] = abs(arr[1] - arr[0]);
//	dp[2] = min(abs(arr[2] - arr[1]) + dp[1], abs(arr[2] - arr[0]));
	dp[0] = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = i + 1; j <= i + k; j++)
		{
			if(j > n)
				break;
			dp[j] = min(dp[j], abs(arr[i] - arr[j]) + dp[i]);
//			cout << "j: " << j << "\ndp[j]: " << dp[j] << "\n";
		}
	}
	cout << dp[n - 1] << "\n";
	
	return 0;
}

Measured memory_bytes: 1024
using System;

namespace ConsoleApp1
{

    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int h = int.Parse(input[2]);
            int m = int.Parse(input[3]);

            double dis = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2) - 2 * a * b * Math.Cos(Math.PI / 180 * (h * 30 + m * 0.5 - m * 6)));

            Console.WriteLine(dis);

        }

    }
}



Measured memory_bytes: 27920
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
using namespace std;
#define MOD 1000000007
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


// ローリングハッシュ
// 二分探索で LCP を求める機能つき
template<typename T>
struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<long long> hash1, hash2, power1, power2;

	// construct
	RollingHash(const T& S) {
		int n = (int)S.size();
		hash1.assign(n + 1, 0);
		hash2.assign(n + 1, 0);
		power1.assign(n + 1, 1);
		power2.assign(n + 1, 1);
		for (int i = 0; i < n; ++i) {
			hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
			power1[i + 1] = (power1[i] * base1) % mod1;
			power2[i + 1] = (power2[i] * base2) % mod2;
		}
	}


	// get hash of S[left:right]
	inline pair<long long, long long> get(int l, int r) const {
		long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
		if (res1 < 0) res1 += mod1;
		long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
		if (res2 < 0) res2 += mod2;
		return { res1, res2 };
	}

	// get lcp of S[a:] and T[b:]
	inline int getLCP(int a, int b) const {
		int len = min((int)hash1.size() - a, (int)hash1.size() - b);
		int low = 0, high = len;
		while (high - low > 1) {
			int mid = (low + high) >> 1;
			if (get(a, a + mid) != get(b, b + mid)) high = mid;
			else low = mid;
		}
		return low;
	}
};


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

	ll n;
	cin >> n;
	Array a(n), b(n);
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	Array aa(n), bb(n);
	REP(i, n)aa[i] = (a[i] ^ a[(i + 1) % n]);
	REP(i, n)bb[i] = (b[i] ^ b[(i + 1) % n]);
	RollingHash<Array> rh_a(aa), rh_b(bb);
	REP(i, n) {
		P ha1 = rh_a.get(i, n);
		P ha2 = rh_a.get(0, i);
		P hb1 = rh_b.get(0, n - i);
		P hb2 = rh_b.get(n - i, n);
		if (ha1 == hb1 && ha2 == hb2) cout << i << ' ' <<( a[i] ^ b[0] )<< endl;
	}


	return 0;
}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

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

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, k, u, v;
    cin >> n >> k;
    vvi ed(n+1);
    REP(i, 0, n-1) {
        cin >> u >> v;
        ed[u].pb(v);
        ed[v].pb(u);
    }
    ll a = k;
    REP(i, k-ed[1].size(), k)
        a = (a*i) % M;
    queue<ll> q;
    vi vis(n+1, 0);
    REP(i, 0, ed[1].size()) {
        vis[ed[1][i]] = 1;
        q.push(ed[1][i]);
    }
    vis[1] = 1;
    while (!q.empty()) {
        auto c = q.front();
        q.pop();
        REP(i, k-ed[c].size(), k-1)
            a = (a*i) % M;
        REP(i, 0, ed[c].size()) {
            if (!vis[ed[c][i]]) {
                vis[ed[c][i]] = 1;
                q.push(ed[c][i]);
            }
        }
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 8180
using System;


class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        if (n % 4 == 0||n%7==0) { Console.WriteLine("Yes");return; }
        for(int a = 1; a < 26; a++)
        {
            for(int b = 1; b < 5; b++)
            {
                if (n % (4 * a + 7 * b) == 0) 
                    { Console.WriteLine("Yes"); return; }

            }
        }
        Console.WriteLine("No");
        
    }
}

Measured memory_bytes: 13140
N = int(input())
S = input()
e_count = S.count('E')
w_count = 0
ans = e_count
for s in S:
    if s == 'E':
        e_count -= 1
    else:
        w_count += 1
    if e_count + w_count < ans:
        ans = e_count + w_count
print(ans)

Measured memory_bytes: 3700
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


int a, b, c;

int read() {
  if (scanf("%d%d%d", &a, &b, &c) < 3) {
    return 0;
  }
  return 1;
}

void solve() {
  if ((a & 1) && (b & 1) && (c & 1)) {
    int xs[3] = {a, b, c};
    sort(xs, xs + 3);
    printf("%lld\n", (long long) xs[0] * xs[1]);
  } else {
    printf("0\n");
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/agc035/tasks/agc035_a
from collections import Counter

n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)

if sum(nums) == 0:
    print('Yes')
elif len(c) == 2:
    for k, v in c.items():
        if k == 0:
            if v != n // 3:
                print('No')
                break
        else:
            if v != n // 3 * 2:
                print('No')
                break
    else:
        print('Yes')
elif len(c) == 3:
    t = 0
    for k, v in c.items():
        if v != n // 3:
            print('No')
            break
        t ^= k
    else:
        if t:
            print('No')
        else:
            print('Yes')
else:
    print('No')

Measured memory_bytes: 94080
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


vll d;
vector<vector<pair<ll, ll>>> rel;

void dfs(ll node) {
    for (pair<ll, ll> _nn : rel[node]) {
        ll nn = _nn.first, cost = _nn.second;
        if (d[nn] > -1) continue;
        d[nn] = d[node] + cost;
        dfs(nn);
    }
}

int main()
{
    ll n; cin >> n;
    d.resize(n, -1);
    rel.resize(n);
    rep(i, n - 1) {
        ll u, v, w; cin >> u >> v >> w; u--, v--, w;
        rel[u].push_back({v, w});
        rel[v].push_back({u, w});
    }
    d[0] = 0;
    dfs(0);
    rep(i, d.size()) {
        cout << d[i] % 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
	const int MAX = 101;
	vector<int> xx(MAX);
	vector<int> yy(MAX);
	vector<ll> hh(MAX);
	int N;
	cin >> N;
	for(int i = 0; i < N; i++)
	{
		int x, y;
		ll h;
		cin >> x >> y >> h;
		xx[i] = x;
		yy[i] = y;
		hh[i] = h;
	}
	for(int cx = 0; cx < MAX; cx++)
	{
		for(int cy = 0; cy < MAX; cy++)
		{
			ll H;
			for(int i = 0; i < N; i++)
			{
				if(hh[i] != 0) H = hh[i] + (ll)abs(xx[i]-cx) + (ll)abs(yy[i]-cy);
			}
			bool flag = true;
			for(int i = 0; i < N; i++)
			{
				ll tmph = max(H - (ll)abs(xx[i]-cx) - (ll)abs(yy[i]-cy), 0LL);
				if(tmph != hh[i]) flag = false;
			}
			if(flag == true)
			{
				cout << cx << " " << cy << " " << H << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int N = sc.nextInt();
        int Q = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[] t = new char[Q];
        char[] d = new char[Q];

        for(int i=0; i<Q; i++) {
            t[i] = sc.next().charAt(0);
            d[i] = sc.next().charAt(0);
        }

        // 落ちる区間を二分探索 左側
        int l = 0;
        int r = N/2;
        int center=0;
        while(l<=r) {
            center = (l+r)/2;
            if (!isExist(center,s,t,d)) {
                l = center + 1;
                center++;
            } else {
                r = center - 1;
            }
        }
        int left = center;

        // 落ちる区間を二分探索 右側
        l = N/2 + 1;
        r = N-1;
        center=0;
        while(l<=r) {
            center = (l+r)/2;
            if (isExist(center,s,t,d)) {
                l = center+1;
                center++;
            } else {
                r = center-1;
            }
        }
        int right = center;

        System.out.println(right - left);
   }

   // 最終的に生き残れるかどうか
   private static boolean isExist(int initialIndex, char[] s, char[] t, char[] d ) {
        int currentIndex = initialIndex;
        for (int i = 0; i < t.length ; i++) {
            if (s[currentIndex] == t[i]) {
                switch(d[i]) {
                    case 'L':
                        currentIndex--;
                        break;
                    case 'R':
                        currentIndex++;
                        break;
                }
                if(currentIndex<0 || currentIndex> s.length-1) return false;
            }
        }
        return true;
   }
}

Measured memory_bytes: 66036
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

struct UnionFind {
    vector<ll> par; 
    vector<ll> siz;
    
    UnionFind(ll N) : par(N), siz(N, 1LL) { 
        for(ll i = 0; i < N; i++) par[i] = i;
    }
 
    void init(ll N) {   
        par.resize(N);
        siz.assign(N, 1LL); 
        for (ll i = 0; i < N; i++) par[i] = i; 
    }
 
    ll root(ll x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    ll size(ll x){ 
      return siz[root(x)];
    }
 
    bool unite(ll x, ll y) {
        ll rx = root(x); 
        ll ry = root(y); 
        if (rx == ry) return false; 
 
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;     
        return true;
    }
 
     bool same(ll x, ll y) { 
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
 
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m,k;
cin>>n>>m>>k;

UnionFind u(n);
vector<vector<int>>f(n),b(n);
rep(i,m){
    int x,y;
    cin>>x>>y;
    x--,y--;
    f[x].pb(y);
    f[y].pb(x);
    u.unite(x,y);
}
rep(i,k){
    int x,y;
    cin>>x>>y;
    x--,y--;
    b[x].pb(y);
    b[y].pb(x);
}
vector<int> ans(n,0);
rep(i,n){
    ans[i]=u.size(i)-1;
    for(auto _f:f[i]){
        if(u.same(i,_f))ans[i]--;
    }
    for(auto _b:b[i]){
        if(u.same(i,_b))ans[i]--;
    }
}
rep(i,n){
    cout<<ans[i]<<endl;
}
//system("pause");
return 0;
}

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

#define endl "\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1n(i, n) for (int i = 1; i < (int)(n); ++i)
#define forln(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define forl1n(i, n) for (long long i = 1; i < (long long)(n); ++i)

const ld EPS = 1e-9;
#define mod 1000000007
const int N = 1000000;

ll GetMod(ll n, ll z) { // func to get mod for positive num and negitive nums
    return (n % z + z) % z;
}
//          U   R  D  L
int dx[] = {-1, 0, 1, 0, -1, +1, +1, -1}; // dx for the 8 adjacent places in matrix
int dy[] = {0, 1, 0, -1, +1, +1, -1, -1};// dy for the 8 adjacent places in matrix
vector<ll> v;
bool check(ll d,ll k){
   for(ll i = 0, p2 = k-1 ;i<v.size();i++,p2++){
       if(p2>=v.size()){
           return false;
       }
        if( v[p2] - v[i] <= d ){
            return true;
        }

   }
   return false;

}
int main() {

    ios_base::sync_with_stdio(false), cin.tie(NULL);
   ll n,k;
   cin >> n >> k;
   v.resize(n);
   forn(i,n)cin>>v[i];
   sort(v.begin(),v.end());
   ll l=0,r=v[v.size()-1]-v[0];
   ll ans = 0;
  // cout<<check(0,k);
    while(l<=r){
        ll mid = (l + r) /2;
      //  cout << mid << endl;
        if( check(mid,k) ){
            ans = mid;
            r = mid -1;
        }else{
            l = mid +1;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1024
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int p, q, r;
	cin >> p >> q >> r;
	cout << p + q + r - max({p, q, r}) << endl;
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define Yes(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll n,m,mod=1e9+7;
string s;
signed main() {
    cin>>s;
   rep(i,s.length()){
       if(s[i]=='x')n++;
   }
   Yes(n<8);
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

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

    int n;
    cin >> n;
    vi v(n);
    for(auto &z : v)
        cin >> z;
    sort(all(v));

    int ans = 0;

    for(int i = 0; i < n; ++i)
    {
        for(int j = i + 1; j < n; ++j)
        {
            for(int k = j + 1; k < n; ++k)
            {
                if(v[i] == v[j] || v[j] == v[k])
                    continue;
                ans += (v[i] + v[j] > v[k]);
            }
        }
    }

    cout << ans << "\n";
} 


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

string d[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string s;
    cin >> s;
    reverse(all(s));
    rep(i,4) reverse(all(d[i]));
    bool ok = true;
    for(int i = 0; i < s.size();) {
        bool oki = false;
        rep(j,4) {
            string t = d[j];
            if(s.substr(i,t.size())==t) {
                oki = true;
                i += t.size();
            }
        }
        if(!oki){
            ok = false;
            break;
        }
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3768