akhauriyash/Code-Regression huggingface dataset:
/*
 * ITP1_11_A: Rolling the dice
 */

#include <stdio.h>

// rolling relations by index (N, S, E, W)
int T[4][1 + 6] = {{0, 2, 6, 3, 4, 1, 5},
                   {0, 5, 1, 3, 4, 6, 2},
                   {0, 4, 2, 1, 6, 5, 3},
                   {0, 3, 2, 6, 1, 5, 4}};

void rotate(int d, int p[])
{
    int q[1 + 6];
    int i;

    for (i = 1; i <= 6; i++)
        q[i] = p[T[d][i]];

    for (i = 1; i <= 6; i++)
        p[i] = q[i];

    return;
}

int main(void)
{
    int dice[1 + 6]; // one-based indexing
    char direction[100 + 2]; // return code + null character
    int i;

    for (i = 1; i <= 6; i++)
        scanf("%d", &dice[i]);
    scanf("%*c");  // throw away return character for next fgets()

    //for (i = 1; i <= 6; i++)
    //    printf("%d: %d  ", i, dice[i]);
    //printf("\n");

    fgets(direction, sizeof(direction), stdin);

    int step = 0;
    while (1) {
        char d = direction[step++];
        if (d == 0x0a || d == 0x00 || step == 101)
            break;
        //printf("%d -> %c (%x)\n", step, d, d);

        switch (d) {
            case 'N':
                rotate(0, dice);
                break;
            case 'S':
                rotate(1, dice);
                break;
            case 'E':
                rotate(2, dice);
                break;
            case 'W':
                rotate(3, dice);
                break;
        }
    }

    //printf("Top: %d\n", dice[1]);
    printf("%d\n", dice[1]);

    return 0;
}



Measured memory_bytes: 2052
n, q = map(int, input().split())
proc = []
for _ in range(n):
    name, time = input().split()
    proc.append([name, int(time)])

time=0
while proc:
    p = proc.pop(0)
    if p[1]-q<=0:
        time += p[1]
        print(p[0], time)
    else:
        p[1]-=q
        time += q
        proc.append(p)


Measured memory_bytes: 13012
#include <iostream>
#include <queue>

using namespace std;

int main() {
    priority_queue<int> pq;

    for (int i = 0; i < 10; ++i) {
        int height;
        cin >> height;
        pq.emplace(height);
    }


    for (int i = 0; i <= 2; ++i) {
        std::cout << pq.top() << endl;
        pq.pop();
    }

    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {

	long long int n, k;
	
	cin >> n >> k;
	
	vector<long long int> a(n);
	
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	long long int p = 1;
	vector<long long int> b;
	for (long long int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			p++;
		}
		else {
			b.push_back(p);
			p = 1;
		}
	}
	b.push_back(p);
	sort(b.begin(), b.end(), greater<long long int>());

	long long int ans = 0;

	for (long long int i = k; i < b.size(); i++) {
		ans += b[i];
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

long long N, K;
long long Ans;
//bool Check()
//{
//    long long x = N - K;
//    if(x < 0)
//        x *= -1;
//    if(x < Ans)
//        return true;
//    else
//        return false;
//}

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


    cin >> N >> K;
    Ans = INT_MAX;

    N = N % K;

    if( N < K)
    {
        long long x = abs( N - K);

        N = min(N, x);

    }

    cout << N;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  function<i64(i64, i64)> count = [&](i64 N, i64 P) {
    i64 h = N / (2 * P);
    i64 t = N - 2 * P * h;
    return P * h + max(t - P, 0ll);
  };
  i64 A, B; cin >> A >> B;
  B++;
  vi64 cnt(60, 0);
  rep(i, 60) cnt[i] += count(B, power(2ll, i));
  rep(i, 60) cnt[i] -= count(A, power(2ll, i));
  i64 ans = 0;
  rep(i, 60) ans += bit(i) * (cnt[i] % 2 ? 1 : 0);
  cout << ans << '\n';
}


Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
ans = 0
for i in range(N):
    left = min(A[i], B[i])
    ans += left
    A[i] -= left
    B[i] -= left

    right = min(A[i+1], B[i])
    ans += right
    A[i+1] -= right
    B[i] -= right
print(ans)

Measured memory_bytes: 18624
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	ll dp[2][220] = {};
	ll *dp0 = dp[0]+1, *dp1 = dp[1]+1;
	dp1[0] = 1;
	for (int i = 1; i <= n; i++) {
		char c; cin >> c;
        if (c == '-') continue;
		for (int j = 0; j <= n; j++) {
			if (c == 'U') {
				dp0[j] = j*dp1[j];
				dp0[j] += dp1[j-1];
			} else {
				dp0[j] = (j+1)*(j+1)*dp1[j+1] + j*dp1[j];
			}
			dp0[j] %= (ll)(1e9+7);
		}
		swap(dp0, dp1);
	}
	cout << dp1[0] << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <cstdlib> 
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  
  for(int i = 1; i < 1000000000; i++){
   if (abs(A-i) == abs(B-i)){
     cout << i << endl; 
     return 0;
   }
  }
  cout << "IMPOSSIBLE" << endl; 
  return 0;
}

