akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int MOD = 1000000007;
const int maxN = 1000005;
#define PI 3.1415926535897932384626

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m ;
	int a[m];
	int sum = 0;
	for (int i = 0; i < m; i++) {
		cin >> a[i] ;
		sum += a[i];
	}
	int ans = n - sum;
	if (ans < 0) cout << -1  << "\n";
	else cout << ans << "\n";
	return 0;
}



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

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

	int N, T, A[100000];
	cin >> N >> T;
	REP(i, N, 0) cin >> A[i];
	int tmp1 = 0, tmp2 = -1, res = 0;
	REP(i, N, 1) {
		tmp1 = max(tmp1, A[N-i]);
		if (tmp1 - A[N-i-1] == tmp2) {
			res++;
		} else if (tmp1 - A[N-i-1] > tmp2) {
			res = 1;
			tmp2 = tmp1 - A[N-i-1];
		}
	}
	cout << res << endl;
	return 0;
}

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

int main(){

	vector<long int> a;
	int q;
	cin >> q;
	int querynum = 0;
	while (querynum < q) {
		int var1, var2;
		cin >> var1;
		if (var1 == 0) {
			cin >> var2;
			a.push_back(var2);
		}
		else if (var1 == 1) {
			cin >> var2;
			cout << a[var2] << endl;
		}
		else {
			a.pop_back();
		}
		querynum++;
	}

	return 0;
}


Measured memory_bytes: 4880
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int MOD{1000000007};
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};

class Graph
{
private:
    int _n;
    vector<vector<int>> _to;

public:
    Graph(int n);
    ~Graph();
    void connect(int a, int b);
    int searchDepth(int start);
    int answer()
    {
        int ans = -1;
        for (int i = 0; i < _n; i++)
        {
            chmax(ans, searchDepth(i)+1);
        }
        return ans;
    }
};

Graph::Graph(int n)
{
    _n = n;
    _to.resize(_n);
}

Graph::~Graph()
{
}

void Graph::connect(int a, int b)
{
    _to[a].push_back(b);
    _to[b].push_back(a);
}

int Graph::searchDepth(int start)
{
    vector<int> dist(_n, -1);
    queue<int> que;

    dist[start] = 0;
    que.push(start);

    int depth = -MOD;

    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (int nv : _to[v])
        {
            if (dist[nv] != -1)
            {
                if (dist[nv] == dist[v] + 1 || dist[nv] == dist[v] - 1)
                    continue;
                else
                    return -MOD;
            }

            dist[nv] = dist[v] + 1;
            chmax(depth, dist[nv]);
            que.push(nv);
        }
    }
    return depth;
}

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

    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];

    Graph g(n);

    for (int i = 0; i < n; i++)
        for (int j = i; j < n; j++)
            if (s[i][j] == '1')
                g.connect(i, j);

    cout << g.answer() << endl;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		String week[] = {"sat","sun","mon","tue","wed","thu","fri"};
		x = x-9;
		if(x > 0) {
			int a = x%7;
			System.out.println(week[a]);
		}else {
			int a = (x+14)%7;
			System.out.println(week[a]);
		}
	}
}



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

using namespace std;

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

