akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M,P = map(int,readline().split())
ABC = np.array(read().split(),np.int64)

A = ABC[::3]
B = ABC[1::3]
C = ABC[2::3]

C = P-C

# bellman fordでAからBへの最短距離を求める

INF = 10**18
dist = np.full(N+1,INF,np.int64)
dist[1] = 0
for T in range(N+N+10):
    x = dist[A] + C
    update = (dist[B] > x) & (x < INF//2)
    b = B[update]; x = x[update]
    if T > N:
        dist[b] = -INF
    else:
        ind = x.argsort(); x = x[ind][::-1]; b=b[ind][::-1]
        dist[b] = x

answer = -dist[N]
if answer < 0:
    answer = 0
elif answer == INF:
    answer = -1
print(answer)


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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n;
signed main(){
    cin>>n;
    int o=(n+1)/2;
    double ans=1.000000*o/n;
    printf("%.7Lf\n",ans);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define inf 10000000000000
#define ll unsigned long long
#define boostUP ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n) for(ll i=0;i<n;i++)
#define fcr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(arr) sizeof(arr)/sizeof(arr[0])
#define mod 1000000007;
 
using namespace std;
// lower_bound
// it returns pos of the elmnt which is not less then the query elmnt
int main() {
	int n; cin >> n;
	vector<int> arr(n,0);

	for(int i = 0; i < n; i++)
		cin >> arr[i];

	int sum = 1e9;
	for(int i = 0; i <= 100; i++){
		int x = 0;
		for(int j = 0; j < n; j++){
			x += ( (arr[j] - i) * (arr[j] - i) );
		}
		sum = min(sum, x);
	}
	cout << sum << endl;
}





Measured memory_bytes: 3596
x = int(input())

five_pows = []
for i in range(1000):
    five_pows.append(i**5)

flag = 0
for i in range(1000):
    if flag:
        break
    for j in range(i, 1000):
        if five_pows[j] - five_pows[i] == x:
            flag = 1
            print(j, i)
            break
        elif five_pows[j] + five_pows[i] == x:
            flag = 1
            print(j, -i)
            break

Measured memory_bytes: 9200
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


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

    int n, m;
    pair<int, int> ab[100100];
    scanf("%d %d", &n, &m);
    rep(i, n) scanf("%d %d", &ab[i].first, &ab[i].second);

    sort(begin(ab), begin(ab) + n);
    priority_queue<int> candidate;
    int ans = 0;

    int i = 0;
    for (int mi = 1; mi <= m; ++mi) {
        for (; i < n && ab[i].first <= mi; ++i)
            candidate.push(ab[i].second);
        if (!candidate.empty()) {
            ans += candidate.top();
            candidate.pop();
        }
    }

    print(ans);

    return 0;
}



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

int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 1e9;
    for (int i = -100; i <= 100; i++) {
        int sum = 0;
        for (int x : a) sum += (i-x) * (i-x);
        ans = min(ans, sum);
    }
    cout << ans << '\n';
    return 0;
}

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

int main()
{
    std::string s;
    std::cin >> s;
    bool res = true;
    while(s.size()){
        std::string sub;
        if(s.back() == 'm'){
            for(int i = 0; i < 5; i++){
                sub.push_back(s.back()); s.pop_back();
            }
            if(sub != "maerd")res = false;
        }else if(s.back() == 'e'){
            for(int i = 0; i < 5; i++){
                sub.push_back(s.back()); s.pop_back();
            }
            if(sub != "esare")res = false;

        }else if(s.back() == 'r'  && *(s.end() -3) == 'm'){
            for(int i = 0; i < 7; i++){
                sub.push_back(s.back()); s.pop_back();
            }
            if(sub != "remaerd")res = false;

        }else if(s.back() == 'r' && *(s.end() - 3) == 's'){
            for(int i = 0; i < 6; i++){
                sub.push_back(s.back()); s.pop_back();
            }
            if(sub != "resare")res = false;
        }else{
            res = false;
            break;
        }
    }
    std::cout << (res ? "YES" : "NO") << std::endl;

}

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

int s[5000];
int ra[5000];
vector<int> v[100000];

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		s[b]++;
		v[a].push_back(b);
	}
	
	int k = 0;
	while (k < n){
		for (int i = 0; i < n; i++){
			if (s[i] == 0){
				ra[k++] = i;
				for (int j = 0; j < v[i].size(); j++){
					s[v[i][j]]--;
				}
				s[i] = -1;
			}
		}
	}
	
	bool r = false;
	for (int i = 0; i < n; i++){
		printf("%d\n", ra[i] + 1);
		if (!r && i){
			bool f = true;
			for (int j = 0; j < v[ra[i - 1]].size() && f; j++){
				if (v[ra[i - 1]][j] == ra[i]){
					f = false;
				}
			}
			r = f;
		}
	}
	printf("%d\n", r);
	
	return 0;
}

