akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int N;
double dp[310][310][310];
double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main() {
    cin >> N;
    int one = 0, two = 0, three = 0;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        if (a == 1) ++one;
        else if (a == 2) ++two;
        else ++three;
    }

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

    cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

Measured memory_bytes: 233088
from math import factorial

a, b = [int(i) for i in input().split()]
num = 1
if abs(a-b) == 1:
    num = factorial(a)*factorial(b)
elif abs(a-b) == 0:
    num = factorial(a) * factorial(b) * 2
else:
    num = 0

print(num%(10**9+7))

Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int m;
    cin>>m;
    ll cnt=0,sum=0;
    rep(i,m){
        ll d,c;
        cin>>d>>c;
        cnt+=c;
        sum+=d*c;
    }
    ll ans=cnt-1+((sum-1)/9);

    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define mod 1000000007
#define pie 3.141592653589793238
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
int main()
{
fast_io
li k,n,x,s=0,i;
cin>>k>>n;
for(i=0;i<n;i++)
{
  cin>>x;
  s+=x;
}
if(s>k)
cout<<"-1";
else
cout<<k-s;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++){
    cin >> s[i];
  }
  int ans = 0;
  int A = 0;
  int B = 0;
  int diff = 0;
  for (int i = 0; i < N; i++){
    int K = s[i].size();
    for (int j = 0; j < K - 1; j++){
      if (s[i].substr(j, 2) == "AB"){
        ans++;
      }
    }
    if (s[i][0] == 'B'){
      B++;
      if (s[i][K - 1] == 'A'){
        A++;
      } else {
        diff++;
      }
    } else if (s[i][K - 1] == 'A'){
      A++;
      diff++;
    }
  }
  ans += min(A, B);
  if (diff == 0 && A != 0){
    ans--;
  }
  cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    int a[n], sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    cout << sum-n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <string> v;
vector<int> x;
string s;
string ans = "Yes";
int main(){
  int a,b;
  cin >>a>>b>>s;

  for(int i = 0;i<a;i++){
    if(s[i] == '-')ans = "No";
  }
  if(s[a] == '-'){
    for(int i = a+1;i<b+a+1;i++){
      if(s[i] == '-')ans = "No";
    }

  }else{
    ans = "No";
  }



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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=0;
    for (int i = 0; i < s.size(); i++)
    {
        n+=s[i]-'0';
    }
    
    if(n%9==0) cout<<"Yes"<<endl;
    else cout<<"No\n";
}

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

int main(void){
  while(1){
    int H,W;
    cin>>H>>W;
    if(H==0&&W==0)break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if((i+j)%2==0){cout<<"#";}
        else {cout<<".";}
      }cout<<endl;
    }
    cout<<endl;
  }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main(){
    set<string> m;
    int n;
    cin >> n;
    for(int i = 0; i < n;i++){
        string s;
        cin >> s;
        m.insert(s);
    }
    cout << m.size() << endl;
    return 0;
}


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

int n, a;
map<int, int> ma;
long long fp;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a;
		fp += ma[a - i];
		++ma[-(a + i)];
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 20676
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 1000000007
#define N 100005
#define PI 3.14159265
bool compare(pair<ll,ll> i, pair<ll,ll> j) 
{
  return i.S < j.S;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
}
int main()
{
	ios
	ll n,k,a,min1;
	cin>>n>>k;
	vi v,v1(n,INF);
	rep(i,0,n)
	{
		cin>>a;
		v.pb(a);
	}
	v1[0]=0;
	v1[1]=abs(v[1]-v[0]);
	if(k>=n)
		k=n-1;
	rep(i,0,k)
	{
		//v1.pb(INF);
		rep(j,0,i)
		{
			v1[i]=min(v1[i],v1[j]+abs(v[j]-v[i]));
		}
	}
	rep(j,k,n)
	{
		//min1=abs(v[j]-v[j-k])+v1[j-k];
		min1=INF;
		rep(i,j-k,j+1)
		{
			if(v1[i]+abs(v[i]-v[j])<min1)
			{
				min1=v1[i]+abs(v[i]-v[j]);
			}
			v1[j]=min1;
		}
	}
	cout<<v1[n-1];
	return 0;
}

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

int main(){
    int n; cin >> n;
    if(n%2==1) cout << n/2 << endl;
    else cout << n/2 - 1 << endl;
}

Measured memory_bytes: 3548
s=int(input())
#S=[-1]*200
#S[0]=s
S=[];A=[];f=-1
if s==1:
  print(4)
elif s==2:
  print(4)
elif s==3:
  print(9)
elif s==4:
  print(4)