int main() {
    int N;
    cin >> N;
    auto A = Vec<int>(N, 0);
    for (auto& a : A) cin >> a;

    // 答えが1 <=> Aが狭義単調増加
    bool incr = true;
    for (int i = 0; i < N - 1; ++i) {
        if (A[i] >= A[i + 1]) incr = false;
    }
    if (incr) {
        cout << 1 << endl;
        return 0;
    }

    int ok = N, ng = 1;
    while (ok - ng > 1) {
        int K = (ok + ng) / 2;

        vector<pair<int, int>> word;
        int L = 0;
        for (auto a : A) {
            if (L >= a) {
                while (!word.empty() && word.back().first > a) word.pop_back();
                word.push_back(make_pair(a + 1, K));
            }
            L = a;

            // 繰り上がり処理
            while (!word.empty() && word.back().second == K) {
                int l = word.back().first;
                word.pop_back();
                if (!word.empty() && word.back().first == l - 1) {
                    ++word.back().second;
                } else {
                    word.push_back(make_pair(l - 1, 1));
                }
            }
        }

        if (word.front().first > 0) {
            ok = K;
        } else {
            ng = K;
        }
    }

    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >> N;
    string S,T;
    cin >> S>>T;
    ll len = -1;
    rep(i,N){
        if(S.substr(N - i - 1,i + 1) == T.substr(0,i + 1)){
            len = i;
        }
    }
    cout << N * 2 - len - 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<long long,long long int> mp;
long long mulmod(long long a,long long b,long long c){
        long long x = 0,y=a%c;
        while(b > 0) {
                if(b%2 == 1) {
                        x = (x+y)%c;
                }
                y = (y*2)%c;
                b /= 2;
        }
        return x%c;
}
long long int modulo_exp(long long int a,long long int b,long long int c)
{
        long long x=1,y=a;
        while(b > 0) {
                if(b%2 == 1) {
                        x = mulmod(x,y,c);
                }
                y = mulmod(y,y,c);
                b /= 2;
        }
        return x%c;
}
bool Miller(long long p,int iteration){
        if(p<2) {
                return false;
        }
        if(p!=2 && p%2==0) {
                return false;
        }
        long long s=p-1;
        while(s%2==0) {
                s/=2;
        }
        for(int i=0; i<iteration; i++) {
                long long a=rand()%(p-1)+1,temp=s;
                long long mod=modulo_exp(a,temp,p);
                while(temp!=p-1 && mod!=1 && mod!=p-1) {
                        mod=mulmod(mod,mod,p);
                        temp *= 2;
                }
                if(mod!=p-1 && temp%2==0) {
                        return false;
                }
        }
        return true;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        long long n,p;
        cin>>n>>p;
        vector< long long > div;
        for(long long i=2; i*i<=p; i++)
        {
                if((p%i)==0)
                {
                        if(i!=(p/i))
                        {
                                div.push_back(i);
                                div.push_back((p/i));
                        }
                        else
                        {
                                div.push_back(i);
                        }
                }
        }
        for(int i=0; i<div.size(); i++)
        {
                if(Miller(div[i],18))
                {
                        long long d=div[i],nn=p;
                        while(nn%d==0)
                        {
                                mp[d]++;
                                nn=nn/d;
                        }
                }
        }
        long long pp=1;
        for(auto it=mp.begin(); it!=mp.end(); it++)
        {
                if( (it->second)>=n )
                {
                        long long int cc=(it->second)/n;
                        while(cc--)
                        {
                                pp=pp*(long long)(it->first);
                        }
                }
        }
        cout<<pp<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	int N, M, X;
	int A[109];
	cin >> N >> M >> X;
	int su1 = 0, su2 = 0;
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}
	sort(A, A + M);
	int i = 0;
	int s1 = 0, s2 = 0;
	while (A[i] < X) {
		s1++;
		i++;
	}
	if (A[i] == X)i++;
	while (A[i] < N&&i<M) {
		s2++;
		i++;
	}
	cout << min(s1, s2);
}

Measured memory_bytes: 256
import numpy as np

n, k = map(int, input().split())
z = np.zeros(10**5 + 1, dtype = np.int64)
for i in range(n):
  a, b = map(int, input().split())
  z[a] += b

a = 0
for i in range(1, 10**5 + 1):
  if k <= z[i]:
    a = i
    break
  k -= z[i]

print(a)


Measured memory_bytes: 15188
N = int(input())
A = list(map(int, input().split()))

def func(N, A):
    ans = 0
    while True:
        for i in range(N):
            if A[i]%2 == 0:
                A[i] /= 2
            else:
                return ans
        ans += 1
    return ans

print(func(N,A))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char x;
    cin>>x;
    if(x=='a'||x=='e'||x=='i'||x=='o'||x=='u')
    {
    cout<<"vowel"<<endl;
	}
    else 
    {
    cout<<"consonant"<<endl;
	}
    return 0;
} 

Measured memory_bytes: 256
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  string N;
  sc.scan(N);
  char[] n = new char[3];

  foreach (i; 0 .. 3)
    n[i] = to!char(N[i]);

  foreach (i; 0 .. 3) {
    if (n[i] == '1')
      n[i] = '9';
    else
      n[i] = '1';
  }

  writeln(n);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

const ll MOD = 1e9 + 7;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __ll128

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}

ll f[1000100];

bool get(ll x){
    if(x==1){
        if(f[1]>1) return true;
        else return false;
    }
    for(ll i=2;i*i<=x;i++){
        if(x%i==0){
            if(f[i]>0 || f[x/i]>0) return true;
        }
    }
    if(f[1]>0 || f[x]>1) return true;
    return false;
}