Measured memory_bytes: 4164
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int arr[8]={1,3,5,7,8,10,12},war[5]={4,6,9,11},n ,m;
bool a,e;
int main()
{
   cin>>n>>m;
   if(n==2&&m==2)return cout<<"Yes",0;
  else if(n==2||m==2)return cout<<"No",0;
  else
  {
      for(int i=0;i<7;i++)
      {
          if(n==arr[i])a=1;
          if(m==arr[i])e=1;
      }
      if(e&&a)return cout<<"Yes",0;
      else if(e||a)return cout<<"No",0;
      for(int i=0;i<4;i++)
      {
          if(n==war[i])a=1;
          if(m==war[i])e=1;
      }
      if(e&&a)return cout<<"Yes",0;
      else if(e||a)return cout<<"No",0;
  }
if(!a||!e)cout<<"No";

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val As = readLine()!!.split(' ').map(String::toInt)
    var b0 = 0
    var isPlus = true
    for(i in n-1 downTo 0){
        b0 += if(isPlus)As[i] else -As[i]
        isPlus = !isPlus
    }

    val Bs = Array<Int>(n){0}
    Bs[0] = b0

    for(i in 1 .. Bs.size - 1){
        Bs[i] = (As[i-1] - Bs[i-1] / 2) * 2
    }
    for(i in Bs.indices){
        print(Bs[i])
        if(i != Bs.size - 1) print(" ")
    }
}

Measured memory_bytes: 78840
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
dd = defaultdict(int)

for i in range(M):
	a,b = inpl()
	if a == 1:
		if dd[b] == 1:
			print('POSSIBLE')
			sys.exit()
		else:
			dd[b] = 1

	if b == N:
		if dd[a] == 1:
			print('POSSIBLE')
			sys.exit()
		else:
			dd[a] = 1

print('IMPOSSIBLE')

Measured memory_bytes: 28272
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

//c -> 1,+ 2,-, 3,*
int calc(int a,int b,int c){
	switch(c){
		case 1:return a+b;
		case 2:return a-b;
		case 3:return a*b;
	}
	return 0;
}
char n2c(int n){
	switch(n){
		case 1: return '+';
		case 2: return '-';
		case 3: return '*';
	}
}

bool comb(int a[], int n){
	if(n == 3){
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 3; j++){
				for(int k = 1; k <= 3; k++){
					if(calc(calc(a[0],a[1],i),calc(a[2],a[3],j),k) == 10){
						cout<<'('<<a[0]<<n2c(i)<<a[1]<<')'<<n2c(k)<<'('<<a[2]<<n2c(j)<<a[3]<<')'<<endl;
						return true;
					}
					if(calc(a[0],calc(a[1],calc(a[2],a[3],i),j),k) == 10){
						cout<<a[0]<<n2c(k)<<'('<<a[1]<<n2c(j)<<'('<<a[2]<<n2c(i)<<a[3]<<"))"<<endl;
						return true;
					}
					if(calc(calc(calc(a[0],a[1],i),a[2],j),a[3],k)== 10){
						cout<<"(("<<a[0]<<n2c(i)<<a[1]<<')'<<n2c(j)<<a[2]<<')'<<n2c(k)<<a[3]<<endl;
						return true;
					}
				}
			}
		}
		return false;
	}else{
		for(int i = n; i < 4; i++){
			swap(a[i],a[n]);
			if(comb(a,n+1)) return true;
			swap(a[i],a[n]);
		}
	}
	return false;
}

int main(){
	int a[4];
	for(int i = 0; i < 4; i++){
		cin >> a[i];
	}
	while(a[0]){
		if(!comb(a,0)) cout << 0 << endl;
		for(int i = 0; i < 4; i++){
			cin >> a[i];
		}
	}
}

Measured memory_bytes: 0
n=int(input())
li=[input() for i in range(n)]
li2 = []
li2.append([0,0,0])
for i in range(n):
    li2.append( [int(x.strip()) for x in li[i].split()])
    
c=0


for i in range(n):
    t = li2[i+1][0] - li2[i][0]
    x = abs(li2[i+1][1] - li2[i][1])
    y = abs(li2[i+1][2] - li2[i][2])
    z = x+y
    if t < z:
        c=1
        break
    if (z - t)%2 == 1:
        c=1
        break
        
        

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

Measured memory_bytes: 78424
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;

