akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define MAX_N 2000

int compare_int(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}

int main()
{
	int N, i, j, k, ans = 0;
	int l[MAX_N];
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%d", &l[i]);
	}

	qsort(l, N, sizeof(int), compare_int);

	for (i = 0; i < N-2; i++)
	{
		for (j = i+1; j < N-1; j++)
		{
			for (k = j+1; k < N; k++)
			{
				if ((l[i]+l[j]) > l[k])
				{
					ans++;
				}
				else
				{
					break;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll N;
	cin >> N;
 
	// 解法
	// エラトステネスの篩
	// M 以下の数に対してエラトステネスの篩を適用した時のオーダーは O(Mlog(logM))
	bool f[55555+1]; // 素数かどうかの判別リスト, falseなら素数、もしくは未確認
	for (ll i=2; i<=55555; i++){ // 2-10000までの整数に対し
		if (!f[i]){ 
			// f[i]=0ならばiはまだ見ていない=iは素数である。
			// !f[i]: iが素数であるなら
			for (ll j = i+i; j<=55555; j+=i){// iの倍数jに対し
				f[j]= true ; // iの倍数jが素数でないことを記録する。
			}
		}
	}
	ll count = 0;
	for (ll i=2; i<=55555; i++){ 
		if (!f[i] && i%5==1){
			if (count==0){
				printf("%lld", i);
				count++;
			}
			else{
				printf(" %lld", i);
				count++;
			}
		}
		if (count==N){
			printf("\n");
			break;
		}
	}
}


Measured memory_bytes: 256
n=int(input())
a=[]
for _ in range(n):
	a.append(list(map(int,input().split())))
from copy import deepcopy
b=deepcopy(a)
for i in range(n):
	for j in range(n):
		for k in range(n):
			b[j][k]=min(b[j][i]+b[i][k],b[j][k])
if a!=b:
	print(-1)
	exit()
ans=0
for i in range(n):
	b[i][i]=10**18
for i in range(n):
	for j in range(n):
		f=1
		for k in range(n):
			if b[i][j]>=b[i][k]+b[k][j]:
				f=0
				break
		if f:
			ans+=b[i][j]
print(ans//2)


Measured memory_bytes: 56668
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int y, m, d;
        char c1, c2;
        cin >> y >> c1 >> m >> c2 >> d;

        if (m <= 4)
        {
                cout << "Heisei" << endl;
        }
        else
        {
                cout << "TBD" << endl;
        }
        return 0;
}


Measured memory_bytes: 256
#import sys
#import math
#import numpy as np

'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
a=int(input())
ans=0
x=[list(map(str,input().split())) for _ in range(a)]
for i in range(a):
  if x[i][1]=='BTC':
    ans+=float(x[i][0])*380000
  else:
    ans+=int(x[i][0])
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005,mod=1e9+7;
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  if(x<0) x+=mod;
  return x;
}
int mult(int x,int y)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
string s;
map<int,int> dp[2*N];
int fun(int ind,int open)
{
  if(ind==sz(s)) return (open==0);
  if(dp[ind].count(open)) return dp[ind][open];
  int ans=0;
  if(s[ind]=='W')
    {
      if(open%2==0)//close here
	ans=add(ans,mult(open,fun(ind+1,open-1)));
      else//open here
	ans=add(ans,fun(ind+1,open+1));
    }
  else
    {
      if(open%2==0)//open here
	ans=add(ans,fun(ind+1,open+1));
      else//close here
	ans=add(ans,mult(open,fun(ind+1,open-1)));
    }
  return dp[ind][open]=ans;
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n>>s;
  if(s[0]=='W' || s[sz(s)-1]=='W')
    {
      cout<<0<<endl;
      return 0;
    }
  int ans=fun(0,0);
  rep(i,1,n+1) ans=mult(ans,i);
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 37908
var
	a,b,c,d,e,f,i,j,k,l,ansa,ansb,tmp:Longint;
begin
	read(a,b,c,d,e,f);
	ansa:=100*a;
	for i:=0 to f div(100*a) do begin
		for j:=0 to (f-100*a*i)div(100*b)do begin
			tmp:=a*i+b*j;
			for k:=0 to (f-100*tmp)div c do begin
				for l:=0 to (f-100*tmp-c*k)div d do begin
					if(tmp*e>=c*k+d*l)and(ansa*(c*k+d*l)>ansb*(100*tmp+c*k+d*l))then begin
						ansb:=c*k+d*l;
						ansa:=100*(a*i+b*j)+ansb;
					end;
				end;
			end;
		end;
	end;
	write(ansa);
	write(' ');
	writeln(ansb);
end.


Measured memory_bytes: 128
import java.util.Scanner;

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

		int[] a = new int[6];
		int[] t = new int[4];

		for (int i = 0; i < 6;i++){
			t[ scan.nextInt() -1]++;
		}
		int min = 6;
		int max = 0;
		for (int i = 0; i < 4;i++){
			if(min > t[i]) min = t[i];
			if(max < t[i]) max = t[i];
		}
		boolean yes = min > 0 && max < 3;

		if(yes){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21716
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())

L = []
L.append(2)
L.append(1)
for i in range(2, 100):
    L.append(L[i - 1] + L[i - 2])

print(L[N])


Measured memory_bytes: 13676
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin>>n;
  vl a(n);
  rep(i,n) cin>>a[i];
  vl l(n), r(n);
  rep(i,n-1) l[i+1] = gcd(l[i], a[i]);
  for (int i = n-1; i >= 1; --i) r[i-1] = gcd(r[i], a[i]);
  ll ans = 1;
  rep(i,n) ans = max(ans, gcd(l[i],r[i]));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2560
import sys
import math
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    A, B = MI()
    x = 10*B
    n = 0

    for i in range(1001):
        if  math.floor(x*0.08) == A:
            break
        x += 1

        if i == 1000:
            x = 10*B
            break
    for i in range(1001):
        x += -1
        if math.floor(x*0.08) != A or math.floor(x*0.1) != B:
            x += 1
            break

    if math.floor(x*0.08) == A and math.floor(x*0.1) == B:
        print(x)
    else:
        print(-1)





if __name__ == "__main__":
	main()

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<bitset>

using namespace std;

/************************************************/

int main(void) {
	int n;
	cin >> n;
	vector<int>l(n), r(n);
	for (int i = 0; i < n; i++)cin >> l[i] >> r[i];
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += r[i] - l[i] + 1;
	}
	cout << sum;
	return 0;
}

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

//kieutrave ten ham(tham so)
int main(){
	string s ;
	int k;
	cin>>k>>s;
	for (int i=0;i<min((int)s.size(),k);i++){
		cout<<s[i];
	}
if (s.size()>k){
	cout<<"...";
}	
	return 0;
}

Measured memory_bytes: 3564
N = int(input())
S = input()
P = []
for_represent = []
for i in range(len(S)):
    if ord(S[i]) + N > 90:
        temp = (ord(S[i]) + N) - 90
        P.append(chr(65 + (temp - 1)))
    else:
        P.append(chr(ord(S[i]) + N))
P = "".join(map(str, P))
print(P)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> ac(n);
    vector<int> wa(n);
    for(int i=0;i<m;i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC") ac[p] = true;
        else if(!ac[p]) wa[p]++;
    }
    int c = 0, w = 0;
    for(int i=0;i<n;i++){
        if(ac[i]){
            c++;
            w += wa[i];
        }
    }
    cout << c << " " << w << endl;
    return 0;
}

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

typedef vector<int> vec;

int main () {
    int N, m; cin >> N >> m;
    vec c(m), d(m);
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    vec h(N + 1);
    for (int i = 0; i < m; i++) {
        if (c[i] < d[i]) {
            for (int j = c[i] + 1; j <= d[i]; j++) {
                h[j] = 1;
            }
        }
    }

    int res = N + 1;
    for (int i = 1; i <= N; i++) {
        if (h[i]) {
            res += 2;
        }
    }

    cout << res << endl;

    return 0;
}

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

int main() {
  int N,M;
  cin >> N;
  vector<string> blue(N);
  vector<int> blnum(N);
  for(int i=0; i<N; i++){
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red(M);
  for(int i=0; i<M; i++){
    cin >> red.at(i);
  }
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      if(blue.at(i)==blue.at(j)){
        blnum.at(i)++;
      }
    }
    for(int k=0; k<M; k++){
      if(red.at(k)==blue.at(i)){
        blnum.at(i)--;
      }
    }
  }
  sort(blnum.begin(), blnum.end());
  if(blnum.at(N-1) < 0){
    cout << 0;
  }
  else{
    cout << blnum.at(N-1)+1;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll x;
  cin >> x;
  vl a;
  rep2(i, -1000, 1001) a.push_back(pow(i, 5));
  ll n = a.size();
  rep(i, n) rep(j, n) {
    if(a[i] - a[j] != x) continue;
    cout << i - 1000 << ' ' << j - 1000 << endl;
    return 0;
  }
}

Measured memory_bytes: 4136
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int UF[2100];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int g[1100][1100];
int cnt[1500];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p][q]=g[q][p]=1;
	}
	for(int i=0;i<a*2;i++)UF[i]=-1;
	for(int i=0;i<a;i++){
		for(int j=i+1;j<a;j++){
			if(g[i][j]==0){
				UNION(i*2,j*2+1);
				UNION(i*2+1,j*2);
			}
		}
	}
	for(int i=0;i<a;i++){
		if(FIND(i*2)==FIND(i*2+1)){
			printf("-1\n");return 0;
		}
	}
	vector<int>c;
	int T=0;
	for(int i=0;i<a;i++){
		cnt[FIND(i*2)]++;
//		printf("%d\n",FIND(i*2));
	}
	for(int i=0;i<a;i++){
		c.push_back(max(cnt[i*2],cnt[i*2+1])-min(cnt[i*2],cnt[i*2+1]));
		T+=min(cnt[i*2],cnt[i*2+1]);
	}
	bitset<710>dp;
	dp[0]=1;
	for(int i=0;i<c.size();i++){
		dp|=(dp<<c[i]);
	}
	int ret=mod;
	for(int i=0;i<710;i++){
		if(dp[i])ret=min(ret,(T+i)*(T+i-1)/2+(a-i-T)*(a-i-T-1)/2);
	}
	printf("%d\n",ret);
}

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