void __sol(){
    ll n; cin >> n;
    forr(i,1000010) f[i]=0;
     vector<ll> v(n);
  //  map<ll,ll> m;
    forr(i,n){
        ll k; cin >> k; f[k]++;
        v[i]=k;
    }
    ll ans=0;
    forr(i,n){
      //  f[v[i]]--;
        if(get(v[i])) ans++;
    }
    cout << n-ans;
    return;
}


int main(){
    fastio
    ll tc=1;// cin >> tc;
    while(tc--) __sol();
    return 0;
}


Measured memory_bytes: 12664
/* ITP1_5_D */
#include <stdio.h>

/* call??¢??° */
void call(short n)
{
	short i = 1;
	
	while( i <= n )
	{
		short x = i;
		
		// x / 3????????????0?????´???(3????????°)
		if( 0 == x % 3 )
		{
			printf(" %d", i);
			i++;
			continue;
		}

		// 3??????????????°??§??????????¢????
		do {
			// x / 10????????????3?????´???(3??????????????°?????´???)
			if ( 3 == x % 10 )
			{
				printf(" %d", i);
				break;
			}
			x /= 10;
		} while( x );
		
		i++;
	}
	printf("\n");
}

/* ???????????¢??° */
int main(void)
{
	// ??\????????????
	short input;
	scanf("%d", &input);
	
	// call??¢??°????????????
	call(input);
	
	return 0;
}

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

int main() {
  int N,Y;
  cin>>N>>Y;
  int x=-1,y=-1,z=-1;
  for(int i=0;i<=N;i++){
    for(int j=0;j+i<=N;j++){
      int k=N-i-j;
      int total=10000*i+5000*j+1000*k;
      if(total==Y){
        x=i;
        y=j;
        z=k;
      }
    }
  }
  cout<<x<<" "<<y<<" "<<z<<endl;
}

Measured memory_bytes: 3620
S=str(input())
a=0
b=0
c=0
for i in range(3):
  if(S[i]=='a'):
    a+=1
  elif(S[i]=='b'):
    b+=1
  else:
    c+=1

if(a==1 and b==1 and c==1):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
s = int(input())
def is_month(x):
  if x == 0 or x >= 13:
    return False
  else:
    return True
if is_month(s // 100):
  if is_month(s % 100):
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if is_month(s % 100):
    print('YYMM')
  else:
    print('NA')

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

int main() {
  string S;
  cin >> S;
  int price =700;

  if(S[0]=='o') price +=100;
  if(S[1]=='o') price +=100;
  if(S[2]=='o') price +=100;
cout << price << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

struct UnionFind{
  vector<int> par;

  UnionFind(int N): par(N){
    for(int i=0;i<N;i++) par[i]=i;
  }

  int root(int x){
    if(par[x]==x) return x;
    else return par[x]=root(par[x]);
  }

  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx!=ry) par[rx]=ry;
  }

  bool sameroot(int x,int y){
    return root(x)==root(y);
  }

};

int main(){
    int N,M; cin>>N>>M;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin>>p[i]; p[i]--;
    }

    UnionFind uf(N);

    int x,y;
    for (int i = 0; i < M; ++i) {
        cin>>x>>y; x--; y--;
        uf.unite(x,y);
    }
    int ans=0;
    for (int i = 0; i < N; ++i) {
        if(uf.sameroot(i,p[i])) ans++;
    }

    cout<<ans<<endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int x,a,b;
  cin>>x;
  cin>>a;
  cin>>b;
  
  cout<<x-a-(x-a)/b*b<<endl;
  
  return 0;
}


Measured memory_bytes: 384
n = int(input())
s = input()

ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n):
    for j in range(i,n-1):
        k = 2*j - i
        if k >= n:
            continue
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1


print(ans)


Measured memory_bytes: 9192
import itertools

def main():

    n,m,x = map(int,input().split())
    C = []
    A = []
    for i in range(n):
        array = list(map(int,input().split()))
        C.append(array[0])
        A.append(array[1:])
    cost = 10**10
    for i in range(1,n+1):
        combs = itertools.combinations(range(n), i)
        for comb in combs:
            skill = [0]*m
            cost_tmp = 0
            for e in comb:
                cost_tmp += C[e]
                for j in range(m):
                    skill[j] += A[e][j]
            for j in range(m):
                if skill[j] < x:
                    break
                if j == m-1:
                    cost = min(cost, cost_tmp)
    if cost == 10**10:
        print(-1)
        return
    print(cost)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68416