Measured memory_bytes: 256
/*****Here we go again!******/

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

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 3e5 + 10;

int main()
{
    fast;
    int n, k;
    cin >> n >> k;
    vi a(n);
    get(a,n);

    vi dp(n,inf);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);

    f(i,2,n)
    {
        if(i < k)
        {
            f(j,1,i+1)
                dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
        }
        else
        {
            f(j,1,k+1)
                dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
        }
    }
    cout << dp[n-1];
}


Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(n) cout << n << endl
#define in(v) int v; cin >> v
#define vint vector<int>
#define pb push_back
typedef long long int ll;


int main(){
  int a,b;cin>>a>>b;print(a*b);
  return 0;
}

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

int main() {
    int n;cin >> n;
    string ans = "APPROVED";
    for (int i = 0; i < n; i++)
    {
        int a;cin >> a;
        if(a%2 == 0){
            if(!(a%3 == 0 || a%5 == 0)){
                ans = "DENIED";
                break;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3632
n = int(raw_input())

dice = [[0 for i in range(6)] for j in range(n)]
for i in range(n):
    dice[i] = map(int, raw_input().split())
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
def dice_matching(dice1, dice2):
    if dice1[1] == dice2[1]:
        for i in range(4):
            if dice1 == dice2:
                return 1
                break
            rolling('E', dice2)
        return 0
    else:
        return 0

def alldice_matching(dice1, dice2):
    count = 0
    while(1):
        if dice_matching(dice1, dice2) == 1:
            return 1
        else:
            if count < 3:
                rolling('N', dice2)
                count += 1
            elif 7 > count and count >= 3:
                if count == 3:
                    rolling('E', dice2)
                rolling('N', dice2)
                count += 1
            else:
                return 0

flag = 0
for i in range(n):
    for j in range(i+1, n):
        if alldice_matching(dice[i], dice[j]) == 1:
            flag = 1
            print "No"
            break
    if flag == 1:
        break
if flag == 0:
    print 'Yes'

Measured memory_bytes: 6468
#include<bits/stdc++.h>
#include<random>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=15;

bool ok[maxn][maxn],dp[1<<maxn];
int n,m;
vector<string>s;

int main(){
	random_device rd;
	mt19937 mt(rd());
	cin>>n>>m;
	for(int i=0;i<n;i++){
		string str;
		cin>>str;
		s.pb(str);
	}
	for(int t=0;t<100000;t++){
		for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) ok[i][j]=true;
		for(int i=0;i<(1<<m);i++) dp[i]=false;
		for(int j1=0;j1<m;j1++) for(int j2=j1;j2<m;j2++)
			for(int i=0;i<n;i++) if(s[i][j1]!=s[n-1-i][j2]) ok[j1][j2]=false;
		dp[0]=true;
		for(int mask=0;mask<(1<<m);mask++) if(dp[mask]){
			for(int j1=0;j1<m;j1++) for(int j2=j1+1;j2<m;j2++)
				if((!(mask&(1<<j1)))&&(!(mask&(1<<j2)))&&ok[j1][j2])
					dp[mask|(1<<j1)|(1<<j2)]=true;
		}
		if(m%2==0){
			if(dp[(1<<m)-1]==true){
				cout<<"YES\n";
				return 0;
			}
		}
      
		if(m%2==1){
			for(int j=0;j<m;j++){
				if(dp[((1<<m)-1)^(1<<j)]&&ok[j][j]){
					printf("YES\n");
					return 0;
				}
			}
		}
		shuffle(s.begin(),s.end(),mt);
	}
  	printf("NO\n");
	return 0;
}


Measured memory_bytes: 384
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n, k, *p = map(int, read().split())
    p2 = [0] + [(1 + pe) / 2 for pe in p]
    r = 0
    p2a = tuple(accumulate(p2))
    for i1 in range(k, n+1):
        r = max(r, p2a[i1] - p2a[i1-k])
    print(r)

if __name__ == '__main__':
    main()


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

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

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

//戻り値: 負の閉路が存在する場合、Trueを返す。
template<typename T>
bool bellman_ford(const vector<vector<pair<int,T>>>& path,vector<T>& dis,int start){
    int n=path.size(),is_null=dis[0];
    int to;
    T cost;
    dis[start]=0;
    for(int i=1;i<=n;i++){
        bool update=false;
        rep(j,n)for(auto e:path[j]){
            tie(to,cost)=e;
            if(dis[j]!=is_null && dis[to]>dis[j]+cost){
                dis[to]=dis[j]+cost;
                update=true;
            }
        }
        if(!update) return false;
        if(i==n) return true;
    }
}

int main(){
    int n,m; cin>>n>>m;
    vector<vector<pair<int,ll>>> path(n);
    vector<ll> dis(n,INF);
    rep(i,m){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        path[a].push_back(mk(b,-c));
    }
    bellman_ford<ll>(path,dis,0);
    ll ans=dis[n-1];
    dis[0]=INF;
    bellman_ford<ll>(path,dis,0);
    if(ans==dis[n-1]){
        cout<<-ans<<endl;
    }
    else cout<<"inf"<<endl;
}


Measured memory_bytes: 3700
#include<stdio.h>
#define MAX 2000000
#define INF (1<<30)
void maxheapify(int);
int extract();
void increasekey(int,int);
void insert(int);
int G,N[MAX+1];

int main(){
  int key;
  char c[10];
  while(1){
    scanf("%s",c);
    if(c[0] == 'e' && c[1] == 'n'){
      break;
    }
    if(c[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}

void increasekey(int i,int key){
  int a;
  if(key < N[i]){
    return;
  }
  N[i]=key;
  while(i > 1 && N[i/2] < N[i]){
    a=N[i];
    N[i]=N[i/2];
    N[i/2]=a;
    i=i/2;
  }
}
int extract(){
  int m;
  if(G<1){
    return -INF;
  }
    m=N[1];
    N[1]=N[G--];
    maxheapify(1);
    return m;
}

void maxheapify(int i){
  int a,k,e,largest;
  k=2*i;
  e=2*i+1;
  if(k<=G && N[k] > N[i])largest = k;
  else largest = i;
  if(e <= G && N[e] > N[largest])largest = e;
  if(largest != i){
    a=N[i];
    N[i]=N[largest];
    N[largest]=a;
    maxheapify(largest);
  }
}
void insert(int k){
  G++;
  N[G]=-INF;
  increasekey(G,k);
}




Measured memory_bytes: 5592
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
long long knap[1024][100001];
int main(){
  int N;
  scanf("%d",&N);
  long long V[1000000],W[1000000];
  for(int i=1;i<=N;i++){
    scanf("%lld%lld",&V[i],&W[i]);
  }
  for(int i=0;i<=min(1023,N);i++){
    int k=i/2;
    for(int j=0;j<=100000;j++){
      if(j==0) knap[i][j]=0;
      else if(i==0){
        knap[i][j]=0;
      }
      else{
        if(j-W[i]>=0&&knap[k][j]<knap[k][j-W[i]]+V[i]) knap[i][j]=knap[k][j-W[i]]+V[i];
        else knap[i][j]=knap[k][j];
      }
    }
  }
  int Q;
  scanf("%d",&Q);
  for(int i=0;i<Q;i++){
    int v,L;
    scanf("%d%d",&v,&L);
    if(v>=1024){
    long long k=1;
    int u[10];
    u[0]=v;
    int t=0;
    while(u[t]>=1024){
      k=k*2;
      u[t+1]=u[t]/2;
      t++;
    }
    long long answer=0;
    for(int a=0;a<k;a++){
      long long val=0;
      long long wei=0;
      int K=1;
      int J=0;
      while(J<t){
        if((a/K)%2==1){
          val+=V[u[J]];
          wei+=W[u[J]];
        }
        J++;
        K=K*2;
      }
      if(wei<=L&&answer<val+knap[u[t]][L-wei]) answer=val+knap[u[t]][L-wei];
    }
    printf("%lld\n",answer);
    }
    else printf("%lld\n",knap[v][L]);
  }
  
  return 0;
}

Measured memory_bytes: 807348
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, M;
    while(cin >> N >> M, N || M) {
        vector<int> A(N), B(M);
        for(int i=0; i<N; i++) {
            cin >> A[i];
        }
        for(int i=0; i<M; i++) {
            cin >> B[i];
        }

        // シミュレーション
        int pos = 0;
        for(int i=0; i<M; i++) {
            pos += B[i];
            if(pos >= N-1) {
                cout << i+1 << endl;
                break;
            }
            pos += A[pos];
            if(pos >= N-1) {
                cout << i+1 << endl;
                break;
            }
            // fprintf(stderr, "pos = %lld\n", pos);
        }
    }
    return 0;
}



Measured memory_bytes: 3032
#include<cstdio>
using namespace std;

int main(){
	int n;
	double wei, hei;
	while( scanf("%d,%lf,%lf", &n, &wei, &hei)==3 ){
		double bmi = wei / (hei*hei);
		if( bmi >= 25.0 ){
			printf("%d\n", n);
		}
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, x; cin >> a >> b >> x;

    int y = a*a*b - x;
    if (x >= y) {
        double l = (double)y/(0.5*a*a);
        cout << fixed << setprecision(7) << atan((double)l/a) * 180.0 / acos(-1.0);
    } else {
        double l = (double)x/(0.5*a*b);
        cout << fixed << setprecision(7) << atan((double)b/l) * 180.0 / acos(-1.0);
    }
}



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

#define f(i,n) for (int i = 0; i < n; i++)
#define fr(i,n) for(int i = n-1; i>=0;i--)

int main() {
	int n,m,t;
	cin>>n>>m>>t;
	int i,j; cin>>i>>j; i--; j--;
	string s,r;
	cin>>s>>r;
	auto win = [&](int a[], int b[], int st, int mx) {
		int l = 0, r = mx-1;
		fr(i,t) {
			if (b[i]==1 && r != mx-1) r++;	
			if (b[i]==2 && l) l--;
			if (a[i]==2) r--;
			if (a[i] == 1) l++;
			if (l>r) break;
		}
		return l<=st&&st<=r;
	};
	int a[t],b[t],c[t],d[t];
	f(i,t) {
		a[i]=b[i]=c[i]=d[i]=0;		
		if (s[i] == 'L') a[i]=1;
		if (s[i] == 'R') a[i]=2;

		if (s[i] == 'U') c[i]=1;
		if (s[i] == 'D') c[i]=2;

		if (r[i] == 'L') b[i]=1;
		if (r[i] == 'R') b[i]=2;

		if (r[i] == 'U') d[i]=1;
		if (r[i] == 'D') d[i]=2;
	}
	cout << (win(a,b,j,m)&&win(c,d,i,n)?"YES":"NO") << endl;
	

	return 0;
}


Measured memory_bytes: 3848
import itertools
import math

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
cnt = 0
tot = 0
for ptn in itertools.permutations(XY):
    now = ptn[0]
    cnt += 1
    for nex in ptn[1:]:
        tot += math.sqrt(pow(now[0]-nex[0], 2)+pow(now[1]-nex[1], 2))
        now = nex
print(tot/cnt)


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

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

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


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

            var input = Reads();
            var a = input[0];
            var b = input[1];
            var c = input[2];
            bool f = false;
            for (int i = 0; i < b; i++)
            {
                if ((a % b * (i % b)) % b == c)
                    f = true;
            }
            if (f)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");


            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
 
#define int long long
 
#define Vanya Unstoppable
 
using namespace std;

const int N = 51, M = 2501;

int dp[N][M][N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
//    int n, k;
//    cin >> n >> k;
//
//    int a[n + 1];
//    for (int i = 1; i <= n; ++i) {
//        cin >> a[i];
//    }
//
//    for (int i = 1; i <= n; ++i) {
//        dp[i][a[i] % k] = 1;
//        for (int j = 0; j < k; ++j) {
//            dp[i][(a[i] + j) % k] += dp[i - 1][j];
//            dp[i][j] += dp[i - 1][j];
//        }
//    }
//
//    int ans = 0;
//    for (int i = 1; i <= n; ++i) {
//        cout << i << ' ' << dp[i][0] << endl;
//    }
//
//    cout << dp[n][0];
    
    int n, k;
    cin >> n >> k;
    
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    for (int i = 0; i < n; ++i) {
        dp[i][a[i]][1] = 1;
        for (int x = 0; x < M; ++x) {
            for (int y = 0; y < N; ++y) {
                int new_x = x + a[i];
                int new_y = y + 1;
                if (i - 1 >= 0) {
                    if (new_x < M && new_y < N) {
                        dp[i][new_x][new_y] += dp[i - 1][x][y];
                    }
                    dp[i][x][y] += dp[i - 1][x][y];
                }
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < M; ++i) {
        for (int j = 1; j < N; ++j) {
            if (i % j == 0 && i / j == k) {
                ans += dp[n - 1][i][j];
            }
        }
    }
    
    cout << ans;
}


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

using namespace std;

using int64 = long long;

int main()
{
  int N;
  cin >> N;
  deque< int > deq(N * 3);
  for(auto &p : deq) cin >> p;
  sort(begin(deq), end(deq));
  int64 ret = 0;
  while(!deq.empty()) {
    deq.pop_back();
    deq.pop_front();
    ret += deq.back();
    deq.pop_back();
  }

  cout << ret << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
    ll n;
    cin>>n;
    const ll N=1e18;
    ll nn=N;
    ll a[n];
    ll i;
    ll z=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]!=0){
        nn/=a[i];
        }
        else{
            z=1;
        }
    }
    if(z)
    {
        cout<<0<<"\n";
        return;
    }

    if(nn==0)
    {
        cout<<"-1\n";
        return;
    }
    ll res=1;
    for(i=0;i<n;i++)
    {
        res*=a[i];
    }
    cout<<res<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 4396
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
const ll inf=(1e18);
const ll mod=1000000007;
double dp[4000][4000];
map<char,ll> mp;
int main(){
int n;cin>>n;
vector<int> s(n);
for(int i=0;i<n;i++)cin>>s[i];
int m;
cin>>m;
vector<int> t(m);
for(int i=0;i<m;i++)cin>>t[i];
sort(all(t));
s.erase(unique(all(s)),s.end());
int ans=0;
int j=0;
for(int i=0;i<m;i++){
    while(j<s.size()&&t[i]>s[j]){j++;}
    if(j<s.size()&&t[i]==s[j]){ans++;j++;}
}
cout<<ans<<endl;
}





Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#define maxm 1004004
#define h 1002
#define w 1002

int is_prime[maxm + 1], nums[h][w], dp1[h][w], dp2[h][w], posx[maxm + 1], posy[maxm + 1];

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int m, n, i, j, d, k;
	int dx[] = {0, 1, 0, -1};
	int dy[] = {1, 0, -1, 0};
	for(i = 0; i <= maxm; i++){
		is_prime[i] = 1;
	}
	is_prime[0] = 0;
	is_prime[1] = 0;
	for(i = 2; i <= maxm; i++){
		for(j = 2; i * j <= maxm; j++){
			is_prime[i * j] = 0;
		}
	}
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			nums[i][j] = 0;
		}
	}
	for(n = maxm, d = 0, i = 0, j = 0; n > 0; n--){
		nums[i][j] = n;
		posx[n] = i;
		posy[n] = j;
		if(i + dx[d] < 0 || h <= i + dx[d] || j + dy[d] < 0 || w <= j + dy[d]){
			d = (d + 1) % 4;
		}
		else if(nums[i + dx[d]][j + dy[d]] > 0){
			d = (d + 1) % 4;
		}
		i += dx[d];
		j += dy[d];
	}
	while(1){
		scanf("%d%d", &m, &n);
		if(m == 0 && n == 0){
			return 0;
		}
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				dp1[i][j] = 0;
				dp2[i][j] = 0;
			}
		}
		for(i = h - 2; i > 0; i--){
			for(j = 1; j < w - 1; j++){
				if(nums[i][j] <= m){
					dp1[i][j]--;
					if(is_prime[nums[i][j]] == 1){
						dp1[i][j]--;
					}
					for(k = -1; k <= 1; k++){
						if(dp1[i][j] < dp1[i + 1][j + k]){
							dp1[i][j] = dp1[i + 1][j + k];
							dp2[i][j] = dp2[i + 1][j + k];
						}
						else if(dp1[i][j] == dp1[i + 1][j + k]){
							dp2[i][j] = max(dp2[i][j], dp2[i + 1][j + k]);
						}
					}
					if(is_prime[nums[i][j]] == 1){
						if(dp1[i][j] == 0){
							dp2[i][j] = nums[i][j];
						}
						dp1[i][j]++;
					}
				}
			}
		}
		printf("%d %d\n", dp1[posx[n]][posy[n]], dp2[posx[n]][posy[n]]);
	}
}


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

int main()
{
    int a, b;
    int result = 0;

    cin >> a >> b;

    if(b == 1)
    {
        result = 0;
    }
    else if((a == b) || (a > b))
    {
        result = 1;
    }
    else
    {
        for(int i = 0; i < b; )
        {
            result++;
            if((i + a) >= b)
            {
                i += a;
            }
            else
            {
                i += (a -1);
            }
        }
        
    }
        
    cout << result << endl;

    return 0;
}


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

int main(){

double f;
int x,y,d,r;

std::cin >> x >> y;

d = x/y;
r = x%y;
f = double(x)/double(y);

std::printf("%d %d %.5f", d, r, f);

return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }



void solve(long long N, std::string S){
	ll res = 0;
	REP(i, N) {
		if (S[i]!=S[i+1]) res++;
	}
	cout << res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

using namespace std;

int main(){
  string s;
  cin>>s;
    
  int c=0,c1=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0')
      c+=1;
    else if(s[i]=='1')
      c1+=1;
  }
  int res=min(c,c1)*2;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 512
package main

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

func StrStdin() (stringInput string) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput = scanner.Text()

	stringInput = strings.TrimSpace(stringInput)
	return
}

func main() {

	var N int
	fmt.Scan(&N)

	S := StrStdin()

	if N%2 == 0 {
		if S[0:len(S)/2] == S[len(S)/2:len(S)] {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	string s, t, ans="Yes";
	cin >> s >> t;
	fore(i, 0, s.size()) {
		if (s[i]!=t[i]) {
			ans = "No";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		int sum = (int)(A + B + C + Math.max(A,Math.max(B,C))*(Math.pow(2,K) -1));
		System.out.println(sum);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(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; }
const ll INF = 1LL << 60;
int main(){
    int n;
    cin >> n;
    vector<pair<string,int>> sv[11];
    sv[0].emplace_back("a",1); //index+1の長さ , 文字の種類
    for(int i=1; i<n; i++){
        for(auto x : sv[i-1]){
            string s = x.first;
            int num = x.second;
            for(int j=0; j<=num; j++){
                string ns = s + (char)('a'+j);
                int nnum = max(num,j+1);
                sv[i].emplace_back(ns,nnum);
            }
        }
    }
    sort(sv[n-1].begin(),sv[n-1].end());
    for(auto x : sv[n-1]){
        cout << x.first << endl;
    }
    
    return 0;
}

Measured memory_bytes: 10736
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    double a, b; cin >> a >> b;
    double h, m; cin >> h >> m;
    double s_param = abs(30*h-11*m/2);
    double param = min(s_param, 360-s_param);
    double c_2 = pow(a, 2.0)+pow(b, 2.0)-2*a*b* cos ( param *  M_PI / 180.0 );
    double ans = sqrt(c_2);
    printf ("%.11f\n",ans); 


}

Measured memory_bytes: 4216
# AFTER EDITORIAL


def solve(ls):
    import math

    x, y, *ls = ls
    z = x + y
    s = 0
    for a in ls:
        s ^= a

    #
    # Max a <= x  s.t.
    #   0 = NimSum(a, (x + y) - a, ls)
    # <=>
    # Max a <= x s.t.
    #   ∃b.
    #     a + b = x + y  (NOTE: a + b = a ^ b + 2 (a & b))
    #     a ^ b = NimSum(ls)
    # <=>
    # Max a <= x s.t.
    #   ∃b.
    #     a & b = (x + y - NimSum(ls)) / 2
    #     a ^ b = NimSum(ls)
    #

    #
    # Thus it amounts to solve
    #   a ^ b = s
    #   a & b = (z - s) / 2 = t
    #
    # which is bit-wise independent as
    #   a  b  ^  &
    #   0  0  0  0
    #   0  1  1  0
    #   1  0  1  0
    #   1  1  0  1
    #

    if (z - s) < 0 or (z - s) % 2 == 1:
        return -1

    t = (z - s) // 2
    s_t = s & t

    if s_t > 0 or t > x:
        return -1

    a = t
    b = t
    first_set = math.floor(math.log2(s + 1))
    for i in range(first_set + 1)[::-1]:
        k = 1 << i
        if s & k:
            if (a | k) <= x:  # Greedy is optimal
                a = a | k
            else:
                b = b | k
    if a == 0:
        return -1
    return x - a


def main(istr, ostr):
    n = int(istr.readline().strip())
    ls = list(map(int, istr.readline().strip().split()))
    result = solve(ls)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)


Measured memory_bytes: 9300
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
	int N;cin>>N;
	int n = N;
	int num = 0;
	for(int i = 1;i < 10;i++){
		num += N % 10;
		N /= 10;
		
	}
	cout<<(n % num == 0?"Yes":"No");

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const ll INF = 1e18;
ll N;
ll X[200000], Y[200000];
char U[200000];

ll get_min(char first, char second, ll sign) {
    map<ll, set<ll>> m;
    REP(i, N) {
        if (U[i] != first) continue;
        ll line = Y[i] + sign * X[i];
        if (m.count(line) == 0) {
            set<ll> set {Y[i]};
            m[line] = set;
        } else {
            m[line].insert(Y[i]);
        }
    }

    ll ret = INF;
    REP(i, N) {
        if (U[i] != second) continue;
        ll line = Y[i] + sign * X[i];
        if (m.count(line) == 0) continue;
        auto it = m[line].lower_bound(Y[i]);
        if (it != m[line].begin()) {
            it--;
            ret = min(ret, (Y[i] - *it) * 10);
        }
    }
    return ret;
}

ll get_min_same_line() {
    ll ret = INF;
    map<ll, set<ll>> m;
    REP(i, N) {
        if (U[i] != 'U') continue;
        if (m.count(X[i]) == 0) {
            set<ll> set {Y[i]};
            m[X[i]] = set;
        } else {
            m[X[i]].insert(Y[i]);
        }
    }
    REP(i, N) {
        if (U[i] != 'D' || m.count(X[i]) == 0) continue;
        auto it = m[X[i]].lower_bound(Y[i]);
        if (it != m[X[i]].begin()) {
            it--;
            ret = min(ret, (Y[i] - *it) * 5);
        }
    }

    m.clear();
    REP(i, N) {
        if (U[i] != 'R') continue;
        if (m.count(Y[i]) == 0) {
            set<ll> set {X[i]};
            m[Y[i]] = set;
        } else {
            m[Y[i]].insert(X[i]);
        }
    }
    REP(i, N) {
        if (U[i] != 'L' || m.count(Y[i]) == 0) continue;
        auto it = m[Y[i]].lower_bound(X[i]);
        if (it != m[Y[i]].begin()) {
            it--;
            ret = min(ret, (X[i] - *it) * 5);
        }
    }
    return ret;
}

int main() {
    cin >> N;
    REP(i, N) cin >> X[i] >> Y[i] >> U[i];
    ll ans = INF;
    ans = min(ans, get_min('R', 'D', -1));
    ans = min(ans, get_min('U', 'L', -1));
    ans = min(ans, get_min('L', 'D', 1));
    ans = min(ans, get_min('U', 'R', 1));
    ans = min(ans, get_min_same_line());
    if (ans == INF) cout << "SAFE" << endl;
    else cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    string s;
    cin >> s;
    vector<int> res(s.size(), 0);
    int num = 1;
    int lastR = 0;
    for (int i = 0; i < s.size() - 1; ++i) {
        if (s[i] == 'R' && s[i+1] == 'L') {
            res[i] += (num + 1) / 2;
            res[i+1] += num / 2;
            lastR = i;
            num = 1;
        } else if (s[i] == 'L' && s[i+1] == 'R') {
            res[lastR] += num / 2;
            res[lastR+1] += (num + 1) / 2;
            num = 1;
        } else {
            num++;
        }
    }
    res[lastR] += num / 2;
    res[lastR+1] += (num + 1) / 2;

    for (int i = 0; i < s.size(); ++i) {
        cout << res[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3852
m, k = gets.chomp.split(' ').map(&:to_i)

def print_ans(*arr)
  puts arr.join(' ')
end

if k >= 2**m
  puts '-1'
else
  case m
  when 0
    if k == 0
      print_ans(0, 0)
    else
      puts '-1'
    end
  when 1
    if k == 0
      print_ans(0, 0, 1, 1)
    else
      puts '-1'
    end
  else
    a = (0...(2**m)).to_a
    a.delete(k)
    b = a.reverse
    print_ans(*a, k, *b, k)
  end
end

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

void func(std::string S){

    if(S[0]=='R' && S[1]=='R' && S[2]=='R')cout<<3<<endl;
    else if(S[0]=='R' && S[1]=='R')cout<<2<<endl;
    else if(S[1]=='R' && S[2]=='R')cout<<2<<endl;
    else if(S[0]=='R' || S[1]=='R' || S[2]=='R')cout<<1<<endl;
    else cout<<0<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N,K,X,Y;
    cin >> N >> K >> X >> Y;
    ll cost = 0;
    cost += X*min(K,N);
    N -= min(K,N);
    cost += Y * N;
    cout << cost << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int h[110];
    int times=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    h[0]=0;
    for(int i=1;i<=n;i++){
        if(h[i]-h[i-1]>0)
            times+=h[i]-h[i-1];
    }
    cout<<times<<"\n";
    return 0;
}


Measured memory_bytes: 896
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        for(int i = 0;i < m; i++) n -= int.Parse(input[i]);
        if(n < 0) n = -1;
		Write(n.ToString());
	}

	static void Write(string output)
	{
		Console.WriteLine(output);
	}

	static void Write(object[] output)
	{
		foreach (var o in output)
		{
			Write(o.ToString());
		}
	}
}

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, x, dp[100005][5] ;
    cin>> n ;
    dp[0][0]=dp[0][1]=dp[0][2]=0 ;
    for(int i=1 ; i<=n ; i++)
      for(int j=0 ; j<3 ; j++)
        {
          cin>> x ;
          dp[i][j]=x+max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) ;
        }
    cout<< max({dp[n][0], dp[n][1], dp[n][2]}) ;
  }


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int turn = 1;
    while(a>0 && c>0){
        if(turn%2==1){
            c -= b;
        }else{
            a -= d;
        }
        turn += 1;
    }
    if(a>0){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

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

int main() {
	string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	int n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.size(); ++i) {
		cout << alphabet.at((s.at(i) - 'A' + n) % 26);
	}
	cout << endl;
}

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

int main(){
	int n,m;
	while(1){
		double x[100][100];
		double dp[101][100] = {};
		cin >> n >> m;
		if(!n) break;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				cin >> x[i][j];
			}
		}
		for(int i = 0;i < n;i++) dp[0][i] = 1;
		for(int i = 1;i < m;i++){
			for(int j = 0;j < n;j++){
				for(int k = 0;k < n;k++){
					dp[i][j] = max(dp[i][j],dp[i - 1][k] * x[k][j]);
				}
			}
		}
		double ma = 0;
		for(int i = 0;i < n;i++) ma = max(ma,dp[m - 1][i]);
		printf("%.2f\n",round(ma * 100.0) / 100.0);
	}
	return 0;
}

Measured memory_bytes: 3480
n = int(input())
s = []
for i in range(n):
  s.append(input())
  
m = int(input())
t = []
for i in range(m):
  t.append(input())

count = 0
for i in range(n):
  count = s.count(s[i]) - t.count(s[i]) if count < s.count(s[i]) - t.count(s[i]) else count
print(count)

Measured memory_bytes: 9164
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	private static final int BIG_LETTER = 0;
	private static final int LITTLE_LETTER = 1;
	private static final int OTHERS = 2;
	
	private static Scanner sc = new Scanner(System.in);
	private static ArrayList<String> result = new ArrayList<String>();
	
	public static void main(String[] args) {
		//1行の入力を受け取る
		String input = getInput();
		
		//入力を分割し文字列リストに追加する
		setInputStrings(input);
		
		//文字列リストの文字列の小文字大文字を入れ替える
		replaceAllStrings();
		
		//文字列リストの文字列を出力する
		printAllInputStrings();
	}
	
	private static String getInput(){
		return sc.nextLine();
	}
	
	private static void setInputStrings(String input){
		String[] strings = input.split(",");
		for(int i = 0; i < strings.length; i++){
			result.add(strings[i]);
		}
	}
	
	private static int isBigLetter(char c){
			if(65 <= c && c <= 90){
				return BIG_LETTER;
			}
			else if(97 <= c &&  c <= 122){
				return LITTLE_LETTER;
			}
			else{
				return OTHERS;
			}
	}
	
	private static String getReplaceString(String str){
		String resultString = new String();
		for(int i = 0; i < str.length(); i++){
			String c = String.valueOf(str.charAt(i));
			switch(isBigLetter(c.charAt(0))){
			case BIG_LETTER:
				resultString = resultString.concat(c.toLowerCase());
				break;
			case LITTLE_LETTER:
				resultString = resultString.concat(c.toUpperCase());
				break;
			case OTHERS:
				resultString = resultString.concat(c);
				break;
			}
		}
		
		return resultString;
	}
	
	private static void replaceAllStrings(){
		for(int i = 0; i < result.size(); i++){
			String str = getReplaceString(result.get(i));
			result.set(i, str);
		}
	}

	private static void printAllInputStrings(){
		for(int i = 0; i < result.size(); i++){
			System.out.printf("%s", result.get(i));
			if(i < result.size() - 1){
				System.out.printf(",");
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 27204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back

int main()
{
    ll r;
    cin>>r;
    cout<<3*r*r;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int A[4];
int calc(int&id,string s)
{
	if(s[id]=='(')
	{
		id++;
		int a=calc(id,s);
		char c=s[id];
		id++;
		int b=calc(id,s);
		id++;
		return c=='+'?a+b:c=='-'?a-b:a*b;
	}
	else
	{
		return s[id++]-'0';
	}
}
main()
{
	while(1)
	{
		for(int i=0;i<4;i++)cin>>A[i];
		if(A[0]==0)break;
		sort(A,A+4);
		string ans="0";
		do{
			for(int T=0;T<27;T++)
			{
				int B[3]={T%3,T/3%3,T/9};
				int C[3]={1,2,3};
				do{
					string now="";
					int lv=0;
					int flag=1;
					if(C[1]==1)
					{
						if(C[0]==3)C[flag=0]=2;
						else C[flag=2]=2;
					}
					for(int i=0;i<3;i++)
					{
						while(lv<C[i])lv++,now+='(';
						now+=A[i]+'0';
						while(lv>C[i])lv--,now+=')';
						now+="+-*"[B[i]];
					}
					now+=A[3]+'0';
					while(lv>0)lv--,now+=')';
					int id=0;
					if(calc(id,now)==10)
					{
						ans=now;
						break;
					}
					if(flag!=1)C[flag]=3;
				}while(next_permutation(C,C+3));
				if(ans!="0")break;
			}
			if(ans!="0")break;
		}while(next_permutation(A,A+4));
		for(int i=0;i<ans.size();i++)
		{
			if(ans[i]=='+'||ans[i]=='-'||ans[i]=='*')cout<<' '<<ans[i]<<' ';
			else cout<<ans[i];
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3060