else:
  S.append(s)
  i=1;p=-1
  while p!=4:
    if S[i-1]%2==0:
      S.append(S[i-1]//2)
      #print(S[i])
    else:
      S.append(S[i-1]*3+1)
      #print(S[i])
    p=S[-1]
    i=i+1
  #print(i,S)
  for i in range(len(S)-1):
    for j in range(i+1,len(S)):
      if S[i]==S[j]:
        f=1
        print(j)
        break
  if f==-1:
    print(len(S)+3)

Measured memory_bytes: 3064
N = int(input())
a = [int(i) for i in input().split()]
all_xor = a[0]

for ai in range(len(a) - 1):
    all_xor = all_xor ^ a[ai + 1]

for ai in a:
    if ai ^ all_xor != ai:
        print('No')
        exit(0)

print('Yes')
exit(0)


Measured memory_bytes: 15524
#include <bits/stdc++.h>
using namespace std;
int a,w,t,r;string s;
int main()
{
   int n; cin>>n;

   while(n--){

       cin>>s;
       if(s=="AC") a++;
       else if(s=="WA") w++;
       else if(s=="TLE") t++;
       else if(s=="RE") r++;


   }
    cout<<"AC x "<<a<<endl;;
    cout<<"WA x "<<w<<endl;;
    cout<<"TLE x "<<t<<endl;;
    cout<<"RE x "<<r<<endl;




    return 0;
}

Measured memory_bytes: 3620
while True:
    n = int(input())
    if n == 0:
        break
    ls = [list(map(int, input().split())) for _ in range(n)]
    P, Q, R, C = map(int, input().split())
    b = True
    for l in ls:
        if P >= l[1] and Q >= l[2] and R >= l[3] and 4*l[1]+9*l[2]+4*l[3] <= C:
            print(l[0])
            b = False
    if b: print("NA")

Measured memory_bytes: 8148
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int n,w,s,e;
string x;

int main() {
    cin >> x;
    rep(i, (int)x.size()) {
        if (x[i] == 'N') n++;
        if (x[i] == 'W') w++;
        if (x[i] == 'S') s++;
        if (x[i] == 'E') e++;
    }

    bool ok = true;
    if (min(n, s) == 0 && max(n, s) != 0) ok = false;
    if (min(e, w) == 0 && max(e, w) != 0) ok = false;
    cout << (ok ? "Yes" : "No") << endl;
}


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

vector<vector<int>> g;
vector<int> dp;
int ans = INT_MIN;

int dfs(int v) {
  if (dp[v] != -1) {
    return dp[v];
  }
  int path = 0;
  for (auto c : g[v]) {
    path = max(path, 1 + dfs(c));
  }
  ans = max(ans, path);
  dp[v] = path;
  return path;
}

int main() {
  int n, m;
  cin >> n >> m;
  g.assign(n, vector<int>());
  dp.assign(n, -1);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
  }
  for (int i = 0; i < n; ++i) {
    if (dp[i] == -1) {
      dfs(i);
    }
  }
  cout << ans << '\n';
  return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   int n;cin >>n;
   int k=-1;
    for (int i = 0; i <=n; ++i) {
        if(2*n==i*(i+1))k=i+1;
    }
//    cout <<k<<endl;
    if(k<0)puts("No");
    else {
        puts("Yes");
        cout <<k<<endl;
        vector<vector<int>> ans(k);
        if (n == 1) {
            ans[0].push_back(1);
            ans[1].push_back(1);
        } else {
            int num=1;
            for (int i = 0; i < k-1; ++i) {
                for (int j = i+1; j < k; ++j) {
                    ans[i].push_back(num);
                    ans[j].push_back(num);
                    num++;
                }
            }
        }
        for (int i = 0; i < k; ++i) {
            cout << k-1<<" ";
            for (int j = 0; j < k - 1; ++j) {
                cout <<ans[i][j]<<" ";
            }
            cout <<endl;
        }
    }
}


Measured memory_bytes: 4300
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=1000005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

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


    string s,t;
    cin >> s >> t;
    ll n=t.length();
    string ans="";
    rep(i,0,n-1) ans+=t[i];
    if(ans==s) ret("Yes");
    ret("No"); 
}

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

const long int INF = 1000000*100+100;

int main(){

    while(1){

      int n,k,order,a,b,c,d,e;

      cin >> n >> k;

      if(n==0&&k==0){
        break;
      }

      long int table[n][n];

      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          if(i==j){
            table[i][j] = 0;
          }
          else{
            table[i][j] = INF;
          }
        }
      }


      for(int i=0;i<k;i++){
        cin >> order;

        if(order==0){
          cin >> a >> b;
          if(table[a-1][b-1]==INF){
            cout << -1 << endl;
          }
          else{
            cout << table[a-1][b-1] << endl;
          }
        }
        else{
          cin >> c >> d >> e;
          if(table[c-1][d-1] > e){
              table[c-1][d-1] = e;
          }
          if(table[d-1][c-1] > e){
            table[d-1][c-1] = e;
          }
          for(int r=0;r<n;r++){
            for(int ii=0;ii<n;ii++){
              for(int j=0;j<n;j++){
                if(table[ii][j] > table[ii][r] + table[r][j]){
                  table[ii][j] = table[ii][r] + table[r][j];
                }
              }
            }
          }
          /*for(int i=0;i<n+1;i++){
            for(int j=0;j<n+1;j++){
              cout << table[i][j] << " ";
            }
            cout << endl;
          }*/
        }
      }


    }
    return 0;
}