string s;

int main(){
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i) 
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　  　 ,ﾍ／L──- 、
	　　　   　Lﾆ)r_」=＝= ｲ
	　　 　,ﾍ、i ﾉノλﾉﾊﾉﾍ
	　　   ,'　｀(ﾊﾘ ﾟ ヮﾟﾉi)　',
	　　 .i　　 >〈(つ,i!と)　　i
	　　  vﾍγk´_/___i,ゝﾍノ
	　　　　　 ｀ﾞr_,ｨ_ｧﾞ´
	*/
	string s;
	cin >> s;
	ll ans = 0;
	if (s.length() == 1) {
		cout << 0 << endl;
		return 0;
	}
	rep0(i, s.length() - 2) {
		if (s[i] != s[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  vector<int> v(5);
  int i,j,k;
  for(i=0;i<5;i++) cin >> v[i];
  cin >> k;
  sort(v.begin(),v.end());
  for(i=0;i<4;i++){
    for(j=i;j<5;j++){
      if(v[j]-v[i]>k){
        cout << ":(" << "\n";
        return 0;
      }
    }
  }
  cout << "Yay!" << "\n";
  return 0;
}

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

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;

    RollingHash rh(S);
    int ans = 0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            int lcp = rh.getLCP(i,j);
            lcp = min(lcp, j-i);
            chmax(ans, lcp);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('', (a) => {
  rl.question('', (s) => {
    if(a >= 3200) {
      console.log(s);
    } else {
      console.log('red');
    }
  });
});

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, C;

    cin >> A >> B >> C;

    if(A + B == C || B + C == A || A + C == B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    // if(ans){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }

}



Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define maxn 301
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define pb push_back
#define mp make_pair

const int mod = 1000000000 + 7;
int a[100000];
int n;
void solve(){
    cin >> n;
    rep(i,n) cin >> a[i];
    sort(a, a+n);
    if(a[n-1] - a[0] > 1){
        cout << "No";
        return;
    }
    int k = 0;
    rep(i,n){
        k += a[i] == a[0];
    }
    if(k==n){
        // individual
        if(a[0] == n-1){
            puts("Yes");
        }else
        // group
        if(a[0] <= n / 2){
            puts("Yes");
        }else{
            puts("No");
        }
        return;
    }
    if(n-k < 2){
        puts("No");
        return;
    }
    int l = k+1, r = k + (n-k) / 2;
    if(a[0]+1 >= l && a[0] + 1 <= r){
        puts("Yes");
    }else{
        puts("No");
    }
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    solve();
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
using vl = vector <ll>;
//#define op operator
#define pb push_back

const int N = 1e5L + 11;
int p[N];

using comp = complex<db>; //??????comp????????¶??´: d /= 1.5, ld /= 3
using vc = vector<comp>; const db PI = atan(1.0L) * 4;
void dft(vc &a, int op = 1) {
	int n = a.size();
	for (int i = 1, j = 0; i < n - 1; ++i) {
		for (int s = n; j ^= s >>= 1, ~j & s;) {}
		if (i < j) swap(a[i], a[j]);
	}
	for (int i = 1; i < n; i *= 2) {
		comp u = {cos(PI / i), op * sin(PI / i)};
		for (int j = 0; j < n; j += i * 2) {
			comp w = 1;
			for (int k = 0; k < i; ++k, w = w * u) {
				comp x = a[j + k], y = w * a[j + k + i];
				a[j + k] = x + y, a[j + k + i] = x - y;
	}}}
	if (op == -1) for (int i = 0; i < n; ++i) a[i] /= n;
}
vl multi(vl a, vl b) { // ????????????: d <= 1e12, ld <= 1e14
	int n = 1; while (n < a.size() + b.size() - 1) n *= 2;
	vc fa(n), fb(n), fc(n);
	copy(a.begin(), a.end(), fa.begin()); dft(fa);
	copy(b.begin(), b.end(), fb.begin()); dft(fb);
	for (int i = 0; i < n; ++i) fc[i] = fa[i] * fb[i];
	dft(fc, -1); vl c(n);
	for (int i = 0; i < n; ++i) c[i] = round(fc[i].real());
	return c;
}

int main() {
	for(int i = 2; i < N; i ++) if(!p[i])
		for(int j = i; j < N; j += i) if(!p[j]) p[j] = i;

	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	vector <ll> v(N, 0);
	for(int i = 2; i < N; i ++)
		v[i] = p[i] == i;
	v = multi(v, v);

	for(int n; cin >> n && n; ) {
		cout << v[n] / 2 + (p[n / 2] == n / 2) << '\n';
	}

	return 0;
}

Measured memory_bytes: 20204
n = gets.to_i

if n % 2 == 0 || n % 5 == 0
  puts -1
  return
end

x = 0
count = 0
n.times do
  x = (x * 10 + 7) % n
  count += 1
  break if x == 0
end

puts x == 0 ? count : -1


Measured memory_bytes: 14324
#include <iostream>

using namespace std;

int main() {
	int N;
	int cnt = 0;
	int li = 1;
	int buf;
	int a[100000] = {};
	cin >> N;
	for (int i = 0; i<N; i++)
		cin >> a[i];

	while (1) {
		buf = li;
		li = a[li-1];
		a[buf-1] = 0;
		cnt++;
		if (!li) { cout << -1 << endl; break; }
		if (li == 2) { cout << cnt << endl; break; }
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    int ans = 0;
    for (int i = 0; i < (int) s.size(); i++){
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/29  Problem: 078_arc_a / Link: https://arc078.contest.atcoder.jp/tasks/arc078_a ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N, 0);
	VL cum(N + 1, 0);
	FOR(i, 0, N) {
		cin >> a[i];
		cum[i + 1] = cum[i] + a[i];
	}

	ans = numeric_limits<long long>::max();
	FOR(i, 1, N) {
		ans = min(ans, abs(cum[i] - (cum[N] - cum[i])));
	}

	cout << ans << "\n";

	return 0;
}


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

int main()
{
    int rc[110][110]{0};
    int r, c;
    cin >> r >> c;

    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            cin >> rc[i][j];
        }
    }

    for(int i=0; i<r; ++i){
        for(int j=0; j<c; ++j){
            rc[i][c] += rc[i][j];
        }
    }
    
    for(int j=0; j<r; ++j){
        for(int i=0; i<c+1; ++i){
            rc[r][i] += rc[j][i];
        }
    }

    for(int i=0; i<r+1; ++i){
        for(int j=0; j<c+1; ++j){
            cout << rc[i][j];
            if( j!= c){
                cout << ' ';
            }
        }
        cout << endl;
    }

    return 0;
}



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

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    vector<vector<int>> count(H, vector<int>(W));
    int count_sharp = 0;
    rep(i, H){
        rep(j, W){
            cin >> s.at(i).at(j);
            count.at(i).at(j) = -1;
            if(s.at(i).at(j) == '#'){
                count_sharp++;
            }
        }
    }

    count.at(0).at(0) = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    while(!q.empty()){
        pair<int, int> xy = q.front();
        q.pop();
        for (int i = 0; i < 4;i++){
            int x = xy.first + dx[i];
            int y = xy.second + dy[i];
            if (x == -1 || y == -1 || x == H || y == W){
                continue;
            }else if(s.at(x).at(y) == '#'){
                continue;
            }else if(count.at(x).at(y) != -1){
                continue;
            }
            count.at(x).at(y) = count.at(xy.first).at(xy.second) + 1;
            q.push(make_pair(x, y));
        }
    }
    
    if(count.at(H - 1).at(W - 1) == -1){
        cout << -1 << endl;
    }else{
        int ans = H * W - count_sharp - (count.at(H - 1).at(W - 1) - 1) - 2;
        cout << ans << endl;
    }
}



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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);


    set<char> alp;
    for(int i = 0; i < 26; ++i){
        alp.insert('a'+i);
    }

    string s;
    cin >> s;

    if(s.size() < 26){
        for(auto c : s){
            alp.erase(c);
        }
        cout << s << *(alp.begin()) << endl;
    }
    else{
        int i = 24;
        while(s[i] > s[i+1] and i >= 0) --i;
        if(i == -1) {
            cout << i << endl;
        }
        else{
            for(int j = 0; j <= i; ++j){
                alp.erase(s[j]);
            }
            for(auto c = alp.begin(); c != alp.end(); ++c){
                if(*c > s[i]){
                    cout << s.substr(0, i) << *c << endl;
                    break;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

bool isprime(int x){
    for (int y = 2; y * y <= x; y++){
        if (x % y == 0) return false;
    }
    return true;
}

const ll mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();

    VI isp(n);
    REP(i,n) isp[i] = isprime(a[i]);

    VVI dp(n+2, VI(2));
    if (isp[0]){
        dp[1][0] = 1;
        dp[2][1] = 1;
    }

    FOR(i,1,n-1) REP(j,2){
        if (!isp[i]) continue;
        if (a[i] <= a[i-j-1]) continue;
        dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % mod;
        dp[i+2][1] = (dp[i+2][1] + dp[i][j]) % mod;
    }

    cout << (dp[n][0] + dp[n][1]) % mod << endl;

    return 0;
}


Measured memory_bytes: 9292
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    P=[int(input()) for i in range(N)]
    alr=set()
    iorn=[False]*(N+1)
    for i in range(N):
        if P[i]-1 in alr:
            iorn[P[i]]=True
        alr.add(P[i])
    maxlen=0
    lenn=0
    for i in range(1,N+1):
        if iorn[i]:
            lenn+=1
        else:
            lenn=1
        maxlen=max(maxlen,lenn)
    print(N-maxlen) 
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 111580
#include <stdio.h>

int main()
{
  char c, h;
  while((c = getchar()) != EOF){
    if(c == ' '){
      c = getchar();
      if(c != h){
        puts("NO");
        return 0;
      }
    }
    h = c;
  }

  puts("YES");
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int memo[50][100]={};
    for(int i=0;i<n;++i){
        string s;cin>>s;
        for(int j=0;j<s.length();++j){
            memo[i][s[j]-'a']++;
        }
    }
    vector<int>ans(100,100000000);
    for(int i=0;i<'z'-'a'+1;++i){
        for(int j=0;j<n;++j){
            ans[i]=min(ans[i],memo[j][i]);
        }
    }
    for(char i='a';i<='z';++i){
        for(int j=0;j<ans[int(i-'a')];++j)cout<<i;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> 
using namespace std;
int main()
{
	char ch[55];
	cin>>ch;
	for(int i=0; i<strlen(ch)-8; i++)
	cout<<ch[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> as(100000, 0);
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        ++as[a];
    }
    int sum=as[0]+as[1]+as[2];
    int ans=sum;
    for(int i=3; i<100000; ++i){
        sum=sum-as[i-3]+as[i];
        ans=max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  if(n<1200){
    cout<<"ABC"<<endl;
  }else if(n<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

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

int d[100010];

int main() {
    int n;
    cin >> n;
    rep(i, n){
        cin >> d[i];
    }

    std::sort(d, d + n);
    int ans = d[n / 2] - d[(n / 2) - 1];
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	long long k, x;

	std::cin >> k >> x;

	if (k * 500 >= x) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
K = input()
D = int(input())
L = len(K)
mod = 10 ** 9 + 7

dp = [[[0] * 2 for _ in range(D)] for _ in range(L+1)]
dp[0][0][0] = 1

for i in range(L):
    nd = int(K[i])
    for j in range(D):
        for k in range(2):
            #lim = 9 if k == 1 else nd
            for d in range(10):
                nk = k
                if k == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1
                dp[i+1][(j+d) % D][nk] += dp[i][j][k]
                dp[i+1][(j+d) % D][nk] %= mod

ans = (dp[L][0][0]+dp[L][0][1]-1+mod) % mod

#for i in range(L+1):
#    print(dp[i])
print(ans)

Measured memory_bytes: 129500
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>

using namespace std;


int main(){
    int n;
    cin >> n;
    vector<string> s;
    for (int i = 0; i < n; i++){
        string ss;
        cin >> ss;
        sort(ss.begin(),ss.end());
        s.push_back(ss);
    }
    sort(s.begin(),s.end());

    long long ans = 0;
    long long num = 0;
    for (int i = 0; i < n-1; i++){
        if (s[i] == s[i+1]) num++;
        else {
            if (num > 0){
                ans += (num+1)*num/(2);
                num = 0;
            }
            else continue;
        }
    }
    if (num > 0){
        ans += (num+1)*num/(2);
    }
    cout << ans << endl;

    return 0;
}

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

vector<int> ans[100];

int main(){
    int N;
    cin>>N;
    if(N==2){
        cout<<-1<<endl;
        return 0;
    }
    if(N%2){
        for(int i=0;i<N;i++){
            for(int j=1;j<N;j++){
                ans[i].push_back((i+j)%N);
            }
        }
    }else{
        for(int i=0;i<N;i++){
            for(int j=2;j<N;j++){
                if(j*2==N) continue;
                else ans[i].push_back((i+j)%N);
            }
            if(i<N/2){
                ans[i].push_back((i+1)%N);
                ans[i].push_back((i+N/2)%N);
            }else{
                ans[i].push_back((i+N/2)%N);
                ans[i].push_back((i+1)%N);
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            if(j)cout<<' ';
            cout<<ans[i][j]+1;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
import sys
from math import sqrt, gcd, ceil, log
# from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
# from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

# sys.setrecursionlimit(5*10**6)

def main():
	n = int(input()); 
	# dic = defaultdict(int)
	# for i in range(1, 10):
	# 	for j in (1, 3, 7, 9):
	# 		dic[(j, (i*j)%10)] = i
	# # print(dic)
	# if n%10 in (1, 3, 7, 9):
	# 	t = n%10; i = 0
	# else:print(-1)
	s = list(input().strip())
	i, j = 0, n-1
	ans = 0
	while i < j:
		if s[i] == "W" and s[j] == "R":
			ans += 1
			s[i], s[j] = s[j], s[i]
		else:
			i += (s[i] == "R")
			j -= (s[j] == "W")
	print(ans)





if __name__ == "__main__":
	main()

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

int main(){
     int N;
    cin >> N;
    int mi = N+1, res = 0;
    for (int i = 0; i < N; ++i) {
        int p; cin >> p;
        mi = min(mi, p);
        if (mi== p) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

string s;
int k;

int main() {
    cin >> k;
    cin >> s;
    if (s.size() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}


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

typedef long long ll;

int main()
{
    ll i,j;
    int n;
    cin >> n;
    vector<string> s(n);
    for(i = 0;i < n;++i){
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    string tmp = s.at(0);
    int num = 1;
    vector<pair<int,string>> ans;
    for(i = 1;i < n;++i){
        if(s.at(i) == tmp){
            ++num;
        }else{
            ans.emplace_back(num, tmp);
            num = 1;
            tmp = s.at(i);
        }
    }
    ans.emplace_back(num, tmp);
    sort(ans.begin(), ans.end());
    int len = ans.back().first;
    vector<string> st;
    for(i = ans.size()-1;i >= 0;--i){
        if(ans.at(i).first == len){
            st.push_back(ans.at(i).second);
        }else{
            break;
        }
    }
    sort(st.begin(), st.end());
    for(i = 0;i < st.size();++i){
        cout << st.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 21744
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a;
    getchar();
    cin>>b;
    getchar();
    cin>>c;
    if(a<=2019&&b<=4&&c<=30)
        cout<<"Heisei"<<endl;
    else
        cout<<"TBD"<<endl;
}


Measured memory_bytes: 3656
import sys,collections as cl,bisect as bs,itertools
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

N,M,Q = m()

dp = itertools.combinations_with_replacement(range(1, M+1), N)

data = []

ma = 0

for i in range(Q):
    data.append(l())
    
for i in dp:
    po = i
    te = 0
    for j in range(len(data)):
        a,b,c,d = data[j]
        if po[b-1]-po[a-1] == c:
            te += d
    ma = max(ma,te)
print(ma)












Measured memory_bytes: 74112
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int a,b;
  cin >> a >> b;
  string s = "";
  if(a < b){
    for(int i=0;i<b;i++) s += to_string(a);
  }
  else{
    for(int i=0;i<a;i++) s += to_string(b);
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
n,d = map(int, input().split())
x = [[] for g in range(n)]
c = 0
ans = 0
for h in range(n):
  x[h] = list(map(int, input().split()))
for i in range(0,n-1):
  for j in range(i+1,n):
    for k in range(d):
      c += (x[i][k] - x[j][k])**2
    if (c**0.5).is_integer():
      ans += 1
    c = 0
print(ans)

Measured memory_bytes: 9336
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    int H = N / 100;
    if (H * 111 >= N) cout << H * 111 << endl;
    else cout << ++H * 111 << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE TypeApplications #-}
import Control.Monad
import Data.List
import Data.Maybe
import Text.Printf

main = do
  [w, h, x, y] <- mapM (readIO @Double) . words =<< getLine
  let ans1 = h * w / 2.0
      ans2 = if w / 2.0 == x && h / 2.0 == y then 1 :: Integer else 0 :: Integer
  printf "%.9f %d" ans1 ans2

Measured memory_bytes: 4196
from typing import List, Tuple


def go_to_jail(N: int, D: List[Tuple[int, int]]) -> bool:
    prev = (False, False)

    for d1, d2 in D:
        if d1 == d2 and all(prev):
            return True
        prev = prev[1], d1 == d2
    return False


if __name__ == "__main__":
    N = int(input())
    D = [tuple(input().split()) for _ in range(N)]
    ans = go_to_jail(N, D)
    print("Yes" if ans else "No")


Measured memory_bytes: 10256
from fractions import gcd
N=int(input())
a_list = list(map(int, input().split()))
gcd_l = [0] * (N+1) 
gcd_r = [0] * (N+1) 
for i, a in enumerate(a_list):
    gcd_l[i+1] = gcd(gcd_l[i], a)
for i in range(N, 0, -1):
    a = a_list[i-1]
    gcd_r[i-1] = gcd(gcd_r[i], a)
ans = 1
#print(gcd_l, gcd_r)
for i in range(N):
    tmp = gcd(gcd_l[i], gcd_r[i+1])
    ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 89580
Q = int(input())
Ri = [list(map(int, input().split())) for _ in range(Q)]

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b

    if a == b:
        print(2 * a - 2)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        r = max_score ** 0.5
        rn = int(r)
        if rn == r:
            rn -= 1
        if rn * (rn + 1) >= max_score:
            print(2 * rn - 2)
        else:
            print(2 * rn - 1)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		int n[] = new int[N.length() + 1];
		int x = 0;
		for (int i = 0; i < N.length(); i++) {
			x += Integer.parseInt(N.substring(i, i + 1));
		}
		if (Integer.parseInt(N) % x == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844