int main(){
	int A,B,T,ans=0;
    cin >> A >> B >> T;
    ans=(T/A)*B;
	
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] arg){
        Scanner scan =new Scanner(System.in);
        String s=scan.next();

        if(s.contains("00")) System.out.print("Bad");
            else if(s.contains("11")) System.out.print("Bad");
            else if(s.contains("22")) System.out.print("Bad");
            else if(s.contains("33")) System.out.print("Bad");
            else if(s.contains("44")) System.out.print("Bad");
            else if(s.contains("55")) System.out.print("Bad");
            else if(s.contains("66")) System.out.print("Bad");
            else if(s.contains("77")) System.out.print("Bad");
            else if(s.contains("88")) System.out.print("Bad");
            else if(s.contains("99")) System.out.print("Bad");
            else System.out.print("Good");

    }

}

Measured memory_bytes: 23124
import numpy as np
import math
PI=np.pi
A,B,H,M=list(map(int,input().split()))

# s_spin=M
# l_spin=H+M/60
# rot=abs((s_spin*6)-(l_spin*30))
s_spin=PI*(H+M/60)*30/180
l_spin=PI*M*6/180
# print(s_spin,l_spin)
# print(np.sin(s_spin),np.sin(l_spin))
S=np.array([A*np.sin(s_spin),A*np.cos(s_spin)])
L=np.array([B*np.sin(l_spin),B*np.cos(l_spin)])
# print(S,L)
# length1=math.sqrt((S[0]-L[0])**2+(S[1]-L[1])**2)
# print(length1)
u=L-S
length2=np.linalg.norm(u)
print(length2)

Measured memory_bytes: 27308
#include <iostream>
#include <vector>
#include <string>


std::string num;
int N = 4;
std::vector<int> v(N);

bool check (int bit) {
    int num = v[0];
    for (int i = 1; i < N; ++i) {
        if (bit & (1 << (i - 1))) num += v[i];
        else num -= v[i];
    }
    if (num == 7) return true;
    else return false;
}