Measured memory_bytes: 3132
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial, gcd
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
import sys  # def input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(10**6)

class SegTree:  # 0-index !!!
    """
    fx: モノイドXでの二項演算
    ex: モノイドXでの単位元
    init(seq, fx, ex): 配列seqで初期化 O(N)
    update(i, x): i番目の値をxに更新 O(logN)
    query(l, r): 区間[l,r)をfxしたものを返す O(logN)
    get(i): i番目の値を返す
    show(): 配列を返す
    """

    def __init__(self, seq, fx, ex):
        self.n = len(seq)
        self.fx = fx
        self.ex = ex
        self.size = 1<<(self.n - 1).bit_length()
        self.tree = [ex] * (self.size * 2)
        # build
        for i, x in enumerate(seq, start=self.size):
            self.tree[i] = x
        for i in reversed(range(1, self.size)):
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def set(self, i, x):  # O(log(n))
        i += self.size
        self.tree[i] = x
        while i:
            i >>= 1
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, i, x):
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def query(self, l, r):  # l = r の場合はたぶんバグるので注意
        tmp_l = self.ex
        tmp_r = self.ex
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                tmp_l = self.fx(tmp_l, self.tree[l])
                l += 1
            if r & 1:
                tmp_r = self.fx(self.tree[r - 1], tmp_r)  # 交換法則を仮定しない(順序大事に)
            l >>= 1
            r >>= 1
        return self.fx(tmp_l, tmp_r)

    def get(self, i):
        return self.tree[self.size + i]

    def show(self):
        return self.tree[self.size: self.size + self.n]

# ---------------------- #

def func(x, y):
    return x | y

n = int(input())
s = input()
q = int(input())
queries = [input().split() for _ in range(q)]

A = [set(x) for x in s]
seg = SegTree(A, fx=func, ex=set())

for t, *arg in queries:
    if t == "1":
        i, c = arg
        i = int(i) - 1
        seg.update(i, set(c))
    else:
        l, r = (int(x) - 1 for x in arg)
        ans = seg.query(l, r + 1)
        print(len(ans))


Measured memory_bytes: 374056
#include <bits/stdc++.h>
    using namespace std;
     
    const long long MOD = 1e9 + 7;
     
    int n, x;
    stack<int> s;
     
    int main() {
     
        scanf("%d", &n);
        
        long long ans = 1;
        for (int i = 0; i < n; i++) {
            scanf("%d", &x);
     
            s.push(x);
     
            if (x < 2 * s.size() - 1) {
                ans = (ans * s.size()) % MOD;
     
                s.pop();
            }
        }
     
        while (!s.empty()) {
            ans = (ans * s.size()) % MOD;
            s.pop();
        }
     
        printf("%lld\n", ans);
     
        return 0;
    }

Measured memory_bytes: 640
{-# LANGUAGE BangPatterns        #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE MultiWayIf          #-}
{-# LANGUAGE RankNTypes          #-}
{-# LANGUAGE ScopedTypeVariables #-}
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State
import           Control.Monad.Trans.State
import           Data.Array.IArray
import           Data.Array.ST
import           Data.Array.Unboxed
import           Data.Bits
import qualified Data.ByteString.Char8        as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Proxy
import           Data.Sequence                (Seq ((:<|), (:|>)), ViewL ((:<)),
                                               ViewR ((:>)), viewl, viewr, (<|),
                                               (><), (|>))
import qualified Data.Sequence                as Seq
import qualified Data.Set                     as S
import           Data.STRef
import qualified Data.Vector                  as V
import qualified Data.Vector.Mutable          as VM
import qualified Data.Vector.Unboxing         as VU
import qualified Data.Vector.Unboxing.Mutable as VUM
import           Numeric

main :: IO ()
main = do
  [a,b,c,d] <- readLnAsListWith unconsInteger
  print $ maximum [a*c,a*d,b*c,b*d]




-- converter
unconsChar :: StateT BS.ByteString Maybe Char
unconsChar = StateT BS.uncons

unconsInt :: StateT BS.ByteString Maybe Int
unconsInt = StateT $ BS.readInt . BS.dropWhile isSpace

unconsInteger :: StateT BS.ByteString Maybe Integer
unconsInteger = StateT $ BS.readInteger . BS.dropWhile isSpace

-- 1D Data
-- for list
readLnAsListWith :: StateT BS.ByteString Maybe a -> IO [a]
readLnAsListWith !st = unfoldr (runStateT st) <$> BS.getLine

-- for array (boxed or unboxed)
readLnAsArrayWith :: IArray a e => StateT BS.ByteString Maybe e -> Int -> IO (a Int e)
readLnAsArrayWith !st !n = listArray (1,n) <$> readLnAsListWith st

-- for boxed vector
readLnAsVecWith :: StateT BS.ByteString Maybe a -> Int -> IO (V.Vector a)
readLnAsVecWith !st !n = V.unfoldrN n (runStateT st) <$> BS.getLine

-- for unboxed vector
readLnAsUVecWith :: VU.Unboxable a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector a)
readLnAsUVecWith !st !n = VU.unfoldrN n (runStateT st) <$> BS.getLine

-- example: 1D tuple vector
readLnAsUVecWith2Tuple :: VU.Unboxable a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector (a,a))
readLnAsUVecWith2Tuple !st !n = VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1)) <$> readLnAsUVecWith st 2