let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make_matrix (m + 1) (n + 1) 0 in
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <-
        if x.[i-1] = y.[j-1] then dp.(i-1).(j-1) + 1
        else
          let a = dp.(i-1).(j) in
          let b = dp.(i).(j-1) in
          if a > b then a else b;
    done
  done;
  dp.(m).(n)

let () =
  let q = read_int () in
  for _ = 0 to q - 1 do
    let x = read_line () in
    let y = read_line () in
    lcs x y |> print_int;
    print_newline ();
  done

Measured memory_bytes: 18328
#import <Foundation/Foundation.h>
#import <stdio.h>

int main(int argc, char **argv) {
  NSInteger N, X, Y;
  scanf("%ld %ld %ld", &N, &X, &Y);

  int count[N+1];
  NSInteger i = 0;
  NSInteger j = 0;

  for(i=0;i<=N;i++) {
    count[i] = 0;
  }
  
  for(i=1;i<N;i++) {
    for(j=i+1;j<=N;j++) {
      NSInteger d = j - i;
      d = MIN(d, abs(X - i) + 1 + abs(j - Y));
      count[d]++;
    }
  }
  for(i = 1; i < N; i++) {
    printf("%ld\n", count[i]);
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define md 1000000007
using namespace std;string s;int dp[10009][100][2],p,d;
int dfs(int n,int z,bool f){if(n==s.size())return!z;int&res(dp[n][z][f]);if(~res)return res;res=0;int x=s[n]-'0';int r=(f?x:9);for(int i=0;i<=r;++i){res+=dfs(n+1,(z+i)%d,f&&i==r);res%=md;}return res;}int main(){memset(dp,-1,sizeof(dp));cin>>s>>d;cout<<(dfs(0,0,1)-1+md)%md<<endl;}

Measured memory_bytes: 8832
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def D(x):
    cnt = 0
    while not x % 2:
        x //= 2
        cnt += 1
    return cnt


n = I()

ans = 0
for i in LI():
    ans += D(i)



print(ans)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,r[4010],g[4010],b[4010],ans=0;
string s;

int main()
{
	cin>>n>>s;
	for(int i=n-1;i>=0;i--)
	{
		r[i]=r[i+1]+(s[i]=='R');
		g[i]=g[i+1]+(s[i]=='G');
		b[i]=b[i+1]+(s[i]=='B');
	}
	rep(i,n)
	{
		for(int j=i;j<n;j++)
		{
			if(s[i]==s[j]) continue;
			int rr=0,gg=0,bb=0;
			if(s[i]=='R') rr++;
			if(s[i]=='G') gg++;
			if(s[i]=='B') bb++;
			if(s[j]=='R') rr++;
			if(s[j]=='G') gg++;
			if(s[j]=='B') bb++;
			if(rr==0) ans+=r[j]-(j+j-i<n ? s[j+j-i]=='R':0);
			if(gg==0) ans+=g[j]-(j+j-i<n ? s[j+j-i]=='G':0);
			if(bb==0) ans+=b[j]-(j+j-i<n ? s[j+j-i]=='B':0);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3688
# 高橋君の仲間たちは N 人で遊園地に遊びにいきました。 遊園地の一番人気のジェットコースターに乗るためには、身長が K cm以上必要です。
# 高橋君の i 番目の仲間の身長は h i cm です。 高橋君の仲間たちのうち、一番人気のジェットコースターに乗ることができる人の数を求めてください。

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

x = 0
for i in h:
    if i >= K:
        x += 1

print(x)

Measured memory_bytes: 18764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    for (int i = 0; i < 5; i++) {
        int x; std::cin >> x;
        if (x == 0) std::cout << i + 1 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for(ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

const ll INF = 100000000;
const ll MOD = 1000000007;

//UnionFind 
struct UnionFind
{
    std::vector<ll> uni;
    UnionFind(ll s) : uni(s, -1) {}

    //頂点aが所属するグループ
    ll root(ll a)
    {
        if (uni[a] < 0)
        {
            return a;
        }
        return uni[a] = root(uni[a]);
    }

    //a,bをつなげる
    bool connect(ll a, ll b)
    {
        a = root(a);
        b = root(b);
        if (a == b)
        {
            return false;
        }

        if (uni[a] > uni[b])
        {
            std::swap(a, b);
        }

        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    //a,bが同グループか確認
    bool isConnect(ll a, ll b)
    {
        return root(a) == root(b);
    }

    //aが属するグループの要素数
    ll size(ll a)
    {
        return -uni[root(a)];
    }
};

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //問題文中の添え字が0-indexか1-indexか確認!

    ll n,m;
    std::cin>>n>>m;
    std::vector<P> path(m);
    std::vector<ll> ans(m);
    rep(i,0,m){
        ll a,b;
        std::cin>>a>>b;
        a--;b--;
        path[i]=P(a,b);
    }
    std::reverse(all(path));
    UnionFind island(n);
    ans[0]=n*(n-1)/2;
    rep(i,0,m-1){
        ll a=path[i].first,b=path[i].second;
        if(!island.isConnect(a,b)){
            ans[i+1]=ans[i]-island.size(a)*island.size(b);
            island.connect(a,b);
        }else{
            ans[i + 1] = ans[i];
        }
    }
    std::reverse(all(ans));
    rep(i,0,m){
        std::cout<<ans[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

using namespace std;

typedef long long ll;

typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002
int dp[MAX_N]={};
bool d[MAX_N]={};
int pa[MAX_N];
vector<edge> G[MAX_N];
P1 cost[MAX_N]={};
vector<int> child[MAX_N];
vector<int> ra[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que;
ll a[100001]={};
ll k[100001]={};
int main() {
	int n;
	cin>>n;
	ll t=0;
	rep(i,n){
		cin>>a[i];
		t+=a[i];
	}
	sort(a,a+n);
	rrep(i,n){
		if(a[i]>2*(t-a[i])){
			cout<<n-i<<endl;
			return 0;
		}
		t-=a[i];
	}
	cout<<n<<endl;
	return 0;

}





Measured memory_bytes: 9728
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())), np.int64)
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Measured memory_bytes: 48804
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

from math import gcd
from collections import defaultdict

def main():
	n=II()
	mod=10**9+7

	ans=1
	cnt=0
	d=defaultdict(int)

	for _ in range(n):
		a,b=MI()
		if a==b==0:
			cnt+=1
		elif a==0:
			d[(1,0)]+=1
		elif b==0:
			d[(0,-1)]+=1
		else:
			g=gcd(abs(a),abs(b))
			if a*b>0:
				d[(abs(a//g),abs(b//g))]+=1
			else:
				d[(abs(a//g),-abs(b//g))]+=1


	s=set()

	for a,b in list(d):
		#print(a,b,s)
		if (a,b) in s:
			continue
		if b>=0:
			x=d[(a,b)]
			y=d[(b,-a)]
			s.add((a,b))
			s.add((b,-a))
		else:
			x=d[(a,b)]
			y=d[(-b,a)]
			s.add((a,b))
			s.add((-b,a))
		ans*=2**x+2**y-1
		ans%=mod
	ans+=cnt-1
	print(ans%mod)

if __name__ == "__main__":
	main()


Measured memory_bytes: 217316
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;


bool f(string S, string T)
{
    if (T.size() != S.size() + 1)
    {
        return false;
    }
    else
    {
        for (size_t i = 0; i < S.size(); i++)
        {
            if (S[i] != T[i])
            {
                return false;
            }
        }
                
    }
    return true;
}


int main()
{

    string S, T;
    cin >> S >> T;

    cout << YesNo(f(S,T)) << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    char c;
    cin>>c;
    vector<char> v={'a','i','u','e','o'};
    bool f=false;
    rep(i,0,5) if(c==v[i]) f=true;
    if(f) cout<<"vowel"<<endl;
    else cout<<"consonant"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;cin >>a >> b;
	if(a == 1 && b != 1){
		cout << "Alice" << endl;
	}
	else if(a != 1 && b == 1){
		cout << "Bob" << endl;
	}
	else if (a == b){
		cout << "Draw" << endl;
	}
	else{
		if(a > b) cout << "Alice" << endl;
		else cout << "Bob" << endl;
	}
	
}

Measured memory_bytes: 256
#168 - F
import sys
import numpy as np
#from numba import njit


def main():
    N, M = map(int, sys.stdin.buffer.readline().split())
    LineData = np.int64(sys.stdin.buffer.read().split())

    INF = 10**9 + 1

    LineData = LineData.reshape(-1, 3)
    A, B, C = LineData[:N].T
    D, E, F = LineData[N:].T
    X = np.unique(np.concatenate([D, [-INF, INF]]))
    Y = np.unique(np.concatenate([C, [-INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B, 'right') - 1
    C = np.searchsorted(Y, C)
    D = np.searchsorted(X, D)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F, 'right') - 1

    area = cal_area(A, B, C, D, E, F, X, Y)

    if area == 0:
        print("INF")
    else:
        print(area)


#@njit
def cal_area(A, B, C, D, E, F, X, Y):
    x = np.searchsorted(X, 0, 'right') - 1
    y = np.searchsorted(Y, 0, 'right') - 1

    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]

    #A = A.tolist()
    #B = B.tolist()
    #C = C.tolist()
    #D = D.tolist()
    #E = E.tolist()
    #F = F.tolist()
    #X = X.tolist()
    #Y = Y.tolist()
    #DX = DX.tolist()
    #DY = DY.tolist()

    LenX = len(X)
    LenY = len(Y)

    visit = [[False] * LenY for _ in range(LenX)]
    visit[x][y] = True
    area = 0
    queue = [(x, y)]

    LineX = [[False] * LenY for _ in range(LenX)]
    LineY = [[False] * LenY for _ in range(LenX)]

    for x1, x2, y in zip(A, B, C):
        for x in range(x1, x2):
            LineY[x][y] = True

    for x, y1, y2 in zip(D, E, F):
        for y in range(y1, y2):
            LineX[x][y] = True

    LenX -= 1
    LenY -= 1
    
    while queue:
        x, y = queue.pop()
        
        if x == 0 or x == LenX or y == 0 or y == LenY:
            area = 0
            break
        
        area += DX[x] * DY[y]
        
        x1 = x - 1
        if not LineX[x][y] and not visit[x1][y]:
            visit[x1][y] = True
            queue.append((x1, y))
        y1 = y - 1
        if not LineY[x][y] and not visit[x][y1]:
            visit[x][y1] = True
            queue.append((x, y1))
        x1 = x + 1
        if not LineX[x1][y] and not visit[x1][y]:
            visit[x1][y] = True
            queue.append((x1, y))
        y1 = y + 1
        if not LineY[x][y1] and not visit[x][y1]:
            visit[x][y1] = True
            queue.append((x, y1))

    return area


if __name__ == '__main__':
	main()

sys.exit()


Measured memory_bytes: 65992
#include <iostream>
using namespace std;
int main(){
 
  int n,m,l,i,j,k;
  long am[100][100],bm[100][100],cm[100][100]={};
 
  cin>>n>>m>>l;
  for(i=0; i<n; i++)for(j=0; j<m; j++)cin>>am[i][j];
  for(j=0; j<m; j++)for(k=0; k<l; k++)cin>>bm[j][k];
  for(i=0; i<n; i++)for(k=0; k<l; k++)for(j=0; j<m; j++)cm[i][k]+=am[i][j]*bm[j][k];
 
  for(i=0; i<n; i++){
    for(k=0; k<l; k++){
            if(k==l-1){
        cout<<cm[i][k]<<"\n";
        break;
      }
 
      cout<<cm[i][k]<<" ";
    }
  }
}


Measured memory_bytes: 3296
#include<stdio.h>
int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  
  if(a<=5)
    printf("0");
  else{
    if(a>=13)
      printf("%d",b);
    else
      printf("%d",b/2);
  }
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (H, N) = ReadStream<int, int>();
        var ab = new (int a, int b)[N];
        for (int i = 0; i < N; i++)
        {
            ab[i] = ReadStream<int, int>();
        }
        var dp = Enumerable.Repeat(int.MaxValue, H + 1).ToArray();
        dp[0] = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < H; j++)
            {
                if (dp[j] == int.MaxValue) continue;
                int nj = Min(H, j + ab[i].a);
                dp[nj] = Min(dp[nj], dp[j]+ab[i].b);
            }
        }
        WriteLine(dp[H]);
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 28524
import java.util.*;
 
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		outside: for(int i=0; i<=3333; i++){
			for(int j=0; j<=3333; j++){
				long li = (long)i;
				long lj = (long)j;
				long A5 = li*li*li*li*li;
				long B5 = lj*lj*lj*lj*lj;
				long B52 = -lj*-lj*-lj*-lj*-lj;
				if(A5-B5 == x){
					System.out.println(i+" "+j);
					break outside;
				}
				if(A5-B52 == x){
					System.out.println(i+" "+(-j));
					break outside;
				}
			}	
		}
	}
}


Measured memory_bytes: 27100
import sys
def main():
    input = sys.stdin.readline
    N,Q=map(int, input().split())
    G=[[] for _ in range(N)]
    for _ in range(N-1):
        a,b=map(int, input().split())
        a,b=a-1,b-1
        G[a].append(b)
        G[b].append(a)
    C=[0]*N
    for _ in range(Q):
        p,x=map(int, input().split())
        C[p-1]+=x
    stk=[0]
    used=[False]*N
    used[0]=True
    while stk:
        v = stk.pop()
        for to in G[v]:
            if used[to]: continue
            used[to] = True
            C[to]+=C[v]
            stk.append(to)
    print(*C)


if __name__ == '__main__':
    main()

Measured memory_bytes: 92876
s = "0" + input()
keta = len(s)
dp = [0] * (keta + 1)
kuri = 0
for i in range(keta):
    ni = i + 1
    num = int(s[-i - 1])
    if kuri:
        num += 1
        kuri = 0
    if num == 10:
        kuri = 1
        dp[ni] = dp[i]
    elif num < 5:
        dp[ni] = dp[i] + num
    elif num > 5:
        num %= 10
        kuri = 1
        dp[ni] = dp[i] + 10 - num
    else:
        nn = int(s[-ni - 1])
        if nn < 5:
            dp[ni] = dp[i] + num
        else:
            kuri = 1
            dp[ni] = dp[i] + 10 - num
print(dp[keta] + kuri)


Measured memory_bytes: 62320
n,k,s = map(int,input().split(" "))
ar = []
for i in range(k):
    ar.append(s)
for i in range(n-k):
    if s == 10 ** 9:
        ar.append(1)
    else:
        ar.append(s + 1)
for i in range(n-1):
    print(ar[i],end=" ")
print(ar[n-1])

Measured memory_bytes: 12872
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int N,K,C;
int A[100001];
int B[100001];
vector<int> ans;



int main(){
    cin >> N >> K;
    int sum = 0;
    for (int i=0;i<K;i++){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum < N){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    
}




Measured memory_bytes: 384
# 2019/08/24
# 第一回日本最強プログラマー学生選手権-予選- - A

# Input
m, d = map(int,input().split())
cnt = 0

# Calc
for i in range(2, m+1):
    for j in range(2, d+1):
        d1 = int(j / 10)
        d10 = j % 10
        if d1 > 1 and d10 != 1:
            if d1 * d10 == i:  
                cnt = cnt + 1

# Output
print(cnt)


Measured memory_bytes: 2940
import java.util.PriorityQueue;
import java.util.Scanner;

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

		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());

		long[] V = new long[N + 1];
		for (int i = 1; i <= N; i++) {
			V[i] = Long.parseLong(sc.next());
		}

		sc.close();

		long max = 0;
		for (int L = 0; L <= K; L++) {
			for (int R = 0; R <= Math.min(K, N) - L; R++) {
				long sum = 0;
				PriorityQueue<Long> pq = new PriorityQueue<Long>();
				for (int l = 1; l <= L; l++) {
					sum += V[l];
					pq.add(V[l]);
				}
				for (int r = 1; r <= R; r++) {
					int i = N - r + 1;
					sum += V[i];
					pq.add(V[i]);
				}
//				System.out.println("L:" + L + "R:" + R + "sum:" + sum);

				for (int d = 1; d <= K - L - R; d++) {
					if(pq.peek() == null) break;
					long i = pq.poll();
					if (i >= 0) {
						break;
					} else {
						sum -= i;
					}
				}
//				System.out.println(sum);

				if(sum > max) max = sum;

			}
		}

		System.out.println(max);

	}
}


Measured memory_bytes: 26324
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;



int main() {
	int N,x;cin>>N>>x;
	vector<long long int>memos(1e5+1,1e18);
	memos[x]=0;
	vector<pair<int ,long long int>>warps(N);
	for (int i = 0; i < N; ++i) {
		int a,b;cin>>a>>b;
		warps[i]=make_pair(a,b);
	}
	priority_queue<pair<long long int,int>,
	vector<pair<long long int,int>>,
	greater<pair<long long int,int>>>que;
	que.emplace(0,x);
	while (!que.empty()) {
		auto p(que.top());
		que.pop();
		const int now_x=p.second;
		const long long int now_cost=p.first;
		if(memos[now_x]!=now_cost)continue;
		if(now_x==0)break;
		for (int i = 0; i < N; ++i) {
			for (int j = -1; j <= 1; j += 2) {
				int next_x=now_x+j*warps[i].first;
				const long long int next_cost=now_cost+warps[i].second;
				next_x=abs(next_x);
				if (next_x <= 1e5) {
					if (memos[next_x] > next_cost) {
						memos[next_x]=next_cost;
						que.emplace(next_cost,next_x);
					}
				}
			}
		}
	}
	if(memos[0]>1e17)memos[0]=-1;
	cout<<memos[0]<<endl;
	return 0;
}


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

int main(){
    ll n, x, y;
    cin >> n >> x >> y;
    vector<vector<ll>> g;
    vector<ll> flag(n);
    vector<set<set<ll>>> ans(n-1);
    vector<ll> len(n-1);

    for(int i = 1; i <= n; i++){
        vector<ll> tmp;
        //tmp.push_back(i);
        if(i > 1) tmp.push_back(i-1);
        if(i < n) tmp.push_back(i+1);
        g.push_back(tmp);
    }
    g[x-1].push_back(y);
    g[y-1].push_back(x);


    for(int i = 0; i < n; i++){
        queue<ll> q;
        q.push(i);
        fill(flag.begin(), flag.end(),-1);
        flag[i] = 0;
        //bfs
        while(!q.empty()){
            ll tmp = q.front(); q.pop();
            for(auto x:g[tmp]){
                if(flag[x-1] < 0){
                    q.push(x-1);
                    flag[x-1] = flag[tmp] + 1;
                    if(flag[x-1] < 1) continue;
                    len[flag[x-1]-1]++;
                    /*
                    set<ll> s;
                    s.insert(i);
                    s.insert(x-1);
                    ans[flag[x-1]-1].insert(s);**/
                }
            }
        }

    }

    for(int i = 0; i < n-1; i++){
        //put(ans[i].size());
        put(len[i] / 2);
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd(a,b) __gcd(a,b)
#define INF INT_MAX
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

int a,b,c;

int main(){
  cin>>a>>b>>c;
  if(a+b+c>=22)
    cout<<"bust"<<endl;
  else
    cout<<"win"<<endl;  
  return 0;
}

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

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

    rep(i, s.size()){
        if(i % 2 == 0){
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(i % 2 != 0){
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }


    cout<<"Yes"<<endl;

    //cout << fixed << setprecision(6) << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3604
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<string, int> > vsi;
    for (int n = 0; n < N; ++n) {
        string s; int p;
        cin >> s >> p;
        vsi.emplace_back(s, -p);
    }
    vector<int> Res;
    for (int n = 0; n < N; ++n) {
        Res.push_back(n);
    }
    sort(Res.begin(), Res.end(), [&](int l, int r) { return vsi[l] < vsi[r]; });
    for (int n = 0; n < N; ++n) {
        cout << Res[n]+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    ll n;
    cin >> n;
    map<ll, ll> mp;
    rep(i, n)
    {
        ll x; cin >> x; mp[x]++;
    }
    ll m;
    cin >> m; ll ans = 0;
    rep(i, m)
    {
        ll x; cin >> x;
        if(mp[x]) {
            mp[x]--;
        }
        else ANS("NO");
    }
    ANS("YES");
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 12800
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 6824
#include<stdio.h>
#include<string.h>
int main(){
  char str[1000];
  int sum;
  while(1){
    sum=0;
    scanf("%s",str);
    if(str[0] == '0')break;
    for(int i=0;str[i]!='\0';i++){
      sum+=(str[i]-'0');
    
    }
    printf("%d\n",sum);
  }
    return 0;
  }



Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
string s;
int one[100005],zer[100005];
int main()
{
	cin>>s;
	one[0]=(s[0]=='1');
	zer[0]=1-one[0];
	for(int i=1;i<s.size();i++)
	{
		one[i]=one[i-1]+(s[i]=='1');
		zer[i]=i+1-one[i];
	}
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		int lo=one[i],lz=zer[i],ro=one[s.size()-1]-one[i],rz=zer[s.size()-1]-zer[i];
		ans=max(ans,min(lz,ro)*2+min(lo,rz)*2);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280