int main(){
    std::cin >> num;
    for (int i = 0; i < N; ++i) v[i] = num[i] - '0';
    for (int bit = 0; bit < (1 << (N - 1)); ++bit) {
        if (check(bit)) {
            std::cout << v[0];
            for (int i = 1; i < N; ++i) {
                if (bit & (1 << (i - 1))) std::cout << '+';
                else std::cout << '-';
                std::cout << v[i];
            }
            std::cout << "=7";
            break;
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int const N_MAX = 20;

int N, M, C;
int B[N_MAX + 1];
int A[N_MAX + 1][N_MAX + 1];

int main() {
  scanf("%d %d %d", &N, &M, &C);
  rep(i, M) scanf("%d", &B[i]);
  rep(i, N) rep(j, M) scanf("%d", &A[i][j]);

  int count = 0;
  rep(i, N) {
    int s = 0;
    rep(j, M) {
      s += A[i][j] * B[j];
    }
    s += C;
    if (s > 0) count++;
  }
  printf("%d\n", count);
}


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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    a[0] = a[0]-32;
    b[0] = b[0]-32;
    c[0] = c[0]-32;
    printf("%c%c%C\n",a[0],b[0],c[0]);
}

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

using namespace std;

int main() {
    int N; cin>>N;
    vector<int> pn(N+1);
    for (int i=1;i<=N;i++) cin>>pn[i];

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

    int sum=0;
    for (int i=1;i<N;i++) {
        sum += pn[i];
    }
    sum += pn[N]/2;

    cout << sum << endl;

    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll n,m,seg[400001];
void segstart(void){
    for(int i=0;i<=400000;i++){
        seg[i]=1e18;
    }
    for(ll i=1;;i*=2){
        if(n<=i){m=i;break;}
    }
    m--;
    for(int i=m-1;i>=0;i--){
        seg[i]=min(seg[2*i+1],seg[2*i+2]);
    }

}
void update(ll a,ll b){
    a+=m;seg[a]=b;
    while(a){
        a=(a-1)/2;
        seg[a]=min(seg[2*a+1],seg[2*a+2]);
    }
}
ll ans(ll a,ll b){
    ll ret=1e18;a+=m;b+=m;
    while(1){
        if(a==b){
            ret=min(ret,seg[a]);
            break;
        }
        if(b==a+1){
            ret=min(ret,seg[a]);
            ret=min(ret,seg[b]);
            break;
        }
        if(a%2)a/=2;
        else{
            ret=min(ret,seg[a]);
            a/=2;
        }
        if(b%2){
            ret=min(ret,seg[b]);
            b/=2;b--;
        }
        else{b/=2;b--;}
    }
    return ret;
}


int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    segstart();
    ll k;
    cin>>k;
    ll l,r,c;
    ll dp[100005];
    for(int i=0;i<n;i++)dp[i]=1e18;
    dp[0]=0;
    vector<pair<pair<ll,ll>,ll> > v;
    for(int i=0;i<k;i++){
        cin>>l>>r>>c;
        v.pb(make_pair(make_pair(l-1,r-1),c));
    }
    sort(be(v));
    update(0,0);
    for(int i=0;i<k;i++){
        dp[v[i].first.second]=min(ans(v[i].first.first,v[i].first.second)+v[i].second,dp[v[i].first.second]);
        update(v[i].first.second,dp[v[i].first.second]);
    }
    if(dp[n-1]==1e18)cout << -1<<endl;
    else cout << dp[n-1] <<endl;
    return 0;
}


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

int N,M;
int main(){
	cin >> N >> M;
	int t = M/N;
	int ans = 0;
	for(int i=1;i*i<=M;i++){
		if(M%i==0 && i<=t) ans = max(i,ans);
		if(M%i==0 && M/i<=t) ans = max(M/i,ans);
	}
	cout << ans << endl;
}

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

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

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

#define sz(x) ((int) (x).size())
#define TASK "text"

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

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

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

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int n;
int b[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  n = 2 * n - 1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    b[i]--;
  }
  return true;
}

int a[maxn];

bool check(int x) {
  for (int i = 0; i < n; i++) {
    a[i] = (b[i] >= x);
  }
  int pos = n / 2;
  if (a[pos] == a[pos - 1] || a[pos] == a[pos + 1]) {
    return a[pos];
  }
  int l = pos, r = pos;
  while (l && a[l - 1] != a[l]) {
    l--;
  }
  while (r + 1 < n && a[r + 1] != a[r]) {
    r++;
  }
  if (a[l] == a[r]) {
    return a[l];
  }
  int m = (l + r) / 2;
  if (pos <= m) {
    return a[l];
  } else {
    return a[r];
  }
}

void solve() {
  int l = 0, r = n;
  while (l < r - 1) {
    int m = (l + r) / 2;
    if (check(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  printf("%d\n", l + 1);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
#define fo(i,s,e_ex) for(i=s;i<e_ex;i++)
#define Fo(i,k,n) for(i=k;k<n?i<=n:i>=n;k<n?i+=1:i-=1)
#define endl '\n'
#define MOD 1000000007//998244353
#define pbb push_back
#define mpp make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mset(arr,val) memset(arr,val,sizeof(arr))
ll arr[405],prefs[405];
ll dp[405][405];
ll suminrange(ll l,ll r){
    if(l==0) return prefs[r];
    return prefs[r]-prefs[l-1];
}
ll findAns(ll l,ll r){
    if(l==r) return 0;
    if(dp[l][r]>=0) return dp[l][r];
    ll i,ans=LLONG_MAX;
    for(i=l;i<r;i++){
        ll myans = suminrange(l,i) + suminrange(i+1,r) + findAns(l,i) + findAns(i+1,r);
        ans = min(ans,myans);
    }
    return dp[l][r]=ans;
}
void solve(ll caseno){
	ll i,j,n,ans;
    cin>>n;
    mset(dp,-1);
    for(i=0;i<n;i++) cin>>arr[i];
    prefs[0]=arr[0];
    for(i=1;i<n;i++) prefs[i]=arr[i]+prefs[i-1];
    ans = findAns(0,n-1);
    cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		solve(i);
	}
	return 0;
}


Measured memory_bytes: 4940
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<vector<int>> ans(200000);


    for (int i = 2; i < n + 1; i++)
    {
        cin >> a[i];
        ans[a[i]].push_back(i);
    }

    for (int i = 1; i < n + 1; i++)
        cout << ans[i].size() << endl;

    return 0;
}


Measured memory_bytes: 14724
#include <stdio.h>
#include <stdlib.h>

int stack[10];
int num = 0;

int pop()
{
        int tmp = stack[num - 1];
        num = num - 1;
        return tmp;
}

void push( int x )
{
        stack[num] = x;
        num = num + 1;
}

int main()
{
        int number;

        while ( scanf("%d", &number) != EOF )
        {
                if ( number == 0 )
                {
                        fprintf( stdout, "%d\n", pop() );
                }
                else
                {
                        push( number );
                }
        }

        return 0;
}

Measured memory_bytes: 600
def Z_algorithm(S):
    l=len(S)
    A=[0]*l
    A[0]=l
    i=1; j=0
    while i<l:
        while i+j<l and S[j]==S[i+j]:
            j+=1
        if not j:
            i+=1
            continue
        A[i]=j
        k=1
        while l-i>k<j-A[k]:
            A[i+k]=A[k]
            k+=1
        i+=k; j-=k
    return A

def Z_find(txt,pattern):
    lp=len(pattern)
    jointxt=pattern+'-'+txt
    Z=Z_algorithm(jointxt)
    return [Z[i]==lp for i in range(lp+1,len(jointxt))]

class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.rank=[0]*n
        self.size=[1]*n
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,x,y):
        px=self.find(x)
        py=self.find(y)
        if px!=py:
            if self.rank[px]==self.rank[py]:
                self.rank[px]+=1
            elif self.rank[px]<self.rank[py]:
                px,py=py,px
            self.par[py]=px
            self.size[px]+=self.size[py]
    def same_check(self,x,y):
        return self.find(x)==self.find(y)

def solve(s,t):
    lt=len(t)
    s*=(lt+len(s)-1)//len(s)
    ls=len(s)
    Z=Z_find(s*2,t)
    uf=UnionFind(ls)
    loop=False
    for i in range(ls):
        if Z[i]:
            j=(i+lt)%ls
            if uf.same_check(i,j):
                return -1
            uf.union(i,j)
    return max(uf.size)-1

s=input(); t=input()
print(solve(s,t))

Measured memory_bytes: 173380
import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))