-- 2D Data
-- n: number of lines
-- m: number of values per a line

-- for boxed vector
readLnAs2DVecWith :: StateT BS.ByteString Maybe a -> Int -> Int -> IO (V.Vector a)
readLnAs2DVecWith !st !n !m = V.unfoldrN (n * m) (runStateT st) . BS.concat <$> replicateM n BS.getLine

readLnAs2DUVecWith :: VU.Unboxable a => StateT BS.ByteString Maybe a -> Int -> Int -> IO (VU.Vector a)
readLnAs2DUVecWith !st !n !m = VU.unfoldrN (n * m) (runStateT st) . BS.concat <$> replicateM n BS.getLine


Measured memory_bytes: 3808
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  n = sc.nextInt();
     int k = sc.nextInt();
     int[] alpha = new int[n];
     int i,j;
     for(i=0;i<n;i++){
       alpha[i]= sc.nextInt();
     }
     int flag;
     for (j = 1; j < alpha.length; j++) {
            int key = alpha[j];
            i = j - 1;
            while (i >= 0 && alpha[i] > key) {
                alpha[i + 1] = alpha[i];
                i--;
            }
            alpha[i + 1] = key;
        }
      int ans=0;
      for(j = 0;j<k;j++){
       ans += alpha[j];
      }
     System.out.println(ans);
 
   }
   
}

Measured memory_bytes: 38620
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
  string s;
  cin>>s;
  if(s[0]=='R' && s[1]=='R' && s[2]=='R')
  	cout<<3<<endl;
  else if((s[0]=='R' && s[1]=='R' )||(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() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast
  int T=1;
  // cin >> T;
  while (T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3616
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var v []int
var n int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	v = make([]int, n)
	m1 := make(map[int]int)
	m2 := make(map[int]int)

	for i := 0; i < n; i++ {
		v[i] = nextInt()
		if i%2 == 0 {
			m1[v[i]]++
		} else {
			m2[v[i]]++
		}
	}

	if len(m1) == 1 && len(m2) == 1 {
		flag := true

		for i := 0; i < n-1; i++ {
			if v[i] != v[i+1] {
				flag = false
				break
			}
		}

		if flag {
			fmt.Println(n / 2)
			return
		}
	}

	// fmt.Println(m1)
	// fmt.Println(m2)

	em := -1
	ek := 0
	for k, v := range m1 {
		if em < v {
			em = v
			ek = k
		}
	}

	om := -1
	for k, v := range m2 {
		if om < v && ek != k {
			om = v
		}
	}
	ans1 := n - em - om

	om = -1
	ok := -1
	for k, v := range m2 {
		if om < v {
			om = v
			ok = k
		}
	}

	em = -1
	for k, v := range m1 {
		if em < v && ok != k {
			em = v
		}
	}

	ans2 := n - em - om

	fmt.Println(min(ans1, ans2))
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}


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

int main( void )
{
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    if ( ( a == b && b == c ) || ( b == c && c == d ) )
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
#define case(i) "Case #" << i << ": "

template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    ll n;
    cin >> n;

    ll mx = n - 1;

    for(ll i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ll j = n / i;

            mx = min(i - 1 + j - 1, mx);
        }
    }
    cout << mx << endl;
}

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

int main() {
	long long int a, b, x;
	cin >> a >> b >> x;

	long long int ans = b / x;
	long long int exclusion = a / x;
	ans -= exclusion;
	
	if (a % x == 0) {
		ans++;
	}

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

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

int main(){
  char s;
  cin >> s;
  if ( s == 'A') cout << "T" << endl;
  if ( s == 'T') cout << "A" << endl;
  if ( s == 'C') cout << "G" << endl;
  if ( s == 'G') cout << "C" << endl;
    

}


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

int main() {
  int n;
  cin >> n;
  
  int per_sum;
  for (int i=0; i<n; i++) {
    int l, r;
    cin >> l >> r;
    per_sum += r-l+1;
  }
  
  cout << per_sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n<1) return;
			n=n<2?2:n;
			int s = 1;
			for(int i=2;i*i<=n;i++){
				if(n%i==0){
					s+=i+n/i;
				}
				if(i*i==n){
					s-=i;
				}
			}
			System.out.println(n==s?"perfect number":n>s?"deficient number":"abundant number");
		}
	}
}

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