Measured memory_bytes: 147372
import math

n = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
i = 1
while i > 0:
    if is_prime(n):
        break
    n += 1 
print (n)

Measured memory_bytes: 9040
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <math.h>


using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	
	int amari = N - K;
	if (K == 1) amari = 0;
	cout << amari;
}


Measured memory_bytes: 256
n, c, k = list(map(int, input().split()))
t = sorted([int(input()) for i in range(n)], reverse=True)
result = 1
bus = 1
time = t[0]
for i in range(1, n):
  if bus + 1 > c or time-t[i] > k:
    time = t[i]
    result += 1
    bus = 1
  else:
    bus += 1
print(result)

Measured memory_bytes: 8280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,flag=0;
    cin>>n;
    for(i=1; i<=9; i++)
    {
        if(n%i==0)
        {
            if((n/i)<=9)
            {
                flag=1;
                break;
            }
        }
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n;
string s,t;
int32_t main(){
CODE_START;
cin>>s>>t;
string x=t.substr(0,s.size());
if(x==s){
    cout<<"Yes"<<endl;
}else cout<<"No";
}


Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>



void a(std::istream& in)
{
    int N, R;

    in >> N;
    in >> R;

    if (N >= 10)
    {
        std::cout << R;
        return;
    }

    std::cout << R + 100 * (10 - N);
}

int main(int, char* [])
{
    a(std::cin);
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string N;

int main() {
  INCANT;
  cin >> N;
  string ans = N[0]==N[2]?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,x,i;
    int count = 0;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&x);
        if(isPrime(x)){
            count++;
        }
    }
    printf("%d\n",count);
    
    return 0;
}

int isPrime(int x){
    int i;
    if(x < 2){
        return 0;
    }
    else if(x == 2){
        return 1;
    }
    if(x % 2 == 0){
        return 0;
    }
    for(i = 3;i*i <= x;i += 2){
        if(x % i == 0){
            return 0;
        }
    }
    return 1;
}


Measured memory_bytes: 2148
#include <iostream>
using namespace std;
int n,x,y;
int a[110];
int t=0,tt=0,ttt=0;
int main()
{
	cin >>n>>x>>y;
	for (int i=0;i<n;i++)
	{
		cin >>a[i];
		if (a[i]<=x) t++;
		else if (a[i]>x && a[i]<=y) tt++;
		else ttt++;
	}
	cout <<min(t,min(tt,ttt));
	return 0;
}

Measured memory_bytes: 256
import random


def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)


def lcm(a, b):
    return (a * b) / gcd(a, b)
# a=list(map(int , input().split()))
# ans=-1
# for i in range(4):
#     for j in range(i+1,4):
#         if ans==-1:
#             ans=a[i]*a[j]
#         else:
#             ans=max(ans, a[i]*a[j])
# print(ans)
x=int(input())
if x==1:
    print(0)
else:
    print(1)

Measured memory_bytes: 9488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define MAX 1000000

ll N;
vector<bool> IsPrime;
vector<ll> D(MAX, 0);

void eratos() {
    if (MAX + 1 > IsPrime.size()) IsPrime.resize(MAX + 1, true);
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (size_t i = 2; i * i < MAX; i++) {
        if (IsPrime[i]) {
            for (size_t j = 2; i * j < MAX; j++) IsPrime[i * j] = false;
        }
    }
}

vector<P> prime_factorize(ll a) {
    vector<P> res;
    for (size_t i = 2; i * i <= a; i++) {
        if (a % i != 0) continue;
        ll ex = 0;

        while (a % i == 0) {
            ex++;
            a %= i;
        }
        res.push_back({i, ex});
    }
    if (a != 1) res.push_back({a, 1});
    return res;
}


void prime_func(ll a) {
    for (size_t i = 2; i * i <= a; i++) {
        if (a % i != 0) continue;
        ll ex = 0;
        while (a % i == 0) {
            ex++;
            a /= i;
        }
        D.at(i) += 1;
    }
    if (a != 1) D.at(a) += 1;
    return;
}

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

string solve(vector<ll> A) {
    //string ans;
    //if (N + 1 > D.size()) D.resize(N + 1, 0);
    for (size_t i = 0; i < N; i++) prime_func(A.at(i));
    for (size_t i = 0; i < MAX; i++) {
        if (D.at(i) > 1) break;
        if (i >= MAX - 1) return "pairwise coprime";
    }
    ll gcd_value = A.at(0);
    for (size_t i = 1; i < N; i++) gcd_value = gcd(gcd_value, A.at(i));
    if (gcd_value == 1) return "setwise coprime";
    return "not coprime";
}

int main(){
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);
    cout << solve(A) << endl;
    return 0;
}


Measured memory_bytes: 26672
@_[glob<>]=$x+0..($x+=$&)for<>=~/ .* /..$`;$s[$_+$']=$s[$_]+abs((($b=$_[$_+$'])/$&|0)-(($a=$_[$_])/$&|0))+abs$b%$&-$a%$&for 1..$x;<>;/ /,print$s[$']-$s[$`],$/for<>