int main() {
  string s;
  cin>>s;
  int c=0;
  for(int i=1;i<s.size()/2;i++) if(s.substr(0,i)==s.substr(i,i)) c=2*i;
  cout<<c;
}


Measured memory_bytes: 3616
import java.util.*;
import java.util.stream.Collectors;

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

        int x = -1;
        int y = -1;
        int z = -1;

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j + i <= n; j++) {
                int k = n - i - j;
                if (i * 10000 + j * 5000 + k * 1000 == otoshidama) {
                    x = i;
                    y = j;
                    z = k;
                    break;
                }
            }
        }
        System.out.println(x + " " + y + " " + z);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, t;
        in >> n;
        t = n;
        ll sum = 0;
        while (t) {
            sum += t % 10;
            t /= 10;
        }
        out << (n%sum == 0 ? "Yes" : "No") << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll mod = 1e9 + 7;
ll dp[2005]; 
vll divs;
ll binpow(ll a, ll b){
	if (b == 0) return 1;
	ll x = binpow(a, b / 2);
	x *= x; x %= mod;
	if (b % 2) return (x * a) % mod;
	else return x;
}
int main(){
	ll n, k; cin >> n >> k;
	for (ll i = 1; i <= sqrt(n); i++){
		if (i == sqrt(n)){
			if (i * i == n) divs.pb(i);
		}
		else if (n % i == 0){
			divs.pb(i); divs.pb(n / i);
		}
	}
	sort(divs.begin(), divs.end());
	for (ll i = 0; i < divs.size(); i++){
		dp[i] = binpow(k, (divs[i] + 1) / 2);
		for (ll j = 0; j < i; j++){
			if (divs[i] % divs[j] == 0) (dp[i] += (mod - dp[j])) %= mod;
		}
 	}
 	ll ans = 0;
 	for (ll i = 0; i < divs.size(); i++){
 		if (divs[i] % 2) (ans += (divs[i] * dp[i])) %= mod;
 		else (ans += (divs[i] / 2 * dp[i])) %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3728
x1,y1,x2,y2,n,*a=`dd`.split.map &:to_i
xf=yf=1
x1>x2&&(x1,x2,xf=x2,x1,-1)
y1>y2&&(y1,y2,yf=y2,y1,-1)
v=a.each_slice(2).select{|x,y|x1<=x&&x<=x2&&y1<=y&&y<=y2}.map{|x,y|[x*xf,y*yf]}.sort
D=[F=1e9]*s=v.size
v.each{|x,y|D[D.bsearch_index{|e|e>=y}]=y}
n=D.bsearch_index{|e|e>=F}||s
p 1e2*(x2-x1+y2-y1)-20*n+5*(n+(n>[x2-x1,y2-y1].min ? 1:0))*Math::PI

Measured memory_bytes: 40972
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] a = new int[N];
	for(int i = 0; i < N;i++){
	    a[i] = sc.nextInt() - (i + 1);
	}

	Arrays.sort(a);

	int median = a[N / 2];

	long sum = 0;
	for(int i = 0; i < N; i++){
	    sum += Math.abs(a[i] - median);
	}
	System.out.println(sum);
    }
}


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

int main(){

  int x,y,n,k;

  cin >> n >> k >> x >> y;

  if(n <= k) printf("%d\n", n*x);

  else {
    printf("%d\n", k*x + (n - k)*y);
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        int i = 1;
        int n = 0;
        Scanner sc = new Scanner(System.in);
        while(true){
            n = sc.nextInt();
            if(n != 0){
                System.out.println("Case " + i + ": " + n);
                i++;
            }
            else {
                break;
            }
        }
    }

}



Measured memory_bytes: 42144
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

int main(){
    ll n;
    cin>>n;
    ll a[n+1],b[n];
    rep(i,0,n+1)cin>>a[i];
    rep(i,0,n)cin>>b[i];
    ll ans=0;
    rep(i,0,n){
        if(a[i]>=b[i]) {ans+=b[i];a[i]-=b[i];b[i]=0;}
		else {ans+=a[i];b[i]-=a[i];a[i]=0;}

		if(a[i+1]>=b[i]) {ans+=b[i];a[i+1]-=b[i];b[i]=0;}
		else {ans+=a[i+1];b[i]-=a[i+1];a[i+1]=0;}
    }
    cout<<ans;
}

Measured memory_bytes: 1792
#ALDS1_6_B パーティション
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp

#入力
#入力の最初の行に、数列Aの長さを表す整数nが与えられます
#二行目にn個の整数Aiが空白区切りで与えられます

#出力
#分割された数列を一行に出力してください。.
#数列の連続する要素は１つの空白で区切って出力してください。また、partition の基準となる要素を [   ]で示してください。

##p~iには基準A[r]より小さい要素
##i+1~jには基準A[r]より大きい要素
##が入るようにA内を入れ替えていく


def partition(a, p ,r)
  #xが基準値(配列の最後のもの)
  x = a[r]
  #敷居のindex-1
  i = p-1
  #敷居のindex
  j = p

  while (j < r) do
    if (a[j] <= x)
      i = i + 1
      t = a[i]
      a[i] = a[j]
      a[j] = t
    end
    j = j + 1
  end
  t = a[i+1]
  a[i+1] = a[r]
  a[r] = t
  return a,i+1
end
n = gets.to_i
a = gets.split(" ").map(&:to_i)

# p a
# 13
# patition(a,0,12)

a,x_index = partition(a,0,n-1)

a.each_with_index do |char,i|
  if (i!=0)
    print(" ")
  end
  if (i == x_index)
    print("[")
  end
  print(a[i])
  if (i == x_index)
    print("]")
  end
end
print("\n")
















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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<float> v = vector<float>();
    for (int i = 0; i < n; i++) {
        float vv;
        cin >> vv;
        v.push_back(vv);
    }
    sort(v.begin(), v.end(), greater<>());
    while (v.size() > 1) {
        float v1 = v.back();
        v.pop_back();
        float v2 = v.back();
        v.pop_back();
        float vv = (v1 + v2) / 2;
        v.push_back(vv);
        sort(v.begin(), v.end(), greater<>());
    }
    float vv = v.back();
    cout << vv << endl;

    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  for (int i = 0; i < n - m + 1; i++)
  for (int j = 0; j < n - m + 1; j++) {
    int f = 1;
    for (int k = 0; k < m; k++)
    for (int l = 0; l < m; l++) {
      if (b[k][l] != a[i + k][j + l]) {
        f = 0;
        break;
      }
    }
    if (f) {
      cout << "Yes" << '\n';
      return;
    }
  }
  cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		//int input=32;
		BufferedReader input_a =
				new BufferedReader (new InputStreamReader (System.in));
		int input;
		String str;
		while((str=input_a.readLine())!=null){
			//String str=input_a.readLine();
			input=Integer.parseInt(str);
			//System.out.println(">"+str+">"+input);
			System.out.println(weight(input));
		}
		
		//int input = Integer.parseInt(input_a.readLine());
		//System.out.println("Input:"+input);
		//System.out.print("Output:");	
	}
	public static String weight(int num){		//num=蛟、縲〔=菫よ焚
		int number=num;
		String sub="";		//途中経過
		String result="";	//結果
		int k=0;
		
		while(number>1){
			//int ans=number%2;
			//System.out.println("number="+number);
			int ans=(number%2);
			sub=ans+","+sub;
			number=number/2;
			k++;
		}
		sub=number+","+sub;
		//System.out.println("sub:"+sub);
		String[] div_sub=sub.split(",");
		for(int i=0;i<div_sub.length;i++){
			int x=(int)Math.pow((double)2,(double)(k-i));
			int ans=x*Integer.parseInt(div_sub[i]);
			//System.out.println("ans("+(k-i)+","+x+")="+ans);
			if(ans!=0){
				if(!result.equals(""))result=ans+" "+result;
				//if(!result.equals(""))result=ans+","+result;
				else result=""+ans;	
			}
		}
		return result;
	}
}

Measured memory_bytes: 9768
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c;
  d = a+b+c;
  if (d>=22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n,k;

vvi a(10);

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int c,t;
		cin>>c>>t;
		a[t-1].push_back(c);
	}
	for(int i=0;i<10;i++) sort(a[i].rbegin(),a[i].rend());
	vvi dp(1<<10,vi(k+1));
	int ind=0;
	for(int i=1;i<1<<10;i<<=1){
		int num=min((int)a[ind].size(),k);
		for(int j=1;j<=num;j++) dp[i][j]+=dp[i][j-1]+a[ind][j-1];
		for(int j=1;j<=num;j++) dp[i][j]+=j*(j-1);
		ind++;
	}
	for(int i=1;i<1<<10;i++) for(int j=0;j<=k;j++){
		int S=(i-1)&i,T=S^i,I=0;
		while(!(T>>I&1)) I++;
		for(int k=0;k<=min((int)a[I].size(),j);k++) dp[i][j]=max(dp[i][j],dp[T][k]+dp[S][j-k]);
	}
	cout<<dp[(1<<10)-1][k]<<endl;
}