Measured memory_bytes: 23296
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#define REP(i, n) for(long long int i=0; i<(n); i++)
#define FOR(i, a, n) for(long long int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int N;cin>>N;
    vector<pair<int, int>> A(N);
    REP(i, N){
        int a; cin >> a;
        A[i] = make_pair(a, i);
    }
    sort(A.begin(), A.end());
    
    REP(i, N){
        int j = N-1;
        while(true){
            if(A[j].second != i){
                cout << A[j].first << endl;
                break;
            }
            j--;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
gets
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.each do |x|
  h[x] += 1
end
ans = 0
h.each do |_, v|
  ans += v * (v - 1) / 2
end
a.each do |x|
  puts ans - h[x] * (h[x] - 1) / 2 + (h[x] - 1) * (h[x] - 2) / 2
end

Measured memory_bytes: 28676
def modpow(a,n,mod):
  bi = str(format(n,"b"))
  res = 1
  for i in range(len(bi)):
    res = (res * res) % mod
    if bi[i] == "1":
      res = (res * a) % mod
  return res

def div(N):
  divv = []
  for i in range(1,int(N ** 0.5) + 1):
    if N % i == 0:
      divv.append(i)
      if i != N // i:
        divv.append(N // i)
  return(divv)
  
N,K = map(int,input().rstrip().split())
O = []
p = [0 for i in range(K + 1)]
ans = 0
for i in range(K,0,-1):
  p[i] = modpow(int(K / i),N,1000000007)
for i in range(K,0,-1):
  ans = (ans + (p[i] * i)) % 1000000007
  O = div(i)
  for o in O:
    if o != i:
      p[o] -= p[i]
print(ans)

Measured memory_bytes: 12172
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,m;
  cin >>n>>m;
  vector <ll> p;
  for(ll i=1; i*i<=m;i++){
    if(m%i==0){
      if((m/i)/n>0) p.push_back(i);
      if(i*i!=m){
        ll k=m/i;
        if((m/k)/n>0) p.push_back(k);
      }
      }
    }
  sort(p.begin(),p.end());
  cout <<p[p.size()-1]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n;
	scanf("%d\n", &n);
	char c;
	while((c=getchar())!=10){
		c+=n;
		if(c>'Z'){
			putchar(c-26);
		}else{
			putchar(c);
		}
	}
	putchar(10);
}


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

int x[2], y[2];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	for (int i = 0; i < 2; i++) cin >> x[i] >> y[i];
	int dx = x[1] - x[0];
	int dy = y[1] - y[0];
	swap(dx, dy);
	dx *= -1;
	cout << x[1] + dx << " " << y[1] + dy << " " << x[0] + dx << " " << y[0] + dy << endl;
	return 0;
}



Measured memory_bytes: 3640
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	int a,b;
	cin>>a>>b;
	if(a>=1 and a<=9 and b>=1 and b<=9){
		cout<<a*b<<endl;
	}  
	else cout<<-1<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
n, k, l = gets.split.map(&:to_i)
pq = []
rs = []
k.times do
    pq.push(gets.split.map(&:to_i))
end
l.times do
    rs.push(gets.split.map(&:to_i))
end

def find(x, parent)
    if parent[x] == x
        return x
    else
        parent[x] = find(parent[x], parent)
        return parent[x]
    end
end

def union(x, y, parent)
    px = find(x, parent)
    py = find(y, parent)
    if px == py
        return
    else
        parent[py] = px
    end
end

lpar = [*0..n]
tpar = [*0..n]

pq.each do |item|
    union(item[0], item[1], lpar)
end
rs.each do |item|
    union(item[0], item[1], tpar)
end

hash = {}
for i in 1..n
    item = [find(i, lpar), find(i, tpar)]
    if hash.has_key?(item)
        hash[item] += 1
    else
        hash[item] = 1
    end
end

arr = []
for i in 1..n
    item = [find(i, lpar), find(i, tpar)]
    arr.push(hash[item])
end
puts arr.join(" ")


Measured memory_bytes: 46188
#include<iostream>

using namespace std;
long long rgb_triplets(int n, string s) {
  if(n<3)
    return 0;
  long long r_count = 0;
  long long g_count = 0;
  long long b_count = 0;
  
  for(int i=0;i<n;i++) {
    if(s[i] == 'R')
      r_count++;
    if(s[i] == 'G')
      g_count++;
    if(s[i] == 'B')
      b_count++;
  }
  long long ans = r_count * g_count * b_count;

  for(long long i=0;i<n-1;i++) {
    for(long long k=i+1;k<n;k++) {
      if((k+i) % 2 != 0)
	continue;
      long long j = (k+i) / 2;
      //cout << i << " " << j << " " <<  k << " -> " << j-i << " " << k-j << endl;
      if(s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
	ans--;
    }
  }
  return ans;
}

int main() {
  int n;
  string s;

  cin >> n;
  cin >> s;

  cout << rgb_triplets(n, s);
}



Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

    int S = count(s.begin(), s.end(), 'S');
    int E = count(s.begin(), s.end(), 'E');
    int N = count(s.begin(), s.end(), 'N');
    int W = count(s.begin(), s.end(), 'W');

    if (!!S != !!N || !!W != !!E) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

int main() {
int N, K, Q;
cin >> N >> K >> Q;
int n;
vector<int> A(N);

 for (int i = 0; i < Q; i++)
  {
      cin >>  n;
      A.at(n-1)++;
  }

  for (int i = 0; i < N; i++)
  {
      if (A.at(i) >= Q-K +1)
      {
          cout << "Yes" << endl;
      }
      else
      {
          cout << "No" << endl;
      }
  }
  


}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main ()
{
    int a=0;
    int b=0;
    cin>>a>>b;
    int arr[b];
    int z=0;
    for(int i =0;i<b;i++)
        cin>>arr[i];


    for(int i =0;i<b;i++)
    z=z+arr[i];

    (z>=a)?cout<<"Yes":cout<<"No";
    /*int z=0;
    for (int i=1;i<100000;i++)
    {
     a=a-b;
     if(a<=0){
     cout<<i<<endl;
      break;}
    }*/
    return 0;
}


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

using namespace std;

int main(){
    int H,W,ans=0;
    cin >> H >> W;
    int coins[H][W];
    vector<pair<int,int>> from,to;
    pair<int,int> P;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> coins[i][j];
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W-1;j++){
            if(coins[i][j]%2==1){
                if(j!=W-1){
                    coins[i][j]--;
                    coins[i][j+1]++;
                    P.first = i;
                    P.second = j;
                    from.push_back(P);
                    P.second = j+1;
                    to.push_back(P);
                    ans++;
                }
            }
        }
    }

    for(int i=0;i<H;i++){
        if(coins[i][W-1]%2==1){
            if(i!=H-1){
                coins[i][W-1]--;
                coins[i+1][W-1]++;
                P.first = i;
                P.second = W-1;
                from.push_back(P);
                P.first = i+1;
                to.push_back(P);
                ans++;
            }
        }
    }

    cout << ans << endl;

    for(int i=0;i<from.size();i++){
        cout << from[i].first+1 << " " << from[i].second+1 << " " << to[i].first+1 << " " << to[i].second+1 << endl;
    }

}

Measured memory_bytes: 5228
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1001001001;

int dp[3005][3005];

#define chmax(x, y) x = max(x, y)

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

    int n, t;
    cin >> n >> t;
    vector<P> ab(n);
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        ab[i] = P(a, b);
    }
    sort(ab.begin(), ab.end());
    int res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < t; ++j){
            dp[i+1][j] = chmax(dp[i+1][j], dp[i][j]);
            int next_pos = j + ab[i].first;
            if(next_pos < t){
                chmax(dp[i+1][next_pos], dp[i][j]+ab[i].second);
            }
            int tmp = dp[i][t-1] + ab[i].second;
            res = max(res, tmp);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 35456
import numpy as np

def test():
    n,m = map(int,input().split())
    s = []
    count = 0
    for i in range(m):
        a = list(map(int,input().split()))
        s.append(a[1:])
    p = np.array(list(map(int,input().split())))

    for i in range(2**n):
        result = np.array([(i>>j)&1 for j in range(n)])
        if all(p == [sum(result[np.array(i)-1])%2 for i in s]):
            count += 1
    print(count)


if __name__ == "__main__":
    test()


Measured memory_bytes: 21304
import java.io.*;
import java.util.*;

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        
        String s = r.next();
        for(int i = 0; i < s.length(); i++){
            if(i % 2 == 0 && s.charAt(i) == 'L' || i % 2 == 1 && s.charAt(i) == 'R'){
                pw.println("No");
                pw.close();
                return;
            }
        }
        pw.println("Yes");
        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 21460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;

int n;
int len[2010];
int sum;
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &len[i]);
    }
    sort(len+1,len+n+1);
    for(int i=1;i<n;++i){
        for(int j= i+1;j<=n;++j){
            int add = len[i]+len[j];
            int  pos = lower_bound(len+j,len+n+1,add) - len;
            sum += pos - 1 - j;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = line[0], M = line[1], X = line[2], Y = line[3];

            var xDem = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var yDem = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ymin = yDem.Min();

            if (X < ymin && ymin <= Y && xDem.Max() < ymin)
                Console.WriteLine("No War");
            else
                Console.WriteLine("War");
        }
    }
}


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

int pad[3][6] = { { 3, 1, 0, 5, 4, 2 }, { 1, 5, 2, 3, 0, 4 }, { 0, 2, 4, 1, 3, 5 } };
void rotate ( int op, string &S )
{
    string temp;
    for ( int i = 0; i < 6; i++ ) {
        temp.push_back ( S[pad[op][i]] );
    }
    S = temp;
}

bool search ( string S, string T )
{
    for ( int i = 0; i < 4; i++ ) {
        for ( int j = 0; j < 4; j++ ) {
            for ( int k = 0; k < 4; k++ ) {
                if ( S == T ) {
                    return ( false );
                }
                rotate ( 2, S );
            }
            rotate ( 1, S );
        }
        rotate ( 0, S );
    }
    return ( true );
}

int main()
{
    int N;
    int rotate_pos[35];

    while ( cin >> N, N ) {
        vector < string > data(N);
        int ans = 0;
        bool flag[35];

        fill_n(flag, 35, true);
        for ( int i = 0; i < N; i++ ) {
            string S;
            for ( int j = 0; j < 6; j++ ) {
                cin >> S;
                data[i] += S[0];
            }
            for ( int j = 0; j < i; j++ ) {
                flag[i] &= search ( data[i], data[j] );
            }
        }
        for ( int i = 0; i < N; i++ ) {
            if ( !flag[i] ) {
                ans++;
            }
        }
        cout << ans << endl;
    }

    return ( 0 );
}



Measured memory_bytes: 3008
n, m = map(int, input().split())
ans = []
for i in range(n):
    ans.append([0, 'WA'])
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)-1
    if(s=='WA' and ans[p][1] == "WA"):ans[p][0]+=1
    else:ans[p][1] = 'AC'
ac = 0
wa = 0
for i in ans:
    if(i[1] == 'AC'):
        ac+=1
        wa+=i[0]
print(ac, wa)

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

int main(){
    ll n;
    cin>>n;
    if(n%111==0){
        cout<<n<<endl;
    }else{
        if(n<(n/100*111)){
            cout<<n/100*111<<endl;
        }else{
            cout<<(n/100+1)*111<<endl;
        }
    }

}



Measured memory_bytes: 3596
# https://atcoder.jp/contests/abc092/tasks/abc092_b
n = int(input())
d, x = map(int, input().split())
nums = []
for _ in range(n):
    nums.append(int(input()))

c = 0
for i in range(n):
    t = 1
    j = 1 + nums[i]
    while j <= d:
        j += nums[i]
        t += 1
    c += t
ans = c + x
print(ans)

Measured memory_bytes: 38512
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static Scanner sc = new Scanner();

    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var D = sc.ReadIntArray(N);

        Array.Sort(D);

        var a = N / 2 - 1;
        var ans = D[a + 1] - D[a];

        Console.WriteLine(ans);
    }

    static long Gcd(long a, long b)
    {
        var v = new[] { a, b };
        while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
        return v[0];
    }

    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }

    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

class HashMap<K, V> : Dictionary<K, V> where V : new()
{
    private V DefaltValue = new V();
    public HashMap() { }
    public HashMap(V defaultValue)
    {
        this.DefaltValue = new V();
    }
    new public V this[K i]
    {
        get
        {
            V v;
            return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
        }
        set { base[i] = value; }
    }
}

Measured memory_bytes: 22112