Measured memory_bytes: 10520
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <array>
#include <cinttypes>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    char A[200001];

    if (scanf("%s", A) < 1) return 0;

    int64_t len = strlen(A);

    array<int64_t, 26> ary;
    ary.fill(0);

    for (int64_t i = 0; i < len; i++) ary[A[i] - 'a']++;

    int64_t t = 0;
    for (int i = 0; i < 26; i++) t += ary[i] * (ary[i] - 1) / 2;

    int64_t ans = len * (len - 1) / 2 - t + 1;

    printf("%" PRId64 "\n", ans);
    return 0;
}


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

int main()
{
    int m, n, o, i, j;
    
    cin >> m;
    cin >> n;
    cin >> o;
    
    if (m>o){
        cout << "0";
    }
    else {
        cout << o/m*n;
    }
    return 0;
}

Measured memory_bytes: 256
import itertools
from collections import defaultdict

N ,K = map(int, input().split())
A = list(map(int, input().split()))

A = [0] + [x-1 for x in A]

Acum = list(itertools.accumulate(A))
Acum = [x % K for x in Acum]

counter = defaultdict(int)
answer = 0
for i,x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-K+1]] -= 1

print(answer)

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vvi T(N);
    vi C(N);
    REP(i, 0, N-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    REP(i, 0, N) cin >> C[i];
    sort(C.rbegin(), C.rend());
    int leaf = 0, count = 0;

    vi ans(N, 0);
    queue<int> que;
    
    while(T[leaf].size() != 1) leaf++;
    que.push(leaf); ans[leaf] = C[count];
    count++;
    while(!que.empty()){
       auto cur = que.front(); que.pop();
       for(int next: T[cur]){
           if(ans[next] == 0){
               que.push(next);
               ans[next] = C[count];
               count++;
           }
        }
    }
    cout << accumulate(C.begin()+1, C.end(), 0) << endl;
    REP(i, 0, N) cout << ans[i] << " ";
    cout << endl;
}

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

int32_t main() {

	int n, k; cin >> n >> k;

	int arr[n + 1];

	for(int i = 1; i <= n; i++)
		scanf("%d" , &arr[i]);

	for(int i = k + 1; i <= n; i ++) {

		if(arr[i] > arr[i - k])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n);
    map<int32,int32> mp;
    mp[-1] = 3;
    int64 ans = 1;
    REP(i,n){
        cin >> a[i];
        ans *= mp[a[i] - 1];
        ans %= MOD;
        mp[a[i]-1] = max<int64>(0, mp[a[i]-1] - 1);
        mp[a[i]]++;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
vector<ll>v[26];
string s,t;
int main() {
	// your code goes here
	ll i,j,k,n,m;
	cin>>s>>t;
    for(i=1;s[i-1];i++) v[s[i-1]-97].push_back(i);
    ll ans=0,pre=0;
    for(i=0;i<t.size();){
        ll ci=i;
        pre=0;
        while(i<t.size()){
            ll cv=t[i]-97;
            ll lo=0,hi=v[cv].size()-1,id=-1;
            while(lo<=hi){
                ll mi=(lo+hi)/2;
                if(v[cv][mi]>pre) id=v[cv][mi],hi=mi-1;
                else lo=mi+1;
            }
            if(id==-1) break;
            else {
                i+=1;
                pre=id;
            }
        }
        if(ci==i) {
            ans=-1;
            break;
        }
        else {
          if(i==t.size()) ans+=pre;
          else ans+=s.size();
        }
        
        
    }
    cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 1724
N,M,X = gets.chomp.split.map(&:to_i)
A = Array.new(N+1,0)
toll = gets.chomp.split.map(&:to_i)
M.times do |m|
	A[toll[m]] += 1
end

p [A[0..X].inject(:+),A[X..N].inject(:+)].min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
// #define ull unsigned long long int
#define ll long long 
#define int ll
#define ppi pair<int, int>
#define ppl pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ff first
#define lb lower_bound
#define ub upper_bound
#define ss second
#define inf 1e9
#define enld '\n'
#define cuot cout
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
#define trace(v)                                                               \
  for (auto it = v.begin(); it != v.end(); it++)                               \
    cerr << *it << " ";                                                        \
  cerr << endl;
#define linf 1e18
#define reset(x) memset(x, 0, sizeof(x))
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    oset;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

void solve()
{
    int n;cin>>n;
    int a[n+1];
    rep(i,1,n+1)cin>>a[i];
    int dp[n+1];
    a[0]=inf;
    dp[0]=0;
    dp[1]=0;
    rep(i,2,n+1){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n];
}

signed main() {
  fastio();
  int t;
  t = 1;
  // cin >> t;
  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";
    solve();
  }
  return 0;
}

Measured memory_bytes: 1792
package main

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

//const (
//	MaxIntValue = int(^uint(0) >> 1)
//)

func main() {
	S := readLine()

	if S[2] == S[3] && S[4] == S[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/////////////////////////////////////////
var scanner = bufio.NewScanner(os.Stdin)

func init() {
	//scanner.Split(bufio.ScanWords)
}
func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
    long long int n[10000];
    long long int i,j,max,min,sum;
    scanf("%lld",&i);
    for(j=0;j<i;j++){
        scanf("%lld",&n[j]);
    }
    max=n[0]; 
    min=n[0];
    sum=0;
    for(j=0;j<i;j++){
        if(max<n[j]){
            max=n[j];
        }      
        if(min>n[j]){
            min=n[j];
            }
        sum+=n[j];
    }
    printf("%lld %lld %lld\n",min,max,sum);
    return 0;
}




Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 900005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll ar[N][2],dp[101][N];
int main(){

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

	ll i,j,k,n,l,W;
	cin>>n>>W;
	for(i=1;i<=n;i++){
		cin>>ar[i][0]>>ar[i][1];
	}

	for(i=0;i<=n;i++){
		for(j=0;j<N;j++){
			dp[i][j]=1e18;
		}
	}

	dp[0][0]=0;
	for(i=1;i<=n;i++){
		for(j=0;j<=100000;j++){
			if(j<ar[i][1]){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-ar[i][1]]+ar[i][0]);
			}
		}
	}

	ll an=100000;
	while(dp[n][an]>W){
		an--;
	}
	cout<<an;
	return 0;
}

Measured memory_bytes: 710912
#include<stdio.h>
int main(){while(1){short n,s;scanf("%d %d",&n,&s);if(n==0)return 0;short ans=0;short i,j;short sum;short time;for(i=0;i<1<<10;i++){sum=0;time=0;for(j=0;j<10;j++)if(i>>j&1){sum+=j;time++;}if(sum==s&&time==n)ans++;}printf("%d\n",ans);}}

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

int main(){
    string str;
    cin >> str;
    int N = str.length();
    char c[N];
    str.copy(c, N);
    int w;
    cin >> w;
     for (int i=0; i<N;){
         cout << c[i];
         i += w;
     }
     cout << endl;
     return 0;
}

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

using namespace std;

const int MAX_N = 1e5 + 200;

typedef long long ll;

int n, m, head[MAX_N], current, ai[MAX_N], bi[MAX_N], ci[MAX_N], id[MAX_N], rk[MAX_N], mem[MAX_N];
ll dp[MAX_N], tot[MAX_N];
vector<int> G[MAX_N];

struct edge
{
    int to, nxt;
} edges[MAX_N << 1];

void addpath(int src, int dst)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    head[src] = current++;
}

int find(int x) { return mem[x] == x ? x : mem[x] = find(mem[x]); }

void dfs(int u, int fa)
{
    tot[u] = bi[u];
    for (auto son : G[u])
        dfs(son, u), tot[u] += tot[son];
}

void calc(int u, int fa)
{
    if (G[u].empty())
        return (void)(dp[u] = bi[u] + ci[u]);
    dp[u] = 1e18;
    for (auto v : G[u])
        calc(v, u), dp[u] = min(dp[u], tot[u] - tot[v] + max(1LL * ci[u], dp[v]));
}

int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &ai[i], &bi[i]), ci[i] = max(ai[i] - bi[i], 0), id[i] = i, mem[i] = i;
    sort(id + 1, id + 1 + n, [](const int &rhs1, const int &rhs2) { return ci[rhs1] < ci[rhs2]; });
    for (int i = 1; i <= n; i++)
        rk[id[i]] = i;
    for (int i = 1, u, v; i <= m; i++)
        scanf("%d%d", &u, &v), addpath(u, v), addpath(v, u);
    for (int idx = 1; idx <= n; idx++)
    {
        int u = id[idx];
        for (int i = head[u]; i != -1; i = edges[i].nxt)
            if (u != find(edges[i].to) && rk[u] > rk[find(edges[i].to)])
                G[u].push_back(find(edges[i].to)), mem[find(edges[i].to)] = u;
    }
    dfs(id[n], 0), calc(id[n], 0), printf("%lld\n", dp[id[n]]);
    return 0;
}

Measured memory_bytes: 14080